The behavior for Date objects stored in Firestore is going to change
See original GitHub issueHi there, I want to share this error I have been getting when I try to test my firestore with my vuejs app
Console log
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.
api.js
import Firebase from '@firebase/app'
import '@firebase/firestore'
import config from './config'
const firebaseApp = Firebase.initializeApp(config, {
timestampsInSnapshots: true
})
const api = firebaseApp.firestore()
export default api
main.js
import Vue from 'vue'
import App from './App.vue'
import Firestore from 'vue-firestore'
Vue.use(Firestore)
Vue.config.productionTip = false
new Vue({
render: h => h(App)
}).$mount('#app')
The view renders but there is no content from firestore.
Hope you can help me!!
Greetings from Argentina.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
The behavior for system Date objects stored in Firestore is ...
With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects.
Read more >The behavior for Date objects stored in Firestore is ... - YouTube
39. Google Firebase - The behavior for Date objects stored in Firestore is going to change. 4.5K views 4 years ago.
Read more >The behavior for Date objects stored in Firestore is going to ...
This is the error that I am getting: The behavior for Date objects stored in Firestore is going to change AND YOUR APP...
Read more >The behavior for Date objects stored in Firestore is ... - Steemit
The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK Created with Sketch.
Read more >The behavior for system Date objects stored in Firestore is ...
The behavior for system Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK? Is there a way to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @amranidev, thank you for your help.
I have solved the problem making changes on api.js as you suggested.
This is what I did, and it’s working fine right now. Note that I’m not longer passing the settings through initializeApp() neither firestore(), I’m doing it on the settings() method as firebase suggested on the console log. For a weird reason this wasn’t working last night.
hello @marcoshuck
Well, as mentioned in the log, you need to audit the usage of the dates, because timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects.
Basically, you should add
timestampsInSnapshots
parameter into the Firestore.Finally, In your component, don’t forget to parse the timestamps
timeStamps.toDate()
Thanks!