hooks.server.ts runs unexpectedly with disabled SSR
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
I am building an SPA and my root layout.ts contains export const ssr = false;. So far so good, +page.ts load functions now only load on the client. But I have a hooks.server.ts which is only supposed to run if +server.ts endpoints are hit. Strangely, it runs on every initial request to the page, which is weird, because with export const ssr = false; no requests should ever hit the server, at least that is what the docs suggest.
Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-grj3wfzf?file=src%2Fhooks.server.js
Logs
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@sveltejs/adapter-auto: ^4.0.0 => 4.0.0
@sveltejs/kit: ^2.16.0 => 2.20.7
@sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.3
svelte: ^5.25.0 => 5.28.2
vite: ^6.2.5 => 6.3.2
Severity
serious, but I can work around it
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction and compare the root layout.ts setting export const ssr = false with the behavior of hooks.server.ts on the initial page request. Trace the server request path and +server.ts endpoint behavior; done means the hook is not run for the initial page request when SSR is disabled, while endpoint requests retain the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100