Skip to content
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

[Bug] First revalidate() + refetch() does not refresh data #497

Open
marvin-j97 opened this issue Nov 16, 2024 · 3 comments
Open

[Bug] First revalidate() + refetch() does not refresh data #497

marvin-j97 opened this issue Nov 16, 2024 · 3 comments

Comments

@marvin-j97
Copy link
Contributor

marvin-j97 commented Nov 16, 2024

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

@Eliot00
Copy link

Eliot00 commented Dec 7, 2024

Found same issue

@marvin-j97 marvin-j97 changed the title First revalidate() + refetch() does not refresh data [Bug] First revalidate() + refetch() does not refresh data Dec 7, 2024
@ryansolid
Copy link
Member

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.

@marvin-j97
Copy link
Contributor Author

marvin-j97 commented Dec 11, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants