Using `rewrites` in `next.config.js` causes double renders
See original GitHub issueRun next info
(available from version 12.0.8 and up)
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:29:10 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T8101
Binaries:
Node: 16.13.1
npm: 8.3.0
Yarn: 1.22.17
pnpm: 6.11.0
Relevant packages:
next: 12.0.8-canary.17
react: 17.0.2
react-dom: 17.0.2
What version of Next.js are you using?
12.0.7 and 12.0.8-canary.17 both reproduce
What version of Node.js are you using?
16.13.1
What browser are you using?
Chrome and Safari both reproduce
What operating system are you using?
macOS 12.1 (21C52)
How are you deploying your application?
Vercel, next dev
and next start
all reproduce
Describe the Bug
When a rewrites
function is specified in next.config.js
, every page renders twice in the browser, regardless of the nature of this function.
Expected Behavior
Specifying a rewrites
function does not cause double renders.
To Reproduce
- Clone
https://github.com/valerie-makes/nextjs-rewrites-bug
- Install dependencies:
npm install
- Build and start the app:
npm run build && npm start
- Visit the index page and observe the browser console:
rendering Home rendering Home
- Comment out the
rewrites
function innext.config.js
- Repeat Step 3 and Step 4:
rendering Home
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
NEXT JS - App is rendered twice with rewrites - Stack Overflow
I'm developing a NEXT JS project and can't find a solution for a twice rendering app! Problem. After adding rewrites to next.config.js ,...
Read more >App is rendered twice with rewrites #30720 - vercel/next.js
Hi, this is the expected behavior when rewrites are present as we parse them after hydration and trigger a query update to ensure...
Read more >Rewrites and _app rendering twice on load : r/nextjs - Reddit
I think _index / _ app js implements router / config and loads initial then router component checks for rewrites and updates and...
Read more >Rewrites - next.config.js
rewrites is an async function that expects to return either an array or an object of arrays (see below) holding objects with source...
Read more >Routing in Next.js – How to Set Up Dynamic Routing with Pre ...
This quick guide aims to help you manage fetching data, which can be used for pre-rendering purposes within dynamic routes in Next.js. We'll ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Submitted PR to update these details. 😃
Thank you for raising this issue. This is actually expected when you have a
rewrites
in your config and is vaguely hinted at in the docs here: https://nextjs.org/docs/advanced-features/automatic-static-optimizationSo what is happening in your code is that the page gets statically optimized at build time without query params.
Rewrites can have params that we need to provide in the query e.g.
/some/:path
so if anyrewrites
are present, we trigger a re-render iterating over the rewrites to provide the parsed params.We will try to make this more clear in the docs.