jss icon indicating copy to clipboard operation
jss copied to clipboard

Dynamic styles doesn't work after mounting/unmounting component

Open VintorezVS opened this issue 7 years ago • 9 comments

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:

  1. Click "Toggle bound" button.
  2. Click few times on the blue box (AR: bound is in sync with box).
  3. Click "Toggle bound" button twice.
  4. Click on the blue box few times (AR: bound is not in sync with box, ER: bound is in sync with box).

VintorezVS avatar Jul 24 '19 08:07 VintorezVS

Seems to me that the old styles are not removed. I will investigate it in the weekend

HenriBeck avatar Jul 24 '19 08:07 HenriBeck

Any update on this? @HenriBeck

Jdyn avatar Jul 31 '19 03:07 Jdyn

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.

HenriBeck avatar Aug 02 '19 07:08 HenriBeck

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.

HenriBeck avatar Aug 18 '19 10:08 HenriBeck

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.

kof avatar Aug 18 '19 10:08 kof

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.

HenriBeck avatar Aug 18 '19 12:08 HenriBeck

@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 avatar Sep 01 '19 15:09 HenriBeck

@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.

felthy avatar Sep 11 '19 23:09 felthy

should be fixed in in 10.0.0-alpha.25 please verify and reopen if it isn't

kof avatar Sep 16 '19 10:09 kof