You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a major breaking change in firebase.firestore.DocumentSnapshot.exists between Web SDK v8 and v9 and I don't see it being called out anywhere. In v8, DocumentSnapshot.exists is a property while in v9, it's a method.
Is this intentional? This can inadvertently cause serious bugs, as a falsy snap.exists in v8 now becomes an always truthy snap.exists in v9. For example, in v8:
Hello @johnnyoshika. I'm sorry that you ran into this subtle bug during the v8 to v9 upgrade. That is definitely something that we overlooked and acknowledge that it could be an easy source of bugs. Unfortunately, we cannot change exists back to a property because that would be yet another breaking change.
Also, one of the benefits of it being a method is that it allows for TypeScript type guards. For example, in this code block
if(docSnap.exists()){vardata : DocumentData=docSnap.data()// Not nullable anymore}
the TypeScript compiler deduces that the return value of docSnap.data() cannot be null, removing the need to explicitly check for non-nullness in your code.
I'm looking into calling this out specifically in the migration guide, as you suggest. I'll update this issue with the outcome of that investigation.
Thanks @dconeybe! The TypeScript type guard is really neat. I didn't realize that.
I don't think there's anything wrong with breaking changes, especially in major version bumps. I was just surprised to see it on DocumentSnapshot.exists. Amending the migration guide is a good idea. Thanks!
The v8 -> v9 migration guide has been updated. The changes are live here: https://firebase.google.com/docs/web/modular-upgrade#exists-update. Googlers can see the changes in cl/426428626. Thank you for reporting this issue. Other Firestore users will definitely benefit from this documentation update.
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Steps to reproduce:
There is a major breaking change in
firebase.firestore.DocumentSnapshot.exists
between Web SDK v8 and v9 and I don't see it being called out anywhere. In v8,DocumentSnapshot.exists
is a property while in v9, it's a method.v8: https://firebase.google.com/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#exists
v9: https://firebase.google.com/docs/reference/js/firestore_.documentsnapshot.md#documentsnapshotexists
Is this intentional? This can inadvertently cause serious bugs, as a falsy
snap.exists
in v8 now becomes an always truthysnap.exists
in v9. For example, in v8:becomes this in v9:
The correct condition in v9 is
snap.exists()
, but this required change is not called out anywhere in the upgrade guidesAre there other breaking changes like this that we should be aware of?
Note also that the Node.js client's DocumentSnapshot.exists is a property, so for some reason v9 has created an inconsistency between libraries.
The documentation here needs to be updated, as
exists()
is no longer aproperty
even though the comment seems to imply that it is.Relevant Code:
See above
The text was updated successfully, but these errors were encountered: