diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index fe7eb284bdd..896847bb6d6 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -28,6 +28,7 @@ import { TypePolicies, } from './policies'; import { hasOwn } from './helpers'; +import { resetStringifyCanon } from './object-canon'; export interface InMemoryCacheConfig extends ApolloReducerConfig { resultCaching?: boolean; @@ -262,6 +263,7 @@ export class InMemoryCache extends ApolloCache { // Request garbage collection of unreachable normalized entities. public gc() { + resetStringifyCanon(); return this.optimisticData.gc(); } @@ -322,6 +324,7 @@ export class InMemoryCache extends ApolloCache { public reset(): Promise { this.init(); this.broadcastWatches(); + resetStringifyCanon(); return Promise.resolve(); } diff --git a/src/cache/inmemory/object-canon.ts b/src/cache/inmemory/object-canon.ts index 84c7c008cd6..a933b36a280 100644 --- a/src/cache/inmemory/object-canon.ts +++ b/src/cache/inmemory/object-canon.ts @@ -194,7 +194,10 @@ type SortedKeysInfo = { json: string; }; -const stringifyCanon = new ObjectCanon; +let stringifyCanon = new ObjectCanon; +export function resetStringifyCanon() { + stringifyCanon = new ObjectCanon; +} const stringifyCache = new WeakMap(); // Since the keys of canonical objects are always created in lexicographically