solidjs-community/solid-primitives

[storage] signal is not updated during hydration when doing SSR or SSG

Open

#501 opened on Aug 21, 2023

 (3 comments) (0 reactions) (1 assignee)TypeScript (153 forks)auto 404
help wanted

Repository metrics

Stars
 (1,541 stars)
PR merge metrics
 (PR metrics pending)

Description

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.

Contributor guide