firebase / firebase/firebase-tools
Firestore emulator Requests Monitor shows many almost identical requests.
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.3k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 84
Description
When you fetch data using the firebase/firestore library in a browser, the request will appear in the monitor.
However, when subscribing to changes via the onSnapshot method, somehow multiple identical requests appear in the monitor. Since these `request.times` are slightly different, it may be that the rule evaluation has been performed multiple times. This number of times increases by one each time you reload the page. It then returns to zero by restarting the emulator.
Note that the first read of onSnapshot is not a problem. The subsequent request when subscribing to the changes is the problem.
### [REQUIRED] Environment info
**firebase-tools:** 10.3.1
**Platform:** macOS Big Sur 11.6.4
### [REQUIRED] Test case
I made a sample project to reproduce this problem.
https://github.com/yukihiroK/firestore-sample
```ts
useEffect(() => {
const unsubscribe = onSnapshot(docRef, (doc) => {
if (doc.exists()) {
const data = doc.data();
console.log(data);
setState(data);
}
});
return unsubscribe;
}, []);
```
Listen to a specific document or collection with the onSnapshot method and make changes to that document on the Firestore.
### [REQUIRED] Steps to reproduce
Use the sample program above.
1. Start firebase emulator suite.
2. Create a document in `/(root)/collection/document/sub/doc1` on the firestore.
3. Edit the `firestore.rules` file to allow reading and writing to the document.
4. Start the sample react program and access `http://localhost:3000/`.
5. Press the "Add KV" button that appears on the screen, change the document, and subscribe to the change with the onSnapshot method.
6. Check the Requests Monitor. `http://localhost:4000/firestore/requests`
### [REQUIRED] Expected behavior
I think the rule evaluation should be done only once, like when the page has never been reloaded.
### [REQUIRED] Actual behavior
Contributor guide
Assessment
This issue has not been assessed yet.