Skip to content

Commit

Permalink
Send state from background when monitor connects (#1771)
Browse files Browse the repository at this point in the history
* Send state from background on connection

* Create green-hats-kick.md
  • Loading branch information
Methuselah96 authored Sep 21, 2024
1 parent 41fae27 commit b25bf13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-hats-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'remotedev-redux-devtools-extension': patch
---

Send state from background when monitor connects
27 changes: 27 additions & 0 deletions extension/src/background/store/apiMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,33 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
};
port.onMessage.addListener(listener);
port.onDisconnect.addListener(disconnect('panel', id, listener));

const { current } = store.getState().instances;
if (current !== 'default') {
const connectionId = Object.entries(
store.getState().instances.connections,
).find(([, instanceIds]) => instanceIds.includes(current))?.[0];
const options = store.getState().instances.options[current];
const state = store.getState().instances.states[current];
const { actionsById, computedStates, committedState, ...rest } = state;
toMonitors({
type: UPDATE_STATE,
request: {
type: 'STATE',
payload: rest as Omit<
LiftedState<S, A, unknown>,
'actionsById' | 'computedStates' | 'committedState'
>,
source: '@devtools-page',
instanceId:
typeof current === 'number' ? current.toString() : current,
actionsById: stringifyJSON(actionsById, options.serialize),
computedStates: stringifyJSON(computedStates, options.serialize),
committedState: typeof committedState !== 'undefined',
},
id: connectionId ?? current,
});
}
}
}

Expand Down

0 comments on commit b25bf13

Please sign in to comment.