fix(web/m7-364): untrack _position in queue immediate-write effect

Wrap the _position read inside untrack() in the immediate-write $effect
so it no longer registers as a reactive dependency, preventing the effect
from firing on every 4Hz position tick. Also adds three missing
restoreQueue unit tests with vi.mock for the auth store.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 21:37:55 -04:00
parent 8cc79ee612
commit 472b9d9e84
2 changed files with 56 additions and 9 deletions
+10 -8
View File
@@ -1,4 +1,5 @@
import type { TrackRef, RadioResponse } from '$lib/api/types';
import { untrack } from 'svelte';
import { api } from '$lib/api/client';
import { user } from '$lib/auth/store.svelte';
import { readPersistedQueue, writePersistedQueue } from './persisted';
@@ -379,20 +380,21 @@ $effect.root(() => {
$effect.root(() => {
let lastPositionWriteAt = 0;
// Immediate write on queue or index changes.
// Immediate write on queue or index changes. Position is read via
// untrack so this effect doesn't fire on every position tick — only
// queue/index changes drive it. The throttled-write effect below
// covers position drift.
$effect(() => {
const userId = user.value?.id;
if (!userId) return;
// Read these to register the dependency. Position is also read but
// its standalone changes are handled by the second effect below.
const _q = _queue;
const _i = _index;
void _q;
void _i;
// Reading these registers the reactive dependency; the values
// themselves are unused — writePersistedQueue re-reads live state.
_queue;
_index;
writePersistedQueue(userId, {
queue: _queue,
index: _index,
position: _position
position: untrack(() => _position)
});
lastPositionWriteAt = Date.now();
});