fix(css): rewrite MiniCssExtractPlugin insert function to ES5 to support legacy browsers#90556
Open
sleitor wants to merge 1 commit intovercel:canaryfrom
Open
fix(css): rewrite MiniCssExtractPlugin insert function to ES5 to support legacy browsers#90556sleitor wants to merge 1 commit intovercel:canaryfrom
sleitor wants to merge 1 commit intovercel:canaryfrom
Conversation
The mini-css-extract-plugin insert() option accepts a function which is
serialized via Function#toString() and injected directly into the browser
runtime bundle. This string bypass all subsequent transpilation steps.
Previously the function used:
- const destructuring: const { href, onload, onerror } = linkTag
- optional chaining: onload?.call(...)
Destructuring assignment is not supported before Chrome 49 / Firefox 47.
When a project targets legacy browsers (browserslist: chrome >= 45),
these pages crash with 'Unexpected token {' before any CSS is loaded.
Fix: use var declarations with individual property access, and replace
optional chaining with explicit null checks. Both are ES5-compatible and
produce identical runtime behavior in all environments.
Fixes vercel#90518
Collaborator
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Rewrite the
insertfunction passed toMiniCssExtractPlugininpackages/next/src/build/webpack/config/blocks/css/index.tsto use only ES5-compatible syntax.Why?
The
insertoption ofmini-css-extract-pluginserialises the function viaFunction#toString()and injects the resulting string directly into the webpack runtime chunk. This string bypasses all subsequent transpilation — it is not processed by Babel/SWC, and is not subject to the project'sbrowserslistoroutput.environmentwebpack config.The current function contains:
When the project targets legacy browsers (e.g.
chrome >= 45) pages crash on load with:before any CSS has been applied.
How?
Replace the destructuring with individual
vardeclarations and replace optional chaining with explicitifnull-checks:Before:
After:
Runtime behavior is identical in all environments. The
varstyle was intentionally chosen (over splittingconstdeclarations) sinceno-varis disabled in the project ESLint config.Fixes #90518