Skip to content

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

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

nikzanda wants to merge 3 commits 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
    • 受控值更新后,过期的输入规范化操作不再覆盖最新输入。
    • 改进数字输入规范化:全角句号可正确转换为半角句号,适用于受控和非受控输入。
    • 输入规范化完成后,onChange 与 onInput 会按预期顺序触发。

@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 in Change Stack →

No actionable comments were generated in the recent review.

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: 23ecf40e-29e8-42d1-bf1f-ee8dc2f64a8b
Commits

Reviewing files that changed from the base of the PR and between 96b0e4c and 4cda1bd.

Files selected for processing: 1
  • src/InputNumber.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.

Walkthrough

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

Changes

输入规范化

Layer / File(s) Summary
失效待处理规范化与回归测试
src/InputNumber.tsx, tests/normalization.test.tsx
受控值与当前输入解析值不同时,组件递增 inputValueUpdateRef,使待处理的输入规范化失效。测试覆盖 2、0、null、undefined、'2.5',以及受控和非受控模式下的全角句号输入。

Priority: Normal

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

Change: Bug fix

Suggested reviewers: qdyanbing

Merge Risk: Minimal · up to 4cda1

No actionable merge-blocking risk remains in the reviewed change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: prevent stale normalization after controlled value updates”描述了本 PR 的主要变更:受控 value 更新后,使过期的输入规范化任务失效。原始摘要显示,src/InputNumber.tsx 在受控 value 与当前输入解析值不同时递增输入更新标识,使待执行的规范化任务失效;新增的 tests/normalizatio…
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
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.
Full details: Title check

Explanation

标题“fix: prevent stale normalization after controlled value updates”描述了本 PR 的主要变更:受控 value 更新后,使过期的输入规范化任务失效。原始摘要显示,src/InputNumber.tsx 在受控 value 与当前输入解析值不同时递增输入更新标识,使待执行的规范化任务失效;新增的 tests/normalization.test.tsx 覆盖了该行为。标题与变更集及 PR 目标一致,且简洁明确。

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 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

小兔看见输入框,
旧任务停在路中央。
值若更新,标记忙,
全角句号变点亮。
测试逐项来检查,
小兔点头跳回家。

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.19%. Comparing base (868bd31) to head (4cda1bd).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #755      +/-   ##
==========================================
+ Coverage   96.16%   96.19%   +0.03%     
==========================================
  Files           6        6              
  Lines         365      368       +3     
  Branches      103      105       +2     
==========================================
+ Hits          351      354       +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.

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

Development

Successfully merging this pull request may close these issues.

1 participant