Closed ConcenTech closed 3 years ago
Hi @ConcenTech
Could you please provide your flutter doctor -v
and flutter pub deps -- --style=compact
?
What versions of the CDN are you importing in index.html
?
Thank you
Hi, Please find the requested information below.
Thanks
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-functions.js"></script>
I was able to reproduce the behavior but not sure if this is intended or not.
cloud_firestore: ^2.4.0
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script
Hey @ConcenTech, this is working as intended.
On web, the default is to disable persistence. The documents are still in-memory, and once the browser tab is refreshed/closed, the data will be lost (i.e. not persisted).
If you enable persistence, you will still have that data should you refresh/close the browser.
Below is a script you can run if you wish to see how firebase web handles it. Toggle the enablePersistence()
to see docs persisted/not persisted once you close/refresh the browser.
Hope this helps.
<html>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script>
var firebaseConfig = {
// TODO - insert your own config here
};
firebase.initializeApp(firebaseConfig);
var firestore = firebase.firestore();
(async function init() {
// TODO - Toggle enable persistence to see the difference
// await firestore.enablePersistence();
await firestore.disableNetwork();
console.log('disabled network');
})()
const collection = 'flutter-tests';
firestore.collection(collection).onSnapshot((snap) => {
console.log('docs: ', snap.docs.length);
});
async function add() {
await firebase.firestore().collection(collection).add({ doc: 'here' });
}
</script>
<button onclick="add()">add</button>
</html>
In my web app, I only want to listen to streams of data from the online database.
In the documentation there is the following information on offline persistence:
This reads as though offline persistence is disabled by default on web and can only be enabled?
Currently if listen to a stream, go offline and add a document to the collection I'm listening to, the new document appears in the stream. Is this expected behaviour, as offline persistence hasn't been enabled.
I expected the write to fail, so I can then handle this case.