r/sveltejs • • 14h ago

Is Sveltekit v3 failing on you, people with an app.html file renamed using appTemplate option?

2 Upvotes

This is happening to me. I already knew sveltekit sync had an issue, but this never prevented building. Now I'm upgrading `@svelte-router/core` to Sveltekit v3 and the project doesn't build because I renamed app.html.

Anyway, tips appreciated. Thanks!

UPDATE

Nevermind. Found the issue. The thing is that the newest Sveltepress for Sveltekit v3 creates its own Sveltekit plug-in, so adding the Svelte plug-in oneself is a mistake because then there are two: One configured with the appTemplate setting, and one with the default value. This is what causes the error. The solution is to configure the Sveltekit plug-in via the Sveltepress plug-in and of course, not add oneself the extra sveltekit() plug-in.


r/sveltejs • • 1h ago

Lessons from running a SvelteKit 3 static build inside a mobile app's WebView

1 Upvotes

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.