`query` not updating on `shallow` push when middleware is defined
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022 Binaries: Node: 14.18.1 npm: 6.14.15 Yarn: 1.22.17 pnpm: N/A Relevant packages: next: 12.2.2 eslint-config-next: N/A react: 17.0.2 react-dom: 17.0.2
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
In v12.2.2, when pushing a route using shallow: true
within a catchAll route and with a middleware defined, query
is not updated.
Say we’ve got the /pages/[...catalog].tsx
page, we are on /shoes
and we want to go to /shoes/black
.
// /middleware.ts
export function middleware() {}
// /pages/[...catalog].tsx
const CatalogPage = () => {
const { query, push } = useRouter();
return (
<>
<button
onClick={() => {
push("/[...catalog]", "/shoes/black", { shallow: true });
}}
>
Push
</button>
<pre>{JSON.stringify({ query }, null, 2)}</pre>
</>
);
};
When clicking the button, query
will not be updated regardless of the path changing.
Expected Behavior
It is expected that query
is updated after pushing the new route, as per the documentation.
Link to reproduction
https://codesandbox.io/s/cranky-burnell-295k32
To Reproduce
- After loading the Sandbox, click on the
Go to shoes
link. It should take you to/shoes
. There you can see the actual value forquery
, which should bequery.catalog = ["shoes"]
- Now click the
push
button, which will set the url to/shoes/black
. You’ll see that thequery
value stays the same, when it should’ve beenquery.catalog = ["shoes", "black"]
. - Reload the page from within the Sandbox browser, and you’ll see the correct expected value for
query
- Now change the
middleware.js
filename to something else like__middleware.js
, so it doesn’t get picked up by next. - Go back to
/shoes
- Click the
push
button again, and you’ll see that this time thequery
value gets correctly updated
Edit 1
It seems like regular dynamic routes are also affected by this issue. See the updated reproduction including regular dynamic routes.
In v12.2.2, when pushing a route using
shallow: true
within acatchAlldynamic route and with a middleware defined,query
is not updated.
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:6 (1 by maintainers)
Top GitHub Comments
Hi, this has been updated in
v12.2.4-canary.3
of Next.js, please update and give it a try!This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.