Skip to content

chore(core): useAttachment can follow its node into another document, for a caller that asks - #9910

Closed
vjeux wants to merge 1 commit into
meta:mainfrom
vjeux:uikit/c19-attach-document
Closed

vjeux wants to merge 1 commit into
meta:mainfrom
vjeux:uikit/c19-attach-document

Conversation

@vjeux

@vjeux vjeux commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

The menu press's ref form attaches listeners on its menu's document, so it must attach again when its menu moves into another document, such as a Picture-in-Picture window. useAttachment is the shared attach-and-release path the gesture hooks, the pager and useAnimator use, and the menu press moves onto it in #9504. It had no way to follow a node into another document.

Intended invariant

architecture:react-component-runtime INV5 and INV6 stay as they are for every current caller. A replaced node is released before the new one attaches, a commit that changes nothing does nothing, and a node that moves to another document keeps its attachment unless its caller asks otherwise. useAnimator keeps its values across such a move (spec:AST-107 FR3).

Change

useAttachment takes an internal option, {followsDocument: true}. With it, useAttachedNodes records each node's document and, when a node moves to another document, releases the attachment and attaches it again. useAttachmentPair and every current caller pass no option, so their behavior is unchanged. No behavior change: no caller opts in until #9504.

Evidence

  • Failure before the change: with useAttachment as on main (NOT-FOR-LANDING arm eb8815f), the opt-in case fails.
  • Success after the change: with the option, the node is released and attached again once, in the document it moved to.
  • Product/runtime behavior verified unchanged: a default useAttachment and useAttachmentPair keep their attachment across a document move, and useAnimator keeps its values. With an earlier version that followed the document for every caller (arm ad7525b), those three cases fail.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Stack: #9910 → #9504 → #8458.

#9504 edits this PR's changeset, so the two merge in one release.

Testing

At c6a1cb5, this pull request is rebased onto main 5083ead with no change: the same patch as bac57ef, so #9504 stacks on exactly this head. The core type check and this pull request's tests (16 of 16) pass there; the gates below ran at bac57ef.

Local gates at bac57ef on main a343c79: the core type check, pnpm lint, strict lint, Prettier, the knowledge and changeset checks and review:pre; the gesture, press tracker, pager, animator, motion and hooks units (2,555 of 2,556; the one failure, PowerSearch's bottom-sheet adopter case, timed out finding a lazily loaded search box on a heavily loaded box and passes three runs of three here and on main). The core ui suite: 18,124 passed. The RadioListItem and Switch source-build tests fail the same way on main in this checkout because a Babel preset does not resolve. Markdown's FR23 overhead case and PowerSearch's SSR case timed out on the loaded box; both pass two runs of two here and on main. On a fresh Storybook build, the gesture, pager and animator interaction specs in Chromium: 119 passed, 6 skipped. NOT-FOR-LANDING arms: eb8815f, main's useAttachment under this head's tests, fails the opt-in case; ad7525b, a version that followed the document for every caller, fails the three unchanged-caller cases, useAnimator's included.

@vercel

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

Request Review

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

astracat-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 4, 2026, 8:41 PM UTC

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded skipped. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@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 are needed, and approval also waits on an engineering owner's decision about the behavior itself.

  • useAnimator now drops its values when its element moves to another document: after the move and a render, get() reports x 0 and opacity 1 while the element still shows its offset, and the next set() jumps it back (useAttachment.ts:82-86 releasing through animator/createAnimator.ts:285-290), which contradicts spec:AST-107 FR3, so keep the animator out of the document re-check and add a useAnimator test for the move.
  • The title and changeset say gestures, press tracking, the pager and the animator attach again when the element moves, but the re-check runs only at the component's next render, Switch and Slider attach outside useAttachment and stay on the old document, and re-attaching the animator moves nothing to the new document, so reword both to match, for example: "When code outside React moves a mounted element into another document, such as a Picture-in-Picture window, its gesture recognizers, press tracking and pager attach in that document at the component's next render, instead of staying bound to the old one."

No current record makes a node's move into another document an attachment lifecycle event: architecture:react-component-runtime INV6 names attachment, null detachment and replacement only. An engineering owner needs to decide that behavior and name or add the clause that governs it, and records the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner. The two fixes above are needed either way.

[Automated review]

nodes.every(
(node, index) =>
node === current.nodes[index] &&
node.ownerDocument === current.documents[index],

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.

This re-check also reaches useAnimator, whose release (attachElement(null) in useAnimator.ts) resets every channel to rest (animator/createAnimator.ts:285-290). After a move and a render, get() reports x 0 while the element still shows its offset, and the next set() jumps it, which contradicts spec:AST-107 FR3. Re-attaching moves nothing of the animator's to the new document (it reads ownerDocument.defaultView per call and keeps the page's frame clock), so it can stay out of this check, for example through an opt-in that only the gesture-host callers pass. A useAnimator test for the move would cover it.

'@astryxdesign/core': patch
---

[fix] An element's gesture recognizers, press tracking, pager and animator attach again when the element moves to another document, such as a Picture-in-Picture window, instead of staying bound to the old one.

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.

This promises more than the change does: the re-check runs only at the component's next render, Switch and Slider attach outside useAttachment and stay on the old document, and re-attaching the animator moves nothing to the new document. Suggested: "[fix] When code outside React moves a mounted element into another document, such as a Picture-in-Picture window, its gesture recognizers, press tracking and pager attach in that document at the component's next render, instead of staying bound to the old one."

Comment on lines +60 to +61
* made once every node is there, and released when a node, a node's document
* or `key` changes and at unmount.

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 (comment style): this sentence is passive. Suggested: "It attaches once every node is there. It releases the attachment at unmount and when a node, a node's document or key changes."

@vjeux
vjeux force-pushed the uikit/c19-attach-document branch from 1a08cd3 to bac57ef Compare November 4, 2026 09:16
@vjeux vjeux changed the title fix(core): a gesture, pager or animator follows its element into another document chore(core): useAttachment can follow its node into another document, for a caller that asks Nov 4, 2026
@cixzhang

cixzhang commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

/approve-spec bac57ef

@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 is a draft from a fork, so CI runs once it is marked ready and a maintainer adds the ci:run label.

The opt-in followsDocument option has no caller yet, every current caller keeps its attachment (and useAnimator its values) across a document move, and the new tests fail without the change. Whether a menu press should follow its document is for the first caller that opts in to settle.

[Automated review]

Comment on lines +27 to +28
* With `followsDocument`, a node that moves to another document is released
* and attached again.

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 (comment style): this sentence is passive and does not say when the re-attach happens. Suggested: "With followsDocument, it also releases a node that moved to another document and attaches it again at the next commit."

@vjeux
vjeux marked this pull request as ready for review November 4, 2026 09:35
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 4, 2026
@cixzhang
cixzhang marked this pull request as draft November 4, 2026 10:16
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 10:16
… for a caller that asks

An attachment that listens on its node's document, as the menu press does, must attach again when the node moves into another document, such as a Picture-in-Picture window. useAttachment gains an internal followsDocument option for that. No current caller passes it, so the gesture hooks, the pager and useAnimator keep their behavior: a document move leaves their attachment as it is, and useAnimator keeps its values.

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

This pull request is reviewed as part of its stack; see the review on #8458.

@vjeux

vjeux commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing: its option's only caller was #9504, which is closed.

@vjeux vjeux closed this Nov 5, 2026

This branch was successfully deployed

1 active deployment
Preview — c6a1cb53 Deployed Nov 4, 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