How to properly set a “global” context in SvelteKit to maintain state-safety?
I’m currently building a web application with SvelteKit (Svelte 5) for the frontend. I’m facing one big problem: to avoid server-side effects, I can’t use global writable store, so I’m using Svelte’s context API. At the moment I load data like the user object in the load function of the routes +layout.ts file (root, home, /) and set the context in the corresponding +layout.svelte file so that it becomes available in all subpages and components. For reactivity, I share instances of classes with $state-properties in the contexts. This works fine, except for /login, /register and /logout, where the user object cannot be loaded initially, but the moment the backend returns the user object after the user submitted. But contexts can only be set during initialization and even if not, it would not be available on other pages except e.g. /login and below. The page navigates to / after successful login, but as the object is not available there, the frontend thinks the user is not logged in eventhough he is (http only cookies are set by the backend). I haven’t found a better way than a complete reload to re-fetch the data, but that’s a terrible workaround. Do you have any idea how I can keep reactivity, preferably with $state rune instead of stores while maintaining state-safety?
How do I make a site work with a URL like localhost:5173/index.html?
Using the new static adapter and hash based routing.
Blotter js in svelte
I’m attempting to integrate blotter.js into my Svelte project but encountering import issues. Has anyone successfully implemented blotter.js in Svelte? If so, could you share your approach and any necessary configurations or workarounds?
How to fake a secure context for Sveltekit development
On my development system, assume it has the name svkitdev, I am developing a Sveltekit 5 application, which I can run with “npm run dev” and access there via http://localhost:5173. But I also want to access it from browsers on mobile phones or tablets. I set the app up by choosing lucia during npx sv screate (and got oslo, lucia being now “only” a learning platform or so), so there is code setting secure cookies.
How to fix Sveltekit build issues
I built an API that uses the canvas module on the server using Sveltekit.
Everything was working properly when I was writing and testing the code.
However, when I perform npm run build
, I get the following error message:
Accessing device local storage values in a global store
My app stores user preferences in local storage, and I’m trying to make these values available as a context in my app. I’m stuck because I don’t understand how to set a context from an async function at the highest level of the app in SvelteKit.
Accessing device local storage values in a global store
My app stores user preferences in local storage, and I’m trying to make these values available as a context in my app. I’m stuck because I don’t understand how to set a context from an async function at the highest level of the app in SvelteKit.
Accessing device local storage values in a global store
My app stores user preferences in local storage, and I’m trying to make these values available as a context in my app. I’m stuck because I don’t understand how to set a context from an async function at the highest level of the app in SvelteKit.
SvelteKit: Accessing device local storage values in a global store
My app stores user preferences in local storage, and I’m trying to make these values available as a context in my app. I’m stuck because I don’t understand how to set a context from an async function at the highest level of the app in SvelteKit.
Routing issues with new SvelteKit project
I am new to SvelteKit and teaching myself routing.