Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Nov 27, 2025

Summary by CodeRabbit

发布说明

  • 错误修复

    • 优化弹出窗口的初始可见性控制,确保 defaultPopupVisible 属性在初始渲染时按预期生效,改善默认显示行为。
  • 测试

    • 新增测试用例验证默认可见性(defaultPopupVisible)的正确性,提升行为回归保障。

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

@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 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.

Walkthrough

将 Trigger 组件的内部 open 状态从 useState 迁移到 useControlledState,移除 popupVisible 到内部状态的同步副作用,统一使用 internalOpen 管理弹窗可见性;新增 defaultPopupVisible 的测试覆盖并调整示例导入方式。

Changes

分组 / 文件(s) 变更摘要
状态管理重构
src/index.tsx
将 open 状态由 useState 改为 useControlledState 实现受控/非受控模式;移除基于 popupVisible 的同步 effect 和原先的 mergedOpen 派生逻辑;替换所有 setMergedOpen 调用为 setInternalOpen;调整触发逻辑以通过 setInternalOpen(nextOpen) 更新。
测试用例更新
tests/basic.test.jsx
触发器用法格式化(多行改单行);新增 defaultPopupVisible should work 测试,验证 defaultPopupVisible 时弹窗默认渲染(存在 .rc-trigger-popup)。
示例/类型导入调整
docs/examples/point.tsx
ActionType 改为类型导入(type-only),并将 Trigger 改为默认导入,保持运行时行为不变。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Consumer as 使用方
  participant Trigger as Trigger 组件
  participant useControlled as useControlledState

  Note over Consumer,Trigger: 初始化
  Consumer->>Trigger: 提供 props (maybe popupVisible / defaultPopupVisible)
  Trigger->>useControlled: 初始化 internalOpen (依据 props)
  useControlled-->>Trigger: internalOpen state

  alt 用户/事件 触发打开/关闭
    Consumer->>Trigger: click / hover / internal event
    Trigger->>useControlled: setInternalOpen(nextOpen)
    useControlled-->>Trigger: internalOpen 更新
    Trigger->>Consumer: render popup (based on internalOpen)
  end

  Note over Trigger: 不再同步外部 popupVisible 到 internalOpen(无后续 effect)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 分钟

可能需额外关注:

  • useControlledState 的实现边界(初始值、受控切换、回调语义)。
  • 移除同步 effect 后是否会导致外部 popupVisible 无法驱动后续更新(兼容性回归)。
  • 测试中新增用例的健壮性与边界场景(受控 props + defaultPopupVisible 组合)。

Possibly related PRs

Suggested reviewers

  • MadCcc

我是小兔写代码,轻敲键盘数星光 🐰
状态从旧巢跳出,受控非受控各安放
同步烟雾已散尽,内态独自跳跃忙
测试点亮新一行,弹窗初现笑开场 ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地反映了主要变更内容——修复 defaultPopupVisible 功能,与代码改动(引入受控状态模式和添加相关测试)完全相关。

📜 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 fa9f855 and a7bb6e7.

📒 Files selected for processing (2)
  • docs/examples/point.tsx (1 hunks)
  • src/index.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.

@gemini-code-assist
Copy link
Contributor

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 internal state management of the Trigger component to properly handle the defaultPopupVisible prop. By integrating the useControlledState hook, the component now correctly initializes its popup's visibility based on the defaultPopupVisible prop, addressing a previous issue where this prop might not have functioned as expected. This change streamlines the state logic and improves the reliability of the component's initial rendering behavior.

Highlights

  • State Management Refactor: The internal state management for popup visibility has been refactored to utilize the useControlledState hook, simplifying the logic for handling both controlled and uncontrolled open states.
  • Fix defaultPopupVisible: The defaultPopupVisible prop now correctly initializes the popup's open state, addressing a previous issue where it might not have functioned as expected.
  • Code Simplification: Redundant useLayoutEffect and setMergedOpen logic were removed, as their functionality is now encapsulated within the useControlledState hook.
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
Contributor

@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 addresses an issue with defaultPopupVisible by refactoring the component's state management. The introduction of the useControlledState hook is a significant improvement, simplifying the logic for handling both controlled and uncontrolled states of the popup's visibility. This change removes complex manual state synchronization, making the code cleaner and more robust. The addition of a specific test case for defaultPopupVisible ensures the fix is effective and prevents future regressions. The changes are well-implemented, with one minor point of feedback regarding an unused import.

@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.40%. Comparing base (bc399d2) to head (a7bb6e7).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #592      +/-   ##
==========================================
- Coverage   96.42%   96.40%   -0.02%     
==========================================
  Files          17       17              
  Lines         952      947       -5     
  Branches      277      279       +2     
==========================================
- Hits          918      913       -5     
  Misses         34       34              

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

@zombieJ zombieJ merged commit ec7342a into master Nov 27, 2025
9 checks passed
@zombieJ zombieJ deleted the fix-default-open branch November 27, 2025 09:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/basic.test.jsx (1)

994-1002: defaultPopupVisible 用例覆盖到关键行为,建议补一个最小 popup(可选)

这个测试很好地验证了:在不触发任何事件的情况下,defaultPopupVisibletrue 时会默认渲染 .rc-trigger-popup,能防止这类回归再次出现。

唯一的小建议是:TriggerPropspopup 是必填属性,示例代码里省略了它,在类型层面略微违背组件约定。可以考虑补一个空的节点,使测试更贴近真实用法,例如:

-    render(
-      <Trigger defaultPopupVisible>
-        <div className="target" />
-      </Trigger>,
-    );
+    render(
+      <Trigger defaultPopupVisible popup={<span />}>
+        <div className="target" />
+      </Trigger>,
+    );

这不会改变断言逻辑,但能让用例在语义上更一致。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc399d2 and fa9f855.

📒 Files selected for processing (2)
  • src/index.tsx (4 hunks)
  • tests/basic.test.jsx (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/basic.test.jsx (2)
docs/examples/simple.tsx (1)
  • render (193-382)
docs/examples/point.tsx (1)
  • render (34-86)
🪛 GitHub Actions: ✅ test
src/index.tsx

[error] 10-10: useLayoutUpdateEffect is defined but never used. (no-unused-vars) ESLint: @typescript-eslint/no-unused-vars

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
tests/basic.test.jsx (1)

371-377: children renderProps 用例调整合理

这里将 Trigger 写成单行并显式传入 popupVisible={true},依然能够让 renderProps 拿到 { open: true } 并渲染 "true",测试逻辑清晰且不依赖异步行为,看起来是一次纯风格层面的改动,可以保持。

src/index.tsx (1)

309-315: open 状态经 internalOpen/mergedOpen 统一后逻辑更清晰、行为集中

  • 通过 internalOpenmergedOpen = internalOpen || false 把「可能为 undefined」的状态统一成布尔值,后续 renderProps、对齐、滚动关闭、ResizeObserver 等逻辑只依赖 mergedOpen,读起来更直观。
  • internalTriggerOpen 内部使用 lastTriggerRef 只在实际开关状态变化时才触发 onOpenChange / onPopupVisibleChange,可以有效避免 pointer + mouse 事件组合触发两次回调的问题。
  • 结合新增的 defaultPopupVisible 测试以及已有的「popupVisibleundefinedfalse 间切换」测试,这一段重构与当前用例预期是一致的,没有明显的行为回归风险。

总体来看,这部分状态管理改动可以保留。

Also applies to: 380-392

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