From 5d7574411f08da4605d3b53c16747adaaa13562c Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Fri, 26 Jan 2024 08:00:25 -0700 Subject: [PATCH] Stop broadcasting events with no listener (#1198) * Remove unused CLIENT_FOUND message * Remove unused PANEL_CLOSED and PANEL_OPEN events * Add changeset --- .changeset/pretty-carrots-rest.md | 9 +++++++++ src/extension/constants.ts | 3 --- src/extension/devtools/devtools.ts | 5 ----- src/extension/tab/hook.ts | 2 -- src/extension/tab/tabRelay.ts | 2 -- 5 files changed, 9 insertions(+), 12 deletions(-) create mode 100644 .changeset/pretty-carrots-rest.md diff --git a/.changeset/pretty-carrots-rest.md b/.changeset/pretty-carrots-rest.md new file mode 100644 index 000000000..719872680 --- /dev/null +++ b/.changeset/pretty-carrots-rest.md @@ -0,0 +1,9 @@ +--- +"apollo-client-devtools": patch +--- + +Stop broadcasting messages that aren't listened to by the extension. + +- `client-found` +- `panel-open` +- `panel-closed` diff --git a/src/extension/constants.ts b/src/extension/constants.ts index 6e668d75f..e365fe6d7 100644 --- a/src/extension/constants.ts +++ b/src/extension/constants.ts @@ -1,12 +1,9 @@ -export const CLIENT_FOUND = "client-found"; export const REQUEST_TAB_ID = "request-tab-id"; export const DEVTOOLS_INITIALIZED = "devtools-initialized"; export const CREATE_DEVTOOLS_PANEL = "create-devtools-panel"; export const ACTION_HOOK_FIRED = "action-hook-fired"; export const REQUEST_DATA = "request-data"; export const UPDATE = "update"; -export const PANEL_OPEN = "panel-open"; -export const PANEL_CLOSED = "panel-closed"; export const EXPLORER_REQUEST = "explorer-request"; export const EXPLORER_RESPONSE = "explorer-response"; export const RELOADING_TAB = "reloading-tab"; diff --git a/src/extension/devtools/devtools.ts b/src/extension/devtools/devtools.ts index e042f242f..a9ff51883 100755 --- a/src/extension/devtools/devtools.ts +++ b/src/extension/devtools/devtools.ts @@ -5,8 +5,6 @@ import { CREATE_DEVTOOLS_PANEL, REQUEST_DATA, UPDATE, - PANEL_OPEN, - PANEL_CLOSED, EXPLORER_REQUEST, RELOADING_TAB, RELOAD_TAB_COMPLETE, @@ -78,8 +76,6 @@ devtools.listen(CREATE_DEVTOOLS_PANEL, async ({ payload }) => { let removeExplorerListener: () => void; panel.onShown.addListener((window) => { - sendMessageToClient(PANEL_OPEN); - const { __DEVTOOLS_APPLICATION__: { initialize, @@ -148,7 +144,6 @@ devtools.listen(CREATE_DEVTOOLS_PANEL, async ({ payload }) => { removeReloadListener(); removeExplorerListener(); devtools.removeConnection("explorer"); - sendMessageToClient(PANEL_CLOSED); }); }); diff --git a/src/extension/tab/hook.ts b/src/extension/tab/hook.ts index 616bc6e8e..5a45493d2 100755 --- a/src/extension/tab/hook.ts +++ b/src/extension/tab/hook.ts @@ -23,7 +23,6 @@ import { } from "./helpers"; import { ExplorerResponse, QueryResult } from "../../types"; import { - CLIENT_FOUND, DEVTOOLS_INITIALIZED, CREATE_DEVTOOLS_PANEL, ACTION_HOOK_FIRED, @@ -280,7 +279,6 @@ function initializeHook() { }); clearInterval(interval); - sendMessageToTab(CLIENT_FOUND); // incase initial update was missed because the client wasn't ready, send the create devtools event. // devtools checks to see if it's already created, so this won't create duplicate tabs sendHookDataToDevTools(CREATE_DEVTOOLS_PANEL); diff --git a/src/extension/tab/tabRelay.ts b/src/extension/tab/tabRelay.ts index 9c91cec7a..1ee8b2e58 100644 --- a/src/extension/tab/tabRelay.ts +++ b/src/extension/tab/tabRelay.ts @@ -1,6 +1,5 @@ import Relay from "../../Relay"; import { - CLIENT_FOUND, REQUEST_TAB_ID, CREATE_DEVTOOLS_PANEL, ACTION_HOOK_FIRED, @@ -41,7 +40,6 @@ export default new Promise(async ($export) => { }); const devtools = `background:devtools-${id}`; - tab.forward(CLIENT_FOUND, devtools); tab.forward(CREATE_DEVTOOLS_PANEL, devtools); tab.forward(ACTION_HOOK_FIRED, devtools); tab.forward(UPDATE, devtools);