···11+---
22+'@urql/core': patch
33+---
44+55+Fix issue where a reexecute on an in-flight operation would lead to multiple network-requests.
66+For example, this issue presents itself when Graphcache is concurrently updating multiple, inter-dependent queries with shared entities. One query completing while others are still in-flight may lead to duplicate operations being issued.
···643643 // Store replay result
644644 onPush(result => {
645645 if (result.stale) {
646646- // If the current result has queued up an operation of the same
647647- // key, then `stale` refers to it
648648- for (const operation of queue) {
649649- if (operation.key === result.operation.key) {
650650- dispatched.delete(operation.key);
651651- break;
646646+ if (!result.hasNext) {
647647+ // we are dealing with an optimistic mutation or a partial result
648648+ dispatched.delete(operation.key);
649649+ } else {
650650+ // If the current result has queued up an operation of the same
651651+ // key, then `stale` refers to it
652652+ for (const operation of queue) {
653653+ if (operation.key === result.operation.key) {
654654+ dispatched.delete(operation.key);
655655+ break;
656656+ }
652657 }
653658 }
654659 } else if (!result.hasNext) {
···697702 // operation's exchange results
698703 if (operation.kind === 'teardown') {
699704 dispatchOperation(operation);
700700- } else if (operation.kind === 'mutation' || active.has(operation.key)) {
701701- let queued = false;
702702- for (let i = 0; i < queue.length; i++)
703703- queued = queued || queue[i].key === operation.key;
704704- if (!queued) dispatched.delete(operation.key);
705705+ } else if (operation.kind === 'mutation') {
705706 queue.push(operation);
706707 Promise.resolve().then(dispatchOperation);
708708+ } else if (active.has(operation.key)) {
709709+ let queued = false;
710710+ for (let i = 0; i < queue.length; i++) {
711711+ if (queue[i].key === operation.key) {
712712+ queue[i] = operation;
713713+ queued = true;
714714+ }
715715+ }
716716+717717+ if (
718718+ !queued &&
719719+ (!dispatched.has(operation.key) ||
720720+ operation.context.requestPolicy === 'network-only')
721721+ ) {
722722+ queue.push(operation);
723723+ Promise.resolve().then(dispatchOperation);
724724+ } else {
725725+ dispatched.delete(operation.key);
726726+ Promise.resolve().then(dispatchOperation);
727727+ }
707728 }
708729 },
709730