Repository navigation
fix(ScrollableArea): complete hardening audit - #6314
Conversation
Component Hardening Protocol pass over ScrollableArea and useScrollableArea (audited against their current contracts): - getContentProps now consumes caller xstyle instead of leaking it to the DOM as an unknown attribute - viewport focus is tracked with focusin/focusout instead of reading document.activeElement during render; a focused viewport that lost overflow now drops its retained tab stop once blurred - prop getter identity stays stable when adopters pass a fresh keyboardAccess literal each render - removed obsolete -webkit-overflow-scrolling and initial-value scrollbar-width/gutter declarations, and a dead Omit member - tests 24 -> 34: padding precedence and published inset asserted by atomic class (mutation-verified), vacuous overflow assertions tightened, keep-last-state, owner registry unregistration, sideways writing modes, content-getter composition, ARIA conflict wins, and compiled-CSS read-back for the scrollbar token and scroll-state guard - stories: NarrowContainer added; RTLBehaviorProbe and ConditionalKeyboardAccess plays now assert live edge state and the focus-retention path - docs: hook @example, exported type docs, canonical xstyle wording, focus-ring guidance for hook adopters Part of meta#6306
Consumers get one line of guidance on when role="region" is worth a landmark-navigation entry versus keeping the group default, in both the full and dense doc surfaces. Part of meta#6306
The keep-last-state test zeroed only client sizes, so removing the isMeasurable zero-size guard recomputed a state identical to the preserved one and survived the suite. Zeroing every metric of the collapsed box makes an unguarded remeasure publish inactive state, which the assertion now catches. Part of meta#6306
Adversarial preflight confirmed two vacuities in the compiled-CSS tests: the scroll-state assertions were satisfied by the @supports prelude text alone (a mutated inline-size declaration survived), and with runtime injection emitting rules for unused styles, neither test proved the rendered viewport carries the classes (dropping styles.viewport from the composition stayed green). Both tests now match the declaration inside its block and require the owning class on the rendered element. Also corrects the doc guidance attribute prefixes: effective axes are data-scrollable-inline/-block, not data-scroll-*. Part of meta#6306
|
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 |
|---|---|---|---|
| DateTimeInput | 208.6 kB (+135 B) · 18.7 kB CSS (0) | — | — · — · — |
| DateInput | 186.8 kB (+129 B) · 17.0 kB CSS (0) | — | — · — · — |
| CodeBlock | 75.5 kB (+119 B) · 11.3 kB CSS (0) | — | — · — · — |
27 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/DiffViewer | 87.5 kB (+118 B) · 2.1 kB CSS (0) | — | — · — · — |
| TimeInput | 162.3 kB (+115 B) · 16.0 kB CSS (0) | — | — · — · — |
| Markdown | 187.7 kB (+114 B) · 20.6 kB CSS (0) | — | — · — · — |
| BottomSheet | 68.3 kB (+105 B) · 7.7 kB CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 107.2 kB (+102 B) · 1.1 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 106.0 kB (+96 B) · 773 B CSS (0) | — | — · — · — |
| PowerSearch | 287.1 kB (+92 B) · 24.1 kB CSS (0) | — | — · — · — |
| lab/NavigationStack | 82.6 kB (+91 B) · 1.5 kB CSS (0) | — | — · — · — |
| Table | 125.0 kB (+90 B) · 18.3 kB CSS (0) | — | — · — · — |
| lab/NavigationScreen | 82.6 kB (+90 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 344.0 kB (+67 B) · 2.4 kB CSS (0) | — | — · — · — |
| lab/Comments | 350.9 kB (+66 B) · 2.5 kB CSS (0) | — | — · — · — |
| lab/CommentComposer | 151.8 kB (+60 B) · 1.9 kB CSS (0) | — | — · — · — |
| lab/EmojiPicker | 87.0 kB (+47 B) · 751 B CSS (0) | — | — · — · — |
| ScrollableArea · Storybook | 11.1 kB (+72 B) · 4.2 kB CSS (−55 B) | 212 (−3) | ✓ · ✓ · ✓ |
| Pagination | 110.0 kB (+1 B) · 17.8 kB CSS (0) | — | — · — · — |
| Popover | 91.1 kB (+1 B) · 14.2 kB CSS (0) | — | — · — · — |
| MoreMenu | 97.5 kB (0) · 17.6 kB CSS (0) | — | — · — · — |
| MultiSelector | 94.9 kB (0) · 16.8 kB CSS (0) | — | — · — · — |
| Selector | 99.9 kB (0) · 17.4 kB CSS (0) | — | — · — · — |
| TableCell | 109.6 kB (0) · 17.9 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 109.2 kB (0) · 17.7 kB CSS (0) | — | — · — · — |
| Tokenizer | 91.5 kB (0) · 18.8 kB CSS (0) | — | — · — · — |
| lab/TourStep | 97.4 kB (0) · 590 B CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 278.1 kB (0) · 454 B CSS (0) | — | — · — · — |
| ContextMenu | 108.4 kB (−1 B) · 17.4 kB CSS (0) | — | — · — · — |
| DropdownMenu | 97.3 kB (−1 B) · 17.6 kB CSS (0) | — | — · — · — |
Package size: @astryxdesign/core 7.20 MB packed (+1.6 kB); no new dependencies.
API changes: core +0 · ~2 · −0
Committed API report behind this build: cli 29 rows, core 36 rows, theme-butter 1 row, theme-y2k 1 row; run pnpm api:report.
2 API changes (advisory)
| Package | Where | Signature | Usage | |
|---|---|---|---|---|
| ~ | core |
. · Types · interface UseScrollableAreaOptions |
overscroll?: ScrollOverscroll → overscroll?: ScrollOverscroll = 'allow' |
import type {UseScrollableAreaOptions} from '@astryxdesign/core'; const x: UseScrollableAreaOptions = {overscroll: …} |
| ~ | core |
. · Types · interface UseScrollableAreaOptions |
stickyContainment?: ScrollStickyContainment → stickyContainment?: ScrollStickyContainment = 'whenScrollable' |
import type {UseScrollableAreaOptions} from '@astryxdesign/core'; const x: UseScrollableAreaOptions = {stickyContainment: …} |
Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
…rden-scrollablearea
There was a problem hiding this comment.
Thank you for the focused hardening work. The focus-retention and content-style regressions are fixed, but this slice also publishes two new compatibility promises that should come out before it lands. Please keep the implementation fixes and remove the public data-scroll* styling guidance plus the prop-getter identity guarantee/test from this PR.
Resolved conflicts: - packages/core/src/hooks/useScrollableArea.ts: took upstream meta#6301's keyboard delegation (hook-scope hasEffectiveAxis, the attachScrollKeyboardDelegation layout effect, the `contentOrViewport` variant, and the `keyboardAccess.owner !== 'content'` gate with its tabIndex ternary). Dropped this branch's keyboardOwner/keyboardLabel/ keyboardRole scalar extraction, which only handled 'viewport' and would have stripped role, aria-label and tabIndex from `contentOrViewport` adopters such as BottomSheetPanel. Kept the event-based focus tracking by swapping `isViewportFocused` into upstream's keepsProgrammaticFocus, and set the getViewportProps deps to keyboardAccess + isViewportFocused (no viewport). Extended the ScrollKeyboardAccess JSDoc to cover the new variant. (astracat F3) Merge fallout: - packages/core/src/hooks/useScrollableArea.test.tsx: removed the "keeps prop getter identity stable" test. It locked the dropped scalar memoization and the review asked for it to go. (astracat F2, test half)
… claims Addresses astracat-bot's review of meta#6314. F1: ScrollableArea.doc.mjs no longer names `data-scrollable-*` or `data-scroll-*` as presentation hooks. The declared theming surface stays the `astryx-scrollable-area` target with `axis`, which theming.targets already covers, so the whole bestPractices line goes. Stories and tests that probe those attributes stay because they check behavior. Docs-only, so there is no red test. Verified with the ScrollableArea suites, themingTargets.test.ts, check-sync and check-knowledge. F2: the changeset no longer claims that prop getter identity stays stable. The identity-locking test and the scalar memoization it guarded were removed in the upstream merge, since meta#6301's `contentOrViewport` variant conflicted with them. This removes a guarantee, so there is no red test. F3: the retained-tab-stop blur test now runs for both `viewport` and `contentOrViewport` owners. Red: against upstream/main's hook, with no event-based focus tracking, both cases fail at `expect(viewport).not.toHaveAttribute('tabindex')`. Gating keyboardProps on `owner === 'viewport'`, which is the naive PR-side merge resolution, fails the contentOrViewport case at `toHaveAttribute('tabindex', '-1')`. Green: 22/22 in useScrollableArea.test.tsx. 157/157 across the useScrollableArea, scrollKeyboardDelegation, ScrollableArea, BottomSheet, BottomSheetKeyboard and BottomSheetPanel suites.
There was a problem hiding this comment.
Thanks for the follow-through — the two promises flagged last time are gone, and the remaining fixes look right: content xstyle passed through the hook now applies instead of leaking to the DOM, and a focused viewport that stops overflowing now drops its leftover tab stop when it loses focus, for both viewport-owned and delegated keyboard access. The tests around padding precedence, writing modes, and the focus lifecycle cover those contracts well.
One item is waiting on a maintainer decision before it can be approved. The new guidance to choose role="region" only for areas significant enough to appear in screen-reader landmark navigation adds a selection rule that the current ScrollableArea spec does not define — it establishes the group/region values and the group default, but not when to choose region. Approval of that guidance needs a maintainer to provide or identify the governing spec for that selection criterion, or to update the existing spec to define when region should be chosen. Nothing else in the PR is blocked by this, and no change to the guidance is being requested while that decision is pending.
[Automated review]
…wing main region (#8111) Siblings: #8066, #6314. ## Why With `height="fill"`, a keyboard user can't scroll AppShell's main region when it holds nothing focusable: Tab skips it, so Page Down and the arrow keys do nothing. axe reports it as `scrollable-region-focusable`, a serious violation. ## What led to it Part of the touch-presentations program's work on AppShell scrolling (`spec:AST-094`), alongside #8066, which changes which element scrolls. Main was only the skip link's `tabIndex={-1}` target, which Tab never stops on. ## Options and tradeoffs - **Always make main a tab stop:** simple, but adds a stop even when main fits, and an extra stop before its first link. - **A stop only while main overflows, with Tab entry moving on to its first link or button:** what `spec:AST-025` FR12 asks; it costs measuring main, which happens only with `fill`. ## Why this choice The second follows FR12 and AppShell FR4: a viewport joins the tab order only while it overflows, and Shift+Tab skips it. A fitting main, and `height="auto"`, keep `tabIndex={-1}`. Only Tab focus draws main's ring, inset and following the surface's rounded corner; a click, the skip link or a script's focus draws none. Main has no inner content box, so an observer internal to AppShell watches main's direct children; the public `useScrollableArea` is unchanged, and its one-element form is a separate draft that waits on AST-025 OQ1. The AppShell record states the observation (PR1) and the ring (FR4), and drops the gap this closes. Main's stop is named by its `main` role alone, which the FR12 ruling allows for the single main. ## How to check it In Chromium, on the AppShell Playground story with `height="fill"` and 40 rows: 1. Press Tab until focus reaches main: a ring appears inside its edge, and Page Down scrolls it. Before, Tab left the page. 2. Add a link inside main: Tab lands on the link instead, and Shift+Tab from it skips main. 3. Click into main, or use the skip link: no ring. 4. Show fewer rows so main fits: main leaves the tab order. ## Evidence Before (main) and after (this PR):   Tab, then Shift+Tab, with a link inside; the ring:   - The browser test `AppShellMainKeyboard.a11y.browser.spec.ts` covers each step: 16 of 16 in Chromium, and 15 of 15 in WebKit, where the window-switch case is skipped. - Tab onto main exposes the landmark: Chromium's accessibility tree shows the focused node as `main`, not ignored and unnamed, so its role is announced; WebKit computes the same role. The test fails on main (Tab never reaches main) and when main is given a name. - AppShell's keyboard tests fail without the observer, or when a `fill`/`auto` switch doesn't restart it; each of the observer's 5 tests fails when its behavior is removed. - Local gates at 7d439ae: core UI suite (655 files), build, type check, lint, Storybook, the keyboard spec in both browsers, knowledge records and changeset coverage pass; the node project fails only on `cache.test.mjs` and `story-tree.test.ts`, which #8520 and #8509 fix. ## Writing rubric results - R1 narration: the PR1, FR4 and verification-map edits are present tense; the closed current-state gap is removed, and the glance row counts four gaps. - R2 research: none in the record. - R3 evidence: the new verification cells name test files, not changes. - R4 rejected alternatives: none added. - R5 change references: none. - R6 open questions: none touched; AST-025 OQ1 stays open with its options.
There was a problem hiding this comment.
Thanks for the follow-through: the content xstyle fix and the blurred-viewport tab-stop fix both match the current ScrollableArea specs, and the new tests fail without them, so two small changes remain. Please move the new focus useIsomorphicLayoutEffect in useScrollableArea.ts into the existing viewport callback ref: read the node's ownerDocument.activeElement, attach focusin/focusout there, and remove them in the ref's cleanup. That drops the extra Effect and its lint suppression, and the ScrollableArea, hook and BottomSheet suites still pass with it. Please also update the PR description: remove the "prop getters keep a stable identity" and "corrected data-attribute names" items, which this revision no longer does, and note that the suites grow from 25 to 35 tests; the role="region" guidance now matches the current spec and needs no further decision.
[Automated review]
Addresses astracat-bot's review of meta#6314. The viewport ref already runs on attach, detach and replacement, and mergeRefs passes React 19 ref cleanups through. The ref now adopts the current focus from the viewport's own document, adds focusin and focusout listeners, and returns a cleanup that removes them and resets the focus and viewport state. That drops the extra layout effect and its set-state-in-effect suppression. Reading the owner document keeps a focused viewport in an iframe focusable when it loses overflow. Focus events do not always reach the viewport: Chromium fires none while the page lacks system focus, and an ancestor can stop them. A measurement that finds no scrollable axis therefore reads focus too. Only a viewport with no scrollable axis reads that state, so the listeners and the measurement skip it while an axis scrolls; otherwise each focus change re-rendered the host, which is costly on lab Schedule's time grid. Until an axis change is measured, the last measured scrolling keeps a focused viewport's tabindex, because dropping it in that first commit blurs the viewport in Chromium. Tests: the focus lifecycle (StrictMode replay, same-commit replacement, detach, fresh caller refs, descendants, same-task focus hops, stopped focus events, axis changes, commit counts while scrolling), padding and inset variables on every edge, exact scrollbar and overflow values, and an unmeasurable test that now exercises a full measurement. All 25 hook mutations are caught. Also reverts a no-op `children` Omit edit, corrects two story comments, and rewrites the changeset. Part of meta#6306
CI's build job checks out the PR head and runs .github/scripts/build-packages-and-storybook.mjs, which landed on main after this branch's base.
There was a problem hiding this comment.
Thanks for moving the focus listeners into the viewport callback ref: the content xstyle fix and the blurred-viewport tab-stop fix both match the current ScrollableArea specs, and the new tests fail without them. One change remains before approval:
- Please update the PR description to remove "prop getters keep a stable identity across re-renders" and "corrected data-attribute names", which this revision does not do (
getViewportPropsstill changes identity with focus, measurement and the inlinekeyboardAccessobject), and to give the test counts as 37 to 65.
Two optional comment-wording suggestions are inline. CI has not run on this head yet; it runs once a maintainer adds the ci:run label.
[Automated review]
| // Only a viewport with no scrollable axis reads this state, and the | ||
| // measurement that ends its scrolling reads focus again, so a scrollable | ||
| // one can skip the render. |
There was a problem hiding this comment.
Non-blocking: this sentence runs 28 words with three clauses, past the 25-word, one-topic limit for source comments. A shorter version that keeps the reason:
// Only a fitting viewport reads this state.
// The measurement that ends scrolling reads focus again.
// So a scrolling viewport skips the render.| // Focus events do not always reach the viewport (Chromium fires none | ||
| // while the page lacks system focus), and this commit may drop the tab | ||
| // stop that keeps focus here. A scrollable viewport never reads it. |
There was a problem hiding this comment.
Non-blocking: the first sentence runs 29 words with a parenthetical and two clauses. A shorter version that keeps the quirk and the reason:
// Focus events do not always reach the viewport.
// Chromium fires none while the page lacks system focus.
// This commit can drop the tab stop that holds focus.
// A scrollable viewport never reads this state.…en-scrollablearea # Conflicts: # packages/core/src/hooks/useScrollableArea.test.tsx
|
/approve-spec ee74608 |
There was a problem hiding this comment.
Approved: required CI passed on this head.
The content xstyle fix and the blurred-viewport tab-stop fix both restore the current ScrollableArea and useScrollableArea contracts: the new tests fail against main and pass here, and a fitting viewport now keeps tabindex="-1" while it holds focus (in another document too) and drops it once focus leaves. The two optional comment-wording suggestions from the last review (useScrollableArea.ts lines 290–292 and 374–376) still apply.
[Automated review]
…er than restating the default Co-authored-by: AK <[email protected]>
|
/approve-spec 653d65c |
There was a problem hiding this comment.
Approved pending CI: two CI test shards were still running on this head; nothing has failed so far.
The content xstyle fix and the blurred-viewport tab-stop fix both restore the current ScrollableArea and useScrollableArea contracts: the new tests fail against main and pass here, and in Chromium a fitting viewport keeps tabindex="-1" while it holds focus (inside an iframe too) and drops it once focus leaves. The reworded role guidance matches the group default. The two optional comment-wording suggestions on useScrollableArea.ts lines 290–292 and 374–376 still apply.
[Automated review]
What this does
Completes the automated and objective layers of the Component Hardening Protocol for ScrollableArea and the useScrollableArea hook. Part of #6306. (The issue title says XDSScrollableArea; the shipped component is ScrollableArea.)
Why
The component merged recently and hardening is the follow-through: fix what the audit found, prove the contract with tests that can actually fail, and route the judgment calls to their owners.
What changed
xstyleongetContentPropswas silently dropped and leaked into the DOM as an unknown attribute.document.activeElementduring render.-webkit-overflow-scrollingand two no-op scrollbar declarations. No visual change intended.mainto 67, and several assertions that could never fail were replaced: padding precedence and published inset variables, writing-mode edge cases, owner-registry cleanup, and compiled-CSS checks now anchored to the rendered element. Every new guard was verified by applying the exact mutation it exists to catch.role="region"versus thegroupdefault, and focus-ring guidance for hook adopters.How to see it
pnpm vitest run ScrollableArearuns both suites (67 tests).Notes for reviewers
One finding is deliberately left for the component owner rather than patched here: when one axis is active, the inactive axis uses
overflow: hiddenper AST-025, and browser focus-scroll can shift content along it with no way for the user to scroll back. Flagged as a pre-promotion question. Also routed rather than built: a shared-observer design for the ancestor MutationObserver, and a docsite showcase block.A patch changeset is included; the component surface is not yet released.
Maintainer follow-up
(Posted by Cindy's agent on her behalf.) Carried on this branch with the author's commits kept. Exact head: 653d65c.
main. The only conflict was inuseScrollableArea.test.tsx: this branch's focus-listener helpers andmain's new scroll-geometry test both stay.getViewportPropsstill changes identity with focus, measurement and an inlinekeyboardAccessobject) and the data-attribute-names claim, and it gives the test counts as measured.vitest run packages/core/src/hooks/useScrollableArea.test.tsx packages/core/src/ScrollableArea: 67 passed. Coretsc, eslint,check:knowledge,check:changesetsand the comment-provenance baseline pass.