Skip to content

Remove the safeTab() test helper, and type-check userEvent options - #4257

Merged
nstepien merged 3 commits into
mainfrom
remove-safetab
Oct 29, 2026
Merged

nstepien merged 3 commits into
mainfrom
remove-safetab

Conversation

@nstepien

@nstepien nstepien commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

safeTab() called userEvent.tab(), and when focus left the page, it clicked a temporary button and tabbed again. That fallback no longer runs: with an assertion added to it, the browser suite never reached it in Chromium, Firefox, or WebKit. The grid only lets Tab leave it from the first header cell or the last cell (canExitGrid), and the tests that tab out of the grid have another element to move focus to.

This PR calls userEvent.tab() directly and removes the helper.

  • renderTextEditor.test.tsx renders a button after its one-cell grid, so tabbing out of the editor keeps focus on the page. Firefox r1555 (Playwright 1.64.1) can't tab out of Vitest's iframe ([Regression]: Firefox cannot move focus from an iframe to its parent since r1553 microsoft/playwright#43280), so the test passes without the button today, but Firefox r1564 (Playwright 1.65) can, and the afterEach focus check then fails.
  • The afterEach focus check explains what moves focus out of the page and suggests rendering a focusable element before or after the grid.

Types of userEvent options

tsconfig.test.json now loads the Playwright provider's types (vite-plus/test/browser-playwright). Without them, UserEventClickOptions and the other option interfaces of vitest/browser stayed empty, so userEvent.click(element, { obviousTypo: 123 }) type-checked, and editors offered no completions for the options.

The provider's types include Node's, so Node globals like process also type-check in browser tests, and Error.stackTraceLimit no longer needs its @ts-expect-error.

How Tab behaves past the page's edges

Measured in Vitest's iframe by tabbing past the last of 3 buttons, and Shift+Tabbing past the first:

Browser Result
Chromium 1248 Focus leaves the page, and 2 more Tabs return it to the first (or last) button.
Firefox r1555 (Playwright 1.64.1) Focus can't leave the iframe, and stays on the last (or first) button.
Firefox r1564 (Playwright 1.65 alpha) Focus leaves the iframe. More Tabs move focus between the buttons while document.hasFocus() stays false, and it later turns true on a Tab that doesn't move focus.
WebKit 2370 Focus leaves the page, and Tab never returns it.

In every browser, one click on the page restores document.hasFocus().

Testing

vp run ci passes. The browser tests also passed with shuffled files and tests (--sequence.shuffle.files --sequence.shuffle.tests), one browser at a time, in 3 seeds per browser. Earlier seeds had Firefox and WebKit click timeouts in the beforeEach focus click, which happen before any Tab, also failed once on main, and passed when the seeds ran again.

🤖 Generated with Claude Code

nstepien and others added 2 commits October 27, 2026 19:24
Its click-then-Tab fallback no longer runs in any browser: the grid only
lets Tab leave it from the first header cell or the last cell, so tests
call `userEvent.tab()` directly. `renderTextEditor.test.tsx` renders a
button after its one-cell grid, so tabbing out of the editor keeps focus
on the page in Firefox r1564 (Playwright 1.65).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`tsconfig.test.json` didn't load the Playwright provider's types, so
`UserEventClickOptions` and the other option interfaces stayed empty:
any object literal type-checked, and editors offered no completions.
The provider's types include Node's, which declare
`Error.stackTraceLimit`, so its `@ts-expect-error` is no longer needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nstepien nstepien changed the title Remove the safeTab() test helper Remove the safeTab() test helper, and type-check userEvent options Oct 27, 2026
@nstepien
nstepien marked this pull request as ready for review October 29, 2026 03:02
@nstepien
nstepien merged commit be16443 into main Oct 29, 2026
5 checks passed
@nstepien
nstepien deleted the remove-safetab branch October 29, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant