Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Tree crashes on mount with `Cannot read properties of null (reading 'scrollTo')` when a node title contains an autoFocus input

未关闭
#1,068 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript

调研方向

从 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 /> }]} />
  1. Render a Tree where any node's title contains an element with autoFocus (or anything that focuses inside a row during the commit).
  2. The input's focus bubbles to the tree container, the tree's focus activation runs scrollTo, and listRef.current is null at 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/tree 1.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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

react-component/tree 的其他 Issue

查看 react-component/tree 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。