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

getDoc() is never resolved nor rejected #5402

Closed
laurentpayot opened this issue Aug 29, 2021 · 10 comments · Fixed by #5434
Closed

getDoc() is never resolved nor rejected #5402

laurentpayot opened this issue Aug 29, 2021 · 10 comments · Fixed by #5434
Assignees

Comments

@laurentpayot
Copy link

[REQUIRED] Describe your environment

  • Operating System version: Ubuntu 21.04
  • Browser version: Chrome 92
  • Firebase SDK version: 9.0.0
  • Firebase Product: Firestore

Note that I'm running Firestore in a web worker.

[REQUIRED] Describe the problem

Steps to reproduce:

got doc is never logged (see code below)

Everything was fine with the v9 beta. The official, non-beta release broke it.

Relevant Code:

import {
    collection, doc, getDoc, writeBatch, updateDoc, deleteDoc, onSnapshot, query, limit
} from '@firebase/firestore'

/* … */

export default {

  /* … */

  // get user by user ID
  async getById(uid:string, db=defaultDb): Promise<User|null> {
    const userDoc = doc(db, 'users', uid)
    console.log("getting doc…")
    const userSnap = await getDoc(userDoc).catch(errorInfo(`user ${uid} fetching`))
    console.log("got doc")
    return <User>userSnap.data() ?? null
  }

  /* … */

}

Related to #5398?

@GaryAustin1
Copy link

GaryAustin1 commented Aug 29, 2021

I have been trying to start the conversion process from 8 and am seeing a similar issue with 9.0.0 in both compat mode and new mode. Neither docRef.get() or getDoc seem to do anything (no debug messages with debug on, no network requests, no error, no return). Auth and database seem to be working in compat mode on same project. The database object and doc object seem to coming back with filled in data.
Edit: Loaded 9.0.0-beta8 and compat docRef.get() works and debug messages and network requests for firestore start working.

@dconeybe
Copy link
Contributor

Hello @laurentpayot. Thank you for reporting this issue. I have attempted to reproduce this "hang" myself without success. Would you be able to create a minimal reproduction app? This bug is especially insidious because there are no logs whatsoever produced which makes debugging near impossible. If you can, could you publish this app into GitHub where I can clone it and reproduce the hang? With that, it should be relatively straight-forward to fix. Thank you.

@GaryAustin1
Copy link

Adding to my comment on @laurentpayot's post.
If I don't turn on persistence 9.0.0 works, 9.0.0-beta.8 works either way. Not sure if the other two report generators have persistence on or not from their descriptions..

@laurentpayot
Copy link
Author

@dconeybe I created a minimal reproduction app at https://github.com/laurentpayot/sscce-firebase
…but I could not reproduce the issue, even within a web worker like in my app

@GaryAustin1 you are right, getDoc() works if persistence is not enabled. Good to know!

Note that Rollup has a similar issue that is caused by the lastest TypeScript version that appeared around the same time as v9. Could the issue come from the buggy TS version Firebase v9.0.0 was transpiled with?

@GaryAustin1
Copy link

GaryAustin1 commented Aug 31, 2021

So I have my case narrowed to the order of setting persistence and auth init....

`firebase.initializeApp(firebaseConfig)
const firebaseApp = initializeApp( firebaseConfig );
const firestoreDb = getFirestore()

enableIndexedDbPersistence(firestoreDb) // persistence first does not work
const ui = new firebaseui.auth.AuthUI(firebase.auth()) // edit also fails with ui=firebase.auth() only

const unregisterAuthObserver = firebase.auth().onAuthStateChanged(user => {
console.log("hi")
console.log("fb initialize")

const docRef = doc(firestoreDb, "users",userId);
getDoc(docRef).then((docSnap) => {
if (docSnap.exists()) {
console.log("Document data:", docSnap.data());
} else {
console.log("No userInfo yet");
}
})
`

If I move the enableIndexedDbPersistence(firestoreDb) right after firebaseui.auth it works....
this is with [email protected] ...

edit: I removed ui and just did firebase.auth and that was sufficient to cause the issue so not dependent of firebaseui

@dconeybe
Copy link
Contributor

Thank you both for all of this info. I'll be digging into this further tomorrow.

@schmidt-sebastian
Copy link
Contributor

@dconeybe I will take a look at this.

@klausbreyer
Copy link

This occurs for me since 9.0.0 beta 3. I stayed at beta 2 until now.
But I learned through this github issue, that it is caused by the auth.

But today upgraded my code and introduced a timeout, to make sure that the auth is resolved, before I am calling getDoc. Without changing anything else, it works again!

@fuelkoy
Copy link

fuelkoy commented Sep 13, 2021

Is this issue resolved yet as I'm facing it still occuring with [email protected].
The issue was still not in [email protected] modular but it occured first in [email protected] and then it has been in all non-beta versions after that as far as I have tested.
No any code changed and firebase is initialized just as in [email protected]. But after upgrading package auth and functions have worked but firestore not as it results to Failed to get document because the client is offline.

@schmidt-sebastian
Copy link
Contributor

@maxfahl What version are you using? If you are on the latest version, do you mind sharing debug logs?

@firebase firebase locked and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants