[Bug] First revalidate() + refetch() does not refresh data
Describe the bug
When using createResource + query, and doing a revalidate(key) + refetch, the first invocation will not refresh data. After that, it works correctly.
Your Example Website or App
https://stackblitz.com/edit/solidjs-templates-spywaw?file=src%2FApp.tsx
Steps to Reproduce the Bug or Issue
Press the button, you would expect every click to update the timestamp, however the first click will not cause a refetch
To repeatedly reproduce you'll have to refresh the project in Stackblitz (or F5 when running locally).
Expected behavior
The first click also refreshes the data
Screenshots or Videos
No response
Platform
Stackblitz and Ubuntu
Additional context
No response
Found same issue
It's because of the way createResource works. It has to do with the serialization cache the value on hydration and where it falls in the resolution chain. This isn't going to get changed before 2.0 as I needed to sort of hack around it which is a large part why I want to move away from it. createAsync works fine. But if you want createResource to work you need to put the body in the first function and pass the value through like:
const [data, { refetch }] = createResource(() => clicky(), v => v);
If you do that you don't even need to call refetch. revalidate will automatically refetch just like it does with createAsync.
@ryansolid I just noticed my repro doesn't line up with what I'm actually doing.
The query fn should be the fetcher function, and the first function is actually taking a URL param (just hard coded in the repro).
Moreover, I found an... interesting workaround:
revalidate('clicky');
await new Promise((resolve) => setTimeout(resolve, 1));
refetch();
Here's the updated repro: https://stackblitz.com/edit/solidjs-templates-5kavuukb?file=src%2FApp.tsx