Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MediaQueryProvider] Fix SSR hydration issues #12824

Merged
merged 2 commits into from
Oct 29, 2024
Merged

Conversation

moraleslevi
Copy link
Contributor

@moraleslevi moraleslevi commented Oct 24, 2024

WHY are these changes introduced?

Fixes #11886

Server-side rendering defaults to isNavigationCollapsed being false, which causes a React hydration issue when rendered on the client at smaller breakpoints (where the value evaluates as true).

WHAT is this pull request doing?

This modifies the initial render state of isNavigationCollapsed to match the server-side rendered value (false) and relies on the existing useEffect to update the value on the client-side after hydration.

Before change - React hydration errors at small breakpoints
ssr-before.mp4
After change - No React hydration errors at small breakpoints
ssr-after.mp4

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

🎩 checklist

@moraleslevi moraleslevi force-pushed the moraleslevi/fix-ssr branch 3 times, most recently from f7ed2f3 to fdce8e8 Compare October 25, 2024 16:27
@moraleslevi moraleslevi marked this pull request as ready for review October 25, 2024 16:39
@moraleslevi
Copy link
Contributor Author

I think there is an unrelated issue with Next.js + Node v23.1.0 causing the CI failures (vercel/next.js#47394 (comment)).

@moraleslevi moraleslevi requested a review from a team October 25, 2024 16:41
Copy link
Member

@kyledurand kyledurand left a comment

Choose a reason for hiding this comment

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

This makes sense to me

@moraleslevi moraleslevi requested a review from shopeter October 25, 2024 17:57
Copy link

@shopeter shopeter left a comment

Choose a reason for hiding this comment

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

🎩 'd & lgtm

@moraleslevi moraleslevi merged commit 85c5bb7 into main Oct 29, 2024
12 of 13 checks passed
@moraleslevi moraleslevi deleted the moraleslevi/fix-ssr branch October 29, 2024 15:56
moraleslevi pushed a commit that referenced this pull request Oct 31, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/[email protected]

### Patch Changes

- [#12824](#12824)
[`85c5bb7b4`](85c5bb7)
Thanks [@moraleslevi](https://github.com/moraleslevi)! - Fix hydration
issues with SSR

## [email protected]

### Minor Changes

- [#12662](#12662)
[`5bb85b547`](5bb85b5)
Thanks [@heyjoethomas](https://github.com/heyjoethomas)! - Removes
unnecessary new badges from navigation

### Patch Changes

- [#12739](#12739)
[`af15611a6`](af15611)
Thanks [@sarahill](https://github.com/sarahill)! - Updated common action
guidelines


- [#12806](#12806)
[`57e6cbe71`](57e6cbe)
Thanks [@IlanaB](https://github.com/IlanaB)! - Fixed a typo in the
common actions overview

- Updated dependencies
\[[`85c5bb7b4`](85c5bb7)]:
    -   @shopify/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

Page component with a title causes a hydration mismatch on small breakpoints
3 participants