-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
useMutation's onSuccess promise never resolves due to setQueryData and refetchQuery edge case #639
Comments
@tannerlinsley you mean here https://github.com/tannerlinsley/react-query/blob/master/src/core/queryCache.js#L226 ? for the 2.x branch (master) ? |
Sorry, yes... no idea why the line numbers didn't paste there. We need to fix that line to not be a promise, but just |
Right, yeah, since we are using await it seems that we might not need to
force it to be a promise. I will try to make this patch tomorrow. Is it ok
to make a PR for the 1.x branch too? We are still using it and will be for
a while.
…On Fri, 26 Jun 2020 at 21:55 Tanner Linsley ***@***.***> wrote:
Sorry, yes... no idea why the line numbers didn't paste there. We need to
fix that line to not be a promise, but just useQuery(key, noop, ...)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#639 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOEIJ4QXUJU7JLB2AE3ZKTRYU7RFANCNFSM4OJRDTZA>
.
|
Yep if you can backport the fix that would be fine. |
…Promise.resolve() instead of new Promise(noop) that caused a never ending promise en certain scenarios. Ref bug TanStack#639
@tannerlinsley done with two PRs sir. I noticed we are using |
That one is actually good. It’s so await chains do not proceed for outdated queries. |
shouldn't that be a `Promise.reject("outdated query, do not follow")` type
of error instead? Having never resolving promises seem dangerous way of
flow control.
…On Sun, Jun 28, 2020 at 12:27 AM Tanner Linsley ***@***.***> wrote:
That one is actually good. It’s so await chains do not proceed for
outdated queries.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#639 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOEIJYSYGZPZL7LND47O23RY22BRANCNFSM4OJRDTZA>
.
|
Yeah we could do that. We could improve the cancelled error object and use that. |
I've messed around with this a bit, and I think I'm still in the camp that the retry promise that doesn't fulfill from the document not being visibile should be a noop promise (so side-effects from the promise don't run at all). I'm still 100% on board with the other noops getting resolved like you've done though. |
Just a heads up so that you have them in mind
|
feel free to resolve this bug :) |
I'll figure something out. It might not be as simple as rejecting it though. I'll have to add in a lot of checks for such an error and just to ignore it. |
I’ll also try to take a look
…On Sun, 28 Jun 2020 at 18:12 Tanner Linsley ***@***.***> wrote:
I'll figure something out. It might not be as simple as rejecting it
though. I'll have to add in a lot of checks for such an error and just to
ignore it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#639 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOEIJZNBYXGMYT7NHZFIETRY6W4ZANCNFSM4OJRDTZA>
.
|
The original problem for this issue was resolved, so I'm going to close this. Feel free to open another one if you encounter issues for the other promise noop, or feel free to open a PR with any ideas to get rid of it. |
Thank you! Have a good one!
…On Sun, 28 Jun 2020 at 20:00 Tanner Linsley ***@***.***> wrote:
Closed #639 <#639>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#639 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOEIJ7QAN6P6IG3USYKTW3RY7DRFANCNFSM4OJRDTZA>
.
|
Describe the bug
I have created a very contrived example reproduction code that you can find here:
https://github.com/franleplant/react-query-unresolved-promises/blob/master/src/App.tsx
I say contrived because it doesn't represent real use case but I first found this error
in a closed source company app where, as you probably know, things started to get messy
and there were some interactions between mutation's onSuccess and refetchQueries.
To be a bit more concrete, when we save
EntityA
we refetchEntityA
(because of the way our particular backend works) but since we weren't usingexact: true
it was causing it to refetchEntityA1
via a query that wasn't initialized, so by a semi complex interactions of the query ofEntityA
we also didsetQueryData
ofEntityA1
which caused the problem I explain below.(Sorry, it ended up not being that much more concrete)
I found this bug in react-query 1.x but I have noticed the same code in 2.x
Expected behavior
A mutation promise always resolves to something, either a value or an error.
Desktop (please complete the following information):
Additional context
I have isolated the bug to an edge case interaction between
queryCache.setQueryData
andqueryCache.refetchQuery
(extracted from the repro repo)
Whenever you try to
setQueryData
on a query that hasn't been instantiated react-query gives thequeryFn
a value ofnew Promise(noop)
which is a promise that never resolves.So when you later do
refetchQuery
of that same query you get a promise that never returns and sinceuseMutation
waits for theonSuccess
async function to resolve then it never resolves.We are virtually saying this
This same default value of
new Promise(noop)
is used in 2.x branch.for lib consumers: A workaround is to check that the query that you are trying to setData on has actually an instance
But I wander why we are giving a default value of a promise that never resolves. Can you we change it to
Promise.resolve()
? It seems that the functionality will be maintained but in these sort of edge cases we wont get a promise that never resolves.Let me know what you think @tannerlinsley and I can definitively help with this in both 1.x and 2.x branches.
The text was updated successfully, but these errors were encountered: