-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
useQuery results gets out of sync after a network error #7045
Comments
Here's a version of the minimal repro with the workaround applied: https://codesandbox.io/s/peaceful-lovelace-bfdgj?file=/components/MakeQuery.js - the UI displays what is expected, the two results stay in sync. |
@magicmark Can you double check your repro? It's working for me in each case: Initial: Toggle 1: Toggle 2: |
@hwillson I think you might be viewing the second link I posted (which demonstrates a workaround) - check out the first link, in my initial message, which demonstrates the issue described - https://codesandbox.io/s/silly-jones-tcpez?file=/components/MakeQuery.js |
Oops! Sorry, I looked before coffee - I'll take a closer look. |
@magicmark If you drop in a quick |
@hwillson Ah, good catch! Yes, this is a problem with my repro :( By removing However.....this brings me back to the original eyebrow-raiser that I started creating the repro for: Here's a version that avoids the infinite rerender loop https://codesandbox.io/s/staging-sun-9ij4e?file=/components/MakeQuery.js Why does Is this expected? |
Sorry for the delay here @magicmark - the issue you've outlined in #7045 (comment) is being tracked in #6905. Thanks! |
I'm having trouble nailing down exactly what's going or how to describe it, but here goes:
Whenever there's a network error, the
data
attribute returned fromuseQuery
"remembers" the previous result. And then things get a little weird, anduseQuery
appears to return the results from the previous network request?This sounds a little crazy, and maybe this isn't accurately describing what's actually happening - repros are worth a 10000 words, so here's something I threw together to demonstrate the issue:
Runnable Codesandbox link: https://codesandbox.io/s/silly-jones-tcpez?file=/components/MakeQuery.js
Code
My repro shows a component using both
useQuery
and the rawapolloClient.query
method on the client instance. (TheapolloClient.query
result appears to show the truth, and what I'd expectuseQuery
to also show.Here what the page looks like to start with - so far so good, both versions show a successful query response
Let's click the 'toggle network error' option to trigger a state change and re-render the component, and have the server return a 500:
The manual query approach appears to show the right thing.
useQuery
shows some....accidentally cached data?Now let's untoggle the network error...
We should go back to the state shown in (1), but....
🤔 🤔 🤔 looks like useQuery is now showing what it should've shown before? We're now in a state where useQuery is one step behind what it should actually be displaying. You can keep clicking the toggle -
useQuery
andapolloClient.query
are now permanently out of sync.It's very possible I'm misunderstanding how state is working here, and I'm doing something dumb - fwiw this came up trying to build https://apollo-visualizer.vercel.app/, in case anyone is interested in the use case. More generally though, I could imagine this causing problems when a network comes back online, or for retries or something.
Is this a bug? Or am I being dumb? Thanks!
Versions
The text was updated successfully, but these errors were encountered: