Skip to content

change(firestore): close Firestore instance more gracefully when "Clear Site Data" button pressed in browser #9118

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Jun 24, 2025

This PR is the 2nd in a chain of PRs (previous PR: #9087) that unify the logic that handles unexpected IndexedDB database deletion.

This PR 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 the DatabaseDeletedListener.
  • 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 type failed-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 the onupgradeneeded event to the onsuccess event. This change prevents generic errors and allows for more precise and actionable error reporting to the databaseDeletedListener.

@dconeybe dconeybe self-assigned this Jun 24, 2025
@dconeybe dconeybe requested review from a team as code owners June 24, 2025 23:06
@dconeybe dconeybe requested a review from a team as a code owner June 24, 2025 23:06
Copy link

changeset-bot bot commented Jun 24, 2025

🦋 Changeset detected

Latest commit: 51a279d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/firestore Patch
firebase Patch
@firebase/firestore-compat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 24, 2025

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (86155b3)Merge (f682044)Diff
    browser395 kB396 kB+569 B (+0.1%)
    main616 kB617 kB+733 B (+0.1%)
    module395 kB396 kB+569 B (+0.1%)
    react-native395 kB396 kB+563 B (+0.1%)
  • bundle

    TypeBase (86155b3)Merge (f682044)Diff
    firestore (CSI Auto Indexing Disable and Delete)291 kB291 kB+368 B (+0.1%)
    firestore (CSI Auto Indexing Enable)291 kB291 kB+368 B (+0.1%)
    firestore (Persistence)322 kB322 kB-33 B (-0.0%)
    firestore (Query Cursors)260 kB261 kB+401 B (+0.2%)
    firestore (Query)258 kB258 kB+401 B (+0.2%)
    firestore (Read data once)248 kB248 kB+401 B (+0.2%)
    firestore (Read Write w Persistence)342 kB342 kB+368 B (+0.1%)
    firestore (Realtime updates)248 kB249 kB+401 B (+0.2%)
    firestore (Transaction)227 kB227 kB+401 B (+0.2%)
    firestore (Write data)228 kB228 kB+401 B (+0.2%)
  • firebase

    TypeBase (86155b3)Merge (f682044)Diff
    firebase-compat.js807 kB807 kB+348 B (+0.0%)
    firebase-firestore-compat.js351 kB352 kB+348 B (+0.1%)
    firebase-firestore.js459 kB459 kB+562 B (+0.1%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/ji2rTOxgBE.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 24, 2025

Size Analysis Report 1

This report is too large (207,898 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/dwtmKeTj5G.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants