From 855c220a631a8ae21be8a3da297406e14130e318 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 29 Apr 2026 04:12:43 +0100 Subject: [PATCH] fix(channels): preserve bundled channel load caches --- src/channels/plugins/bundled.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/channels/plugins/bundled.ts b/src/channels/plugins/bundled.ts index ec367cbeb2a..67af22f3298 100644 --- a/src/channels/plugins/bundled.ts +++ b/src/channels/plugins/bundled.ts @@ -88,6 +88,8 @@ type BundledChannelLoadContext = { }; const log = createSubsystemLogger("channels"); +const MAX_BUNDLED_CHANNEL_LOAD_CONTEXTS = 32; +const bundledChannelLoadContextsByRoot = new Map(); function resolveChannelPluginModuleEntry( moduleExport: unknown, @@ -310,9 +312,27 @@ function resolveActiveBundledChannelLoadScope(): { loadContext: BundledChannelLoadContext; } { const rootScope = resolveBundledChannelRootScope(); + const cachedContext = bundledChannelLoadContextsByRoot.get(rootScope.cacheKey); + if (cachedContext) { + bundledChannelLoadContextsByRoot.delete(rootScope.cacheKey); + bundledChannelLoadContextsByRoot.set(rootScope.cacheKey, cachedContext); + return { + rootScope, + loadContext: cachedContext, + }; + } + const loadContext = createBundledChannelLoadContext(); + bundledChannelLoadContextsByRoot.set(rootScope.cacheKey, loadContext); + while (bundledChannelLoadContextsByRoot.size > MAX_BUNDLED_CHANNEL_LOAD_CONTEXTS) { + const oldestKey = bundledChannelLoadContextsByRoot.keys().next().value; + if (oldestKey === undefined) { + break; + } + bundledChannelLoadContextsByRoot.delete(oldestKey); + } return { rootScope, - loadContext: createBundledChannelLoadContext(), + loadContext, }; }