Skip to content

DocumentChange.newIndex equals -1 for 'added' events #4079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MieleVL opened this issue Nov 17, 2020 · 1 comment · Fixed by #4080
Closed

DocumentChange.newIndex equals -1 for 'added' events #4079

MieleVL opened this issue Nov 17, 2020 · 1 comment · Fixed by #4080
Assignees

Comments

@MieleVL
Copy link

MieleVL commented Nov 17, 2020

  • Operating System version: Windows 10
  • Browser version: Chrome (latest)
  • Firebase SDK version: 8.0.2
  • Firebase Product: Firestore

[REQUIRED] Describe the problem

DocumentChange.newIndex === -1 for 'added' events. According to the documentation, this should only be the case for 'removed' events: https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentChange#newindex

Steps to reproduce:

Create a query snapshot listener. When the callback is triggered for the first time, change.newIndex is always -1.

Relevant Code:

db.collection("cities").docChanges().forEach(change => {
  if (change.oldIndex === -1) {
    // Should only be true for added documents.
    // change.newIndex also equals -1, which should not be the case imo. Should be >= 0.
  }

  if (change.newIndex === -1) {
    // Should only be true for removed documents.
    // Currently also true for added documents.
  }
});
@schmidt-sebastian
Copy link
Contributor

@MieleVL Thanks for filing this. We have been changing the internals of our SDK and it looks like this might be a regression. We will try to get this fixed as soon as possible.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants