Guide
€19 PDF
Base price (bazna cijena) on 16.10.2026: €19
- The full guide (3 chapters, 16 pages)
- Every measurement with versions and scripts
- Free updates to this edition
Keep the signed-in user in module-level state, and the server shares it between requests. You won't see it when you test alone. Real traffic sees it.
A module is evaluated once per server process. A $state object in a .svelte.ts file, a store or a plain let is shared by every request that process handles. Write the user into it during a request, and the next request can render with that user.
// src/lib/unsafe/session.svelte.ts
export const session = $state<{ name: string | null }>({ name: null });
// src/routes/leak/module-state/+layout.server.ts
// ANTI-PATTERN: "remember the signed-in user globally, so any component can read it".
export const load = async ({ locals }) => {
session.name = locals.user?.name ?? null;
return {};
};
// src/routes/safe/props/+layout.server.ts
// SAFE: per-request data leaves the load function as data, never through a module.
export const load = async ({ locals }) => ({ name: locals.user?.name ?? null });
The SvelteKit docs warn about this: "it's important not to store data in shared variables". It still slips through, because every test you run alone passes. Free write-up with the method and the two free rules: the article.
N requests kept in flight, each from a different user. 3 rounds of 200 requests = 600 (150 for one at a time). Simulated 20–80 ms data wait. Windows 11, i9-13900KF, Node 26.3.
| Where the user is kept | 1 at a time | 10 in flight | 50 in flight | 200 in flight |
|---|---|---|---|---|
| module $state | 0 / 150 | 594 / 600 | 597 / 600 | 597 / 600 |
| module let | 0 / 150 | 594 / 600 | 597 / 600 | 597 / 600 |
| module store | 0 / 150 | 592 / 600 | 595 / 600 | 597 / 600 |
| set in hook, read by helper | 0 / 150 | 595 / 600 | 596 / 600 | 597 / 600 |
| set in layout component, read after await (async SSR) | 0 / 150 | 594 / 600 | 597 / 600 | 597 / 600 |
| set in layout component (sync render) | 0 | 0 | 0 | 0 |
| all 7 safe routes | 0 | 0 | 0 | 0 |
| /leak/module-state | Another user's name |
|---|---|
| 1 request/s for 180 s | 6 / 180 (3.3%) |
| 10 requests/s for 30 s | 123 / 300 (41%) |
| 100 requests/s for 10 s | 978 / 1,000 (97.8%) |
| safe route (props), 100 requests/s | 0 / 1,000 |
Open loop: requests arrive at random (Poisson), each from a new user. The rate of wrong pages depends on your traffic and how long your data calls take.
In 10 of 10 browser trials, the server HTML showed another user's name. After hydration the page said "Not signed in" (10 of 10). The wrong name is in the HTML that caches, previews and slow phones get.
Your assistant keeps writing the code. The rules tell it which pattern to use and why, in the format it reads: a Claude skill, a Cursor rule, Copilot instructions or AGENTS.md. Every rule names the test that backs it.
Rules 1 and 2 are free in the demo README. The pack adds the rest, templates, an audit prompt, a PR checklist and the tests to run in your own repo.



getRequestEvent(), load data, page.data, context.€19 PDF
Base price (bazna cijena) on 16.10.2026: €19
€39 PDF + AI pack
Base price (bazna cijena) on 16.10.2026: €39
€199 up to 10 developers
Base price (bazna cijena) on 16.10.2026: €199
Planned prices. Sales open soon. The waitlist hears first. Season 1 bundle: all four topics, Guide + Measured Rules for €99 (base price (bazna cijena) on 16.10.2026: €99), or any three topics for the price of two. Prices in euro, VAT included. Payment goes through Paddle, the merchant of record; a business can enter its VAT ID at checkout, and reverse charge then applies where the law allows.
One page per topic, every check backed by a measurement: section renderer, ssr state, sveltekit defaults and big lists in svelte 5 state.
After that: one email when the guides open, and a short note when a new measurement is published. Unsubscribe in one click. No confirmation, no emails: the address is deleted within 30 days.
Ask it. It can quote the SvelteKit docs: don't store data in shared variables. What it can't tell you is what that costs in production, which of your patterns count as "shared" (a hook-set variable and a plain let leak the same way), what happens to anonymous visitors, or how to prove the fix in your repo. I haven't measured how often assistants write the module-level store. I measured what it does: 594 of 600 pages with the wrong name at 10 requests in flight, 6 of 180 at one request per second. The pack gives your assistant the rule and gives you a concurrency test that fails if any response shows another user's data.
Yes. The docs say "it's important not to store data in shared variables". I don't claim it's hidden. What I add: how often it goes wrong, at stress and at realistic rates, why you won't see it in development, the anonymous-visitor case, async SSR, what the browser shows, and a test.
Right: "N in flight" is a stress test, and it is always labelled that way. So I also measured requests arriving at random. At 1 request per second, 6 of 180 pages showed another user (3.3%). Lower, but not zero.
Not by default. Instances are reused between requests. And a public page that only reads the global greeted 20 of 20 anonymous visitors with a previous user's name, one request at a time.
No. It's how JavaScript modules work on a server: one module instance per process. A plain let and a variable set in a hook leak the same way. The demo shows both.
Sales open soon. The waitlist hears first: one email when the guides open. The SSR state checklist, with the other three, arrives as soon as you confirm your address.
Yes: the measurement, the method and the two free rules are in the article "Module-level state in SvelteKit leaks between requests". The guide adds the anonymous-visitor case, async SSR, search patterns for your codebase and the drop-in test.
2 of 5 sections in the server HTML with {#await import()}
demo public (MIT) · guide soon
Read the measurements →
13 server loads for one opened page, reading a list with hover preloading
demo public (MIT) · guide soon
Read the measurements →
48 vs 2.2 ms to edit one of 100,000 rows with a $derived total: $state vs $state.raw
demo public (MIT) · guide soon
Read the measurements →