[V2] :global doesn't rerender. :global stay on the page when component is unmounted
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (15 by maintainers)
Top Results From Across the Web
How to keep React component state between mount/unmount?
1) The most obvious place to save the state is within the parent component. · 2) You can save the state elsewhere, like...
Read more >Global state management in React with global variables and ...
Global states are used when components need to share states. React provides a very good and simple way to manage local state(React hooks) ......
Read more >Avoid React state update warnings on unmounted components
React raising a warning when you try to perform a state update on an unmounted component. React setState is used to update the...
Read more >How to work with React the right way to avoid some common ...
To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
Read more >React.Component
By default, when your component's state or props change, your component will re-render. If your render() method depends on some other data, you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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
@mxstbr included in v2.0.0
Yeah if we can remove
:global
,@global
and:host
and let people use&
andinjectGlobal
that would be great, thanks @thysultan!