-
Notifications
You must be signed in to change notification settings - Fork 926
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
dconeybe
merged 3 commits into
main
from
dconeybe/ClearInMemoryStateWhenIndexedDBIsCleared
Mar 28, 2025
Merged
firestore: fix undefined
document snapshot data after "clear site data"
#8871
dconeybe
merged 3 commits into
main
from
dconeybe/ClearInMemoryStateWhenIndexedDBIsCleared
Mar 28, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: 3c75c6d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
This was referenced Mar 27, 2025
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1This 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 |
MarkDuckworth
approved these changes
Mar 27, 2025
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.
LGTM with suggestion for code comment.
… its name is more self-documenting
…nIndexedDBIsCleared
Merged
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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