Skip to content
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

New Firestore bug in v.8.0.* when list of documents is listened to and new documents added to the list #4083

Closed
rscotten opened this issue Nov 17, 2020 · 2 comments

Comments

@rscotten
Copy link

rscotten commented Nov 17, 2020

[REQUIRED] Describe your environment

  • Operating System version: OSX 10.15.6
  • Browser version: Chrome 86.0.4240.193
  • Firebase SDK version: 8.0.2
  • Firebase Product: Cloud Firestore

[REQUIRED] Describe the problem

Steps to reproduce:

This bug occurs in the Firebase library starting with version 8.0.*.

I have a Firestore listener listening to a list of 50 documents ordered by creation date descending. The creation date is a number field on the Firestore document (the value is the milliseconds returned from Date.now()), not the internal Firestore document timestamp.

Previously, before version 8.0.*, when I add a new document with the latest timestamp (ms), the document would appear at the top of the list because it was the newest document. This is expected. It definitely behaves this way with version 7.* because I had to revert back to that version.

With version 8.0.*, the newly created document appears at the bottom of the list of 50. This is the bug. When refreshing the page, the item appears first, as expected. So the problem is with the listener, not the data.

Relevant Code:

// listen to the docs ordered by createdAt desc

firestore
  .collection('items')
  .orderBy('createdAt', 'desc')
  .limit(50)
  .onSnapshot(querySnap => {
     // display docs in browser
  });

// add a new doc

const newItem = {
  text: "yo, I'm new",
  createdAt: Date.now()
}

firestore
  .collection('items')
  .add(newItem)

// the new item appears in the list, 
// In firebase 7.* the new item appears first, as expected
// In firebase 8.*, the new item appears at the end instead of first.  When refreshing, the new item appears first, as expected.
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@schmidt-sebastian
Copy link
Contributor

Thanks for reporting this. This will be fixed in the next release.

Fix is #4080

@firebase firebase locked and limited conversation to collaborators Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants