[Next 13] - Multiple versions of React is shipped. One page has 2x the bundle size without any libraries.
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.6.0: Sat Jun 18 17:05:47 PDT 2022; root:xnu-8020.140.41~1/RELEASE_ARM64_T8101
Binaries:
Node: 18.10.0
npm: 8.19.2
Yarn: 1.22.17
pnpm: 7.5.0
Relevant packages:
next: 13.0.0
eslint-config-next: 13.0.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Chrome 106.0.5249.119
How are you deploying your application? (if relevant)
next start
Describe the Bug
When building my app this is the result:
Route (app) Size First Load JS
┌ ○ / 0 B 0 B
├ ○ /dashboard 105 B 66.6 kB
├ ○ /dashboard/users 186 B 141 kB // What is going on here?
└ λ /dashboard/users/[id] 4.59 kB 75.7 kB
+ First Load JS shared by all 66.5 kB
├ chunks/main-app-fd902262245ffaed.js 64.5 kB
└ chunks/webpack-8876bb8973ebf277.js 2.07 kB
Route (pages) Size First Load JS
─ ○ /404 179 B 79.8 kB
+ First Load JS shared by all 79.6 kB
├ chunks/main-d4cdf33ec41ad030.js 77.3 kB
├ chunks/pages/_app-4e5b418629f6f9e0.js 193 B
└ chunks/webpack-8876bb8973ebf277.js 2.07 kB
It appears that Next is bundling 2 instances of React for the endpoint /dashboard/users
. This has resulted in a 2x bundle increase on this particular page, and I cannot seem to figure out why.
I’ve fired up the bundle analyzer and see that a specific chunk includes both next.js and react + react-dom, and its not the main bundle.
I have attempted running with swcMinify
& without. Same result.
Expected Behavior
Dual versions of React should not be shipped randomly on a page.
Link to reproduction
https://github.com/sannajammeh/next-13-dual-react
To Reproduce
- Git clone
- pnpm install
- next build
- Observe /dashboard/users has double the size despite not needing it.
- Run
ANALYZE=true next build
and observe the chunk shipped with code identical tomain-...
with some exceptions in the Next runtime.
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Hooks + multiple instances of React · Issue #13991 - GitHub
I had multiple instances of React by mistake. When trying to use hooks, got this error: hooks can only be called inside the...
Read more >How to Reduce Next.js Bundle Size | NE Digital - Medium
If we can reduce the amount of js we ship, then those smaller scripts can be ... Check if a library showing up...
Read more >React v18.0 – React Blog
It's a new behind-the-scenes mechanism that enables React to prepare multiple versions of your UI at the same time.
Read more >Solve having more than one copy of React in the same app
In the module you are developing, add the conflicting packages to peerDependencies (and remove them from dependencies or devDependencies ):
Read more >Firebase Android SDK Release Notes
The latest Firebase BoM version contains the latest versions of each Firebase Android library. To learn which library versions are mapped to a...
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 Free
Top 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
I upgraded to
v13.0.1-canary.1
since it was just published and, although I am now only seeingreact-dom
once, I am still seeing multiple versions ofreact
being bundled when using the app directory and runningnpm run build
Happy to create a new issue for this, if required.
Total JS transferred
v13.0.0: 90kB gzipped / 272kB minified
v13.0.1-canary.1: 78kB gzipped / 234kB minified
That’s the main bundle for
pages
, it’s still built currently because the default 404 page doesn’t use the component defined inapp
yet (it’s on the list of things to implement).