Dynamic styles doesn't work after mounting/unmounting component
Expected behavior: Dynamic styles are changing on the fly.
Describe the bug: Dynamic styles are static.
Codesandbox link: https://codesandbox.io/embed/magical-turing-w5oov
Versions (please complete the following information):
- jss: 10.0.0-alpha.23
- Browser [e.g. chrome, safari]: Chrome
- OS [e.g. Windows, macOS]: MacOS
Codesandbox STR:
- Click "Toggle bound" button.
- Click few times on the blue box (AR: bound is in sync with box).
- Click "Toggle bound" button twice.
- Click on the blue box few times (AR: bound is not in sync with box, ER: bound is in sync with box).
Seems to me that the old styles are not removed. I will investigate it in the weekend
Any update on this? @HenriBeck
No, I didn't found time last week for jss. I have blocked some time this weekend, and this is on the top of my priority list.
Sorry for the late reply. I finally found what is causing this, but I haven't found a way of fixing this sadly
@kof This happens because of unmanaging the sheet. We are correctly removing it as far as I can see. If I remove the unmanaging of the sheet, the bug doesn't happen anymore.
So they stop working after we remove the style tag from the dom and then we insert it again, right?
Some background info:
When insertRule api is used created rules are not persistent, they are removed when style tag is removed, so we insert them all again when we insert the style tag back. I think somewhere on the way of reinserting something goes wrong and we loose the ability to update them.
No, it's like the sheet contains removed rules when we detach and attach it again. So the sheet is one update cycle behind for some reason.
But I also wasn't able to recreate this issue in a test yet.
@kof I would for now disable the unmounting of the sheet. This shouldn't be too big of an issue performance-wise I think.
@HenriBeck you're right, I should have found this issue! It is exactly the same as #1187.
@VintorezVS I've forked your sandbox https://codesandbox.io/s/serene-silence-fbbdd and hacked in the same fix I came up with in #1190 - and it solves the issue in your sandbox too.
I'm now using the build from #1190 now in my current project (which is a fairly big codebase) and I haven't noticed any other side effects yet, and it has solved the problem everywhere I was experiencing it.
should be fixed in in 10.0.0-alpha.25 please verify and reopen if it isn't