Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch queries are stuck in loading: true, partial: true when notifyOnNetworkStatusChange is enabled #9845

Closed
javier-garcia-meteologica opened this issue Jun 22, 2022 · 5 comments
Labels
🏓 awaiting-team-response requires input from the apollo team 🐞 bug 🧞 fixed-by-contributor issues where the contributor went the extra mile and fixed the problem with a PR

Comments

@javier-garcia-meteologica
Copy link
Contributor

When notifyOnNetworkStatusChange is enabled some watchQueries get stuck in loading: true, partial: true after calling reobserve/setVariables even if the underlying network request has already returned a successful result.

In particular, this bug happens when a reobserved query returns the same data with the new variables as before, or when the query is simply refreshed.

1: loading: false, data           ->   isDifferentFromLastResult=true, savedAsLastResult=true
2: loading: true, partial: true   ->   isDifferentFromLastResult=true, savedAsLastResult=false
3: loading: false, data           ->   isDifferentFromLastResult=false, savedAsLastResult=false, suppressed

Related to #9367

Proposed fix in #9844

Aside: notice also that apollo-client is returning partial: true even if returnPartialData is disabled when notifyOnNetworkStatusChange is enabled.

Intended outcome:
I would expect ObservableQuery to always report loading: false when a network request finishes. Also I would expect apollo client to never loading: true open forever.

Actual outcome:

ObservableQuery supresses result with loading: false because data is the same as ObservableQuery.last.result. But loading: true, partial: true, data: undefined was not saved as ObservableQuery.last.result.

How to reproduce the issue:

See test added in pull request #9844

Versions

apollo client 3.6.8

@fmorenodesigns
Copy link

fmorenodesigns commented Jun 23, 2022

At risk of this being unrelated (my apologies in advance if it isn't the same thing), I'd like to add that this also happens on fetchMore, under similar circumstances, i.e.:

this bug happens when a reobserved query returns the same data with the new variables as before

We have a case where we are using the InMemoryCache feature to make pagination. We've noticed that after upgrading to 3.6.0, if the incoming page is empty (in our case we can have empty pages in between others), i.e. the merged result is the existing page, then the loading state is not updated even though the network connection has completed successfully.

For the time being, we've worked around it (in React) with:

const [loading, setLoading] = useState(false)

function foo() {
    setLoading(true)
    fetchMore({...}).finally(() => setLoading(false))
}

@jpvajda jpvajda linked a pull request Jun 23, 2022 that will close this issue
2 tasks
@jpvajda jpvajda added 🧞 fixed-by-contributor issues where the contributor went the extra mile and fixed the problem with a PR 🐞 bug 🏓 awaiting-team-response requires input from the apollo team labels Jun 23, 2022
@bignimbus
Copy link
Contributor

Hi all, I'm doing some housekeeping and found this issue. It appears this was resolved in #10105 so I'll close this. Thanks a bunch!

@fmorenodesigns
Copy link

Thank you for the update on the issue 🙌
Though I must say that I've just tested this in version 3.7.7 and the problem persists.

@phryneas
Copy link
Member

@fmorenodesigns since the original issue added a test that is now successful, it seems that you have a different issue.
Could you please open a new issue and provide some kind of reproduction or test case?

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🏓 awaiting-team-response requires input from the apollo team 🐞 bug 🧞 fixed-by-contributor issues where the contributor went the extra mile and fixed the problem with a PR
Projects
None yet
5 participants