Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari gets stuck when using cache #8081

Open
cherylEnkidu opened this issue Mar 18, 2024 · 6 comments
Open

Safari gets stuck when using cache #8081

cherylEnkidu opened this issue Mar 18, 2024 · 6 comments

Comments

@cherylEnkidu
Copy link
Contributor

cherylEnkidu commented Mar 18, 2024

Operating System

MacOS Sonoma 14.4

Browser Version

Safari 17.4

Firebase SDK Version

10.8.0

Firebase SDK Product:

Firestore

Describe your project's tooling

NA

Describe the problem

Context: #7940
Internal tracking ticket: b/330146982, b/330181199

A developer, @jmw11x reports Safari getting stuck when using cache.

After initial investigation, the root cause is data stored in cache on Safari lost at some point. The problem is related to Safari indexdb issue. The Firestore SDK team hasn't find work around so far.

Steps and code to reproduce issue

The issue can be consistently reproduced on Safari using developer's repo App : https://github.com/jmw11x/FirebaseFirestore-Case-10271607/tree/main

@cherylEnkidu cherylEnkidu added question new A new issue that hasn't be categoirzed as question, bug or feature request labels Mar 18, 2024
@cherylEnkidu cherylEnkidu added bug internal-bug-filed browser-compatibility-issue and removed new A new issue that hasn't be categoirzed as question, bug or feature request question labels Mar 18, 2024
@cherylEnkidu cherylEnkidu changed the title Safari getting stuck when using cache Safari gets stuck when using cache Mar 18, 2024
@pJimenezProadata
Copy link

Are there any news on this issue? We are using this library on an Ionic Capacitor app for iOS and the problem still persists. Thank you!!

@cherylEnkidu
Copy link
Contributor Author

@pJimenezProadata

Unfortunately the team doesn't have a workaround so far.

@tobylewis
Copy link

This has cost me days and significant frustration.

Firebase seems to get stuck right at the beginning. Clearing caches from the Safari developer menu, or clear history, immediately unblocks any pending queries etc.

As a workaround I set a timeout before calling onSnapshot() and clear it in the callback.

let fix:any = setTimeout(() => {
    localStorage.setItem('safari-reset', String(Date.now()))
    window.location.reload()
}, 5000) // 5 second timeout
onSnapshot((snaps)=>{
    if (fix) {
        clearTimeout(fix)
        fix = false
    }
    // process snaps
}

If firebase is not responding then the timeout fires setting a flag and reloading the page.

When initialising firebase after reload I use the memoryLocalCache() instead of persistentMultipleTabManager() if it has failed in the last five minutes.

let localCache: any = persistentLocalCache({ tabManager: persistentMultipleTabManager() })
if (Number(localStorage.getItem('safari-reset')) > (Date.now() - 300000)) { // five minutes
    localCache = memoryLocalCache()
}
initializeFirestore(app, { localCache })

Not ideal but gets the app working on safari. I actually show the user a confirmation dialog before doing the reload so they know why it is reloading and to prevent infinite looping if something else has gone pear shaped.

@cherylEnkidu
Copy link
Contributor Author

Hi @tobylewis,

Thank you so much for providing your workaround to help other developers! Could you please help our team verify if you just use persistentMultipleTabManager() and not ask the page the force reload, will that solve the problem?

@tobylewis
Copy link

Hi @cherylEnkidu
I use persistentMultipleTabManager() as default because I want the data persisted all the time. The problem is that sometimes the request seems to get stuck in the cache retreival and never pings the server nor returns a result to my call. So when fails (using a setTimout() I detect a long delay after making firestore query) I downgrade to memoryLocalCache().

It's my understanding I can only only set the localCache with initializeFirestore() and this can only be called before any other firestore commands. Therefore I need to reload the page in order to call this again.

@cherylEnkidu
Copy link
Contributor Author

Hi @tobylewis ,

Thank you for you detailed and quick explanation.

The problem you are running into seems to be different from this open ticket. In the ticket's case, cache on Safari lost at some point but it won't make request pending. Could you please open a new ticket to provide us a repo / log? Also could you please help us check your issue only happened with Safari but not other browsers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants