Skip to content

collectionData fires twice #50

Open

Description

@benzmarkus

Using the newest version and if i use collectionData(query(ref)) it fires once so this is correct.
If I am using collectionData(query(ref, ...whereStatements) and with one where statement it fires twice to the subscribe method returns twice.

Activity

  1. mvgijssel commented on Feb 10, 2022

    @mvgijssel

    I'm experiencing the exact same issue using rxfire 6.0.3 also with a collectionData and a where condition.

  2. davideast commented on Feb 13, 2022

    @davideast
    Collaborator

    Hey @benzmarkus and @mvgijssel! Thanks for the report! Can one of you create a small sample in StackBlitz, a small GitHub repo, or something of the like? I'd be happy to debug.

  3. ronnelreposo commented on Feb 19, 2022

    @ronnelreposo

    The same experience @davideast, I tried the code snipper in example-use, without where statement.

  4. mlahp7 commented on Mar 9, 2022

    @mlahp7

    We are experiencing this issue as well.
    It doesn't happen every time collectionData is called, but on subsequent calls. The first chunk of data is only a subset of the result we are expecting, the second chunk that comes through is the full result we expect.

  5. masterodi commented on Mar 15, 2022

    @masterodi

    Did anyone find a solution or workaround for this?

  6. SpraylnlPray commented on Jun 5, 2022

    @SpraylnlPray

    @davideast As @ronnelreposo mentioned it can be reproduced with the snippet in the example use from the readme. Do you need more information to be able to reproduce the issue?

  7. SpraylnlPray commented on Jun 5, 2022

    @SpraylnlPray

    I have a (ugly but working) workaround for the time being. For me the first time I subscribed to the query it behaved correctly, but afterwards the problem @benzmarkus describes occurred.

    In my case the query is called within an effect from a component store. Inside the store I have a variable called firstSubscription, that tracks if its the first subscription or not (Captain Obvious right there).
    If that variable is false, I skip the first emission from collectionData:

    this.effect((queryParam$: Observable<ParamType>) =>
      queryParam$.pipe(
        distinctUntilChanged(),
        withLatestFrom(this.state$),
        switchMap(([param, state]: [ParamType, ComponentState]) =>
          this._dataService.getDataAccordingToParam(param).pipe(  // returns collectionData with where statements
            skip(state.firstSubscription ? 0 : 1), // skip emission accordingly
          )
        ),
        tap(() =>
          this.patchState({ state.firstSubscription: false })
        )
        .... // transformat data
        tap((data: Data[]) => {
          this.patchState({
            data
          });
        })
      )
    )(this.queryParam$);
    

    Hope this helps someone

  8. narongdejsrn commented on Jul 10, 2022

    @narongdejsrn

    Another workaround that I found is to use throttleTime

    For example

    .pipe(
      throttleTime(500),
    )
    
  9. markklesel commented on Aug 31, 2022

    @markklesel
  10. Supamiu commented on Oct 20, 2022

    @Supamiu

    Any news on that? It's quite impactful when some other operations depend on that and thus fire twice themselves, throttleTime and other operators being just hotfixes that don't really fix the main issue.

  11. jits commented on Aug 15, 2023

    @jits

    This is likely related to the includeMetadataChanges option being hard coded to true when setting up the onSnapshot, which will always trigger the snapshot callback twice after writes (as this is the behaviour of the underlying Firebase library – it performs optimistic updates client-side, and then updates the hasPendingWrites metadata flag after the server-side update is confirmed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions