Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): workaround some webpack issues causing first save after running gatsby develop to not have any effect #30193

Merged
merged 4 commits into from
Mar 11, 2021

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Mar 11, 2021

Gather around, I will tell a story ...

Description

gatsby develop react to invalid 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 in invalid event because those only happen on change events ( https://github.com/webpack/webpack/blob/3f7f059d502e1e174f0c9432d927c3ec9b028241/lib/node/NodeWatchFileSystem.js#L68-L70 ). Funnily enough - deletion however do cause aggregated event ( https://github.com/webpack/watchpack/blob/f1b5e2da2d5dfd46f99b9b405c97b9d6441687d5/lib/watchpack.js#L315-L323 ) and because NodeWatchFileSystem and wepback's Watching manager only react once to change or aggregated events, in first compilation what happens is that we receive aggregated event without individual invalid 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 receive aggregated 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:

  • to avoid marking virtual modules as deleted we actually create those files (tho we won't use them)
  • move writing initial loading-indicator module before we start compilation to avoid marking this file as changed

Related Issues

Fixes #30183

…running gatsby develop to not have any effect
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 11, 2021
@pieh pieh added topic: hot reloading and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Mar 11, 2021
@wardpeet wardpeet changed the title fix(gatsby): wokraround some webpack issues causing first save after running gatsby develop to not have any effect fix(gatsby): workaround some webpack issues causing first save after running gatsby develop to not have any effect Mar 11, 2021
@kelvindecosta
Copy link
Contributor

Hey @pieh, just thought I'd let you know about another relevant issue which seems to have an active discussion.

See #27609 and #30194

Thank you!

pieh and others added 2 commits March 11, 2021 17:51
Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
Copy link
Contributor

@vladar vladar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find! 👍 I am lurking in the same area of webpack sources ATM so at least I understand the description of this PR and what's going on there 😄

@vladar vladar merged commit a9d65f6 into master Mar 11, 2021
@vladar vladar deleted the fix/v3-first-save-hmr branch March 11, 2021 19:49
@LekoArts LekoArts added the topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) label May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gatsby v3: Refresh misses first bundle rebuild after gatsby develop
4 participants