solid-primitives
solid-primitives copied to clipboard
[storage] signal is not updated during hydration when doing SSR or SSG
Describe The Problem To Be Solved
Reproduce by creating a new solid-start project from the bare
template with SSR and change the line in Counter.tsx to:
const [count, setCount] = makePersisted(createSignal(0));
(Sorry I couldn't find a stackblitz template with solid-start.)
If you increase the counter and then reload the page, the counter isn't rendered and you get in the console:
Counter.tsx:7 Unable to find DOM nodes for hydration key: 0-0-0-0-0-0-0-0-0-1-0-0-0-0-2-1-0-0-2-1
Similarly, using Astro's client:load
directive (which does server-side render or generate the HTML in SSG-mode), on page-load the counter is always 0
.
Suggest A Solution
While it's unavoidable that the initial HTML contains 0
(since we cannot know the value of localStorage on the server), ideally storage
would update the signal during or after hydration to read out the value from localStorage
.