Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Dec 5, 2025

Summary by CodeRabbit

发布说明

  • 重构

    • 改进了 Select 组件的事件处理逻辑和下拉框关闭行为
    • 优化了点击事件的目标检测机制
  • 测试

    • 更新测试代码以使用键码常量,提高代码可维护性

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 5, 2025

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

Project Deployment Preview Comments Updated (UTC)
select Ready Ready Preview Comment Dec 5, 2025 6:50am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

概览

该 PR 用基于 cancelFun 回调的条件关闭机制替换了原有的延迟关闭逻辑(基于 macroTask)。涉及多个核心文件的事件处理和打开/关闭控制流的重构,以优化组件的模态状态管理。

变更

内聚组 / 文件 变更摘要
打开/关闭逻辑重构
src/BaseSelect/index.tsx, src/hooks/useOpen.ts, src/hooks/useSelectTriggerControl.ts
用条件关闭机制(基于 cancelFun 回调)替换 macroTask 延迟关闭;更新 TriggerOpenType API 从 { ignoreNext?: boolean; lazy?: boolean } 改为 { cancelFun?: () => boolean };移除 taskLock 机制和基于 ignoreNext 的时序控制;重命名事件处理器 onInternalMouseDownonRootMouseDown
事件目标追踪
src/SelectInput/index.tsx, src/hooks/useSelectTriggerControl.ts
_ori_target 事件属性替换 _ignore_global_close;通过存储原始输入 DOM 来改进外部点击检测的目标识别
测试优化
tests/Select.test.tsx
KeyCode 枚举常量替换魔法数字(DOWN:40 → KeyCode.DOWN,ENTER:13 → KeyCode.ENTER

预估代码审查工作量

🎯 3 (中等) | ⏱️ ~20-25 分钟

需关注的重点区域:

  • src/hooks/useOpen.ts 中的 TriggerOpenType API 变更及其对 cancelFun 回调的使用——需验证取消逻辑的正确性和 ID 匹配的完整性
  • src/BaseSelect/index.tsx 中事件处理器命名更改和触发逻辑的简化——需确认所有调用点均正确更新
  • 新的 _ori_target 事件属性传递机制——需确认与原有 _ignore_global_close 标记的语义差异是否被正确处理

可能关联的 PR

建议审查人

  • afc163

🐰 闭包曾为宏任务所困,
如今 cancelFun 来相助,
目标追踪更清晰,
模态关闭不再乱——
重构之心,代码更顺!✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch adjust-order

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b04dc0f and 8c4da64.

📒 Files selected for processing (5)
  • src/BaseSelect/index.tsx (5 hunks)
  • src/SelectInput/index.tsx (1 hunks)
  • src/hooks/useOpen.ts (2 hunks)
  • src/hooks/useSelectTriggerControl.ts (3 hunks)
  • tests/Select.test.tsx (3 hunks)

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 and usage tips.

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.42%. Comparing base (d1f91b7) to head (8c4da64).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1183      +/-   ##
==========================================
- Coverage   99.42%   99.42%   -0.01%     
==========================================
  Files          31       31              
  Lines        1210     1209       -1     
  Branches      430      430              
==========================================
- Hits         1203     1202       -1     
  Misses          7        7              

☔ View full report in Codecov by Sentry.
📢 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.

@gemini-code-assist
Copy link

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the core event handling and state management logic for the BaseSelect component, specifically focusing on how its open/close state is triggered. By introducing a new 'weak' mechanism for triggerOpen calls, the changes aim to provide more precise control over when the select component should open or close, particularly in scenarios involving blur and mouse down events. This enhancement is designed to prevent unintended state changes and improve the component's overall responsiveness and reliability.

Highlights

  • Refactored triggerOpen Mechanism: Introduced a weak flag to triggerOpen calls, allowing certain calls (like those from blur events) to be ignored if a stronger triggerOpen call is already active or pending. This new mechanism replaces the previous ignoreNext logic, providing more granular control over the open/close state.
  • Improved Event Handling in BaseSelect: Updated onRootBlur and onRootMouseDown within the BaseSelect component to leverage the new weak flag in triggerOpen calls. This ensures more robust and predictable control over the select's open/close state during various user interactions, preventing unintended state changes.
  • Enhanced Test Code Readability: Replaced magic numbers (e.g., 40 for DOWN, 13 for ENTER) with KeyCode constants in Select.test.tsx. This change improves the clarity and maintainability of the test suite.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 refactors the open/close logic for the select component by introducing a weak update mechanism to better handle race conditions, for instance, when a blur event fires after a click inside the popup. The changes in BaseSelect/index.tsx and useSelectTriggerControl.ts correctly adopt this new mechanism. Additionally, the tests have been improved by replacing magic numbers for key codes with KeyCode enum members, which enhances readability.

However, I've identified a potential issue in the new implementation within useOpen.ts. The lock intended to prevent weak updates is released immediately, which could lead to the very race conditions this change aims to prevent. I've provided a suggestion to fix this by reintroducing a delayed unlock, similar to the previous logic.

@zombieJ
Copy link
Member Author

zombieJ commented Dec 5, 2025

@gemini-code-assist 请帮忙重新 CR 一下

Copy link

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

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 refactors the open/close logic for the Select component, improving its robustness. The changes replace a lock-based mechanism with a more explicit cancelFun callback and better event target tracking. This simplifies the useOpen hook and related event handlers. Additionally, magic numbers for key codes in tests have been replaced with named constants, which improves readability. My only finding is a leftover console.log statement in a test file that should be removed.


toggleOpen(container);

console.log('!~~~~~~~~');

Choose a reason for hiding this comment

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

medium

A console.log statement has been left in the test file. This should be removed before merging as it adds noise to test outputs.

@zombieJ zombieJ marked this pull request as ready for review December 5, 2025 07:04
@zombieJ zombieJ merged commit 5033561 into master Dec 5, 2025
11 of 12 checks passed
@zombieJ zombieJ deleted the adjust-order branch December 5, 2025 07:04
zombieJ added a commit that referenced this pull request Dec 5, 2025
* chore: use weak instead

* chore: adjust

* chore: adjust

* chore: clean up

* chore: clean up
zombieJ added a commit that referenced this pull request Dec 5, 2025
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.

2 participants