Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Bug: Race condition in completeSegment ($RS) causes "Cannot read properties of null (reading 'parentNode')" error | GoodFirstPicks

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

facebook/react 3 comments 1mo ago
View on GitHub
lowopenScope: clearSkill match: maybeReactJavaScriptTypeScript

Why this is a good first issue

The issue involves a straightforward null check fix in a specific function.

AI Summary

The issue describes a race condition in the `completeSegment` function where null safety checks are missing, leading to crashes in production builds. The fix involves adding null checks before accessing `parentNode`. The scope is clear, but understanding the SSR context might require some domain knowledge.

Issue Description

The $RS (completeSegment) function in React DOM's Server-Side Rendering lacks null safety checks on parentNode, causing a race condition error when Suspense boundaries resolve in production builds.

Error: Cannot read properties of null (reading 'parentNode')

Root Cause: File: packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js (line 15)

The completeSegment function doesn't check if a.parentNode or b.parentNode is null before accessing it. During Suspense resolution, nodes can be removed by other processes, setting parentNode to null.

Buggy Code: https://github.com/facebook/react/blob/v19.2.0/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js#L15

export const completeSegment =
  '$RS=function(a,b){a=document.getElementById(a);b=document.getElementById(b);for(a.parentNode.removeChild(a);a.firstChild;)b.parentNode.insertBefore(a.firstChild,b);b.parentNode.removeChild(b)};';

Proposed Fix:

export const completeSegment =
  '$RS=function(a,b){a=document.getElementById(a);b=document.getElementById(b);if(a&&b&&a.parentNode&&b.parentNode){for(a.parentNode.removeChild(a);a.firstChild;)b.parentNode.insertBefore(a.firstChild,b);b.parentNode.removeChild(b)}};';

React version: 19.2.0

Steps To Reproduce

  1. Clone the reproduction repository
  2. Run npm install
  3. Run npm run build (production build required)
  4. Run npm run start
  5. Navigate to http://localhost:3000
  6. Note: The bug may not occur on the first page load. Reload the page several times if needed.
  7. Check browser console for the error

GitHub Labels

Status: Unconfirmed

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • race condition
  • production crash
Loading labels...

Details

Points10 pts
Difficultylow
Scopeclear
Skill Matchmaybe
Test Focusedno