Skip to content

fix: use centralized cache for usePrefersReducedMotion hook#468

Open
mdjastrzebski wants to merge 2 commits intofacebook:mainfrom
mdjastrzebski:fix/prefers-reduce-motion-cache
Open

fix: use centralized cache for usePrefersReducedMotion hook#468
mdjastrzebski wants to merge 2 commits intofacebook:mainfrom
mdjastrzebski:fix/prefers-reduce-motion-cache

Conversation

@mdjastrzebski
Copy link
Copy Markdown

@mdjastrzebski mdjastrzebski commented Apr 1, 2026

Fix a performance issue in RN, when each RSD component (div, span, button, etc) calls AcessibilityInfo.isReduceMotionEnabled on mount due to usePrefersReduceMotion hook called from styles calculation.
This is especially visible on Android, where a single call is relatively cheap (0,1-0,3 ms), but with larger (e.g. 1000) number of components, this operation alone could take ~300ms in our app during screen load.

CleanShot 2026-04-01 at 10 19 21@2x

The fix is to keep a reactive JS cache for this value, so that only single AcessibilityInfo.isReduceMotionEnabled is ever made, all other components would use the cached value. The cache itself subscribes to reduceMotionChanged event, hence the value stays up to date.

Additionally, having up-to-date value, prevents effect triggered re-renders when default value would switch to true.

@meta-cla meta-cla bot added the cla signed label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant