fix: prevent makeBodyVisible timeout from running after test teardown#22972
fix: prevent makeBodyVisible timeout from running after test teardown#22972anikdhabal merged 2 commits intomainfrom
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 defineddue to a recursive timeout from themakeBodyVisiblefunction continuing to run after test environment teardown.Root cause: The
makeBodyVisiblefunction 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 (afterEachblock) 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
makeBodyVisiblefunction, 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→setTimeoutchainafterEachdoesn'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.tsin CI over several runs to confirm stable behavior, particularly watching for the original "Unhandled Errors" section that contained theReferenceError: document is not defined.Diagram
%%{ init : { "theme" : "default" }}%% graph TD TestFile["packages/embeds/embed-core/src/<br/>__tests__/embed-iframe.test.ts"]:::major-edit EmbedIframe["packages/embeds/embed-core/src/<br/>embed-iframe.ts"]:::context UtilsFile["packages/embeds/embed-core/src/<br/>embed-iframe/lib/utils.ts"]:::context TestFile -->|"calls functions that trigger"| EmbedIframe EmbedIframe -->|"makeBodyVisible() uses"| UtilsFile UtilsFile -->|"runAsap() creates setTimeout"| Timeout["Recursive setTimeout<br/>(50ms intervals)"]:::context Timeout -->|"continues after test teardown<br/>causing ReferenceError"| Error["document is not defined<br/>CI failure"]:::context TestFile -->|"vi.clearAllTimers() in afterEach<br/>now prevents"| Error subgraph Legend L1["Major Edit"]:::major-edit L2["Minor Edit"]:::minor-edit L3["Context/No Edit"]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
vi.clearAllTimers()alone would be sufficient