fix(css): rewrite urls in OnceExit-injected content#22983
Open
soreavis wants to merge 1 commit into
Open
Conversation
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.
Description
UrlRewritePostcssPluginruns atOnce, but postcss-modules prepends the CSS ofcomposesdependencies atOnceExit— after the rewriter has already walked the tree. Content injected that late is never visited, so itsurl()references are left untransformed. The same applies to any user postcss plugin that injects content in itsOnceExit; the comment above the plugin's registration already says it is added "because we don't know the content injected by those plugins", but injected-at-OnceExitcontent was still missed.This moves the rewriter to
OnceExit. It is registered last in the plugin array, so its hook runs after every other plugin'sOnceExitand sees all injected content. The rewriter already resolves each declaration againstdeclaration.source.input.file, so injected nodes that carry a source are rebased against the file they actually came from. Added a regression test with a plugin that injects aurl()declaration atOnceExit.Part of #15410 — the composed-CSS-module case additionally needs madyankin/postcss-modules#173 (prepended nodes currently carry no source), so this PR deliberately does not close that issue. One behavior note: url rewriting now happens at the end of the postcss pipeline instead of the start, so a plugin whose own
OnceExitexpected already-rewritten urls would now see raw ones — the new timing is the correct one for injection.