-
-
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
suspense useQuery infinite loop when query goes from success to false and query key changes #2187
Comments
I could look into fixing it, but not sure where to even start on this one |
I have to quit for the day, but I tracked this down to this line not being called but it should be: https://github.com/tannerlinsley/react-query/blob/master/src/react/useBaseQuery.ts#L135 |
This comment has been minimized.
This comment has been minimized.
not sure if I'm of much help here. At the time where the line in question is called,
|
Ok
…On Sat, Apr 24, 2021, 11:29 AM Dominik Dorfmeister ***@***.***> wrote:
but I tracked this down to this line not being called but it should be:
not sure if I'm of much help here. At the time where the line in question
is called, result.isError is still false. When we log it, we can se that
we still have one render cycle where succeed is true. When the infinite
loop starts, we somehow never even get to this line of code....
console.log
query query_1-true
at src/react/tests/suspense.test.tsx:35:19
console.log
result.isError false
at useBaseQuery (src/react/useBaseQuery.ts:130:11)
console.log
query query_1-true
at src/react/tests/suspense.test.tsx:35:19
console.log
query query_1-false
at src/react/tests/suspense.test.tsx:35:19
console.log
query query_1-false
at src/react/tests/suspense.test.tsx:35:19
console.log
query query_1-false
at src/react/tests/suspense.test.tsx:35:19
console.log
query query_1-false
at src/react/tests/suspense.test.tsx:35:19
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2187 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOMGT5WEN2SW6DO27VXEDC3TKKMP3ANCNFSM43PHVW4A>
.
|
Whew, I spent awhile digging into this more. Haven't really got anywhere, but I did find that when query key changes, query Also it almost appears as if there are two observers for the same query fighting each other 🤔 This change actually fixes this bug, but breaks a few other tests. // src/core/queryObserver.ts
fetchOptimistic(
options: QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>
): Promise<QueryObserverResult<TData, TError>> {
const defaultedOptions = this.client.defaultQueryObserverOptions(options)
const query = this.client
.getQueryCache()
.build(
this.client,
defaultedOptions as QueryOptions<
TQueryFnData,
TError,
TQueryData,
TQueryKey
>
)
+ if (query.state.status === 'error') {
+ throw query.state.error
+ }
return query.fetch().then(() => this.createResult(query, defaultedOptions))
} I'd be grateful if someone else could take this from here. |
same issue in react-query 3.18.0 version |
Change this condition to not change the status of result to 'loading' when state.status is 'error' Fixes TanStack#2187
Change this condition to not change the status of result to 'loading' when state.status is 'error' Fixes TanStack#2187
Change this condition to not change the status of result to 'loading' when state.status is 'error' Fixes TanStack#2187
🎉 This issue has been resolved in version 3.19.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
the change in shouldFetchOptionally was introduced in TanStack#2556 to avoid an infinite loop wen using suspense (see TanStack#2187), but it broke the case where we're switching keys between two erroneous queries - they now didn't refetch even though they should this fix scopes the error check to only usages where suspense is turned on, so that we get the same behaviour as in v3.19.4 for non-suspense users, while still having the fix for suspense users
Describe the bug
The workaround in #2157 fixed only part of the issue we are having in Blitz. We still have a case on user logout where we get infinite loops.
Failing test case included below. They key thing that makes it go into the infinite loop is the query key changing. If the key doesn't change, then it works fine.
To Reproduce
Add the following test to
src/react/tests/suspense.test.tsx
Version
React-query 3.13.9
The text was updated successfully, but these errors were encountered: