Add idempotency guard to offline cache listeners

Prevents duplicate event listeners if startOfflineCacheEventListeners
is called multiple times (e.g., during HMR or accidental remount).
This commit is contained in:
vicrodh committed 2026-02-12 13:02:41 -06:00
1 parent 20ab229cfe
commit 36632548fe
1 file changed
+5
+5
View File
@@ -95,6 +95,11 @@ export async function initOfflineCacheStates(): Promise<void> {
// Start listening for offline cache events
export async function startOfflineCacheEventListeners(): Promise<void> {
// Idempotency guard: prevent duplicate listeners on HMR/remount
if (unlisteners.length > 0) {
return;
}
try {
const unlistenStarted = await listen<{ trackId: number }>('offline:caching_started', (event) => {
console.log('Offline caching started:', event.payload.trackId);