fix: use consistent CSS precedence for dynamic imports#84522
Open
TrevorBurnham wants to merge 1 commit into
Open
fix: use consistent CSS precedence for dynamic imports#84522TrevorBurnham wants to merge 1 commit into
TrevorBurnham wants to merge 1 commit into
Conversation
Member
|
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 |
1e98201 to
f8673aa
Compare
f8673aa to
7015b18
Compare
Changes the precedence value used for CSS from dynamic imports to match the precedence used for static imports, ensuring consistent CSS ordering in the App Router. Previously, CSS loaded via next/dynamic used precedence="dynamic" while CSS from static imports used precedence="next" (production) or precedence="next_<path>" (development). This inconsistency could lead to unpredictable CSS ordering when the same stylesheet was referenced through both code paths. Fixes vercel#42082
7015b18 to
5e1407e
Compare
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.
This PR fixes CSS ordering inconsistencies in the App Router by ensuring that CSS from dynamic imports (
next/dynamic) uses the same precedence values as CSS from static imports.Fixes #42082
Problem
When using
next/dynamicin the App Router, CSS files were being loaded with different React precedence attributes depending on how they were imported:precedence="next"(production) orprecedence="next_<path>"(development)precedence="dynamic"This inconsistency caused unpredictable CSS ordering, particularly when the same stylesheet was referenced through both static and dynamic import paths.
React's resource deduplication relies on matching
hrefattributes to prevent duplicate stylesheets, but different precedence values could lead to inconsistent ordering behavior.Solution
Modified
PreloadChunkscomponent inpreload-chunks.tsxto use the same precedence pattern asrenderCssResource:This ensures: