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

Router loses query params after push() with a dynamic route #26508

Closed
alecrae opened this issue Jun 23, 2021 · 5 comments · Fixed by #29246
Closed

Router loses query params after push() with a dynamic route #26508

alecrae opened this issue Jun 23, 2021 · 5 comments · Fixed by #29246
Labels
bug Issue was opened via the bug report template.

Comments

@alecrae
Copy link

alecrae commented Jun 23, 2021

What version of Next.js are you using?

11.0.1

What version of Node.js are you using?

14.17.0

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Local build

Describe the Bug

I think I have found a router regression. When calling router.push with a dynamic route, any query string values are lost on the new route if the asPath value doesn't have those query string values. This was working in 10.1.3 and i think it broke around 10.2.x. Something like:

router.push({
  pathname: "/something/new",
  query: {param: "value"}},
"/something/new")

where there is a [catchall]/new.js page. See the reproduction repo below.

Expected Behavior

Query parameters should be accessible with dynamic routes when asPath doesn't contain the query params

To Reproduce

Clone and run https://github.com/alecrae/nextjs-router-query-missing
Go to the index page and then on load it will execute a router.push to a new page, the query params is missing. Downgrade the next version to 10.1.3 and it will work

@alecrae alecrae added the bug Issue was opened via the bug report template. label Jun 23, 2021
@timneutkens
Copy link
Member

This is the API for router.push:

router.push(internalPath, shownPath)

Sounds more like we fixed a bug where query was incorrectly appended to the shown path in the newer versions 🤔 cc @ijjk

@vlad-zhukov
Copy link

We've also encountered a serious regression after upgrading Next.js from v10.2.0 to any higher, including 11.0.x. I was able to track the problem down, it was introduced in #25112.

I've created a better reproduction case: https://github.com/vlad-zhukov/nextjs-router-query-missing

The index page works as expected, clicking the button shallowly changes query params. Now got to /any page and click the button. The following error occurs

Screen Shot 2021-06-26 at 18 11 58

and page reloads, __HIDDEN=true is obviously missing.

@ijjk
Copy link
Member

ijjk commented Sep 21, 2021

Closing as a duplicate of #26169

@ijjk ijjk closed this as completed Sep 21, 2021
@ijjk
Copy link
Member

ijjk commented Sep 21, 2021

Hi, this has been updated in v11.1.3-canary.29 of Next.js, please update and give it a try!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants