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
|
// Start listening for offline cache events
|
||||||
export async function startOfflineCacheEventListeners(): Promise<void> {
|
export async function startOfflineCacheEventListeners(): Promise<void> {
|
||||||
|
// Idempotency guard: prevent duplicate listeners on HMR/remount
|
||||||
|
if (unlisteners.length > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const unlistenStarted = await listen<{ trackId: number }>('offline:caching_started', (event) => {
|
const unlistenStarted = await listen<{ trackId: number }>('offline:caching_started', (event) => {
|
||||||
console.log('Offline caching started:', event.payload.trackId);
|
console.log('Offline caching started:', event.payload.trackId);
|
||||||
|
|||||||
Reference in new issue
Block a user