Skip to content

feat(layer): the layer runtime owns the viewport inset (spec:AST-059) - #6919

Merged
cixzhang merged 16 commits into
mainfrom
layer-viewport-inset-runtime
Oct 6, 2026
Merged

cixzhang merged 16 commits into
mainfrom
layer-viewport-inset-runtime

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

#6916 (spec:AST-059) has landed as current; this PR carries one post-merge record delta (FR4 states the slide as its own option; two block-axis verification rows) beside the implementation. Implements the record, moves the viewport stories to Layer, and amends the two current records the record names.

User need

A person who opens a 352px menu from a control near a panel edge gets a 274px one today, because an aligned layer's inline size is capped to the span of viewport beside its trigger. A long menu on a phone is squeezed beside its trigger instead of keeping its labels readable. An app with a floating navigation bar has no way to tell Astryx layers the bar is there. Four components each carry their own copy of the viewport gutter, and the copies have drifted.

Problem and solution fit

  • The layer runtime now owns the viewport inset (spec:AST-059 DEC-1): one gutter definition in Layer/layerViewportInset.stylex.ts, read by useLayer for every anchor-mode layer — the block cap on the layer box and the far-edge gutter of the alignment axis — and by Popover, DropdownMenu, DropdownMenuSubMenu, BaseTypeahead and PowerSearch for the sizes they clamp.
  • The span cap calc(100% - gutter) is gone everywhere. An explicit width / menuWidth renders at its size up to the viewport (FR2); a content-sized layer wraps to the room beside its trigger when it can and flips when it cannot (DEC-2). No branch on whether a size was given.
  • The fallback order is the runtime's (FR4). While the anchor is in view, a layer that fits on neither side is slid into the viewport by position-area's own overflow alignment. Once the anchor has left the viewport — observed with an IntersectionObserver while open — the layer's self-alignment is pinned unsafe toward the anchor so it holds its position and size instead of sliding to the edge (FR5, owner ruling 2026-10-03).
  • An app declares a floating bar once as inset on LayerProvider (blockStart, blockEnd, inlineStart, inlineEnd; zero by default) (FR6). The provider publishes it through context; useLayer writes it inline on the layer as --astryx-layer-inset-* and the toast viewport writes the same on itself, so one bar is declared once for both (DEC-5) and a corrective portal cannot lose it. toast.inset stays as the toast-only per-edge override and still wins (inline style). A nested provider that declares an inset narrows it for the layers in its subtree (Storybook mounts the root provider, so stories need this; an app hosted inside another provider does too). App configuration, not a theme value; no layer theme target (DEC-4). INV10 stays true: nothing resolves placement through the provider.
  • The gutter bounds position as well as size (FR1/FR6): on the placement axis it is a margin on the far edge beside the anchor clearance on the near edge, so a layer that would end under the bar does not fit and flips. A flip tactic swaps the two, so the block value is the larger of the two block gutters (recorded consequence: a bottom bar keeps layers the same distance from the top).
  • The slide is its own position option (FR4). A layer wider than the room on both sides of its trigger overflows every flipped option on the alignment axis, so Chromium keeps the base option and never reaches the block flip — Cindy's "wide layer near the bottom" finding. Each fallback list now ends with two named @position-try options (whole-axis span, same side then opposite) carrying the gutter on both alignment-axis edges and the landing side's clearance/gutter pair; no uniform margin/inset set can do that (an aligned edge on the trigger and a slid layer 16px from the viewport edge are contradictory with shared declarations). The 24 static rules are installed once per document head before first paint — stylex.positionTry() emits malformed CSS in the pinned release; inside the layer the text would be read as its accessible name (the InputClearButton tooltip test caught it); beside it, it changed parents' last child (ButtonGroup).
  • FR8 (first frame is the settled frame): no geometry input is measured after paint; anchor visibility is read synchronously before first paint and only observed afterwards (guarded so an unchanged answer commits nothing — the Tokenizer commit-count test caught the first version).

Current specification

spec:AST-059 (#6916, draft). This PR applies the deltas it lists to architecture:layer-runtime (viewport-inset section, INV3, new INV11, owning code, verification) and component:Popover (FR3 and ORD3 retired, ORD2 clamps rather than caps, ownership boundary, verification map). Both are current, so this PR waits on spec-owner-approval at its exact head.

Public delta and caller burden

  • New: LayerProvider.inset (LayerInset, exported). Unset → released geometry, with or without a provider (the default-provider and no-provider cases render identically, asserted in LayerProvider.test.tsx). The custom properties it emits are mechanism, not API.
  • ToastViewport positions itself at var(--astryx-layer-inset-*, 0px) instead of 0; an existing toast.inset is unchanged in effect.
  • No prop, type, or default changes. Popover.width strings that are lengths are now clamped to the viewport (previously "used as-is" under the span cap).
  • Behavior change for every useLayer anchor-mode and usePopover consumer (FR7): Tooltip, HoverCard, ContextMenu, the selector family, TopNav menus, date inputs gain the gutter, the block cap, and the flip/hold behavior. A layer that already fit is unchanged.

Design and alternatives

  • The layer box carries no inline cap of its own: an auto-width positioned box shrinks to its position-area region on its own, and a cap on the box keeps Chromium from choosing flip-inline (the submenu already records this). Consumers cap their painted surface with the runtime's expression instead.
  • Rejected: span-all fallbacks passed from Popover (fix(popover): an explicit width is capped by the viewport, not the span beside the trigger #6688) — crosses the ownership boundary and extends sliding to an anchor nobody can see.
  • Rejected: a shared constant imported by each component while each keeps its own fit styles.

Evidence

  • Sixteen Core/Layer "Viewport inset" stories, one per claim, each asserting the first painted frame equals the settled one, run by the story play guard at 1280×900 and 390×844 (28 runs): content fits beside the trigger; content does not fit (flips where it fits the viewport, capped where it does not); explicit 352px near an edge; trigger near an edge flips (slides on a phone); neither side fits (1000px slides on desktop, capped to 358px on a phone); taller than the viewport; anchor leaves the viewport; anchor already off-screen at open; app-declared inset (160px bar); inset changes while open; layer opens as the inset arrives; inset measured by the app; layer portaled out of its JSX position; the gutter at a flush edge; trigger near the bottom flips above; wide layer, trigger near the bottom (690px — Cindy's phone case). Plus a draggable playground (not evidence).
  • Recorded gap VG1: at phone width a layer that had to slide and whose anchor leaves and returns can come back off-screen until its next layout; asserted only where the layer fit.
  • LayerProvider.test.tsx: default provider emits no declaration; one property per declared edge; the anchored layer and the toast viewport both sit under the declaring wrapper; toast.inset overrides per edge.
  • layerViewportInset.test.ts scans packages/core/src for a second gutter definition or a 100%-of-span cap; useLayer.test.tsx covers the per-placement gutter classes and the anchor-observer gate; Popover, DropdownMenu, SubMenu, PowerSearch suites assert the clamp strings.
  • Not reproducible in CI: env(safe-area-inset-*) — a device run is owed (record, verification table).
  • Popover's ViewportFit story is replaced by the Layer stories; MatchTriggerViewportFit stays (trigger matching is Popover's preference). Expect the visual-regression report to show that removal.

Writing rubric results

Records touched: docs/architecture/layer-runtime.md, packages/core/src/Popover/Popover.spec.md (both current), and spec:AST-059 (phase only; its own pass is on #6916).

R1 narration: layer-runtime's new viewport-inset section and INV10/INV11 state behavior in the present tense; Popover's FR3 and ORD3 are marked "Retired" with the owning claim named rather than narrating the move. The Popover intent paragraph lists this change's date beside the two it already listed — kept, since that sentence is the record's own convention for what it describes.
R2 research: none added.
R3 evidence: new verification cells name tests, stories, and the story play guard, not pull requests.
R4 rejected alternatives: none added to either current record.
R5 change references: none added. One pre-existing "PR #5373" cell in Popover's verification map shows in the diff only because Prettier re-wrapped the table; its text is unchanged and predates the rule.
R6 open questions: none added; Popover's section still reads "None".

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

npx vitest run packages/core/src — 10,896 passed; 10 failures are the known perf-budget / 30s-timeout set (Table perf, DateTimeInput touch, SideNav, TabList, Resizable, MultiSelector a11y) and pass in isolation
pnpm check:knowledge — Knowledge templates and records are aligned.
node scripts/check-changesets.mjs — 33 changeset(s) valid
tsc --noEmit (core, storybook) — clean · eslint on touched files — no new findings · Prettier — clean
Rendered geometry at head cac226c: pr-a11y story play guard — all 32 runs (16 stories × desktop and phone) passed in Chromium, first-frame-equals-settled included; full CI green. The a11y audit's 2 color-contrast nodes are PowerSearch's pre-existing disabled-token text, audited here because PowerSearch.tsx was touched. Preview: https://astryx-git-layer-viewport-inset-runtime-fbopensource.vercel.app/storybook/

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 3, 2026
@vercel

vercel Bot commented Oct 3, 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 Oct 4, 2026 12:56pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🔄 In progress (for maintainers only) Oct 6, 2026, 2:26 PM UTC

@cixzhang
cixzhang changed the base branch from spec-layer-viewport-inset to main October 3, 2026 19:23
@cixzhang cixzhang closed this Oct 3, 2026
@cixzhang cixzhang reopened this Oct 3, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Oct 3, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: Storybook and Sandbox are not both ready on the exact-head Vercel preview.

Modified Components

Popover (@astryxdesign/core)
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 678 -
Complexity N/A Very High (77) -
PowerSearch (@astryxdesign/core)
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 3856 -
Complexity N/A Very High (335) -
Toast (@astryxdesign/core)
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1303 -
Complexity N/A Very High (129) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

PowerSearch - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/28 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Visual Regression

15 of 420 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Chat Full AI Chat probe light 155,733
Chat Full AI Chat probe dark 155,005
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,229
Chat With Attachments probe dark 11,065
SideNav Resizable in AppShell probe dark 3,208
Markdown Default probe dark 897
Markdown Default probe light 897
Markdown Default neutral dark 882
Markdown Default neutral light 858

Generated by PR Enrichment workflow | View full report

One gutter definition in Layer/layerViewportInset.stylex.ts, read by
useLayer for every anchor-mode layer (block cap, far-edge gutter) and by
Popover, DropdownMenu, DropdownMenuSubMenu, BaseTypeahead and PowerSearch
for their own clamped sizes. The span cap (calc(100% - gutter)) is gone:
an explicit width renders at its size up to the viewport. An aligned
layer whose anchor leaves the viewport is pinned unsafe toward its anchor
so it holds position and size instead of sliding to the edge.
…pover records for spec:AST-059

Nine Core/Layer stories, one per claim, registered in the story play guard
for real-Chromium geometry. Popover's ViewportFit story is replaced by
them. The architecture record gains the viewport-inset section and INV11;
the Popover record gives up FR3 and ORD3 and keeps its preferred size.
…ers and toasts

The provider carries the inset as custom properties on a box-less wrapper;
anchored layers read them through the gutter and the toast viewport sits at
them, so one declaration clears one bar for both. Zero by default, so a
surface with no provider renders as one under a default provider;
toast.inset stays as the per-edge toast override (spec:AST-059 FR6, DEC-5).
…text; the first frame is the settled frame

The layer box is capped to the viewport on the inline axis too, so a
1000px layer on a phone stays on screen and its content overflows inside
(FR2). LayerProvider publishes the inset through context and useLayer
writes it inline on the layer, so a corrective portal cannot lose it and
no measurement applies it. Anchor visibility is read synchronously before
first paint (FR8). Fourteen Core/Layer stories, each asserting the first
painted frame equals the settled one, run at 1280x900 and 390x844; a
draggable playground story for exploration.
… the playground readout settles

The synchronous anchor-visibility read set state on every open even when
the answer was already true, costing Tokenizer's search one extra commit.
The playground's readout re-rendered itself on every commit.
…s hold at phone width

The placement-axis gutter and a declared bar were only a size cap: a layer
that fit below its trigger could end under the bar. The gutter is now an
inset on the far edge of the position-area region, carried by named
@position-try options for the placement-axis flip (a flip tactic would
mirror it onto the wrong edge), with a span-all last resort for content no
side can hold. Story fixtures place the trigger above the bar; the flip and
return assertions account for a phone where neither side fits.
…ition-try rules

The build pipeline mangles @position-try output (the sandbox build failed
on the CSS), so the placement-axis positional gutter is a flip-mirrored
inset carrying the larger of the two block gutters, and the span last
resort is withdrawn. Records state the consequence.
… anchor clearance

Insets did not bound position in Chromium; margins do — the margin box is
what a position option must fit and what the overflow shift keeps inside
the viewport. The clearance rides the anchor-facing edge and the gutter the
far edge; a flip tactic swaps them with the area. Failure messages now
carry the layer's computed geometry.
… for its subtree

Storybook mounts the root provider, so a story's provider is nested; a
nested provider was a no-op and no inset reached the stories' layers. One
declaring an inset now provides it to the anchored layers in its subtree;
the toast viewport stays the root's. The slide-then-return case at phone
width is recorded as a verification gap rather than asserted.
…it above the bar

A layer with no offset carries only the far-edge gutter (a static class),
so a consumer's flush overlay sees no clearance variable, as before. The
Selector and ComplexSelector clearance tests describe the new shape: the
clearance rides the anchor-facing edge and a flip carries it across. The
portaled story's provider now wraps the component that calls useLayer.
…ill flips on the placement axis

A layer wider than the room beside its trigger on both sides overflowed
every flipped option on the alignment axis, so Chromium kept the base
option and the layer never flipped above a trigger near the bottom. Each
fallback list now ends with span-all options, same side first; the
alignment-axis gutter rides both edges as margins with a negative inset on
the anchor-facing edge so the aligned edge still meets the trigger and a
slid layer keeps both gutters. Two block-axis stories join the guard.
…ication rows

The one delta to the merged record from the block-flip fix: FR4 states the
slide as a position option a layer wider than both sides still reaches,
and the verification table gains the two block-axis stories.
…d once per document

A plain position-area fallback keeps the base margins, which belong to an
edge-aligned layer; and uniform margins and insets cannot place a slid
layer 16px from the viewport edge while keeping an aligned layer's edge on
its trigger. Each slide option therefore carries its own declarations —
the gutter on both alignment-axis edges and the clearance/gutter pair of
the side it lands on — as a static style sheet the runtime installs in the
document head before first paint (StyleX positionTry() output is malformed
in the pinned release). The sheet is not inside the layer, whose text
would name it to assistive technology, and not beside it, where it would
change a parent's last child.
@cixzhang

cixzhang commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec cac226c

@cixzhang
cixzhang marked this pull request as ready for review October 6, 2026 14:25
@cixzhang
cixzhang enabled auto-merge (squash) October 6, 2026 14:25
@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 6, 2026
@cixzhang
cixzhang merged commit d45599c into main Oct 6, 2026
47 checks passed
@github-actions
github-actions Bot deleted the layer-viewport-inset-runtime branch October 7, 2026 06:24

This branch was successfully deployed

1 active deployment
Preview — cac226c9 Deployed Oct 4, 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant