Solidstart Hydration error when using show and jsx element
I am moving my project to solidstart and i having an error with this component
Error
After trial and error i have pinpointed the error to this section
When using Show for the prefixIcon i get the current error but if i remove the Show tag (put still use prefix icon) the error is completely gone.
Can someone tell me what am i missing?
10 Replies
where do you set
prefixIcon
?
Looks like it's different on the server vs. the client
this is how i use the component
I think prefixIcon should be a component (function) or it'll generate twice with different hydration ids
try this
but that means my type cannot be a JSX element anymore but a component right?
yeah it'll be a component
() => JSX.Element
and you have to call it in the jsx
yeah like this
that does fix the issue indeed
nice
this changes the syntax used for a lot of things then. I am surprised solidstart require changes this big in the writing of component. espectially when all the solidjs example tells you tu use JSX.Element almost all the time for that specific case
Note that it's not really a problem with Start, it's just a general SSR thing. Without providing a function, each time
props.prefixIcon
is ran its JSX is re-evaluated, so in your case it was running twice, and hydration was expecting two icons to be present in the HTML.
You can avoid this by using a function instead as you've seen, or by ensuring props.prefixIcon
doesn't get evaluated twice. You'll want to use the children
helper for this, as it will memoise the component.
thank you for this explaination. I do find your solution nicer to use! thanks ❤️