Skip to content

fix: buildCssSnippet self-referential var() bug + slot styling guidance#158

Merged
himerus merged 3 commits intodevfrom
feature/fix-css-snippet-enhance-diagnostics
Mar 21, 2026
Merged

fix: buildCssSnippet self-referential var() bug + slot styling guidance#158
himerus merged 3 commits intodevfrom
feature/fix-css-snippet-enhance-diagnostics

Conversation

@himerus
Copy link
Contributor

@himerus himerus commented Mar 21, 2026

Summary

  • Bug fix: buildCssSnippet was generating circular CSS like --my-button-bg: var(--my-button-bg) — agents copying this would produce broken styles. Now generates correct override patterns using CEM defaults or smart property-name heuristics.
  • Slot styling section: CSS snippet now includes light DOM slot styling examples with default slot child selectors and named slot attribute selectors.
  • Font inheritance warning: New anti-pattern warning explaining that font properties inherit through Shadow DOM but layout properties don't — a common source of confusion for agents styling slotted content.

Test plan

  • 6 new tests added covering: no self-referential var(), CEM defaults, slot styling section, named slot selectors, default slot child selectors, font inheritance warning
  • All 33 styling-diagnostics tests pass
  • Full suite: 2284 pass, 1 pre-existing failure (hx-carousel phantom events)
  • TypeScript: clean
  • Prettier: clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added diagnostic warnings for incorrect CSS expectations with slotted elements
    • Introduced slot styling guidance sections to generated CSS snippets with light-DOM selector examples
  • Improvements

    • Enhanced CSS token customization output with improved default value handling and inline descriptions
    • Refined anti-pattern detection to catch common layout styling mistakes on slotted components

himerus and others added 2 commits March 21, 2026 02:43
…ce + font inheritance warnings

- Fix buildCssSnippet generating circular --token: var(--token) CSS
- Use CEM default values or smart property-name heuristics for placeholder values
- Add slot styling section showing correct light DOM CSS patterns
- Add font vs layout inheritance anti-pattern warning for slotted content

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

Warning

Rate limit exceeded

@himerus has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c60135c1-3547-47f4-9389-c05c154981bb

📥 Commits

Reviewing files that changed from the base of the PR and between 0192413 and bd07aff.

📒 Files selected for processing (1)
  • .changeset/fix-css-snippet-slot-guidance.md

Walkthrough

The changes extend a styling diagnostics handler to emit warnings about CSS inheritance expectations for slotted elements, add slot styling guidance to CSS snippets with light-DOM selectors, update token customization output with default values, and introduce a helper function to generate placeholder CSS values. Tests validate these features, and a benchmark fixture is refreshed with new timing metrics.

Changes

Cohort / File(s) Summary
Styling Diagnostics Core
packages/core/src/handlers/styling-diagnostics.ts
Added warning pattern for incorrect layout CSS expectations on slotted elements; updated token customization to use default values instead of circular var() references; introduced slot styling section in CSS snippets with light-DOM selectors for default and named slots; added guessDefaultValue() helper to generate placeholder CSS values when CEM defaults unavailable.
Styling Diagnostics Tests
tests/handlers/styling-diagnostics.test.ts
Extended test coverage for font inheritance warnings conditioned on slot presence; added assertions validating non-circular token customization and CEM default value usage; added slot-related snippet section validation for presence/absence based on component slot configuration; refactored property count assertions.
Benchmark Fixture
tests/__fixtures__/benchmark-results/latest-benchmark.json
Updated timestamps and phase duration metrics from a new benchmark run; total time decreased from 2907ms to 2262ms with individual phase timings adjusted accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: fixing a self-referential var() bug in buildCssSnippet and adding slot styling guidance, both of which are primary objectives reflected in the changeset.
Description check ✅ Passed The description covers the key objectives (bug fix, slot styling, font inheritance warning) and test plan comprehensively. However, it lacks the structured template format with explicit sections for Type of change, Related issue, and Checklist items that were specified in the description template.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix-css-snippet-enhance-diagnostics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/src/handlers/styling-diagnostics.ts`:
- Around line 247-250: The generated slot CSS includes an extra space when
slot.description is empty; update the formatting in the loop over namedSlots so
you conditionally render the description and its surrounding spaces rather than
always inserting desc.trim(). Specifically, in the block that builds desc and
calls lines.push (referencing namedSlots, desc, tag, slot.name, and the
lines.push call), change the push so it emits `{ ${slot.description.trim()} }`
only when a non-empty description exists and otherwise emits `{ }` (no double
space).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fbdd8743-8084-484c-8f96-ed9879817082

📥 Commits

Reviewing files that changed from the base of the PR and between 0be3991 and 0192413.

📒 Files selected for processing (3)
  • packages/core/src/handlers/styling-diagnostics.ts
  • tests/__fixtures__/benchmark-results/latest-benchmark.json
  • tests/handlers/styling-diagnostics.test.ts

Comment on lines +247 to +250
for (const slot of namedSlots.slice(0, 3)) {
const desc = slot.description ? ` /* ${slot.description} */` : '';
lines.push(`${tag} [slot="${slot.name}"] { ${desc.trim()} }`);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Minor formatting inconsistency when slot description is empty.

When slot.description is falsy, desc is '' and desc.trim() produces an empty string, resulting in output like my-button [slot="prefix"] { } with a double space before the closing brace. This is purely cosmetic but slightly inconsistent with other generated CSS.

✨ Optional: Clean up empty description handling
     for (const slot of namedSlots.slice(0, 3)) {
       const desc = slot.description ? ` /* ${slot.description} */` : '';
-      lines.push(`${tag} [slot="${slot.name}"] { ${desc.trim()} }`);
+      lines.push(`${tag} [slot="${slot.name}"] {${desc} }`);
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (const slot of namedSlots.slice(0, 3)) {
const desc = slot.description ? ` /* ${slot.description} */` : '';
lines.push(`${tag} [slot="${slot.name}"] { ${desc.trim()} }`);
}
for (const slot of namedSlots.slice(0, 3)) {
const desc = slot.description ? ` /* ${slot.description} */` : '';
lines.push(`${tag} [slot="${slot.name}"] {${desc} }`);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/handlers/styling-diagnostics.ts` around lines 247 - 250,
The generated slot CSS includes an extra space when slot.description is empty;
update the formatting in the loop over namedSlots so you conditionally render
the description and its surrounding spaces rather than always inserting
desc.trim(). Specifically, in the block that builds desc and calls lines.push
(referencing namedSlots, desc, tag, slot.name, and the lines.push call), change
the push so it emits `{ ${slot.description.trim()} }` only when a non-empty
description exists and otherwise emits `{ }` (no double space).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@himerus himerus merged commit 20b3001 into dev Mar 21, 2026
8 of 10 checks passed
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