fix(build): isolate React into stable vendor chunk to prevent HMR crashes#223
Open
austin-liminal wants to merge 4 commits into
Open
fix(build): isolate React into stable vendor chunk to prevent HMR crashes#223austin-liminal wants to merge 4 commits into
austin-liminal wants to merge 4 commits into
Conversation
…shes React was being co-bundled into shared app chunks by rolldown's automatic code splitting. During HMR, re-importing the shared chunk created a fresh React instance while the mounted component tree still referenced the old one, causing "Cannot read properties of null (reading 'useState')" crashes. Two changes fix this: 1. Add manual_code_splitting with a vendor group that forces react and react-dom into their own chunk 2. Switch shared chunk filenames from build-ID hashing to rolldown's content-based [hash], so the vendor chunk keeps a stable filename across HMR rebuilds and the browser reuses the cached ESM module Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
ApprovabilityVerdict: Needs human review Unable to check for correctness in e5456b6. No code changes detected at You can customize Macroscope's approvability policy. Learn more. |
Verifies that manual_code_splitting isolates React into dedicated chunk-vendor-*.js files with content-based hashes, and that page entry chunks import React from the vendor chunk rather than bundling it inline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
manual_code_splittingconfig to the client bundler to forcereactandreact-dominto a dedicatedchunk-vendor-[hash].jschunk, preventing React from being co-located in shared app chunkschunk-[name]-{buildId}.js) to rolldown's content-based[hash], so the vendor chunk keeps a stable filename across HMR rebuilds and the browser reuses the cached ESM moduleWithout this fix, HMR would re-import a shared chunk containing React, creating a fresh React instance while the mounted component tree still referenced the old one — causing
TypeError: Cannot read properties of null (reading 'useState').Test plan
cargo run -- dev --root fixtures/basic, edit a page file, confirm no React dispatcher crash on HMR🤖 Generated with Claude Code
Note
Isolate React into a stable vendor chunk to prevent HMR crashes in client bundle builds
reactandreact-dominto a dedicatedchunk-vendor-[hash].jschunk, keeping React stable across rebuilds.{hash}to[hash]to align with rolldown's content-hash interpolation syntax.shared_chunksentry.Macroscope summarized 3faa195.