solidjs-community/solid-primitives

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

Ouverte

#501 ouverte le 21 août 2023

 (3 commentaires) (0 réaction) (1 personne assignée)TypeScript (153 forks)auto 404
help wanted

Métriques du dépôt

Stars
 (1 541 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

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.

Guide contributeur