createAsync different values on client and server SSR issue
I'm trying to conditionally render components based on auth - think paywalled content.
I have a server function that detects if user has logged in:
However, createAsync returns undefined leading nothing to be rendered on the server:
Server:
Client returns the expected value:
10 Replies
Is there a way to ensure the same value on the server and client?
Or should I tackle the paywall problem in a different way?
Hmm maybe I need to wrap the component with
<Suspense>
?
Seems to solve the issue if the value is true
, but not when it's false
It’ll always start as undefined on the server, since that console log runs before the server function completes
The client will always receive the actual value since you’ve got deferStream
The issue is this leads to
Error: Hydration Mismatch
It seems that SSR is using the undefined
value to render instead of the actual intended value?
Here is the JSX:
Where are
c
and dc
from?They are both child components
Not sure if it matters but
children
will evaulate the children before rendering the rest of your component, i don't think you need it in this caseYeah, I think that was the cause.
How did this solve the problem?
Can't say for sure but there was probably a mismatch in which elements were being included in the page
children
and createMemo
is quite known for producing hydration mismatches, but mainly children
I found a GitHub issue detailing the children hydration mismatch: https://github.com/solidjs/solid-start/issues/1392
GitHub
[Bug?]: Hydration Mismatch when using
children
· Issue #1392 · so...Duplicates I have searched the existing issues Latest version I have tested the latest version Current behavior 😯 Hello, I am getting a hydration mismatch error when attempting the following in ssr...