Skip to content

Commit 7ef7d51

Browse files
Attempt to delete client metadata row (#1131)
1 parent 4152a29 commit 7ef7d51

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/firestore/src/local/shared_client_state.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,11 @@ export class WebStorageSharedClientState implements SharedClientState {
624624
}
625625

626626
this.earlyEvents = [];
627+
628+
// Register a window unload hook to remove the client metadata entry from
629+
// LocalStorage even if `shutdown()` was not called.
630+
this.platform.window.addEventListener('unload', () => this.shutdown());
631+
627632
this.started = true;
628633
}
629634

@@ -728,13 +733,11 @@ export class WebStorageSharedClientState implements SharedClientState {
728733
}
729734

730735
shutdown(): void {
731-
assert(
732-
this.started,
733-
'WebStorageSharedClientState.shutdown() called when not started'
734-
);
735-
this.platform.window.removeEventListener('storage', this.storageListener);
736-
this.removeItem(this.localClientStorageKey);
737-
this.started = false;
736+
if (this.started) {
737+
this.platform.window.removeEventListener('storage', this.storageListener);
738+
this.removeItem(this.localClientStorageKey);
739+
this.started = false;
740+
}
738741
}
739742

740743
private getItem(key: string): string | null {

packages/firestore/test/unit/local/web_storage_shared_client_state.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ describe('WebStorageSharedClientState', () => {
191191
// client. If we directly relied on LocalStorage listeners, we would not
192192
// receive events for local writes.
193193
window.addEventListener = (type, callback) => {
194-
expect(type).to.equal('storage');
195-
localStorageCallbacks.push(callback);
194+
if (type === 'storage') {
195+
localStorageCallbacks.push(callback);
196+
}
196197
};
197198
window.removeEventListener = () => {};
198199

0 commit comments

Comments
 (0)