Skip to content

perf(core): hit areas read no layout during a scroll or a press at rest - #11083

Merged
cixzhang merged 7 commits into
meta:mainfrom
vjeux:hit-area-scroll-quiet
Nov 11, 2026
Merged

cixzhang merged 7 commits into
meta:mainfrom
vjeux:hit-area-scroll-quiet

Conversation

@vjeux

@vjeux vjeux commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

User impact

On a phone, a touch on any touch target reads every interactive element's box in its pointerdown. Hit areas also measure during a scroll and one frame after a NavigationStack push. These forced layouts add to the long tasks that turn a fling into a tap, which closes an open menu.

Problem and solution fit

The press check swallows a click whose tap a moved neighbor is nearer, but reads at the pointerdown. Passes also run during a scroll and under an animating ancestor, and a layer's open or close re-matches the page.

  • A press on a control at rest reads nothing. Its click runs the check, reads the unscaled box and writes no insets.
  • A control that a pass saw an ancestor animation move is checked at the press, where its box still matches the finger.
  • No pass runs during a scroll, until scrollend or 150 ms without a scroll event.
  • A pass skips a control while a parent's running animation moves it.
  • The page's interactive elements persist: a mutation or a watch change matches only its own subtree.

Expected behavior and authority

spec:AST-094 FR42: a coarse pointer's hit area grows toward 44 px and never takes a neighbor's tap, at no set time. spec:AST-110 FR3: the scroll gate, page state, lives under a registered key. No record changes.

Gap: motion no pass saw before the press goes unchecked; the browser's hit test takes that tap.

Smallest restoration

  • Drop the press check: a moved neighbor's tap could reach the wrong control.
  • Read at the pointerup: a hold with no click still reads.
  • Read at the click, or at the press for a moving control (chosen).

Evidence

  • Reproduction before the change: on main, five new unit cases fail. They cover a pointerdown read, scroll and slide passes, a layer's page match and a scaled press's insets.
  • Result after the change: they pass.
  • Representative unchanged path: a tap in a gap still goes to the nearer button, in both engines.
  • Regression test or other mutation-sensitive proof: writing the click's insets failed ButtonHitArea's gap tap 10 of 10. A click that read moved boxes failed ListReorderMode's Done tap 10 of 10.

Scope

Components: utils/hitArea and utils/touchHitArea, which Button, List, SegmentedControl, Switch and the other touch targets use.

  • 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

At 0bd3bda: a "Merge main" onto 18af3dc, then the fixes.

  1. pnpm exec vitest run --project ui packages/core/src/utils/hitArea.test.ts packages/core/src/utils/touchHitArea.test.tsx: 74 pass. Without the click rule, two of the four motion cases fail; without the press rule, a third fails. At 1ad995b, a paused parent and a fading one held the pass: their two cases fail. At 97a5ec3, the click skipped a control under a paused parent and a neighbour under a paused animation: those two cases fail. On main's hitArea.ts, the five earlier cases fail.
  2. pnpm exec vitest run --project ui packages/core: 21,872 pass. pnpm test:node: 18,769 pass, with scripts/shared-identity.test.mjs, which failed on the merge.
  3. pnpm exec playwright test --config playwright.interaction.config.ts --project=chromium: every List spec, the hit-area specs, and the Button, ButtonGroup, Indicator, SegmentedControl, Switch, ToggleButton and Popover touch specs. 301 pass. In WebKit's CI container, at CI's one worker: 244 pass and 58 cases skip.
  4. ListReorderMode's "taps alone reorder … and Done ends the mode": 10 of 10 in Chromium. On the merge before the fixes, 0 of 10; on main, 10 of 10.
  5. ButtonHitArea's "a tap in the gap goes to the nearer button, never its neighbor": 10 of 10 in Chromium.

Local gates: the core type check, strict ESLint, Prettier and pnpm review:pre against main (no findings). Device before/after clips come at landing.

A touch hit area read the rect of every interactive element on the page
in a finger's pointerdown, before the browser could start the touch's
scroll. Its passes also ran in the frames of a scroll, and under an
ancestor's motion, as when a screen slides in.

The press now arms a check that its click runs. The click comes only
once the touch is a tap. It reads the control's box without its own
press scale and writes no insets: a pass after the press's motion ends
takes them. No pass runs while the page scrolls, until scrollend or 150
ms without a scroll event. A pass skips a control while an ancestor runs
a finite animation, and measures it once the animation ends. The page's
interactive elements are kept across mutations and watch changes, so a
layer that opens or closes is matched alone, not the whole page.
@vercel

vercel Bot commented Nov 10, 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 1:37am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

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

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 10, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 0bd3bda

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC
richtext/RichTextEditorToolbar 281.3 kB (+1.2 kB) · 454 B CSS (0) —
lab/Comments 355.5 kB (+1.1 kB) · 2.5 kB CSS (0) —
lab/TransferListSelector 112.2 kB (+1.1 kB) · 1.4 kB CSS (0) —
94 more components
Component Size LoC
lab/EmojiPicker 89.2 kB (+1.1 kB) · 751 B CSS (0) —
lab/DialogHeroHeader 85.4 kB (+1.1 kB) · 372 B CSS (0) —
richtext/RichTextView 278.8 kB (+1.1 kB) · 2.3 kB CSS (0) —
Stepper 64.0 kB (+1.1 kB) · 10.1 kB CSS (0) —
Pagination 112.7 kB (+1.1 kB) · 17.8 kB CSS (0) —
Typeahead 83.0 kB (+1.1 kB) · 12.4 kB CSS (0) —
ChatLayoutScrollButton 62.9 kB (+1.1 kB) · 10.2 kB CSS (0) —
Field 57.1 kB (+1.1 kB) · 7.2 kB CSS (0) —
ChatLayout 85.0 kB (+1.1 kB) · 10.5 kB CSS (0) —
AppShell 93.9 kB (+1.1 kB) · 13.5 kB CSS (0) —
Slider 111.3 kB (+1.1 kB) · 8.8 kB CSS (0) —
InputGroup 58.7 kB (+1.1 kB) · 7.8 kB CSS (0) —
DateInput 189.7 kB (+1.1 kB) · 17.0 kB CSS (0) —
Switch 105.9 kB (+1.1 kB) · 9.9 kB CSS (0) —
lab/SelectableCardGroup 66.5 kB (+1.1 kB) · 162 B CSS (0) —
ChatComposer 80.6 kB (+1.1 kB) · 12.0 kB CSS (0) —
ButtonGroup 43.0 kB (+1.1 kB) · 3.7 kB CSS (0) —
MobileNavToggle 62.6 kB (+1.1 kB) · 10.0 kB CSS (0) —
lab/ChatReactionBar 109.6 kB (+1.1 kB) · 1.1 kB CSS (0) —
SideNavHeading 77.8 kB (+1.1 kB) · 11.3 kB CSS (0) —
DrawerHeader 65.3 kB (+1.1 kB) · 12.9 kB CSS (0) —
RadioListItem 69.5 kB (+1.1 kB) · 10.1 kB CSS (0) —
TextArea 64.5 kB (+1.1 kB) · 9.3 kB CSS (0) —
Lightbox 124.8 kB (+1.1 kB) · 10.6 kB CSS (0) —
Thumbnail 66.7 kB (+1.1 kB) · 11.6 kB CSS (0) —
Banner 64.3 kB (+1.1 kB) · 10.5 kB CSS (0) —
ComplexSelector 73.2 kB (+1.1 kB) · 11.8 kB CSS (0) —
SideNavCollapseButton 63.2 kB (+1.1 kB) · 10.0 kB CSS (0) —
TextInput 69.9 kB (+1.1 kB) · 11.2 kB CSS (0) —
ToggleButton 88.8 kB (+1.1 kB) · 10.1 kB CSS (0) —
ChatSendButton 62.7 kB (+1.1 kB) · 10.0 kB CSS (0) —
RadioList 58.4 kB (+1.1 kB) · 7.3 kB CSS (0) —
InfoTip 48.6 kB (+1.1 kB) · 5.4 kB CSS (0) —
lab/DiffViewer 89.5 kB (+1.1 kB) · 2.1 kB CSS (0) —
lab/ListInput 90.4 kB (+1.1 kB) · 922 B CSS (0) —
FieldLabel 53.1 kB (+1.1 kB) · 5.7 kB CSS (0) —
AlertDialog 107.8 kB (+1.1 kB) · 14.6 kB CSS (0) —
CodeBlock 77.4 kB (+1.1 kB) · 11.3 kB CSS (0) —
DateRangeInput 95.3 kB (+1.1 kB) · 12.5 kB CSS (0) —
lab/TransferList 104.5 kB (+1.0 kB) · 1.2 kB CSS (0) —
Toast 100.2 kB (+1.0 kB) · 10.3 kB CSS (0) —
NumberInput 73.8 kB (+1.0 kB) · 11.4 kB CSS (0) —
BaseTypeahead 74.0 kB (+1.0 kB) · 10.9 kB CSS (0) —
DateTimeInput 211.3 kB (+1.0 kB) · 18.7 kB CSS (0) —
TableSelectionToolbar 72.6 kB (+1.0 kB) · 13.2 kB CSS (0) —
CheckboxListItem 73.4 kB (+1.0 kB) · 11.4 kB CSS (0) —
TopNavHeading 77.4 kB (+1.0 kB) · 11.2 kB CSS (0) —
IconButton 62.4 kB (+1.0 kB) · 10.0 kB CSS (0) —
ChatDictationButton 62.9 kB (+1.0 kB) · 10.1 kB CSS (0) —
BreadcrumbItem 86.9 kB (+1.0 kB) · 12.1 kB CSS (0) —
lab/TourStep 99.5 kB (+1.0 kB) · 590 B CSS (0) —
DialogHeader 65.1 kB (+1.0 kB) · 11.5 kB CSS (0) —
ListItem 72.4 kB (+1.0 kB) · 11.4 kB CSS (0) —
SegmentedControlItem 18.5 kB (+1.0 kB) · 4.3 kB CSS (0) —
MultiSelector 97.3 kB (+1.0 kB) · 16.8 kB CSS (0) —
TableCell 112.5 kB (+1.0 kB) · 17.9 kB CSS (0) —
TabMenu 74.1 kB (+1.0 kB) · 11.1 kB CSS (0) —
lab/Schedule 108.3 kB (+1.0 kB) · 3.9 kB CSS (0) —
PowerSearch 292.9 kB (+1.0 kB) · 24.2 kB CSS (0) —
TopNavMenu 76.9 kB (+1.0 kB) · 11.2 kB CSS (0) —
lab/ChatEmojiPicker 108.5 kB (+1.0 kB) · 773 B CSS (0) —
lab/CommentThread 348.5 kB (+1.0 kB) · 2.4 kB CSS (0) —
Button 62.3 kB (+1.0 kB) · 10.0 kB CSS (0) —
Carousel 72.1 kB (+1.0 kB) · 10.9 kB CSS (0) —
MoreMenu 99.7 kB (+1.0 kB) · 17.6 kB CSS (0) —
TableHeaderCell 112.1 kB (+1.0 kB) · 17.6 kB CSS (0) —
lab/CommentComposer 154.7 kB (+1.0 kB) · 1.9 kB CSS (0) —
ChatComposerInput 78.3 kB (+1.0 kB) · 11.3 kB CSS (0) —
ChatComposerTokenElement 78.3 kB (+1.0 kB) · 11.3 kB CSS (0) —
DropdownMenu 99.4 kB (+1.0 kB) · 17.6 kB CSS (0) —
FileInput 71.3 kB (+1.0 kB) · 10.9 kB CSS (0) —
Popover 93.2 kB (+1.0 kB) · 14.2 kB CSS (0) —
lab/PageControl 76.6 kB (+1.0 kB) · 709 B CSS (0) —
Calendar 73.3 kB (+1.0 kB) · 10.6 kB CSS (0) —
Tokenizer 94.7 kB (+1.0 kB) · 18.8 kB CSS (0) —
MobileNav 72.7 kB (+1.0 kB) · 10.6 kB CSS (0) —
lab/TabBarMoreList 94.6 kB (+1.0 kB) · 1.8 kB CSS (0) —
Selector 102.6 kB (+1.0 kB) · 17.4 kB CSS (0) —
TimeInput 164.8 kB (+1.0 kB) · 16.0 kB CSS (0) —
CheckboxInput 66.4 kB (+1.0 kB) · 9.2 kB CSS (0) —
SideNav 116.9 kB (+1.0 kB) · 11.4 kB CSS (0) —
CheckboxList 70.7 kB (+1.0 kB) · 7.7 kB CSS (0) —
TopNavMegaMenu 71.9 kB (+1.0 kB) · 11.8 kB CSS (0) —
richtext/RichTextEditor 300.6 kB (+1.0 kB) · 2.6 kB CSS (0) —
SideNavItem 72.6 kB (+1.0 kB) · 11.1 kB CSS (0) —
ContextMenu 111.2 kB (+1017 B) · 17.4 kB CSS (0) —
Markdown 191.0 kB (+1014 B) · 20.7 kB CSS (0) —
Table 128.1 kB (+1006 B) · 18.4 kB CSS (0) —
ToggleButtonGroup 40.3 kB (+1000 B) · 3.7 kB CSS (0) —
TopNav 74.4 kB (+995 B) · 10.9 kB CSS (0) —
SegmentedControl 97.3 kB (+49 B) · 6.9 kB CSS (0) —
lab/TabBar 81.3 kB (+48 B) · 1.8 kB CSS (0) —
Timestamp 34.6 kB (+3 B) · 10.2 kB CSS (0) —
lab/TabBarItem 3.9 kB (0) · 1.8 kB CSS (0) —

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

Not run on this PR: add ci:run-visual 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.

Changes requested. The click-time press check, the scroll gate and the ancestor-animation hold behave as described, and their new unit cases fail on main and pass here. Two things need fixing first:

  • regroup (packages/core/src/utils/hitArea.ts:642-646) checks every kept interactive element on each new watch, so watching 300 rows beside 2,000 buttons now takes about 26–30 ms in Chromium against about 1 ms on main; deleting only element.querySelectorAll(INTERACTIVE_SELECTOR) before addMatches brings it to about 2 ms, and every existing hit-area test still passes.
  • The new settlingAnimations and scheduleAtRest (hitArea.ts:724-735, 972-996) copy the at-rest gate in packages/core/src/utils/touchHitArea.ts:68-80 with different rules, so please keep one shared helper in hitArea.ts and have useTouchHitArea use it instead of its own copy.

Optional: the scroll-stop detector repeats the one in Layer/useLayer.tsx, and the interactive JSDoc says each mutation updates the set, although a removal leaves only at the next read.

[Automated review]

Comment thread packages/core/src/utils/hitArea.ts Resolved
Comment thread packages/core/src/utils/hitArea.ts Resolved
Comment thread packages/core/src/utils/hitArea.ts Resolved
A new watch checked every interactive element the page kept, so a layer
of watched rows cost the rows times the page's controls. It now regroups
only the interactive elements it holds.

The pass, the click's follow-up pass and useTouchHitArea wait out motion
through one helper: the finite animations running or held in a scope,
until each settles. useTouchHitArea had its own copy, and the click's
follow-up counted only running animations.

@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, because the pull request is a draft from a fork. Once it is ready for review, a maintainer adds the ci:run label so CI runs.

Both earlier requests are addressed: a new watch now regroups only its own subtree (packages/core/src/utils/hitArea.ts:643-646), and the pass, the click's follow-up and useTouchHitArea share one at-rest helper pair. Optional: the scrollend-or-150 ms detector still repeats the ones in Layer/useLayer.tsx and gestures/fingerScroll.ts.

[Automated review]

@cixzhang cixzhang added 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) labels Nov 10, 2026
@vjeux
vjeux marked this pull request as ready for review November 10, 2026 21:53
@vjeux
vjeux marked this pull request as draft November 10, 2026 22:32
Whether the page is scrolling is page state, so every copy of Core
shares one scroll gate under a registered key. The first copy to
observe listens for the page, and the last one to stop ends it. Each
watch keeps the ancestor animations it waits out, so no module map
holds another copy's watches.
A pass that sees an ancestor animation move a control holds it back,
and the press then measures it, while its box is still where the
finger landed. A control at rest still reads nothing at the press, and
its click measures. An animation that starts after the press moves the
boxes before the click, so the control's click goes through, as the
browser's hit test took it, and a moving neighbour is left out. A fade
or a tint moves nothing, so the click's check still runs.
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 1ad995b

@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.

Changes requested: the hit-area changes behave as described and their new tests pass, but the release note overstates what ships.

  • Regression: .changeset/hit-area-scroll-quiet.md says a tap still never reaches a neighbor that is nearer the finger and that a press no longer measures the page, yet during motion that no measuring pass saw the tap now goes to the control the browser hit-tests (isNearerAtClick in packages/core/src/utils/hitArea.ts), and a press on a control a pass saw moving still reads every box at pointerdown, so please reword the changeset and the title to state those exceptions.

A changeset wording that fits:

On a phone, a press on a control at rest no longer measures the page, so a scroll that starts there does not wait. Hit areas no longer measure while the page scrolls or while a parent animates, such as a screen that slides in. While a control or its neighbor moves in an animation, the browser's own hit test decides the tap. No API changes.

Two optional fixes: a paused, finite ancestor animation holds a control's measurement forever, and the measuring pass's hold counts fades that the click check ignores.

Automated review (maintainer link)

Comment thread .changeset/hit-area-scroll-quiet.md Resolved
Comment thread packages/core/src/utils/hitArea.ts Resolved
Comment thread packages/core/src/utils/hitArea.ts Resolved
A pass held a control under any finite parent animation. A paused one
can stay paused, so the control was never measured, and a fade or a
tint moves no box. The pass now waits only while a parent's running
animation moves boxes, as the click's check reads motion. The release
note states what ships: a press on a moving control still measures,
and motion that starts after the last measurement leaves the tap to
the browser's hit test.
@vjeux vjeux changed the title perf(core): hit areas read no layout as a finger presses or scrolls perf(core): hit areas read no layout during a scroll or a press at rest Nov 11, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 97a5ec3

@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.

Changes requested: the click-time check, the scroll gate and the moving-ancestor hold behave as described, and their new cases fail on the base and pass here, but one case skips the nearer-neighbour check.

  • Regression: isNearerAtClick (packages/core/src/utils/hitArea.ts:1101) still counts paused animations as motion while measure() treats them as at rest, so a tap on a control under a paused, finite animation, or nearer a neighbour under one, is no longer checked (in Chromium on this head, a touch 2 px from a link that moved under a Switch is swallowed while the row is still and turns the Switch on while the row holds a paused animation; the base checks that tap at the press); please keep only running animations there, as measure() does, ideally through one shared helper, and add click tests for a paused ancestor and a paused neighbour (the paused-neighbour half was already present at the previous head, and the earlier review missed it).

CI has not run on this draft head yet.

Automated review (maintainer link)

Comment thread packages/core/src/utils/hitArea.ts Resolved
The pass treated a paused animation as at rest, but the click's check
counted it as motion. A tap on a control under a paused animation, or
nearer a neighbour under one, then went unchecked. One helper now
gives both the running animations that move boxes.
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 0bd3bda

@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, because the pull request is a draft; it already carries ci:run, so CI runs once it is marked ready for review.

The click-time check, the scroll gate and the moving-ancestor hold behave as described, and the click now uses the same running-only motion rule as the pass, so a tap under a paused animation is checked again (the two new click cases fail on the previous revision and pass here). The fallback while unseen motion moves a control or its neighbour is the gap an engineering owner accepted for this revision.

Non-blocking:

  • settlingAnimations's JSDoc (packages/core/src/utils/hitArea.ts:726-729) still says a paused hold is released, which movingAnimations now contradicts; see the inline suggestion.
  • A running ancestor animation that an app pauses later stays in watch.heldBy, so presses on that control keep reading layout at pointerdown until a resize or content change re-measures it.

Automated review (maintainer link)

Comment on lines +726 to +729
* The finite animations running or held in `root` and its subtree. An endless
* one, such as a spinner, moves nothing that comes to rest. Core pauses an
* animation only inside a gesture, and the gesture ends it. So a watch that a
* paused animation holds is released.

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.

Non-blocking (INV29): the last sentence no longer holds. The pass and the click now ignore paused animations (movingAnimations below says an app can leave one paused), and a running animation an app pauses mid-hold is never released from watch.heldBy. Suggested:

Suggested change
* The finite animations running or held in `root` and its subtree. An endless
* one, such as a spinner, moves nothing that comes to rest. Core pauses an
* animation only inside a gesture, and the gesture ends it. So a watch that a
* paused animation holds is released.
* The finite animations running or held in `root` and its subtree. An endless
* one, such as a spinner, never comes to rest.

@vjeux
vjeux marked this pull request as ready for review November 11, 2026 02:17
@cixzhang
cixzhang merged commit 08b7422 into meta:main Nov 11, 2026
167 of 173 checks passed
@vjeux
vjeux deleted the hit-area-scroll-quiet branch November 11, 2026 05:25

This branch was successfully deployed

1 active deployment
Preview — 0bd3bda8 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants