Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix: only send data to extension if DevTools are open #1735

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-apples-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'remotedev-redux-devtools-extension': patch
---

Fix: only send data to extension if DevTools are open
20 changes: 7 additions & 13 deletions extension/src/background/store/apiMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ const chunks: {
>;
} = {};
let monitors = 0;
let isMonitored = false;

const getId = (sender: chrome.runtime.MessageSender, name?: string) =>
sender.tab ? sender.tab.id! : name || sender.id!;
Expand All @@ -262,12 +263,7 @@ type MonitorAction<S, A extends Action<string>> =
// Chrome message limit is 64 MB, but we're using 32 MB to include other object's parts
const maxChromeMsgSize = 32 * 1024 * 1024;

// TODO Clean up args
function toMonitors<S, A extends Action<string>>(
action: MonitorAction<S, A>,
tabId?: string | number,
verbose?: boolean,
) {
function toMonitors<S, A extends Action<string>>(action: MonitorAction<S, A>) {
for (const port of [
...Object.values(connections.monitor),
...Object.values(connections.panel),
Expand Down Expand Up @@ -417,6 +413,7 @@ function toAllTabs(msg: TabMessage) {
}

function monitorInstances(shouldMonitor: boolean, id?: string) {
if (!id && isMonitored === shouldMonitor) return;
const action = {
type: shouldMonitor ? ('START' as const) : ('STOP' as const),
};
Expand All @@ -425,6 +422,7 @@ function monitorInstances(shouldMonitor: boolean, id?: string) {
} else {
toAllTabs(action);
}
isMonitored = shouldMonitor;
}

function getReducerError() {
Expand Down Expand Up @@ -499,7 +497,7 @@ function messaging<S, A extends Action<string>>(
}
if (request.type === 'ERROR') {
if (request.payload) {
toMonitors(request, tabId);
toMonitors(request);
return;
}
if (!request.message) return;
Expand Down Expand Up @@ -541,11 +539,7 @@ function messaging<S, A extends Action<string>>(
}
store.dispatch(action);

if (request.type === 'EXPORT') {
toMonitors(action, tabId, true);
} else {
toMonitors(action, tabId);
}
toMonitors(action);
}

function disconnect(
Expand Down Expand Up @@ -587,7 +581,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
chrome.action.enable(id);
chrome.action.setIcon({ tabId: id, path: 'img/logo/38x38.png' });
}
port.postMessage({ type: 'START' });
if (isMonitored) port.postMessage({ type: 'START' });

const state = store.getState();
if (state.instances.persisted) {
Expand Down
Loading