ConsoleTVs / sswr

🔥 Svelte stale while revalidate (SWR) data fetching strategy
MIT License
234 stars 11 forks source link

make revalidate() fires immediately? #28

Closed halindraprakoso closed 2 years ago

halindraprakoso commented 2 years ago

hey first of all thanks for the awesome plugin.

when using revalidate(), it doesn't seem to refetch the data immediately, but I have to click out the window and click back again. is it possible to make it immediately fires when called?

ConsoleTVs commented 2 years ago

You are talking about window focus revalidation. Can you post a sample code with this revalidation call not being evaludated?

halindraprakoso commented 2 years ago

Maybe it's my misunderstanding, but my issue has since resolved by using mutate instead. Nevertheless, the issue was like the following: for instance I have this fetch:

let { data } = useSWR('profile', {
        fetcher: () => fetcher(),
        dedupingInterval: 900 * 1000
});

$data is displayed as a list. Then if I make some changes to the data, I want the list to display the fresh data, so I call:

revalidate('profile', { force: true })

I expected the refetch will happen immediately, but it's like what I described before.

ConsoleTVs commented 2 years ago

It's strange...

First, can u try getting the revalidate function that's given by useSWR instead of the global one?

It is strance, since when you're forcing, this should trigger the request:

https://github.com/ConsoleTVs/swrev/blob/master/src/SWR.ts#L108

halindraprakoso commented 2 years ago

ohh if I again passed on the fetcher function to the revalidate() function, it refetches immediately!