Skip to content

Call toFirestore() only once #3755

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 6 commits into from
Sep 11, 2020
Merged

Call toFirestore() only once #3755

merged 6 commits into from
Sep 11, 2020

Conversation

thebrianchen
Copy link

@thebrianchen thebrianchen commented Sep 9, 2020

Fixes #3742.

@changeset-bot
Copy link

changeset-bot bot commented Sep 9, 2020

🦋 Changeset is good to go

Latest commit: eea74f4

We got this.

This PR includes changesets to release 8 packages
Name Type
@firebase/firestore Patch
firebase Patch
firebase-exp Patch
firebase-firestore-integration-test Patch
@firebase/rules-unit-testing Patch
@firebase/testing Patch
firebase-namespace-integration-test Patch
firebase-messaging-integration-test 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 Sep 9, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (95ab732) Head (056466e) Diff
    browser 249 kB 249 kB +192 B (+0.1%)
    esm2017 196 kB 196 kB +194 B (+0.1%)
    main 483 kB 483 kB +57 B (+0.0%)
    module 246 kB 246 kB +192 B (+0.1%)
    react-native 196 kB 196 kB +194 B (+0.1%)
  • @firebase/firestore/exp

    Type Base (95ab732) Head (056466e) Diff
    browser 189 kB 190 kB +205 B (+0.1%)
    main 478 kB 478 kB +117 B (+0.0%)
    module 189 kB 190 kB +205 B (+0.1%)
    react-native 190 kB 190 kB +205 B (+0.1%)
  • @firebase/firestore/memory

    Type Base (95ab732) Head (056466e) Diff
    browser 186 kB 187 kB +107 B (+0.1%)
    esm2017 147 kB 147 kB +109 B (+0.1%)
    main 357 kB 357 kB +57 B (+0.0%)
    module 184 kB 185 kB +107 B (+0.1%)
    react-native 147 kB 147 kB +109 B (+0.1%)
  • firebase

    Type Base (95ab732) Head (056466e) Diff
    firebase-firestore.js 287 kB 287 kB +192 B (+0.1%)
    firebase-firestore.memory.js 226 kB 226 kB +107 B (+0.0%)
    firebase.js 830 kB 830 kB +192 B (+0.0%)

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 9, 2020

Size Analysis Report

Affected Products

No changes between base commit (95ab732) and head commit (056466e).

Test Logs

Comment on lines 2383 to 2399
validateExactNumberOfArgs('CollectionReference.add', arguments, 1);
const convertedValue = this._converter
? this._converter.toFirestore(value)
: value;
validateArgType('CollectionReference.add', 'object', 1, convertedValue);
const docRef = this.doc();
return docRef.set(value).then(() => docRef);
return ((docRef as unknown) as DocumentReference)
.set(value, undefined, 'CollectionReference.add')
.then(() => docRef);
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you just leave the original code as is and do:

return docRef.withConverter(defaultConverter).set(value).then(() => docRef)

?

'@firebase/firestore': patch
---

Fixed a bug that where CollectionReference.add() called FirestoreDataConverter.toFirestore() twice intead of once (#3742).
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix grammar.

Copy link
Author

Choose a reason for hiding this comment

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

done.

return snapshot.data(options)!;
}
};
return docRef
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just call the DocumentReference constructor here? That way you can pass "null" and don't need to specify a converter.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@thebrianchen thebrianchen merged commit e81c429 into master Sep 11, 2020
@thebrianchen thebrianchen deleted the bc/conv-fix-add branch September 11, 2020 20:50
@google-oss-bot google-oss-bot mentioned this pull request Sep 15, 2020
@firebase firebase locked and limited conversation to collaborators Oct 12, 2020
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: CollectionReference.withConverter(converter).add(data) invokes converter.toFirestore twice
3 participants