Skip to content

Use 'pagehide' for page termination by default. #4886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 13, 2021
Merged
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
5 changes: 5 additions & 0 deletions .changeset/perfect-comics-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

Use 'pagehide' for page termination by default.
4 changes: 2 additions & 2 deletions packages/firestore/src/local/indexeddb_persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ export class IndexedDbPersistence implements Persistence {
return this.shutdown();
});
};
this.window.addEventListener('unload', this.windowUnloadHandler);
this.window.addEventListener('pagehide', this.windowUnloadHandler);
}
}

Expand All @@ -976,7 +976,7 @@ export class IndexedDbPersistence implements Persistence {
typeof this.window?.removeEventListener === 'function',
"Expected 'window.removeEventListener' to be a function"
);
this.window!.removeEventListener('unload', this.windowUnloadHandler);
this.window!.removeEventListener('pagehide', this.windowUnloadHandler);
this.windowUnloadHandler = null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/local/shared_client_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ export class WebStorageSharedClientState implements SharedClientState {

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

this.started = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/test/util/test_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class FakeWindow implements WindowLike {
case 'storage':
this.storageListeners.push(listener);
break;
case 'unload':
case 'pagehide':
case 'visibilitychange':
// The spec tests currently do not rely on `unload`/`visibilitychange`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Looks like this comment refers to the old ‘unload’ rather than ‘pagehide’

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. WIll fix soon.

// listeners.
Expand Down