From c6276769e2ce4119a60a881e69021062c8870b97 Mon Sep 17 00:00:00 2001 From: Eva Date: Mon, 4 May 2026 03:12:45 +0700 Subject: [PATCH] fix: keep retiring cleanup across swaps --- docs/.generated/plugin-sdk-api-baseline.sha256 | 4 ++-- src/plugins/runtime.test.ts | 17 +++++++++++++++-- src/plugins/runtime.ts | 7 +++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/.generated/plugin-sdk-api-baseline.sha256 b/docs/.generated/plugin-sdk-api-baseline.sha256 index a258452941a..c3180d4b9e0 100644 --- a/docs/.generated/plugin-sdk-api-baseline.sha256 +++ b/docs/.generated/plugin-sdk-api-baseline.sha256 @@ -1,2 +1,2 @@ -120e369c16fc57dd038a08ff4bbea3f436bbecb0572171923ad05f933903edae plugin-sdk-api-baseline.json -311eae09f9c5b6f2c5877d6e7661bec2c755bc22fcc4036e6eeda40e8668e418 plugin-sdk-api-baseline.jsonl +783f2c0fa7ca9e72fbb553aaebc88a3ba0ec6820c39a373dcc648f95a49c340d plugin-sdk-api-baseline.json +f4cbb04f31648599ade2010ee67444ed6c22dd7e210f037bfaabfe8ea39021b4 plugin-sdk-api-baseline.jsonl diff --git a/src/plugins/runtime.test.ts b/src/plugins/runtime.test.ts index 26e5c2b2b24..13232e39cb2 100644 --- a/src/plugins/runtime.test.ts +++ b/src/plugins/runtime.test.ts @@ -218,7 +218,20 @@ describe("setActivePluginRegistry", () => { expect(listImportedRuntimePluginIds()).toEqual(["runtime-plugin"]); }); - it("continues cleanup when the same active registry is refreshed", async () => { + it.each([ + { + name: "same active registry is refreshed", + refresh(nextRegistry: ReturnType) { + setActivePluginRegistry(nextRegistry); + }, + }, + { + name: "active registry advances again", + refresh() { + setActivePluginRegistry(createEmptyPluginRegistry()); + }, + }, + ] as const)("continues cleanup when the $name", async ({ refresh }) => { let releaseFirstCleanup: (() => void) | undefined; let markFirstCleanupStarted!: () => void; let markSecondCleanupCalled!: () => void; @@ -271,7 +284,7 @@ describe("setActivePluginRegistry", () => { setActivePluginRegistry(next); await waitForCleanupSignal(firstCleanupStarted, "first cleanup start"); - setActivePluginRegistry(next); + refresh(next); releaseFirstCleanup?.(); await waitForCleanupSignal(secondCleanupCalled, "second cleanup"); diff --git a/src/plugins/runtime.ts b/src/plugins/runtime.ts index cd4cbcd0515..cc93ee54d6e 100644 --- a/src/plugins/runtime.ts +++ b/src/plugins/runtime.ts @@ -74,10 +74,9 @@ async function cleanupPreviousPluginHostRegistry(params: { if (!nextRegistry || nextRegistry === params.previousRegistry) { return; } - // Async cleanup must not clear state after another registry becomes live. - // Re-activating the same registry refreshes caches, but it is still the same - // live cleanup target and must not abort the old registry cleanup. - const shouldCleanup = () => state.activeRegistry === nextRegistry; + // Async cleanup must not clear state for a registry that has been restored + // active, but later swaps should not strand cleanup for the retiring registry. + const shouldCleanup = () => state.activeRegistry !== params.previousRegistry; await cleanupReplacedPluginHostRegistry({ cfg: getRuntimeConfig(), previousRegistry: params.previousRegistry,