react-redux-firebase: Getting data from the collection() query with `useFirestoreConnect` after getting particular doc() causes multiple renders
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:
What is the expected behavior? If I change collection to any other, that is not related to user profile, I meet the expected behavior:
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:
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",
}
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 9
- Comments: 21 (4 by maintainers)
@prescottprue 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:the second query in that case will trigger multiple
DOCUMENT_ADDED
events and rerender the Component after each update. This seems to me as very serious bug, you definitely should look on it.Confirm this issue. Also
isLoaded
is not working correctly. Always showstrue
, if you reapplywhere
query foruseFirestoreConnect
“react-redux-firebase”: “^3.7.0”,Hopefully, https://github.com/prescottprue/redux-firestore/pull/319 will fix this, when merged in
@alekseykarpenko and others - Thanks for catching this, it does hurt first-load performance. Any workarounds?
I see the same thing happening. At the moment you cannot use user profiles and retrieve the users collection without this issue occurring.
I found the same wrong behavioral. When I’m trying to get list of docs in child component and parent doc is getting docs from the same collection I see multiple “@@reduxFirestore/DOCUMENT_ADDED” actions.
@potier97 I believe @mike-lvov is just an external person who wrote a PR to attempt to fix this issue. The timing of if/when this gets accepted/merged into the project/released is entirely up to @prescottprue (or another direct ‘contributor’ to this project, if there are any)
@prescottprue Any thoughts on this?
Make sure you are passing an array of query configs to
useFirestoreConnect
instead of a single object. We should have something in place to throw an error in this case, thanks for reaching out