Tree crashes on mount with `Cannot read properties of null (reading 'scrollTo')` when a node title contains an autoFocus input
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- react, typescript
- Ambito
- frontend, testing-qa
Direzione di ricerca
Inizia in Tree.js, su Tree.scrollTo, e segui il ciclo di vita delle ref di NodeList descritto nell’issue. Usa la riproduzione di autoFocus fornita come prima verifica, poi esegui o aggiungi il test di regressione menzionato; il lavoro è completato quando il primo mount non va più in crash e il test copre questo caso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What happened
We render an inline editor (a text input with autoFocus) inside a tree node's title — a common inline-rename pattern. Mounting the tree crashes the entire React root:
TypeError: Cannot read properties of null (reading 'scrollTo')
at Tree.scrollTo (Tree.js)
Because the error is thrown from React's focus event dispatch during the commit, it escapes any local error handling and unmounts the whole application root, not just the tree. We hit this in production via antd's Tree, which wraps this package; TreeSelect and Cascader share the same code path.
Reproduction
import Tree from '@rc-component/tree';
// Mounting this crashes the React root:
<Tree treeData={[{ key: 'a', title: <input autoFocus /> }]} />
- Render a
Treewhere any node'stitlecontains an element withautoFocus(or anything that focuses inside a row during the commit). - The input's focus bubbles to the tree container, the tree's focus activation runs
scrollTo, andlistRef.currentisnullat that moment → crash.
Why the ref is null
NodeList's useImperativeHandle has no dependency array, so on every commit the handle is detached during the mutation phase and re-attached in the layout phase. autoFocus focuses the input between those two, so the bubbled focus-activation dereferences a null listRef. First mount is the simplest trigger, but any re-render has the same window.
Versions
@rc-component/tree1.2.4 → 1.5.0 (current) — call sites unguarded in all- React 19, reproduced in jsdom and real browsers
Fix
Proposed in #1067 — optional chaining on the two listRef.current.scrollTo call sites, plus a regression test that reproduces the crash on first mount.
- Lingua principale
- TypeScript
- Stelle
- 1.3k
- Fork
- 490
- Merge medio
- 3g 17h
- PR unite (30g)
- 5
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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-component/tree
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
react-component/tree#983 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
react-component/tree#937 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
react-component/tree#935 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
react-component/tree#929 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
react-component/tree#854 · 1 commento ·
Tutte le issue di react-component/tree
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
mksglu/context-mode#1200 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
anthropics/claude-code#96687 ·
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
AOSSIE-Org/DebateAI#582 · 2 commenti ·