Skip to content

fix: keep InputNumber refs stable between renders - #760

Open
wozhenbang2004 wants to merge 2 commits into
react-component:masterfrom
wozhenbang2004:fix-stable-input-number-ref
Open

wozhenbang2004 wants to merge 2 commits into
react-component:masterfrom
wozhenbang2004:fix-stable-input-number-ref

Conversation

@wozhenbang2004

@wozhenbang2004 wozhenbang2004 commented Nov 12, 2026 •

Copy link
Copy Markdown

Keep InputNumber's ref stable to avoid an update loop when it is used as a Radix Tooltip trigger.

Added regression coverage for state-setting refs, Strict Mode, ref replacement, and focus/blur after updates. Tests, lint, type check, compile and build pass.

Fixes #664

Summary by CodeRabbit

  • 修复
    • 改进了数字输入框在属性更新、替换引用及卸载后的引用行为。

@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

@wozhenbang2004 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

InputNumber 的 imperative handle 现在通过空依赖数组创建一次,focus、blur 和 nativeElement 的代理定义保持不变。新增测试覆盖 Fragment、StrictMode、props 更新、ref 替换和组件卸载场景。

Changes

Imperative ref

层 / 文件 摘要
Imperative handle 与 ref 生命周期验证
src/InputNumber.tsx, tests/ref.test.tsx
imperative handle 改为使用空依赖数组创建一次。测试验证 setter ref、props 更新后的 ref 行为、ref 替换,以及卸载时 ref 清空。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: qdyanbing

Merge Risk: Minimal · up to a2eed

This change keeps InputNumber refs stable, which fixes the update loop seen with libraries such as Radix Tooltip. Regression tests cover the main ref scenarios. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: keep InputNumber refs stable between renders”与变更内容一致。变更将 InputNumber 的 imperative handle 改为只创建一次(依赖数组为 []),并新增 ref 相关测试。标题准确概括了主要修复点,即保持 ref 在多次渲染之间稳定,从而避免作为 Radix Tooltip 触发器时出现更新循环(关联 issue …
Linked Issues check Passed [#664] 要求消除 InputNumber 作为 Radix Tooltip 触发器时的 "maximum depth exceeded" 错误。问题根源是每次渲染都生成新的 imperative handle 对象,导致 forwardRef 与 composeRef 反复触发更新。审阅的 head 版本 src/InputNumber.tsx 中,React.useImperativeHa…
Out of Scope Changes check Passed 变更集中在 src/InputNumber.tsx 的 imperative handle 创建方式,以及 tests/ref.test.tsx 中的 ref 相关测试。两者都直接服务于 [#664] 的 ref 稳定性要求。未发现与 ref 稳定性或 InputNumber ref 行为无关的变更。审阅所用证据限于 head 文件内容和 PR 摘要,无法读取 base 与 head 的文本 di…
Full details: Title check

Explanation

标题“fix: keep InputNumber refs stable between renders”与变更内容一致。变更将 InputNumber 的 imperative handle 改为只创建一次(依赖数组为 []),并新增 ref 相关测试。标题准确概括了主要修复点,即保持 ref 在多次渲染之间稳定,从而避免作为 Radix Tooltip 触发器时出现更新循环(关联 issue #664)。

Full details: Linked Issues check

Explanation

[#664] 要求消除 InputNumber 作为 Radix Tooltip 触发器时的 "maximum depth exceeded" 错误。问题根源是每次渲染都生成新的 imperative handle 对象,导致 forwardRef 与 composeRef 反复触发更新。审阅的 head 版本 src/InputNumber.tsx 中,React.useImperativeHandle 的依赖数组为 [],handle 只在挂载时创建一次。暴露的 focus、blur 和 nativeElement(rootRef.current)行为保持不变。摘要显示 tests/ref.test.tsx 新增了状态 setter 作为 ref、Strict Mode、ref 替换及更新后 focus/blur 的测试。证据限于 head 文件和 PR 摘要:无法读取 base 与 head 的完整文本 diff,因此未能逐行核对改动前后的差异。上述证据支持 ref 稳定性要求已满足。

Full details: Out of Scope Changes check

Explanation

变更集中在 src/InputNumber.tsx 的 imperative handle 创建方式,以及 tests/ref.test.tsx 中的 ref 相关测试。两者都直接服务于 [#664] 的 ref 稳定性要求。未发现与 ref 稳定性或 InputNumber ref 行为无关的变更。审阅所用证据限于 head 文件内容和 PR 摘要,无法读取 base 与 head 的文本 diff,因此改动范围的判断基于摘要。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

小兔看见 ref 稳稳挂上,
Fragment 里也亮起 ready 的光。
props 更新,方法依旧可用,
ref 替换,旧指针轻轻退场。
卸载之后,引用清空,
小兔蹦跳,合上测试篇章。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 152f93b1-1cf2-4878-8834-c03da773654e
Commits

Reviewing files that changed from the base of the PR and between 868bd31 and a2eed50.

Files selected for processing: 2

  • src/InputNumber.tsx
  • tests/ref.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@wozhenbang2004
wozhenbang2004 marked this pull request as ready for review November 12, 2026 09:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant