From 6c8e4c85df8d34cd525696134fe9fc65f66786e5 Mon Sep 17 00:00:00 2001 From: Alek Angelov Date: Tue, 13 Dec 2022 12:19:47 +0100 Subject: [PATCH 1/3] feat: add prevent broadcast option in QueryManager --- src/core/ApolloClient.ts | 7 +++++++ src/core/QueryManager.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index b26da37e579..fae22119ca4 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -60,6 +60,7 @@ export type ApolloClientOptions = { fragmentMatcher?: FragmentMatcher; name?: string; version?: string; + notifyOnTeardown?: boolean; }; // Though mergeOptions now resides in @apollo/client/utilities, it was @@ -123,6 +124,10 @@ export class ApolloClient implements DataProxy { * version of your client, which you may want to increment on * new builds. This is NOT the version of Apollo Client that * you are using. + * + * @param notifyOnTeardown Defaults to true, but when set to false will + * prevent the client from notifying any active queries. + * Could result in substantial performance gains in some cases. */ constructor(options: ApolloClientOptions) { const { @@ -147,6 +152,7 @@ export class ApolloClient implements DataProxy { fragmentMatcher, name: clientAwarenessName, version: clientAwarenessVersion, + notifyOnTeardown = true } = options; let { link } = options; @@ -253,6 +259,7 @@ export class ApolloClient implements DataProxy { }); } } : void 0, + notifyOnTeardown }); } diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 36fac27ef13..9b6a58d3bbf 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -85,6 +85,7 @@ export class QueryManager { public link: ApolloLink; public defaultOptions: DefaultOptions; + public readonly notifyOnTeardown: boolean; public readonly assumeImmutableResults: boolean; public readonly ssrMode: boolean; @@ -115,6 +116,7 @@ export class QueryManager { clientAwareness = {}, localState, assumeImmutableResults, + notifyOnTeardown = true }: { cache: ApolloCache; link: ApolloLink; @@ -125,6 +127,7 @@ export class QueryManager { clientAwareness?: Record; localState?: LocalState; assumeImmutableResults?: boolean; + notifyOnTeardown?: boolean; }) { this.cache = cache; this.link = link; @@ -134,6 +137,7 @@ export class QueryManager { this.localState = localState || new LocalState({ cache }); this.ssrMode = ssrMode; this.assumeImmutableResults = !!assumeImmutableResults; + this.notifyOnTeardown = !!notifyOnTeardown; if ((this.onBroadcast = onBroadcast)) { this.mutationStore = Object.create(null); } @@ -915,6 +919,7 @@ export class QueryManager { public stopQuery(queryId: string) { this.stopQueryNoBroadcast(queryId); + if(!this.notifyOnTeardown) return; this.broadcastQueries(); } From 05d7f86c8194883db5e0aea556bfdc68643b6658 Mon Sep 17 00:00:00 2001 From: Alek Angelov Date: Tue, 13 Dec 2022 12:53:35 +0100 Subject: [PATCH 2/3] chore(changeset): added changeset for patch --- .changeset/giant-icons-sit.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/giant-icons-sit.md diff --git a/.changeset/giant-icons-sit.md b/.changeset/giant-icons-sit.md new file mode 100644 index 00000000000..50f3b54cf7d --- /dev/null +++ b/.changeset/giant-icons-sit.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Added option to prevent broadcasting on query teardown. May increase performance. From 2e68a732baf7132e666e271a5cc7c4c9c3f0d6c4 Mon Sep 17 00:00:00 2001 From: Alek Angelov Date: Tue, 13 Dec 2022 13:00:26 +0100 Subject: [PATCH 3/3] chore(filesize): bump filesize limit by 0.03KB --- config/bundlesize.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/bundlesize.ts b/config/bundlesize.ts index b628fb88013..37cf95e8f51 100644 --- a/config/bundlesize.ts +++ b/config/bundlesize.ts @@ -3,7 +3,7 @@ import { join } from "path"; import { gzipSync } from "zlib"; import bytes from "bytes"; -const gzipBundleByteLengthLimit = bytes("31.87KB"); +const gzipBundleByteLengthLimit = bytes("31.9KB"); const minFile = join("dist", "apollo-client.min.cjs"); const minPath = join(__dirname, "..", minFile); const gzipByteLen = gzipSync(readFileSync(minPath)).byteLength;