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
fix: first render consistency of useBreakpointValue in SSR+CSR envs #5651
Conversation
🦋 Changeset detectedLatest commit: 7200e52 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/chakra-ui/chakra-ui-storybook/GmkXx6Vj4jdNZe1MWu7LPPLbxhgn |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 23c8246:
|
@@ -19,7 +19,7 @@ import { useBreakpoint } from "./use-breakpoint" | |||
*/ | |||
export function useBreakpointValue<T = any>( | |||
values: Partial<Record<string, T>> | T[], | |||
defaultBreakpoint?: string, | |||
defaultBreakpoint = "base", // default value ensures SSR+CSR consistency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If defaultBreakpoint
is set by default, layout flashing will probably occur even in a Vanilla environment.
Although rendering mismatch may be more serious than layout flashing...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to have a global defaultBreakPoint
setting for users who use SSR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly! We need to support SSR. And this is by my knowledge only possible with a rerender on the client.
It's a great idea to configure this via the theme. I think it's best to do this iterative.
- fix the bug
- add the theme config in another PR
LGTM. Fixes issues with Next.js |
Closes #5506
Based on PR #5638 💖 thanks to @ishowta
📝 Description
Ensure first render consistency in SSR+CSR environments.
⛳️ Current behavior (updates)
The PR #5234 introduced the side effect of mismatching SSR+CSR renders.
This was not fixed by my previous PR #5576.
🚀 New behavior
To ensure the render consistency on the server and client I reordered the priority of the parameter
defaultBreakpoint
foruseBreakpoint
.If a
defaultValue
is set, it has priority overwindow.matchMedia
.The hook
useBreakpointValue
uses now a default value fordefaultBreakpoint
(base
) to make use of this priority change.💣 Is this a breaking change (Yes/No):
No