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:
1 parent
20ab229cfe
commit
36632548fe
1 file changed
+5
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user