From c728f8c09de625a0180b49a2cffc975623d6afde Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Thu, 4 May 2023 16:45:40 -0400 Subject: [PATCH] init the store the right way --- src/lib/store/api.ts | 16 ++++++++-------- svelte.config.js | 4 ++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lib/store/api.ts b/src/lib/store/api.ts index 997ec61..2501b46 100644 --- a/src/lib/store/api.ts +++ b/src/lib/store/api.ts @@ -5,17 +5,17 @@ import { writable } from "svelte/store"; export type Api = ReturnType; export const createApi = () => { - const state = browser - ? JSON.parse(localStorage.getItem("ship") || "null") - : undefined; + const options: Partial<{ preloadedState: object }> = {}; - const api = ship.createStore({ - preloadedState: state, - }); + const preloadedState = browser && localStorage.getItem("ship"); + if (preloadedState) options.preloadedState = JSON.parse(preloadedState); - api.dispatch.restore(state); + const api = ship.createStore(options); - const svelteStore = writable(state); + const svelteStore = writable(); + if (preloadedState) { + svelteStore.set(JSON.parse(preloadedState)); + } if (browser) { api.subscribe(() => { diff --git a/svelte.config.js b/svelte.config.js index 702adb1..08c9540 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,8 +1,12 @@ import preprocess from "svelte-preprocess"; +import adapter from "@sveltejs/adapter-static"; /** @type {import('@sveltejs/kit').Config} */ const config = { preprocess: preprocess(), + kit: { + adapter: adapter({}), + }, }; export default config;