Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[React] CSS specificity issue: extend imported component #1378

Closed
PierreGUI opened this issue Oct 26, 2023 · 4 comments
Closed

[React] CSS specificity issue: extend imported component #1378

PierreGUI opened this issue Oct 26, 2023 · 4 comments
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@PierreGUI
Copy link

PierreGUI commented Oct 26, 2023

Environment

Linaria version: 5.0.3
Bundler: Webpack 5

Description

When extending a component with styled function (const B = styled(A)``;) I expect the resulting component's CSS to have higher specificity.
When the components are declared in the same file, Linaria seems to append the parent's classname to the child's (.B.A -> increased specificity) ✅
When the component to extend from is imported, Linaria doesn't append its classname. The new component's specificity is the same as its parent component ❌

This result is mismatching style when a child component inherits from a complex parent component, defined in another file:
image

In this example the classname for Red is .Red_rhnsy8v which has lower specificity than .Blue_b7lcn1q.Base_b15uhwgc, therefore the text isn't red but blue.
It should be .Red_rhnsy8v.Blue_b7lcn1q.Base_b15uhwgc in order to override its parent's style correctly.

See the reproduction demo for source code.

Reproducible Demo

https://stackblitz.com/edit/linaria-bug-kahsvz?file=src%2FTitle.tsx

@PierreGUI PierreGUI added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Oct 26, 2023
@github-actions github-actions bot added bundler: webpack 📦 Issue is related to webpack bundler and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Oct 26, 2023
@PierreGUI
Copy link
Author

PierreGUI commented Dec 8, 2023

@Anber nice release yesterday 👌 I like the way this project is going.
Would you mind having a look at this issue, please? I believe it is rather serious one because it can break styles on production in an unpredictable way (since this is "just" CSS specificity).

The only workaround I could find is to find those style overrides manually and artificially increase specificity (&& { /* css */ }).

Thanks

@Anber
Copy link
Collaborator

Anber commented Dec 8, 2023

Hi @PierreGUI

Unfortunately, I haven't had enough time for the last two months. And I will be completely offline for the next two and a half weeks. I will take a look as soon as I return.

@PierreGUI
Copy link
Author

Hey @Anber , friendly reminder of this troubling issue. Any chance you'll have a look at it soonish?
I'm currently not confident writing styles when extending components from my design system.
Thanks 🙏

@Anber
Copy link
Collaborator

Anber commented Apr 25, 2024

Hi @PierreGUI

Sorry for such a late response. It appeared that styled couldn't resolve imported components, so they were ignored. Hopefully, this has been fixed in #1405. I will test it a bit more and release it later today or tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

No branches or pull requests

2 participants