-
Notifications
You must be signed in to change notification settings - Fork 10.4k
fix: prevent makeBodyVisible timeout from running after test teardown #22972
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: prevent makeBodyVisible timeout from running after test teardown #22972
Conversation
- Add timeout tracking to makeBodyVisible function to enable cleanup - Add vi.clearAllTimers() to test teardown to clear recursive timeouts - Prevents 'ReferenceError: document is not defined' in CI tests Fixes intermittent test failures where makeBodyVisible recursive timeout continues running after test environment is torn down. Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
WalkthroughThe Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (2)**/*.ts📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Files:
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
The
Both callers don't use the return value, so changing the function signature from |
Good question! Both changes are actually needed for a complete fix: Why alone isn't sufficient:
Why the timeout tracking is necessary:
The combination ensures robust cleanup: handles fake timers, and the timeout tracking handles any real timers that might slip through. |
Based on code review feedback, test if vi.clearAllTimers() alone is sufficient without modifying makeBodyVisible function. - Reverted makeBodyVisible function changes - Kept only vi.clearAllTimers() in test teardown - Verified with multiple test runs and type checking Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
✅ Investigation Results: You were absolutely right! I tested the simplified approach (using only Testing performed:
Why
Updated the PR to use only the simplified approach. Thanks for the excellent suggestion - this is definitely the better solution! 🎯 |
27c8cae
to
12eee13
Compare
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (08/08/25)1 reviewer was added to this PR based on Keith Williams's automation. |
E2E results are ready! |
…calcom#22972) * fix: prevent makeBodyVisible timeout from running after test teardown - Add timeout tracking to makeBodyVisible function to enable cleanup - Add vi.clearAllTimers() to test teardown to clear recursive timeouts - Prevents 'ReferenceError: document is not defined' in CI tests Fixes intermittent test failures where makeBodyVisible recursive timeout continues running after test environment is torn down. Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * simplify: use only vi.clearAllTimers() to fix timeout issue Based on code review feedback, test if vi.clearAllTimers() alone is sufficient without modifying makeBodyVisible function. - Reverted makeBodyVisible function changes - Kept only vi.clearAllTimers() in test teardown - Verified with multiple test runs and type checking Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
fix: prevent makeBodyVisible timeout from running after test teardown
Summary
Fixed a frequently failing unit test in CI that was throwing
ReferenceError: document is not defined
due to a recursive timeout from themakeBodyVisible
function continuing to run after test environment teardown.Root cause: The
makeBodyVisible
function usesrunAsap()
(a 50ms setTimeout wrapper) to recursively call itself, ensuring the document body stays visible. In tests, this recursive timeout would sometimes continue running after the test environment was cleaned up, causing the "document is not defined" error when it tried to accessdocument.body
.Solution: Added
vi.clearAllTimers()
to the test teardown (afterEach
block) to ensure all pending timers are cleared before switching back to real timers. This prevents the recursive timeout from executing after the test environment is destroyed.Key decision: Initially implemented a comprehensive solution that tracked timeout IDs in the
makeBodyVisible
function, but based on code review feedback from @hariombalhara, simplified to use onlyvi.clearAllTimers()
which proved sufficient and much cleaner.Review & Testing Checklist for Human
vi.clearAllTimers()
effectively clears the recursive timeout created bymakeBodyVisible
→runAsap
→setTimeout
chainafterEach
doesn't negatively impact other tests in the same file or test suiteRecommended test plan: Monitor the specific test file
packages/embeds/embed-core/src/__tests__/embed-iframe.test.ts
in CI over several runs to confirm stable behavior, particularly watching for the original "Unhandled Errors" section that contained theReferenceError: document is not defined
.Diagram
Notes
vi.clearAllTimers()
alone would be sufficient