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

Previous data returned when changing variables and fetchPolicy is network-only (Reproduction Provided) #7978

Closed
dylanwulf opened this issue Apr 13, 2021 · 5 comments · Fixed by #8422 or #8642
Assignees

Comments

@dylanwulf
Copy link
Contributor

dylanwulf commented Apr 13, 2021

Intended outcome:
If I change variable values when fetchPolicy === 'network-only', then data should immediately become undefined while the results are being fetched from the server. This seemed to work correctly in v3.0.0 - v3.0.2, but broke in v3.1.0.

Actual outcome:
When I change the variable values, data still holds the previous data which was associated with the previous variable values.

How to reproduce the issue:
https://github.com/dylanwulf/react-apollo-error-template (look at the console as you click the radio buttons)

Possibly related to #7058 and #7048

Versions

System:
    OS: Windows 10 10.0.19042
Binaries:
    Node: 14.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.21.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
Browsers:
    Chrome: 89.0.4389.114
    Edge: Spartan (44.19041.423.0), Chromium (89.0.774.75)
npmPackages:
    @apollo/client: ^3.3.11 => 3.3.11
@dylanwulf
Copy link
Contributor Author

Also, if you change notifyOnNetworkStatusChange to true, then it will first return results for the previous variables, then it will return CACHED results for the current variables, and finally it will return the fetched results for the current variables. Is network-only supposed to return cached results when you change the variables? That seems wrong to me

@jcreighton jcreighton self-assigned this Apr 16, 2021
@dylanwulf
Copy link
Contributor Author

Updated reproduction to use the latest template and apollo client version (3.3.19), issue is still there

@hwillson
Copy link
Member

Thanks for this @dylanwulf - we'll take a closer look.

@hwillson hwillson added this to the June 2021 milestone Jun 15, 2021
@dylanwulf
Copy link
Contributor Author

@hwillson thank you for the response! sorry for my previous (now deleted) comment, it turned out to be a dumb mistake unrelated to this issue and has been taken care of. The original bug reproduction still stands though.

@benjamn benjamn assigned benjamn and unassigned brainkim Jun 23, 2021
benjamn added a commit that referenced this issue Jun 23, 2021
Appears to fix #7978.

Note that QueryInfo#getDiff knows how to handle fetchPolicy: "no-cache",
so it's safe to call it even in that case.
benjamn added a commit that referenced this issue Jun 23, 2021
benjamn added a commit that referenced this issue Jun 23, 2021
Appears to fix #7978.

Note that QueryInfo#getDiff knows how to handle fetchPolicy: "no-cache",
so it's safe to call it even in that case.
benjamn added a commit that referenced this issue Jun 23, 2021
@dylanwulf
Copy link
Contributor Author

Confirmed that #8422 fixes this, closing! Thank you so much for your help ❤️

@hwillson hwillson removed this from the MM-2021-06 milestone Jul 29, 2021
benjamn added a commit that referenced this issue Aug 12, 2021
This fixes #7978 in a better way than #8422, by actually checking
whether the `last.variables` used for `last.result` are still equal to
the current `options.variables`, before reusing `last.result` in
`ObservableQuery#getCurrentResult`.
benjamn added a commit that referenced this issue Aug 13, 2021
This fixes #7978 in a better way than #8422, by actually checking
whether the `last.variables` used for `last.result` are still equal to
the current `options.variables`, before reusing `last.result` in
`ObservableQuery#getCurrentResult`.
benjamn added a commit that referenced this issue Aug 16, 2021
This fixes #7978 in a better way than #8422, by actually checking
whether the `last.variables` used for `last.result` are still equal to
the current `options.variables`, before reusing `last.result` in
`ObservableQuery#getCurrentResult`.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.