-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Prefetch for links not working as expected with App Router #47981
Comments
I can reproduce the issue, prefetch does not seem to work |
I believe this behavior is because you're triggering a hard navigation when navigating to If you look at the hard vs. soft navigation docs, a route including dynamic segments isn't eligible for a soft navigation (unless it has the same dynamic segments as the current route). During a hard navigation, "the cache is invalidated and the server refetches data and re-renders the changed segments.". So it's prefetching when the link is displayed, but when you navigate, the cache is cleared and the data is refetched from the server. I'm running into the same issue: is it not possible to prefetch a dynamic page and use that data rather than making another request when you navigate? What's the point in even prefetching in this case? |
I think this PR that just landed in canary will allow for prefetching of dynamic pages... 🤞 |
what does the actual route definition look like for your case? is blog/projects a dynamic segment? If so, it would still be a hard navigation since it doesn't meet the conditions for a soft navigation, regardless if you're using |
@m1yon No, only the language ("en") is a dynamic segment. Like that:
|
@dlehmhus @m1yon Actually, I hade a mistake in my layout. It has to be nested below the [lang] folder. Additionally you have to generate the static params (generateStaticParams()). With that, it worked for me, I think, starting 13.3.2-canary-8, but definetly now, 13.3.2 |
An update on that. Dynamic routes actually work, you just either have to pregenerate them or |
@johannesschaffer I don't think the static part is needed for the prefetch to work! The important part is that the explicitly set |
@dlehmhus Thanks for the tip. I think it's however still worth mentioning, that you can get full prefetch without specifying prefetch={true} by just setting dynamic=error on the dynamic page. Doesn't involve as much rewriting. |
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. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 Binaries: Node: 18.15.0 npm: 9.5.0 Yarn: 1.22.19 pnpm: 7.3.0 Relevant packages: next: 13.2.5-canary.30 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue
https://github.com/dlehmhus/next-link-preload-example
To Reproduce
Click on any link.
link-prefetch-example.mov
Describe the Bug
When using the next link component with prefetch enabled, not all data is actually prefetch.
Expected Behavior
All relevant page data should be prefetched.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: