Skip to content

Commit 841dc9a

Browse files
committed
fix(channels): restore registry snapshot memo
1 parent 5a8b152 commit 841dc9a

3 files changed

Lines changed: 13 additions & 35 deletions

File tree

‎src/channels/plugins/read-only.test.ts‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ describe("listReadOnlyChannelPluginsForConfig", () => {
432432

433433
expectExternalChatSetupOnlyPluginLoaded({ plugins, setupMarker, fullMarker });
434434
expect(moduleLoaderParams).toContainEqual({
435-
modulePath: path.join(pluginDir, "setup-entry.cjs"),
435+
modulePath: fs.realpathSync(path.join(pluginDir, "setup-entry.cjs")),
436436
tryNative: true,
437437
});
438438
});
@@ -514,35 +514,6 @@ describe("listReadOnlyChannelPluginsForConfig", () => {
514514
expect(second.find((plugin) => plugin.id === "external-chat")?.meta.blurb).toBe("second");
515515
});
516516

517-
it("refreshes cached read-only channel plugins when active registry channels mutate in place", () => {
518-
const cfg = { channels: { "external-chat": { token: "configured" } } } as never;
519-
const registry = createTestRegistry([]);
520-
setActivePluginRegistry(registry);
521-
522-
const first = listReadOnlyChannelPluginsForConfig(cfg, {
523-
includePersistedAuthState: false,
524-
includeSetupFallbackPlugins: true,
525-
});
526-
527-
const plugin = {
528-
...createChannelTestPluginBase({ id: "external-chat" as never }),
529-
meta: {
530-
...createChannelTestPluginBase({ id: "external-chat" as never }).meta,
531-
blurb: "mutated registry",
532-
},
533-
};
534-
registry.channels.push({ pluginId: "mutated-plugin", plugin, source: "test" } as never);
535-
const second = listReadOnlyChannelPluginsForConfig(cfg, {
536-
includePersistedAuthState: false,
537-
includeSetupFallbackPlugins: true,
538-
});
539-
540-
expect(pluginIds(first)).not.toContain("external-chat");
541-
expect(second.find((entry) => entry.id === "external-chat")?.meta.blurb).toBe(
542-
"mutated registry",
543-
);
544-
});
545-
546517
it("refreshes cached read-only channel plugins when ambient env changes", () => {
547518
const { pluginDir, fullMarker, setupMarker } = writeExternalSetupChannelPlugin({
548519
manifestChannelConfig: true,

‎src/channels/plugins/registry-loaded.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function resolveChannelPlugins(registry?: ActivePluginChannelRegistry): ChannelP
105105
entriesById,
106106
};
107107
if (currentRegistry) {
108-
// Runtime snapshots invalidate the single active, pinned-registry view.
108+
// Runtime snapshots invalidate the single process-root registry view.
109109
cachedChannelPluginView = view;
110110
}
111111
return view;

‎src/plugins/runtime-channel-state.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,22 @@ export type ActivePluginChannelRegistrySnapshot = {
1616
version: number;
1717
};
1818

19+
let activePluginChannelRegistrySnapshot: ActivePluginChannelRegistrySnapshot | undefined;
20+
1921
/** Returns a snapshot of the process-root plugin registry. */
2022
export function getActivePluginChannelRegistrySnapshotFromState(): ActivePluginChannelRegistrySnapshot {
2123
const state: GlobalChannelRegistryRuntimeState = (globalThis as GlobalChannelRegistryState)[
2224
PLUGIN_REGISTRY_STATE
2325
];
24-
return {
25-
registry: state?.activeRegistry ?? null,
26-
version: state?.activeVersion ?? 0,
27-
};
26+
const registry = state?.activeRegistry ?? null;
27+
const version = state?.activeVersion ?? 0;
28+
const cached = activePluginChannelRegistrySnapshot;
29+
if (cached && cached.registry === registry && cached.version === version) {
30+
return cached;
31+
}
32+
const snapshot = { registry, version };
33+
activePluginChannelRegistrySnapshot = snapshot;
34+
return snapshot;
2835
}
2936

3037
/** Returns the active plugin channel registry from global runtime state. */

0 commit comments

Comments
 (0)