Skip to content

fix: css specificity bug is fixed with @layer wrapper#65

Open
atakanbayrak wants to merge 19 commits into
mainfrom
fix/css_specificity_layers_fix
Open

fix: css specificity bug is fixed with @layer wrapper#65
atakanbayrak wants to merge 19 commits into
mainfrom
fix/css_specificity_layers_fix

Conversation

@atakanbayrak
Copy link
Copy Markdown
Contributor

Description

When consumers install this library and try to override component styles, they are forced to use !important on every declaration. This happens because our component styles (injected via rollup-plugin-styler at runtime) load after the consuming app's styles in an unpredictable order, and since both sides write plain CSS with no explicit priority rules, the last one loaded wins. There is no reliable way for consumers to win this specificity battle without !important.

Solution:

We wrap all component styles in a single named CSS @layer called motif-ui directly in the SCSS source files. Each component's selectors are placed inside @layer motif-ui { }, while SCSS compile-time declarations (@use, @forward, $variables, @mixin, @function) remain outside the layer block as required by the SCSS spec.

Type of Change

  • 🆕 New Component
  • ✨ Feature / Enhancement
  • 🐛 Bug Fix
  • 💥 Breaking Change
  • 📦 Build / Dependency / Docs Update
  • 🧹 Code Refactoring

Screenshots / Preview

Before:

.mtf-Badge { padding: 8px !important; }

After:

.mtf-Badge { padding: 8px }

Checklist

  • Self-reviewed, no leftover logs or debug code
  • Uses design tokens — no hardcoded style values
  • Accessible (keyboard nav, ARIA, contrast)
  • Tests added/updated and passing
  • Storybook story added/updated

How to Test

Tests are completed with @sengulnecmi inside real project. There was no error, complex components are also tested with different css styles. No need for !important after all.

#EDKUI-1363

.motifIconsDefault {
font-family: motif-icons-default, serif !important;
speak: none;
speak: never;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would like to know that this refactor is legit ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it is legit. none is replaced with never

Comment thread rollup.config.mjs Outdated
commonjs(),
json(),
styles({
//mode: ["extract", "dist/bundle.css"], //TODO: Lets keep it like this unless there is problem.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will fix this with incoming commit. I am waiting review to fix it for avoiding commit garbage.

@aktasmehmet aktasmehmet deployed to development May 22, 2026 13:30 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants