Skip to content

Conversation

@ponharu
Copy link

@ponharu ponharu commented Nov 6, 2025

Summary

This PR fixes a race condition bug in React DOM's Server-Side Rendering where the $RS (completeSegment) function doesn't check if parentNode is null before accessing it.

Problem:
During Suspense boundary resolution in production builds, the completeSegment function can encounter a race condition where DOM nodes are removed by other processes, causing parentNode to become null. This results in the error: Cannot read properties of null (reading 'parentNode').

Solution:
Added null safety checks for a, b, a.parentNode, and b.parentNode before 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:

  • Repository: https://github.com/ponharu/react-issue
  • Setup: Next.js 16.0.1 + React 19.2.0 + Chakra UI v3 with Suspense boundaries
  • Steps: Production build with async page component (1s delay) + Suspense fallback

2. Verification:

  • Before fix: Error occurred consistently when reloading the page multiple times
  • After applying the fix: Error no longer occurs, page renders correctly
  • Applied the fix to all affected compiled files in Next.js project and verified in production environment

3. Commands run:

# Applied fix to production build
npm run build
npm run start

# Tested multiple page reloads to trigger race condition
# Monitored browser console for errors

4. Environment tested:

  • Next.js 16.0.1 (production build)
  • React/React DOM 19.2.0
  • Chakra UI v3
  • Node.js 24.11.0
  • Browser: google Chrome 142.0.7444.60

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.

…ndition

The completeSegment function can encounter a race condition where
parentNode is null during Suspense boundary resolution. This adds
null safety checks to prevent 'Cannot read properties of null' errors.
@meta-cla
Copy link

meta-cla bot commented Nov 6, 2025

Hi @ponharu!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@meta-cla
Copy link

meta-cla bot commented Nov 6, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed label Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Race condition in completeSegment ($RS) causes "Cannot read properties of null (reading 'parentNode')" error

1 participant