Skip to content

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

Closed
@rscotten

Description

@rscotten

[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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions