Repository navigation
test(Switch): detach the touch controllers each test attaches - #13017
Conversation
A test drives a tap's lift on a controller that it never detaches. The lift starts the 300 ms wait for the browser's click. When the file ends first, the wait outlives the test environment. Its timer then calls removeEventListener on a window that the environment has torn down, and Vitest reports an unhandled error for the file. The file's afterEach now detaches every controller that its tests attach. Detach ends the wait and clears its timer.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Switch · Storybook | 110.7 kB (0) · 10.4 kB CSS (0) | 1,784 (0) | — · ✓ · ✓ |
Package size: no published package changed; no new dependencies.
Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-rtl for RTL.
Generated by PR Enrichment workflow | View full report
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Approved pending CI. CI has not run on this head yet because the pull request is a draft from a fork: a maintainer adds the ci:run label so CI runs once it is marked ready for review.
The fix holds up: detaching every controller in afterEach ends the 300 ms browser-click wait that the tap-lift test starts, and with Vitest's teardown simulated after the last test, the reported TypeError appears without the change and not with it. No public API, shipped behaviour or release note changes.
Claims and files checked
Review mode: full; reason: no-earlier-review
Claims:
- Under load, a full
uirun on main can end with one unhandled error while every test passes: verified in mechanism by the simulated teardown; the round counts are the author's own measurement. - That error makes a local preflight fail: verified; preflight runs
vitest run --project ui, and Vitest exits non-zero on an unhandled error. - The error comes from the wait's timer in
browserClickWait.ts:90, throughstop, toinputStream.ts:244: verified; the reproduction shows the same frames. - The file passes when it runs alone: verified, 12 of 12 with and without the change.
- The file's tests and assertions do not change: verified.
browserClickWait.test.tsalready ends each wait in itsafterEach: verified (browserClickWait.test.ts:23-26).- The tap-lift test starts the 300 ms wait on a controller it never detaches: verified (
useSwitchTouch.test.ts:341,useSwitchTouch.ts:728). - Vitest's jsdom environment points
document.defaultViewat the Node global and deletesremoveEventListenerat teardown, whilesetTimeoutstays Node's own: verified in Vitest 4.1.11. - The file now records each controller and detaches them after each test: verified (
useSwitchTouch.test.ts:93,:114,:545,:156-158). - Lint-staged added braces for an existing
curlywarning: verified; the warning shows on main and not on this branch. - Only a test changes, so no Changeset is needed: verified against CONTRIBUTING.md.
- One timer is still pending at the end of the file on main and none with the change: verified (one 300 ms timer before, none after).
- No product, API, workflow or CI change: verified; one test file changes and the built API surface is identical.
- The file's tests, ESLint with zero warnings, Prettier and the Core typecheck pass: verified.
Files:
packages/core/src/Switch/useSwitchTouch.test.ts: clear.
|
/approve-spec 15ed46b |
|
/approve-spec 8265376 |
There was a problem hiding this comment.
Approved pending CI: the pull request is still a draft, so CI has not run on this head; it already carries ci:run, so marking it ready for review starts the run.
The merge of main leaves the patch unchanged and touches neither this test file nor the modules it exercises. Detaching every controller in afterEach ends the 300 ms browser-click wait that the tap-lift test starts, and with Vitest's teardown simulated after the last test, the reported TypeError appears without the change and not with it. No public API, shipped behaviour or release note changes.
Claims and files checked
Review mode: carry-forward; reason: none
Claims:
- Under load, a full
uirun on main can end with one unhandled error while every test passes: verified in mechanism by the simulated teardown; the round counts are the author's own measurement. - That error makes a local preflight fail: verified; preflight runs
vitest run --project ui, and Vitest exits non-zero on an unhandled error. - The error comes from the wait's timer in
browserClickWait.ts:90, throughstop, toinputStream.ts:244: verified; the reproduction shows the same frames, and those lines are unchanged at this head. - The file passes when it runs alone: verified, 12 of 12 with and without the change.
- The file's tests and assertions do not change: verified.
browserClickWait.test.tsalready ends each wait in itsafterEach: verified (browserClickWait.test.ts:23-26).- The tap-lift test starts the 300 ms wait on a controller it never detaches: verified (
useSwitchTouch.test.ts:341,useSwitchTouch.ts:728). - Vitest's jsdom environment points
document.defaultViewat the Node global and deletesremoveEventListenerat teardown, whilesetTimeoutstays Node's own: verified in Vitest 4.1.11, which the merge ofmaindoes not change. - The file now records each controller and detaches them after each test: verified (
useSwitchTouch.test.ts:93,:114,:545,:156-158). - Lint-staged added braces for an existing
curlywarning: verified; the warning shows without the change and not with it. - Only a test changes, so no Changeset is needed: verified against the contributing guide's Changeset rules.
- One timer is still pending at the end of the file on main and none with the change: verified (one 300 ms timer before, none after).
- No product, API, workflow or CI change: verified; one test file changes and the built API surface is identical.
- Public text carries no internal context: verified.
- The file's tests, ESLint with zero warnings, Prettier and the Core typecheck pass: verified before the merge of
main, which changes none of the file's inputs.
Files:
packages/core/src/Switch/useSwitchTouch.test.ts: clear.
|
/approve-spec 9e74a6b |
There was a problem hiding this comment.
Approved pending CI. The fast checks pass on this head, and this review's pass released the heavy suites, which were still running as it was written.
Detaching every controller in afterEach ends the 300 ms browser-click wait that the tap-lift test starts. Re-measured on this head: with Vitest's teardown simulated after the last test, the base tree reports the same TypeError with the same frames and one 300 ms timer still pending at the end of the file, while the head tree reports neither and the file passes 12 of 12 on both. No public API, shipped behaviour or release note changes, and the merge of main leaves the patch unchanged.
Claims and files checked
Review mode: carry-forward; reason: none
Claims:
- Under load a full
uirun on main can end with one unhandled error while every test passes: the mechanism is verified by the simulated teardown on the base tree; the round counts are the author's own measurement, which the review sandbox cannot reproduce. - That error turns a local preflight red: verified; preflight runs
vitest run --project ui, and Vitest exits non-zero on an unhandled error. - The error comes from the wait's timer at
browserClickWait.ts:90, throughstop, toinputStream.ts:244: verified; the base-tree reproduction prints exactly those frames. - The file passes when it runs alone: verified, 12 of 12 on both trees.
- The file's tests and assertions do not change: verified against the diff.
browserClickWait.test.tsalready ends each wait it starts in itsafterEach: verified (browserClickWait.test.ts:20-27).- The tap-lift test starts the 300 ms wait on a controller it never detaches: verified (
useSwitchTouch.test.ts:324,:341;useSwitchTouch.ts:592-611,:724-730). - Vitest's jsdom environment points
document.defaultViewat the Node global and deletesremoveEventListenerat teardown whilesetTimeoutstays Node's own: verified by the teardown simulation, which fails on the base tree only; the pinned Vitest version is unchanged by the merge. - The file now records each controller its tests attach and detaches them after each test: verified (
useSwitchTouch.test.ts:93,:114,:545,:156-158). - Lint-staged's
eslint --fixalso added braces for an existingcurlywarning: verified; ESLint reports that warning at:454on the base tree and nothing on the head. - One timer is still pending at the end of the file without the change and none with it: verified, one 300 ms timer against none.
- Only a test changes, so no Changeset is needed: verified against the contributing guide, which exempts tests.
- No product, API, workflow or CI change: verified; one test file changes and no published package's surface moves.
- The file's tests, ESLint with zero warnings, Prettier and the Core typecheck pass: verified on the head tree.
- Public text carries no internal context: verified.
Files:
packages/core/src/Switch/useSwitchTouch.test.ts: clear.
Maintainer impact
On main, a full
vitest --project uirun under load can report one unhandled error while every test passes. That error turns a localpnpm preflightred. It isTypeError: view.removeEventListener is not a function, thrown frombrowserClickWait.ts:90throughstopintoinputStream.ts:244. Vitest says it originated inSwitch/useSwitchTouch.test.ts, and the file passes when it runs alone.Intended invariant
The file's tests and assertions do not change. A test leaves no listener or timer running after it ends.
browserClickWait.test.tsalready ends each wait that it starts in itsafterEach.Change
The test
reads no box when it attaches, and reads the track once at each presslifts a tap on aSwitchTouchControllerthat it never detaches. The lift starts the 300 msawaitBrowserClickwait. No click, later lift ordetach()ends it in that test, so it runs until its timer fires.Vitest's jsdom environment makes
document.defaultViewthe Node global, soview.setTimeoutis Node's own timer. At teardown, Vitest deletes jsdom's keys from that global,removeEventListeneramong them. When the file ends inside the 300 ms and its worker is still alive, the timer fires into that global and throws.The file now records each controller that its tests attach, and its
afterEachdetaches them. Lint-staged'seslint --fixalso adds braces to an existingcurlywarning in the file. The test file is the only change, so no Changeset is needed.Evidence
Scope
Components: Switch
Testing
Each round runs this command on main a19a517, then on this branch, back to back:
TypeError: view.removeEventListener is not a function, thrown atinputStream.ts:244from the timer atbrowserClickWait.ts:90. All 384 tests pass in each round.awaitBrowserClickinSwitchTouchController.release, started by thetouchUpInsidecall in that test. On this branch it lists none.useSwitchTouch.test.tspasses 12 of 12. ESLint with--max-warnings=0, Prettier andtsc --noEmit -p packages/core/tsconfig.jsonpass.