Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
Does the Firestore SDK creates multiple listeners for same query?
private loadData(): void {
    const q = query(collection(this.store, 'users'), orderBy('userName'));
    this.unsubscribe = onSnapshot(q, p => {
        let users: any[] = [];
        p.forEach(x => {
            users.push(x.data());
        });
        this.usersDataSource = users;
    });
}

In the above method a listener is being created, and it can be removed the listener by calling -

this.unsubscribe();

On the same page/component, if this method gets called multiple times, does Firebase creates new listener each time? If yes, then what is the best way to remove all those listeners?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems your question is around having to remove each listener you register, which indeed you have to do.

While the SDK may deduplicate the listeners to the backend (it may, but I actually haven't checked in a while) that is unrelated to the API exposed to you: the number of calls to subscribe a listener must be balanced with the number of calls to unsubscribe it before the SDK will stop listening for changes on the server.

I typically keep a list of unsubscribe method for each scope of my application that I need to unsubscribe when the scope changes. So for example, if I have a React app, I do this per component. In other frameworks, the route-change logic is usually a good place to unsubscribe listeners from the old route.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!