fix(gatsby): workaround some webpack issues causing first save after running gatsby develop to not have any effect #30193
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.
Gather around, I will tell a story ...
Description
gatsby develop
react toinvalid
events coming from webpack to decide wether webpack need to recompile or not, however first compilation has some issues with virtual modules - because those are not real modules first time we start watching,watchpack
will report all virtual modules as "deleted" ( https://github.com/webpack/watchpack/blob/f1b5e2da2d5dfd46f99b9b405c97b9d6441687d5/lib/watchpack.js#L176-L180 ). This doesn't result ininvalid
event because those only happen onchange
events ( https://github.com/webpack/webpack/blob/3f7f059d502e1e174f0c9432d927c3ec9b028241/lib/node/NodeWatchFileSystem.js#L68-L70 ). Funnily enough - deletion however do causeaggregated
event ( https://github.com/webpack/watchpack/blob/f1b5e2da2d5dfd46f99b9b405c97b9d6441687d5/lib/watchpack.js#L315-L323 ) and becauseNodeWatchFileSystem
and wepback's Watching manager only reactonce
tochange
oraggregated
events, in first compilation what happens is that we receiveaggregated
event without individualinvalid
event so gatsby never mark webpack to recompile.Then when user make their first change we receive
invalid
event and mark things to recompile, but we won't receiveaggregated
event after that, which means that new change won't be compiled ... after that initial first re-compilation watcher gets recreated and everything become happy again ...So to workaround this 2 things:
Related Issues
Fixes #30183