question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] `loading` doesn't change back to false if updateQuery doesn't mutate the store

See original GitHub issue

I was dealing with pagination in an app and I forgot to update my hasNextPage field which caused a call to fetchMore which returned an empty array (because the connection had no more edges). When I proceeded to merge this with my previous result, the loading prop didn’t change to false after the APOLLO_UPDATE_QUERY_RESULT was fired.

I tried to reproduce the error by simply returning previousResult from updateQuery. Funnily enough, the error was only happening when I included pagination variables. This leads me to believe that the bug only occurs when APOLLO_QUERY_RESULT changes but APOLLO_QUERY_UPDATE_RESULT doesn’t update the store.

Here is a snippet of my code (I changed some variable names for clarity):

// repro
fetchMore({
  variables: { after: connection.pageInfo.endCursor },
  updateQuery: (previousResult, { fetchMoreResult: { data } }) => previousResult,
});

If variables is removed (or after), the bug will stop occurring. If after is removed, but first is added (thus changing APOLLO_QUERY_RESULT but NOT APOLLO_UPDATE_QUERY_RESULT) then the bug will start occurring again.

tl;dr: If updateQuery results in a different query being fetched but it returns the previous result, loading will never be set to false even after both APOLLO_QUERY_RESULT and APOLLO_QUERY_UPDATE have been fired.

EDIT: FYI, our GraphQL backend uses the Relay Cursor Connections Specification for pagination.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
helfercommented, Sep 22, 2016

Thanks, that sounds like it could be a bug. We’ll probably take care of this when we refactor the loading state in the next few weeks.

cc @tmeasday

0reactions
miguelollercommented, Sep 23, 2016

@tmeasday, I am using react-apollo. Sorry for the misunderstanding.

I’ve split the issue into two separate ones as needed. Closing this one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] `loading` doesn't change back to false if updateQuery ...
@davidyaha, the way I got to work around it was by checking if the query variable existed and used that as a proxy...
Read more >
Mutations in Apollo Client - Apollo GraphQL Docs
An update function attempts to replicate a mutation's back-end modifications in your client's local cache. These cache modifications are broadcast to all ...
Read more >
react query mutation isLoading turns false when switching tabs
When I switch tabs and come back to the original tab, the button is enabled again, even if the mutation is still loading....
Read more >
React.Component
An update can be caused by changes to props or state. These methods are called in ... render() will not be invoked if...
Read more >
Refreshing Server-Side Props - Next.js - Josh W Comeau
Here's my problem: in my dashboard, I'm able to edit users, ... This is because the page doesn't know that the underlying data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found