Skip to content

fix(core,lab): reset container padding custom properties on overlay elements (#5208) - #5209

Merged
imdreamrunner merged 3 commits into
meta:mainfrom
Geervan:fix/overlay-section-padding
Aug 19, 2026
Merged

imdreamrunner merged 3 commits into
meta:mainfrom
Geervan:fix/overlay-section-padding

Conversation

@Geervan

@Geervan Geervan commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5208

Problem

When a <Section> is rendered inside an overlay (Drawer, Dialog, MobileNav) that sits inside a page <Section padding={4}>, the inner <Section> calculates -16px negative margins on both sides and overflows the overlay by 32px.

Section uses margin-inline-start: calc(-1 * var(--container-padding-inline-start, 0px)) to escape parent section padding. Because fixed overlay elements inherit CSS custom properties from ancestor DOM elements, the inner Section escapes padding that isn't visually there on the overlay panel.

Fix

Reset container padding CSS variables to 0px on root overlay styles in Drawer.tsx, Dialog.tsx, and MobileNav.tsx:

'--container-padding-inline-start': '0px',
'--container-padding-inline-end': '0px',
'--container-padding-block-start': '0px',
'--container-padding-block-end': '0px',

@vercel

vercel Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 19, 2026 6:14pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 19, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 19, 2026
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

BottomSheet (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 3122 -
Complexity N/A Very High (249) -
Dialog (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 629 -
Complexity N/A Very High (79) -
MobileNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 417 -
Complexity N/A Very High (49) -
Popover (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 557 -
Complexity N/A Very High (52) -
Drawer (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 485 -
Complexity N/A Very High (52) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB
@astryxdesign/lab N/A 3.6KB 1.5KB

Accessibility Audit

Status: No accessibility violations detected.


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

github-actions Bot added a commit that referenced this pull request Aug 19, 2026
@imdreamrunner

imdreamrunner commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

(this is an AI agent comment)

Not a review, just findings — I filed #5208, so I built this branch and measured it against the repro. The mechanism is right. Zeroing --container-padding-* at the overlay root is exactly the fix. Two things stop it from closing the issue as-is.

1. BottomSheet isn't covered — and it's the component in the issue

The branch is based on 2026-07-21, 634 commits behind main, which predates the BottomSheet promotion into core. packages/core/src/BottomSheet/ doesn't exist on it, so a rebase is needed before the component can be touched at all.

BottomSheet renders its own <dialog> (BottomSheet.tsx, styles.dialog) rather than going through Dialog, so it doesn't inherit this fix.

2. The Dialog change is a no-op today

I measured the variable at each level, using a 40px page padding so the leaked value is distinguishable from Dialog's own 16px:

page Section        40px
<dialog>            40px   ← the leak arrives (this PR sets it to 0)
  content wrapper   16px   ← Dialog's own padding already shadows it
    inner Section   16px   ← reads 16px either way

The escape margin is -16px with the fix and -16px without it. Same layout both ways.

That is also why BottomSheet is the one that breaks: its scroll body is padding: 0, so nothing shadows the leaked value and it reaches the Section intact — 672px of content in a 640px sheet.

Worth keeping the Dialog change as defence in depth (it is correct, and a future Dialog with an unpadded body would need it), but it isn't what closes #5208.

Smaller things

  • No changeset. Nothing under .changeset/; the rubric treats a missing changeset as blocking for a consumer-visible change (X20). CI seems not to flag the absent-file case.
  • The Drawer test doesn't test the fix. It's titled "resets container padding custom properties on the root dialog element" but only asserts expect(dialog).toBeInTheDocument() — it passes unchanged with the fix reverted. jsdom does no layout, so the assertable thing is the computed custom property:
    expect(
      getComputedStyle(dialog).getPropertyValue('--container-padding-inline-start'),
    ).toBe('0px');
  • Popover is also non-portaling and has the same exposure; not covered here, and fine as a follow-up.

Suggested shape

  1. Rebase onto main.
  2. Add the reset to BottomSheet's <dialog> (and its panel).
  3. Add a changeset.
  4. Make the test assert the property.

Repro I used, if it helps — the inner Section overflows the sheet by 16px each side:

<Section padding={4}>
  <BottomSheet isOpen label="Sheet" height="tall" onOpenChange={() => {}}>
    <Section padding={4}>content</Section>
  </BottomSheet>
</Section>

Thanks for picking this up — the diagnosis is right, it just needs the newer base to reach the component that shows it.

@Geervan
Geervan force-pushed the fix/overlay-section-padding branch from 641f74d to 8d0c34e Compare August 19, 2026 18:11
@Geervan

Geervan commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review feedback, @imdreamrunner, I dont know how i didnt realise the stale branch

Updates in this push:

  1. Rebased onto latest upstream/main:
    Rebased onto HEAD commit (33ba2b6a81b083568bf46cd579fb50e5b36285da) so the branch is 0 commits behind facebook/astryx:main.

  2. Core Fix Applied to BottomSheetPanel:
    Added --container-padding-* resets (0px) directly to styles.sheet in packages/core/src/BottomSheet/BottomSheetPanel.tsx—the actual visual sheet surface container in @astryxdesign/core. Also added resets to usePopover.tsx (styles.surface) and preserved Dialog.tsx for defense-in-depth.

  3. Updated Unit Tests with Computed Style Assertions:
    Replaced passive toBeInTheDocument() checks with explicit window.getComputedStyle(element) assertions in BottomSheet.test.tsx, Dialog.test.tsx, and Drawer.test.tsx, asserting that --container-padding-inline-start, inline-end, block-start, and block-end directly evaluate to '0px'.

  4. Added Changeset:
    Added .changeset/reset-overlay-container-padding.md targeting @astryxdesign/core.


Verification Summary

  • node scripts/check-changesets.mjs: ✓ 1 changeset(s) valid
  • BottomSheet unit test suite (BottomSheet.test.tsx): 71/71 passed.
  • Drawer unit test suite (Drawer.test.tsx): 39/39 passed.

@imdreamrunner imdreamrunner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is an AI agent review, run by @imdreamrunner)

Approving — this closes #5208. Verified on a build of 8d0c34e.

The repro is fixed. Section inside a 640px sheet: 672px before (32px overflow), 640px now. The sheet panel reads --container-padding-inline-start: 0px instead of the leaked 16px.

The tests are real now. I stripped the reset from BottomSheetPanel.tsx, Dialog.tsx and Drawer.tsx and all three new tests failed with expected '' to be '0px' — they discriminate, unlike the earlier toBeInTheDocument() version. Thanks for reworking those.

No harm from the reset. The four patched elements have no padding of their own to escape (Drawer/MobileNav dialogs are padding: 0, the sheet has only its safe-area paddingBlockEnd, and the popover surface keeps padding on the inner content div). Every consumer reads these as var(--container-padding-*, 0px), so with no ancestor leak they already computed 0px — the reset changes a computed value only where an ancestor leaked one, which was the bug. Legitimate escapes still work: a Section inside a Dialog still bleeds to the dialog edge (640px in a 640px dialog, -16px margins), because Dialog's inner wrapper sets real values via container() and shadows the root zero.

Full suites for the five touched components: 351/351. pnpm lint clean. Core-only changeset frontmatter is correct — @astryxdesign/lab is private: true.

Two things I'm deliberately not blocking on; I'll send a follow-up PR for both:

  1. The other half of the leak. --astryx-section-padding and --layout-padding-inner-x/y still cross the overlay boundary, so an unpadded Section in an overlay under <Section padding={10}> renders at 40px instead of the 16px theme default. The overflow is gone; this isn't.
  2. Three overlays still uncovered — Lightbox (own <dialog>), ContextMenu and HoverCard (they call useLayer directly, so the usePopover surface reset misses them). Putting the reset in useLayer's base style covers the last two, and an exported containerPaddingReset would stop the block being hand-copied — it's in six places now, which is why each new overlay keeps forgetting it.

One nit worth a quick push before merge: pnpm exec prettier --write on the three test files. The expect(...) lines exceed print width and BottomSheet.test.tsx / Drawer.test.tsx each end with a stray blank line. No CI job runs a format check, so it's green either way — it'd just land as drift.

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 19, 2026
@imdreamrunner

Copy link
Copy Markdown
Contributor

Thanks for the fix! Looks good!

@imdreamrunner
imdreamrunner merged commit 0c6ab03 into meta:main Aug 19, 2026
21 checks passed
imdreamrunner added a commit that referenced this pull request Aug 20, 2026
…ndary

Follow-up to #5209, which zeroed --container-padding-* on four overlay
roots and closed the visible overflow in #5208. Two gaps remained.

The variables descendants ADD (--layout-padding-*, and a Section's
propagated padding) still crossed the boundary, so an unpadded Section
inside an overlay took the page's padding instead of the theme default —
40px where 16px was meant. And Lightbox, ContextMenu and HoverCard were
never covered.

The reset now lives in one place (overlayPaddingReset, exported from
@astryxdesign/core/Layout) instead of being hand-copied per overlay, and
moved onto the useLayer root, which covers every layer surface at once.
Values descendants subtract are zeroed; values they add are cleared to
initial so readers fall through to their own default rather than losing
their padding.

Section's padding propagation moved from the public
--astryx-section-padding token to a private --_section-padding-propagated.
The two carried different authority under one name — a theme's value
versus one ancestor's — and an overlay could not drop the inherited one
without blanking the theme's. Propagated values still win over the theme
for nested sections, so behavior is unchanged.
imdreamrunner added a commit that referenced this pull request Aug 20, 2026
…ndary (#5231)

Follow-up to #5209, which zeroed --container-padding-* on four overlay
roots and closed the visible overflow in #5208. Two gaps remained.

The variables descendants ADD (--layout-padding-*, and a Section's
propagated padding) still crossed the boundary, so an unpadded Section
inside an overlay took the page's padding instead of the theme default —
40px where 16px was meant. And Lightbox, ContextMenu and HoverCard were
never covered.

The reset now lives in one place (overlayPaddingReset, exported from
@astryxdesign/core/Layout) instead of being hand-copied per overlay, and
moved onto the useLayer root, which covers every layer surface at once.
Values descendants subtract are zeroed; values they add are cleared to
initial so readers fall through to their own default rather than losing
their padding.

Section's padding propagation moved from the public
--astryx-section-padding token to a private --_section-padding-propagated.
The two carried different authority under one name — a theme's value
versus one ancestor's — and an overlay could not drop the inherited one
without blanking the theme's. Propagated values still win over the theme
for nested sections, so behavior is unchanged.
@github-actions
github-actions Bot deleted the fix/overlay-section-padding branch August 20, 2026 06:54

This branch was successfully deployed

1 active deployment
Preview — 8d0c34ea Deployed Aug 19, 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. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Section inside a BottomSheet overflows the sheet (escapes an ancestor's container padding)

2 participants