fix(site): flush deferred Radix focus-scope timer before jsdom teardown (#26983)

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 commit is contained in:
Ehab Younes
2026-07-06 12:14:44 +03:00
committed by GitHub
parent dd216b96fe
commit f444c6f585
+11 -1
View File
@@ -8,4 +8,14 @@ afterEach(() => {
server.resetHandlers();
vi.clearAllMocks();
});
afterAll(() => server.close());
afterAll(async () => {
// A leftover fake clock would make the timer flush below hang.
if (vi.isFakeTimers()) {
vi.useRealTimers();
}
// Radix FocusScope defers its unmount dispatch with setTimeout(0). Flush
// it before vitest tears down the jsdom environment, where it would throw
// an unhandled "parameter 1 is not of type 'Event'" TypeError.
await new Promise((resolve) => setTimeout(resolve, 0));
server.close();
});