fix(site): flush deferred Radix focus-scope timer before jsdom teardown#26983
Draft
EhabY wants to merge 2 commits into
Draft
fix(site): flush deferred Radix focus-scope timer before jsdom teardown#26983EhabY wants to merge 2 commits into
EhabY wants to merge 2 commits into
Conversation
Radix's FocusScope defers its unmount event dispatch and focus restore with setTimeout(0). The cleanup() in the shared afterEach schedules that timer, and for the last test in a file it could still be pending when vitest tears down the jsdom environment. The callback then constructs a CustomEvent from Node's built-in constructor instead of jsdom's, and jsdom rejects the dispatch with "parameter 1 is not of type 'Event'" as an unhandled error, failing the run. Await one timer turn in afterAll, while the jsdom environment is still alive, to deterministically drain the 0ms timers scheduled by cleanup(). Timers with the same delay run in FIFO order, so this is not a race. Fixes coder/internal#1613
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UserDropdownContent.test.tsxintermittently fails CI with an unhandled error:Radix's
FocusScopedefers its unmount dispatch withsetTimeout(0). The sharedafterEachcleanup()schedules that timer, and for the last test in a file it can still be pending when vitest tears down the per-file jsdom environment. It then fires with Node's built-inCustomEventinstead of jsdom's, and the dispatch throws. Any test file whose last test unmounts a focus-trapped Radix component (Dialog, Popover, DropdownMenu) can hit this.Await one timer turn in the shared
afterAll, before environment teardown. Same-delay timers run in FIFO order, so this deterministically drains the pending timer rather than shrinking the race window. Costs ~1ms per test file; avi.isFakeTimers()guard keeps the flush from hanging if a file leaves fake timers installed.Verified with A/B stress runs alternating main's and this branch's
msw.ts, 20 jsdom teardowns per invocation:All main failures match the CI error signature exactly; the full unit suite passes.
Closes coder/internal#1613
This PR was generated by Coder Agents on behalf of @EhabY.