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
Madaxen86
Madaxen863d ago
Are you using SSR?
stan_dard
stan_dardOP3d ago
I think it is on; but I dont think I need it
Madaxen86
Madaxen863d ago
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.ts
stan_dard
stan_dardOP3d ago
my project started with an entry-server, but I am not doing anything in it like this: export default defineConfig({ ssr: false }); ?
Madaxen86
Madaxen863d ago
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.
stan_dard
stan_dardOP3d ago
that fixed it okay, can't I still put some meta into entry-server.tsx, or is this now disabled?
Madaxen86
Madaxen863d ago
Yes, but it will the same for every page.

Did you find this page helpful?