Skip to content

firestore: fix undefined document snapshot data after "clear site data" #8871

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 3 commits into from
Mar 28, 2025

Conversation

dconeybe
Copy link
Contributor

If using IndexedDB persistence with Firestore and a user clicks the "Clear Site Data" button in a web browser, the IndexedDB database is closed (as expected); however, it is re-opened as soon as it is needed again, under the assumption that the database contents haven't changed. This incorrect assumption can lead to writing inconsistent data into the database, causing all sorts of problems.

One notable problem is that if a snapshot listener receives an "update" after "Clear Site Data" was clicked, then it will write the updated document contents into the database as if the rest of the information (e.g. the target) is also in the database. This is an inconsistent database state. If, then, the web page is reloaded, it will misinterpret the data in the database and produce document snapshots with erroneous undefined snapshot data.

To avoid this corruption, this PR improves the SimpleDB class to detect the "Clear Site Data" button click and to refuse to re-open the database thereafter. This avoids database corruption and leads to a working Firestore after reloading the web page. This does, however, completely break the Firestore client until the web page is reloaded; however, since a page refresh seems like a probable next step after a "Clear Site Data" button click, this probably is reasonable, and better than a perpetually-unusable Firestore SDK.

Fixes #8593

@dconeybe dconeybe self-assigned this Mar 27, 2025
@dconeybe dconeybe requested review from a team as code owners March 27, 2025 03:09
Copy link

changeset-bot bot commented Mar 27, 2025

🦋 Changeset detected

Latest commit: 3c75c6d

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 Mar 27, 2025

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (670eba6)Merge (c5b4f9d)Diff
    browser381 kB382 kB+539 B (+0.1%)
    main590 kB591 kB+677 B (+0.1%)
    module381 kB382 kB+539 B (+0.1%)
    react-native381 kB382 kB+539 B (+0.1%)
  • bundle

    TypeBase (670eba6)Merge (c5b4f9d)Diff
    firestore (CSI Auto Indexing Disable and Delete)272 kB272 kB+539 B (+0.2%)
    firestore (CSI Auto Indexing Enable)272 kB272 kB+539 B (+0.2%)
    firestore (Persistence)303 kB304 kB+539 B (+0.2%)
    firestore (Read Write w Persistence)328 kB328 kB+539 B (+0.2%)
  • firebase

    TypeBase (670eba6)Merge (c5b4f9d)Diff
    firebase-compat.js793 kB793 kB+533 B (+0.1%)
    firebase-firestore-compat.js339 kB340 kB+533 B (+0.2%)
    firebase-firestore.js440 kB440 kB+539 B (+0.1%)

Test Logs

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 27, 2025

Size Analysis Report 1

This report is too large (66,076 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/41wR5GYCz9.html

Copy link
Contributor

@MarkDuckworth MarkDuckworth left a comment

Choose a reason for hiding this comment

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

LGTM with suggestion for code comment.

@dconeybe dconeybe merged commit 195d943 into main Mar 28, 2025
47 of 48 checks passed
@dconeybe dconeybe deleted the dconeybe/ClearInMemoryStateWhenIndexedDBIsCleared branch March 28, 2025 14:47
@google-oss-bot google-oss-bot mentioned this pull request Apr 22, 2025
@firebase firebase locked and limited conversation to collaborators Apr 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Firestore indexDB persistence corrupted after user "Clear site data"
3 participants