-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Describe the bug
After upgrading to react-query 3.5.11 from 2.26.4 last week, our project's Cypress tests started failing randomly because the app started showing a loading spinner at random times. After a lot of head-banging, we finally tracked down the issue: even though, based on the network inspector, the request had gone through successfully, react-query's useQuery
was returning an object with isLoading
as true
and data
as undefined
. Reverting back to react-query 2 fixed the problems.
Most of the requests in our Cypress tests are stubbed using cy.server
and cy.route
. This probably shouldn't affect react-query but mentioning it here just in case.
Our cache is configured in the following manner at the top of one of our source files, so this shouldn't be caused by us accidentally creating multiple caches:
const queryCache = new QueryCache({
defaultConfig: {
queries: {
staleTime: 10 * 60 * 1000,
cacheTime: 15 * 60 * 1000,
retry: (
_failureCount,
error: any,
) => error.status !== 403 && error.status !== 401,
},
},
});
// Further down:
class AppProvider extends Component<{}, State> {
public render() {
return (
<ReactQueryCacheProvider queryCache={queryCache}>
{/* ... */}
</ReactQueryCacheProvider>
);
}
}
To Reproduce
Unfortunately, this happens randomly and is thus very hard to reproduce. The randomness does point towards some type of race condition. Our app performs many (~10) requests on startup.
Even though which tests fail is random, I can consistently get at least one test to fail. Is there something I can do to help track down what could be the issue?
Expected behavior
useQuery
should return the data it receives in the response once the request is successful.
Desktop (please complete the following information):
- OS: MacOS
- Browser: Chrome
- Version: 87
Additional context
Happens on both Cypress version 5.3.0 and 6.2.1.