Skip to content

refactor(core): migrate style-only wrappers onto component xstyle - #4775

Merged
cixzhang merged 4 commits into
mainfrom
migrate-style-wrappers
Aug 7, 2026
Merged

cixzhang merged 4 commits into
mainfrom
migrate-style-wrappers

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Why

Style-only wrappers are the root cause of wrapper-shaped theme targets: a <div>/<span> that exists only to carry styles is often the only element in the subtree with styles on it, so that's what people end up theming — a node the component contract never promised. Theming targets should attach to the component that paints; layout is not a theme seam.

This is the follow-up #4758 (feat(lint): flag div/span wrappers that only style an Astryx component) names in its own description: migrate the pre-existing sites so the rule can eventually go strict. Each site moves real styles onto a component root, which is why it wanted its own visual check rather than riding along with the rule.

Related: #4752, which fixed an off-center pagination caret caused by exactly one of these wrappers.

The count is 23, not 25 — #4758's description should be corrected

Running the rule against origin/main (cherry-picking #4758's plugin locally, not included in this diff) reports 23 violations in shipped code, in 10 files. There are 3 more in *.test.tsx, which eslint.config.js deliberately turns the rule off for — 23 + 3 = 26, so the "25" looks like an older count taken before that test exclusion settled. No packages/core file flagged here changed between #4758's merge-base and main, so this is not drift since the branch was cut.

What moved (15 of 23)

# Site Wrapper carried Now
1-2 Carousel.tsx:563,588 rtlStyles.mirror <Icon xstyle={rtlStyles.mirror}>
3-4 Lightbox.tsx:615,682 rtlStyles.mirror <Icon xstyle={rtlStyles.mirror}>
5-6 Pagination.tsx:815,868 rtlStyles.mirror <Icon xstyle={rtlStyles.mirror}> (matches what #4752 already did for prev/next)
7 useTableRowExpansion.tsx:601 rtlStyles.mirror <Icon xstyle={rtlStyles.mirror}>
8 Lightbox.tsx:598 position:absolute, top, insetInlineEnd, zIndex <IconButton xstyle={[styles.closeButton, styles.controlButton]}>
9-10 Lightbox.tsx:612,679 position:absolute, top:50%, transform:translateY(-50%), inset, zIndex <IconButton xstyle={[styles.navButton, styles.navPrev|navNext, styles.controlButton]}> — transform became the individual translate property, see below
11 MobileNav.tsx:456 marginInlineStart <Heading xstyle={styles.headerText}>
12 Switch.tsx:646 marginTop <FieldStatus xstyle={styles.statusGap}>
13 TopNav.tsx:246 marginBlock <Divider xstyle={styles.drawerDivider}>
14 TopNavMegaMenu.tsx:496 flexGrow/flexShrink/flexBasis/minWidth <Grid xstyle={styles.menuWrapper}>
15 Pagination.tsx:794 width: 80 <Selector width={80}> — the width prop, not xstyle, see below

Two of these are not a plain relocation, and both are because the target component already owns the property:

  • Lightbox nav buttons — transform: translateY(-50%) on the Button root collides with Button's own transform rules. Measured: with transform in xstyle, the pressed button reports matrix(1,0,0,1,0,-16) — Button's scale(0.98) press feedback silently stops firing. Switching to the individual translate: '0 -50%' property composes instead of replacing: pressed reports translate: 0px -50% + transform: matrix(0.98,0,0,0.98,0,0), i.e. exactly the wrapper-translates-button-scales composition that existed before. Disabled state (transform: none) also behaves.
  • Pagination page-size Selector — Selector's xstyle lands on the trigger box, not the field root (Selector.tsx:1193 vs the <Field> it returns at the bottom), which is documented on the width prop itself. width is the API that sizes the field, so width={80} reproduces the wrapper exactly.

Visual evidence

Playwright + Chromium at DPR 2 against local Storybook, before/after per component, full-image pixel diff plus computed geometry. Images and geometry dumps: ~/wrapper-migration/*.png (also /tmp/wrapper-migration/).

Story Result
core-carousel--default, LTR + forced RTL pixel-identical, DOM one node lighter
core-pagination--with-page-size-selector pixel-identical
core-switch--status-variations pixel-identical; FieldStatus root margin-top 4px → 8px, rendered y unchanged (the wrapper's 8px was collapsing with the child's 4px)
core-appshell--top-nav-with-side-nav @500px, drawer open pixel-identical; Divider now carries margin: 8px 0 itself
core-mobilenav--default, drawer open pixel-identical; Heading now carries margin-left: 4px
core-topnavmenu--mega-menu, panel open pixel-identical
core-lightbox--gallery LTR / RTL / last-item (disabled next) 292px differ (0.010%): the prev/next chevrons moved down 2.5px into the button's vertical centre. Before, icon box y 679-711 inside a button y 668-732 (centre 695 vs 700); after, centred exactly. Nav-button positions are otherwise identical, RTL mirroring unchanged.
core-pagination--input-variant LTR / RTL 811px differ (0.113%): the first/last chevrons moved down 3px into the button's centre (icon y=38 → y=44, matching prev/next which were already at 44). This is the same defect #4752 fixed for prev/next — the wrapper was the cause.
core-tablerowexpansion--inherited-columns, context menu open icon box identical; the menu label's ink centroid shifts 0.44 × 0.65 CSS px (the icon span stops being an inline box in the row's line box). Sub-pixel, no layout change.

So: 11 of the 13 captured states are pixel-identical, and the two that differ are pre-existing mis-centering that this PR fixes.

Left unmigrated (8) — both are rule findings, not cowardice

7 × PowerSearchEditPopover.tsx (312, 324, 337, 555, 740, 799, 811) — blocked, xstyle reaches the wrong element.
Six of these wrap a <Selector> in a flex sizing box (flexGrow/flexShrink/minWidth, or width: 200/180). Because Selector puts xstyle on its trigger container and returns a <Field> root, moving those styles to xstyle sizes the box inside the field instead of the field itself. Measured in a scratch story: field is 472px wide with the wrapper, 85px with xstyle={{flexGrow:1,minWidth:0}} (the flexGrow lands two levels down, on the trigger). That's a severe regression, so they stay. Unblocking them needs a decision on whether Selector's xstyle should target the field root — public API, maintainer's call, and adjacent to #4528.
The seventh (337) wraps PowerSearchValueEditor, which is not a BaseProps component at all — it takes no xstyle/className/style and just returns one of TextInput/Typeahead/Tokenizer/NumberInput. The rule flagged it because it is imported relatively, and the default componentSources assumes every relative import takes xstyle. Rule bug: over-flag.

1 × ChatLayoutScrollButton.tsx:133 — rule over-flag, the wrapper is a clipping container.
That <div> is the pill: overflow: hidden + animated max-width (32px collapsed → 200px expanded) around a ghost Button that is deliberately wider than the pill. I implemented the migration, measured it, and reverted: with the styles on the Button, the collapsed chevron sits 4px left of the circle's centre (button width 145.9px→32px, icon centre 250px→246px against a 250px circle centre), because the icon is no longer centred by clipping an over-wide button. The rule's structural exemptions cover display, flex/grid container props, gap and padding, but a wrapper whose job is overflow + max-width clipping is doing layout work just as much. Suggested rule fix: treat overflow, max-width/max-height and contain as structural.
Side finding while I had it apart: that same overflow: hidden clips the Button's :focus-visible ring today (offset 3px, pill is exactly the button's height) — a latent a11y issue in ChatLayoutScrollButton worth its own issue, independent of this PR.

Rule tier: not flipping to error here

Deliberately not flipping @astryx/no-style-only-wrapper to error in the strict tier, for two reasons:

  1. 8 sites remain, 7 of them blocked on an API decision.
  2. Per the theming-target inventory running in parallel: the rule currently can't see any element that actually carries a theme target, because it bails on spreads that aren't literally stylex.props(...) and every target is {...mergeProps(themeProps(...), stylex.props(...))}. That ~15-line fix should land before the tier flip, so the flip happens against the rule's real scope rather than its current partial one.

Test plan

  • npx vitest run over Carousel, Lightbox, Pagination, MobileNav, Switch, TopNav, Table, Chat, Selector — 1030 passed (Table.perf 500-row budget flaked once under load alongside Storybook; passes clean in isolation).
  • tsc --noEmit on @astryxdesign/core — no new errors (two pre-existing locales/pseudo.json module errors in i18n tests, present on main).
  • eslint on every changed file — clean; the 8 remaining no-style-only-wrapper warnings are the sites listed above.
  • node scripts/check-changesets.mjs ✓, plus the pre-commit gate (check:sync, package boundaries, demo media, executable bits, CLI structure) on each commit.
  • Changeset added, patch, @cixzhang — no API change, but consumer-visible DOM, and the reasoning for patch over [breaking] is written into the changeset body.

Refs #4758.

🤖 Drafted with agentcloud; every measurement above was taken on this branch.

…style

The <span {...stylex.props(rtlStyles.mirror)}> wrappers around directional
chevrons exist only to carry the mirror transform. Icon extends BaseProps and
merges xstyle into the same span it already renders, so the style lands on the
same element and one DOM node goes away. Pagination's prev/next carets already
use this shape (#4752); this brings first/last, Carousel, Lightbox and the
Table row-expansion menu icon in line.

Sites: Carousel x2, Lightbox x2, Pagination x2, Table/rowExpansion x1.
Each wrapper here carried only positioning/spacing for the single Astryx
component inside it, so the styles move onto that component's own root:

- Lightbox close/prev/next: absolute placement onto IconButton's xstyle.
  navButton switches transform: translateY(-50%) to the individual translate
  property, because on the Button root a transform replaces the Button's own
  transform rules and kills its scale(0.98) press feedback; translate composes
  with them, which is what the wrapper+button pair did before.
- Pagination page-size Selector: the wrapper set width, so it becomes the
  documented width prop. Selector's xstyle targets the trigger box, not the
  field root, so xstyle would have sized the wrong element.
- MobileNav header Heading, Switch FieldStatus, TopNav drawer Divider,
  TopNavMegaMenu Grid: straight move onto xstyle.

Measured with Playwright against Storybook: rendered geometry is unchanged
except where the wrapper was actively mis-centering the icon — Lightbox
prev/next chevrons and Pagination first/last chevrons were 2.5-3px off the
button's vertical center (same defect #4752 fixed for prev/next) and are now
centered.
@vercel

vercel Bot commented Aug 7, 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 7, 2026 12:47am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 7, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Aug 7, 2026
@cixzhang
cixzhang marked this pull request as ready for review August 7, 2026 01:04
@cixzhang
cixzhang merged commit 5fb9a2d into main Aug 7, 2026
21 checks passed
@github-actions

github-actions Bot commented Aug 7, 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

Carousel (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 427 -
Complexity N/A Very High (48) -
Lightbox (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 642 -
Complexity N/A Very High (83) -
MobileNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 376 -
Complexity N/A Very High (39) -
Pagination (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 638 -
Complexity N/A Very High (92) -
Switch (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 466 -
Complexity N/A Very High (43) -
Table (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1936 -
Complexity N/A Very High (112) -
TopNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 2100 -
Complexity N/A Very High (156) -

Bundle Size Summary

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

Accessibility Audit

Status: No accessibility violations detected.


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

This branch was successfully deployed

1 active deployment
Preview — a4e43a9d Deployed Aug 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.

1 participant