Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

fetchMore causes loading to be indefinitely true when getting an empty response #3468

Closed
strblr opened this issue Sep 7, 2019 · 13 comments
Closed

Comments

@strblr
Copy link

strblr commented Sep 7, 2019

Intended outcome:

loading being true while the fetchMore request is done, then merging the results with updateQuery, then rerendering with loading to false.

Actual outcome:

When fetchMore gets an empty array from the server, updateQuery is called as it should be, but the component never rerenders, thus loading being indefinitely true.

Version

@apollo/react-hooks : 3.1.0

The problem started with this version.
3.0.1 worked fine.

@Victordmdb
Copy link

Not sure if this would help anyone but I resolved this because my fetchMore was unnecessarily being called immediately after render. After fixing that the issue stopped.

@strblr
Copy link
Author

strblr commented Sep 12, 2019

That is not my case, and everything was fine in version 3.0.1. I don't think this comes from my code.

@scf4
Copy link

scf4 commented Sep 16, 2019

I'm also experiencing this issue. networkStatus is stuck on 3, fetch more. This is with hooks 3.1.1 and apollo-client 2.6.4. Mine isn't being triggered immediately after render either.

@scf4
Copy link

scf4 commented Sep 16, 2019

It seems like this happens when updateQuery returns previousQueryResult, regardless of the result, as the component isn't re-rendered.

Forcing a render fixes it.

@dylanwulf
Copy link
Contributor

I created a reproduction for this bug: https://codesandbox.io/s/reproduction-for-react-apollo-3468-jt3b5
@hwillson this seems like it could be related to PR #3433

P.S. I love using addMockFunctionsToSchema in my client side tests, it's so much easier when the data is mocked automatically

@scf4
Copy link

scf4 commented Sep 19, 2019

@dylanwulf I think your reproduction is for a different bug. This issue happens with a successful response of an empty array when no other data/state changes.

@dylanwulf
Copy link
Contributor

@dylanwulf I think your reproduction is for a different bug. This issue happens with a successful response of an empty array when no other data/state changes.

@scf4 I am fairly confident that both issues are caused by the same bug, but just in case I created another reproduction with a successful response of empty array: https://codesandbox.io/s/reproduction-for-react-apollo-3468-with-successful-response-p4gmo

@scf4
Copy link

scf4 commented Sep 19, 2019

@dylanwulf Oops, yeah I see what you're saying now. 👍

@Quadriphobs1
Copy link

Same happens here, building pagination components and when I get a empty array response from the API the loading get stucked and it is not updated.

@Quadriphobs1
Copy link

It looks like a fix has been proposed but it has not been merged #3514

@ehortle
Copy link

ehortle commented Sep 30, 2019

I am also experiencing the bug described by @scf4 . When I use fetchMore, it successfully makes the network request, but networkStatus is stuck on 3, and loading is stuck on true, but only when the result of fetchMore is the same as the previous result.

I am experiencing this with:

"react-apollo": "^3.0.1",
"apollo-client": "^2.5.1",

@hwillson
Copy link
Member

hwillson commented Oct 2, 2019

#3514 has been merged, and will be deployed shortly. Thanks all!

@hwillson hwillson closed this as completed Oct 2, 2019
@maafaishal-tkpd
Copy link

@hwillson have you deployed it? Because I still have this problem

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

No branches or pull requests

8 participants