Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Using urlKeys option with history push makes state unresponsive to URL change #758

Closed
hallucinogenizer opened this issue Nov 12, 2024 · 4 comments · Fixed by #759
Closed
Labels
bug Something isn't working released

Comments

@hallucinogenizer
Copy link

hallucinogenizer commented Nov 12, 2024

Context

What's your version of nuqs?

"nuqs": "2.1.1"

What framework are you using?

  • ✅ Next.js (app router)

Which version of your framework are you using?
v14.2.0

-> Paste the relevant framework versions from your package.json here
"dependencies": {
    "next": "14.2.0",
    "nuqs": "2.1.1",
    "react": "^18",
    "react-dom": "^18"
  },

Description

If you use the urlKeys option along with history: "push", then on pressing the browser back button, the query params get removed from the URL but the state variable returned by useQueryStates still shows the old value.

This issue does not occur if you remove urlKeys.

Reproduction

https://codesandbox.io/p/devbox/tender-paper-8sd759

Example: Steps to reproduce the behavior:

  1. Open the code sandbox
  2. Go to /working route to see the correct behvaior. The steps to perform are written there. This page does not use urlKeys hence it works well.
  3. Now go to the /not-working route to see the incorrect behavior that happens when you add urlKeys. The steps to perform are mentioned there.
@hallucinogenizer hallucinogenizer added the bug Something isn't working label Nov 12, 2024
@franky47
Copy link
Member

Thanks for this great report!

I can reproduce the error and I think I see where it's coming from, I'll have a fix out shortly.

franky47 added a commit that referenced this issue Nov 12, 2024
@franky47 franky47 added this to the 🪵 Backlog milestone Nov 12, 2024
@franky47
Copy link
Member

Could you try this and let me know if it solves the problem on your end?

pnpm add https://pkg.pr.new/nuqs@759

@hallucinogenizer
Copy link
Author

Yup, this fixes the problem in my codebase as well. Thanks!

Copy link

🎉 This issue has been resolved in version 2.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47 franky47 removed this from the 🚀 Shipping next milestone Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants