reactfire icon indicating copy to clipboard operation
reactfire copied to clipboard

Infinite request loop in useFirestoreCollection

Open maxprilutskiy opened this issue 4 years ago • 2 comments

Hello,

the following code results in an infinite loop when user isn't authenticated aka user.data is undefined. Is this expected?

  const user = useUser(undefined, { suspense: true });
  const subscriptions = useFirestoreCollection(
    firestore
      .collection('customers')
      .doc(user.data?.uid)
      .collection('subscriptions')

When something random and non-existent is passed to doc(myId), it throws Missing or insufficient permissions, when null is passed it throws Function CollectionReference.doc() cannot be called with an empty path, however when undefined is passed the code goes into an infinite loop and triggers hundreds of requests per second.

maxprilutskiy avatar May 23 '21 11:05 maxprilutskiy

Hi, did you solve your problem? If yes, could you help me?

hcyildirim avatar Jul 03 '21 13:07 hcyildirim

@prilutskiy I've had indefinite loop/suspending issues as well with v3.0.0-rc.*. They manifested at different times at different places in my app. I managed to get it working, not sure what the root cause is though. Maybe give my workaround a try and see if it solves your issues as well. For more details, see: https://github.com/FirebaseExtended/reactfire/issues/405#issuecomment-884860980.

steurt avatar Jul 22 '21 12:07 steurt