Race condition in valueChanges()
See original GitHub issueRace condition happening in valueChanges() of doc [subscribe keeps firing with no data change in document]. The issue is happening in angular prod build, Dev build works fine. Tested downgrading the package to AngularFire v6.0.5, the issue is not replicable.
Version info
**Angular: 10.2.3
**Firebase:8.2.1
**AngularFire:6.1.4
How to reproduce these conditions
sample code
this.getString()
.pipe(switchMap((docName) => {
if (docName !== '') {
return this.angularFireStore.collection(eColName.PublicCol).doc(docName).valueChanges();
}
})).pipe(filter(val => val !== null))
.subscribe(
(publicDocData) => {
this.publicData.next(publicDocDataa);
}
);
Debug output
NA
Expected behavior
Subscribe method should execute on start and on doc change
Actual behavior
Subscribe method executed like while loop without any end
Details I’m not sure is relevant: Tsconfig: “module”: “es2020”, “target”: “ES2015”, Angular dev and Prod build diff. optimization & buildOptimizer are true in prod rest are same
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Developers - Race condition in valueChanges() - - Bountysource
Race condition happening in valueChanges() of doc [subscribe keeps firing with no data change in document]. The issue is happening in angular prod...
Read more >How to avoid race conditions when subscribing to ...
I'm new to Angular and was writing this code. onUpdate(relation: RelationTypes) { let userId: number; this.assigneeId ...
Read more >Handling Form Race Conditions in Angular With RxJS
The race condition is when the POST call to save the newly created comment is still in-flight, while the user is on the...
Read more >How do I avoid race conditions in WaitOnAddress where the ...
Now we're actually waiting for a condition, namely for the m_compare to become nonzero. This solves the race condition, because if an item...
Read more >Automatic Race Condition Handling - Strickland
Value change race conditions are a common pitfall with async validation to ... If the value changes during async validation, the result Promise...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I bet this has to do with metadata changes, I fixed a bug which meant they weren’t getting emitted on
snapshotChanges
… perhaps I need to add adistinctUntilChanged(... /* deep eq check */)
on the return fromvalueChanges()
. Honestly I usually usesnapshotChanges
myself so I’m use to seeing all these extra emissions. I’ll look into this.FWIW that might be a work around for now.
Closing as some of this should be addressed in v7, others are just how the library works, developers should use
distinctUntilChanged
to reduce down change detection fires to changes that they care about