Delay before disconnecting useFirestore
See original GitHub issueClear 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (8 by maintainers)
Top GitHub Comments
@Zehir oh, that’s a mistake and thanks for making PR!
I cared about compatibility, I wanted to write
because documents always close regardless
autoDispose
option in previous code.but almost users will expect to be able to use
autoDispose
to documents sois good like your PR.
I think it’s the simplest way
autoDispose
option also accept milliseconds of timeout (number
) not onlyfalse
.Can you do this? I want to know how it is implemented.