-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix _app global css import order #9836
Conversation
Stats from current PRDefault Server Mode (Increase detected
|
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
buildDuration | 13.9s | 13.8s | -96ms |
nodeModulesSize | 49 MB | 49 MB |
Client Bundles (main, webpack, commons)
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
main-HASH.js | 18.2 kB | 18.2 kB | ✓ |
main-HASH.js gzip | 6.44 kB | 6.44 kB | ✓ |
webpack-HASH.js | 1.53 kB | 1.53 kB | ✓ |
webpack-HASH.js gzip | 746 B | 746 B | ✓ |
4952ddcd88e7..1db6754d3.js | 12 kB | 12 kB | ✓ |
4952ddcd88e7..54d3.js gzip | 4.68 kB | 4.68 kB | ✓ |
commons.HASH.js | 10.9 kB | 10.9 kB | ✓ |
commons.HASH.js gzip | 4.06 kB | 4.06 kB | ✓ |
de003c3a9d30..17cdc0d60.js | 38.3 kB | 38.3 kB | ✓ |
de003c3a9d30..0d60.js gzip | 13.9 kB | 13.9 kB | ✓ |
framework.HASH.js | 126 kB | 126 kB | ✓ |
framework.HASH.js gzip | 39.5 kB | 39.5 kB | ✓ |
Overall change | 206 kB | 206 kB | ✓ |
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
main-HASH.module.js | 14.4 kB | 14.4 kB | ✓ |
main-HASH.module.js gzip | 5.42 kB | 5.42 kB | ✓ |
webpack-HASH.module.js | 1.53 kB | 1.53 kB | ✓ |
webpack-HASH..dule.js gzip | 746 B | 746 B | ✓ |
4952ddcd88e7..b9.module.js | 14.9 kB | 14.9 kB | ✓ |
4952ddcd88e7..dule.js gzip | 5.56 kB | 5.56 kB | ✓ |
de003c3a9d30..e3.module.js | 33.1 kB | 33.1 kB | ✓ |
de003c3a9d30..dule.js gzip | 12.5 kB | 12.5 kB | ✓ |
framework.HASH.module.js | 126 kB | 126 kB | ✓ |
framework.HA..dule.js gzip | 39.4 kB | 39.4 kB | ✓ |
Overall change | 189 kB | 189 kB | ✓ |
Legacy Client Bundles (polyfills)
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
polyfills-HASH.js | 15.3 kB | 15.3 kB | ✓ |
polyfills-HASH.js gzip | 4.76 kB | 4.76 kB | ✓ |
Overall change | 15.3 kB | 15.3 kB | ✓ |
Client Pages
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
_app.js | 2.94 kB | 2.94 kB | ✓ |
_app.js gzip | 1.33 kB | 1.33 kB | ✓ |
_error.js | 10.4 kB | 10.4 kB | ✓ |
_error.js gzip | 4.07 kB | 4.07 kB | ✓ |
hooks.js | 1.44 kB | 1.44 kB | ✓ |
hooks.js gzip | 779 B | 779 B | ✓ |
index.js | 318 B | 318 B | ✓ |
index.js gzip | 222 B | 222 B | ✓ |
link.js | 6.88 kB | 6.88 kB | ✓ |
link.js gzip | 2.93 kB | 2.93 kB | ✓ |
routerDirect.js | 411 B | 411 B | ✓ |
routerDirect.js gzip | 283 B | 283 B | ✓ |
withRouter.js | 421 B | 421 B | ✓ |
withRouter.js gzip | 282 B | 282 B | ✓ |
Overall change | 22.8 kB | 22.8 kB | ✓ |
Client Pages Modern
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
_app.module.js | 1.54 kB | 1.54 kB | ✓ |
_app.module.js gzip | 757 B | 757 B | ✓ |
_error.module.js | 7.35 kB | 7.35 kB | ✓ |
_error.module.js gzip | 3.06 kB | 3.06 kB | ✓ |
hooks.module.js | 651 B | 651 B | ✓ |
hooks.module.js gzip | 371 B | 371 B | ✓ |
index.module.js | 276 B | 276 B | ✓ |
index.module.js gzip | 212 B | 212 B | ✓ |
link.module.js | 5.54 kB | 5.54 kB | ✓ |
link.module.js gzip | 2.49 kB | 2.49 kB | ✓ |
routerDirect.module.js | 383 B | 383 B | ✓ |
routerDirect..dule.js gzip | 273 B | 273 B | ✓ |
withRouter.module.js | 394 B | 394 B | ✓ |
withRouter.m..dule.js gzip | 272 B | 272 B | ✓ |
Overall change | 16.1 kB | 16.1 kB | ✓ |
Client Build Manifests
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
_buildManifest.js | 81 B | 81 B | ✓ |
_buildManifest.js gzip | 61 B | 61 B | ✓ |
_buildManifest.module.js | 81 B | 81 B | ✓ |
_buildManife..dule.js gzip | 61 B | 61 B | ✓ |
Overall change | 162 B | 162 B | ✓ |
Rendered Page Sizes
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
index.html | 4.06 kB | 4.06 kB | ✓ |
index.html gzip | 1.03 kB | 1.04 kB | |
link.html | 4.11 kB | 4.11 kB | ✓ |
link.html gzip | 1.04 kB | 1.05 kB | |
withRouter.html | 4.12 kB | 4.12 kB | ✓ |
withRouter.html gzip | 1.03 kB | 1.03 kB | ✓ |
Overall change | 12.3 kB | 12.3 kB | ✓ |
Serverless Mode (Increase detected ⚠️ )
General Overall increase ⚠️
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
buildDuration | 14.1s | 14.1s | -16ms |
nodeModulesSize | 49 MB | 49 MB |
Client Bundles (main, webpack, commons)
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
main-HASH.js | 18.2 kB | 18.2 kB | ✓ |
main-HASH.js gzip | 6.44 kB | 6.44 kB | ✓ |
webpack-HASH.js | 1.53 kB | 1.53 kB | ✓ |
webpack-HASH.js gzip | 746 B | 746 B | ✓ |
4952ddcd88e7..1db6754d3.js | 12 kB | 12 kB | ✓ |
4952ddcd88e7..54d3.js gzip | 4.68 kB | 4.68 kB | ✓ |
commons.HASH.js | 10.9 kB | 10.9 kB | ✓ |
commons.HASH.js gzip | 4.06 kB | 4.06 kB | ✓ |
de003c3a9d30..17cdc0d60.js | 38.3 kB | 38.3 kB | ✓ |
de003c3a9d30..0d60.js gzip | 13.9 kB | 13.9 kB | ✓ |
framework.HASH.js | 126 kB | 126 kB | ✓ |
framework.HASH.js gzip | 39.5 kB | 39.5 kB | ✓ |
Overall change | 206 kB | 206 kB | ✓ |
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
main-HASH.module.js | 14.4 kB | 14.4 kB | ✓ |
main-HASH.module.js gzip | 5.42 kB | 5.42 kB | ✓ |
webpack-HASH.module.js | 1.53 kB | 1.53 kB | ✓ |
webpack-HASH..dule.js gzip | 746 B | 746 B | ✓ |
4952ddcd88e7..b9.module.js | 14.9 kB | 14.9 kB | ✓ |
4952ddcd88e7..dule.js gzip | 5.56 kB | 5.56 kB | ✓ |
de003c3a9d30..e3.module.js | 33.1 kB | 33.1 kB | ✓ |
de003c3a9d30..dule.js gzip | 12.5 kB | 12.5 kB | ✓ |
framework.HASH.module.js | 126 kB | 126 kB | ✓ |
framework.HA..dule.js gzip | 39.4 kB | 39.4 kB | ✓ |
Overall change | 189 kB | 189 kB | ✓ |
Legacy Client Bundles (polyfills)
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
polyfills-HASH.js | 15.3 kB | 15.3 kB | ✓ |
polyfills-HASH.js gzip | 4.76 kB | 4.76 kB | ✓ |
Overall change | 15.3 kB | 15.3 kB | ✓ |
Client Pages
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
_app.js | 2.94 kB | 2.94 kB | ✓ |
_app.js gzip | 1.33 kB | 1.33 kB | ✓ |
_error.js | 10.4 kB | 10.4 kB | ✓ |
_error.js gzip | 4.07 kB | 4.07 kB | ✓ |
hooks.js | 1.44 kB | 1.44 kB | ✓ |
hooks.js gzip | 779 B | 779 B | ✓ |
index.js | 318 B | 318 B | ✓ |
index.js gzip | 222 B | 222 B | ✓ |
link.js | 6.88 kB | 6.88 kB | ✓ |
link.js gzip | 2.93 kB | 2.93 kB | ✓ |
routerDirect.js | 411 B | 411 B | ✓ |
routerDirect.js gzip | 283 B | 283 B | ✓ |
withRouter.js | 421 B | 421 B | ✓ |
withRouter.js gzip | 282 B | 282 B | ✓ |
Overall change | 22.8 kB | 22.8 kB | ✓ |
Client Pages Modern
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
_app.module.js | 1.54 kB | 1.54 kB | ✓ |
_app.module.js gzip | 757 B | 757 B | ✓ |
_error.module.js | 7.35 kB | 7.35 kB | ✓ |
_error.module.js gzip | 3.06 kB | 3.06 kB | ✓ |
hooks.module.js | 651 B | 651 B | ✓ |
hooks.module.js gzip | 371 B | 371 B | ✓ |
index.module.js | 276 B | 276 B | ✓ |
index.module.js gzip | 212 B | 212 B | ✓ |
link.module.js | 5.54 kB | 5.54 kB | ✓ |
link.module.js gzip | 2.49 kB | 2.49 kB | ✓ |
routerDirect.module.js | 383 B | 383 B | ✓ |
routerDirect..dule.js gzip | 273 B | 273 B | ✓ |
withRouter.module.js | 394 B | 394 B | ✓ |
withRouter.m..dule.js gzip | 272 B | 272 B | ✓ |
Overall change | 16.1 kB | 16.1 kB | ✓ |
Client Build Manifests
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
_buildManifest.js | 81 B | 81 B | ✓ |
_buildManifest.js gzip | 61 B | 61 B | ✓ |
_buildManifest.module.js | 81 B | 81 B | ✓ |
_buildManife..dule.js gzip | 61 B | 61 B | ✓ |
Overall change | 162 B | 162 B | ✓ |
Serverless bundles
zeit/next.js canary | IgorCRD/next.js import-order | Change | |
---|---|---|---|
_error.js | 299 kB | 299 kB | ✓ |
_error.js gzip | 78.8 kB | 78.8 kB | -3 B |
hooks.html | 4.19 kB | 4.19 kB | ✓ |
hooks.html gzip | 1.07 kB | 1.07 kB | |
index.js | 299 kB | 299 kB | ✓ |
index.js gzip | 79.1 kB | 79.1 kB | -3 B |
link.js | 306 kB | 306 kB | ✓ |
link.js gzip | 81.1 kB | 81.1 kB | -2 B |
routerDirect.js | 299 kB | 299 kB | ✓ |
routerDirect.js gzip | 79.1 kB | 79.1 kB | -2 B |
withRouter.js | 299 kB | 299 kB | ✓ |
withRouter.js gzip | 79.3 kB | 79.3 kB | -3 B |
Overall change | 1.51 MB | 1.51 MB | ✓ |
Commit: 35fa510
@@ -64,6 +64,8 @@ export async function loadComponents( | |||
const DocumentMod = require(documentPath) | |||
const { middleware: DocumentMiddleware } = DocumentMod | |||
|
|||
const AppMode = require(appPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is server-side only code so I'm guessing it doesn't need changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Timer,
You are right, this change is not needed to fix the css issue I described above, but since the import/require order can affect side effects started on root components I thought it was a good idea to change the import order on this point as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK -- we need to add tests for both of these modified behaviors then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Timer,
pushed tests for these new beheaviors.
Blocking this as I want to do a thorough review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocked as said
35fa510
to
d49e892
Compare
Stats from current PRDefault Server Mode (Decrease detected ✓)General Overall decrease ✓
Client Bundles (main, webpack, commons)
Client Bundles (main, webpack, commons) Modern
Legacy Client Bundles (polyfills)
Client Pages
Client Pages Modern
Client Build Manifests
Rendered Page Sizes
Serverless Mode (Decrease detected ✓)General Overall decrease ✓
Client Bundles (main, webpack, commons)
Client Bundles (main, webpack, commons) Modern
Legacy Client Bundles (polyfills)
Client Pages
Client Pages Modern
Client Build Manifests
Serverless bundles
Commit: d49e892 |
Stats from current PRDefault Server Mode (Decrease detected ✓)General Overall decrease ✓
Client Bundles (main, webpack, commons)
Client Bundles (main, webpack, commons) Modern
Legacy Client Bundles (polyfills)
Client Pages
Client Pages Modern
Client Build Manifests
Rendered Page Sizes
Serverless Mode (Decrease detected ✓)General Overall decrease ✓
Client Bundles (main, webpack, commons)
Client Bundles (main, webpack, commons) Modern
Legacy Client Bundles (polyfills)
Client Pages
Client Pages Modern
Client Build Manifests
Serverless bundles
Commit: d297ba2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes seem okay, but I'm pretty sure this will break in a percentage of user applications and the reasoning behind the change is to fit to making css imports work which is something Next.js will cover by default very soon: #8626. So I'm not sure if it's worth changing these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidentally clicked approve.
@timneutkens, About if it is worth the change, I feel like this is an unintended implicit API that users expect it to work in a way it doesn't and I think it will keep causing issues to pop up because of that. It might also be the cause of unintended breaking changes because there are no tests asserting the order in which chunks are attached to the doom and also no tests to assert in which order root components and pages are imported, this affects side effects which are the other use case this PR intendeds to fix. Sorry for not mentioning it in the original description, I commented about it to Timer here #9836 (review). |
We’re not planning on doing a major version in the short term, i don’t mind keeping this pr open though. Furthermore React components shouldn’t have side effects outside of the React lifecycle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this again it actually isn't really breaking and will work fine.
Hello,
First of all, thanks for all the work you all have put into nextjs, I and my team really appreciate it.
We have recently configured our project to import css files directly from their respective react components and also got css splitting working.
The only problem we have is when importing global/third-party css. We import them in our custom _app file, but the split page css keeps getting added to page head before our global/third-party css. This causes our third-party customizations to be overwritten by their original styles.
After debugging and examining nextjs code I have found two points where, it seems, "root" components (like _document and _app) are imported after the page component and that's causing their chunks to be added after the page chunks, causing the problems I described above.
As custom _app and _document are supposed to act as root components for our nextjs apps, nextjs users expect that those components and their dependencies to be imported first. I say that based on
vercel/next-plugins#399
https://spectrum.chat/next-js/general/control-the-placement-of-styles-chunk-css-in-nextjs7~0d91eec7-6a38-4943-98f6-0bb3a71d50f6
and a few other cases I found while looking for a solution for this.
We are currently using a custom extended HEAD component that reorder our css files attaching first our global styles as a workaround (not pretty at all xD).
The changes in this PR fix the issue.