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`.