I maintain Valence, an open-source project that runs a web app as the UI of a Flutter mobile app and ships UI updates as signed bundles, so there's no store release. SvelteKit is one of the main supported stacks. This week I had an AI agent build a SvelteKit app from my docs alone, and it hit three things worth sharing with anyone doing static SvelteKit builds in a WebView, Capacitor or similar.
1. SvelteKit 3 config lives in vite.config.ts now In SvelteKit 3, the kit options go in sveltekit({...}) in vite.config.ts; per the types, svelte.config.js is no longer read for them. My docs and my setup wizard only looked at svelte.config.js, so they told people to set options in a file SvelteKit ignores. If you maintain tooling or docs that read SvelteKit config, check both places.
2. Asset paths: think "origin root", not "base path" Inside the app, every route is served the same index.html (SPA fallback) from a local server. If your build references assets relatively, then a reload or a back gesture on a nested route like /notes/42 resolves them against the wrong folder, and you get a blank white screen with nothing in the console. What works:
// vite.config.ts
sveltekit({
adapter: adapter({ fallback: 'index.html' }),
paths: { base: '', relative: false },
})
with export const ssr = false in the root +layout.ts. You also need client routes that match deep links; a fallback page doesn't make /notes/[id] exist by itself.
3. onMount with async loses your cleanup
onMount(async () => {
const unsub = await subscribe();
return () => unsub(); // never called: onMount got a Promise, not a function
});
onMount only runs a cleanup function returned synchronously. Start the async work inside, and return the cleanup right away:
onMount(() => {
let unsub: (() => void) | undefined;
let gone = false;
subscribe().then((u) => (gone ? u() : (unsub = u)));
return () => { gone = true; unsub?.(); };
});
In a long-lived WebView that never reloads, a leaked subscription adds up.
All three are fixed in the docs and in the wizard in Valence 0.5.0-beta.1.
If you want to try SvelteKit as a mobile UI: npm create valence@latest (Android supported; iOS experimental and untested). Docs: https://getvalence.dev/docs/guides/web-app/ Code (MIT): https://github.com/valence-dev/valence
Has anyone run into other gotchas with SvelteKit in a WebView or Capacitor? I'd like to cover them in the docs.