Fix chunk-merge bug in ReactFlightWebpackPlugin (v19.0.3)#20
Fix chunk-merge bug in ReactFlightWebpackPlugin (v19.0.3)#20AbanoubGhadban wants to merge 3 commits intomainfrom
Conversation
When a 'use client' module appears in multiple webpack chunk groups, recordModule() was overwriting the manifest entry instead of merging chunk arrays. This caused missing chunk preloads during RSC hydration, leading to __webpack_require__ failures under slow networks. Built from React fork rsc-patches/v19.0.3 with the fix applied. Resolves #19 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryFixes a critical bug where
The fix addresses the root cause by preserving all chunk references needed for proper RSC client-side hydration. Confidence Score: 4/5
Important Files Changed
Last reviewed commit: ef99ec0 |
| id = filePathToModuleMetadata[module]; | ||
| module = new Set(); |
There was a problem hiding this comment.
Variable shadowing: id and module parameters are being reused as local variables. While this works, it reduces readability.
| id = filePathToModuleMetadata[module]; | |
| module = new Set(); | |
| const existing = filePathToModuleMetadata[module]; | |
| const existingChunkIds = new Set(); |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| for (var i = 0; i < id.chunks.length; i += 2) | ||
| module.add(id.chunks[i]); |
There was a problem hiding this comment.
Use descriptive variable name in loop instead of reusing i
| for (var i = 0; i < id.chunks.length; i += 2) | |
| module.add(id.chunks[i]); | |
| for (let j = 0; j < id.chunks.length; j += 2) | |
| module.add(id.chunks[j]); |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
recordModule()inReactFlightWebpackPluginto merge chunk arrays instead of overwriting when the same module appears in multiple webpack chunk groupsTypeError: r[e] is not a functionerrors during RSC hydration on slow networks (e.g., 3G + CPU throttling)rsc-patches/v19.0.3with the fix appliedRoot Cause
When webpack splits modules across multiple chunks (via chunk groups), the plugin's
recordModule()was called multiple times for the same module. Each call overwrote the previous entry with only the current chunk group's chunks, losing earlier chunk references. The RSC flight client then failed to preload all necessary chunks, causing__webpack_require__to fail when a module factory hadn't been registered yet.The Fix
Changed from:
To merge logic that preserves chunks from all chunk groups:
Test plan
TypeErrorerrors after 3+ hard reloadsResolves #19
🤖 Generated with Claude Code