question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Race condition in valueChanges()

See original GitHub issue

Race 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:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
jamesdanielscommented, Jan 22, 2021

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 a distinctUntilChanged(... /* deep eq check */) on the return from valueChanges(). Honestly I usually use snapshotChanges 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.

0reactions
jamesdanielscommented, Sep 2, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found