fix: keep retiring cleanup across swaps

This commit is contained in:
Eva
2026-05-04 03:12:45 +07:00
committed by Josh Lehman
parent 4e76983ad6
commit c6276769e2
3 changed files with 20 additions and 8 deletions

View File

@@ -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

View File

@@ -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<typeof createEmptyPluginRegistry>) {
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");

View File

@@ -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,