From f498a22919ee48f2d3b27cdf6ec2249fce757737 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sat, 21 Sep 2024 11:07:01 -0400 Subject: [PATCH] Send state from background on connection --- .../src/background/store/apiMiddleware.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/extension/src/background/store/apiMiddleware.ts b/extension/src/background/store/apiMiddleware.ts index f6b02f6d..b01853bf 100644 --- a/extension/src/background/store/apiMiddleware.ts +++ b/extension/src/background/store/apiMiddleware.ts @@ -592,6 +592,33 @@ function onConnect>(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, + '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, + }); + } } }