Fix hydration mismatch in markup in useReducedMotion hook#1263
Fix hydration mismatch in markup in useReducedMotion hook#1263
Conversation
🦋 Changeset detectedLatest commit: c34e63c The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🟢 No design token changes found |
There was a problem hiding this comment.
Pull request overview
This PR fixes a hydration mismatch issue in the useReducedMotion hook by changing the initial state from a lazy initializer that checks window.matchMedia to a simple false value. The fix ensures consistent rendering between server and client on initial mount, with the correct value being set in a useEffect after hydration.
Changes:
- Modified
useReducedMotionhook to initialize withfalseinstead of checking media query during initialization - Added changeset documenting the SSR hydration fix for Hero, LogoSuite, and TextCursorAnimation components
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react/src/hooks/useReducedMotion.ts | Changed useState initialization from lazy initializer checking window.matchMedia to simple false value |
| .changeset/fuzzy-spiders-chew.md | Added patch-level changeset documenting the hydration fix |
🟢 No unit test coverage changes foundAll components and hooks with tests maintain the same coverage as the main branch. |
🟢 No visual differences foundOur visual comparison tests did not find any differences in the UI. |
|
Going to close this for now as this doesn't seem to be root cause for the hydration issue in dotcom |
Summary
Fixes a hydration mismatch in components that use the
useReducedMotionhook.Before: initial mount value can be different between client and server
After: initial mount value is the same (false) and set correctly in the client in subsequent render (SSR-safe)
This makes the components SSR-safe, but could also lead to flash of animation issues but we can mitigate that in CSS.
List of notable changes:
What should reviewers focus on?
Steps to test:
Supporting resources (related issues, external links, etc):
Contributor checklist:
update snapshotslabel to the PR)Reviewer checklist:
Screenshots: