styled-components: [V2] :global doesn't rerender. :global stay on the page when component is unmounted
I have found a bug in 2.0.0-9 using global injection.
When I use :global within a component for example :
styled.div`
:global(body) {
${props.isOpen ? `margin-right: ${props.size}px !important;` : ''}
}
${!props.isOpen ? `transform: translate3d(${props.size-10}px, 0, 0);` : ''}
`
Version
2.0.0-8
Reproduction
Unfortunately it’s hard to produce a reproduction, webpackbin work bad these days. I don’t know how to use styled template literal in codepen.
Steps to reproduce
Using react-router, create a router that container a css injection that use :global. Go on that page, then change to another page, the css stay injected
Expected Behavior
- When the component is rerendered with a new
props.size:global should apply the new css - if the components get umounted, the style injected in body are removed from on the page.
Actual Behavior
- When the component is rerendered with a new
props.size:global doesn’t refresh the css - if the components get umounted, the style injected in body stay on the page.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (15 by maintainers)
@mxstbr included in v2.0.0
Yeah if we can remove
:global,@globaland:hostand let people use&andinjectGlobalthat would be great, thanks @thysultan!Yes it does disable mixins and variables, planning on a release that removes them, since you could use middleware to re-construct them,
:globalselector is not, will improve the compact option to include it with that release.@mxstbr can you weigh in here? I thought we weren’t adding any of these?
For the record, I’m extremely against any CSS metaprogramming in Styled Components without very careful consideration. At the moment, the only two things we allow are nesting (
&) and autoprefixing. So just because Stylis or PostCSS supports something, doesn’t mean we will expose it. You have all of JS to build mixins, andinjectGlobalfor global rules, anything that diverges from our simplified superset of raw CSS makes it vastly more difficult to build tooling like @philpl’s preprocessor in the future.Um… what is
:global? That’s not a thing in Styled Components (unless someone merged something without me noticing…)