Skip to content

fix(ScrollableArea): a focus move inside the area adds no commit - #11135

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:uikit/scrollable-focus-no-commit
Nov 11, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:uikit/scrollable-focus-no-commit

Conversation

@vjeux

@vjeux vjeux commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A component built on useScrollableArea, such as ScrollableArea or BottomSheet, can render once more when focus moves between two descendants of a fitting viewport. It does when the move comes just after the component's own update. In the DateInput bottom sheet, the month title's focus hand-off then costs two commits instead of one.

Problem and solution fit

  • Why the defect occurs: a viewport with no scrollable axis tracks whether it holds focus with focusin and focusout listeners. A focus move between two descendants fires both, and each sets the same value, false.
  • Why it harms the task: React renders a component again for a same-value update that follows its own update. Only then does it bail out. So the update that moved focus costs a second render and commit.
  • Why that matters: a sheet's date picker hands focus on inside one commit.

The fix: the focus setters skip a value the state already holds.

Expected behavior and authority

  • A hook test holds this for a scrollable viewport: "does not commit for a focus change or the next measurement while the %s axis scrolls".
  • Regression history: the focusin and focusout tracking arrived with #6314. Before it, the hook read focus during render, and a focus move set no state.

Smallest restoration

  • useScrollableArea keeps the last focus value it set in a ref. Its three focus setters (the listener, the detach cleanup and the measurement) set state only when the value changes.
  • Rendering still reads the state, so the ref holds no rendered value.
  • There is no public API, visual change or string.

Evidence

  • Reproduction before the change: the new case in useScrollableArea.test.tsx fails on main. The component's own update moves focus from one button to another inside the area, and costs two commits.
  • Result after the change: the same update costs one commit.
  • Representative unchanged path: the hook's other focus cases pass. They cover a blurred fitting viewport, focus moving from the viewport to a descendant, focus events that never reach the viewport, and StrictMode replay.
  • Mutation-sensitive proof: with the guard never recording the value it set, 8 existing focus cases fail.
  • With this change merged into fix(DateInput, DateTimeInput): the sheet calendar's toggle and day tap under a finger #8206, its focus hand-off cases pass. The DateInput, DateTimeInput and Calendar unit suites: 1,359 passed. Without it, two of them fail on the second commit.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

This head, ce5ef53, rewords only the changeset, one doc comment and the commit message. At this head, pnpm check:changesets and Prettier pass. Its code is the same as 6a9ec5c, where these runs happened:

  • pnpm -F @astryxdesign/core typecheck, pnpm check:knowledge and pnpm check:changesets pass. pnpm lint:strict: 0 errors.
  • Vitest, the core suite: 21,870 passed.
  • BottomSheet's interaction specs at one worker: Chromium 18 passed, 1 skipped. WebKit through webkit-container.mjs with CI's four CPUs: 10 passed, 9 skipped.
  • BottomSheet's and CodeBlock's accessibility contracts: Chromium 107 passed. WebKit in CI's container, BottomSheet's nine: 55 passed, 1 skipped.

@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 11, 2026 2:37am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 11, 2026
@astracat-bot

astracat-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 11, 2026, 2:43 AM UTC

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · ce5ef53

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC
TimeInput 164.4 kB (+80 B) · 16.1 kB CSS (0) —
lab/EmojiPicker 88.6 kB (+56 B) · 751 B CSS (0) —
Markdown 190.5 kB (+41 B) · 20.8 kB CSS (0) —
28 more components
Component Size LoC
ScrollableArea 11.3 kB (+36 B) · 4.2 kB CSS (0) —
Table 127.6 kB (+35 B) · 18.4 kB CSS (0) —
lab/Comments 354.9 kB (+35 B) · 2.5 kB CSS (0) —
lab/ChatVirtualizer 55.6 kB (+30 B) · 144 B CSS (0) —
lab/CommentComposer 154.1 kB (+30 B) · 1.9 kB CSS (0) —
lab/NavigationStack 83.2 kB (+28 B) · 1.5 kB CSS (0) —
lab/NavigationScreen 83.2 kB (+27 B) · 1.5 kB CSS (0) —
lab/CommentThread 347.9 kB (+25 B) · 2.4 kB CSS (0) —
BottomSheet 69.0 kB (+23 B) · 7.7 kB CSS (0) —
DateInput 189.1 kB (+19 B) · 17.1 kB CSS (0) —
lab/DiffViewer 88.9 kB (+14 B) · 2.1 kB CSS (0) —
lab/ChatReactionBar 109.1 kB (+13 B) · 1.1 kB CSS (0) —
PowerSearch 292.4 kB (+11 B) · 24.2 kB CSS (0) —
lab/ChatEmojiPicker 107.9 kB (+11 B) · 773 B CSS (0) —
CodeBlock 76.9 kB (+7 B) · 11.3 kB CSS (0) —
Popover 92.7 kB (+1 B) · 14.2 kB CSS (0) —
Tokenizer 94.1 kB (+1 B) · 18.8 kB CSS (0) —
ContextMenu 110.7 kB (0) · 17.5 kB CSS (0) —
MoreMenu 99.1 kB (0) · 17.6 kB CSS (0) —
MultiSelector 96.7 kB (0) · 16.9 kB CSS (0) —
Pagination 112.2 kB (0) · 17.8 kB CSS (0) —
Selector 102.1 kB (0) · 17.4 kB CSS (0) —
TableCell 111.9 kB (0) · 17.9 kB CSS (0) —
TableHeaderCell 111.5 kB (0) · 17.7 kB CSS (0) —
lab/TourStep 99.0 kB (0) · 590 B CSS (0) —
richtext/RichTextEditorToolbar 280.7 kB (−1 B) · 454 B CSS (0) —
DropdownMenu 98.8 kB (−2 B) · 17.6 kB CSS (0) —
DateTimeInput 210.7 kB (−6 B) · 18.7 kB CSS (0) —

Package size: @astryxdesign/core 7.29 MB packed (+216 B); no new dependencies.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for one wording fix; the code change itself is sound. The new test fails without the guard, and the existing focus cases fail if the guard stops recording the value it set.

  • .changeset/scrollable-area-focus-move-no-commit.md:5 says every ScrollableArea used to render again on this focus hand-off, but a scrolling viewport already cost one commit and only a viewport whose content fits cost two, so please scope the note, for example: "[fix] A ScrollableArea whose content fits, and a component built on useScrollableArea such as BottomSheet, no longer renders again when a commit moves focus between two of its descendants."

Optional: the first sentence of the setIfChanged comment restates its name, and the second sentence alone carries the reason.

Automated review (maintainer link)

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for one wording fix. The code change itself is sound: the new test fails without the guard, and 8 existing focus cases fail if the guard stops recording the value it wrote.

  • Miss: .changeset/scrollable-area-focus-move-no-commit.md:5 says a fitting ScrollableArea rendered again when a commit moved focus between two of its descendants, but on main that hand-off already costs one commit, since only a component whose own commit moves focus (as in the new test), or the first focus move right after the area's own update, rendered again; please reword it, for example: "[fix] A component built on useScrollableArea, such as ScrollableArea or BottomSheet, no longer renders again when focus moves between two descendants of a fitting viewport just after the component's own update."

The earlier automated review suggested this wording. The pull request body's User impact repeats the claim. Optional: the setIfChanged comment has the same imprecision, and "follows the component's own update" is closer to what React does.

Automated review (maintainer link)

A viewport with no scrollable axis tracks whether it holds focus with
focusin and focusout listeners. When focus moved between two of its
descendants just after the component's own update, both events set
the same value again. React then rendered the component once more
before it bailed out, so the update cost two commits. The focus
setters now skip a value the state already holds.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet. The pull request is a draft from a fork, so CI starts once it is marked ready for review and a maintainer adds the ci:run label.

The changeset and the setIfChanged comment now describe what the change does: the hand-off in the new test drops from two commits to one, and a ScrollableArea's first focus move after its own update no longer renders again. The new test fails without the guard, and 8 existing focus cases fail if the guard stops recording the value it wrote.

Automated review (maintainer link)

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 11, 2026
@vjeux
vjeux marked this pull request as ready for review November 11, 2026 03:33
@cixzhang
cixzhang merged commit ebb9dde into meta:main Nov 11, 2026
133 checks passed
@vjeux
vjeux deleted the uikit/scrollable-focus-no-commit branch November 11, 2026 04:22
@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 11, 2026

This branch was successfully deployed

1 active deployment
Preview — ce5ef539 Deployed Nov 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants