Skip to content

fix: use latest Transfer onSelectChange callback - #59307

Merged
QDyanbing merged 3 commits into
ant-design:masterfrom
yunfeizhu:fix/transfer-latest-select-callback
Sep 16, 2026
Merged

QDyanbing merged 3 commits into
ant-design:masterfrom
yunfeizhu:fix/transfer-latest-select-callback

Conversation

@yunfeizhu

@yunfeizhu yunfeizhu commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

Fixes #59306

💡 Background and Solution

When a parent replaces or removes onSelectChange while the selected keys stay unchanged, Transfer can keep invoking the previous callback. For example, switching the active project from A to B and then selecting an item reports project A.

Use useEvent from @rc-component/util for handleSelectChange, keeping its reference stable while subsequent selection events read the current callback and selected keys. Regression tests cover callback replacement in both lists and callback removal.

Validation:

  • All three new regression cases fail on the unchanged master source and pass with the fix.
  • npx jest --config .jest.js --runInBand --no-cache --runTestsByPath components/transfer/__tests__/index.test.tsx: 57 tests and 5 snapshots passed.
  • Biome checks passed for both changed files.

📝 Change Log

Language Changelog
🇺🇸 English Fix Transfer calling an outdated onSelectChange after the callback is replaced or removed.
🇨🇳 Chinese 修复 Transfer 在替换或移除 onSelectChange 后仍调用旧回调的问题。

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

👁 Visual Regression Report for PR #59307 Passed ✅

🎯 Target branch: master (2a95ebe)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎

🎊 Congrats! No visual-regression diff found.

📖 中文报告

👁 PR #59307 视觉回归报告 通过 ✅

🎯 目标分支: master (2a95ebe)

🎊 恭喜!未发现视觉回归差异。

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Preview is ready

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e38a1f09-61d4-473b-b353-61c54fea6ea2

📥 Commits

Reviewing files that changed from the base of the PR and between 6ebb09b and da7da7d.

📒 Files selected for processing (1)
  • components/transfer/index.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug 修复

    • 修复 Transfer 组件更新或移除选择变更回调后仍调用旧回调的问题。
    • 确保选择项目时使用最新回调,并在回调移除后不再触发。
  • 测试

    • 增加回调更新、移除及选中项参数传递的测试覆盖。

Walkthrough

Transfer 的选择处理函数现在使用最新的 onSelectChange。新增测试覆盖回调替换和回调移除。

Changes

Transfer 回调更新

Layer / File(s) Summary
选择回调引用与回归测试
components/transfer/index.tsx, components/transfer/__tests__/index.test.tsx
handleSelectChange 改用 useEvent,以读取最新的 onSelectChange。测试验证重新渲染后调用新回调,以及移除属性后不再调用旧回调。

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: zombiej

Merge Risk: ⚪ Minimal · up to da7da

The Transfer callback update has no identified blocking behavior and is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed PR #59306 的编码要求已满足。components/transfer/index.tsx 使用 useEvent 包装 handleSelectChange,因此回调会读取最新的 onSelectChange,不会保留旧的父组件状态;移除该 prop 后也不会继续调用旧回调。components/transfer/__tests__/index.test.tsx 覆盖左…
Out of Scope Changes check ✅ Passed 变更仅包含 Transfer 选择变更回调的处理修复和对应回归测试。两部分变更都直接支持 #59306 的要求。没有证据表明存在无关功能或无关文件变更。
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…
Description check ✅ Passed 描述明确说明了 Transfer 的缺陷、修复方案、回归测试和验证结果,与变更内容直接相关。
Title check ✅ Passed 标题“fix: use latest Transfer onSelectChange callback”准确概括了使用最新回调修复 Transfer 过期回调问题的主要变更。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.


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

小兔挥爪改回调,
新鲜引用不迟到。
旧声退场静悄悄,
测试守住每一跳。
Transfer 轻快向前跑。

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

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Bundle Report

Changes will decrease total bundle size by 44 bytes (-0.0%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.24MB -44 bytes (-0.0%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: antd.min-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antd-with-locales.min.js -22 bytes 1.81MB -0.0%
antd.min.js -22 bytes 1.43MB -0.0%

@pkg-pr-new

pkg-pr-new Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
More templates

npm i https://pkg.pr.new/antd@59307

commit: da7da7d

Comment thread components/transfer/index.tsx Outdated
}
},
[sourceSelectedKeys, targetSelectedKeys],
[sourceSelectedKeys, targetSelectedKeys, onSelectChange],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use util useEvent instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! Switched handleSelectChange to useEvent from @rc-component/util. The existing regression tests are unchanged, and the Transfer suite passes with 57 tests and 5 snapshots.

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2a95ebe) to head (da7da7d).

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #59307   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          834       834           
  Lines        16026     16025    -1     
  Branches      4205      4205           
=========================================
- Hits         16026     16025    -1     

☔ 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.

@coderabbitai
coderabbitai Bot requested a review from zombieJ September 16, 2026 10:00

@QDyanbing QDyanbing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@QDyanbing
QDyanbing merged commit 8a7c340 into ant-design:master Sep 16, 2026
44 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Thank you for your contribution! If you have not yet joined our DingTalk community group, please feel free to join us (when joining, please provide the link to this PR).

🎉 感谢您的贡献!如果您还没有加入钉钉社区群,请扫描下方二维码加入我们(加群时请提供此 PR 链接)。

钉钉社区群二维码

@PeachScript PeachScript mentioned this pull request Sep 20, 2026
1 of 17 tasks
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.

Transfer onSelectChange calls a stale callback after parent re-render

3 participants