-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
App Dir is caching renders even with "dynamic" set to "force-dynamic" #42546
Comments
Manually setting |
It is because of soft navigation, with the new layouts nextjs does soft navigation by default, when your page has not been rendered already and the user navigates to it with a link component, it does not rerender the page each time. What the nextjs team said is that your page should rerender if you do a mutation with their upcoming mutation, or if you call It is a PIA i think because the mental model of dynamic pages is that it should rerender each time you go to them. Update : I tried to disable prefetching of links to force rerendering but it disables client side page navigation, im gonna open an issue for this |
From the docs link above:
So not only a PITA, it doesn't work when data is dynamic but not dynamic based on route params (i.e. data that changes frequently, or data that changes based on current user / http headers). How are we supposed to force hard navigation in these cases? Rather than adding more exceptions to the rules of when Next.js will use soft vs hard navigation, I would rather see it simplified. |
It does feel misleading that a "force-dynamic" page will still use a soft render. There should be some place in the docs suggesting something like... useState(() => router.refresh()) Or some other way to have this run on the first render only. I don't think this is very elegant. |
There is a problem though : it causes hydration mismatches, as you can see in the screenshot below : And what about data fetching ? And wether i add a |
@gfortaine , the solution you’re suggesting is to use the |
Yes
Still one odd thing I noticed is that it still does at least 3 or 4 fetches (which is isn’t supposed to be the case, right ?) But it fetches once in the server and 3 or 4 more in the client. |
According to the following comment, it seems that one should create a new root layout ( |
@gfortaine I've put up an example with that in mind : https://stackblitz.com/edit/nextjs-wxc4fy I still think this is not good enough, and they should this fix... or at least indicate in the doc a way around this. |
What is weird, is that when using a dynamic route segment, a hard navigation always occurs : https://stackblitz.com/edit/nextjs-51tdbm?file=app%2F[any]%2Fpage.tsx I think this is indeed a bug |
@Fredkiss3 Just pointing out that this is the documented behavior. See https://beta.nextjs.org/docs/routing/linking-and-navigating#soft-navigation :
Of course there's still an issue with this documented behavior.. |
Closing in favor of #42991 |
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: linux
Arch: x64
Version: #14 SMP Sat Jun 4 00:16:10 CEST 2022
Binaries:
Node: 16.17.0
npm: 8.15.0
Yarn: 1.22.19
pnpm: 7.1.0
Relevant packages:
next: 13.0.2
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
next start
Describe the Bug
When clicking on to go to a page that has "dynamic" segment config set to "force-dynamic" the page still uses a cached render from a previous visit.
Expected Behavior
The "force-dynamic" config should make the page render again each time you visit the page through or any other client side transition.
Link to reproduction
https://stackblitz.com/edit/nextjs-sxijav?file=package.json,app%2Fnested%2Fpage.tsx
To Reproduce
The text was updated successfully, but these errors were encountered: