Skip to content

fix: release the option lock when a delayed close is canceled - #1262

Merged
yoyo837 merged 2 commits into
react-component:masterfrom
clean99:contrib/cancelled-close-option-lock
Nov 24, 2026
Merged

yoyo837 merged 2 commits into
react-component:masterfrom
clean99:contrib/cancelled-close-option-lock

Conversation

@clean99

@clean99 clean99 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

A canceled blur close keeps the popup open but leaves option updates locked: the list can retain 20 rows after receiving 40 options. The temporary lock introduced in #1193 should end when the current task completes.

Release that task's lock even when closing is canceled. Keep the task-id guard, canceled-close notification suppression, and scheduling unchanged. Hook tests cover controlled/uncontrolled cancellation, normal close, immediate reopen, and an older task finishing before a newer close.

Native keyboard reproduction on 1.12.0 source (fcbd87e), React 19.2.0
import { useState } from 'react';
import Select from '@rc-component/select';
import '@rc-component/select/assets/index.css';

export default function Demo() {
  const [count, setCount] = useState(20);
  return (
    <Select
      style={{ width: 300 }}
      showSearch allowClear virtual={false}
      defaultActiveFirstOption={false}
      optionFilterProp="label"
      options={Array.from({ length: count }, (_, i) => ({ value: `${i}`, label: `Option ${i}` }))}
      onPopupScroll={() => setCount(40)}
    />
  );
}

Click the input, type Option, Tab to Clear, optionally Shift+Tab back, then wheel-scroll the popup without clicking it. Before: only options 0–19 remain available. After: all 40 options are available and the popup stays open. Omitting Tab displays 40 in both versions. Verified with native keyboard/wheel input in Chromium 156.

Regression: npm test -- --runInBand -t useOpen fails on the old source and passes with the fix. Full tests with coverage (455 tests), lint, TypeScript, compile, changed-file formatting, and documentation build pass.

Closes #1260.

Prepared by an automated contribution pipeline that I build and operate (https://github.com/clean99/software-factory); the tests and evidence above were produced by it.

Summary by CodeRabbit

  • Bug Fixes
    • 取消关闭操作后,锁定状态现在会正确解除。
    • 改进了快速重新打开时的锁定处理,避免旧的关闭操作影响新状态。
  • Tests
    • 补充了关闭、取消关闭及快速重新打开等场景的测试。

@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@clean99 is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

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: 31aecedf-73e9-4d42-8ec6-2a6455a9b0a8
Commits

Reviewing files that changed from the base of the PR and between 2f37d4b and a9dbdf0.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

useOpen 在延迟关闭被取消时仍会解除锁定,同时保留任务 ID 检查。新增测试覆盖取消关闭、正常关闭、关闭完成前重新打开,以及连续关闭时旧定时器不解除新锁定。

Changes

延迟关闭锁定处理

Layer / File(s) Summary
延迟关闭与锁定验证
src/hooks/useOpen.ts, tests/Hooks.test.tsx
任务 ID 匹配时,即使 cancelFun 返回真值并跳过 triggerEvent,useOpen 仍调用 setLock(false)。新增测试覆盖取消关闭、正常关闭、重新打开和连续关闭。

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: zombiej

Merge Risk: Minimal · previous review 2f37d

This change fixes the popup option list staying stale after blur and refocus by releasing the update lock when a delayed close is canceled. No remaining 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: release the option lock when a delayed close is canceled”描述了 PR 的主要变更:取消延迟关闭时释放选项锁。原始摘要说明 useOpen 在 cancelFun 返回 true 时仍调用 setLock(false),与标题一致。PR 目标也说明同一修复,且关联 issue #1260 要求相同行为。标题简洁、具体,没有使用…
Linked Issues check Passed [#1260] 要求:延迟关闭任务在 cancelFun() 返回 true 时,也必须释放选项锁,同时保留任务 ID 守卫。在 head 的 src/hooks/useOpen.ts 中,triggerUpdate 仍只在 id === taskIdRef.current 时执行。随后,无论 cancelFun() 结果如何,都会调用 setLock(false)。cancelFun() 返回 …
Out of Scope Changes check Passed PR 变更范围包括 src/hooks/useOpen.ts(约 +5/-6 行)和 tests/Hooks.test.tsx(约 +101/-2 行)。useOpen.ts 中的改动仅是把 setLock(false) 移到 cancelFun 判断之外,直接实现 #1260 的要求。测试改动覆盖同一 hook 的取消、关闭和重开场景,属于支持性测试。未发现与 #1260 无关的改动。
Full details: Title check

Explanation

标题“fix: release the option lock when a delayed close is canceled”描述了 PR 的主要变更:取消延迟关闭时释放选项锁。原始摘要说明 useOpen 在 cancelFun 返回 true 时仍调用 setLock(false),与标题一致。PR 目标也说明同一修复,且关联 issue #1260 要求相同行为。标题简洁、具体,没有使用模糊词语。

Full details: Linked Issues check

Explanation

[#1260] 要求:延迟关闭任务在 cancelFun() 返回 true 时,也必须释放选项锁,同时保留任务 ID 守卫。在 head 的 src/hooks/useOpen.ts 中,triggerUpdate 仍只在 id === taskIdRef.current 时执行。随后,无论 cancelFun() 结果如何,都会调用 setLock(false)。cancelFun() 返回 true 时只跳过 triggerEvent,锁仍会释放。过期任务因 ID 不匹配而不会解锁,满足“旧任务不得解锁新关闭”的要求。[#1175][#1193] 仅作为背景,不产生额外编码要求。PR 描述中提到的 useOpen 测试覆盖取消关闭、正常关闭、立即重开和旧任务晚完成等场景。本次仅基于源码和 PR 摘要确认行为,未读取测试文件内容。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

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

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

我是小兔,轻敲定时钟,
取消关闭,锁也松一松。
重新打开,旧计时停步,
连续关闭,新锁稳稳守。
测试跑过,胡萝卜香浓。
月光之下,安心蹦蹦走。

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: f07f3383-a076-4195-a3ea-2719425a8bd1
Commits

Reviewing files that changed from the base of the PR and between fcbd87e and 2f37d4b.

Files selected for processing: 2

  • src/hooks/useOpen.ts
  • tests/Hooks.test.tsx

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

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.46%. Comparing base (bbbd33c) to head (a9dbdf0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1262      +/-   ##
==========================================
- Coverage   99.46%   99.46%   -0.01%     
==========================================
  Files          31       31              
  Lines        1308     1307       -1     
  Branches      480      479       -1     
==========================================
- Hits         1301     1300       -1     
  Misses          7        7              

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

@yoyo837
yoyo837 merged commit bc783bb into react-component:master Nov 24, 2026
11 of 12 checks passed
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.

OptionList stops updating after blur and immediate refocus

2 participants