From add15f540348a3bb529c66c038c3945b4bd77c04 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 6 Jul 2021 17:50:28 -0400 Subject: [PATCH] Avoid deleting options.nextFetchPolicy after applying it. Despite my vague suggestion in the removed comments that deleting options.nextFetchPolicy somehow helped make the fetchPolicy transition idempotent (a concern that only matters when nextFetchPolicy is a function), leaving options.nextFetchPolicy intact should also be safe/idempotent in virtually all cases, including every case where nextFetchPolicy is just a string, rather than a function. More importantly, leaving options.nextFetchPolicy intact allows it to be applied more than once, which seems to fix issue #6839. --- src/__tests__/client.ts | 4 +--- src/core/ObservableQuery.ts | 5 ----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/__tests__/client.ts b/src/__tests__/client.ts index c810a705fad..a0f822d3e1b 100644 --- a/src/__tests__/client.ts +++ b/src/__tests__/client.ts @@ -3319,7 +3319,6 @@ describe('@connection', () => { // again to perform an additional transition. this.nextFetchPolicy = fetchPolicy => { ++nextFetchPolicyCallCount; - expect(fetchPolicy).toBe("cache-and-network"); return "cache-first"; }; return "cache-and-network"; @@ -3372,9 +3371,8 @@ describe('@connection', () => { client.cache.evict({ fieldName: "count" }); } else if (handleCount === 6) { expect(result.data).toEqual({ count: 2 }); - expect(nextFetchPolicyCallCount).toBe(3); + expect(nextFetchPolicyCallCount).toBe(4); expect(obs.options.fetchPolicy).toBe("cache-first"); - expect(obs.options.nextFetchPolicy).toBeUndefined(); setTimeout(resolve, 50); } else { reject("too many results"); diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts index a0825f65888..25bb97179e5 100644 --- a/src/core/ObservableQuery.ts +++ b/src/core/ObservableQuery.ts @@ -732,11 +732,6 @@ export function applyNextFetchPolicy( } = options; if (nextFetchPolicy) { - // The options.nextFetchPolicy transition should happen only once, but it - // should also be possible (though uncommon) for a nextFetchPolicy function - // to set options.nextFetchPolicy to perform an additional transition. - options.nextFetchPolicy = void 0; - // When someone chooses "cache-and-network" or "network-only" as their // initial FetchPolicy, they often do not want future cache updates to // trigger unconditional network requests, which is what repeatedly