Skip to content

Hydration Mismatch with makePersisted and sessionStorage #737

Answered by atk
jcalfee asked this question in Q&A
Discussion options

You must be logged in to vote

I' am afraid this is failure by design. The hydration expects the same element to render on the server and the client, but the client has the users from session storage faster than the server, which leads to a mismatch. Our primitive behaves exactly as specified, but that becomes an issue with hydration.

How to solve this? In theory, you could block the rendering until hydration is done. Let me think about how to do this. As a workaround, you could use a memo to return an empty array until hydration. We have a nifty little lifecycle primitive you might find helpful. I might add an option where you can add an accessor that will let us block updates until truthy.

Update: I added the option.…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jcalfee
Comment options

@atk
Comment options

atk Jan 16, 2025
Maintainer

Answer selected by atk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants