What happened?
Hi! I noticed a performance issue when updating ScopedVariables on web with multiple components using useCSSVariable.
I reproduced this with 100 components in the linked demo.
What’s causing it
In getWebStyles.ts, each read applies all scoped variables to a shared measurement element and removes them afterward. Consecutive reads with the same scope repeat those mutations, triggering unnecessary style recalculations.
Local fix and results
I changed this to update only values that differ and remove variables missing from the next scope, including when returning to an unscoped context.
In my app, style recalculations dropped from around **867 to 25 per update ( approximately 97% fewer ), with noticeably better responsiveness.
I’d be glad to put together a PR if this approach makes sense. Thanks!
Steps to Reproduce
- Clone the reproduction repository:
git clone https://github.com/eserdeiro/uniwind-web-demo.git
cd uniwind-web-demo
- Install dependencies and start the web app:
- Open the app in your browser and move the Letter spacing slider continuously.
- Record the interaction in the browser’s Performance panel and inspect the repeated Recalculate Style events. The visible slowdown will vary depending on your hardware.
Snack or Repository Link
https://github.com/eserdeiro/uniwind-web-demo
Uniwind version
1.12.0
React Native Version
0.86.0
Platforms
Web
Expo
Yes
Additional information 〰
What happened?
Hi! I noticed a performance issue when updating
ScopedVariableson web with multiple components usinguseCSSVariable.I reproduced this with 100 components in the linked demo.
What’s causing it
In
getWebStyles.ts, each read applies all scoped variables to a shared measurement element and removes them afterward. Consecutive reads with the same scope repeat those mutations, triggering unnecessary style recalculations.Local fix and results
I changed this to update only values that differ and remove variables missing from the next scope, including when returning to an unscoped context.
In my app, style recalculations dropped from around **867 to 25 per update ( approximately 97% fewer ), with noticeably better responsiveness.
I’d be glad to put together a PR if this approach makes sense. Thanks!
Steps to Reproduce
git clone https://github.com/eserdeiro/uniwind-web-demo.git cd uniwind-web-demoSnack or Repository Link
https://github.com/eserdeiro/uniwind-web-demo
Uniwind version
1.12.0
React Native Version
0.86.0
Platforms
Web
Expo
Yes
Additional information 〰