Open ReinoutStevens opened 5 months ago
I dislike bumping issues by adding a comment, but this issue is still affecting our site. We're adding notices to our users when firebase doesnt load within a certain timeframe to kill other tabs, but this is a really abysmal user experience.
@ReinoutStevens I believe we are facing the same issue. We was using onAuthStateChanged
then tried authStateReady
. Both have the same issue. Have you found a solution for this? Do you mind share if you are using signInWithPopup
or signInWithRedirect
No. We basically added a timeout, and when firebase doesnt resolve within that limit we show a popup to the user telling him to reload, and close other tabs of our website.
We are using signInWithPopup
Thanks for sharing:
We just found out that the behavior can be triggered by having multiple tabs open to the same site, and after several hours, opening a new tab will get stuck.
I was able to reproduce it.
Operating System
iOS
Browser Version
Safari
Firebase SDK Version
10.7.2
Firebase SDK Product:
Auth
Describe your project's tooling
NextJS app with Firebase loading as a dynamic component / separate chunk
Describe the problem
There is a problem with the
onAuthStateChanged
event callback in Safari on iOS ( or just with authentication in general ). The callback is not always invoked when the app has started, and as a result, the user is stuck while our app is waiting for firebase to finish. More specifically, the callback can also be invoked unreasonably late, as if firebase is stuck somewhere.Initially, we could not reproduce this reliably, and have only seen it ourselves a couple of times. As such, we have added an analytics event in the
onAuthStateChanged
callback to trigger when and how often firebase loads. We just found out that the behavior can be triggered by having multiple tabs open to the same site, and after several hours, opening a new tab will get stuck.Not loading:
Delayed loading:
For sessions in which firebase loads we looked at the different percentiles, median and average. Timings are in ms
Yes, that average for Safari is correct. For a small subset of users the onAuthStateChanged callback takes an insanely long amount of time to get called.
We have reworked our application a bit to try to not give these users an awful experience. For users where we suspect that firebase is not loading, but that still stick around long enough, we notice that firebase can eventually load after some time.
Timings are in seconds
Chrome and Firefox timings can be explained due to slow devices or networks ( as we're quite a heavy site in terms of downloading assets ), but Safari has other problems.
Steps and code to reproduce issue
We recently ( read, last night ) finally found out that you can get this behavior by having multiple tabs open of site for a couple of hours ( we managed to get it after waiting 2h, we don't know if you can get it sooner ), and then opening a new tab to the site. This tab will be stuck. Refreshing any of the other tabs will also result in them being stuck. Closing some of the tabs will result in a stuck tab to become unstuck.
We haven't looked deeper into how long tabs need to be open, or whether it's a specific tab you need to close. In case it matters, we've had it happen on a device where we never logged in on firebase, and a device where we had previously logged in. In both cases after a couple of refreshes firebase loaded just fine.
The code boils down to:
We have tried other implementations using
authStateReady
( which under the hood also useonAuthStateChanged
), where the same problem occurs.Related issues: https://github.com/firebase/firebase-js-sdk/issues/2167