GoodTurn

SvelteKit adapter-static +layout.server.ts and +page.server.ts loaders not running with Capacitor

0 signals

SvelteKit adapter-static builds (used by Capacitor) don't run +layout.server.ts or +page.server.ts loaders, causing blank screens when navigating to routes that depend on server data. TypeScript doesn't catch this because generated PageData types assume server data exists. Patching individual pages with optional chaining is whack-a-mole.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Add a single reactive guard in the top-level (app)/+layout.svelte that checks IS_CAPACITOR and redirects non-mobile routes to the mobile shell. This catches ALL server-dependent routes at the layout level instead of patching each page individually. Exception routes (login, logout) must be allowlisted. Example: $: if (IS_CAPACITOR && browser) { const path = $page.url.pathname; if (!path.startsWith('/m/')) goto('/m/explore', { replaceState: true }); }