-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
query re runs after a a mutation and cache update #6702
Comments
I created 2 codesandbox examples to showcase this issue! |
If I'm understanding the flow correctly, it sounds like you want those queries to start out with If you update to const { loading, data } = useQuery(THE_QUERY, {
// This is the default fetch policy, so you don't usually have to specify it,
// but I wanted to be explicit.
fetchPolicy: "cache-first",
// This means: stop making network requests for this query after the first
// request, but keep listening to the cache. Explicitly refetching still works.
nextFetchPolicy: "cache-only",
// Tolerating partial cache data is probably useful if you can't fall back
// to the network when cache data is incomplete.
returnPartialData: true,
}); If you don't change the fetch policy with |
@tafelito Since @danfernand mentioned #6760, you might also want to check out my comment there: #6760 (comment) |
@benjamn thanks for the response and the detailed explanation.
If by incomplete you mean deleted data, yes, that's the correct flow, I don't need to make an additional request if I deleted an item.
~~Edit Item ~~
@benjamn I have to keep testing this but |
@benjamn we've been testing this for the last couple of days and we found one use case where we couldn't find a proper way to use the combination of As ai detailed before, sometimes we want to request an item, and then if we delete the item from the cache, we wan't to prevent a network request. That works if we do what you suggested before, use the Now the issue we have, is that sometimes, we need to use Isn't that the purpose of doing this? cache.evict({
id: cacheId,
broadcast: false
}); |
@benjamn wrote:
Is that behavior description correct, @benjamn? After setting |
@benjamn Same question as @KeithGillette . Explicit refetching doesn't work for me, and given the code, I'm not sure why it should?
|
@KeithGillette @gbilodeau Ahh, right, that. My take is that we should remove that invariant. Calling |
@KeithGillette @gbilodeau Ok, I've removed that invariant in |
It seems more in line with my (rather new and untested) mental model. Anyway, looking forward to the release, thanks! |
@benjamn I know the OP is already fixed and so the subsequent related issues posted here, but I'm still having the evict issue mentioned here #6702 (comment). This is also related to the issue #6962 I recently opened. Basically what I'm seeing is that even using |
This solution is working for me, thanks |
@benjamn Setting both |
I've spent a few hours debugging the internals and trying to figure out if this is an actual issue or if it's working as intended. or maybe I'm just doing something wrong.
It's a very simple use case
I have 2 queries and 1 mutation. 1 query gets a list of items. The 2 query get's an item by id. I have a page with a list of items, and a second page with the items details. On the details page, I have the mutation where it updates the item. The result of the mutation could be either the item updated, or null in case the items needs to be removed.
What I'm doing is, checking if the returned data is null, I evict the item from the cache, if not, I let AC to update the cache with the results.
When the results are null, the item of course is not automatically deleted from the cache, so I
evict
it from the cache in the update function and then from the read fn in the typePolicy I filter the items withcanRead
.After I finish the update, I go pack to the list page.
The issue I have is that, after the item is updated in the cache, the item details query is executed again, a networks request is made to the server, and since I request an item by id, I get the result back. The item is then back to the cache. And Not only that, when I navigate after the onComplete to the list page, the query for the items list is also executed an another request is made. The request in this case, brings no results, but since I already have the item on the cache, the list query returns that item.
Is it ok that the item details query re runs after the cache update? is there anyway to prevent that? I tried setting the broadcast property from the cache evict to false but that didn't work and as far as I understand, that is used for a different purpose than this. Please correct me if I'm wrong
Versions
The text was updated successfully, but these errors were encountered: