refactor(web/auth): extract user state to break auth<->player cycle (B2)

This commit is contained in:
2026-05-08 10:49:39 -04:00
parent 68af48bb37
commit 909b36d5ad
3 changed files with 32 additions and 19 deletions
+3 -6
View File
@@ -1,7 +1,7 @@
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 { user } from '$lib/auth/user.svelte';
import { readPersistedQueue, writePersistedQueue } from './persisted';
export type PlayerState = 'idle' | 'loading' | 'playing' | 'paused' | 'error';
@@ -397,10 +397,7 @@ $effect.root(() => {
// queue/index changes drive it. The throttled-write effect below
// covers position drift.
$effect(() => {
// `user?.value` (not `user.value`) guards against module-init order during
// tests: auth/store.svelte.ts imports from this file, so when this module
// loads via that chain, `user` may not yet be assigned. See I2 follow-up.
const userId = user?.value?.id;
const userId = user.value?.id;
if (!userId) return;
// Reading these registers the reactive dependency; the values
// themselves are unused — writePersistedQueue re-reads live state.
@@ -416,7 +413,7 @@ $effect.root(() => {
// Throttled write on position changes.
$effect(() => {
const userId = user?.value?.id;
const userId = user.value?.id;
if (!userId) return;
const _p = _position;
void _p;