S
SolidJS5mo ago
Dom

Using localStorage after creating a project with solidstart

I've just created a project with solidstart and started to add an option for dark mode using localStorage, but get
10:47:37 [vite] Error when evaluating SSR module /src/entry-server.tsx:
|- ReferenceError: localStorage is not defined
10:47:37 [vite] Error when evaluating SSR module /src/entry-server.tsx:
|- ReferenceError: localStorage is not defined
as a result... I understand that when using SSR I won't have access to localStorage but I don't need SSR. How do I configure this properly? Can I simply delete entry-server?
4 Replies
Dom
DomOP5mo ago
You can turn of SSR with
import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
ssr: false
});
import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
ssr: false
});
which resolves my issue
Alex Lohr
Alex Lohr5mo ago
Or you use cookieStorage/makePersisted from @solid-primitives/storage so you can even render the dark mode on the server and avoid the flash of missing mode.
Dom
DomOP5mo ago
thanks thats very useful
Madaxen86
Madaxen865mo ago
Use cookies with SSR

Did you find this page helpful?