When Page A is requested, as expected both /[locale]/layout.js and /[locale]/a/page.js are rendered.
However, when Page B/C/D are requested /[locale]/layout.js is rendered again each time, despite all pages being under the same route segment.
This only happens the first time the pages are requested. Subsequent requests to a previously loaded page, performs as expected and only renders the page and not the layout again. This can be seen in step (6) when Page A is revisited.
It should be noted that two condition appear to be required for the bug to occur:
On the Link component prefetch={false}. Setting prefetch={true} seems to resolve it but this is not suitable for our project.
The middleware rewrites the browser URL. For example, when explicitly including the locale in the browser URL e.g. /fr/a then the issue does not occur. However, this would mean we cannot support a default locale URL
Expected Behavior
Page A/B/C/D are all under the same route segment and share the same layout. Therefore /[locale]/layout.js should only be rendered with the first page request and not subsequent ones.
Particularly as out layouts require API fetches, it can slow down page transitions.
Which browser are you using? (if relevant)
Chrome latest
How are you deploying your application? (if relevant)
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router
Link to the code that reproduces this issue or a replay of the bug
https://github.com/p00000001/next-routing-issue
To Reproduce
/[locale]/*
to support different languages.Describe the Bug
The layout and all pages are located under the same route segment:
/[locale]/layout.js
/[locale]/a/page.js
/[locale]/b/page.js
/[locale]/c/page.js
/[locale]/d/page.js
When Page A is requested, as expected both
/[locale]/layout.js
and/[locale]/a/page.js
are rendered.However, when Page B/C/D are requested
/[locale]/layout.js
is rendered again each time, despite all pages being under the same route segment.This only happens the first time the pages are requested. Subsequent requests to a previously loaded page, performs as expected and only renders the page and not the layout again. This can be seen in step (6) when Page A is revisited.
It should be noted that two condition appear to be required for the bug to occur:
Link
componentprefetch={false}
. Settingprefetch={true}
seems to resolve it but this is not suitable for our project./fr/a
then the issue does not occur. However, this would mean we cannot support a default locale URLExpected Behavior
Page A/B/C/D are all under the same route segment and share the same layout. Therefore
/[locale]/layout.js
should only be rendered with the first page request and not subsequent ones.Particularly as out layouts require API fetches, it can slow down page transitions.
Which browser are you using? (if relevant)
Chrome latest
How are you deploying your application? (if relevant)
Next start