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.

Losing URL Search params on navigate.push under certain scenarios

See original GitHub issue

Description

Under certain conditions (see Loom video for example) we are finding that we are losing URL search params after a navigate.push call and are having a hard time understanding why this is happening. General debugging would suggest to look for unintentional follow-up calls to navigate.push, but since we wrap all navigate method calls with our own wrapper with debug output, we are finding only a single navigate.push call is made (with correct path + search params) but yet browser history appears to immediately update and we lose search params.

Example scenario:

  1. Visit https://contra.com/discover/independents and click on a “Get In Touch” button.
  2. You’ll be presented with a modal indicating you need to “Complete Sign Up”. Click the “Complete Sign Up” button which will redirect you to the /sign-up route with attached search params (redirectTo, etc).
  3. Note that the URL is in the browser address bar is correct, and the search params exist in the path.
  4. Hit the “back” button in your browser to go back to the /discover/independents page.
  5. Click on a “Get In Touch” button followed up by the modals “Complete Sign Up” button.
  6. Notice how you are navigated to the /sign-up route with search params, and then almost immediately lose search params as another entry to the history stack is made for the same path (but now without the search params). Note how you lost the search params in the browser address bar.
  7. If you were to hit “back” in the browser again now, you’ll notice that the search params come back.

Again, we only see one call from our code to navigate.push() happening, but clearly for some reason we are getting two entries in the browser history, one correctly with the search params, immediately followed by another entry without them.

https://www.loom.com/share/9dc365e4e4a948369080d76d6549b89c


Not sure how this would be taking place and would love any guidance on debugging this behavior from vite-plugin-ssr client routing.

Error Stack

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Nov 10, 2022

Adding console.log(new Error('breadcrumbs').stack) will give you further insights.

I recommend to do this then. This should definitely tell you why pushState() is being called twice.

0reactions
erictaylorcommented, Nov 10, 2022

Yeah thanks @brillout. I’ll keep digging here. I’ll update you later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby navigation with query parameters do hard refresh and ...
In this case, the behavior is: Redirect to the Login page. After login navigate(https://example.com/one-of ...
Read more >
React Router 6: Search Params (alias Query Params)
Search Params (also called Query Params) are a powerful feature, because they enable you to capture state in a URL. By having state...
Read more >
Navigate to a URL with Query Strings (Search Params) in ...
React Router has a useSearchParams hook to help us read or update the query string of a route that's active, but it doesn't...
Read more >
allow searchParams to be passed to useNavigate's options to ...
I'd like to be able to do something like: const navigate = useNavigate(); // this would ... You can create search Pram using...
Read more >
How To Use Query Parameters with Angular Router
By default, the query parameters are lost on any subsequent navigation action. To prevent this, you can set queryParamsHandling to either ' ...
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