Next.js: Code splitting treats _app.js like any other page

Created on 5 Sep 2019  路  2Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Given the following pages/ folder:

  • _app.js
  • index.js
  • page2.js
  • page3.js

If only _app.js and index.js import the same module (call it module X), webpack will include module X in both _app.js and index.js's bundles.

This leads to larger bundles than necessary. For example, when visiting the index at localhost:3000/, both _app.js and index.js are downloaded, and both contain a copy of module X.

Note that module X will be moved to commons.js if > 50% of pages use it.

To Reproduce

  1. Clone this repo https://github.com/WestonThayer/bug-nextjs-app-codesplitting
  2. yarn build

Notice how in the client bundle @sentry is included in both _app.js and index.js.

Expected behavior

I would expect any module in _app.js to either be extracted to the commons.js bundle or remain in _app.js, but excluded from any page that also requires it.

Screenshots

Screenshot of the client bundle analysis

Most helpful comment

Thanks, looking forward to the next release!

All 2 comments

Thanks, looking forward to the next release!

Was this page helpful?
0 / 5 - 0 ratings