Usage of cartCount causes an SSR mismatch error in Next.js
See original GitHub issueI’m not sure why this is happening:
cartCount
renders correctly in the <p>
tag but for setting the disabled value on the button it doesn’t: https://github.com/thorsten-stripe/next.js/blob/thor/stripe/add-use-shopping-cart-example/examples/with-stripe-typescript/components/CartSummary.tsx#L45
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (3 by maintainers)
Top Results From Across the Web
react-hydration-error - Next.js
When css-in-js libraries are not set up for pre-rendering (SSR/SSG) it will often lead to a hydration mismatch. In general this means the...
Read more >SSR mismatch adventures in Next.js | by Mark Miro - Medium
My simple page had hydration errors. At first, it looked to me that the mismatch issue was entirely because of SWC. After all,...
Read more >Handling the React server hydration mismatch error
How to resolve the server mismatch error when hydrating a shared React component that can be used in client-side only or server-side rendered ......
Read more >Next.JS - Error when Checking if window == undefined ...
The point of SSR is to prerender the page on the server. If on the server your page renders always null there's no...
Read more >How to Fix "window is not defined" in Next.js - Upmostly
This issue has to do with Server-Side Rendering in Next.js. Next.js will by default try to use SSR for your site.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ChrisBrownie55 Yes, I believe that is the only way to avoid this discrepancy, however it’s not great, because you have an initial render with the default state and then an immediate re-render with the localStorage state, which can result in a flicker when the page loads.
One potential solution would be to initially return null until we had the chance to check the localStorage, that way you can employ conditional rendering to avoid the “flicker”, but none of this feels great for non-SSR applications 😦
Don’t think this is an issue anymore, let me know if I’m wrong tho