Repository navigation
test: cut the jsdom style work that times out UI suites under load - #10285
Conversation
DateTimeInputTouch queried buttons by name on an open sheet of about 300 buttons. jsdom reads styles to compute each accessible name, so each query took about 6 s, and 13 cases took over 3 s alone. A buttonNamed helper gives the full role, name and accessibility check only to the buttons whose label or text is the name. useTableRowExpansion's two zebra cases rendered with row dividers. The panel's divider carry reads the striped row's computed style, which jsdom resolves in about 2,000 nested passes. Striping does not depend on dividers, so both cases render without them. Table.perf's render budgets timed a run's first Table render, which also pays one-off module and compiler work. An untimed warm-up render now runs first.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| TableBody | 3.5 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · ✗ |
| TableFooter | 3.5 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · ✗ |
| TableHeader | 3.5 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · ✗ |
6 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| TableRow | 6.7 kB (0) · 3.9 kB CSS (0) | — | ✓ · ✓ · ✗ |
| DateTimeInput · Storybook | 195.1 kB (0) · 18.1 kB CSS (0) | 3,567 (0) | ✓ · ✓ · ✓ |
| Table | 99.9 kB (0) · 17.3 kB CSS (0) | — | ✓ · ✓ · — |
| TableCell | 91.7 kB (0) · 17.0 kB CSS (0) | — | ✓ · ✓ · ✓ |
| TableHeaderCell | 91.3 kB (0) · 16.8 kB CSS (0) | — | ✓ · ✓ · ✓ |
| TableSelectionToolbar | 61.2 kB (0) · 12.4 kB CSS (0) | — | ✓ · ✓ · ✓ |
Package size: no published package changed; no new dependencies.
API changes: none in this pull request
Committed API report behind this build: cli 19 rows, core 24 rows; run pnpm api:report.
Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
|
/approve-spec 2ff0257 |
The warm-up render unmounts, and its rows now differ from the timed ones. So the timed render is a fresh mount that reuses nothing.
There was a problem hiding this comment.
Changes requested: the three test fixes work as described, and one change is needed before they land.
buttonNamedinDateTimeInputTouch.test.tsxre-implements the fast button lookup thatpackages/core/src/__tests__/fastRoleQueries.tsalready provides andDateTimeInput.test.tsxalready uses, so please move the stricter exactly-one lookup into that shared module and call it from here instead of keeping a local copy.
The Table.perf warm-up and the zebra cases' dividers="none" need no change, and the two slow DateTimeInputTouch cases drop from about 12 s to under 1 s with every case still passing. A smaller, non-blocking point: the helper's uniqueness check counts only buttons named by aria-label or text, so a duplicate named through aria-labelledby would slip past it; choosing candidates with the shared module's name computation would close that. CI has not run on this head yet: it starts once the pull request is marked ready for review and a maintainer adds the ci:run label.
[Automated review]
| // The open sheet holds about 300 buttons, most of them days in the month | ||
| // grids. jsdom reads styles to compute each accessible name, at several | ||
| // milliseconds per element, so a role query by name takes seconds. Only the | ||
| // buttons whose label or text is the name get the full check. | ||
| function buttonNamed(name: string): HTMLElement { | ||
| const matches = screen.getAllByRole('button', {hidden: true}).filter( | ||
| element => | ||
| (element.getAttribute('aria-label') ?? element.textContent)?.trim() === | ||
| name && | ||
| within(element.parentElement as HTMLElement) | ||
| .queryAllByRole('button', {name}) | ||
| .includes(element), | ||
| ); | ||
| expect(matches, `accessible buttons named "${name}"`).toHaveLength(1); | ||
| return matches[0]; | ||
| } |
There was a problem hiding this comment.
This duplicates the fast lookup in packages/core/src/__tests__/fastRoleQueries.ts (getButton/queryButton), which DateTimeInput.test.tsx already uses for the same names (Open calendar, Clear Meeting). Moving this exactly-one, full-check variant into that module (for example getOnlyButton(name)) and calling it here keeps one helper for this jsdom cost. Choosing candidates by that module's stubbed-style name computation instead of aria-label/text would also catch a duplicate named through aria-labelledby, which this version misses.
There was a problem hiding this comment.
Done in b57f904: the lookup moved into fastRoleQueries.ts as getOnlyButton. It picks candidates with that module's name computation, so an aria-labelledby name counts. Each candidate then goes through Testing Library's own role, name and accessibility query, and exactly one must match. The local helper is gone.
DateTimeInputTouch's local buttonNamed duplicated the fast lookup in fastRoleQueries.ts. That module gains getOnlyButton. It picks candidates with the module's own name computation, then runs RTL's full role, name and accessibility query on each one's parent, and requires exactly one match. A name from aria-labelledby now counts too.
|
/approve-spec b57f904 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, and it runs once the pull request is marked ready for review and a maintainer adds the ci:run label.
The shared getOnlyButton in fastRoleQueries.ts resolves the earlier request, and it returns the same element as getByRole at all 29 call sites in DateTimeInputTouch.test.tsx. One small, non-blocking point: its name prefilter ignores CSS hiding, so a duplicate whose name differs only by hidden text is not counted, and the header line saying it keeps getByRole's checks could say so.
[Automated review]
| * | ||
| * Trade-off vs getByRole: first match wins — no tree-wide uniqueness check. | ||
| * Trade-off vs getByRole: getButton and queryButton take the first match — | ||
| * no tree-wide uniqueness check. getOnlyButton keeps getByRole's checks. Each |
There was a problem hiding this comment.
Non-blocking: the prefilter computes names with the constant-visible stub, so text hidden by CSS still counts there. Beside a plain Save button, a Save<span style="display:none"> draft</span> button makes getByRole('button', {name: 'Save'}) throw for multiple matches, while getOnlyButton('Save') returns the plain one; alone, that button makes getOnlyButton throw where getByRole finds it. No call site in this pull request hits it. Suggested wording:
* no tree-wide uniqueness check. getOnlyButton keeps getByRole's checks for
* names that no CSS-hidden text changes. Each…ove the date like UIDatePicker's (#8209) * fix(DateInput, DateTimeInput): under a finger the month/year wheels move the date like UIDatePicker's Under a finger, turning the month or year wheel behind the sheet calendar's title moves a chosen date to the wheels' month and keeps its day: October 15 becomes May 15, and a day the month lacks becomes its last day (January 31 becomes February 28), inside min and max, by the months of the calendar the sheet shows; DateTimeInput keeps the time. A date dateConstraints refuses is not chosen, and with no date chosen the wheels move only the calendar. With a mouse the wheels move the calendar only, as today. The month wheel does not loop. DateInput FR22 records the rule under a coarse primary pointer, and DateTimeInput FR14 does the same and keeps the time. Each has a verification row. * test(DateInput): the month/year wheels' proof waits on the sheet's own end, not on still frames before a deadline `openWheels` waited for the sheet, and then for the wheels, with the harness's `waitForRest`: three still frames within 5 s. On a loaded runner the page can present no frame for 6 s right after the sheet opens, so the wait ran out with nothing moving ("still moving", while the page held no animation). The proof now checks the sheet's open transform, and then the wheels' full opacity, once a frame with no deadline of its own, and waits on each animation's `finished` promise. A starved runner only makes it later. * refactor(DateInput, DateTimeInput): the wheels' comments keep the reason The comments above both sheets' handleWheelChange keep only the reason: UIDatePicker moves a chosen date with the wheels. The day and bound clamps read from dateInMonth itself, which moves the date by the calendar's own months through calendarShiftMonths. * Merge main into the month/year wheels Main gained #10285, which adds a `getOnlyButton` import beside the testing-library import this pull request widens in DateTimeInputTouch.test.tsx. The merge keeps both imports; this pull request's own changes are unchanged. * Merge main into the month/year wheels Main gained #10231, which adds DateInput FR22 for the touch sheet's month arrows. This pull request's month/year wheel requirement moves from FR22 to FR23, with its verification row, the Bottom-sheet calendar row, the scope line and DateTimeInput FR14's two citations. Only the numbers change; this pull request's own changes are otherwise unchanged.
Maintainer impact
On a loaded machine, three UI test files fail on jsdom style work, not on the code under test. Under two CPUs with 12 busy loops, two DateTimeInputTouch cases timed out in every run, and a useTableRowExpansion case in 1 of 5. Table.perf's 100-row budget also fails when that case runs by itself, with no added load.
Intended invariant
Each case keeps its assertions, and its role queries stay as strict as
getByRole. A render budget times the render it names, not one-off warm-up work.Change
fastRoleQueries.tshas fast lookups that take the first match. It gainsgetOnlyButton, which picks candidates with that module's name computation. It then runs Testing Library's own role, name and accessibility query on each and requires exactly one match.Evidence
Scope
Testing
Counts:
fastRoleQueries.tspass: Calendar 134, DateInput 134, DateRangeInput 64 and DateTimeInput 171. useTableRowExpansion 51 of 51 in 7 s, down from 11 s. Table.perf 15 of 15.tsc --noEmitfor core passes, and ESLint reports nothing on the added lines.Review notes
fastRoleQueries.ts's header goes to the next change that touches that file; no call site hits the CSS-hidden-name case (29/29 return getByRole's element).