cssinjs / jss

JSS is an authoring tool for CSS which uses JavaScript as a host language.
https://cssinjs.org
MIT License
7.08k stars 399 forks source link

Keep classes ref when sheet and dynamicRules have not any change #1573

Closed behnammodi closed 3 years ago

behnammodi commented 3 years ago

What Would You Like to Add/Fix?

getSheetClasses always return new object even sheet and dynamicRules haven't any change

Also I wrote a small test to keep it in future

Todo

Expectations on Changes

So, I memoized it to prevent this behavior

Changelog

Improve performance at useStyle

behnammodi commented 3 years ago

@kof Thanks for review, all of them is done

behnammodi commented 3 years ago

@kof This is ready to merge

kof commented 3 years ago

@behnammodi thanks, will look into it, in the meantime, please test it in your app in production and let me know if you notice anything

behnammodi commented 3 years ago

@behnammodi thanks, will look into it, in the meantime, please test it in your app in production and let me know if you notice anything

Sure, I'll tell you

behnammodi commented 3 years ago

@kof I build react-jss then I created a pack and install on our project everything works very well

behnammodi commented 3 years ago

@kof I found a better solution, please see this file packages/react-jss/src/createUseStyles.js changes

behnammodi commented 3 years ago

@kof This PR ready to merge and main change is:

-    const classes = sheet && dynamicRules ? getSheetClasses(sheet, dynamicRules) : emptyObject
+    const classes = React.useMemo(
+      () => (sheet && dynamicRules ? getSheetClasses(sheet, dynamicRules) : emptyObject),
+      [sheet, dynamicRules]
+    )

not anymore

kof commented 3 years ago

looks great now, thank you

kof commented 2 years ago

released in v10.9.0