Description
Environment
- Operating System version: OSX Version 10.14.5
- Browser version: iOS simulator Version 10.2.1 (SimulatorApp-880.5 CoreSimulator-587.35)
- Firebase SDK version: [email protected]
- Firebase Product: firestore
- React Native: 0.59.8
- React: 16.8.3
The problem
When using doc.set() to create a new doc a query for the list of docs before the set() has completed returns the new doc but with the timestamp value set to null.
I've replicated this on a single client by not waiting for the set() promise to return before running the query. I realise this isn't how a single client should be implemented. However, it does make me worry that if one client is running set() while a different client runs a query that it's possible for other clients to receive a doc where the timestamp value is null.
I also read a firebase developer advocate on stackoverflow stating that it's not possible for a document to be returned without the serverTimestamp value and that seems to make sense to me. So I wouldn't expect to be seeing this document returned in the query.
I've also tried to replicate this issue using the node.js SDK running from the CLI and can't replicate it there. However, I'm definitely seeing it in React Native using the Web SDK.
Steps to reproduce:
I've replicated in the iOS emulator and my react native application using this code.
const ref = db.collection('bug');
ref.doc().set({'ts': firebase.firestore.FieldValue.serverTimestamp()});
ref.orderBy('ts', 'desc')
.limit(1)
.get()
.then((docRefs) => {
console.log(docRefs.docs[0].data());
});
Here's the result of running it a few times
Object {
"ts": null,
}
Object {
"ts": null,
}
Object {
"ts": null,
}
Object {
"ts": null,
}
Object {
"ts": null,
}
Object {
"ts": null,
}
Object {
"ts": null,
}
Object {
"ts": e {
"nanoseconds": 765000000,
"seconds": 1561795381,
},
}
Object {
"ts": null,
}
Object {
"ts": e {
"nanoseconds": 828000000,
"seconds": 1561795382,
},
}
Relevant Code:
I'm not sure how to create a working database query on StackBlitz without also sharing database credentials.
Here's the code that replicates the issue though.
const ref = db.collection('bug');
ref.doc().set({'ts': firebase.firestore.FieldValue.serverTimestamp()});
ref.orderBy('ts', 'desc')
.limit(1)
.get()
.then((docRefs) => {
console.log(docRefs.docs[0].data());
});