guard around potential crashes

This commit is contained in:
2026-09-02 18:38:38 +02:00
parent 9c3fd4c1a2
commit e98293fa7c
5 changed files with 32 additions and 16 deletions
+3 -5
View File
@@ -1,12 +1,10 @@
import { browser } from '$app/environment';
import { SvelteSet } from 'svelte/reactivity';
import { readStored, writeStored } from './utils.ts';
export const favoritedStreams = new SvelteSet<string>(
JSON.parse((browser && localStorage.getItem('favoritedStreams')) || '[]')
);
export const favoritedStreams = new SvelteSet<string>(readStored('favoritedStreams', []));
$effect.root(() => {
$effect(() => {
localStorage.setItem('favoritedStreams', JSON.stringify(Array.from(favoritedStreams)));
writeStored('favoritedStreams', Array.from(favoritedStreams));
});
});