-
Notifications
You must be signed in to change notification settings - Fork 978
Description
Operating System
macOS 14.2
Browser Version
Safari 17.2
Firebase SDK Version
10.7.1
Firebase SDK Product:
Auth
Describe your project's tooling
Next.JS 14.0.4
Describe the problem
I'm running into an issue where neither authStateReady
nor onAuthStateChanged
is working consistently in Safari (i.e. 90% of the time authStateReady
never resolves or onAuthStateChanged
isn't called). It's a challenging bug because:
- It only seems to happen in production
- It doesn't occur in private browsing
- It doesn't occur in Chrome
- Sometimes I get an AbortError which calls out specific IndexedDB issues.
- Sometimes I don't, but it still doesn't work.
I was able to track down when one of the errors occurred:
"Firebase: Error thrown when reading from IndexedDB. Original error: Error looking up record in object store by key range. (app/idb-get).
Unhandled Promise Rejection: AbortError: AbortError
I set a breakpoint and it appears that the error is coming from line 68 in indexeddb.ts
:
One thing I've noticed is that in tabs where the page isn't working, if I look at IndexedDB there's no data in firebase-heartbeat-storage
or firebaseLocalStorageDb
but on the pages where it is working, there is data.
I have a theory that there's a bug / some interaction with Safari's IndexedDB support, but I'm not sure what exactly. As you can imagine this bug is somewhat a showstopper since users can't log in :-)
Steps and code to reproduce issue
This is what I have for a minimal repro:
useEffect(() => {
// Initialize Firebase
initializeApp(firebaseConfig)
const auth = getAuth();
(async () => {
console.log('calling authStateReady')
try {
await auth.authStateReady()
} catch (error) {
console.log('Unable to call authStateReady', error)
}
console.log('called authStateReady')
setUser(auth.currentUser)
})()
}, [])
When auth works, called authStateReady
is called, otherwise not. I have a live demo here: https://repro.easiestcourses.com/minimal
If it says User: pending
then the bug is present. If it switched to User: signed out
then it's working as expected. As I mentioned earlier, one challenging thing is that this doesn't happen consistently so that page may or may not work in Safari if you load it.