-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
persisted store results in ReferenceError: window is not defined #53
Comments
Any sample code? Any environment information? This is hard to debug otherwise, as I don't see this problem. |
Please also include which version of the package you are using from your lock file. |
This is only fixed when I turn ssr off at the root .ts file |
Anything rendered server side is not going to have access to the window object and thus persisted stores won't work. |
Closing for now. Feel free to reopen with more details if this is not an issue of SSR not having access to the window object. |
I think this should be reopened, as the persisted store example doesnt run in sveltekit out of the box. Any client side storage of course wont run in a project enabled for SSR but what i would expect is for persisted to do the checking and waiting internally |
so what is the recommended way of implementing client-side persisted store on a ssr-capable app? |
This works for me: // src/lib/stores.ts
const createStarredWorkloads = () => {
const {subscribe, update} = persisted(
{},
'STARRED',
{storageType: "LOCAL_STORAGE"}
)
return {
subscribe,
update,
star: key => update((a) => {
if (a[key]) {
a[key] = false
} else {
a[key] = true
}
return a
}),
}
}
export const starredWorkloads = browser ? createStarredWorkloads() : readable(); Seems like as soon as we hit the client, the starredWorkloads store is resubbed? It might be the side effect of me doing other dynamic loading, so not sure if YMMV. |
No description provided.
The text was updated successfully, but these errors were encountered: