Hard Navigation for segments marked with dynamic="force-dynamic" or when using dynamic functions
Describe the feature you'd like to request
In the documentation it is said that the conditions for hard navigation are :
- when navigating between dynamic segments
- When navigating between two different group layouts (ex: from
(groupA)/layoutto(groupB)/layout)
I'd like to suggest also adding hard navigation for segments marked with dynamic='force-dynamic' or when using dynamic functions and even when using fetch with cache: 'no-store'.
In the docs you said that using these configurations is like using getServerSideProps() in the pages directory, but it does not behave the same between navigations which is quite confusing.
Use cases for this feature could be these :
- this app that only store pokemon data in cookies (Live here and source here)
- this simple case for an app that generate a random number each time : ckblitz.com/edit/nextjs-sxijav?file=package.json,app%2Fnested%2Fpage.tsx
Describe the solution you'd like
The solution i propose is to consider hard navigation for these cases :
-
When navigating to a page marked with
dynamic='force-dynamic', next should always do a hard navigation -
When navigating to a page using dynamic functions
headers()andcookies(), next should always do a hard navigation -
When navigating to a page using
fetchwithcache: 'no-store', next should always do a hard navigation, or at least next should always refetch the data -
When navigating to a page using either
fetchwithnext: { revalidate: n_seconds }orexport const revalidate = n_seconds, next should only do hard navigation when then_secondshas elapsed.
The last two could be tricky and if it is not ideal, at least add a paragraph in the doc explaining why it is not possible and maybe recommending the first two approaches.
Describe alternatives you've considered
Right now i find a workaround by using dynamic segments and throwing a notFound() call to fix the page to only one route : https://stackblitz.com/edit/nextjs-51tdbm?file=app%2F[any]%2Fpage.tsx