Skip to content

fix(transform): deduplicate CSS rules from resolveStyleRulesForSlots#834

Open
layershifter wants to merge 2 commits intomicrosoft:mainfrom
layershifter:fix/transform-dedup-css-rules
Open

fix(transform): deduplicate CSS rules from resolveStyleRulesForSlots#834
layershifter wants to merge 2 commits intomicrosoft:mainfrom
layershifter:fix/transform-dedup-css-rules

Conversation

@layershifter
Copy link
Copy Markdown
Member

@layershifter layershifter commented Apr 9, 2026

Summary

  • dedupeCSSRules() was being called on the previously accumulated cssRulesByBucket instead of the freshly resolved resolvedCSSRules. This meant duplicates within each makeStyles call were never removed from the intermediate result.
  • The deduplicated result (uniqueCSSRules) was only used for metadata — the raw un-deduplicated resolvedCSSRules was appended to the output bucket.

This does not affect the final generated CSS (the webpack plugin deduplicates when collecting CSS across modules), but it does cause the cssRulesByBucket returned by transformSync() to contain duplicate entries — LTR/RTL pairs and cross-slot duplicates.

Fix

- const uniqueCSSRules = dedupeCSSRules(cssRulesByBucket);
+ const uniqueCSSRules = dedupeCSSRules(resolvedCSSRules);
  ...
- cssRulesByBucket = concatCSSRulesByBucket(cssRulesByBucket, resolvedCSSRules);
+ cssRulesByBucket = concatCSSRulesByBucket(cssRulesByBucket, uniqueCSSRules);

This matches how @griffel/babel-preset handles deduplication (line 341 of transformPlugin.ts).

Test plan

  • All 79 transform tests pass (3 snapshots updated to remove duplicate entries)

dedupeCSSRules() was being called on the previously accumulated
cssRulesByBucket instead of the current resolvedCSSRules. This caused
duplicate LTR/RTL pairs and cross-slot duplicates to accumulate in the
output, roughly doubling CSS bundle size.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@layershifter layershifter requested a review from a team as a code owner April 9, 2026 16:01
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

📊 Bundle size report

✅ No changes found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant