docs(transcription): explain why @mention mirror uses \$state+\$effect

The mirror effect on the dropdown's searchQuery looks like it should be
\$derived but it cannot be: bind:value on the <input> writes to the same
state, so it must remain mutable. Felix #2 on PR #629.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-19 23:10:30 +02:00
committed by marcel
parent 6a82f4b5b0
commit 88722e04cd

View File

@@ -34,6 +34,12 @@ let searchQuery = $state(untrack(() => editorQuery));
let userHasEdited = $state(false); let userHasEdited = $state(false);
// Mirror the editor's typed text until the user takes ownership. // Mirror the editor's typed text until the user takes ownership.
//
// Why `$state + $effect` (not `$derived`): `searchQuery` is also written by
// `bind:value` on the <input> below, so it needs to be a mutable `$state`.
// A `$derived` would be read-only and would clobber direct user edits on
// every editor keystroke. The `userHasEdited` latch pins ownership once the
// user types into the input. Felix #1 on PR #629.
$effect(() => { $effect(() => {
if (!userHasEdited) { if (!userHasEdited) {
searchQuery = editorQuery; searchQuery = editorQuery;