Skip to content

fix(gestures): each document's gesture host reads that window's clock - #11155

Merged
cixzhang merged 5 commits into
meta:mainfrom
vjeux:fix/gesture-host-document-clock
Nov 11, 2026
Merged

cixzhang merged 5 commits into
meta:mainfrom
vjeux:fix/gesture-host-document-clock

Conversation

@vjeux

@vjeux vjeux commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

User impact

An app can render a component into a same-origin iframe or a Document Picture-in-Picture window through a portal. Under a finger there, every timed gesture runs early. A long press begins on a short tap, and the press can claim the finger, so the tap loses its click. This restores the timing that the page's own document already has.

Problem and solution fit

  • Why does it occur? A gesture host builds every document's arena on the page's clock. A second window stamps its events on its own clock, which starts later and reads less.
  • Why does it harm the task? The arena sets each timer at an event's time plus a delay, and measures it on the page's clock. That deadline has already passed, so the timer fires at once.
  • Why does it matter? A short tap becomes a long press, and the press takes the tap's click.

The fix gives each host its own window's clock, so an event's time and the arena's clock share one origin.

Expected behavior and authority

spec:AST-094 FR16: recognizers read time from the input events' timestamps, and a long press is a deadline on that clock. An event's timeStamp counts from the time origin of its own window (High Resolution Time). LongPressGestureRecognizer begins only after minimumPressDuration. In the page's document the arena already meets both.

Smallest restoration

  • GestureHost looks up its document's window clock through clockOf at each read. For the page's document, the arena clock is the same browserClock object as before. For another window, it is a copy whose now() reads that window's performance.now().
  • eventTime converts an epoch-stamped event with that window's time origin. In the page's document it reads the same performance object as before.

Beyond GestureHost.ts, only the internal EventClock type changes: it gains timeOrigin. There is no new API.

Evidence

  • Reproduction before the change: at cf8a455, the new long-press case fails. A 120 ms tap stamped on an iframe's clock, 5 s behind the page's, begins the long press at once.
  • Result after the change: the case passes at 93d0770.
  • Representative unchanged path: a second case pins the page's document to browserClock itself. A third starts a hold after fake timers replace the page's clock; it fails at 220119c.
  • Regression test or other mutation-sensitive proof: the three cases above.

Scope

Components: gestures

  • 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

The first CI run at 220119c failed lab's PageControl hold case. That head kept the clock object its window had when the host was made. Fake timers replace that object, so touch stamps converted on a stale origin, and the hold began late. This head looks the clock up at each read.

Local checks at 99175c7, one worker:

  • the three GestureHost clock cases: at cf8a455 the iframe case fails; at 220119c the replaced-clock case fails; at this head all three pass;
  • lab's PageControl file in the ui project: 220119c fails in 20 of 20 runs, main passes in 20 of 20, this head passes in 20 of 20;
  • the tests this change reaches on a merge with main 264e885 (test:ui --changed): 481 files, 14,331 passed; the core typecheck, eslint on gestures/, check:changesets and check:knowledge;
  • the gesture specs: Chromium 76 passed, 4 skipped; WebKit under the CI profile 68 passed, 12 skipped; presented hit testing 6 passed in each;
  • the second-document specs: Dialog in Chromium (10 passed) and WebKit (7 passed, 3 skipped), HoverCard in Chromium (3 passed) and Popover in Chromium (23 passed).

Public and internal API delta

Public: none.

Internal, changed: EventClock in utils/inputAge.ts widens from Pick<Performance, 'now'> to Pick<Performance, 'now' | 'timeOrigin'>. GestureHost.ts passes clockOf(doc), read at each event, to its event-time read, which subtracts timeOrigin from an epoch-stamped event. An epoch stamp converts only with its own window's origin. GestureHost.ts and longPressDetector.ts import the type.
Usage: const clock: EventClock | null = clockOf(doc);

No new module, hook or exported function: clockOf is already on main, so no owning-record line is needed.

Lines: product +67/−34 (GestureHost.ts +62/−32, inputAge.ts +5/−2), tests +100/−0, changeset +7/−0.

App-level size, eager JS gzip of the example-vite page in a Vite production build: no change as shipped or with one ContextMenu; +67 B with one Switch, which loads the gesture host.

A same-origin iframe or a Picture-in-Picture window stamps its events
on its own window's clock, which reads less than the page's. A long
press in an iframe gets a 120 ms tap stamped on that clock, and it may
not begin. A second case pins the page's own clock object for the
page's document.
A gesture host built every document's arena on the page's clock. In a
same-origin iframe or a Picture-in-Picture window, events come stamped
on that window's own clock, so the arena's timers ran early: a long
press began on a short tap. The host now reads the clock of its
document's window, and an epoch stamp converts with that window's time
origin. The page's document keeps the page's clock object, so nothing
changes there.
@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 1:39pm 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, 1:49 PM UTC

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 99175c7

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC
lab/TabBar 81.9 kB (+134 B) · 1.8 kB CSS (0) —
lab/ChatVirtualizer 55.7 kB (+119 B) · 144 B CSS (0) —
ButtonGroup 42.6 kB (+115 B) · 3.7 kB CSS (0) —
113 more components
Component Size LoC
lab/CommentThread 348.8 kB (+113 B) · 2.4 kB CSS (0) —
lab/PageControl 75.7 kB (+109 B) · 709 B CSS (0) —
ToggleButtonGroup 39.9 kB (+108 B) · 3.7 kB CSS (0) —
lab/NavigationScreen 83.5 kB (+105 B) · 1.5 kB CSS (0) —
lab/NavigationStack 83.5 kB (+105 B) · 1.5 kB CSS (0) —
Switch 105.5 kB (+100 B) · 10.0 kB CSS (0) —
AlertDialog 107.9 kB (+97 B) · 14.6 kB CSS (0) —
DateTimeInput 211.7 kB (+95 B) · 18.7 kB CSS (0) —
Lightbox 124.7 kB (+84 B) · 10.6 kB CSS (0) —
richtext/RichTextEditorToolbar 281.4 kB (+83 B) · 454 B CSS (0) —
Toast 99.9 kB (+78 B) · 10.3 kB CSS (0) —
lab/Comments 355.6 kB (+72 B) · 2.5 kB CSS (0) —
SegmentedControl 99.4 kB (+71 B) · 6.9 kB CSS (0) —
ToggleButton 88.8 kB (+69 B) · 10.1 kB CSS (0) —
lab/Schedule 108.4 kB (+69 B) · 3.9 kB CSS (0) —
Slider 110.9 kB (+67 B) · 8.8 kB CSS (0) —
DateInput 189.6 kB (+63 B) · 17.1 kB CSS (0) —
PowerSearch 292.8 kB (+62 B) · 24.2 kB CSS (0) —
TimeInput 164.8 kB (+60 B) · 16.1 kB CSS (0) —
AppShell 93.7 kB (0) · 13.5 kB CSS (0) —
AvatarGroupOverflow 50.4 kB (0) · 5.7 kB CSS (0) —
Banner 63.9 kB (0) · 10.5 kB CSS (0) —
BaseTypeahead 73.8 kB (0) · 11.0 kB CSS (0) —
BreadcrumbItem 86.7 kB (0) · 12.1 kB CSS (0) —
Button 62.0 kB (0) · 10.0 kB CSS (0) —
Calendar 72.9 kB (0) · 10.6 kB CSS (0) —
Carousel 71.7 kB (0) · 11.0 kB CSS (0) —
ChatComposer 80.5 kB (0) · 12.1 kB CSS (0) —
ChatComposerInput 78.1 kB (0) · 11.3 kB CSS (0) —
ChatComposerTokenElement 78.1 kB (0) · 11.3 kB CSS (0) —
ChatDictationButton 62.5 kB (0) · 10.1 kB CSS (0) —
ChatLayout 84.8 kB (0) · 10.6 kB CSS (0) —
ChatLayoutScrollButton 62.5 kB (0) · 10.2 kB CSS (0) —
ChatSendButton 62.4 kB (0) · 10.0 kB CSS (0) —
CheckboxInput 66.0 kB (0) · 9.2 kB CSS (0) —
CheckboxListItem 73.0 kB (0) · 11.5 kB CSS (0) —
ClickableCard 18.1 kB (0) · 7.3 kB CSS (0) —
CodeBlock 77.1 kB (0) · 11.3 kB CSS (0) —
Collapsible 28.5 kB (0) · 4.5 kB CSS (0) —
CommandPalette 74.9 kB (0) · 12.7 kB CSS (0) —
CommandPaletteItem 13.1 kB (0) · 3.6 kB CSS (0) —
ComplexSelector 73.0 kB (0) · 11.9 kB CSS (0) —
ContextMenu 111.0 kB (0) · 17.5 kB CSS (0) —
ContextMenuItem 32.9 kB (0) · 6.3 kB CSS (0) —
DateRangeInput 95.0 kB (0) · 12.5 kB CSS (0) —
DialogHeader 64.8 kB (0) · 11.5 kB CSS (0) —
DrawerHeader 64.9 kB (0) · 13.0 kB CSS (0) —
DropdownMenu 99.1 kB (0) · 17.6 kB CSS (0) —
DropdownMenuCheckboxItem 23.4 kB (0) · 6.6 kB CSS (0) —
DropdownMenuItem 22.6 kB (0) · 6.3 kB CSS (0) —
DropdownMenuRadioItem 23.4 kB (0) · 6.6 kB CSS (0) —
DropdownMenuSubMenu 72.0 kB (0) · 9.7 kB CSS (0) —
FileInput 70.9 kB (0) · 11.0 kB CSS (0) —
IconButton 62.0 kB (0) · 10.0 kB CSS (0) —
Item 17.6 kB (0) · 5.5 kB CSS (0) —
Link 54.7 kB (0) · 7.1 kB CSS (0) —
ListItem 72.1 kB (0) · 11.5 kB CSS (0) —
Markdown 190.8 kB (0) · 20.8 kB CSS (0) —
MobileNav 72.5 kB (0) · 10.6 kB CSS (0) —
MobileNavToggle 62.3 kB (0) · 10.0 kB CSS (0) —
MoreMenu 99.3 kB (0) · 17.6 kB CSS (0) —
MultiSelector 97.0 kB (0) · 16.9 kB CSS (0) —
NavHeadingMenu 16.9 kB (0) · 3.5 kB CSS (0) —
NumberInput 73.5 kB (0) · 11.5 kB CSS (0) —
Outline 24.9 kB (0) · 4.1 kB CSS (0) —
Pagination 112.5 kB (0) · 17.8 kB CSS (0) —
Popover 93.0 kB (0) · 14.2 kB CSS (0) —
RadioListItem 69.1 kB (0) · 10.2 kB CSS (0) —
SegmentedControlItem 17.5 kB (0) · 4.3 kB CSS (0) —
SelectableCard 18.3 kB (0) · 7.5 kB CSS (0) —
Selector 102.4 kB (0) · 17.4 kB CSS (0) —
SelectorOption 21.2 kB (0) · 6.1 kB CSS (0) —
SideNav 116.8 kB (0) · 11.4 kB CSS (0) —
SideNavCollapseButton 62.8 kB (0) · 10.1 kB CSS (0) —
SideNavHeading 77.6 kB (0) · 11.3 kB CSS (0) —
SideNavItem 72.4 kB (0) · 11.2 kB CSS (0) —
Step 31.2 kB (0) · 5.6 kB CSS (0) —
Stepper 63.6 kB (0) · 10.2 kB CSS (0) —
Tab 14.5 kB (0) · 4.2 kB CSS (0) —
Table 127.8 kB (0) · 18.4 kB CSS (0) —
TableCell 112.2 kB (0) · 17.9 kB CSS (0) —
TableHeaderCell 111.8 kB (0) · 17.7 kB CSS (0) —
TableSelectionToolbar 72.3 kB (0) · 13.3 kB CSS (0) —
TabMenu 73.9 kB (0) · 11.2 kB CSS (0) —
TextInput 69.6 kB (0) · 11.2 kB CSS (0) —
Thumbnail 66.3 kB (0) · 11.6 kB CSS (0) —
Timestamp 34.7 kB (0) · 10.3 kB CSS (0) —
Token 28.7 kB (0) · 4.7 kB CSS (0) —
Tokenizer 94.5 kB (0) · 18.8 kB CSS (0) —
TopNav 74.3 kB (0) · 11.0 kB CSS (0) —
TopNavHeading 77.2 kB (0) · 11.3 kB CSS (0) —
TopNavItem 14.1 kB (0) · 4.0 kB CSS (0) —
TopNavMegaMenu 71.7 kB (0) · 11.9 kB CSS (0) —
TopNavMegaMenuItem 13.8 kB (0) · 4.2 kB CSS (0) —
TopNavMenu 76.6 kB (0) · 11.3 kB CSS (0) —
TreeList 45.7 kB (0) · 5.6 kB CSS (0) —
Typeahead 82.7 kB (0) · 12.5 kB CSS (0) —
lab/ChatEmojiPicker 108.2 kB (0) · 773 B CSS (0) —
lab/ChatReactionBar 109.4 kB (0) · 1.1 kB CSS (0) —
lab/CommentComposer 154.4 kB (0) · 1.9 kB CSS (0) —
lab/CommentPin 58.9 kB (0) · 1.2 kB CSS (0) —
lab/DialogHeroHeader 85.0 kB (0) · 372 B CSS (0) —
lab/DiffViewer 89.1 kB (0) · 2.1 kB CSS (0) —
lab/EmojiPicker 88.7 kB (0) · 751 B CSS (0) —
lab/ListInput 90.0 kB (0) · 922 B CSS (0) —
lab/SelectableCardGroup 66.1 kB (0) · 162 B CSS (0) —
lab/TabBarItem 3.9 kB (0) · 1.8 kB CSS (0) —
lab/TabBarMoreList 94.2 kB (0) · 1.8 kB CSS (0) —
lab/TourStep 99.2 kB (0) · 590 B CSS (0) —
lab/TransferList 104.1 kB (0) · 1.2 kB CSS (0) —
lab/TransferListSelector 111.9 kB (0) · 1.4 kB CSS (0) —
richtext/RichTextEditor 300.2 kB (0) · 2.6 kB CSS (0) —
richtext/RichTextView 278.5 kB (0) · 2.3 kB CSS (0) —

Package size: @astryxdesign/core 7.30 MB packed (+765 B); 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

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 93d0770

@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 fix itself is right: the new case fails on main and passes here, and the page's own document keeps the same clock object. One change is needed before it lands:

  • GestureHost.ts:924-926 copies the window-clock lookup that clockOf in utils/inputAge.ts already owns, and documentClock reads it again; take this.timing from one clockOf(doc) call, build the arena clock from it, and widen EventClock to Pick<Performance, 'now' | 'timeOrigin'> so eventTime keeps its epoch conversion.

CI has not run on this head yet.

Automated review (maintainer link)

The gesture host read its document's window clock itself, a copy of
the lookup that clockOf in the input-age utility owns for the press
tracker and the long-press hold. The host now takes that clock from
one clockOf call and builds the arena clock from it. EventClock gains
the time origin, so an epoch stamp still converts on that clock. In
the page's document clockOf returns the page's own performance, so
the host keeps the same clock object.
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 220119c

@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 11, 2026

@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: it starts once the pull request is marked ready for review.

The host now takes its window's clock from clockOf, which resolves the earlier change request. The new long-press case fails on main and passes here, and in Chromium a 120 ms tap in a same-origin iframe or a Picture-in-Picture window no longer starts a 500 ms long press, while the page's own document keeps its clock object.

Automated review (maintainer link)

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 220119c

@vjeux
vjeux marked this pull request as ready for review November 11, 2026 12:24
Fake timers replace the page's performance object after the gesture
host exists. A hold that starts then must begin at its deadline: the
touch's epoch stamp converts on the clock the page has now.
The host kept the clock object its window had when the host was made.
A page that replaces it later, as fake timers do, then converted touch
stamps on a stale origin, so a hold began far from its deadline. The
host now looks the clock up at each read. The page's own document
keeps the page's clock, found by its window.
@vjeux
vjeux marked this pull request as draft November 11, 2026 12:55
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 99175c7

@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: it starts once the pull request is marked ready for review.

The host now looks up its window's clock through clockOf at each event, which fixes the PageControl hold case that CI failed on the previous revision; the new case for a clock replaced after the host exists fails there and passes here. The iframe long-press case still fails on main and passes here, and in Chromium a 120 ms tap in a same-origin iframe no longer starts a 500 ms long press while the page's own document keeps its timing.

Automated review (maintainer link)

@vjeux
vjeux marked this pull request as ready for review November 11, 2026 13:50
@cixzhang
cixzhang merged commit b8835b8 into meta:main Nov 11, 2026
136 checks passed
@vjeux
vjeux deleted the fix/gesture-host-document-clock branch November 11, 2026 14:29

This branch was successfully deployed

1 active deployment
Preview — 99175c72 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