solid-primitives/storage help for a persistent user config store not loading properly on refresh/
I have user config in a store that I want to persist. I added makePersisted from solid-primitives/storage 4.3.1. I do a check for if it is the first time the user has visited to give initial config. I load the components based on each config item in the store array. When I refresh the page, the UI does not reflect values from localStorage; it loads the same as first initialized. When I make a config change, one div "catches up" (the For with Show), but the other one doesn't load the correct value until I re-toggled them myself. I've tried a resource from init tied to Suspense or even Show. Any help appreciated.
import { makePersisted } from "@solid-primitives/storage";
export default function Home() {
const [config, setConfig init] = makePersisted(createStore<UserConfig[]>([]), { name: "default" });
if (config.length === 0) {
//do initial config setup
}
return (
<main>
...
<div>
<For each={config}>
{(conf) => (
<Show when=conf.exists}
<button onClick={() => setConfig(conf.findIndex(c => c.abbr === conf.abbr), "active", !conf.active)}>
<ConfComponent abbr={conf.abbr} />
</button>
</Show>
)}
</For>
<div>
<For each={config}>
{(conf) => (
<button onClick={() => setConfig(conf.findIndex(c => c.abbr === conf.abbr), "exists", !conf.exists)}>
<ConfCompon abbr={conf.abbr} />
</button>
)}
</For>
</div>
...
</main>
7 Replies
Are you using SSR?
I think it is on; but I dont think I need it
Use the cookieStorage as local storage is not available on the server only cookies are available both on client and server.
Or you can add
ssr:false
to you app.config.tsmy project started with an entry-server, but I am not doing anything in it
like this:
export default defineConfig({
ssr: false
});
?
If SSR is enabled the initial page load/render will be done on the server. Great from SEO optimisation, preview links in Meta and other social media apps.
that fixed it
okay, can't I still put some meta into entry-server.tsx, or is this now disabled?
Yes, but it will the same for every page.