solidjs-community/solid-primitives

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

Aberta

#501 aberto em 21 de ago. de 2023

 (3 comentários) (0 reação) (1 responsável)TypeScript (153 forks)auto 404
help wanted

Métricas do repositório

Stars
 (1.541 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

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.

Guia do colaborador