-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Expire errored payload with suspense: true
#160
Comments
It seems like I think this particular issue could possibly be fixed if we set up |
Hi, since #231 got merged you can now clear up the cached error value on your own. import { cache } from 'swr';
// ...
try {
console.log("requesting", { key });
result = useSWR(key, fetcher, { suspense: true });
} catch (err) {
console.log("error", { key });
const [, , errorKey] = cache.serializeKey(key);
cache.delete(errorKey, false);
throw err;
}
// ...
const { data, isValidating, revalidate } = result; |
Thanks a lot @nulladdict, you really helped me. This works for me: let result;
try {
result = useSWR(key, fetcher, { suspense: true });
} catch (err) {
const [, , errorKey] = cache.serializeKey(key);
window.setTimeout(() => cache.delete(errorKey, false));
throw err;
}
const { data, isValidating, revalidate } = result; As you can see I have to delete the cache entry after rethrowing, otherwise it loops indefinitely. Do you have any idea why deleting the entry from the cache could be somehow affecting Suspense's logic? |
Hi @bbenezech, I think the better approach is to clear out cached error in designated error boundary component Couple points to mention:
|
Awesome! I love this, much better. Works for me. I think we should close this? |
I ran into the same problem and found this issue. Thing is, in SWR 1.x the cache has changed such that |
Is there any update on this? How should this be handled? |
I have an error boundary with a retry button that updates its own key to rerender the whole subtree.
I want to retry the failed request on rerender (I use
shouldRetryOnError: false
).I tried to rethrow the error around
useSWR
. I get the logs, but on next render, the xhr request isn't refired, but SWR reraises the same error as before :(Any pointer?
Thx a lot!
The text was updated successfully, but these errors were encountered: