question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Delay before disconnecting useFirestore

See original GitHub issue

Clear and concise description of the problem

In the case you are using vue-plugin-pages you can have a case that you load the same documents multiple times in case you came back to a page you already loaded once. But when you change the page the connection is closed at the moment you left the page thanks to:

    tryOnScopeDispose(() => {
      close()
    })

So you will be charged by one read each time.

Suggested solution

Using a little delay could alow you to use the cached document instead of get one new.

    tryOnScopeDispose(() => {
      useTimeoutFn(() => {
        close()
      }, 30000)
    })

You don’t need more code because the firestore sdk handle it by default. Even if the first useFirestore is closed I still get updates on the new useFirestore

Alternative

An alternative is to store your useFirestore in a pinia store but it’s lead to many tracks of what you put there.

Additional context

I can make a PR for that but I don’t know about the delay, should it’s be lower ? configurable ? Maybe a force close option ? Maybe a close if I get an update during the timeout ?

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
kiyopikkocommented, Sep 30, 2022

@Zehir oh, that’s a mistake and thanks for making PR!

I cared about compatibility, I wanted to write

if (autoDispose || isDocumentReference<T>(refOfDocRef.value)) { 
  tryOnScopeDispose(() => {})
}

because documents always close regardless autoDispose option in previous code.

but almost users will expect to be able to use autoDispose to documents so

if (autoDispose) { 
  tryOnScopeDispose(() => {})
}

is good like your PR.

1reaction
kiyopikkocommented, Sep 26, 2022

I think it’s the simplest way autoDispose option also accept milliseconds of timeout (number) not only false.

Maybe a close if I get an update during the timeout ?

Can you do this? I want to know how it is implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase Firestore - delay between data is written and ...
I had that before in my code and it looked like the database was slow. By removing the await the code was running...
Read more >
Best practices for Cloud Firestore - Firebase
If the lookup and the query do not have a data dependency, there is no need to synchronously wait until the lookup completes...
Read more >
How to use React Hooks with Firebase Firestore
Streaming data to React in real time from Firestore as a side effect; Wrapping query string handling logic into a custom Hook; Recap...
Read more >
Firestore clients: To cache, or not to cache? (or both?) - Medium
If your internet connection is slow, the SDK will fall back to results from cache ... (However, this document does exist in the...
Read more >
Firebase Tutorial: Real-Time Chat - RayWenderlich.com
For this tutorial, you'll use Firestore as your database. However, in a production chat app with lots of reads and writes to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found