Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

test(ui): run leftover rAF callbacks at teardown instead of dropping them (MUL-9984) (#11324)

Jiayuan Zhang30f350c8f220
diff --git a/packages/ui/components/ui/__tests__/collapsible.test.tsx b/packages/ui/components/ui/__tests__/collapsible.test.tsx
index 513c726295..b17ece91ef 100644
--- a/packages/ui/components/ui/__tests__/collapsible.test.tsx
+++ b/packages/ui/components/ui/__tests__/collapsible.test.tsx
@@ -5,9 +5,6 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../collapsi
afterEach(() => {
cleanup();
- // Base UI shares one frame scheduler across panels; a frame left queued by
- // one test would swallow the next test's frame requests.
- flushRaf();
delete (Element.prototype as { getAnimations?: unknown }).getAnimations;
delete (HTMLElement.prototype as { scrollHeight?: unknown }).scrollHeight;
});
diff --git a/packages/ui/test/setup.ts b/packages/ui/test/setup.ts
index 24caf964a7..d4cb0bf80a 100644
--- a/packages/ui/test/setup.ts
+++ b/packages/ui/test/setup.ts
@@ -51,7 +51,25 @@ declare global {
globalThis.triggerResizeObservers = ResizeObserverStub.triggerAll;
-afterEach(() => {
+// Run leftover frames instead of dropping them: Base UI's module-level frame
+// scheduler only requests a new frame after its pending one has run, so a
+// dropped frame stalls every later Base UI animation in the same file.
+const MAX_TEARDOWN_FRAMES = 100;
+
+function drainRaf(): void {
+ for (let i = 0; i < MAX_TEARDOWN_FRAMES && rafQueue.length > 0; i++) {
+ for (const cb of rafQueue.splice(0, rafQueue.length)) {
+ try {
+ cb?.(performance.now());
+ } catch {
+ // The component is already unmounted; its late frame has nothing to update.
+ }
+ }
+ }
rafQueue.length = 0;
+}
+
+afterEach(() => {
+ drainRaf();
roInstances.length = 0;
});