Seemingly random hydration mismatches
Hello! I'm super new to solid js and web frameworks in general
This is the code I use to check if a given server is online
And when I reload it, and only when I reload my webpage does it return a hydration mismatch. I only found out after making a commit.
This is the code that fixed it:
Then I tried copying the
div
from the old code into the p
, to simulate that the that server is online.
I have a few questions:
- Why error on reload and not when it hot reloads/reloads by itself?
- Why arent div
s allowed inside p
s?
Again I only know enough html to make a couple side projects. I've never actually done anything like this before5 Replies
This might happen when on the server
props.online
evaluates to a different value than on the client.
Regarding no div in p: This is a web standard:https://www.w3.org/TR/html401/struct/text.html#h-9.3.1The div/p thing is what causes these errors.
When getting the plain html, the browser assumes that div inside of a p is an error, closes the p and opens a new div.
Once solid hydrates it sees this, complains, and tries to fix it. So when you look in devtools it will be correct. If you disable JS or only look at the returned static html, you will see another structure.
Nice. I didn’t know that.
how can this be?
props.online
is a bool
:
and im using online
properly:
Well, that code wasn’t available.
It could happen when you fetch data from a headless cms, and you forget to pass cookies/the token on the server but they are include on the client.