Repository navigation
fix(worker): keep chunks conflicted with unused workers that are still used by a live worker - #23956
Merged
sapphi-red merged 2 commits intoNov 5, 2026
Merged
Conversation
sapphi-red
approved these changes
Nov 5, 2026
This was referenced Nov 5, 2026
Merged
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.
fixes #23894
So here's the bug: if the module that starts a nested worker gets tree-shaken out of the main bundle, but another worker still uses it, the outer worker ends up pointing at the nested worker's file, and that file just isn't there.
What happens is the main build sees the
new Worker(new URL(...))call and emits the nested worker early (generateEntryUrlExpr). ThengenerateBundlesees the module got tree-shaken, decides the worker is dead, and deletes it. Then it realises the worker is actually still needed and tries to emit it again, but Rolldown ignores a secondemitFilefor the same file. So it's gone.The fix: figure out what's still live first, and don't delete anything that's still used through another worker. Nothing that's still needed gets deleted, so nothing needs re-adding.
For the test, the main page imports a module without using it, and a live worker uses that same module to start a nested worker. The test checks the nested worker's file exists. It fails without the fix and passes with it. A nested worker nobody uses still gets removed like before. I also ran the worker playground in dev, build and bundled-dev modes, plus the
packages/viteunit tests.I thought about ripping out the whole emit-early-then-delete thing, but kept the change small instead. One thing to look at: the same cleanup runs inside worker sub-builds, so those now keep live nested workers too.
There was an earlier PR for this, #23899, but its author closed it to cut down on open PRs. It takes a similar approach, keeping still-live workers in both main and worker builds.
AI usage: Claude Code helped me with testing and information gathering. I built the issue's repro with and without the fix and checked that the nested worker was referenced but missing before, and emitted after.