question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[V2] :global doesn't rerender. :global stay on the page when component is unmounted

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
thysultancommented, Apr 1, 2017

@mxstbr included in v2.0.0

1reaction
geelencommented, Mar 27, 2017

Yeah if we can remove :global, @global and :host and let people use & and injectGlobal that would be great, thanks @thysultan!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found