-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
No next/link prefetch and client-side navigation for rewritten routes with query parameters #35696
Comments
I am having the same issues but without a "catch-all route". When I hover over a link for rewritten routes, the JSON is prefetched and cached without the query parameters. When I click on the same link, the query parameters [path to the file] are added to the JSON, so it doesn't use the cached version and download the file again (200). Example: When I hover the link for /pages/[id]/[name] I get: When I click on the same link I get: If I don't use "rewrites", I get only a 200 status for HEAD and the file is not downloaded again. I am using version 12.2.5 |
I'm seeing this issue when using getStaticProps with rewrites. Nextjs use to pass in |
Nice catch. I hope they fix it soon. |
Prefetch doesn't have this problem because when I'm not sure what the best solution is. Maybe you could add that In that commit there are some changes in For the example of |
I have the same problem with auth redirects inside the middleware. The redirects are getting cached on prefetch and when you navigate to a cached url the entire website hangs. Sadly you cannot really turn off prefetching so you have to redesign everything in a way that a user cannot accidentally hover over a link that could lead to redirected urls... . That is really bad. Ideally the prefetch mechanism should honor the status codes in the responses. I tried with 403 for example but that in turn crashes the server. Any workaround? |
For anyone stumbling upon this. It is possible to disable the entire prefetching system which currently is the only way of using redirects in middleware if you are not using the app folder: |
This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you. |
This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding! |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
next start
Describe the Bug
If you have an optional catch-all route and use rewrites to convert query parameters into route parameters, links that have those query parameters don't automatically prefetch the props json even when the json is pregenerated at built time.
Expected Behavior
Prefetch and client-side navigation should work for links/routes with query params the same way as for any other internal link. No page reload, etc.
To Reproduce
I have prepared a minimal repository where the issue is reproduced. https://github.com/dklymenk/next-query-rewrite-router-issue
See my last commit to get the idea of what it takes to reproduce the issue starting from a clean template.
Here are some must-haves
[[...slug]]
to catch our potential parameters.getStaticPaths
andgetStaticProps
to enable SSG.next.config.js
to transform query params into route params/?s=query1
to/query1
, etc.yarn build
,yarn start
and go to localhost:3000.You can open dev tools on the network to see that there is no prefetch happening and if you click on any of the links with query params the page will reload (no client-side navigation).
Interestingly enough, if you remove the
/
on thehref
, the preload works (you can see json preloaded on network tab), but clicking on the link seems to load only theindex.json
(props for the case with no query params).The text was updated successfully, but these errors were encountered: