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

useQuery: on using refetch, 'loading' keeps true when same error returned twice or more #3395

Closed
jet2jet opened this issue Aug 20, 2019 · 12 comments

Comments

@jet2jet
Copy link
Contributor

jet2jet commented Aug 20, 2019

When using refetch method on the return value of useQuery, and an error returned with the same name and message for the previous error, loading value of the return value keeps true (not changes to false), even if notifyOnNetworkStatusChange option is true.

Intended outcome:

loading changes to false whenever an error returned

Actual outcome:

loading keeps true when the same error returned (though it changes to false on the first error)

How to reproduce the issue:

I created an repository with the reproduction code here:
https://github.com/jet2jet/react-apollo-test

After build and open dist/index.html, when clicking 'Refetch' at first, an error data will be shown. But when clicking 'Refetch' on the third time (callCount = 4 on the log), 'Loading...' will be shown (an error data should be shown on this time).

Version

Note: I think this problem might not occur with react-apollo: 3.0.0

npmPackages:
apollo-cache-inmemory: ^1.6.3 => 1.6.3
apollo-client: 2.6.4 => 2.6.4
react-apollo: 3.0.1 => 3.0.1

@jet2jet
Copy link
Contributor Author

jet2jet commented Aug 20, 2019

I think the following code is not working as expected...

if (!isEqual(error, this.previousData.error)) {

(it seems that equal from @wry/equality does only compares name and message for Error object: https://github.com/benjamn/wryware/blob/master/packages/equality/src/equality.ts#L72 )

@Kreozot
Copy link

Kreozot commented Aug 21, 2019

I confirm the issue.
I've created the sandbox for this issue: https://codesandbox.io/s/quirky-dhawan-csdxw
First time error handled correctly, but when the query is updating, error is disappears and loading is forever true.

@Kreozot
Copy link

Kreozot commented Aug 21, 2019

❗️ Important notice: When I change version of @apollo/react-hooks from 3.0.1 to 3.0.0 the issue is not reproducing.

@hinok
Copy link

hinok commented Aug 21, 2019

I struggle with the same issue but it's not really related to refetch.

I made codesandbox that shows this issue: https://codesandbox.io/s/react-apollo-3x-and-loading-true-i7ub1

This issue doesn't exist when react-apollo@3.0.0 is used.

@dylanwulf
Copy link
Contributor

@jet2jet That code was recently added in PR #3339. The purpose of that PR was to set loading properly when refetch is called, but it seems like it's still not working correctly

@Kreozot
Copy link

Kreozot commented Aug 26, 2019

Looks like a blocker for me.

@hwillson
Copy link
Member

hwillson commented Sep 6, 2019

Could someone here re-test using React Apollo 3.1.0 and let us know if this is still an issue? Thanks!

@jet2jet
Copy link
Contributor Author

jet2jet commented Sep 6, 2019

Could someone here re-test using React Apollo 3.1.0 and let us know if this is still an issue?

@hwillson I tried with react-apollo@3.1.0, but (unfortunately) the problem still occurs.
(reproduction: npm install --save-exact react-apollo@3.1.0 on the repository https://github.com/jet2jet/react-apollo-test , build with npm run build, and view dist/index.html)

$ npx envinfo@latest --preset apollo --clipboard

  System:
    OS: Windows 10
  Binaries:
    Node: 10.15.0 - N:\Nodejs\v10\bin\node.EXE
    Yarn: 1.12.3 - N:\Yarn\bin\yarn.CMD
    npm: 6.4.1 - N:\Nodejs\v10\bin\npm.CMD
  Browsers:
    Edge: 44.18362.267.0
  npmPackages:
    apollo-cache-inmemory: ^1.6.3 => 1.6.3
    apollo-client: 2.6.4 => 2.6.4
    react-apollo: 3.1.0 => 3.1.0

Thanks!

@hinok
Copy link

hinok commented Sep 6, 2019

@hwillson This issue still exists https://codesandbox.io/s/react-apollo-310-and-loading-true-tl1x0

@diazdell91
Copy link

#3270 (comment)

@jet2jet
Copy link
Contributor Author

jet2jet commented Sep 8, 2019

@hwillson I created PR #3477 to fix the problem, so please review it. Thanks.

@hwillson
Copy link
Member

#3477 has been merged (thanks @jet2jet!), and will be coming shortly in a patch release.

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

6 participants