question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Next 13] - Multiple versions of React is shipped. One page has 2x the bundle size without any libraries.

See original GitHub issue

Verify 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

  1. Git clone
  2. pnpm install
  3. next build
  4. Observe /dashboard/users has double the size despite not needing it.
  5. Run ANALYZE=true next build and observe the chunk shipped with code identical to main-... with some exceptions in the Next runtime.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:9
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

8reactions
alexparishcommented, Oct 30, 2022

I upgraded to v13.0.1-canary.1 since it was just published and, although I am now only seeing react-dom once, I am still seeing multiple versions of react being bundled when using the app directory and running npm run build

Happy to create a new issue for this, if required.

Screenshot 2022-10-30 at 13 19 57

Total JS transferred

v13.0.0: 90kB gzipped / 272kB minified

Screenshot 2022-10-30 at 13 25 32

v13.0.1-canary.1: 78kB gzipped / 234kB minified

Screenshot 2022-10-30 at 13 25 11
7reactions
timneutkenscommented, Nov 1, 2022

That’s the main bundle for pages, it’s still built currently because the default 404 page doesn’t use the component defined in app yet (it’s on the list of things to implement).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found