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:
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user