Repository navigation
fix(useScrollableArea): a viewport is a tab stop from the first frame its content overflows - #8388
Conversation
… its content overflows The first measure reads the viewport while this hook still has it at overflow: clip, so it finds overflow but no scrollable axis; the axis became scrollable on the next render, but the tab stop waited for an animation-frame remeasure. Remeasure in the same commit once the overflow style changes. Fixes the scrollable-region-focusable violation on the lab Schedule Async Loader story, where loaded data replaces the loading fallback's viewport.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report
|
There was a problem hiding this comment.
The same-commit re-measure does make the viewport a tab stop from its first scrolling frame (the new test fails on main and passes here, and in Chromium the Schedule async loader's time grid now carries tabindex="0" in the commit that first lets it scroll), but one change is needed before this can land. The new layout effect in useScrollableArea.ts re-measures on every overflow change with no bound, so when a space-taking scrollbar decides whether the content fits (for example a 16:9 child at full width in a 540 × 300 block ScrollableArea with 15px scrollbars), each flip re-measures and flips back inside one commit until React throws "Maximum update depth exceeded" and unmounts the tree, where main only flickers once per frame. Bounding the follow-up (for example, re-measuring synchronously only when an axis has just gained overflow or the mapping changed) and adding a hook test whose content fits only under auto would resolve it.
[Automated review]
| useIsomorphicLayoutEffect(() => { | ||
| measureRef.current?.(); | ||
| }, [overflow, mapping]); |
There was a problem hiding this comment.
This follow-up re-measures on every overflow change, including the ones it causes. When a space-taking scrollbar decides whether the content fits (a 16:9 child at full width in a 540 × 300 block ScrollableArea with 15px scrollbars), the measure under auto sets overflow back to fitting, the clip commit re-runs this effect, and React throws "Maximum update depth exceeded" after about 50 nested commits; main alternates once per frame instead (AST-025 FR7, FR9). Bounding it, for example to commits where an axis has just gained overflow or the mapping changed, keeps the first-frame tab stop (the 15 hook tests still pass) and stops the abort.
…s gains overflow Review round 1: content that fits only once a space-taking scrollbar appears flipped overflow back and forth inside one commit until React aborted. The same-commit remeasure now runs only when an axis has just gained overflow or the axis mapping changed; a loss waits for the next frame, as on main. Adds a hook test whose content fits only under auto.
There was a problem hiding this comment.
The same-commit re-measure makes an overflowing viewport a tab stop from its first scrolling frame (the new test fails on main and passes here, and in Chromium the Schedule async loader's time grid now carries tabindex="0" in the commit that first lets it scroll), and the gain-only bound fixes the earlier in-commit loop, but two changes are needed before this can land.
measurestarts withframe = null, so calling it from the new layout effect forgets the frame thatobserveResizescheduled at registration: every overflowing mount then runs two measurements in the next frame and unmount cancels only one of them (AST-025 FR7), so leaveframeto the frame callback, for example with ameasureNowthe effect calls, and add a test that an overflowing mount leaves one frame pending and unmount leaves none.- The
hasRemappedpath keeps the tab stop through a writing-mode change, but the hook suite still passes with it removed, so add a test that switches an overflowing viewport tovertical-rland expectstabindex="0"after one frame.
[Automated review]
| const hasGainedOverflow = | ||
| (overflow.inline && !previous.inline) || | ||
| (overflow.block && !previous.block); | ||
| const hasRemapped = mapping !== previousMappingRef.current; |
There was a problem hiding this comment.
This keeps the tab stop through a writing-mode change that moves the overflowing axis (without it the stop disappears for one frame), but with || hasRemapped removed from the condition below all 16 hook tests still pass. A test that settles an overflowing block viewport, sets writing-mode: vertical-rl, runs one frame and expects tabindex="0" would protect it.
| previousOverflowRef.current = overflow; | ||
| previousMappingRef.current = mapping; | ||
| if (hasGainedOverflow || hasRemapped) { | ||
| measureRef.current?.(); |
There was a problem hiding this comment.
measure begins with frame = null (line 223) because it was written as the frame callback. Called here, it runs while the frame that observeResize scheduled at registration is still pending (the shared observer calls its callback synchronously on registration), so that frame is forgotten: the MutationObserver then schedules a second one, two measurements run in the next frame (AST-025 FR7), and cleanup can cancel only the newer frame, so the older one outlives unmount. Calling a body that leaves frame alone, for example a measureNow that measure wraps with frame = null, keeps one pending frame.
…ng frame Review round 2: the remeasure called the frame callback, which clears the pending frame, so an overflowing mount ran two measurements in the next frame and unmount could cancel only one. It now calls a measureNow body that leaves the frame alone. Adds tests that an overflowing mount leaves one frame pending and unmount none, and that a writing-mode change moving the overflowing axis keeps the tab stop after one frame.
…comments The set-state-in-effect suppressions became unused once the setters moved into measureNow; lint-staged dropped them with their explanations. Restore the explanations as comments.
There was a problem hiding this comment.
No changes are needed: the same-commit re-measure makes an overflowing scroll viewport a tab stop from its first scrolling frame, the new first-frame test fails on main and passes here, and in Chromium and WebKit the Schedule async loader's loading time grid no longer scrolls without tabindex. The gain-only bound, the single pending frame and the writing-mode remap are each pinned by a test that fails without them. One optional touch-up: the comment at useScrollableArea.ts:363 and the test note at useScrollableArea.test.tsx:263 say a loss waits for the next frame, but when content fits only once a scrollbar takes space the same-commit re-measure itself records the loss, so rewording them would keep that case clear for the next reader.
[Automated review]
| // a tab stop from the first frame it scrolls, not an animation frame later | ||
| // (`spec:AST-025` FR12). Only on a gain: content that fits only once a | ||
| // scrollbar takes space would otherwise flip overflow back and forth inside | ||
| // one commit; a loss waits for the next frame, as before. |
There was a problem hiding this comment.
Optional: the gate bounds what triggers a re-measure, not when a loss lands. When content fits only once a scrollbar takes space, the re-measure under auto records the loss itself, so the viewport writes auto and then clip within one frame (and the test note at useScrollableArea.test.tsx:263 has the same wording). Something like "a loss never triggers this re-measure; the next measurement after it waits for a frame, as before" would match what the code does.
useScrollableArea.ts: main's meta#8388 same-commit remeasure (measureNow, measureRef, the gained-overflow layout effect) with this branch's scroll path (publish, measuredMapping/measuredOverflow, onScroll); main's comment style replaces the set-state-in-effect disables. ci.yml: main's, which discovers browser accessibility specs by file name (meta#8367), so this branch's explicit AppShell keyboard step is dropped and the spec runs by its AppShell folder.
User impact
A keyboard user can't Tab into a scroll viewport for a moment after its content arrives already overflowing. Example: loaded data replacing a loading state in Schedule's week view. The viewport scrolls, but it isn't in the tab order until an animation frame later, and longer on a busy page. On
main, an accessibility audit of the lab Schedule "Async Loader" story catches that window and reportsscrollable-region-focusable(serious). It isn't in the a11y baseline, so the next PR that touches Schedule would fail pr-a11y on it.After this change, the viewport is a tab stop in the same commit that lets its overflowing axis scroll, so it is reachable from its first scrolling frame.
Problem and solution fit
useScrollableAreakeeps a fitting viewport atoverflow: clip.autoon the next render.clipat that moment. SoisScrollable, which grants the tab stop, stays false.tabindex="0". A loss of overflow still waits for the next frame, as onmain, so content that fits only once a scrollbar takes space alternates at most once per frame and never loops inside a commit. No API, markup or style change.Expected behavior and authority
spec:AST-025FR12 (current): a viewport that owns keyboard access is in the tab order while an axis overflows.component:ScheduleAR1 (current): the time-grid viewport is that owner, a namedregionin the tab order while an axis overflows.Smallest restoration
hooks/useScrollableArea.ts: keep a ref to the activemeasure, and remeasure in a layout effect when an axis gains overflow or the mapping changes (43 product lines). The same-commit remeasure calls the measurement body directly, so the frame already scheduled stays the only pending one.hooks/useScrollableArea.test.tsx: a race test. Computed overflow follows the hook's own style, as in a browser, and the content is taller than the viewport at mount. With no animation frame run, the viewport isauto,tabindex="0", andisScrollable. It fails onmain.auto(a scrollbar that takes space) renders and flushes frames without looping; an overflowing mount leaves exactly one animation frame pending and unmount leaves none; a writing-mode change that moves the overflowing axis keeps the tab stop after one frame.Evidence
Real Chromium (headless) with axe-core 4.12, Storybook built from
mainand from this branch. The story islab-schedule--async-loaderat 1280×720 with reduced motion. axe runsscrollable-region-focusableat 25 ms steps from 0 to 775 ms after the story renders, with CPU throttling ×1 and ×4 (64 scans each):mainrole="region""… time grid",data-scroll-axis="both", overflow set, notabindex)A full axe run on the settled story at this branch reports only
landmark-one-mainandpage-has-heading-one, which the audit disables for story isolation.Tests:
useScrollableArea.test.tsx18/18, each new case failing without the code it covers. The first-frame case fails onmain, and the fits-only-under-autocase fails on this PR's first round. The ScrollableArea, BottomSheet, CodeBlock, Table, Schedule and DiffViewer suites pass. The Table perf budgets pass when run alone; they time out only on a loaded local machine, onmaintoo.Scope
Testing