Skip to content

fix(css): read the live root in the OnceExit url rewriter (fix #23348) - #23349

Closed
lazerg wants to merge 1 commit into
vitejs:mainfrom
lazerg:fix/css-oncexit-stale-root
Closed

fix(css): read the live root in the OnceExit url rewriter (fix #23348)#23349
lazerg wants to merge 1 commit into
vitejs:mainfrom
lazerg:fix/css-oncexit-stale-root

Conversation

@lazerg

@lazerg lazerg commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Vite 8.2.2 moved the built-in CSS url rewriter from a Once visitor to OnceExit (#22983), so it can see content injected by other plugins' own OnceExit hooks. That works fine for plugins that mutate the existing root in place, but breaks for plugins that reassign result.root outright, which is what postcss-lightningcss does.

PostCSS's OnceExit dispatch loop captures root once, before any OnceExit hook runs, and passes that same reference to every plugin registered for the event. If an earlier plugin sets result.root to a brand new tree instead of mutating the node it was handed, later OnceExit hooks still get the stale, pre-reassignment root as their argument, even though result.root has already moved on. Our rewriter is registered last so it runs after plugins like postcss-lightningcss, walks that stale root, and rewrites urls on a tree that never makes it into the final output.

This reads result.root instead of trusting the root argument, since helpers.result is 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 replaces result.root, alongside the existing OnceExit-injection test.

Fixes #23348

@github-actions github-actions Bot added the bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR label Aug 24, 2026
@github-actions

Copy link
Copy Markdown
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.

@github-actions github-actions Bot closed this Aug 24, 2026
@lazerg

lazerg commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

🤦🏻

@lazerg

lazerg commented Aug 24, 2026

Copy link
Copy Markdown
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?

@sapphi-red sapphi-red added bot: skip Skip AgentScan analysis bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR and removed bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR bot: skip Skip AgentScan analysis labels Aug 27, 2026
@sapphi-red

Copy link
Copy Markdown
Member

I tried to re-open, but failed because the repo is deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vite 8.2.x leaves CSS asset URLs stale after PostCSS transforms

2 participants