fix(react-dom): add null checks to completeSegment to prevent race condition #35057
+1
−1
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
This PR fixes a race condition bug in React DOM's Server-Side Rendering where the
$RS(completeSegment) function doesn't check ifparentNodeis null before accessing it.Problem:
During Suspense boundary resolution in production builds, the
completeSegmentfunction can encounter a race condition where DOM nodes are removed by other processes, causingparentNodeto becomenull. This results in the error:Cannot read properties of null (reading 'parentNode').Solution:
Added null safety checks for
a,b,a.parentNode, andb.parentNodebefore DOM manipulation. This ensures the function safely exits if any required node or parent is missing.Affected code:
packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js(line 15)Fixes #35056
How did you test this change?
1. Minimal Reproduction:
Created a minimal Next.js application that consistently reproduces the bug:
2. Verification:
3. Commands run:
4. Environment tested:
Note: This is a minimal defensive fix that adds null checks without changing the core logic. The race condition is timing-sensitive and more likely to occur with CSS-in-JS libraries like Chakra UI.