Skip to content

Getting data from the collection() query with useFirestoreConnect after getting particular doc() causes multiple renders #914

Open
prescottprue/redux-firestore
#319
@alekseykarpenko

Description

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

When I'm using useFirestoreConnect to get the data from collection, that was previously provided to store user profiles (as userProfile option), I'm facing a very strange behavior, that seems like a bug. My component is being continuously updated, adding one new element to collection state after each iteration, while isLoaded is true from the very beginning.

Here is the code:

export const Authors: React.FC<Props> = (props) => {
  useFirestoreConnect(
    [{
      collection: 'users',
      storeAs: "authors"
    }]
  )

  const users = useSelector((state:AppState) => state.firestore.ordered.authors)

  console.log(users, isLoaded(users));

  return (
    <div>

    </div>
  );
};

And here is console output:
image

What is the expected behavior?
If I change collection to any other, that is not related to user profile, I meet the expected behavior:

image

UPDATE: If I remove profile definition from config, the same code also works as expected, so it's definitely a bug related to profile and useFirestoreConnect:

const rrfConfig = {
  userProfile: 'users',
  useFirestoreForProfile: true
}

UPDATE 2: I see a bunch of DOCUMENT_ADDED actions in my Redux console., so it's thinking that i'm adding those documents into my collection at the same time while i'm actually requesting them:
Kapture 2020-04-18 at 0 25 03

UPDATE 3
I have found, that this bug is not related to profiles only, but to any situation, when you first connect the particular doc, and then query all the collection. See my comment.

Which versions of dependencies, and which browser and OS are affected by this issue? Did this work in previous versions or setups?

{
    "firebase": "^7.13.1",
    "react": "^16.13.1",
    "react-redux": "^7.2.0",
    "react-redux-firebase": "^3.3.0",
    "redux": "^4.0.5",
    "redux-firestore": "^0.13.0",
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions