Skip to content

feat(eslint): catch a theme target rendered on nothing (spread-vs-spread className clobber) - #5334

Merged
cixzhang merged 2 commits into
mainfrom
fix/lint-spread-classname-clobber
Aug 22, 2026
Merged

cixzhang merged 2 commits into
mainfrom
fix/lint-spread-classname-clobber

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Last night's Breadcrumbs audit (#5332) turned up a theme target that rendered on nothing: astryx-breadcrumb-item-menu-trigger was documented, registered, and reached no element in the DOM, so a theme written for it silently did nothing. The cause was two JSX spreads that each carried a className:

<button
  {...mergeProps(themeProps('breadcrumb-item-menu-trigger'), {...popover.triggerProps})}
  {...stylex.props(itemStyles.link, itemStyles.buttonReset)}
/>

React applies attributes left to right and does not merge them. The second spread replaced the className the first built. Both halves read as correct in review, and mergeProps on the first line reads as if the merging is already handled.

Neither existing guard could see it. @astryx/no-classname-clobber only looked for a literal className=/style= attribute beside a {...stylex.props()} spread, never spread against spread. themingTargets.test.ts is subset-only — it asserts documented targets are a subset of what source registers, so a target that renders on zero elements passes.

Widened, not a sibling rule

The rule keeps its name and gains a third messageId.

It is the same defect (a className silently replaced on one element), the same author-facing fix (put both inside one mergeProps(...)), and the same thing to learn. The rule already carries two distinct messages, so precision comes from a third message rather than a third rule — a sibling would mean two entries in both tier configs, two README sections, and two rules a contributor has to know apart, for one idea.

Detection

On one JSX opening element, count the spread attributes whose expressions are statically recognizable className producers: stylex.props(...), themeProps(...) (plus the pre-rename spellings xdsThemeProps/xdsClassName, which have no call sites left), focusOutlineProps.*(...), and mergeProps(...) when any of its own arguments is one of those, recursively. Two or more on the same element is the report; the rule points at the second one and names both.

focusOutlineProps.* is not in the original brief and is in the rule because every one of its members returns stylex.props(...) (focusOutline.stylex.ts:153) and it is spread on 17 elements today — the Breadcrumbs fix itself routes the trigger's styles through it, so a rule blind to it would miss the same defect in any component that draws a focus ring.

False positives, deliberately

  • A spread of anything that is not a recognized producer — {...rest}, {...popover.triggerProps}, an unknown call — is not counted. One producer beside any number of those is fine, and there are three such cases in the tests.
  • mergeProps is the sanctioned merge and concatenates class names, so any number of producers inside one mergeProps(...) is correct. It is only a problem beside a second, separate spread that carries a className of its own.
  • mergeProps(...) that merges nothing carrying a className is not a producer at all, so {...mergeProps(rest, {role: 'group'})} {...stylex.props(...)} stays clean.
  • A producer reached through a conditional ({...(cond ? stylex.props(a) : {})}) is out of scope. No call site in the repo writes one, and reading through the branches would invite guesses the rule cannot verify.
  • A TS cast does not hide a call: {...(stylex.props(x) as never)} is unwrapped.

Reported once per element rather than once per extra spread — the fix rewrites the whole attribute list either way.

Sweep

All 3933 tracked .ts/.tsx/.jsx/.mjs files, with the rule forced on regardless of what the tier config scopes it to.

The new spread check has exactly one hit in the repo:

File Line Shape
packages/core/src/Breadcrumbs/BreadcrumbItem.tsx 627 mergeProps(themeProps(…), …) then stylex.props(…)

That is the live defect on main, and its fix is already open in #5332. No other component in core, lab, charts, richtext, the apps, or the CLI block templates has this shape. Nothing is fixed here.

Two adjacent findings, not touched:

  • The rule's pre-existing halves fire 50 times outside the paths the tier config points the rule at: styleClobber in apps/sandbox (19), apps/docsite (18), apps/storybook (6), packages/richtext (2), packages/lab (2), packages/charts (1), and classNameClobber twice in packages/richtext/src/RichTextView.tsx (186, 208). The tier config applies the Astryx rules to packages/core/src/** only, so these have never been enforced. Widening that scope is its own change with its own diff.
  • A literal className= beside {...themeProps(...)} with no stylex.props() present is the same defect and is still not flagged, because the original half is written around stylex.props(). Left alone here to keep this diff to one idea.

Severity: warn in both tiers, temporarily

The repo is not clean — it has the one hit above — and CI runs ESLint with CI=true, which selects the strict tier, so shipping at error would turn main red for a defect whose fix is already in review. Both tiers are warn with a comment naming the flip condition; when #5332 lands, both go back to error. This is the pattern no-nullish-jsx-guard and no-style-only-wrapper already use in the same file.

The cost is that the rule's two original messages sit at warn for the same window. They have zero violations in the enforced scope, and the alternative — duplicating the Breadcrumbs fix here — would collide with #5332, which rewrites exactly those lines.

Verification

The rule was confirmed blind to the Breadcrumbs shape before anything was written: the shape as a failing RuleTester case against the old rule reported Should have 1 error but had 0.

End to end against the real file, both versions, rule forced to error:

--- origin/main (pre-fix): 1 problem(s)
  line 627:9  stylex.props() and mergeProps() are separate spreads that each set
              className, so stylex.props() replaces the one mergeProps() built and
              its classes never reach the DOM. Pass both through a single
              mergeProps() call.

--- PR #5332 (fixed): 0 problem(s)
  • no-classname-clobber.test.mjs — the rule's first colocated test file: 27 cases, 14 valid and 13 invalid, including the Breadcrumbs shape verbatim as a regression case.
  • Plugin suite: 454 passed across 24 files.
  • ASTRYX_STRICT_LINT=1 eslint . — 0 errors, 56 warnings (55 pre-existing, 1 the Breadcrumbs hit).
  • pnpm check:repo and pnpm build: clean.

No changeset: nothing in a published package changes.

Night Watch — Component Auditor

Widen no-classname-clobber to the shape it could not see: two JSX spreads
that each carry a className, where the later one silently replaces the
earlier. Adds the rule's first colocated test file.
The spread check has one violation in the repo — BreadcrumbItem, whose fix
is open in #5332 — so both tiers warn until that lands rather than turning
CI red.
@vercel

vercel Bot commented Aug 22, 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 22, 2026 1:22pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 22, 2026
@github-actions

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.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

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 22, 2026
@cixzhang
cixzhang merged commit 0dfce02 into main Aug 22, 2026
18 checks passed
@github-actions
github-actions Bot deleted the fix/lint-spread-classname-clobber branch August 23, 2026 06:11

This branch was successfully deployed

1 active deployment
Preview — 23eb9f70 Deployed Aug 22, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant