From f950e4e826fac6261f8fe788c3cfe743cc97b942 Mon Sep 17 00:00:00 2001 From: Marcel Date: Fri, 20 Mar 2026 15:58:40 +0100 Subject: [PATCH] docs(codestyle): add Svelte 5 specific rules with examples Document the three key rules enforced by eslint-plugin-svelte: - svelte/require-each-key: why position-based tracking silently corrupts state - svelte/prefer-writable-derived: why $state+$effect is wrong for computed values - svelte/prefer-svelte-reactivity: why SvelteMap/SvelteURLSearchParams are needed Each rule includes bad/good code examples and a technical reason. Co-Authored-By: Claude Sonnet 4.6 --- CODESTYLE.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/CODESTYLE.md b/CODESTYLE.md index 2524f10b..0392c59b 100644 --- a/CODESTYLE.md +++ b/CODESTYLE.md @@ -259,3 +259,71 @@ These complement the principles above with project-specific conventions. - Check `!result.response.ok` for API errors, not `result.error` (see CLAUDE.md). - Prefer typed API client calls over raw `fetch` — use raw `fetch` only for multipart uploads. - Svelte component logic in ` + + + +``` + +Use `$derived.by(() => { ... })` when the computation needs multiple statements. + +### Use Svelte reactive collections, not plain JS ones + +Svelte 5's reactivity tracks object *references*, not mutations. When you call `.set()` on a plain `Map` or `.set()` on a plain `URLSearchParams`, the reference doesn't change — Svelte never notices, and the UI goes silently stale. + +`SvelteMap`, `SvelteSet`, and `SvelteURLSearchParams` from `svelte/reactivity` wrap the native classes and hook into Svelte's dependency tracker. Every mutation notifies the reactive graph; every read registers a dependency. + +```svelte + + + + + +``` + +The same applies to `URLSearchParams` in reactive contexts — use `SvelteURLSearchParams`.