fix: destroyOnHidden should work when forceRender is true - #581
fix: destroyOnHidden should work when forceRender is true#581EmilyyyLiu wants to merge 4 commits into
Conversation
- Fix logic to use animatedVisible to check if component has ever been opened - Add test case for forceRender + destroyOnHidden scenario Co-Authored-By: Claude <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
Next review available in: 3 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Walkthrough调整 Changes对话框隐藏销毁
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 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 |
There was a problem hiding this comment.
Code Review
This pull request modifies the destruction logic in DialogWrap to ensure the component is destroyed when destroyOnHidden is true, even if forceRender is enabled, and adds a corresponding test. However, the reviewer identified a critical regression where the new condition causes the dialog to unmount immediately when visible becomes false, which skips close animations and prevents afterClose from being called. A solution using a ref to track whether the dialog has ever been opened was suggested to resolve this issue.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #581 +/- ##
==========================================
+ Coverage 98.94% 98.95% +0.01%
==========================================
Files 8 8
Lines 190 192 +2
Branches 69 69
==========================================
+ Hits 188 190 +2
Misses 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- Use hasOpenedRef to track if dialog has ever been opened - Wait for afterClose callback before destroying (preserves animation) - Fixes regression where dialog would unmount immediately without animation
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/index.spec.tsx (1)
180-186: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win增加对卸载时机(动画期间)的断言。
为了防止上述立即卸载的 Bug 再次出现,建议在触发
visible={false}之后、动画计时器运行之前,验证 DOM 元素尚未被卸载。这样能真正测试组件是否在等待动画结束(afterClose)后才执行销毁操作。♻️ 建议的重构
// Hide - should destroy because destroyOnHidden is true rerender(<Demo visible={false} />); + + // 验证在动画结束前,元素仍存在于 DOM 中 + expect(document.querySelectorAll('.test-force-destroy')).toHaveLength(1); + act(() => { jest.runAllTimers(); }); expect(document.querySelectorAll('.test-force-destroy')).toHaveLength(0); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/index.spec.tsx` around lines 180 - 186, Update the destroyOnHidden test around the visible=false rerender to assert that .test-force-destroy is still present before jest.runAllTimers executes, then retain the existing assertion that it is removed after timers complete, verifying destruction occurs only after the close animation finishes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/DialogWrap.tsx`:
- Around line 50-54: Update the destroy-on-hidden condition in DialogWrap to
check !animatedVisible instead of !visible, while retaining destroyOnHidden and
hasOpenedRef.current. This must keep the Dialog mounted during the closing
animation and only return null after animatedVisible becomes false following
afterClose.
---
Nitpick comments:
In `@tests/index.spec.tsx`:
- Around line 180-186: Update the destroyOnHidden test around the visible=false
rerender to assert that .test-force-destroy is still present before
jest.runAllTimers executes, then retain the existing assertion that it is
removed after timers complete, verifying destruction occurs only after the close
animation finishes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 682cced5-37b2-4761-8b04-cb5011c03ac9
📒 Files selected for processing (2)
src/DialogWrap.tsxtests/index.spec.tsx
- Add !animatedVisible to condition to ensure exit animation plays - afterClose callback will be called before destroying component
- Use hasOpenedRef initialized with visible prop to track opened state - Add !animatedVisible to wait for animation before destroy - Fixes exit animation being interrupted
Description
修复 forceRender 在 时destroyOnHidden不生效的问题。
Problem
当同时设置 和 时,隐藏对话框后内容不会被销毁,这与预期行为不符。
Solution
修改判断逻辑,使用 来检查组件是否曾经打开过,而不是依赖 和 的组合条件。
关联issue
ant-design/ant-design#28847
Changes
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug 修复
测试