Skip to content

spec(layer-runtime): a click inside a layer stops at the layer root - #9398

Merged
cixzhang merged 7 commits into
mainfrom
spec/layer-click-boundary
Nov 2, 2026
Merged

cixzhang merged 7 commits into
mainfrom
spec/layer-click-boundary

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

People clicking inside an open layer (a Tooltip, HoverCard, Popover, menu, sheet, dialog, or toast) should never also activate the row, card, field, or app element around the layer's trigger. Today React carries the click out through the portal, and only Tooltip and HoverCard are guarded, and only against the Core containers that check them. This records one rule at the layer runtime: a press that starts inside a layer root stops at that root in the React tree, while document and window listeners and light dismiss still hear it. A new layer gets the rule by using the runtime, so containers stop carrying per-site guards.

Exact decision needed

Who owns the layer boundary for presses that start inside a layer, and what release class closing it carries.

Existing authority searched

  • architecture:layer-runtime INV1–INV15 and its open proposal for INV16 (the input hold); no invariant says where a press that starts inside a layer may travel. INV9 governs outside channels only. INV17 is the next free id.
  • spec:AST-038 FR7 and FR8 govern which providers cross the layer boundary, not where events travel; INV17 reuses the same content roots for a separate fact.
  • component:Tooltip FR11, component:HoverCard FR11, and component:ChatComposer FR8 state the Tooltip/HoverCard-only form of this rule.
  • Open Tooltip and HoverCard press-toggle pull requests: a press on the trigger sits outside the layer, so they are unaffected.

Decision

The owner chose this on 2026-11-01 (the layer runtime owns the boundary) and ruled it a patch.

  • INV17 — A click inside a layer stops at the layer root. A pointer, mouse, touch, or click event that starts inside a layer root (both useLayer renderers and the Dialog, Drawer, Lightbox, MobileNav, BottomSheetPanel, and ToastViewport content roots) runs the handlers inside the layer, then stops propagating through the React tree: no bubble-phase handler on an ancestor of the layer's JSX position receives it, including a caller's own element. An ancestor's capture-phase handler runs before the stop and still receives it. A nested layer stops at its own root. The native event is not stopped, so document and window listeners and light dismiss still receive it. Keyboard, focus, input, wheel, and drag events are out of scope.
  • Release class: patch [fix] for every caller no released record covered (the owner's ruling, 2026-11-01). The one released promise, component:SelectableCard FR2's caller onClick for clicks that do not toggle (including clicks inside an open Tooltip or HoverCard surface), keeps until the next minor, where that part is staged as [breaking] (spec:AST-017 FR32).
  • Implementation constraint: one shared seam stops propagation through the React tree only. React's stopPropagation() also stops the native event in React 19, which would break ContextMenu's outside mousedown, Typeahead's pending click, and the layer's keep-open pointerup.

Rejected alternatives

  • The clickable container owns it: app wrappers would still receive layer clicks, and every new container must remember the rule.
  • Per-site guards (today's shape): Popover, menu, and Dialog clicks still reach Core rows and cards.

Changed records

  • component:SelectableCard FR2: the staged next-minor layer exception, marked not built; Contract at a glance (Builder impact, Compatibility/readiness), Compatibility and migration, and Current-state impact state the staged [breaking] change and its migration (a handler that needs those presses moves to the layer content).
  • architecture:layer-runtime: INV17 (bubble-phase handlers) (also routed under the layering review trigger); an owning-code sentence for the React-tree-only seam; a change-coupling bullet; a verification row; Current gaps marks INV17 "Implementation gap: not built" with the patch rationale; the record's opening line names INV17 beside INV14 and INV15.
  • component:Tooltip FR11 and component:HoverCard FR11: cite INV17 (requirement text and basis).
  • component:ChatComposer FR8: notes that INV17 subsumes its layer clause; the focus-ring and body-click clauses are unchanged.

Claim scope and non-goals

Keyboard, focus, input, wheel, and drag propagation; presses on a trigger (outside the layer); outside-press routing (INV9). The per-site guard lines in other records stay until the code lands.

Follow-up: guards removable once INV17 is built

  1. packages/core/src/Layer/layerSurfacePress.ts: the registerLayerSurface / isLayerSurface registry, replaced by the runtime's record of open roots.
  2. packages/core/src/Tooltip/useTooltip.tsx: ref={registerLayerSurface} on the content.
  3. packages/core/src/HoverCard/useHoverCard.tsx: ref={registerLayerSurface} on the content.
  4. packages/core/src/Item/Item.tsx: the isLayerSurface walk in the row click.
  5. packages/core/src/Token/Token.tsx: the isLayerSurface walk in the container click.
  6. packages/core/src/Chat/ChatComposer.tsx: the layer-surface skip in the body click.

Kept and re-pointed: hooks/useClickableContainer.ts hasInteractiveAncestor is exported, so its answer for a press inside an open layer stays the same, sourced from the runtime.

Evidence and implementation relationship

Spec only; no implementation in this pull request. The native-event constraint was confirmed with a React 19 probe: a full stopPropagation() in a React handler silenced a document bubble listener, while capture listeners and the browser's light dismiss kept working.

Writing rubric results

  • R1 narration: none; the gap paragraph states the current behavior ("still propagates") and the compatibility class in the present tense.
  • R2 research in the record: none; the React 19 probe is summarized here, and the record keeps only the one-sentence constraint the seam rests on.
  • R3 evidence naming a change: none; the INV17 verification row names the suite's cases and failure signals.
  • R4 rejected alternatives over one line or outside a decision: none in the records; they live in this description.
  • R5 pull request or issue references remaining: none.
  • R6 ruled open questions still listing options: none.

Scope

  • This PR contains specification records only.
  • It records observable behavior and preserves equivalent internal implementations.
  • Any named internal mechanism is intentionally public, names its dependent caller/system, and explains why an equivalent implementation would not satisfy the contract.
  • Verification states the evidence layer and failure signal without prescribing CI job/workflow topology.
  • It records one intentional durable decision, not a rescue for a separable tagalong.
  • The canonical knowledge owner, affected current claims, and overlapping open work are named; any ownership collision is resolved or called out for human decision.
  • Adjacent API, visual, accessibility, composition, and implementation facts remain outside scope unless this exact decision depends on them.
  • Public text and artifacts contain no internal Meta context.

Validation

  • pnpm install --frozen-lockfile
  • pnpm check:knowledge: Knowledge templates and records are aligned.
  • Prettier
  • git diff --check

@vercel

vercel Bot commented Nov 1, 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 2, 2026 5:59am UTC

Request Review

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

astracat-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

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

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 1, 2026
@cixzhang

cixzhang commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 0616399

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 2097367

⏳ Building… Until it's ready, Storybook · Sandbox open the branch's previous preview.

Current run: Heavy CI deferred: runs when marked ready and before merge. Lint, typecheck and any path-filtered checks ran on this push.


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.

Requesting changes: the INV17 direction is owner-approved, but the record leaves two current specs contradicting it. Please amend component:SelectableCard FR2, which still promises that a caller onClick runs for a click inside an open Tooltip or HoverCard, and revisit the patch [fix] class, which conflicts with spec:AST-017 FR1, FR5 and FR32 because the record itself gives affected app wrappers a migration. While you are in there, scope INV17's "no ancestor … receives it" to bubble-phase handlers, since an ancestor's capture-phase handler (ChatComposer's onPointerDownCapture, for example) runs before any stop at the layer root can act.

[Automated review]

Comment thread docs/architecture/layer-runtime.md Outdated
Comment on lines +516 to +517
the layer, then stops propagating through the React tree: no ancestor of the
layer's JSX position receives it, including a caller's own element. A nested

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.

React runs an ancestor's capture-phase handlers before anything inside the layer, so a stop at the layer root cannot keep them out. Core already has such ancestors: ChatComposer's body onPointerDownCapture and Item's swipe onClickCapture, which can even stop the click before the layer's own handlers run. Suggest scoping this sentence to bubble-phase handlers and saying capture-phase handlers on ancestors still run first; the INV17 verification row's failure signal needs the same scope.

Comment thread docs/architecture/layer-runtime.md Outdated
Comment on lines +564 to +568
`component:HoverCard` FR11). Compatibility: closing the gap is a patch
`[fix]`. Propagation across a layer boundary is not intended behavior, so a
caller's ancestor handler receiving clicks from inside a layer is the defect;
an app wrapper that relied on it attaches its handler to the layer content
instead.

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.

component:SelectableCard FR2 still documents the behavior this removes: a caller onClick runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. The migration sentence here concedes that some consumers must change source. Under spec:AST-017 FR1, FR5 and FR32 that makes it a [breaking] correction rather than a patch [fix]. Please reclassify it or narrow the patch claim, and amend SelectableCard FR2 in this PR.

…rs; the patch class is the owner's ruling; SelectableCard FR2 cites INV17
@cixzhang

cixzhang commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec a4a63b3

@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: INV17's direction is owner-approved at this head, but its release class still conflicts with the release-compatibility spec. The record calls closing the gap a patch [fix] because "no record ever promised" that a press inside a layer reaches the layer's JSX ancestors, yet component:SelectableCard FR2 as released in 0.7.5 says a caller onClick "also runs for clicks that do not toggle", which this PR has to amend. Under spec:AST-017 FR5, FR32–FR34 and DEC-11 that is a correction with a released victim, so please class it [breaking] (staged while main declares a patch) or narrow the patch claim to callers no released record covered.

  • Mark SelectableCard FR2's new layer exception as an implementation gap, since the component still calls the caller onClick for those clicks.
  • Scope the INV17 change-coupling bullet and verification row to bubble-phase handlers, matching INV17.
  • Update the description's Decision bullet and Changed records to match the record.

[Automated review]

Comment thread docs/architecture/layer-runtime.md Outdated
Comment on lines +566 to +571
`component:HoverCard` FR11). Compatibility: the owner ruled on 2026-11-01
that closing the gap ships as a patch `[fix]` (`spec:AST-017` FR5's fix
class): no record ever promised that a press inside a layer reaches the
layer's JSX ancestors, so that propagation is the defect the fix removes, not
a supported behavior with a migration. A handler that needs presses inside a
layer belongs on the layer content.

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.

A released record did promise this: component:SelectableCard FR2 in 0.7.5 says the caller onClick "also runs for clicks that do not toggle", and this PR has to amend FR2 to drop clicks inside a layer. Under spec:AST-017 FR5, FR32–FR34 and DEC-11 that makes closing the gap a correction with a released victim ([breaking], staged per FR34 while main declares a patch), and FR6 says engineering approval cannot make it nonbreaking. Please reclassify it or narrow the patch claim, and drop the "no record ever promised" premise.

| ID | Invariant | Basis |
| --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant` and `selected`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests |
| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, except a click inside an open layer, which stops at the layer root (`architecture:layer-runtime` INV17). A caller `onMouseUp` runs after the card's own handling. | Current source and tests |

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 exception is not shipped: SelectableCard.tsx still calls the caller onClick for a click inside an open layer, and INV17 is "not built". Since the record says it "records shipped behavior", please add an Implementation gap: not yet built … (Current-state impact) note here and a matching Current-state impact bullet.

Comment on lines +592 to +594
- A change to a layer content root or to the INV17 seam verifies that a press
inside each kind of root reaches no ancestor handler and still reaches
document listeners and light dismiss.

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.

INV17 now lets capture-phase ancestors receive the press, so "reaches no ancestor handler" contradicts it (Core has onPointerDownCapture on ChatComposer's body and a swipe onClickCapture on Item). Suggest "reaches no bubble-phase ancestor handler" here and in the INV17 verification row's failure signal.

…ectableCard's released onClick promise staged for the next minor; bubble-phase wording
@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 866b648

@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: INV17's direction and its release tiers are settled at this head, but three pieces of text still disagree with the approved rule.

  • SelectableCard FR2 now stages a [breaking] change for the next minor, yet the record's Compatibility and migration section, its Builder impact and Compatibility/readiness cells, and Current-state impact still say there is no change or migration; please state the staged change and its migration there.
  • The INV17 verification row still fails on "an ancestor handler"; please scope it to bubble-phase handlers, since INV17 lets capture-phase ancestors receive the press.
  • The description's INV17 Decision bullet says no ancestor receives the press; please match the record's bubble-phase wording.

[Automated review]

| ID | Invariant | Basis |
| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
| FR1 | SelectableCard renders `component:Card` with the given `variant`, `elevation`, `padding`, and sizing. The root also carries the `selectable-card` target reflecting `variant` and `selected`, and the first child is a visually hidden native `input type="checkbox"` named by `label` with `checked` equal to `isSelected`. | Current source and tests |
| FR2 | While enabled, a click on the card surface, a click or Space on the checkbox, or Enter on the checkbox calls `onChange(!isSelected)` exactly once. A click that belongs to nested interactive content, an open Tooltip or HoverCard surface (`component:Tooltip` FR11), or selected text does not toggle. A caller `onClick` runs after the toggle for a surface click, before it for a click or Space on the checkbox, and not at all for Enter; it also runs for clicks that do not toggle, including a click inside an open Tooltip or HoverCard surface. At the next minor, staged as `[breaking]`, a click inside an open layer stops at the layer root and the caller `onClick` no longer receives it (`architecture:layer-runtime` INV17); implementation gap: not built. A caller `onMouseUp` runs after the card's own handling. | Current source and tests |

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.

FR2 now stages a [breaking] change for the next minor, but this record still says "Migration decision: none" and "records shipped behavior" under Compatibility and migration, "Builder impact: None" in the glance table, and lists only two gaps under Current-state impact. Please state the staged change and its migration (move a handler that needs those clicks onto the layer content) there, and add a Current-state impact bullet for this gap.

Comment thread docs/architecture/layer-runtime.md Outdated
| INV9 | Representative Dialog, ContextMenu, Tooltip/HoverCard, and BottomSheet source/tests | A current local channel silently changes ownership or policy |
| INV10 | `LayerProvider.tsx`, `LayerProvider.test.tsx`, `useToast.tsx`, `ToastViewport.test.tsx`, and `ToastViewport.modalHost.test.tsx` | Provider begins relocating ordinary layers, Toast fallback loses its current lifecycle, or a default provider renders differently from no provider |
| INV14, INV15 | Source boundary check over Core for top-layer hosts, exit copies, backdrop elements, lift, and rectangle-morph code outside the runtime and the lift module | A component building its own copy of a mechanism INV14 lists (top-layer mounting, close-request delivery, hold, exit copy, or backdrop element), or re-implementing the lift or the grow |
| INV17 | One runtime suite over every kind of layer root: a `useLayer` layer, inline and portaled, and the Dialog, Drawer, Lightbox, MobileNav, BottomSheetPanel, and ToastViewport content roots, each inside a plain `onClick` wrapper and a Core clickable container; nested layers | A click inside a layer root that reaches an ancestor handler, a caller's wrapper included; an outer layer's handler that receives an inner layer's press; or a document listener or light dismiss that no longer receives it |

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.

INV17 lets an ancestor's capture-phase handler receive the press (Item's swipe onClickCapture, ChatComposer's onPointerDownCapture), so "reaches an ancestor handler" would fail a correct build. Suggest "reaches an ancestor bubble-phase handler, a caller's wrapper included", matching the change-coupling bullet.

…ick change and its migration; INV17 verification names bubble-phase handlers
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 2, 2026
@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec b1f407e

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 2, 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.

Approval recommended: INV17 and SelectableCard FR2's staged [breaking] change are owner-approved at this head, and the SelectableCard compatibility sections, the INV17 verification row and the description now match the approved rule. Nothing else is needed before merge; the follow-up build should keep the stop React-tree only and keep SelectableCard's caller onClick receiving layer clicks until the next minor, as the records say.

[Automated review]

@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 8dc1e6d

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

Approval recommended: INV17 and SelectableCard FR2's staged [breaking] change are owner-approved at this head, and the records' statements about the shipped layer runtime (the Tooltip/HoverCard-only guard and the three document listeners the React-tree-only seam protects) check out. The latest push only merges main and leaves the records' text unchanged. Nothing else is needed before merge; the follow-up build should keep the stop React-tree only and keep SelectableCard's caller onClick receiving layer clicks until the next minor, as the records say.

[Automated review]

@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec c9423be

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

Approval recommended: INV17 and SelectableCard FR2's staged [breaking] change are owner-approved at this head, and the records' statements about the shipped layer runtime (the Tooltip/HoverCard-only guard and the three document listeners the React-tree-only seam protects) check out. The latest push only merges main and leaves the records' text unchanged. The follow-up build should keep the stop React-tree only and keep SelectableCard's caller onClick receiving layer clicks until the next minor, as the records say.

[Automated review]

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

Approval recommended: architecture:layer-runtime INV17 and SelectableCard FR2's staged [breaking] change are owner-approved at this head, and the records' statements about the shipped layer runtime (the Tooltip/HoverCard-only guard and the three document listeners the React-tree-only seam protects) check out. The latest push only merges main and leaves the records' text unchanged. The follow-up build should keep the stop React-tree only and keep SelectableCard's caller onClick receiving layer clicks until the next minor, as the records say.

[Automated review]

@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 2097367

@cixzhang
cixzhang merged commit 41aa832 into main Nov 2, 2026
90 of 93 checks passed
@github-actions
github-actions Bot deleted the spec/layer-click-boundary branch November 3, 2026 06:05

This branch was successfully deployed

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

Labels

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.

1 participant