Bug: Race condition in completeSegment ($RS) causes "Cannot read properties of null (reading 'parentNode')" error
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 75/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- javascript, react
- Domaine
- frontend
Piste de recherche
Commencez par completeSegment dans packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js et reproduisez le problème en utilisant le dépôt lié avec npm install, npm run build et npm run start. Rechargez la page de production comme décrit et vérifiez que la résolution de Suspense ne produit plus l'erreur null parentNode.
Rédigé par le modèle d'indexation à partir du texte de l'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.
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
- Clone the reproduction repository
- Run
npm install - Run
npm run build(production build required) - Run
npm run start - Navigate to http://localhost:3000
- Note: The bug may not occur on the first page load. Reload the page several times if needed.
- Check browser console for the error
Link to code example:
https://github.com/ponharu/react-issue
The current behavior
During SSR with Suspense boundaries in production builds, the $RS function throws:
Cannot read properties of null (reading 'parentNode')
This occurs when the function attempts to manipulate DOM nodes whose parentNode has become null due to a race condition during Suspense resolution.
The expected behavior
The $RS function should safely handle cases where parentNode is null by checking for null before attempting DOM manipulation, preventing the error and allowing the page to render correctly.
- Langage dominant
- JavaScript
- Étoiles
- 251k
- Forks
- 51.4k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 50
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de react/react
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Toutes les issues de react/react
Issues similaires
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Improve Title Support Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·