Do not hook assetEmitted when writeToDisk is true#2277
Open
AdrianBannister wants to merge 1 commit intowebpack:mainfrom
Open
Do not hook assetEmitted when writeToDisk is true#2277AdrianBannister wants to merge 1 commit intowebpack:mainfrom
AdrianBannister wants to merge 1 commit intowebpack:mainfrom
Conversation
When `writeToDisk: true`, `setupOutputFileSystem` already configures webpack to use the native (disk) output file system, so webpack writes all assets to disk itself. Calling `setupWriteToDisk` on top of that tapped `assetEmitted` and wrote every file a second time. Only invoke `setupWriteToDisk` when `writeToDisk` is a filter function, where the in-memory fs is still used and selective disk writes are needed. Fixes webpack#2270
|
|
Author
|
This closes #2270 |
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.
Summary
When
writeToDisk: trueis set, files were being written to disk twice — once by webpack via its native output file system (configured bysetupOutputFileSystem), and again by theassetEmittedhook set up insetupWriteToDisk. This caused redundant I/O for every emitted asset.The fix changes the call site in
index.jsto only invokesetupWriteToDiskwhenwriteToDiskis a filter function. When it istrue, webpack handles disk writes natively and no hook is needed.What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes. The existing
writeToDisk: truetests inmiddleware.test.jsalready asserted on the number ofassetEmittedtaps — those assertions have been updated fromtoHaveLength(1)totoHaveLength(0)to reflect thatDevMiddlewareno longer tapsassetEmittedwhenwriteToDisk: true. The tests continue to verify that the bundle file is found on disk.Does this PR introduce a breaking change?
No. Behaviour for end users is unchanged — files are still written to disk when
writeToDisk: true, just without the redundant second write.If relevant, what needs to be documented once your changes are merged or what have you already documented?
No documentation changes needed.
Use of AI
This PR was developed with the assistance of Claude (Anthropic). The fix and tests were generated and reviewed with AI support, in accordance with the webpack AI policy.