fix: add motionDeadline to to fix the preview not be removed when the preview closed immediately after opening#508
Conversation
… preview closed immediately after opening
|
@Emiyaaaaa is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 13 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough在 Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Code Review
This pull request introduces a motionDeadline of 500ms to the Preview component's motion configuration. Feedback suggests that this hardcoded value might prematurely terminate custom animations that exceed 500ms, recommending either increasing the deadline to 1000ms or exposing it as a configurable property.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/Preview/index.tsx (1)
431-431: 建议将截止时间提取为具名常量,减少魔法数字。Line 431 的
motionDeadline={1000}直接写数字降低了可读性和可维护性。建议提取为常量(如PREVIEW_MOTION_DEADLINE_MS),并注明该值应大于 CSS 动画时长(当前 0.3s),以确保动画完成后再触发兜底机制。这样当样式中的transition时长调整时,也能及时同步更新此处。♻️ 建议修改
+const PREVIEW_MOTION_DEADLINE_MS = 1000; ... <CSSMotion motionName={motionName} visible={portalRender && open} motionAppear motionEnter motionLeave - motionDeadline={1000} + motionDeadline={PREVIEW_MOTION_DEADLINE_MS} onVisibleChanged={onVisibleChanged} >🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Preview/index.tsx` at line 431, Extract the magic number passed to the Preview component as a named constant (e.g., PREVIEW_MOTION_DEADLINE_MS) instead of the inline literal used in motionDeadline={1000}; define the constant near the top of the module and use it in motionDeadline, and add a short comment that the value must be greater than the CSS transition duration (currently 0.3s) so maintainers update both when changing animation timing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/Preview/index.tsx`:
- Line 431: Extract the magic number passed to the Preview component as a named
constant (e.g., PREVIEW_MOTION_DEADLINE_MS) instead of the inline literal used
in motionDeadline={1000}; define the constant near the top of the module and use
it in motionDeadline, and add a short comment that the value must be greater
than the CSS transition duration (currently 0.3s) so maintainers update both
when changing animation timing.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 00fb93f5-5059-4de3-a7bd-c26e56fac4dd
📒 Files selected for processing (1)
src/Preview/index.tsx
问题描述
点击image打开图片预览弹窗的同时,立即按esc关闭时,预览弹窗不可见但是dom没有移除导致页面无法点击
复现步骤
antd https://ant.design/components/image-cn 中可以手动复现(点击图片打开预览的同时按esc关闭预览)
(视频中第一次手速慢了失败了,第二次复现成功)
test.MOV
rc-image 和 rc-motion 中可以代码方式复现(不稳定复现,但概率较大)
问题原因
打开预览后快速关闭时,rc-motion 中 dom 的
transitionend事件有概率不会触发,导致跳过后续的处理逻辑。代码位于react-component/motion/src/hooks/useDomMotionEvents.ts解决方案
设置 rc-motion 的
motionDeadline字段,同时在 bug 产生到 Deadline 兜底的这段时间,添加点击穿透的处理