Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix DevTools from losing connection #1767

Merged
merged 2 commits into from
Sep 20, 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/kind-seals-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'remotedev-redux-devtools-extension': patch
---

Fix DevTools from losing connection
6 changes: 6 additions & 0 deletions extension/src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ chrome.storage.onChanged.addListener((changes) => {
else removeMenu();
}
});

// https://developer.chrome.com/docs/extensions/develop/migrate/to-service-workers#keep_a_service_worker_alive_continuously
setInterval(
() => chrome.storage.local.set({ 'last-heartbeat': new Date().getTime() }),
20000,
);
6 changes: 2 additions & 4 deletions extension/src/background/store/apiMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
console.log(`Connected to tab ${id}`);
if (port.sender!.frameId) id = `${id}-${port.sender!.frameId}`;
connections.tab[id] = port;
listener = (msg: ContentScriptToBackgroundMessage<S, A> | 'heartbeat') => {
if (msg === 'heartbeat') return;
listener = (msg: ContentScriptToBackgroundMessage<S, A>) => {
console.log(`Message from tab ${id}: ${msg.name}`);
if (msg.name === 'INIT_INSTANCE') {
if (typeof id === 'number') {
Expand Down Expand Up @@ -593,8 +592,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
connections.panel[id] = port;
monitors++;
toAllTabs({ type: 'START' });
listener = (msg: BackgroundAction | 'heartbeat') => {
if (msg === 'heartbeat') return;
listener = (msg: BackgroundAction) => {
console.log(`Message from monitor ${id}: ${msg.type}`);
store.dispatch(msg);
};
Expand Down
4 changes: 0 additions & 4 deletions extension/src/contentScript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,3 @@ function handleMessages<S, A extends Action<string>>(
prefetchOptions();

window.addEventListener('message', handleMessages, false);

setInterval(() => {
bg?.postMessage('heartbeat');
}, 15000);
4 changes: 0 additions & 4 deletions extension/src/devpanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ function init() {
}
bgConnection = chrome.runtime.connect({ name });

setInterval(() => {
bgConnection.postMessage('heartbeat');
}, 15000);

bgConnection.onMessage.addListener(
<S, A extends Action<string>>(
message: PanelMessageWithSplitAction<S, A>,
Expand Down
Loading