Skip to content

Route devtools messages by client connection and aggregate frame discovery - #1914

Open
phryneas wants to merge 1 commit into
mainfrom
pr/background-routing
Open

phryneas wants to merge 1 commit into
mainfrom
pr/background-routing

Conversation

@phryneas

Copy link
Copy Markdown
Member

This moves message routing into a separate router.ts.
Each tab gets a router. Each frame (the "root window" is called "frame" too in this context) is held as a connection, their client ids are tracked.
The router starts tracking which rpc and stream messages actually belong to which source and drops unrelated messages from other sources.
Before this PR, getClients would only wait for the fastest frame to respond, and drop all responses from other frames. That is now fixed.


Stack created with GitHub Stacks CLI • Give Feedback 💬

@phryneas
phryneas requested a review from a team as a code owner November 20, 2026 15:02
@phryneas
phryneas added this pull request to stack #1916 November 20, 2026 15:02
@relativeci

relativeci Bot commented Nov 20, 2026

Copy link
Copy Markdown

#2389 Bundle Size — 2.04MiB (+0.16%).

2d8db69(current) vs 08f3a19 main#2386(baseline)

Warning

Bundle contains 16 duplicate packages – View duplicate packages

Bundle metrics  Change 6 changes Regression 2 regressions
                 Current
#2389
     Baseline
#2386
Regression  Initial JS 1.75MiB(+0.14%) 1.75MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 84.99% 86.55%
No change  Chunks 5 5
Change  Assets 242(+0.41%) 241
Change  Modules 1531(+0.2%) 1528
Regression  Duplicate Modules 140(+1.45%) 138
Change  Duplicate Code 5.98%(+0.84%) 5.93%
No change  Packages 180 180
No change  Duplicate Packages 12 12
Bundle size by type  Change 2 changes Regression 2 regressions
                 Current
#2389
     Baseline
#2386
Regression  JS 1.75MiB (+0.14%) 1.75MiB
Regression  Other 253.23KiB (+0.29%) 252.51KiB
No change  IMG 35.85KiB 35.85KiB
No change  HTML 857B 857B

Bundle analysis report Branch pr/background-routing Project dashboard


Generated by RelativeCI Documentation Report issue

Comment thread src/extension/tab/hook.ts
@@ -74,9 +73,6 @@ function getClientInfo(client: ApolloClient): ApolloClientInfo {
}

handleRpc("getClients", () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a routing layer, any frame could previously respond, and any responses after that would be ignored.

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/apollo-client-devtools@1914
npm i https://pkg.pr.new/@apollo/client-devtools-vscode@1914

commit: 2d8db69

continue;
}
try {
tabPort.postMessage(message);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, starting cache-write recording could throw in sibling frames.
The old code would broadcast anything but RPCMessages, so RPCStartStream got broadcast.
A sibling frame would look up a client it didn’t own and try to read .cache from undefined.

Comment thread src/extension/tab/hook.ts
handleRpc("getClients", () => {
if (knownClients.size === 0) {
return SKIP_RESPONSE as any;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no clients were present, this would previously "immediately return", but never send a response, causing the devtools to run into a timeout.

Comment thread src/extension/rpc.ts
});

if (signal) {
signal.addEventListener("abort", () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were never cleaned up and could cause memory to accumulate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant