Bug: Race condition in completeSegment ($RS) causes "Cannot read properties of null (reading 'parentNode')" error
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, react
- Ambito
- frontend
Direzione di ricerca
Inizia con completeSegment in packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js e riproduci il problema usando il repository collegato con npm install, npm run build e npm run start. Ricarica la pagina di produzione come descritto e verifica che la risoluzione di Suspense non produca più l'errore null parentNode.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- JavaScript
- Stelle
- 251k
- Fork
- 51.4k
- Merge medio
- 2g 4h
- PR unite (30g)
- 50
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di react/react
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Theme loads third-party resources on every page (jsdelivr web font, cdnjs Font Awesome) – GDPR Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
docToolchain/docToolchain#1705 ·
-
Timezone select lists one option per character; duplicate "Failed" reason; shared tracker popover id Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
nightscout/nocturne#1414 ·
-
bug v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
modelcontextprotocol/inspector#2458 · 1 commento ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
carbon-design-system/ibm-products#9907 ·