This site uses one functional cookie to keep feature rollouts consistent for you. Nothing is set until you choose. See the privacy notice.
Dev notes
I wanted something on the site that shows I have started learning Svelte, and a framework is easiest to learn by building something small that actually gets used. So /mind-reader is a party game: one person is dealt a secret role toward the other ( “I am your bodyguard”, “I am a spy trying to steal your wallet”), talks normally while dropping hints, and the other has five minutes to work out what it is.
The deck is 240 sentences in six categories: protector, threat, secret, history, fantasy and everyday. Every one starts with “I am” because it is what Player A could say out loud, and the categories exist so a pair can pick the mood they want. A test pins the deck at over 200, rejects a repeated id or wording, and makes sure no category falls under ten, so filtering never leaves anyone with a deck that runs dry in two rounds. A role also does not repeat until the whole deck, or the chosen category, has been dealt.
Before I wrote any Svelte I wrote the game as a pure reducer: setup, secret, playing, reveal, with the dice and the clock passed in instead of read. That kept the interesting part, what a round is allowed to do next, testable without rendering anything, and it left Svelte with a narrow job: turn state into a screen. It also meant I was learning one thing at a time. The component uses $state for the game, $derived for the time left and the screen reader message, $effect for the interval, $props for an injectable dice and clock, and snippets for the heading and buttons I would otherwise have copied five times.
I could have stood up a separate SvelteKit project, but the point was a Svelte feature on this site. Next does not know what a .svelte file is, but Svelte 5's compiler already strips TypeScript, so the whole integration is a loader that calls compile() and hands back the JavaScript, registered as a Turbopack rule (and a webpack one so pnpm analyze still works). The React page is a thin client shell that imports Svelte inside an effect, mounts the component into an empty div, and unmounts it on the way out. Doing the import inside the effect also keeps the Svelte runtime out of every other route.
My component tests passed on the first full run, and the production build still printed this, because the loader forwards the compiler's warnings:
./src/app/mind-reader/MindReader.svelte Warning: Issue while running loader Error: This reference only captures the initial value of `game`. Did you mean to reference it inside a closure instead? https://svelte.dev/e/state_referenced_locally
I had written let lastPhase = game.phase to remember the previous screen, which reads reactive state once, at setup, and never again. It worked in the tests because the starting phase was the value I wanted anyway. I fixed it by starting from the literal "setup". The second warning was the same mistake in a quieter place: $state(now()) reads the now prop at init. The effect resets the clock as soon as a round starts, so the seed can be 0. I now check the compiler's warning count is zero before I trust a green run.
The lint rule for accessibility is applied to every file, but the Next config only registers its plugin for some extensions, so naming the loader svelte-loader.cjs broke the whole lint run:
A configuration object specifies rule "jsx-a11y/alt-text", but could not find plugin "jsx-a11y".
Nothing was wrong with the plugin. Renaming the file to .js put it back inside the glob. And the axe test timed out at five seconds until I stopped using fake timers for it, since axe schedules its own work with timers; every other Svelte test keeps the fake clock so five minutes of game takes a few milliseconds.
The clock has role="timer" with aria-live="off", and a separate status region announces only “one minute left” and “ten seconds left”, because reading out every second would drown the conversation the game is about. Focus moves to the new heading on every screen change but not on first load, so the page does not steal it from the header. Everything is a real button or radio, and the secret role leaves the DOM entirely once the clock starts rather than being hidden with CSS.
Update — October 26, 2026
The first version was one shared phone, with Player B told to look away. That was the weakest part of the game, so I added rooms: Player A taps Start a room, sends the link, and Player B plays from their own device. The rule I held it to was that the role is only ever sent to Player A.
My first sketch had an API route draw the role, store the room and send each player their half. That is a database table, an expiry job and a second copy of the rules for a five-minute party game. Instead Player A's device stays the only place the reducer runs. It deals the role locally and sends the room apublicView after every change, which carries the phase, the score and the time left, and the role only once the round is over. Player B's buttons are asks, and A's device decides on them. Nothing on the server ever knows the role, so there is nothing to leak.
{ "t": "view", "view": { "phase": "playing", "round": 1,
"guessed": 0, "stumped": 0, "lastOutcome": null,
"remainingMs": 270000, "paused": false, "role": null } }The test I care most about plays a round between two rendered devices on an in-memory channel, records every message, and checks the role text isn't in any of them until the reveal. The clock goes as time left rather than a deadline, because two phones never agree on the time.
World presence already talks over Ably with a token route and falls back to a BroadcastChannel, so rooms copy that pair. They get their own route,/api/mind-reader/token, so world presence's capability never widens. The room code is checked against its pattern before it goes into the capability, otherwise a code of * would mint a token for every channel. The page asks the route first and drops straight to the local channel on a 503, instead of waiting out Ably's connection retries. That fallback only reaches tabs in the same browser, so the room says so rather than looking connected. It's also what CI plays on, with two pages in one browser context.
Moving the button styles and the clock announcement into shared modules, so both players' screens use the same ones, turned the dead-export check red. It only follows TypeScript imports, and these are imported from .svelte files.
Found 2 dead export(s) — nothing imports these: src/app/mind-reader/buttonStyles.ts:2 - BUTTON src/app/mind-reader/buttonStyles.ts:5 - PRIMARY_BUTTON
Each one now carries an ignore comment that says why. It's a real cost of adding a second framework: every tool that walks the import graph has to be taught, or told, that.svelte files are part of it.