Skip to content

fix(popover): an explicit width is capped by the viewport, not the span beside the trigger - #6688

Closed
vjeux wants to merge 4 commits into
meta:mainfrom
vjeux:popover-width-overhang
Closed

vjeux wants to merge 4 commits into
meta:mainfrom
vjeux:popover-width-overhang

Conversation

@vjeux

@vjeux vjeux commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A start- or end-aligned Popover with an explicit width on a trigger near its panel edge renders narrower than asked: an end-aligned 352px popover on a 40px trigger 45px from a panel edge renders 274px in Chromium. A design width is unreachable near any edge.

Problem and solution fit

  • Why it occurs: an aligned layer's max-inline-size: calc(100% - gutter) resolves, under anchor positioning, against the anchor's inset-modified containing block — the span beside the trigger — not the viewport.
  • Why it harms: width is the component's one sizing knob, overridden by trigger position.
  • Why it matters: the contract caps an explicit width by viewport and safe-area availability; the span cap breaks that near every panel edge.

The fix caps an explicit width to the viewport minus both inline gutters. Dropping the span cap exposes one case the old cap masked by shrinking: when neither side of the trigger fits the width (a phone), the layer would clip. Popover therefore appends span-all fallbacks after the runtime's flips, so the browser centers the layer on the trigger and shifts it into view — only when the width fits nowhere else.

Expected behavior and authority

component:Popover (Popover.spec.md, authority: current) ORD2: "Either preferred size remains capped by available viewport and safe-area space" — the viewport, not the span beside the trigger. The one unresolved owner decision is the span-all last resort for a width that fits on neither side; this PR records it as FR8 / ORD2a / DEC-4, marked pending owner review.

Smallest restoration

  • Popover with a width and a start/end alignment: max-inline-size becomes calc(100vi − both gutters); the layer may overhang past the trigger's other side.
  • Same case, placed above or below: Popover passes position-try-fallbacks: <runtime flips>, <same> span-all, <opposite> span-all through the render props' style. Side placements stop at the flips.
  • Unchanged: popovers without a width, centered popovers, useLayer — no public API, type or default changes.

Evidence

  • Reproduction before the change: the new Core/Popover → Width Overhang story on the base commit, run by the story play guard in Chromium — Explicit width was not honoured: layer is 274px wide, end span 290px, viewport 1280px.
  • Result after the change: same story, same guard — play passed: 352px wide, on-screen, overhanging the trigger.
  • Representative unchanged path: a no-width end-aligned popover keeps the span cap and flip-only fallbacks; a centered width keeps the centered clamp.
  • Regression test or other mutation-sensitive proof: the Popover unit suite asserts --x-width, the clamp class and the exact fallback list per alignment; the story is registered in the story play guard, so a regression fails pr-a11y.

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

npx vitest run packages/core/src/Popover packages/core/src/Layer packages/core/src/docPropLiterals.test.ts scripts/check-knowledge.test.mjs
  Test Files 10 passed · Tests 320 passed
pnpm lint — 0 errors (82 pre-existing warnings, none in Popover/)
pnpm -F @astryxdesign/core build — 629 dist files checked, exit 0
pnpm storybook:build && node .github/scripts/story-play-guard.js --storybook-dir apps/storybook/dist
  ✓ Popover (core-popover--width-overhang): play passed — 352px, on-screen, overhanging the trigger (exit 0)
pnpm test -- --maxWorkers=4 (previous head) — 913 files / 19568 tests passed

…an beside the trigger — the layer may overhang past the trigger
@vercel

vercel Bot commented Sep 28, 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 1, 2026 2:42am UTC

Request Review

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

astracat-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 3, 2026, 9:41 PM UTC

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

Thanks for fixing this — a caller who asks for a 352px menu should not silently get 259px just because the trigger sits near a panel edge, and honouring the explicit width up to the viewport (minus the safe-area gutters) matches the documented Popover sizing contract.

Approval is on hold for a maintainer spec decision. Two parts of the change add new public behaviour that no current spec settles: aligned (start/end) layers gaining span-all slide fallbacks that centre on the trigger when neither side fits — the current layer-runtime contract describes span fallbacks only for centred placements — and the new public useLayer render option hasSlideFallback. A maintainer needs to provide or identify the governing spec for those additions, or update the owning spec to settle them, before this can be approved.

Two follow-ups are also recorded in the review, independent of that decision:

  • For side placements (placement="start" / "end"), the appended fallbacks span the block axis, so they cannot rescue the inline width overflow that turns the fallback on — a side-placed Popover whose width fits on neither side would still clip instead of centring as the width documentation promises. An inline-axis fallback (or scoping the promise to above/below) plus a Popover-level side-placement width test would close this.
  • The sizing evidence is jsdom-level (emitted width, classes, fallback strings). Real-browser before/after evidence for the rendered geometry — for example the existing Viewport Fit story and a panel-edge 352px case, including the neither-side-fits state — is still needed.

Popovers without a width and centred Popovers are unchanged, which keeps the blast radius of the core fix small.

[Automated review]

github-actions Bot added a commit that referenced this pull request Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

Popover (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 779 -
Complexity N/A Very High (90) -

Bundle Size Summary

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

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

1 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
SideNav Resizable in AppShell probe light 3,208

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

…ding owner review records the explicit-width cap and overhang rule
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Sep 28, 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.

Thanks for fixing this — a caller who asks for a 352px menu should not silently get a much narrower one just because the trigger sits near a panel edge, and honouring the explicit width up to the viewport (minus the safe-area gutters) matches the documented Popover sizing contract. The new real-browser story is a welcome addition: it proves the 352px case renders at full width and stays on-screen.

Approval is on hold for a maintainer spec decision. Two parts of the change add new public behaviour that no current spec settles: aligned popovers placed above or below gaining span-all slide fallbacks that centre on the trigger when neither side fits, and the new public useLayer render option hasSlideFallback. The PR proposes both in a new decision marked pending owner review. A maintainer needs to provide or identify the governing spec for those additions — approving that proposed decision, or pointing to an existing spec that already covers them — before this can be approved.

Two smaller notes are recorded in the review, independent of that decision:

  • Rendered evidence for the neither-side-fits state is still missing: the new story's layer fits after flipping, so the span-all centering path is only proven by the emitted fallback strings, and there is no WebKit result yet.
  • The changeset says the layer "centers on the trigger" when neither side fits, without scoping that to above/below placements; a side-placed popover flips only, so that sentence should be scoped to match.

Popovers without a width, centred popovers, and side placements' fallback behaviour are otherwise unchanged, which keeps the core fix's blast radius small.

[Automated review]

…eps its released API; no internal identifiers
@vjeux vjeux changed the title fix(popover): an explicit width clamps to the viewport, not to the span beside the trigger — the layer may overhang past the trigger fix(popover): an explicit width is capped by the viewport, not the span beside the trigger Oct 1, 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.

Thanks for fixing this — a caller who asks for a 352px menu should not silently get a much narrower one just because the trigger sits near a panel edge, and honouring the explicit width up to the viewport (minus the safe-area gutters) matches the documented Popover sizing contract. The new real-browser story proves the 352px case renders at full width and stays on-screen.

Approval is on hold for a maintainer spec decision. One part of the change adds new behaviour that no current spec settles: aligned popovers placed above or below gaining span-all slide fallbacks that centre on the trigger when neither side fits. The PR proposes this in a new decision marked pending owner review. A maintainer needs to approve that proposed decision, or point to an existing spec that already covers it, before this can be approved.

One smaller note is recorded in the review, independent of that decision: rendered evidence for the neither-side-fits state is still missing — the new story's layer fits after flipping, so the span-all centring path is only proven by the emitted fallback strings — and there is no WebKit result yet.

Popovers without a width, centred popovers, and side placements are otherwise unchanged, which keeps the core fix's blast radius small.

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

The width fix is right and the owner has confirmed it in the preview: an explicit width honoured up to the viewport rather than the span beside the trigger is what component:Popover ORD2 already promises, and the overhang reads correctly. One behavior found by testing needs resolving before this lands.

Shrink the viewport until the trigger leaves it, and the layer repositions toward the viewport edge, leaving itself less room than it had. The owner's words: "when the viewport shrinks so the target is outside of the viewport it repositions the menu towards the edge, leaving less room."

That is the slide behavior doing the wrong thing in a state nobody designed for. The span-all fallbacks keep a layer on screen while its anchor is still on screen, which is their job — but once the anchor has left the viewport entirely, sliding toward the anchor's edge pins the layer into the narrowest strip available, so a surface that had room a moment earlier is now cramped against the edge. The width fix did not cause it; it made it visible, because a layer that previously shrank to the span now has a real width to defend.

Worth settling what should happen when the anchor is no longer in view at all, since the answer is not "slide further":

  • Hold the last in-view position and let the layer stay where it is until the anchor returns. The layer keeps its size; nothing reflows under the person reading it.
  • Close the layer. A popover anchored to something the person can no longer see is arguably stale, and several systems dismiss on exactly this condition.
  • Clamp the slide so the layer never gives up inline size to chase an anchor it cannot reach.

The first is the smallest and the least surprising; the second is a product decision rather than a geometry one. Whichever is taken, the spec's ordering rules should say it, because right now the behavior is emergent from the fallback list rather than stated anywhere.

Two things already noted that still stand:

  • The span-all centering path has no rendered evidence. The Width Overhang story's layer fits after flipping, so the centring is proven only by the emitted fallback strings — and that is the exact state the pending decision is about. A story with a trigger where neither side fits the width would close it.
  • No WebKit result yet.

Everything else holds: popovers without a width, centred popovers, and side placements are unchanged, which keeps the blast radius small.

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

Correcting my own framing above, having read what ships today.

I described the off-screen-anchor behavior as the slide misbehaving in a state nobody designed for. That is not accurate. On main an aligned layer has no span fallbacks at all — getPositionTryFallbacks returns flip-block, flip-inline, flip-block flip-inline for every non-centered alignment and stops there. Span sliding exists only for centered layers, and the comment says why: a flip maps center to center, so overflow on the alignment axis would clip a centered layer, while flips already resolve an aligned one.

So this change introduces span sliding to aligned layers for the first time, and the behavior the owner found is the first place it shows. Before this change an end-aligned popover with an off-screen anchor did not slide — it shrank, through the span cap this PR is removing.

That makes the question narrower than I put it. The two candidate behaviors are no longer three:

  • Do not slide an aligned layer toward an anchor that has left the viewport. This restores what ships today for that state, so it is a restoration rather than a new design, and it keeps the width fix's blast radius where the PR says it is.
  • Keep the slide and accept the cramped result, on the grounds that an on-screen layer beats an off-screen one. That is a real position, but it needs stating in the ordering rules rather than emerging from a fallback list, because it is new behavior for aligned layers.

I would take the first. The span-all fallbacks are there to serve the neither-side-fits case while the anchor is visible — which is the pending decision — and extending them to an anchor nobody can see is a second, separable change that this PR does not argue for.

The evidence gaps I named still stand: the centring path has no rendered proof, and there is no WebKit result.

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

Owner ruling, cixzhang, 2026-10-03: an aligned layer does not slide toward an anchor that has left the viewport.

The width fix is approved and stands as built: an explicit width is honoured up to the viewport minus its gutters, never shrunk to the span of viewport beside the trigger. That is what component:Popover ORD2 already promises, and the preview shows the 352px case rendering at full width.

The span-all fallbacks stay for the case they were added to serve — neither side of a visible trigger fitting the width, where the layer centres on the trigger and slides into view. That proposed decision is approved too.

What comes out is the slide continuing once the anchor is no longer on screen. Today an aligned layer has flips only, so this state has no slide at all and the layer keeps its size; with the slide extended to aligned layers it chases the anchor to the viewport edge and pins itself into the narrowest strip available, giving up room it had a moment earlier. Restoring today's behavior there keeps this change's blast radius exactly where its summary says it is, and the owner's words are: "don't slide an aligned layer toward an off-screen anchor."

Three things to carry:

  • Gate the slide on the anchor being in view. An aligned layer whose anchor has left the viewport holds its position and its size.
  • State it in the ordering rules. Right now the behavior is emergent from the fallback list; the condition under which an aligned layer slides belongs in the record beside the rest of the sizing order, so the next person reading it does not have to derive it.
  • Rendered evidence for the centring path. It is still proven only by emitted fallback strings — the Width Overhang story's layer fits after flipping, so the one state the decision is about is the one nobody has seen. A story with a trigger where neither side fits the width closes it. A WebKit result is still outstanding too.

Nothing else in the change needs revisiting: popovers without a width, centred popovers, and side placements are unchanged.

cixzhang added a commit that referenced this pull request Oct 3, 2026
Gutter, size cap, fallback order, app-declared inset, and the Layer stories
move to the layer runtime; Popover keeps its props, styling, scrolling and
the explicit-width preference. Supersedes the component-level approach in
#6688 and places #6686's inset at the layer.
cixzhang added a commit that referenced this pull request Oct 4, 2026
* spec(AST-059): the layer runtime owns the viewport inset

Gutter, size cap, fallback order, app-declared inset, and the Layer stories
move to the layer runtime; Popover keeps its props, styling, scrolling and
the explicit-width preference. Supersedes the component-level approach in
#6688 and places #6686's inset at the layer.

* spec(AST-059): state the system, not the project

Rubric pass (docs/contributing/spec-writing.md): the Intent names the
behaviors rather than the changes that reached for them; no pull request
remains as standing content; the open-pull-request and follow-up sections
are gone (their durable facts are in the FRs; the rest is for the pull
request description); rejected alternatives are one line each.

* spec(AST-059): the app declares its floating bar on LayerProvider

FR6 and DEC-4 rewrite on the owner's ruling: LayerProvider carries the
inset, typed beside toast, with zero defaults; anchored layers and the
toast viewport read one declaration (DEC-5). toast.inset stays as the
per-edge toast override. Custom properties are the mechanism, not the API.

* spec(AST-059): the first frame is the settled frame; the layer box never exceeds the viewport

FR8: a layer MUST NOT paint at a geometry it is about to correct; every
geometry input resolves in the same frame as the render that produced it
and the runtime measures nothing after paint. FR2/FR3: the layer box never
exceeds the cap; content that cannot fit overflows inside. Verification
rows name both viewports and the first-frame comparison.

* spec(AST-059): current — approved by the owner on 2026-10-03

/approve-spec clears the merge gate; the record's own authority is written
here: authority current, approved_by cixzhang, phase accepted, DEC-2 and
DEC-5 as the owner's decisions.

* spec(AST-059): the gutter bounds position on the placement axis; a span last resort

* spec(AST-059): the placement-axis positional gutter is one value for both edges

* spec(AST-059): nested provider narrows the inset; VG1 slide-then-return
cixzhang added a commit that referenced this pull request Oct 6, 2026
#7011)

Every Viewport inset story places its layer below its trigger, so the
side placements had no coverage at either viewport. A side placement is
the case where the slide cannot help: the alignment axis is the block
axis, so sliding moves the layer up or down and does nothing about an
inline overflow. Only the flip and the cap can keep it on screen.

Two stories, both running at 1280x900 and 390x844 like the rest:
a 320px layer placed to the inline end of a trigger 24px from that edge,
which must flip rather than shrink; and a 900px layer placed to the start
of a centred trigger, where neither side fits and on a phone the viewport
does not either, so the cap is what saves it.

Ported from #6688, which found these cases while fixing the explicit-width
defect at the component. Its other three cases are already covered by the
landed viewport stories, and its assertions read internal class names and
position-try strings from an implementation the layer runtime has since
replaced — these assert the rendered geometry instead.
@cixzhang

cixzhang commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Closing: superseded in substance, with its coverage preserved.

The defect this found is real and is fixed — an explicit width capped by the span of viewport beside the trigger rather than by the viewport itself. spec:AST-059 moved that fix to the layer runtime, where it belongs: one gutter definition instead of six copies, one size cap, one fallback order, and every component that renders through useLayer or usePopover inherits it. The 352px end-aligned case that started this is a Layer story now, asserted in real Chromium at 1280×900 and 390×844.

Its two cases that the layer stories did not reach — a side placement with a width, and a side placement where neither side fits — were ported in #7011 and landed as 3811094. They assert rendered geometry rather than class names and position-try strings, since the implementation those read has been replaced.

Also worth recording: your observation that a slide cannot rescue a side placement, because the alignment axis is the block axis there, is exactly what those two stories pin.

Nothing here is lost. Thank you for the find.

@cixzhang cixzhang closed this Oct 6, 2026
@vjeux
vjeux deleted the popover-width-overhang branch October 6, 2026 15:55

This branch was successfully deployed

1 active deployment
Preview — 9c288dda Deployed Oct 1, 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:spec-owner-review Current knowledge records await owner approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants