vercel / swr-site

The official website for SWR.
https://swr.vercel.app
Apache License 2.0
481 stars 351 forks source link

Feedback for “Cache” - Clear Cache function / example #571

Open SimonKraushaar opened 5 months ago

SimonKraushaar commented 5 months ago

I have been receiving stale error states from SWR when navigating back to a page after a login ( SWR reports an error, page redirects, using logs in setting tokens, and then navigates back to the page, the error is still set and displays an error until the SWR fetch result has been completed, this can take a second or so where my "Not Authorized" page is present until its refreshed.)

To rectify this the only way i can seem able to do this is clear the cache using mutate(() => true, undefined, { revalidate: false }); to initiate a "new" session.

But it seems to me that errors should not be cached anyway? if a previous error exists in the cache, should useSWR immediately re-fetch, clearing the cache and setting {isLoading } - if not, is there a flag I am missing that would force such a thing on the hook itself?

Perhaps I am miss understanding the flow?