Skip to content

Commit 96a4709

Browse files
authored
Use 'pagehide' for page termination by default. (#4886)
1 parent de68cdc commit 96a4709

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

.changeset/perfect-comics-march.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": patch
3+
---
4+
5+
Use 'pagehide' for page termination by default.

packages/firestore/src/local/indexeddb_persistence.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ export class IndexedDbPersistence implements Persistence {
966966
return this.shutdown();
967967
});
968968
};
969-
this.window.addEventListener('unload', this.windowUnloadHandler);
969+
this.window.addEventListener('pagehide', this.windowUnloadHandler);
970970
}
971971
}
972972

@@ -976,7 +976,7 @@ export class IndexedDbPersistence implements Persistence {
976976
typeof this.window?.removeEventListener === 'function',
977977
"Expected 'window.removeEventListener' to be a function"
978978
);
979-
this.window!.removeEventListener('unload', this.windowUnloadHandler);
979+
this.window!.removeEventListener('pagehide', this.windowUnloadHandler);
980980
this.windowUnloadHandler = null;
981981
}
982982
}

packages/firestore/src/local/shared_client_state.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ export class WebStorageSharedClientState implements SharedClientState {
613613

614614
// Register a window unload hook to remove the client metadata entry from
615615
// WebStorage even if `shutdown()` was not called.
616-
this.window.addEventListener('unload', () => this.shutdown());
616+
this.window.addEventListener('pagehide', () => this.shutdown());
617617

618618
this.started = true;
619619
}

packages/firestore/test/util/test_platform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class FakeWindow implements WindowLike {
5858
case 'storage':
5959
this.storageListeners.push(listener);
6060
break;
61-
case 'unload':
61+
case 'pagehide':
6262
case 'visibilitychange':
6363
// The spec tests currently do not rely on `unload`/`visibilitychange`
6464
// listeners.

0 commit comments

Comments
 (0)