Skip to content

Firestore timestampsInSnapshots #181

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
CalebKester opened this issue Apr 25, 2018 · 2 comments
Closed

Firestore timestampsInSnapshots #181

CalebKester opened this issue Apr 25, 2018 · 2 comments
Labels

Comments

@CalebKester
Copy link

CalebKester commented Apr 25, 2018

I'm having issues adding the new timestampsInSnapshots: https://firebase.google.com/support/release-notes/js#4.13.0

I have this config file that I pass around components. When I tried adding the settings I'm now getting this error on my pages ref.onSnapshot is not a function

import firebase from 'firebase/app';
import 'firebase/firestore';

const config = {..};

firebase.initializeApp(config);

const firestore = firebase.firestore();

firestore.settings({
	timestampsInSnapshots: true
});

export default firestore;

Any idea? Is this an update that is needed in vuefire? Thanks for all the great work on this.

Here's the console.warn that firebase has

The behavior for Date objects stored in Firestore is going to change
AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to add the
following code to your app before calling any other Cloud Firestore methods:

  const firestore = firebase.firestore();
  const settings = {/* your settings... */ timestampsInSnapshots: true};
  firestore.settings(settings);

With this change, timestamps stored in Cloud Firestore will be read back as
Firebase Timestamp objects instead of as system Date objects. So you will also
need to update code expecting a Date to instead expect a Timestamp. For example:

  // Old:
  const date = snapshot.get('created_at');
  // New:
  const timestamp = snapshot.get('created_at');
  const date = timestamp.toDate();

Please audit all existing usages of Date when you enable the new behavior. In a
future release, the behavior will change to the new behavior, so if you do not
follow these steps, YOUR APP MAY BREAK.```
@posva
Copy link
Member

posva commented Apr 25, 2018

There is an update needed for this in vuefire code, so it's normal for it to break 🙂

@posva posva added enhancement firestore new Cloud Store labels Apr 25, 2018
@sne11ius
Copy link

Hey @posva , thanks a lot for your work so far ;)
Can you give any ETA on this one?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants