Repository navigation
feat(eslint): catch a theme target rendered on nothing (spread-vs-spread className clobber) - #5334
Merged
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Last night's Breadcrumbs audit (#5332) turned up a theme target that rendered on nothing:
astryx-breadcrumb-item-menu-triggerwas 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 aclassName: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
mergePropson the first line reads as if the merging is already handled.Neither existing guard could see it.
@astryx/no-classname-clobberonly looked for a literalclassName=/style=attribute beside a{...stylex.props()}spread, never spread against spread.themingTargets.test.tsis 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 spellingsxdsThemeProps/xdsClassName, which have no call sites left),focusOutlineProps.*(...), andmergeProps(...)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 returnsstylex.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
{...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.mergePropsis the sanctioned merge and concatenates class names, so any number of producers inside onemergeProps(...)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.{...(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.{...(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/.mjsfiles, 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:
packages/core/src/Breadcrumbs/BreadcrumbItem.tsxmergeProps(themeProps(…), …)thenstylex.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:
styleClobberinapps/sandbox(19),apps/docsite(18),apps/storybook(6),packages/richtext(2),packages/lab(2),packages/charts(1), andclassNameClobbertwice inpackages/richtext/src/RichTextView.tsx(186, 208). The tier config applies the Astryx rules topackages/core/src/**only, so these have never been enforced. Widening that scope is its own change with its own diff.className=beside{...themeProps(...)}with nostylex.props()present is the same defect and is still not flagged, because the original half is written aroundstylex.props(). Left alone here to keep this diff to one idea.Severity:
warnin both tiers, temporarilyThe repo is not clean — it has the one hit above — and CI runs ESLint with
CI=true, which selects the strict tier, so shipping aterrorwould turnmainred for a defect whose fix is already in review. Both tiers arewarnwith a comment naming the flip condition; when #5332 lands, both go back toerror. This is the patternno-nullish-jsx-guardandno-style-only-wrapperalready use in the same file.The cost is that the rule's two original messages sit at
warnfor 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
RuleTestercase against the old rule reportedShould have 1 error but had 0.End to end against the real file, both versions, rule forced to
error: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.ASTRYX_STRICT_LINT=1 eslint .— 0 errors, 56 warnings (55 pre-existing, 1 the Breadcrumbs hit).pnpm check:repoandpnpm build: clean.No changeset: nothing in a published package changes.
Night Watch — Component Auditor