Skip to content

Fix hydration mismatch in markup in useReducedMotion hook#1263

Closed
rezrah wants to merge 1 commit intomainfrom
rezrah/fix-ssr-mismatch-use-reduced-motion
Closed

Fix hydration mismatch in markup in useReducedMotion hook#1263
rezrah wants to merge 1 commit intomainfrom
rezrah/fix-ssr-mismatch-use-reduced-motion

Conversation

@rezrah
Copy link
Collaborator

@rezrah rezrah commented Feb 23, 2026

Summary

Fixes a hydration mismatch in components that use the useReducedMotion hook.

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:

  • Change initial state value for useReducedMotion to false instead of setting it through the initializer function

What should reviewers focus on?

Steps to test:

Supporting resources (related issues, external links, etc):

Contributor checklist:

  • All new and existing CI checks pass
  • Tests prove that the feature works and covers both happy and unhappy paths
  • Any drop in coverage, breaking changes or regressions have been documented above
  • UI Changes contain new visual snapshots (generated by adding update snapshots label to the PR)
  • All developer debugging and non-functional logging has been removed
  • Related issues have been referenced in the PR description

Reviewer checklist:

  • Check that pull request and proposed changes adhere to our contribution guidelines and code of conduct
  • Check that tests prove the feature works and covers both happy and unhappy paths
  • Check that there aren't other open Pull Requests for the same update/change

Screenshots:

Please try to provide before and after screenshots or videos

Before After

@rezrah rezrah requested a review from danielguillan February 23, 2026 11:30
@rezrah rezrah requested a review from a team as a code owner February 23, 2026 11:30
Copilot AI review requested due to automatic review settings February 23, 2026 11:30
@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

🦋 Changeset detected

Latest commit: c34e63c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@primer/react-brand Patch
@primer/brand-docs Patch
@primer/brand-css Patch
@primer/brand-primitives Patch
@primer/brand-e2e Patch
@primer/brand-fonts Patch
@primer/brand-config Patch
@primer/brand-storybook Patch

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

@github-actions
Copy link
Contributor

🟢 No design token changes found

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 useReducedMotion hook to initialize with false instead 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

@github-actions
Copy link
Contributor

🟢 No unit test coverage changes found

All components and hooks with tests maintain the same coverage as the main branch.

@github-actions
Copy link
Contributor

🟢 No visual differences found

Our visual comparison tests did not find any differences in the UI.

@rezrah rezrah marked this pull request as draft February 23, 2026 12:53
@rezrah
Copy link
Collaborator Author

rezrah commented Feb 23, 2026

Going to close this for now as this doesn't seem to be root cause for the hydration issue in dotcom

@rezrah rezrah closed this Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants