Skip to content

fix(usePanGesture): write the onPan ref at commit - #10090

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/f2-pan-onpan-commit
Nov 5, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/f2-pan-onpan-commit

Conversation

@vjeux

@vjeux vjeux commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

User impact

usePanGesture could hand a drag to an onPan from a render React threw away. A transition that suspends is one such render. The committed element then ran a listener its screen never showed, with that render's props and state.

Problem and solution fit

  • Why it occurs: the hook copied onPan into a ref during render. React can render and then discard that render, and the ref keeps the discarded listener.
  • Why it harms the task: the pan calls the ref's listener, so a drag runs code from a render that never committed.
  • Why it matters: transitions and Suspense discard renders by design, so any app that uses them with the hook can reach it.

The fix copies onPan into the ref at commit. A layout Effect runs only for renders React commits, and a drag's events arrive only after a commit.

Expected behavior and authority

  • spec:AST-107 FR6: "the hook delegates entirely to its factory and has no behavior of its own." Calling a listener that no committed render passed is behavior of its own.
  • architecture:react-component-runtime INV4: ref-backed coordination must preserve the current API contract.
  • React's useRef reference: do not write ref.current during rendering, except to initialize it.

Smallest restoration

onPanRef.current = onPan moves into useIsomorphicLayoutEffect, Core's server-safe layout Effect. Its comment says why it runs at commit. There is no API, timing, or visual change.

Core has no shared latest-ref helper. useGestureRecognizer (lines 105–107), PickerWheel and Markdown each write their listener's ref in a layout Effect, and this follows that pattern. review:pre flags such an Effect as a copy into a ref (INV3); here the copy at commit is the fix. useEffectEvent needs React 19.2, and Core supports 19.0.

The changeset is [chore] Internal: because the hook has not shipped yet.

Evidence

  • Reproduction before the change: the new case fails on main without the fix (e9a56db, on this fork's bank/f2/pan-onpan-commit-main-red-arm). The discarded render's onPan received the drag's 5 events.
  • Result after the change: the committed onPan receives began, changed and ended, and the discarded one receives nothing.
  • Representative unchanged path: "reports what its factory reports, through the latest onPan" still passes. A rerender that commits still hands the drag to its new listener.
  • Regression test: "keeps the committed onPan when React discards a render, as a suspended transition does" in createPanGesture.test.tsx.

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

Local gates at a4d8303, one commit on main 0a1e6a0.

  • npx vitest run --project ui packages/core/src/gestures/__tests__/createPanGesture.test.tsx: 15 passed. The new case fails on main without the fix.
  • Core's unit tests: 707 files, 19,376 tests passed.
  • tsc --project packages/core/tsconfig.json --noEmit, strict ESLint, Prettier and pnpm check:changesets: clean.
  • node scripts/pre-review.mjs --base main: one finding, the Effect that copies into a ref, answered under Smallest restoration.

usePanGesture kept the latest onPan in a ref written during render. A
render React discards, as a suspended transition does, left its onPan
there, so a drag on the committed element called a listener from a
render that never committed. The hook now writes the ref in a layout
effect, as useGestureRecognizer already does.
@vercel

vercel Bot commented Nov 5, 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 5, 2026 4:44pm UTC

Request Review

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

astracat-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 5, 2026, 4:45 PM UTC

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 9f0facd

Storybook · Sandbox · built from this PR's head

Package size: measured; main has no measurement of the merge base to compare yet.

API changes: cli +8 · ~1 · −0 (against the merge base's committed report)

Committed API report behind this build: cli 9 rows, core 8 rows; run pnpm api:report.

9 API changes (advisory)
Package Where Signature Usage
+ cli ./api · Types · type SearchResultEntry deprecated?: ComponentDeprecation | undefined import type {SearchResultEntry} from '@astryxdesign/cli/api'; const x: SearchResultEntry = {deprecated: …}
+ cli ./authoring · Types · interface ComponentDeprecation interface ComponentDeprecation import type {ComponentDeprecation} from '@astryxdesign/cli/authoring'
+ cli ./authoring · Types · interface MultiComponentDoc deprecated?: ComponentDeprecation import type {MultiComponentDoc} from '@astryxdesign/cli/authoring'; const x: MultiComponentDoc = {deprecated: …}
+ cli ./authoring · Types · interface SingleComponentDoc deprecated?: ComponentDeprecation import type {SingleComponentDoc} from '@astryxdesign/cli/authoring'; const x: SingleComponentDoc = {deprecated: …}
+ cli ./doc · Types · interface ComponentBaseDoc deprecated?: ComponentDeprecation import type {ComponentBaseDoc} from '@astryxdesign/cli/doc'; const x: ComponentBaseDoc = {deprecated: …}
+ cli ./doc · Types · interface SubComponentDoc deprecated?: ComponentDeprecation import type {SubComponentDoc} from '@astryxdesign/cli/doc'; const x: SubComponentDoc = {deprecated: …}
+ cli ./doc · Also exported from an earlier entry point · ComponentDeprecation ComponentDeprecation (./authoring) import {ComponentDeprecation} from '@astryxdesign/cli/doc'
+ cli ./template · Also exported from an earlier entry point · ComponentDeprecation ComponentDeprecation (./authoring) import {ComponentDeprecation} from '@astryxdesign/cli/template'
~ cli ./api · Functions · function search function search: (query: string, options?: { cwd?: string | undefined; type?: "template" | "component" | "hook" | "theme" | "doc" | undefined; limit?: number | undefined }) => Promise<SearchResponse> → function search: (query: string, options?: { cwd?: string | undefined; type?: "template" | "component" | "doc" | "theme" | "hook" | undefined; limit?: number | undefined }) => Promise<SearchResponse> import {search} from '@astryxdesign/cli/api'; search(…)

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.

Approved pending CI: CI has not run on this head yet. Moving the onPan ref write to commit keeps a discarded render's listener away from the next drag, and the new suspended-transition test fails without the fix and passes with it.

Next: mark the pull request ready for review, and a maintainer adds the ci:run label so CI runs on the fork branch.

  • Optional: the sentence added to the file header in usePanGesture.ts repeats the reason the inline comment already gives and pushes the header past about 12 lines; consider dropping it.

[Automated review]

Comment on lines +13 to +15
* ref, so a new function each render re-creates nothing. The hook writes
* the ref at commit, so a render React discards leaves no listener. A drag
* costs no React render.

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: this sentence repeats the reason the comment at lines 48-49 gives, and the header grows to 14 lines, past the about-12-line header limit in architecture:knowledge-contracts INV29. Keeping the original two lines leaves the reason in one place:

 *   ref, so a new function each render re-creates nothing. A drag costs no
 *   React render.

@vjeux
vjeux marked this pull request as ready for review November 5, 2026 15:13
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 5, 2026
@cixzhang
cixzhang marked this pull request as draft November 5, 2026 15:15
@cixzhang
cixzhang marked this pull request as ready for review November 5, 2026 15:16

@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: the CI workflow is still running on this head. Moving the onPan ref write to commit keeps a discarded render's listener away from the next drag, and the new suspended-transition test fails without the fix and passes with it.

  • Optional: the sentence added to the file header in usePanGesture.ts repeats the reason the inline comment already gives and pushes the header past about 12 lines; consider dropping it.

[Automated review]

@cixzhang
cixzhang merged commit ecd6523 into meta:main Nov 5, 2026
66 checks passed
@vjeux
vjeux deleted the uikit/f2-pan-onpan-commit branch November 5, 2026 17:16

This branch was successfully deployed

1 active deployment
Preview — 9f0facd6 Deployed Nov 5, 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) 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