diff --git a/src/plugins/loader-cache-state.test.ts b/src/plugins/loader-cache-state.test.ts index 6ccce703899e..158b6cf23c1d 100644 --- a/src/plugins/loader-cache-state.test.ts +++ b/src/plugins/loader-cache-state.test.ts @@ -18,6 +18,18 @@ describe("PluginLoaderCacheState", () => { expect(cache.get("c")).toBe("charlie"); }); + it("bounds open-allowlist warning suppression by loader cache capacity", () => { + const cache = new PluginLoaderCacheState(2); + + cache.recordOpenAllowlistWarning("first"); + cache.recordOpenAllowlistWarning("second"); + cache.recordOpenAllowlistWarning("third"); + + expect(cache.hasOpenAllowlistWarning("first")).toBe(false); + expect(cache.hasOpenAllowlistWarning("second")).toBe(true); + expect(cache.hasOpenAllowlistWarning("third")).toBe(true); + }); + it("clears registry, in-flight, and warning state together", () => { const cache = new PluginLoaderCacheState(2); diff --git a/src/plugins/loader-cache-state.ts b/src/plugins/loader-cache-state.ts index 97de1860e95e..f02c16e6c4c7 100644 --- a/src/plugins/loader-cache-state.ts +++ b/src/plugins/loader-cache-state.ts @@ -16,10 +16,11 @@ class PluginLoadReentryError extends Error { export class PluginLoaderCacheState { readonly #registryCache: PluginLruCache; readonly #inFlightLoads = new Set(); - readonly #openAllowlistWarningCache = new Set(); + readonly #openAllowlistWarningCache: PluginLruCache; constructor(defaultMaxEntries: number) { this.#registryCache = new PluginLruCache(defaultMaxEntries); + this.#openAllowlistWarningCache = new PluginLruCache(defaultMaxEntries); } clear(): void { @@ -57,10 +58,10 @@ export class PluginLoaderCacheState { } hasOpenAllowlistWarning(cacheKey: string): boolean { - return this.#openAllowlistWarningCache.has(cacheKey); + return this.#openAllowlistWarningCache.get(cacheKey) === true; } recordOpenAllowlistWarning(cacheKey: string): void { - this.#openAllowlistWarningCache.add(cacheKey); + this.#openAllowlistWarningCache.set(cacheKey, true); } }