Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Free lock if motion not start #472

Merged
merged 6 commits into from
Feb 11, 2025
Merged

fix: Free lock if motion not start #472

merged 6 commits into from
Feb 11, 2025

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 11, 2025

ref ant-design/ant-design#52625

Summary by CodeRabbit

  • 新增功能

    • 在演示组件中新增了一个“快速”按钮,可即时触发短暂显示对话框的交互效果。
  • 重构

    • 优化了对话框的关闭逻辑和引用处理,进一步整合交互流程,提升用户体验。
  • 构建和依赖维护

    • 更新了发布流程及构建脚本,同时调整了部分依赖项,确保项目持续稳定运作。
  • 测试

    • 改进了异步操作和组件引用的测试用例,增强了测试的准确性与稳定性。

Copy link

vercel bot commented Feb 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dialog ❌ Failed (Inspect) Feb 11, 2025 9:17am

Copy link

coderabbitai bot commented Feb 11, 2025

Warning

Rate limit exceeded

@zombieJ has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3c465b4 and fc9079d.

📒 Files selected for processing (2)
  • src/Dialog/Content/index.tsx (4 hunks)
  • src/Dialog/index.tsx (3 hunks)

Walkthrough

该 PR 在示例中为 Demo 组件增加了一个 “quick” 按钮,实现点击后快速显示并自动隐藏对话框。同时,更新了构建和发布脚本,调整了 package.json 中的依赖(如移除 @babel/runtimerc-motion,添加 @rc-component/motion@rc-component/np,更新 @rc-component/father-plugin 版本)。此外,对话框组件内部也进行了优化:重命名了类型(从 ContentRef 到 PanelRef)、更新了 CSSMotion 的导入、提取了关闭逻辑至新函数 doClose,并调整了相关测试用例。

Changes

文件 变更摘要
docs/…/multiple-Portal.tsx 在 Demo 组件中新增 “quick” 按钮,点击后设置状态显示对话框,并通过 0 毫秒超时恢复状态。
package.json 更新发布脚本(由 np --yolo --no-publish 改为 rc-np),移除 @babel/runtimerc-motion,添加 @rc-component/motion@rc-component/np,同时更新 @rc-component/father-plugin 版本。
src/Dialog/** - 在 Panel 组件中将类型 ContentRef 重命名为 PanelRef,并更新了 React.forwardRef 泛型。
- 在 Content 组件中更新 CSSMotion 导入、增加 ContentRef 类型及新方法,并调整 ref 处理。
- 在 Mask 组件中更新 CSSMotion 导入。
- 在 Dialog 组件中新增 doClose 函数封装关闭逻辑,并更新 Content 导入。
tests/** 更新测试文件中 Provider 和 CSSMotion 的导入路径至 @rc-component/motion,同时修改 mock 实现并在 afterClose 测试中用 act() 包装 jest.runAllTimers() 调用。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant D as Demo组件
    participant Dialog as 对话框

    U->>D: 点击 "quick" 按钮
    D->>Dialog: 设置 showDialog = true
    Dialog-->>D: 对话框显示
    D->>Dialog: 0 毫秒超时后设置 showDialog = false
    Dialog-->>D: 对话框隐藏
Loading
sequenceDiagram
    participant D as Dialog组件
    participant doClose as doClose函数
    participant S as 系统

    D->>D: onDialogVisibleChanged(visible=false)
    D->>doClose: 调用 doClose()
    doClose->>S: 清理滚动状态及恢复焦点
    doClose->>D: 触发 afterClose 回调
Loading

Possibly related PRs

Suggested reviewers

  • thinkasany

Poem

我是一只快乐的小兔,
跳跃在代码的草地间,
“quick” 按钮轻点一瞬,
对话框悄然启封后又关,
更新依赖如春风拂面,
编码乐章中我蹦跳无限! 🐰
代码世界,花开不断!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

socket-security bot commented Feb 11, 2025

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@rc-component/[email protected] None 0 89.1 kB zombiej
npm/@rc-component/[email protected] Transitive: environment, eval, filesystem, shell, unsafe +140 18.2 MB zombiej

View full report↗︎

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: 2

🔭 Outside diff range comments (1)
src/Dialog/Content/index.tsx (1)

77-77: ⚠️ Potential issue

修复 ref 类型不匹配问题

当前 dialogRef 的类型与 CSSMotion 组件期望的 ref 类型不匹配。

建议使用 CSSMotionRef 类型:

-ref={dialogRef}
+ref={dialogRef as any} // 临时修复

更好的解决方案是定义正确的类型:

import type { CSSMotionRef } from '@rc-component/motion';

const dialogRef = useRef<CSSMotionRef>();
🧰 Tools
🪛 GitHub Actions: ✅ test

[error] 77-77: Type 'MutableRefObject<{ nativeElement: HTMLDivElement; inMotion: () => boolean; }>' is not assignable to type 'LegacyRef'.

🧹 Nitpick comments (2)
docs/examples/multiple-Portal.tsx (1)

48-58: 建议优化快速显示/隐藏对话框的实现方式

当前实现使用 setTimeout(fn, 0) 来立即隐藏对话框可能不是最佳方案:

  • 这种方式可能导致不稳定的行为,因为 0ms 延迟并不保证立即执行
  • 对于测试动画行为来说不够可靠

建议使用以下实现:

-      <button
-        type="button"
-        onClick={() => {
-          setShowDialog(true);
-          setTimeout(() => {
-            setShowDialog(false);
-          }, 0);
-        }}
-      >
-        quick
-      </button>
+      <button
+        type="button"
+        onClick={() => {
+          // 使用 requestAnimationFrame 来确保状态更新在下一帧执行
+          setShowDialog(true);
+          requestAnimationFrame(() => {
+            setShowDialog(false);
+          });
+        }}
+      >
+        quick
+      </button>
src/Dialog/index.tsx (1)

164-170: 建议简化 useEffect 中的条件判断

当前条件判断较为复杂,可以提取为一个命名良好的变量以提高可读性。

+    const shouldCloseImmediately = 
+      animatedVisible && 
+      contentRef.current.enableMotion() && 
+      !contentRef.current.inMotion();
+
-    } else if (
-      animatedVisible &&
-      contentRef.current.enableMotion() &&
-      !contentRef.current.inMotion()
-    ) {
+    } else if (shouldCloseImmediately) {
       doClose();
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffa313a and 3c465b4.

📒 Files selected for processing (8)
  • docs/examples/multiple-Portal.tsx (1 hunks)
  • package.json (2 hunks)
  • src/Dialog/Content/Panel.tsx (1 hunks)
  • src/Dialog/Content/index.tsx (4 hunks)
  • src/Dialog/Mask.tsx (1 hunks)
  • src/Dialog/index.tsx (3 hunks)
  • tests/index.spec.tsx (2 hunks)
  • tests/ref.spec.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • tests/ref.spec.tsx
  • src/Dialog/Mask.tsx
🧰 Additional context used
🪛 GitHub Actions: ✅ test
src/Dialog/Content/index.tsx

[error] 46-46: Property 'enableMotion' does not exist on type '{ nativeElement: HTMLDivElement; inMotion: () => boolean; }'.


[error] 77-77: Type 'MutableRefObject<{ nativeElement: HTMLDivElement; inMotion: () => boolean; }>' is not assignable to type 'LegacyRef'.

🔇 Additional comments (8)
src/Dialog/Content/Panel.tsx (1)

20-23: 类型重命名改进了代码清晰度

ContentRef 重命名为 PanelRef 更好地反映了该类型的用途和归属。

src/Dialog/index.tsx (1)

83-100: 提取的 doClose 函数改进了代码组织

将关闭逻辑集中到 doClose 函数中提高了代码的可维护性和可读性。

tests/index.spec.tsx (3)

3-3: 导入路径已更新

从 'rc-motion' 更新为 '@rc-component/motion',与包依赖变更保持一致。


9-25: Mock 实现已更新

Mock 路径和实现已更新以匹配新的包路径,保持了与实际代码的一致性。


518-520: 测试用例改进

使用 act() 包装 jest.runAllTimers() 调用,这是一个很好的改进,可以确保在测试期间正确处理所有状态更新。

Also applies to: 523-525

package.json (3)

40-40: 构建脚本更新

从 np 更新为 rc-np,这是一个更专业的发布工具。


55-55: 依赖更新

添加了 @rc-component/motion 作为新的动画实现依赖,替代了之前的 rc-motion。


58-59: 开发依赖更新

更新和添加了新的开发工具:

  • @rc-component/father-plugin 升级到 ^2.0.2
  • 新增 @rc-component/np ^1.0.3 用于发布流程

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.

Project coverage is 98.42%. Comparing base (ffa313a) to head (fc9079d).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Dialog/index.tsx 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #472      +/-   ##
==========================================
- Coverage   99.44%   98.42%   -1.03%     
==========================================
  Files           8        8              
  Lines         181      190       +9     
  Branches       60       64       +4     
==========================================
+ Hits          180      187       +7     
- Misses          1        3       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zombieJ zombieJ merged commit 53df080 into master Feb 11, 2025
9 of 12 checks passed
@zombieJ zombieJ deleted the bump-motion branch February 11, 2025 09:19
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