fix(css): read the live root in the OnceExit url rewriter (fix #23348) - #23349
Closed
lazerg wants to merge 1 commit into
Closed
fix(css): read the live root in the OnceExit url rewriter (fix #23348)#23349lazerg wants to merge 1 commit into
lazerg wants to merge 1 commit into
Conversation
Contributor
|
This PR has been automatically flagged as likely to be created by a bot, LLM, or agent, and will be automatically closed. These contributions harm the maintenance of the project. Please read our AI policy for more information. If you believe this is a mistake, please reply to this comment and we will review it. |
Contributor
Author
|
🤦🏻 |
Contributor
Author
|
Hi @sapphi-red, replying to the bot flag above since it asks for that if it's wrong. I'm a real person, not a bot account. This PR fixes a genuine regression in the OnceExit CSS url rewriter from #22983, with a repro and a test. Happy to answer any questions about the change if that helps confirm it. Could this get reopened? |
Member
|
I tried to re-open, but failed because the repo is deleted. |
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.
Vite 8.2.2 moved the built-in CSS url rewriter from a
Oncevisitor toOnceExit(#22983), so it can see content injected by other plugins' ownOnceExithooks. That works fine for plugins that mutate the existing root in place, but breaks for plugins that reassignresult.rootoutright, which is whatpostcss-lightningcssdoes.PostCSS's
OnceExitdispatch loop capturesrootonce, before anyOnceExithook runs, and passes that same reference to every plugin registered for the event. If an earlier plugin setsresult.rootto a brand new tree instead of mutating the node it was handed, laterOnceExithooks still get the stale, pre-reassignment root as their argument, even thoughresult.roothas already moved on. Our rewriter is registered last so it runs after plugins likepostcss-lightningcss, walks that stale root, and rewrites urls on a tree that never makes it into the final output.This reads
result.rootinstead of trusting therootargument, sincehelpers.resultis a live reference. postcss-modules still mutates the tree it's given, so the #22983 fix keeps working, and plugins that swap the whole tree are now covered too. Added a regression test modeled on a plugin that replacesresult.root, alongside the existing OnceExit-injection test.Fixes #23348