Skip to content

Commit

Permalink
Stop broadcasting events with no listener (#1198)
Browse files Browse the repository at this point in the history
* Remove unused CLIENT_FOUND message

* Remove unused PANEL_CLOSED and PANEL_OPEN events

* Add changeset
  • Loading branch information
jerelmiller committed Jan 26, 2024
1 parent cca7bb9 commit 5d75744
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .changeset/pretty-carrots-rest.md
Original file line number Diff line number Diff line change
@@ -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`
3 changes: 0 additions & 3 deletions src/extension/constants.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
5 changes: 0 additions & 5 deletions src/extension/devtools/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
CREATE_DEVTOOLS_PANEL,
REQUEST_DATA,
UPDATE,
PANEL_OPEN,
PANEL_CLOSED,
EXPLORER_REQUEST,
RELOADING_TAB,
RELOAD_TAB_COMPLETE,
Expand Down Expand Up @@ -78,8 +76,6 @@ devtools.listen<string>(CREATE_DEVTOOLS_PANEL, async ({ payload }) => {
let removeExplorerListener: () => void;

panel.onShown.addListener((window) => {
sendMessageToClient(PANEL_OPEN);

const {
__DEVTOOLS_APPLICATION__: {
initialize,
Expand Down Expand Up @@ -148,7 +144,6 @@ devtools.listen<string>(CREATE_DEVTOOLS_PANEL, async ({ payload }) => {
removeReloadListener();
removeExplorerListener();
devtools.removeConnection("explorer");
sendMessageToClient(PANEL_CLOSED);
});
});

Expand Down
2 changes: 0 additions & 2 deletions src/extension/tab/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
} from "./helpers";
import { ExplorerResponse, QueryResult } from "../../types";
import {
CLIENT_FOUND,
DEVTOOLS_INITIALIZED,
CREATE_DEVTOOLS_PANEL,
ACTION_HOOK_FIRED,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/extension/tab/tabRelay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Relay from "../../Relay";
import {
CLIENT_FOUND,
REQUEST_TAB_ID,
CREATE_DEVTOOLS_PANEL,
ACTION_HOOK_FIRED,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5d75744

Please sign in to comment.