Skip to content

Commit b25bf13

Browse files
authored
Send state from background when monitor connects (#1771)
* Send state from background on connection * Create green-hats-kick.md
1 parent 41fae27 commit b25bf13

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.changeset/green-hats-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'remotedev-redux-devtools-extension': patch
3+
---
4+
5+
Send state from background when monitor connects

extension/src/background/store/apiMiddleware.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,33 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
592592
};
593593
port.onMessage.addListener(listener);
594594
port.onDisconnect.addListener(disconnect('panel', id, listener));
595+
596+
const { current } = store.getState().instances;
597+
if (current !== 'default') {
598+
const connectionId = Object.entries(
599+
store.getState().instances.connections,
600+
).find(([, instanceIds]) => instanceIds.includes(current))?.[0];
601+
const options = store.getState().instances.options[current];
602+
const state = store.getState().instances.states[current];
603+
const { actionsById, computedStates, committedState, ...rest } = state;
604+
toMonitors({
605+
type: UPDATE_STATE,
606+
request: {
607+
type: 'STATE',
608+
payload: rest as Omit<
609+
LiftedState<S, A, unknown>,
610+
'actionsById' | 'computedStates' | 'committedState'
611+
>,
612+
source: '@devtools-page',
613+
instanceId:
614+
typeof current === 'number' ? current.toString() : current,
615+
actionsById: stringifyJSON(actionsById, options.serialize),
616+
computedStates: stringifyJSON(computedStates, options.serialize),
617+
committedState: typeof committedState !== 'undefined',
618+
},
619+
id: connectionId ?? current,
620+
});
621+
}
595622
}
596623
}
597624

0 commit comments

Comments
 (0)