Repository navigation
perf(core): an overlay's eager import no longer carries the lazy BottomSheet's padding and focus code #8550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
vjeux
wants to merge
1
commit into
meta:main
Choose a base branch
from
vjeux:uikit/overlay-eager-padding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [perf] Components that import Popover no longer load BottomSheet's container padding styles and focus helper up front. Popover loads a BottomSheet on demand for its phone presentation, and a bundler that splits code put the modules both of them use into one chunk that loads with the component, keeping every export either side uses: about 3.5 KB minified in Popover, Carousel, DateRangeInput, DropdownMenu, Table and the other components that import Popover or DropdownMenu. `paddingStyles` and `overlayPaddingReset` now have their own modules, still exported from `@astryxdesign/core/Layout/padding.stylex`, and `isFocusDetached` has its own module, still exported from `@astryxdesign/core/utils`. Rendering is unchanged. | ||
|
|
||
| @vjeux | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file overlayPaddingReset.stylex.ts | ||
| * @input Uses @stylexjs/stylex | ||
| * @output overlayPaddingReset: the container padding boundary at an overlay's root | ||
| * @position Layout utility, re-exported by padding.stylex.ts and Layout/index.ts. | ||
| * Its own module so an overlay's eager code (useLayer) imports it without | ||
| * padding.stylex.ts: a lazily loaded overlay that uses the container padding | ||
| * styles there then keeps them out of the eager chunk it shares with this | ||
| * module. | ||
| */ | ||
|
|
||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| /** | ||
| * Padding-variable reset for overlay roots (Dialog, BottomSheet, Drawer, | ||
| * MobileNav, Lightbox, and every layer surface). | ||
| * | ||
| * ## Why an overlay needs this | ||
| * | ||
| * The container padding system talks to descendants through inherited custom | ||
| * properties: a padded container announces its padding, and children read the | ||
| * value either to apply it or to cancel it with a negative margin | ||
| * (`Section`, `Divider`, `Layout`, `Table`). | ||
| * | ||
| * Inheritance follows the DOM, but an overlay leaves its parent's visual box — | ||
| * a fixed/top-layer `<dialog>` is a DOM descendant of the padded page while | ||
| * being nowhere near it on screen. It inherits values describing padding that | ||
| * is not there, and its content compensates against phantom space: a `Section` | ||
| * inside a 640px sheet rendered 672px wide and hung off both edges (#5208). | ||
| * | ||
| * Two families leak, and they need opposite treatments: | ||
| * | ||
| * - `--container-padding-*` -> `0px`. Descendants SUBTRACT these (bleed | ||
| * margins). The overlay root has no padding of its own to escape, so the | ||
| * honest answer is zero. Nested containers that do set padding (a Dialog's | ||
| * content wrapper) re-announce their own values below this point, so | ||
| * legitimate edge-to-edge bleed inside the overlay is unaffected. | ||
| * - `--layout-padding-*` and `--_section-padding-propagated` -> `initial`. | ||
| * Descendants ADD these, so zeroing them would strip padding rather than | ||
| * restore it. `initial` makes each guaranteed-invalid, so readers fall | ||
| * through their own `var(…, fallback)` chain and land on the theme default — | ||
| * which is what an overlay at the top of the tree should show. | ||
| * | ||
| * `initial` is also why propagation moved off `--astryx-section-padding`: that | ||
| * name is public theme surface, set at the theme root, and making it invalid | ||
| * here would blank the theme's own section padding inside every overlay. | ||
| * | ||
| * Apply on the overlay's outermost styled element. | ||
| * | ||
| * @example | ||
| * ``` | ||
| * <dialog {...stylex.props(styles.dialog, overlayPaddingReset.reset)} /> | ||
| * ``` | ||
| */ | ||
| export const overlayPaddingReset = stylex.create({ | ||
| reset: { | ||
| // Subtracted by descendants — the overlay root has no padding to escape. | ||
| '--container-padding-inline-start': '0px', | ||
| '--container-padding-inline-end': '0px', | ||
| '--container-padding-block-start': '0px', | ||
| '--container-padding-block-end': '0px', | ||
| // Added by descendants — fall through to each reader's own default. | ||
| '--layout-padding-outer-x': 'initial', | ||
| '--layout-padding-outer-y': 'initial', | ||
| '--layout-padding-own-outer-x': 'initial', | ||
| '--layout-padding-own-outer-y': 'initial', | ||
| '--layout-padding-inner-x': 'initial', | ||
| '--layout-padding-inner-y': 'initial', | ||
| '--_section-padding-propagated': 'initial', | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file paddingStyles.stylex.ts | ||
| * @input Uses @stylexjs/stylex, spacing from theme | ||
| * @output paddingStyles: uniform padding on all four sides by SpacingStep | ||
| * @position Layout utility, re-exported by padding.stylex.ts. Its own module so an | ||
| * overlay's eager code (usePopover) imports it without padding.stylex.ts: | ||
| * a lazily loaded overlay that uses the container padding styles there then | ||
| * keeps them out of the eager chunk it shares with this module. | ||
| */ | ||
|
|
||
| import * as stylex from '@stylexjs/stylex'; | ||
| import {spacingVars} from '../theme/tokens.stylex'; | ||
|
|
||
| /** | ||
| * Padding styles for all sides using spacing tokens. | ||
| * Each key applies uniform padding to all four sides. | ||
| */ | ||
| export const paddingStyles = stylex.create({ | ||
| 0: { | ||
| paddingInlineStart: spacingVars['--spacing-0'], | ||
| paddingInlineEnd: spacingVars['--spacing-0'], | ||
| paddingBlockStart: spacingVars['--spacing-0'], | ||
| paddingBlockEnd: spacingVars['--spacing-0'], | ||
| }, | ||
| 0.5: { | ||
| paddingInlineStart: spacingVars['--spacing-0-5'], | ||
| paddingInlineEnd: spacingVars['--spacing-0-5'], | ||
| paddingBlockStart: spacingVars['--spacing-0-5'], | ||
| paddingBlockEnd: spacingVars['--spacing-0-5'], | ||
| }, | ||
| 1: { | ||
| paddingInlineStart: spacingVars['--spacing-1'], | ||
| paddingInlineEnd: spacingVars['--spacing-1'], | ||
| paddingBlockStart: spacingVars['--spacing-1'], | ||
| paddingBlockEnd: spacingVars['--spacing-1'], | ||
| }, | ||
| 1.5: { | ||
| paddingInlineStart: spacingVars['--spacing-1-5'], | ||
| paddingInlineEnd: spacingVars['--spacing-1-5'], | ||
| paddingBlockStart: spacingVars['--spacing-1-5'], | ||
| paddingBlockEnd: spacingVars['--spacing-1-5'], | ||
| }, | ||
| 2: { | ||
| paddingInlineStart: spacingVars['--spacing-2'], | ||
| paddingInlineEnd: spacingVars['--spacing-2'], | ||
| paddingBlockStart: spacingVars['--spacing-2'], | ||
| paddingBlockEnd: spacingVars['--spacing-2'], | ||
| }, | ||
| 3: { | ||
| paddingInlineStart: spacingVars['--spacing-3'], | ||
| paddingInlineEnd: spacingVars['--spacing-3'], | ||
| paddingBlockStart: spacingVars['--spacing-3'], | ||
| paddingBlockEnd: spacingVars['--spacing-3'], | ||
| }, | ||
| 4: { | ||
| paddingInlineStart: spacingVars['--spacing-4'], | ||
| paddingInlineEnd: spacingVars['--spacing-4'], | ||
| paddingBlockStart: spacingVars['--spacing-4'], | ||
| paddingBlockEnd: spacingVars['--spacing-4'], | ||
| }, | ||
| 5: { | ||
| paddingInlineStart: spacingVars['--spacing-5'], | ||
| paddingInlineEnd: spacingVars['--spacing-5'], | ||
| paddingBlockStart: spacingVars['--spacing-5'], | ||
| paddingBlockEnd: spacingVars['--spacing-5'], | ||
| }, | ||
| 6: { | ||
| paddingInlineStart: spacingVars['--spacing-6'], | ||
| paddingInlineEnd: spacingVars['--spacing-6'], | ||
| paddingBlockStart: spacingVars['--spacing-6'], | ||
| paddingBlockEnd: spacingVars['--spacing-6'], | ||
| }, | ||
| 8: { | ||
| paddingInlineStart: spacingVars['--spacing-8'], | ||
| paddingInlineEnd: spacingVars['--spacing-8'], | ||
| paddingBlockStart: spacingVars['--spacing-8'], | ||
| paddingBlockEnd: spacingVars['--spacing-8'], | ||
| }, | ||
| 10: { | ||
| paddingInlineStart: spacingVars['--spacing-10'], | ||
| paddingInlineEnd: spacingVars['--spacing-10'], | ||
| paddingBlockStart: spacingVars['--spacing-10'], | ||
| paddingBlockEnd: spacingVars['--spacing-10'], | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: "about 3.5 KB minified" fits Carousel, ContextMenu, Markdown and Table, but Popover saves about 2.9 KB, DateRangeInput about 2.9 KB, DropdownMenu about 2.6 KB and DateInput only 66 B. "Up to about 3.8 KB minified (about 1 KB gzip)" would be accurate.