Description
Operating System
Ubuntu 20.04.6 LTS
Environment (if applicable)
Chrome Version 133.0.6943.126
Firebase SDK Version
11.3.1
Firebase SDK Product(s)
Database
Project Tooling
React app with Webpack
Detailed Problem Description
I have a listener attached to a specific path, which works as expected. At some point in my application, I need to read from a specific node that it is under the path with the listener attached, right after I updated this node. The data returned is not up to date, being returned the values as the write operation never happened. If I set some delay, like 3 seconds for example, sometimes the returned data from get() works as expected.
Steps and code to reproduce issue
Create a listener to path:
const transactionRef = ref(db, 'financial/transactions/costCenter');
onValue(transactionRef, (snapshot) => {
const data = snapshot.val();
});
Later, perform a update to a node under the path being listened to:
const updates = {};
updates[`financial/transactions/costCenter/${id}/value`] = someValue;
updates[`financial/transactions/costCenter/${id}/date`] = date;
return update(ref(db), updates);
And then, get the value from the precious path with its updated values:
const dbRef = ref(getDatabase());
get(child(dbRef, `financial/transactions/costCenter/${id}`)).then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
}
}).catch((error) => {
console.error(error);
});
Or using onValue:
return onValue(ref(db, `financial/transactions/costCenter/${id}`), (snapshot) => {
// ...
}, {
onlyOnce: true
});
The value returned from the read operation is out of date, making it looks like the write operation never happened, however the values are successfully written to the database