fix: update open state while disabled#641
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough调整 Changes禁用状态下的打开状态处理
React Doctor 工作流配置
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
React Doctor found 8 issues in 1 file · 8 warnings · score 71 / 100 (Needs work) · vs 8 warnings
Reviewed by React Doctor for commit |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
❌ Deploy failed
📋 Build log (last lines)🤖 Powered by surge-preview |
|||||||||
There was a problem hiding this comment.
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.
| const internalTriggerOpen = useEvent((nextOpen: boolean) => { | ||
| flushSync(() => { | ||
| if (mergedOpen !== nextOpen) { | ||
| if (rawOpen !== nextOpen) { |
There was a problem hiding this comment.
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;
Follow up #638
Summary
Tests
ut test --runInBandut tscut lintSummary by CodeRabbit