Closed JoviDeCroock closed 2 months ago
Latest commit: b82e18477da7e683c42d4ecbcffcdfdcef9a6246
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Resolves #3565
Summary
In the initial issue we were faced with the following problem, imagine a query that returns a list with values
[Todo:1, Todo:2]
we use this list to return components that in turn has its own query to fetch the details of thisTodo
. Both this list and the details have a shared parent field let's name itQuery.author
, this is important for graph-cache to re-dispatch operations.This diagram of this looks like the following
Notice that we re-dispatch
Todo:2
even though it is already in-flight, this is problematic as in the cache it has not resolved to a response yet and hence we send off multiple network requests. This issue becomes more and more apparent given more queries being in-flight. The lines causing this issue can be found here since there is no operation queued we will always remove the operation from our in-flight operations.The solution here is to change this logic to only remove
dispatched
on a queued operation that either is already indispatched
or isnetwork-only
.The above fix however re-introduces the issue we faced in https://github.com/urql-graphql/urql/issues/3254 this due to our optimistic mutation re-triggering the operation and resulting in
stale
and then our real data re-triggering the query but it already having been dispatched. This because we have similar logic in theonPush
part of ouroperation
. When it's stale we'll check the queue whether there is an operation in there, however there won't be as we are dealing with an optimistic mutation re-trigger, to fix this I added a check whether the stale result has a next payload coming, if not it gets deleted form dispatched either way.I think the above
stale
flag fix is the root cause that needed to be addressed in #3254 but I am not a 100% sure as I got a bit overloaded while leveragingconsole.log
in all of these reproductions 😅