fix: resolve lifecycle memory leaks by cleaning up listeners and root closures (#25049)

This commit is contained in:
Spencer
2026-04-10 00:21:14 -04:00
committed by GitHub
parent 43b93e9e1b
commit 5fc8fea8d7
8 changed files with 108 additions and 18 deletions

View File

@@ -24,10 +24,24 @@ export function registerCleanup(fn: (() => void) | (() => Promise<void>)) {
cleanupFunctions.push(fn);
}
export function removeCleanup(fn: (() => void) | (() => Promise<void>)) {
const index = cleanupFunctions.indexOf(fn);
if (index !== -1) {
cleanupFunctions.splice(index, 1);
}
}
export function registerSyncCleanup(fn: () => void) {
syncCleanupFunctions.push(fn);
}
export function removeSyncCleanup(fn: () => void) {
const index = syncCleanupFunctions.indexOf(fn);
if (index !== -1) {
syncCleanupFunctions.splice(index, 1);
}
}
/**
* Resets the internal cleanup state for testing purposes.
* This allows tests to run in isolation without vi.resetModules().