Tree crashes on mount with `Cannot read properties of null (reading 'scrollTo')` when a node title contains an autoFocus input
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- react, typescript
- 领域
- frontend, testing-qa
调研方向
从 Tree.js 中的 Tree.scrollTo 开始,跟踪 issue 中描述的 NodeList ref 生命周期。先使用提供的 autoFocus 复现作为第一项检查,然后运行或添加提到的回归测试;当首次 mount 不再崩溃且测试覆盖该情况时,即可完成。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 1.3k
- 派生
- 490
- 平均合并
- 3 天 17 小时
- 30 天内合并 PR
- 5
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
react-component/tree 的其他 Issue
-
难度 5/5 一周以上 新手友好度 20/100
react-component/tree#983 ·
-
难度 3/5 1-2 天 新手友好度 35/100
react-component/tree#937 ·
-
难度 5/5 一周以上 新手友好度 25/100
react-component/tree#935 ·
-
难度 3/5 1-2 天 新手友好度 35/100
react-component/tree#929 ·
-
难度 5/5 一周以上 新手友好度 25/100
react-component/tree#854 · 1 条评论 ·
查看 react-component/tree 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
mksglu/context-mode#1200 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
难度 2/5 1-3 小时 新手友好度 75/100
anthropics/claude-code#96687 ·
-
good first issue
难度 1/5 1 小时以内 新手友好度 95/100
AOSSIE-Org/DebateAI#582 · 2 条评论 ·