fix(plugin-legacy): group discovered polyfills by output #17347
Merged
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
Since merging #16566, it caused CI to be flaky as in Rollup watch mode, the
renderStart
andrenderChunk
hooks are all running overlapping due to Rollup writing each output in parallel: https://github.com/rollup/rollup/blob/1a7da5ac529d543ad8fffd1cdfbf9a80040a1176/src/watch/watch.ts#L205-L216In contrary to Vite where we write each output serially:
vite/packages/vite/src/node/build.ts
Lines 762 to 765 in 6236846
If we want to, we can fix watch mode to write serially manually, but I figured to fix this in plugin-legacy itself first. By grouping each output to its own map, we can handle the chunks in
renderChunk
in parallel.I also updated the code to use the variables defensively to prevent issues like this in the future. I needed to hook into the Rollup watcher error event in order to get the error message: