solidjs-community / solidjs-community/solid-primitives

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

Open
#501 3 comments 0 reactions 1 assignee View on GitHub

@atk is already working on this.

Since Sep 8, 2024.

help wanted
Dominant language
TypeScript
Stars
1.6k
Forks
162
Avg merge
19h 40m
Merged PRs (30d)
8

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.