The question is somewhat similar to Firebase transaction returns null and completes without error . However, I already had the suggested solution.
The following uses Firebase web version 9. Running in node v14.17.3
const returnVal = await runTransaction(firebaseRef, async node => {
console.log("1", node);
if (node && node.ready != true) {
node.ready = true;
}
console.log("2", node);
return node;
});
if (!returnVal.committed) throw new Error("Not committed");
console.log("3", returnVal.snapshot.toJSON());
Before you go ahead and say, I am not setting node as an empty object, I expect it to become an object later on already.
And here is my output.
1 null
2 null
1 {otherMeta: {…}}
2 {otherMeta: {…}, ready: true}
3 null
As you can see, the transaction is completed with a null value. Which is strange.