Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/firestore-storage-unique-listener-ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@capacitor-firebase/firestore': patch
'@capacitor-firebase/storage': patch
---

fix: generate unique listener/callback IDs on web so listeners created in the same millisecond do not overwrite each other
11 changes: 8 additions & 3 deletions packages/firestore/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class FirebaseFirestoreWeb
implements FirebaseFirestorePlugin
{
private readonly unsubscribesMap: Map<string, Unsubscribe> = new Map();
private lastListenerId = 0;

public async addCollectionGroupSnapshotListener<
T extends DocumentData = DocumentData,
Expand Down Expand Up @@ -129,7 +130,7 @@ export class FirebaseFirestoreWeb
},
error => callback(null, error),
);
const id = Date.now().toString();
const id = this.generateListenerId();
this.unsubscribesMap.set(id, unsubscribe);
return id;
}
Expand Down Expand Up @@ -166,7 +167,7 @@ export class FirebaseFirestoreWeb
},
error => callback(null, error),
);
const id = Date.now().toString();
const id = this.generateListenerId();
this.unsubscribesMap.set(id, unsubscribe);
return id;
}
Expand Down Expand Up @@ -220,7 +221,7 @@ export class FirebaseFirestoreWeb
},
error => callback(null, error),
);
const id = Date.now().toString();
const id = this.generateListenerId();
this.unsubscribesMap.set(id, unsubscribe);
return id;
}
Expand Down Expand Up @@ -670,4 +671,8 @@ export class FirebaseFirestoreWeb
return marker;
}
}

private generateListenerId(): string {
return (++this.lastListenerId).toString();
}
}
10 changes: 8 additions & 2 deletions packages/storage/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class FirebaseStorageWeb
{
public static readonly ERROR_BLOB_MISSING = 'blob must be provided.';

private lastCallbackId = 0;

public async downloadFile(
options: DownloadFileOptions,
callback: DownloadFileCallback,
Expand All @@ -63,7 +65,7 @@ export class FirebaseStorageWeb
.catch(error => {
callback(null, error);
});
return Date.now().toString();
return this.generateCallbackId();
}

public async deleteFile(options: DeleteFileOptions): Promise<void> {
Expand Down Expand Up @@ -179,7 +181,7 @@ export class FirebaseStorageWeb
callback(result, undefined);
},
});
return Date.now().toString();
return this.generateCallbackId();
}

public async useEmulator(options: UseEmulatorOptions): Promise<void> {
Expand All @@ -199,4 +201,8 @@ export class FirebaseStorageWeb
};
return result;
}

private generateCallbackId(): string {
return (++this.lastCallbackId).toString();
}
}
Loading