Skip to content

fix(Layout): scope a Layout's padding to its own regions - #6810

Merged
cixzhang merged 1 commit into
mainfrom
fix/layout-nested-padding
Oct 7, 2026
Merged

cixzhang merged 1 commit into
mainfrom
fix/layout-nested-padding

Conversation

@thedjpetersen

@thedjpetersen thedjpetersen commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

A Layout placed inside AppShell content, or inside another Layout, inherits the outer Layout's padding. AppShell's own Layout is full bleed, so page titles, body text, and side panels render flush against the screen edge. With this PR a Layout's padding applies only to its own regions, so nested Layouts keep their default 16px inset with no extra props.

Side-by-side 390px phone screenshots of an Orders page inside AppShell: before, the "Orders" title and body text touch the screen edge; after, every region has a 16px inset.

At a glance

  • Page Layout inside AppShell: title, body, and panel inset 0px → 16px at 390px, 1440px, and in RTL; no horizontal overflow
  • Unchanged: Layouts inside a padded Card (8px), a theme-default Card (12px), or a Section (24px) are pixel-identical to main, and so is any Layout with explicit padding
  • Tests: 7 new regression tests. 3 fail on main (AppShell and nested Layout cases), and 3 fail on the simpler reset-everything fix (Card and Section cases)
  • No new API. Internal padding variables are scoped; one compatibility call for an owner: a padding-less Layout nested in a non-zero-padding Layout now uses the default instead of inheriting (undocumented behavior, no in-repo caller)
  • Preview story: Core/Layout → "Nested Layout — Inset in AppShell" (390px and 960px frames)
Second view: Layouts inside a Card with padding 2, a theme-default Card, and a Section with padding…

Side-by-side screenshots of Layouts inside a Card with padding 2, a theme-default Card, and a Section with padding 6, identical before and after.

Every screenshot, measurement file and repro script for this PR: astryx-pr-evidence/layout-nested-padding


User impact

Anyone who puts a page Layout inside AppShell content, or nests one Layout inside another. That is common: in a blind agent-built UI benchmark (three AI coding models, 24 real product screens, ~440 Astryx builds), nested Layouts appeared in 28.5% of builds, and the same defect showed up 12 times across 6 real apps built on Astryx.

What fails: the nested Layout's LayoutHeader, LayoutContent, LayoutPanel, and LayoutFooter lose their default 16px inset. The page title and body text sit at 0px from the content edge, and an end panel's outer and bottom edges lose their padding, at 1440 and at 390 alike. AppShell contentPadding cannot fix it (it pads the LayoutContent around the page Layout, which the page Layout's outer wrapper escapes by design).

What the fix enables: the page Layout renders with its documented default inset with no extra props. Layouts inside a padded Card, Section, or Dialog keep that container's inset, exactly as today.

Problem and solution fit

  1. Why does it occur? AppShell composes an internal Layout with padding={0}. Layout published its padding through the inherited custom properties --layout-padding-outer-x/y, which every Layout region reads. Custom properties inherit through the DOM, so a Layout rendered anywhere inside AppShell's content inherits 0px for its own regions.
  2. Why does it harm the task? The page Layout's header title, content text, and panel outer edges render flush against the content surface (0px instead of 16px). The page looks unfinished at every width, and on a phone glyphs touch the screen edge.
  3. Why does that matter? Nesting a page Layout in AppShell is the composition our own docs point to (AppShell owns the shell, Layout arranges a page's regions), and agents produce it in more than a quarter of builds. Every one of those pages needs a hand-written workaround or ships flush text.

Fit: a Layout's padding now applies only to that Layout's own regions. It writes --layout-padding-own-outer-x/y, which the regions read ahead of the inherited --layout-padding-outer-x/y. Every Layout, every padding container (container(): Card, Section, Dialog), and every overlay root clears the own value, so it cannot reach a nested Layout's regions. The container-published --layout-padding-outer-x/y is left alone, so a Layout inside a padded container still takes that container's inset.

Re-derived from the original source commit

The source commit for this fix reset --layout-padding-outer-x/y to initial on every Layout. That fixes the AppShell case but also discards the value Card, Section, and Dialog publish for the Layouts inside them. Measured in a browser (neutral theme), it moved a Layout inside <Card padding={2}> from 8px to 16px, inside a theme-default Card from 12px to 16px, and inside <Section padding={6}> from 24px to 16px (compare-unchanged.png). This PR keeps the container channel and scopes only the Layout-published value. The regression tests below fail on that original commit.

Expected behavior and authority

  • family:layout-regions (current) FR3: "Header, Content, Footer, and Panel apply outer inset where they touch the Layout boundary and inner inset where they meet another region." A nested Layout has its own boundary; its regions currently apply the outer Layout's padding={0} instead of any inset.
  • architecture:container-padding (current) INV4: "Named Layout regions apply outer inset where they touch the shell." System model, layer 2: container() resolves Card, Section, and Dialog padding into internal logical-edge and Layout inset variables. That second clause is the channel the original commit broke and this PR preserves.
  • architecture:container-padding INV1/INV6: --layout-padding-* is internal protocol, not theme API, and overlay roots invalidate it. The new --layout-padding-own-outer-x/y sits inside that name family, is cleared by overlayPaddingReset, and is registered as a structural var in derivedVarRegistry.test.ts.
  • Layout prop doc: padding is "Padding at the layout's outer edges". The component doc and JSDoc now say this padding applies to that Layout's own regions and is not inherited by a nested Layout.
  • component:Layout spec is draft and not authoritative. It already records the same scoping choice for contentWidth ("Reset inherited width so nested Layouts without contentWidth keep their released padding", Layout.tsx). This PR applies that precedent to padding.

Smallest restoration

  • Layout.tsx: Layout's inner wrapper clears --layout-padding-own-outer-x/y (next to the existing contentWidth reset). padding and padding={0} now write the own variables.
  • LayoutHeader/Content/Footer/Panel.tsx: each var(--layout-padding-outer-*, spacing-4) read becomes var(--layout-padding-own-outer-*, var(--layout-padding-outer-*, spacing-4)). The change is mechanical: same fallback, same edges, same republished --container-padding-* pairing.
  • padding.stylex.ts: Layout's padding maps write the own variables, and overlayPaddingReset clears them.
  • container.stylex.ts: the shared container base clears the own variables, so a padded Card/Section/Dialog inside a padded Layout re-establishes its own inset for Layouts inside it.
  • No new prop, export, target, token, visual representation, or default. The region inset values are the existing ones.

Supporting only: a regression test file, two test-list registrations, one Layout.doc.mjs example plus the padding prop description, one Storybook story, one changeset.

Representative callsite

// Before and after: the same code. Only the rendered inset changes.
<AppShell sideNav={<SideNav>{/* … */}</SideNav>}>
  <Layout
    header={
      <LayoutHeader hasDivider>
        <Heading level={1}>Orders</Heading>
      </LayoutHeader>
    }
    end={
      <LayoutPanel hasDivider width={320} role="complementary" label="Order details">
        {/* … */}
      </LayoutPanel>
    }
    content={<LayoutContent>{/* … */}</LayoutContent>}
  />
</AppShell>
// before: "Orders" and the body text at 0px from the content edge; panel outer/bottom padding 0px
// after:  16px (the default region inset) on every region edge
// The workaround people wrote on main, now unnecessary (and still honored):
<Layout padding={4} header={/* … */} content={/* … */} />

Evidence

  • Reproduction before the change: origin/main build, AppShell page with a nested Layout (header, 320px end panel, content). The header title and content text sit at 0px inline and 0px block from their region edge. The panel's padding is 16px 0px 0px 16px (outer inline-end and block-end edges are 0). Same at 1440, 390, and 1440 RTL.
  • Result after the change: 16px on every region edge at 1440, 390, and 1440 RTL. The panel's padding is 16px. No horizontal overflow (document width = viewport).
  • Representative unchanged paths (identical on main and after): Layout in Card padding={2} → 8px; Layout in a theme-default Card → 12px (neutral theme card padding); Layout in Section padding={6} → 24px; a single Layout padding={2} → 8px. The original source commit changed all three container cases to 16px.
  • Regression test (mutation-sensitive): packages/core/src/Layout/__tests__/nestedPadding.test.tsx resolves each region's inline inset through the injected StyleX rules, walking custom-property inheritance the way the browser does (jsdom does neither).
    • On origin/main: 3 failed / 4 passed (AppShell > Layout, full-bleed Layout > Layout, padding={8} Layout > Layout).
    • On the original source commit: 3 failed / 4 passed (Card, Section, and Card-inside-full-bleed-Layout: all resolve to the default instead of the container's inset).
    • After: 7 passed.

Measurements (real browser, Chromium, neutral theme)

Case Viewport main (before) original commit this PR (after)
AppShell > Layout: header title inline inset 1440 / 390 / 1440 RTL 0 / 0 / 0 px 16 / 16 / 16 16 / 16 / 16
AppShell > Layout: header title block inset 1440 / 390 0 / 0 px 16 / 16 16 / 16
AppShell > Layout: content text inline inset 1440 / 390 / 1440 RTL 0 / 0 / 0 px 16 / 16 / 16 16 / 16 / 16
AppShell > Layout: end panel padding 1440 / 390 16px 0 0 16px 16px 16px
Document width (overflow check) 1440 / 390 1440 / 390 1440 / 390 1440 / 390
Card padding=2 > Layout: header/content inset 480 8 px 16 (regressed) 8
Card (theme default) > Layout 480 12 px 16 (regressed) 12
Section padding=6 > Layout 480 24 px 16 (regressed) 24
Layout padding=2 (single) 480 8 px 8 8

Raw numbers: measurements.json.

Images

Preview story

Core/Layout → "Nested Layout — Inset in AppShell" (NestedInAppShell) shows the page Layout in AppShell inside a 390px frame, plus the unchanged Card padding={2} case; "Nested Layout — Inset in AppShell (960px)" (NestedInAppShellWide) shows the same page at 960px. Both live in apps/storybook/stories/Layout.stories.tsx, with one AppShell per story so each document has a single main landmark.

Agent-facing example

astryx component Layout now prints "Page with a details panel inside AppShell": an AppShell page with a nested Layout (header, end details panel, content) and no padding props. The padding prop description now states its scope.

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.

Compatibility, and the one decision I need from an owner

Under spec:AST-017 FR5 I classify this as contract-restoring. Explicit padding on any Layout, a Layout directly inside a Card/Section/Dialog, and a single Layout render exactly as before (measured above).

One released behavior does change, and an owner needs to confirm the classification: a Layout without padding nested inside a Layout with a non-zero padding (for example <Layout padding={2}> → <Layout>) used to inherit that value (8px). It now uses the nearest padding container's inset or the 16px default. The inheritance was never documented; the only statement was the JSDoc line that padding "controls --layout-padding-outer-x", an internal variable (container-padding INV1). If an owner decides a supported consumer relied on it, this becomes an FR32 incompatible-fix, and the migration is to put the same padding on the nested Layout. I found no in-repo caller that relies on it. Among the page templates and docs examples, the only nested Layout under a padded Layout is in canvas-editor, and it sets explicit padding on every region, so it renders the same. AppShell (padding={0}) is the source of the defect.

No record amendment is required. The own variables belong to the --layout-padding-* family that container-padding INV1/INV6 already cover. If owners want the architecture record's "System model, layer 3" sentence to name the Layout-scoped value explicitly, that is a separate documentation edit.

Testing

  • Fail-before/pass-after (patch-out method): pnpm vitest run packages/core/src/Layout/__tests__/nestedPadding.test.tsx against origin/main sources, the original source commit's sources, and this PR (results above; log: fail-before.txt).
  • Focused: pnpm vitest run packages/core/src/Layout packages/core/src/AppShell packages/core/src/Card packages/core/src/Section packages/core/src/Dialog packages/core/src/theme/derivedVarRegistry.test.ts: all pass.
  • Full core suite, bounded, from the repo root: pnpm vitest run packages/core → 10655 passed, 1 failed. The failure is ContextMenu > opens the real menu content in a BottomSheet when requested, which also fails on untouched origin/main in this environment (2 ContextMenu BottomSheet failures there); it does not involve Layout.
  • pnpm -F @astryxdesign/core typecheck and typecheck:docs: clean. apps/storybook pnpm typecheck: clean (after building the workspace theme/charts/vega packages it imports).
  • prettier --check on changed files: clean except Layout.doc.mjs, which is already unformatted on origin/main. eslint: 0 errors.
  • pnpm check:repo passed in the pre-commit hook.
  • Real browser: core built from origin/main, from the original source commit, and from this branch, overlaid into the same Vite + StyleX scaffold with the neutral theme. Playwright/Chromium at 1440×900, 390×844, 1440 RTL, and a 480px unchanged-path page (DPR 2).
  • astryx component Layout --dense: the new example renders under Examples.
Global-baseline review receipt (regenerated at this head; 73 matched claims)

node scripts/review-global-baselines.mjs --authority-commit 217f41d74ec41aee7f6895ea53e8b6035831f3b7 --review-head ebb80e3606b65df352d2d611ea37d3775cf00de7 --triggers layout,styling,theming,layering,testing,compatibility

Direct owners resolved first: family:layout-regions (current; FR3, FR4) and architecture:container-padding (current; INV1, INV2, INV4, INV6, System model layer 2). component:Layout is draft and non-governing.

Record (digest) Trigger Matched claims Applies to this delta
architecture:container-padding (55a9a38ca6cd) layout INV1, INV3, INV6, INV8, INV9, INV10, INV11 INV1: new var is internal and in the --layout-padding-* family. INV6: overlayPaddingReset clears it (test updated). INV3/INV8–INV11: no bleed, participation, or edge-compensation change.
architecture:component-size-cascade (a66fae4c1dd9) layout INV1–INV5, INV9 No size axis touched.
architecture:component-style-authoring (69512012c9a9) styling INV1–INV5 StyleX only. Static, valid declarations. No new wrapper.
architecture:component-theming-surface (78928cd43564) theming INV3–INV10, INV12, INV14, INV15 No target, anatomy, or public variable change. Theme card/section/dialog padding still reaches Layout regions (neutral card 12px measured).
architecture:theme-application (77631b8bd5cf) theming INV1–INV3, INV7–INV9 Not affected.
architecture:theme-authoring-contract (09b609519bc2) theming INV1, INV3, INV8, INV9, INV11, INV12 Not affected. No theme input change.
architecture:theme-compilation (623dcf810add) theming INV2–INV4, INV6, INV9, INV10 INV6: the var stays private (registered structural, not in derived[]).
architecture:layer-runtime (07e6230a3d89) layering INV2, INV5–INV7 Only the padding reset on overlay roots changes. No hosting, placement, or close behavior change.
family:overlay-dismissal (9f69d7b26765) layering FR1–FR3, FR6 Not affected.
spec:AST-003 (1a6b6c7bd2f3) layering DEC-1–3, DEC-5, FR10 Not affected.
spec:AST-027 (f37669e66720) layering DEC-1–4, FR11 DEC-4 "leaks are repaired at their owner": the leak is fixed in Layout, its owner.
spec:AST-012 (f06af20e9991) theming FR4–FR7 Not affected.
spec:AST-017 (bb984e5601a7) compatibility DEC-1, DEC-5–14, FR3–FR5, FR12, FR14–FR45 FR5 contract-restoring proposed. FR32 decision flagged above for an owner.
architecture:component-test-sufficiency (2312a6256ab0) testing INV1–INV7, INV10, INV11 New proof obligation (padding scope), mutation-sensitive against main and against the original commit, bounded to 7 cases.
spec:AST-030 (66dd54060c69) testing FR7, FR11 No lane or check-name change.

Full machine-readable receipt: review-receipt.json.

Note

Rebased onto main @ 217f41d with no conflicts. At this head, the focused tests, core typecheck, ESLint and check:repo were re-run and pass, and the global-baseline receipt was regenerated (same matched claims). Screenshots and measurements were captured against main @ eedc844; the regression tests that encode them pass at this head.

@vercel

vercel Bot commented Oct 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 Oct 7, 2026 2:26pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 1, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Oct 1, 2026
@astracat-bot

astracat-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
⏳ Waiting for review (for maintainers only) Oct 7, 2026, 3:56 PM UTC

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

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

17 of 436 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
FileInput Default neutral light 44
FileInput Default neutral dark 42

Generated by PR Enrichment workflow | Storybook | Sandbox | 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.

Thanks for the detailed fix and evidence. Scoping a Layout's padding to its own regions restores the default inset for a page Layout inside AppShell, and the Card, Section, and Dialog cases correctly keep the container's inset instead of resetting to the default — the new regression tests cover exactly the cases that separate those two behaviors.

One decision is needed from an owner before this can be approved. A padding-less Layout nested inside a Layout with non-zero padding (for example <Layout padding={2}> wrapping a padding-less <Layout>) used to inherit the outer value; it will now use the nearest container inset or the 16px default. That inheritance was not documented and no in-repo caller was found to rely on it, but approval needs an owner to confirm that no supported consumer relied on it — in which case this stands as a contract-restoring fix — or to identify such a consumer, in which case it needs to be handled as an incompatible fix with its migration (putting the same padding on the nested Layout).

Everything else is ready on the current change: no new public API, explicit padding is unchanged, and the focused tests pass.

[Automated review]

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

Nice one! 👍

@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 the detailed fix and evidence. Scoping a Layout's padding to its own regions restores the default inset for a page Layout inside AppShell, and the Card, Section, and Dialog cases correctly keep the container's inset instead of resetting to the default — the new regression tests cover exactly the cases that separate those two behaviors.

One decision is needed from an owner before this can be approved. A padding-less Layout nested inside a Layout with non-zero padding (for example <Layout padding={2}> wrapping a padding-less <Layout>) used to inherit the outer value; it will now use the nearest container inset or the 16px default. That inheritance was not documented and no in-repo caller was found to rely on it, but approval needs an owner to confirm that no supported consumer relied on it — in which case this stands as a contract-restoring fix — or to identify such a consumer, in which case it needs to be handled as an incompatible fix with its migration (putting the same padding on the nested Layout).

Everything else is ready on the current change: no new public API, explicit padding is unchanged, and the focused tests pass.

[Automated review]

Need: AppShell composes an internal Layout with padding={0}. Layout's
padding was published as the inherited --layout-padding-outer-x/y, so a
page Layout inside AppShell content (or inside any other Layout) inherited
the outer value. Its LayoutHeader, LayoutContent, LayoutPanel, and
LayoutFooter lost their default 16px inset, and page titles and body text
rendered flush against the content edge at every width.

Model: a Layout's padding now writes --layout-padding-own-outer-x/y, which
its regions read ahead of the inherited --layout-padding-outer-x/y that
Card, Section, and Dialog publish through container(). Every Layout,
padding container, and overlay root clears the own value, so it never
reaches a nested Layout's regions. The container-published value is left
alone: a Layout inside a padded Card, Section, or themed Dialog keeps that
container's inset. (Clearing --layout-padding-outer-* on every Layout
instead resets those containers' Layouts to 16px.)

Compatibility: a nested Layout without padding takes the nearest padding
container's inset or the default instead of an ancestor Layout's padding.
Explicit padding on any Layout, Layouts directly in Card/Section/Dialog,
and single Layouts are unchanged. No public API change.

@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 at this exact head. The owner settled the compatibility question: each nested Layout owns its own boundary, so a padding-less Layout inside a padded Layout using the nearest container inset or the default is a contract restoration under the layout-regions and container-padding records, and the patch changeset stands. The own-padding values are cleared by every Layout, padding container, and overlay root, so one Layout padding never reaches a nested Layout, while Card, Section, and Dialog insets and explicit padding still win. Rebased cleanly on main; CI is green, including stable visual regression, accessibility, and RTL.

[Automated review]

@cixzhang
cixzhang merged commit 22a934a into main Oct 7, 2026
45 checks passed
@github-actions
github-actions Bot deleted the fix/layout-nested-padding branch October 8, 2026 06:25

This branch was successfully deployed

1 active deployment
Preview — ed90b63c Deployed Oct 7, 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.

3 participants