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;