cssinjs / cssinjs/jss

JSS Dynamic Rules are not removed on re-render V10.0.9

Open
#1,616 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.1k
Forks
386
PR merge metrics
No merged PRs in 30d

Description

__Expected behavior:__
Once new css rules are added older css rules should be deleted from DOM

__Describe the bug:__
When i use dynamic selectors in dynamic styles, the new rules are added while the older ones are not removed from DOM resulting in elements having style while the current state doesn't require them to have this style.
Noticed it used to work in JSS v9.07 and stopped working from V10.0.0+

__Reproduction:__
open the codesandbox bellow and:

1. click on a box to select it and make it change the color to red using the dynamic selector
2. click again and notice the older dynamic selector is still in the DOM resulting the button to become red

**Codesandbox link:**
https://codesandbox.io/s/react-jss-playground-forked-o7fmy1

**further explanation:**
i know the example i give doesn't look like the common use case, sure you can apply a class for selected items, but in my project i really heavily on SVGs in a way which i would want to manipulate some inner paths to paint in different colors or locations based on state, for that reason i needed to have dynamic selectors to be able to color inner paths in the svg component, i did found a work-around by adding a unique class name to the svg container in each render, and applying new css rules on a `&.timespamp svg[id=${id}]` selector. but i do experience some animalities when for some millseconds the newer style wasn't yet rendered on DOM but the class name timestamp already changed and the entire component entirely loses its style for a brief moment

__Versions (please complete the following information):__
- jss:10.0.9

**Screenshots:**
![image](https://user-images.githubusercontent.com/8542480/169823470-2a31fa97-812b-4af5-a385-bb6c3cdc1ba9.png)
![image](https://user-images.githubusercontent.com/8542480/169823599-c7845322-d58f-4409-bfe3-126873337349.png)

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the linked CodeSandbox with JSS 10.0.9, then inspect the DOM after each dynamic-selector re-render and compare the behavior with JSS 9.0.7. Done means obsolete dynamic CSS rules are removed after re-render without the component temporarily losing its style.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.