next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Hard Navigation for segments marked with dynamic="force-dynamic" or when using dynamic functions

Open Fredkiss3 opened this issue 3 years ago • 0 comments

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)/layout to (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 :

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() and cookies(), next should always do a hard navigation

  • When navigating to a page using fetch with cache: '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 fetch with next: { revalidate: n_seconds } or export const revalidate = n_seconds, next should only do hard navigation when the n_seconds has 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

Fredkiss3 avatar Nov 16 '22 14:11 Fredkiss3