Skip to content

Commit a60c0d1

Browse files
cliffhallclaude
andcommitted
test(web): tighten the review-trail comments (round 2)
Comment-accuracy follow-ups from PR #1793 round 2 (test infra only, no behavior change): - DEFAULT_SETTLE_MS: drop the false "Mantine's default header transitions run ~300ms" attribution (300ms is ViewHeader's HEADER_ANIM_MS; Mantine's Transition default is 250ms). Justify 500ms generically — a typical few-hundred-ms transition plus rAF slack. - settleTransitions doc: stop asserting a single escape mechanism as fact. State what's observed (a post-teardown dispatchSetState throwing from resolveUpdatePriority, which runs synchronously inside dispatchSetState), what's known (useTransition has an unmount cleanup), and that the exact escape route isn't pinned down — the act-wrapped drain fixes it regardless. - setup.ts: happy-dom v20 does implement matchMedia, so reframe the block as a deliberate override (pinning prefers-reduced-motion: reduce) rather than a polyfill for a missing API. - Export MantineRenderOptions so callers can name the options type. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5
1 parent 5834cd2 commit a60c0d1

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

‎clients/web/src/test/renderWithMantine.tsx‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { theme } from "../theme/theme";
88
// `wrapper`, which we own) plus an optional forced `colorScheme`. The default
99
// is "light"; pass "dark" to exercise `useComputedColorScheme` dark branches
1010
// without hand-rolling a bare `MantineProvider` (the #1760 anti-pattern).
11-
type MantineRenderOptions = Omit<RenderOptions, "wrapper"> & {
11+
export type MantineRenderOptions = Omit<RenderOptions, "wrapper"> & {
1212
colorScheme?: MantineColorScheme;
1313
};
1414

@@ -52,26 +52,30 @@ export function renderWithMantineTransitions(
5252
return render(ui, { wrapper: makeWrapper("default", colorScheme), ...rest });
5353
}
5454

55-
// Fallback settle window: Mantine's default header transitions run ~300ms, so
56-
// 500ms clears them plus the two-frame rAF scheduling slack. Callers that know
57-
// their component's animation duration should pass it (duration + slack) rather
58-
// than rely on this.
55+
// Fallback settle window: ≈500ms clears a typical few-hundred-millisecond
56+
// transition plus the two-frame rAF scheduling slack. Callers that know their
57+
// component's animation duration should pass it (duration + slack) rather than
58+
// rely on this default.
5959
const DEFAULT_SETTLE_MS = 500;
6060

6161
// Flush any in-flight `renderWithMantineTransitions` animation before the test
62-
// ends. Mantine's `useTransition` cancels its own timers on unmount (its
63-
// `useEffect` cleanup clears the rAF + `setTimeout`), so the hazard isn't a
64-
// timer surviving unmount — it's the React state update that Mantine's inner
65-
// rAF schedules *outside* `act` (`setStatus("entering"/"exiting")` → the
66-
// terminal `setStatus`). Left in flight, that work resolves after happy-dom
67-
// tears down `window` and throws `ReferenceError: window is not defined` from
68-
// react-dom's `dispatchSetState → resolveUpdatePriority`, failing the whole run
69-
// even when every assertion passed (#1760/#1786). This awaits a real timer
70-
// inside `act` so those queued rAF callbacks and the React updates they schedule
71-
// run and flush against the still-mounted tree — the ordering that keeps the
72-
// settling `setState` on a live component. Because it awaits a *real*
73-
// `setTimeout`, it deadlocks under fake timers, so guard against that with a
74-
// clear message rather than a 5s test-timeout hang.
62+
// ends. What's observed when it isn't flushed: an in-flight Mantine transition
63+
// produces an uncaught, post-teardown `dispatchSetState` that throws
64+
// `ReferenceError: window is not defined` from react-dom's
65+
// `resolveUpdatePriority` (React 19 reads `window.event` there) — after
66+
// happy-dom has torn down `window` — failing the whole run even though every
67+
// assertion passed (#1760/#1786). What's known: Mantine's `useTransition` does
68+
// have an unmount cleanup (`useEffect` clearing its rAF + `setTimeout`), yet the
69+
// failing frame is an rAF callback executing *after* teardown, so the precise
70+
// escape route (a cancelAnimationFrame that doesn't fully cancel under
71+
// happy-dom, an rAF re-armed after cleanup, or a scheduler-flushed
72+
// continuation) isn't pinned down. The fix doesn't depend on which: awaiting a
73+
// real timer inside `act` drains the queued rAF callbacks, the terminal
74+
// `setTimeout`, and the React work they schedule against the still-mounted tree
75+
// — whichever is the actual escapee, it resolves on a live component before
76+
// cleanup unmounts. Because it awaits a *real* `setTimeout`, it deadlocks under
77+
// fake timers, so guard against that with a clear message rather than a 5s
78+
// test-timeout hang.
7579
export async function settleTransitions(ms: number = DEFAULT_SETTLE_MS) {
7680
if (vi.isFakeTimers()) {
7781
throw new Error(

‎clients/web/src/test/setup.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ Object.defineProperty(globalThis, "fetch", {
5757
),
5858
});
5959

60-
// happy-dom doesn't implement `matchMedia`, so anything reading it (Mantine's
61-
// `useReducedMotion`, `useMediaQuery`-driven layout) would otherwise throw.
62-
// Provide a stub. We report `prefers-reduced-motion: reduce` and keep all other
63-
// queries `false` (matching the prior absent-matchMedia layout behavior). Note
64-
// this does *not*, on its own, disable Mantine transitions: `useTransition`
65-
// only honors reduced motion when `theme.respectReducedMotion` is true, and
66-
// Mantine 8 defaults it to `false` (the project theme doesn't override it). The
67-
// actual protection against the #1760 post-teardown `window is not defined`
68-
// leak is `env="test"` in `renderWithMantine`, which forces transitions
69-
// synchronous regardless; this stub just keeps `matchMedia` callers from
70-
// blowing up. Tests that need specific media results still mock `@mantine/hooks`
71-
// or stub `matchMedia` themselves.
60+
// happy-dom (v20) *does* implement `matchMedia`/`MediaQueryList`, so this isn't
61+
// a polyfill for a missing API — it's a deliberate **override** of happy-dom's
62+
// implementation, pinning `prefers-reduced-motion: reduce` and reporting `false`
63+
// for every other query (preserving the historical absent-matchMedia layout
64+
// behavior for `useMediaQuery`-driven code). Note this does *not*, on its own,
65+
// disable Mantine transitions: `useTransition` only honors reduced motion when
66+
// `theme.respectReducedMotion` is true, and Mantine 8 defaults it to `false`
67+
// (the project theme doesn't override it). The actual protection against the
68+
// #1760 post-teardown `window is not defined` leak is `env="test"` in
69+
// `renderWithMantine`, which forces transitions synchronous regardless. Tests
70+
// that need specific media results still mock `@mantine/hooks` or stub
71+
// `matchMedia` themselves.
7272
Object.defineProperty(window, "matchMedia", {
7373
configurable: true,
7474
writable: true,

0 commit comments

Comments
 (0)