Set up a multi-tenant/domain Next.js pages router app, borrowing the architecture from the Vercel Platforms Starter Kit example
Introduce new views using the app router
Try to navigate between views that use the pages router app
Current vs. Expected behavior
Navigating between two pages that share the same layout (whether using the app router or pages router) should not cause a full re-render of the page (exemplified in the repro with an artificial delay to render the navigation component).
Navigating between app router views (i.e. /a and /b) always works as expected, however navigating within pages router views (i.e. /x and /y) consistently causes a full re-render in one of the following circumstances:
The app/ folder is present (try deleting/renaming it and the problem disappears)
A middleware is used to rewrite the pathname (try disabling the middleware and the problem disappears too)
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
Available memory (MB): 32768
Available CPU cores: 10
Binaries:
Node: 20.12.0
npm: 10.5.0
Yarn: 1.22.21
pnpm: 8.5.1
Relevant Packages:
next: 14.2.2 // Latest available version is detected (14.2.2).
eslint-config-next: 14.2.2
react: 18.2.0
react-dom: 18.2.0
typescript: 5.4.5
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Middleware, Pages Router
Which stage(s) are affected? (Select all that apply)
next dev (local), Vercel (Deployed)
Additional context
This has been a blocking issue for as long as I can remember and prevents us from gradually migrating a multi-tenant Next.js app and start using app router.
Link to the code that reproduces this issue
https://github.com/raphaelsaunier/nextjs-pages-router-app-router-middleware-repro
To Reproduce
Current vs. Expected behavior
Navigating between two pages that share the same layout (whether using the app router or pages router) should not cause a full re-render of the page (exemplified in the repro with an artificial delay to render the navigation component).
Navigating between app router views (i.e.
/a
and/b
) always works as expected, however navigating within pages router views (i.e./x
and/y
) consistently causes a full re-render in one of the following circumstances:app/
folder is present (try deleting/renaming it and the problem disappears)Provide environment information
Which area(s) are affected? (Select all that apply)
Middleware, Pages Router
Which stage(s) are affected? (Select all that apply)
next dev (local), Vercel (Deployed)
Additional context
This has been a blocking issue for as long as I can remember and prevents us from gradually migrating a multi-tenant Next.js app and start using app router.