-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Cache not updating after mutation when using fallback data in useQuery
#502
Comments
Additionally, the Supabase clients I'm using for both the server and the client are set up following this guide: https://supabase.com/docs/guides/auth/server-side/nextjs?queryGroups=router&router=app |
did you try to pin-point the cause? cache updates are working in normal circumstances, and I wonder what causes it to break here. if |
I’ve made some progress on the issue. Here’s what I found: I noticed that when passing only the const { cache } = useSWRConfig(); When What worked:Instead of passing just Hypothesis:It seems that when passing only I believe this should be corrected in the documentation. Currently, it mentions that you can either pass Let me know if you agree with the analysis, I can do a PR updating the docs! |
After further testing I realized that I was wrong about the solution in my previous comment. I was incorrectly setting the Initially I was passing it as This means that currently, neither approach correctly handles the fallback, setting |
thanks for the detailed investigation! Did you confirm the same behaviour with using plain swr? I am struggling to find the cause in cache helpers for this. |
I ended up using the react-query package. If I remember correctly, the root cause of the issue was that setting This behavior contrasts with react-query, where you have Initial Query Data and Placeholder Query Data. Found a comment that proves this: vercel/swr#2114 (comment) |
Describe the bug
When using mutation hooks with fallback data set in the
useQuery
hook, the cache does not update after triggering a mutation. Specifically, after passing fallback data touseQuery
viafetchQueryFallbackData
,useUpdateMutation
doesn't seem to update the cache as expected.To Reproduce
Steps to reproduce the behavior:
useQuery
withfallbackData
as shown in the example below:useUpdateMutation
to update a user record:Expected behavior
The cache should be updated after a mutation when using
useQuery
withfallbackData
.Additional context
revalidateIfStale: true
, either directly in the hook or globally viaSWRConfig
, resolves the issue and updates the cache as expected.The text was updated successfully, but these errors were encountered: