FirebaseExtended / reactfire

Hooks, Context Providers, and Components that make it easy to interact with Firebase.
https://firebaseopensource.com/projects/firebaseextended/reactfire/
MIT License
3.52k stars 401 forks source link

Firebase states stuck issue #619

Open jacobgram opened 1 month ago

jacobgram commented 1 month ago

Version info

React: 18.3.1

Firebase: 10.12.2

ReactFire: not used

Other (e.g. Node, browser, operating system) (if applicable):

Test case

We have the code below placed outside of react

let counter = 0;
const firebaseReadyCheck = setInterval(() => {
  counter++;
  trackEvent({ eventKey: "FIREBASE_READY_CHECK", metaData: { counter } });
  auth
    .authStateReady()
    .then(() => {
      trackEvent({
        eventKey: "FIREBASE_READY_CHECK_SUCCESS",
        metaData: { counter },
      });
      clearInterval(firebaseReadyCheck);
    })
    .catch((e) => {
      trackEvent({
        eventKey: "FIREBASE_AUTH_STATE_READY_ERROR",
        metaData: {
          message: e?.message,
          code: e?.code,
        },
      });
      clearInterval(firebaseReadyCheck);
    });
}, 3000);

Steps to reproduce

The below is the data we got. For desktop users: 4.18% users wait authStateReady for more than 3 seconds (including below) 2.4% users wait authStateReady for more than 6 seconds 1.42% users wait authStateReady for more than 9 seconds ...

For mobile users: 6.86% users wait authStateReady for more than 3 seconds (including below) 3.6% users wait authStateReady for more than 6 seconds 2.41% users wait authStateReady for more than 9 seconds ...

Waiting for 3/6/9 seconds doesn't mean authStateReady will stuck forever. We do have data showing authStateReady got resolved after 10+ seconds, however most of users won't wait that long.

Similar issue: https://github.com/firebase/firebase-js-sdk/issues/8019

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.

Expected behavior

auth.authStateReady() / auth.onAuthStateChanged() shouldn't stuck

Actual behavior

auth.authStateReady() / auth.onAuthStateChanged() stuck