fix(components): add css output validation #3111
Open
+306
−2
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.
📝 Summary of CSS Issues & Recommendations
🚨 What Happened
csso
to Lightning CSS, builds started failing.::file-selector-button::before
).🔍 Root Cause
hds-button-state-disabled()
mixin includes:&::file-selector-button
block, it compiles to::file-selector-button::before
.⚡ Impact
border-color: transparent
never hits).✅ Recommendations
1. Fix the mixin
Option A: Add a flag to disable pseudo-element emission.
Use with
$include-before: false
for::file-selector-button
.Option B: Split into two mixins (
*-base
and*-decorators
) and include only what’s valid in each context.2. Add validation in the build pipeline
Since the library uses
rollup-plugin-scss
, add strict CSS validation before publishing:Lightning CSS parse check
After SCSS compiles, run:
This fails fast if invalid CSS is generated.
Stylelint rule for chained pseudo-elements
Custom rule: flag any
::<something>::<something>
in selectors.Catches misuse at the SCSS source before it compiles.
3. CI integration
📌 Takeaway
🤔 Why
clean-css
andcsso
didn’t fail (but Lightning CSS does)Older/legacy-focused minifiers like clean-css (and historically csso) primarily optimize for byte reduction and throughput, not strict standards enforcement. In practice this means:
By contrast, Lightning CSS is designed for spec compliance and safe transforms (e.g., prefixing, modern syntax → widely supported output). To guarantee correctness it must trust the AST, so it throws on invalid CSS, like a chained pseudo-element selector (
::file-selector-button::before
).Quick comparison
errorRecovery: true
)Implication for us: With Lightning CSS (and generally modern pipelines), invalid CSS should be fixed at the source. If we relied on lenient tools before, they may have masked issues that were already ineffective in browsers.
📸 Screenshots
🔗 External links
Jira ticket: HDS-XXX
Figma file: [if it applies]
👀 Component checklist
💬 Please consider using conventional comments when reviewing this PR.
📋 PCI review checklist
Examples of changes to controls include access controls, encryption, logging, etc.
Examples include changes to operating systems, ports, protocols, services, cryptography-related components, PII processing code, etc.