Skip to content

fix: update open state while disabled#641

Merged
zombieJ merged 2 commits into
masterfrom
codex/fix-disabled-open-state
Jul 17, 2026
Merged

fix: update open state while disabled#641
zombieJ merged 2 commits into
masterfrom
codex/fix-disabled-open-state

Conversation

@zombieJ

@zombieJ zombieJ commented Jul 17, 2026

Copy link
Copy Markdown
Member

Follow up #638

Summary

  • separate the raw open state from the disabled merged state
  • update the raw open state when hover leaves while disabled
  • prevent the popup from reopening after disabled is removed when the pointer has already left

Tests

  • ut test --runInBand
  • ut tsc
  • ut lint

Summary by CodeRabbit

  • Bug 修复
    • 修复触发器在悬停打开后切换为禁用,再触发离开鼠标时,受控/受管打开状态未能正确同步的问题。
    • 恢复启用后,弹出层保持隐藏,避免因状态更新导致的意外重新显示。
  • 测试
    • 新增“禁用时离开鼠标并恢复启用后不自动弹出”的用例,覆盖该状态流转场景。

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
trigger Ready Ready Preview, Comment Jul 17, 2026 4:03am

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6d928630-a680-4671-812f-7aa7a6ca0b0c

📥 Commits

Reviewing files that changed from the base of the PR and between 5194518 and 6f53057.

📒 Files selected for processing (1)
  • .github/workflows/react-doctor.yml

Walkthrough

调整 Triggerdisabled 状态下的内部打开状态比较逻辑,新增鼠标离开测试,并将 react-doctor 工作流固定到 0.7.4。

Changes

禁用状态下的打开状态处理

Layer / File(s) Summary
打开状态派生与关闭事件更新
src/index.tsx, tests/basic.test.jsx
拆分 rawOpen 与受 disabled 影响的 mergedOpen,内部状态更新改用 rawOpen 比较,并测试禁用期间 mouseLeave 触发关闭及恢复后的隐藏状态。

React Doctor 工作流配置

Layer / File(s) Summary
React Doctor 版本配置
.github/workflows/react-doctor.yml
移除 github-token 输入,并将 react-doctor 版本设置为 0.7.4

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

Possibly related PRs

Poem

我是兔子,蹦过开关旁,
禁用之时,状态不迷藏。
鼠标离开,关闭回响,
再次启用,弹层仍安详。

🚥 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 标题简洁且准确概括了在 disabled 状态下更新 open 状态这一主要改动。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-disabled-open-state

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.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

React Doctor found 8 issues in 1 file · 8 warnings · score 71 / 100 (Needs work) · vs master

8 warnings

src/index.tsx

  • ⚠️ L155 Large component is hard to read and change no-giant-component
  • ⚠️ L198 Empty default prop breaks memo rerender-memo-with-default-value
  • ⚠️ L384 Missing effect dependencies exhaustive-deps
  • ⚠️ L437 Derived state stored in an effect no-derived-state-effect
  • ⚠️ L516 Missing effect dependencies exhaustive-deps
  • ⚠️ L516 Missing effect dependencies exhaustive-deps
  • ⚠️ L580 Missing effect dependencies exhaustive-deps
  • ⚠️ L771 Static value rebuilt every render prefer-module-scope-static-value

Reviewed by React Doctor for commit 6f53057. See inline comments for fixes.

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.28%. Comparing base (a2fcd03) to head (6f53057).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #641   +/-   ##
=======================================
  Coverage   97.28%   97.28%           
=======================================
  Files          17       17           
  Lines         957      958    +1     
  Branches      279      280    +1     
=======================================
+ Hits          931      932    +1     
  Misses         26       26           

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

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

❌ Deploy failed

PR preview ❌ Failed ❌ Failed
🔗 Preview https://react-component-trigger-preview-pr-641.surge.sh (may be unavailable)
📝 Commit6f53057
🪵 LogsView logs
📋 Build log (last lines)
npm error
npm error Could not resolve dependency:
npm error peer eslint@"^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7" from eslint-plugin-react@7.37.5
npm error node_modules/eslint-plugin-react
npm error   dev eslint-plugin-react@"^7.37.5" from the root project
npm error   eslint-plugin-react@"^7.32.2" from @umijs/fabric@4.0.1
npm error   node_modules/@umijs/fabric
npm error     @umijs/fabric@"^4.0.0" from rc-test@7.1.3
npm error     node_modules/rc-test
npm error       dev rc-test@"^7.1.3" from the root project
npm error
npm error Conflicting peer dependency: eslint@9.39.5
npm error node_modules/eslint
npm error   peer eslint@"^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7" from eslint-plugin-react@7.37.5
npm error   node_modules/eslint-plugin-react
npm error     dev eslint-plugin-react@"^7.37.5" from the root project
npm error     eslint-plugin-react@"^7.32.2" from @umijs/fabric@4.0.1
npm error     node_modules/@umijs/fabric
npm error       @umijs/fabric@"^4.0.0" from rc-test@7.1.3
npm error       node_modules/rc-test
npm error         dev rc-test@"^7.1.3" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /home/runner/.npm/_logs/2026-07-17T04_04_16_367Z-eresolve-report.txt
npm error A complete log of this run can be found in: /home/runner/.npm/_logs/2026-07-17T04_04_16_367Z-debug-0.log

🤖 Powered by surge-preview

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a rawOpen variable to track the open state of the trigger component independently of its disabled status, and updates the internalTriggerOpen callback to use rawOpen instead of mergedOpen. It also adds a test case to verify that the open state updates correctly when the mouse leaves while the trigger is disabled. The reviewer identified an issue where openRef still tracks mergedOpen (which is always false when disabled), preventing toggle actions from closing the trigger when disabled. They suggested updating openRef to track rawOpen instead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.tsx
const internalTriggerOpen = useEvent((nextOpen: boolean) => {
flushSync(() => {
if (mergedOpen !== nextOpen) {
if (rawOpen !== nextOpen) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

When disabled is true, mergedOpen is always false. Currently, openRef is assigned to mergedOpen (on lines 386-387):

const openRef = React.useRef(mergedOpen);
openRef.current = mergedOpen;

Because of this, when disabled is true, openRef.current is always false. This causes issues with toggle actions (such as click, touch, and contextMenu) when the trigger is disabled. For example, in the onClick handler:

if (openRef.current && clickToHide) {
  triggerOpen(false);
} else if (!openRef.current && clickToShow) {
  setMousePosByEvent(event);
  triggerOpen(true);
}

Since openRef.current is always false when disabled, clicking the target will always attempt to call triggerOpen(true) and can never call triggerOpen(false). This means the user cannot toggle the underlying open state back to false by clicking while disabled.

To fix this and ensure consistency with the new rawOpen logic, openRef should be updated to track rawOpen instead of mergedOpen:

const openRef = React.useRef(rawOpen);
openRef.current = rawOpen;

@zombieJ
zombieJ merged commit 595413c into master Jul 17, 2026
12 of 13 checks passed
@zombieJ
zombieJ deleted the codex/fix-disabled-open-state branch July 17, 2026 04:05
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