What this thread does
Do first: set export const ssr = false in the browser-only subtree's +layout.js, then configure adapter-static with the static host's fallback filename.
Short answer
Diagnostic: ReferenceError: document is not defined
As of November 2026, the release reference is SvelteKit 3.4.0 (released 2026-11-18; checked 2026-11-24). The current SPA guide configures adapter through sveltekit(...) in vite.config.js; it says the legacy svelte.config.js configuration is unsupported . The old January 2022 discussion is historical configuration guidance, not a current template.
Choose / don't choose
- SPA subtree: choose for a browser-dependent private app; accept empty initial HTML and JavaScript dependency.
- Prerendered page: choose for build-time-known public content; enable both
ssrandprerender. - Server adapter: choose when routes require server logic;
adapter-staticis suitable when there is no server-side logic (source).
Not for: load invalidation and duplicate fetching; see sveltekit-load-runs-twice-or-does-not-refresh-invalidate-depends-untrack.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
fallback | "200.html" as a common host-dependent fallback name; "404.html" for GitHub Pages; default undefined; avoid index.html collisions | Current adapter-static docs | source |
ssr | false in the nearest +layout.js for the browser-only subtree; root placement affects the whole app | Current SvelteKit page options | source |
prerender and ssr | Set both true on pages selected for prerendering | Current SvelteKit SPA docs | source |
strict | Keep default true; require prerendered routes or a fallback; false disables the completeness safeguard | Current adapter-static docs | source |
adapter | Configure adapter through sveltekit in Vite plugins; adapter-static fallback value "200.html"; import adapter from @sveltejs/adapter-static | SvelteKit 3 current docs; Vite configuration support added in 2.62 | source |
Order of operations
1. Choose the static host first. Generate its expected fallback filename and deploy the complete output directory. 2. Scope ssr = false to the client-only layout; keep unrelated public routes server-renderable (source). 3. Configure the host to serve the fallback for unknown application paths while serving real assets and prerendered pages normally. A generated fallback alone does not configure a host rewrite. The SPA guide includes an Apache rewrite example. 4. Enable ssr = true and prerender = true on eligible pages; open a nested route directly and reload it to check routing and asset resolution.
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
Nested SPA route returns 404 (symptom) | The fallback serves URLs that cannot be served by other means | Use the host's fallback/rewrite convention; inspect the response to a direct nested URL | source |
ReferenceError: document is not defined | Browser-dependent module executes in server evaluation | Keep literal page options and move browser-only imports into the client-rendered page/layout component | source; source |
| Prerendered page becomes an empty shell (symptom) | ssr is set to false | Ensure ssr is not set to false for prerendered pages | source |
Missing
- No static host was selected, so there is no universal fallback filename or rewrite file.
- Disabling both
ssrandcsrrenders nothing; SSR-disabled routes still need client rendering.
Checked
2026-11-12; linked sources read. No application commands executed.
Started from a post by @Svelte, packaged by the editor. Original post