Skip to content

Route each Apollo Client through a dedicated MessageChannel - #1915

Open
phryneas wants to merge 4 commits into
pr/background-routingfrom
pr/individual-MessageChannels
Open

phryneas wants to merge 4 commits into
pr/background-routingfrom
pr/individual-MessageChannels

Conversation

@phryneas

Copy link
Copy Markdown
Member

Building on the router PR, this changes the connection model around.
Each Client gets its own MessageChannel, and separate Port instances all the way to the router. Each Client is considered its own individual connection. Client ids are now created and managed on a router level, while any level before that doesn't have to concern itself with them.
Frames themselves also have a "root connection" that is used for global concerns like registering new client connections or loadErrorCodes.
While a MessageChannel Port doesn't have a disconnect event, the final runtime Port used to transport data into the extension has a disconnect event. Where applicable, that is now used to close down subscriptions.


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

#2395 Bundle Size — 2.04MiB (+0.38%).

8c623d5(current) vs c6e6bbf main#2392(baseline)

Warning

Bundle contains 16 duplicate packages – View duplicate packages

Bundle metrics  Change 6 changes Regression 2 regressions
                 Current
#2395
     Baseline
#2392
Regression  Initial JS 1.76MiB(+0.34%) 1.75MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 86.62% 0.59%
No change  Chunks 5 5
Change  Assets 242(+0.41%) 241
Change  Modules 1533(+0.33%) 1528
Regression  Duplicate Modules 142(+2.9%) 138
Change  Duplicate Code 6.27%(+5.73%) 5.93%
No change  Packages 180 180
No change  Duplicate Packages 12 12
Bundle size by type  Change 2 changes Regression 2 regressions
                 Current
#2395
     Baseline
#2392
Regression  JS 1.76MiB (+0.34%) 1.75MiB
Regression  Other 254.31KiB (+0.71%) 252.51KiB
No change  IMG 35.85KiB 35.85KiB
No change  HTML 857B 857B

Bundle analysis report Branch pr/individual-MessageChannels Project dashboard


Generated by RelativeCI Documentation Report issue

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026 •

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

commit: 8c623d5

Comment on lines -28 to -39
actor.on(
"explorerSubscriptionTermination",
() => subscription.unsubscribe(),
options
);
if (subscription.closed) return;
const stop = () => subscription.unsubscribe();
const { signal } = options;
if (signal?.aborted) return stop();

if (options.signal) {
options.signal.addEventListener(
"abort",
() => subscription.unsubscribe(),
{ once: true }
);

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.

Both of these listeners were never cleaned up and could start accumulating.

Comment thread src/extension/rpc.ts
if (result === SKIP_RESPONSE) {
return;
}
if (options.signal?.aborted) return;

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 this, closing the panel while a request was ongoing could cause postMessage on a closed port.

@phryneas
phryneas marked this pull request as draft November 20, 2026 16:18
@phryneas
phryneas marked this pull request as ready for review November 20, 2026 17:23
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