-
Notifications
You must be signed in to change notification settings - Fork 926
Fix FirestoreDataConverter.fromFirestore() being called with QueryDocumentSnapshot from exp #4284
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
Conversation
🦋 Changeset detectedLatest commit: 4aa48fe The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 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 |
Size Analysis Report |
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.
Thank you for this fix! I have a couple of lame suggestions for you, but I am impressed. Especially with the PR description :)
FirestoreDataConverter.fromFirestore()
was being invoked with an instance ofQueryDocumentSnapshot
from the experimental SDK; however, it was expected to be invoked with an instance ofQueryDocumentSnapshot
from the Classic SDK. This worked okay, except that the object was lacking attributes likeref
, which are only provided by the Classic SDK.The root cause is that the
FirestoreDataConverter
provided by the user was registered directly with theQueryDocumentSnapshot
from the experimental SDK, and therefore was invoked with types from the experimental SDK. The fix is to instead register a "wrapper" data converter with theQueryDocumentSnapshot
that calls the underlying data converter with the equivalent objects from the Classic SDK.There was, however, a side effect of this change that caused
isEqual()
methods (e.g.DocumentReference.isEqual()
) to incorrectly returnfalse
if compared with anotherDocumentReference
created with the same converter instance. This is because the implementation ofisEqual()
compares the converters using the===
operator. The wrapper instances that wrapped the same converters were distinct objects, and thus did not compare equal using===
. The fix was to store each converter in aWeakMap
mapping it to its wrapper instance so that the same wrapper instance can be used for each given converter, causingisEqual()
to compare correctly.Fixes #4278