From 4dce8673b1757d8a3a4edd2996d780e86fad14e3 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 29 Nov 2023 12:19:14 +0100 Subject: [PATCH] `QueryManager.transformCache`: use `WeakCache` (#11387) Co-authored-by: phryneas --- .changeset/shaggy-sheep-pull.md | 5 +++++ .size-limits.json | 4 ++-- src/core/QueryManager.ts | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/shaggy-sheep-pull.md diff --git a/.changeset/shaggy-sheep-pull.md b/.changeset/shaggy-sheep-pull.md new file mode 100644 index 00000000000..9c4ac23123b --- /dev/null +++ b/.changeset/shaggy-sheep-pull.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +`QueryManager.transformCache`: use `WeakCache` instead of `WeakMap` diff --git a/.size-limits.json b/.size-limits.json index ee06be421b2..203fbb531d2 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 38625, - "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32203 + "dist/apollo-client.min.cjs": 38630, + "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32213 } diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 98ab4d1d1f4..f6c471ef840 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -4,6 +4,7 @@ import type { DocumentNode } from "graphql"; // TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356) type OperationTypeNode = any; import { equal } from "@wry/equality"; +import { WeakCache } from "@wry/caches"; import type { ApolloLink, FetchResult } from "../link/core/index.js"; import { execute } from "../link/core/index.js"; @@ -27,7 +28,6 @@ import { hasClientExports, graphQLResultHasError, getGraphQLErrorsFromResult, - canUseWeakMap, Observable, asyncMap, isNonEmptyArray, @@ -651,10 +651,10 @@ export class QueryManager { return this.documentTransform.transformDocument(document); } - private transformCache = new (canUseWeakMap ? WeakMap : Map)< + private transformCache = new WeakCache< DocumentNode, TransformCacheEntry - >(); + >(/** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */); public getDocumentInfo(document: DocumentNode) { const { transformCache } = this;