Skip to content

fix: prevent stale normalization after controlled value updates - #755

Open
nikzanda wants to merge 1 commit into
react-component:masterfrom
nikzanda:fix/stale-input-normalization
Open

fix: prevent stale normalization after controlled value updates#755
nikzanda wants to merge 1 commit into
react-component:masterfrom
nikzanda:fix/stale-input-normalization

Conversation

@nikzanda

@nikzanda nikzanda commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the discussion in #751.

Typing 1。 schedules normalization to 1.. If the controlled value changes to 2 before that callback runs, the stale normalization can overwrite the displayed value and emit an outdated onChange.

This fix invalidates pending normalization when a controlled update replaces the typed value, while preserving normal behavior when the parent echoes the value received through onChange.

Includes regression tests for controlled updates, zero and empty values, stale callbacks, and continued normalization in controlled and uncontrolled modes.

Summary by CodeRabbit

  • Bug Fixes
    • 修复受控值更新后,过期的输入规范化操作可能覆盖最新输入的问题。
    • 改进数字输入的规范化处理,确保全角句号等输入可正确转换为标准格式。
    • 修复输入规范化后的 onChangeonInput 事件触发顺序与时机。

@vercel

vercel Bot commented Sep 9, 2026

Copy link
Copy Markdown

@nikzanda 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 Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: c32f5c7e-bfa5-4516-a82e-627bfd7a7d58

📥 Commits

Reviewing files that changed from the base of the PR and between 2e4c1b7 and c37d436.

📒 Files selected for processing (2)
  • src/InputNumber.tsx
  • tests/normalization.test.tsx

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

受控值变化时,InputNumber 现在会使待处理的输入规范化失效。新增测试覆盖多种受控值、受控与非受控模式,以及全角句号输入。

Changes

输入规范化

Layer / File(s) Summary
失效待处理规范化与回归测试
src/InputNumber.tsx, tests/normalization.test.tsx
受控值变化时递增 inputValueUpdateRef.current,使旧的待处理规范化失效。测试覆盖 20nullundefined'2.5'、受控模式、非受控模式及全角句号输入。

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to c37d4

Controlled value updates no longer allow stale input normalization to overwrite the displayed value or emit an outdated change. The affected behaviors are covered across controlled and uncontrolled usage, and no current merge-blocking risk remains.

Suggested reviewers: qdyanbing

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:防止受控值更新后执行过期的输入规范化。标题简洁、明确,并与代码和测试变更一致。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

小兔挥耳检查输入框
旧的规范化悄悄失效
全角句号变成小圆点
受控数值稳稳更新
测试把每条路径照亮

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.17%. Comparing base (2e4c1b7) to head (c37d436).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #755      +/-   ##
==========================================
+ Coverage   96.14%   96.17%   +0.03%     
==========================================
  Files           6        6              
  Lines         363      366       +3     
  Branches      102      104       +2     
==========================================
+ Hits          349      352       +3     
  Misses         14       14              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant