From e8c8e704ab370508a9462299a7958bce9da01023 Mon Sep 17 00:00:00 2001 From: Daniel Vicory Date: Tue, 15 Feb 2022 20:05:05 -0800 Subject: [PATCH] Fix bug where if you first start the exchanges with server offline, it will never show optimistic results Also use a cache-only requestPolicy to prevent refetching queries every time. It seems that cache-first gets upgraded to cache-and-network by graphcache upon receiving a mutation result. It's not known why it decides to do this right now. This was caused by the dedup exchange filtering out the reexecuted queries, believe them to be extraneous. It would never see the OperationResult coming back since server offline causes uncaught errors to be thrown from the fetch exchange. That in turn causes no errored results to come back. The easy fix is to simply place queries on the rebound channel, rather than reexecuting them through the client. Whether or not this is "correct" is hard to say. The underlying fix should be tracked via https://github.com/FormidableLabs/urql/issues/2234 --- src/exchanges/crdtExchange.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exchanges/crdtExchange.ts b/src/exchanges/crdtExchange.ts index 8fbff03..bcee1aa 100644 --- a/src/exchanges/crdtExchange.ts +++ b/src/exchanges/crdtExchange.ts @@ -280,7 +280,7 @@ class CrdtManager { const dependentQueries = new Set(); this.collectDependentQueries(dependentQueries, mutation); for (const dependentQuery of dependentQueries) { - this.#client.reexecuteOperation(toRequestPolicy(dependentQuery, 'cache-first')); + this.#next(toRequestPolicy(dependentQuery, 'cache-only')); } if (!this.#unsubscribe) { @@ -484,7 +484,7 @@ class CrdtManager { this.updateOptimisticState(this.#mutations.values()); for (const dependentQuery of dependentQueries) { - this.#client.reexecuteOperation(toRequestPolicy(dependentQuery, 'cache-first')); + this.#next(toRequestPolicy(dependentQuery, 'cache-only')); } }