-
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
Error cached on suspenseQuery #12181
Comments
Hey @mehdiSlam 👋 Appreciate the reproduction! The That said, it looks like what's happening is that the Incidentally, this is something we've actually tested for. You can see how the test waits for the apollo-client/src/react/hooks/__tests__/useSuspenseQuery.test.tsx Lines 3669 to 3699 in 10c8755
That said, I would agree that this isn't super great DX as-is. I'll see if I can play around with this a bit and figure out how to dispose of the |
Thanks for the explanation @jerelmiller . Indeed we found this "problem" in a test where two unit tests shared the same Apollo client but tested two different errors. The second test failed because of this delay. const suspenseCacheSymbol = Symbol.for(‘apollo.suspenseCache’);
if (myApolloClient[suspenseCacheSymbol]) {
delete myApolloClient[suspenseCacheSymbol];
} Using the fake timeout is more appropriate There are very few real cases where this delay could be a problem, and at worst it would be resolved after 30 seconds. |
Hey @mehdiSlam 👋 So sorry for my delayed response. This does work, but I'm curious why you share a client between multiple tests? We'd recommend against that mostly to avoid carrying internal state/caches around between tests which might add implicit dependencies between them (like you're seeing here). If you're able to, I'd highly recommend recreating your client for each test so that each test is isolated. That said, if you want something a little more "official", there is a timeout that controls when those cache entries get cleaned up automatically. It defaults to 30s, but you can tweak it by modifying new ApolloClient({
defaultOptions: {
react: {
// Make sure this is long enough to allow the operation to finish fetching
suspense: { autoDisposeTimeoutMs: 1000 }
}
}
}) This will at least reduce that 30s timeout so that its less likely that cache kicks in between tests. |
Hello, Thanks for the tips 👍 |
Issue Description
Hello,
When an error is throw by a suspenseQuery, the result of the error call is cached even if i use 'no-cache' as fetch-policy.
I checked in the code of useSuspenseQuery and a promise containing the error call is cached in the queryRef in the suspense cache and reuse every time.
Example :
Link to Reproduction
https://codesandbox.io/p/devbox/dawn-brook-wl8883
Reproduction Steps
Suspense error
linkThrow fake error server side
and throw error => Error display on the pageHome
linkSuspense error
link@apollo/client
version3.12.2
The text was updated successfully, but these errors were encountered: