SvelteKit 2.70.3 · Svelte 5.57.1

Your SvelteKit app can show users each other's data

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.

/leak/module-state · module-level $state
594 / 600 responses showed another user's name
● 10 requests in flight, production build, 9 Oct 2026 · SvelteKit 3.0.1 · Svelte 5.57.1 · node build One tile per request. Counts measured; tile order illustrative.
The problem

It looks like idiomatic Svelte 5. On the server, it's one object for everyone.

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.

The common pattern
// 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 {};
};
demos/02-ssr-state-leak · /leak/module-state
The safe pattern
// 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 });
demos/02-ssr-state-leak · /safe/props

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.

Measured on node build · 28 Sep 2026

How often the page showed another user

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 kept1 at a time10 in flight50 in flight200 in flight
module $state0 / 150594 / 600597 / 600597 / 600
module let0 / 150594 / 600597 / 600597 / 600
module store0 / 150592 / 600595 / 600597 / 600
set in hook, read by helper0 / 150595 / 600596 / 600597 / 600
set in layout component, read after await (async SSR)0 / 150594 / 600597 / 600597 / 600
set in layout component (sync render)0000
all 7 safe routes0000

Requests arriving at a realistic rate

/leak/module-stateAnother user's name
1 request/s for 180 s6 / 180 (3.3%)
10 requests/s for 30 s123 / 300 (41%)
100 requests/s for 10 s978 / 1,000 (97.8%)
safe route (props), 100 requests/s0 / 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.

What a real browser shows

127.0.0.1:4321/leak/module-state
Demo dashboard requested as User you, rendered 'Signed in as User u015'
server HTML: request from User you, page says User u015

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.

Measured Rules · 7 rules, 15 passing tests

Your assistant gets the rule, you get the test

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.

  1. 01 Never write per-user or per-request data into module-level state on the server. free
  2. 02 Pass per-request data as data. free
  3. 03 When components need shared state that depends on the request, create it per request and share it with context. in the pack
  4. 04 On the server, keep request data in event.locals and reach the current request with getRequestEvent(). in the pack
  5. 05 Module-level state is fine for values that are the same for every user, and for state only written in the browser. in the pack
  6. 06 Test with concurrent users, not one at a time. in the pack
  7. 07 With experimental async SSR, treat every read of shared state after an await as unsafe. in the pack

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.

What you get

The guide, the rules and the test

Guide cover: Per-User State During SSRGuide page: chapter 1, One object, every requestGuide page: the result table
Guide 02, draft PDF · 16 pages, 3 chapters
  • Chapter 1: one object, every request. The measurements, the anonymous visitor, what the browser shows.
  • Chapter 2: where per-request data belongs: locals, getRequestEvent(), load data, page.data, context.
  • Chapter 3: find it, fix it, test for it: search patterns, a migration recipe, and the drop-in concurrency test.
Planned pricing

Pick what you need

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
Join the waitlist

Team

€199 up to 10 developers

Base price (bazna cijena) on 16.10.2026: €199

  • Everything in Guide + Measured Rules
  • Licence for up to 10 developers of one company
  • Commit the rules to all of your company's repos
Join the waitlist

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.

Free now · guides soon

Get the SSR state checklist

One page per topic, every check backed by a measurement: section renderer, ssr state, sveltekit defaults and big lists in svelte 5 state.

  1. 1Enter your email. You land on our mailing-list page.
  2. 2Open the confirmation email from hello@measuredfrontend.com and click the link.
  3. 3The confirmation page lists the four PDFs. About one minute in total.

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.

Double opt-in: nothing is sent until you click the link in that email.

FAQ

Questions

Why not just ask my AI assistant?

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.

Isn't this in the SvelteKit docs?

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.

97% sounds like a stress test, not real traffic.

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.

I'm on serverless. Am I safe?

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.

Is this a Svelte bug?

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.

When can I buy it?

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.

Is there a free write-up?

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.