-
Notifications
You must be signed in to change notification settings - Fork 0
change(firestore): close Firestore instance more gracefully when "Clear Site Data" button pressed in browser #1
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @dconeybe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the robustness and user experience when the Firestore SDK's IndexedDB database is unexpectedly deleted, such as by a user clicking 'Clear Site Data' in their browser or another tab clearing persistence. It introduces a more granular event system for database deletion notifications, enabling the SDK to provide more informative error messages and ensure a more graceful termination process.
Highlights
- Improved IndexedDB Deletion Handling: Introduced specific event types (
ClearSiteDataDatabaseDeletedEvent
,VersionChangeDatabaseDeletedEvent
) to differentiate between various IndexedDB database deletion scenarios, providing more context to theDatabaseDeletedListener
. - Enhanced Firestore Termination: Modified the
setDatabaseDeletedListener
to receive detailed event information, allowing for more specific logging and error handling during Firestore termination. - Specific Error for 'Clear Site Data': When a 'Clear Site Data' event is detected, a
FirestoreError
of typefailed-precondition
is now thrown. This error provides a clear message to the user about potential IndexedDB corruption and suggests a page reload, and is thrown after attempting to terminate Firestore. - Robust IndexedDB Open Logic: Refactored
SimpleDb.open()
to defer handling of 'Clear Site Data' detection from theonupgradeneeded
event to theonsuccess
event. This change prevents generic errors and allows for more precise and actionable error reporting to thedatabaseDeletedListener
.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request addresses the issue of gracefully terminating Firestore when the "Clear Site Data" button is pressed in a web browser. It introduces new event types for database deletion listeners and modifies the Firestore client to handle these events, throwing a FirestoreError to prevent retries and logging relevant information. The changes also include modifications to the IndexedDB implementation to detect and handle potential database corruption due to the "Clear Site Data" action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This patch improves handling of IndexedDB “clear site data” and version-change deletions by queuing specific deletion events and terminating Firestore with more descriptive errors.
- Introduce
ClearSiteDataDatabaseDeletedEvent
andVersionChangeDatabaseDeletedEvent
to distinguish deletion causes. - Update
SimpleDb
to detect “clear site data” inonupgradeneeded
, queue the event, and dispatch it inonsuccess
instead of throwing directly. - Enhance the Firestore client to log context and throw a
FirestoreError
with guidance when these events occur.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
packages/firestore/src/local/simple_db.ts | Added event queue for Clear Site Data, removed direct throw, and dispatch queued events on success. |
packages/firestore/src/local/persistence.ts | Defined two new event classes and updated DatabaseDeletedListener to accept event objects. |
packages/firestore/src/core/firestore_client.ts | Enhanced listener to branch on event type, log details, and throw FirestoreError for clear-data. |
.changeset/hot-birds-report.md | Added changelog entry noting graceful termination on “Clear Site Data.” |
Comments suppressed due to low confidence (3)
packages/firestore/src/local/simple_db.ts:314
- [nitpick] This variable is an array but named in singular. Rename it to
clearSiteDataEvents
and iterate through all entries instead of only handling the first.
const clearSiteDataEvent: ClearSiteDataDatabaseDeletedEvent[] = [];
packages/firestore/src/local/persistence.ts:108
- [nitpick] The
VersionChangeDatabaseDeletedEvent
only captureseventNewVersion
. Consider also includingoldVersion
for consistency withClearSiteDataDatabaseDeletedEvent
and richer diagnostic context.
export class VersionChangeDatabaseDeletedEvent {
packages/firestore/src/local/simple_db.ts:23
- The
logError
import is not used in this file; consider removing it to avoid unused imports.
import { logDebug, logError } from '../util/log';
@gemini-code-assist give me 5 suggestions on ways to improve the changes in this PR to be more idiomatic |
Hi @dconeybe, Thanks for reaching out! I've reviewed the changes in your pull request, and here are 5 suggestions to make the code more idiomatic, focusing on common TypeScript/JavaScript patterns and best practices:
Let me know if you'd like to discuss any of these in more detail! |
Real PR: firebase#9118