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

themed useCreateStyles leaks style tags in StrictMode #1332

Open
eps1lon opened this issue Apr 20, 2020 · 1 comment
Open

themed useCreateStyles leaks style tags in StrictMode #1332

eps1lon opened this issue Apr 20, 2020 · 1 comment
Labels
bug It went crazy and killed everyone. help wanted

Comments

@eps1lon
Copy link
Member

eps1lon commented Apr 20, 2020

Expected behavior:
<style> elements get disposed when re-rendering in StrictMode.

Describe the bug:
When using themed styles (possibly prop-based as well) re-rendering a component using useStyles with a new theme will leak their <style> elements.

This is possibly due to useStyles managing the sheet during render but unmanaging it in a effect cleanup. A component can render multiple times (in concurrent and strict mode) before an effect is scheduled.

Codesandbox link:
https://codesandbox.io/s/determined-wood-8d0s7?file=/src/App.js:513-622

Click "rerender" and see that the number of <style> element grows with every "rerender" click.

Versions (please complete the following information):

  • react-jss: 10.1.1
  • Browser [e.g. chrome, safari]: Chrome 81
  • OS [e.g. Windows, macOS]: Ubuntu 18.04
  • react: 16.13.1
@half-halt
Copy link

half-halt commented Jul 29, 2020

I have the same problem, in my case, I have two themes, you can toggle once, then you can't toggle again and whichever on is the second theme lives forever.

I have changed createUseStyles to avoid both the problem mentioned above @eps1lon and also the problem I was having (which is kind of related by not really. Since affects the timing, I need to update a couple of tests, but if anyone wants try the change, I can provide it while I work on the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It went crazy and killed everyone. help wanted
Projects
None yet
Development

No branches or pull requests

3 participants