fix(gatsby): Persist manifest on cached builds #36693
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
In our current implementation the client module manifest is wiped on subsequent builds, breaking hydration.
This happens because we run
PartialHydrationPlugin
during thebuild-javascript
stage, and on subsequent builds webpack doesn't revisit untouched files and uses the cache instead.This change restores the previous manifest when
PartialHydrationPlugin
runs and merges it with any new client modules found.React has a similar implementation looking for
.client.js
files (the old API) in abeforeCompile
hook to iterate over later - https://github.com/facebook/react/blob/3f70e68cea8d2ed0f53d35420105ae20e22ce428/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js#L110-L132. We could do something similar, but it would be more expensive with the new API because we'd need to check every file's contents forclient export
on every run.Instead our plugin runs alongside JavaScript bundling, relies on webpack to detect touched files, and adds new client modules to the manifest as needed. This won't handle deletion, but deleted client modules don't need to be referenced from the manifest at runtime anyway since they're not loaded.
The way I see it this change fixes the subsequent builds problem for now, and if we see issues in the future with this approach we can re-evaluate using an approach like React's (and test the performance impact).
Documentation
N/A
Related Issues
[sc-55768]