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: cleanup ssr markup mismatch errors #26
Conversation
@tmm Do ya'll have any advice for wagmi localStorage caching + Next.js server side rendering having incompatible content during hydration? Feels weird bypassing server rendering but not sure the implication of these sorts of rehydration errors. Is this the right approach? |
@holic I dug into this some more and found a previous convo in the wagmi repo here: wevm/wagmi#542 (comment) I've updated this branch to use a similar pattern of a reusable |
packages/app/src/pages/index.tsx
Outdated
{totalSupply.data?.toNumber().toLocaleString() ?? "??"}/ | ||
{maxSupply.data?.toNumber().toLocaleString() ?? "??"} minted | ||
</p> | ||
{isMounted && ( |
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.
Small nit: I tend to prefer full ternaries like {condition ? (<>render</>) : null}
as it avoids the edge case where your condition might not be a boolean and will unintentionally render the condition value itself.
Not sure if there is a linter for this kind of thing. I feel like I wrote one for this pattern at Stripe but I don't have the code anymore.
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.
@holic Cool, I hadn't thought about this much before but I agree. I wasn't able to find an existing rule for this, although there is one proposed here that we might be able to use: jsx-eslint/eslint-plugin-react#2888
I made #29 so we can track this in backlog
Currently some markup depends on client-side requests (or local storage caches). This can cause mismatch errors with Next.js server-side rendering. One way we can minimize these errors is wrapping into an
isLoaded
conditional withuseEffect
.Example error: