FirebaseExtended / FirebaseExtended/reactfire

Infinite request loop in useFirestoreCollection

Open
#374 2 comments 0 reactions 0 assignees View on GitHub
v5
Dominant language
TypeScript
Stars
3.6k
Forks
403
Avg merge
14h 53m
Merged PRs (30d)
5

Description

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.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the shown useUser and useFirestoreCollection snippet, then trace how useFirestoreCollection handles an undefined document path. Compare its behavior with null and a nonexistent id; done means the undefined case no longer causes repeated requests and has a defined outcome.

Written by the indexing model from the issue text.

Assessment

Tech stack
firebase, react, typescript
Domain
databases, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.