global player pt. 3 persistence shenanigans

This commit is contained in:
2026-02-06 01:44:47 -08:00
parent b4d68299c3
commit 938b3a3334
2 changed files with 16 additions and 3 deletions

View File

@@ -154,12 +154,19 @@ const snapshot = $derived<PlayerSnapshot>({
uiOpen,
});
/** Persist on changes (best effort, throttled). */
/**
* Persistence
*
* NOTE: Module-level `$effect` is not allowed (it becomes an "orphaned effect").
* Instead, the GlobalPlayer component (or any single always-mounted component)
* should call `schedulePersistNow()` inside its own `$effect`.
*/
const schedulePersist = createPersistScheduler(250);
$effect(() => {
export function schedulePersistNow(): void {
if (!browser) return;
schedulePersist(persistableState());
});
}
/** --- Public reads --- */