Order of CSS injection
See original GitHub issueJust hit a problem:
const SVG = styled.svg`
line {
stroke-width: 1px;
}
`
const Horizontal = styled.g`
line {
shape-rendering:crispEdges;
}
`
const Vertical = styled.g`
line {
stroke-width: 1.5px;
}
`
export default () => (
<SVG>
<Horizontal>
<line x1={0} y1={0} x2={width} y2={0}/>
</Horizontal>
<Vertical>
<line x1={0} y1={0} x2={width} y2={height}/>
</Vertical>
</SVG>
)
Because Horizontal
and Vertical
get rendered before SVG
, and I’m only injecting the styles on render, ._compile_from_Vertical line {}
appears before ._compiled_from_SVG line {}
. They have the same specificity of course and so SVG
wins.
Injected source should be in the same order it is written, not in the order it’s rendered.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (13 by maintainers)
Top Results From Across the Web
material ui - How to specify the order in which the style sheets ...
The CSS injected by Material-UI to style a component has the highest specificity possible as the <link> is injected at the bottom of...
Read more >Style library interoperability - Material UI - MUI
CSS injection order ⚠️. Note: Most CSS-in-JS solutions inject their styles at the bottom of the HTML <head> , which gives MUI precedence...
Read more >Material UI v5 CSS injection order - CodeSandbox
TemplateMaterial UI v5 CSS injection order (theme); Environmentcreate-react-app. Files. App.js. ButtonBox.js. index.html. index.js. package.json.
Read more >Testing for CSS Injection - WSTG - v4.1 | OWASP Foundation
Summary. A CSS Injection vulnerability involves the ability to inject arbitrary CSS code in the context of a trusted web site which is...
Read more >CSS injection (stored) - PortSwigger
CSS injection vulnerabilities arise when an application imports a style sheet from a user-supplied URL, or embeds user input in CSS blocks without...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Woo, found a manual escape hatch:
This generates
.xxx.xxx line
which lifts its specificity above.yyy line
(fromSVG
above), so tbh I think this is “good enough” to consider this option closed.In fact you can actually use
&& { some: thing; }
to target the element itself (not just descendants). In case you have some greedy rules outside (likehtml p
) which would override astyled.p
with a single class name. This is great, since we don’t have to design good JS to cover bad CSS, we can just give folks a way to generate even worse CSS 👍So this didn’t stay solved for long. I found that server-side rendering wasn’t firing the
componentDidMount
, so we can’t use that to inject.