remix icon indicating copy to clipboard operation
remix copied to clipboard

<PrefetchPageLinks /> crashes the page when there is a query param in the URL

Open samstanding opened this issue 3 years ago • 7 comments

What version of Remix are you using?

1.6.1

Steps to Reproduce

  1. Add a <PrefetchPageLinks /> to an active route.
  2. Add some query params to your URL ie ?query and hit return to reload the page
  3. Observe: image

Expected Behavior

I would expect the page to load, unless there's some behavior with PrefetchPageLinks I was not aware of where it can't be rendered on a page with query params.

Actual Behavior

The page crashes and we see the following window is not defined error image

samstanding avatar Jul 13 '22 17:07 samstanding

Verified on 1.6.4 as well

machour avatar Jul 13 '22 18:07 machour

tracking this internally now, and I plan to look into it today!

edit: OP actually has a potential fix for this via #3791

edit 2: actually looking over this more, the issue at hand is we use window in PrefetchPageLinks so we can get the current url as well as get the proper links depending on media queries, but i know we have a internal ticket for that already. Usage in the Link component is to conditionally rendered depending on intent https://github.com/remix-run/remix/blob/142aedc69b62633c4a6ebd49c0ae333255aa5d5a/packages/remix-react/components.tsx#L499 - but gonna look into a broader fix for this, first thought is return early if typeof document === "undefined" as ideally we don't render these during SSR, but we'll see

mcansh avatar Aug 02 '22 17:08 mcansh

Hey @mcansh any updates? Is it possible to use my PR as a stopgap so that we can use PrefetchPageLinks if there's a query param?

samstanding avatar Sep 30 '22 19:09 samstanding

@samstanding not currently, do you have a use case where you can't conditionally render <PrefetchPageLinks>?

skipping them during the server render and applying them during hydration would more than likely cause a hydration warning

mcansh avatar Oct 03 '22 15:10 mcansh

@samstanding not currently, do you have a use case where you can't conditionally render <PrefetchPageLinks>?

skipping them during the server render and applying them during hydration would more than likely cause a hydration warning

@mcansh I can conditionally render it but we're using it to help a slow endpoint so it would be preferred to use it across the board. Right I'm doing something like {!location.search && <PrefetchPageLinks />}

samstanding avatar Oct 03 '22 16:10 samstanding

This is still broken for me. Any updates?

danielgangl avatar Jan 06 '23 20:01 danielgangl

using 'typeof document !== "undefined"' now to conditionally render the PrefetchPageLinks component as a workaround

danielgangl avatar Jan 06 '23 20:01 danielgangl

I don't think this is an issue anymore since 1.10.0 and the incorporation of RouterProvider from react-router-dom

brophdawg11 avatar May 05 '23 17:05 brophdawg11