question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mcanshcommented, Aug 2, 2022

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

0reactions
samstandingcommented, Oct 3, 2022

@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 />}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Page crashing from '#' as a GET-parameter - Stack Overflow
Whenever you create URL to be displayed in the browser it has to be urlencoded. If you are just appending the query string...
Read more >
Data Loading - Remix
URL Search Params are the portion of the URL after a ? . Other names for this are "query string", "search string", or...
Read more >
Fixing Next.js router query param returning undefined on ...
for a lot of time, the page kept crashing. When I saw your code, it immedeately clicked in my mind, why not do...
Read more >
Appending the referrer's query string to the curre...
I'm looking to keep URL query string parameters. ... It's also good that he mentioned both pages are running over SSL (https), ...
Read more >
How to Access the URL Params in React with React Router's ...
This guide walks through how to utilize React Router's useParams hook to get access to the URL params data for a route, such...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found