Fix memory leak in dev server

This commit is contained in:
2026-10-16 14:25:18 +01:00
parent 3d0771f2d0
commit 5dc783fe97
36 changed files with 642 additions and 406 deletions
+8 -7
View File
@@ -3,6 +3,8 @@ import allPagesESBuildContextBundler from "../bundler/all-pages-esbuild-context-
import serverPostBuildFn from "./server-post-build-fn";
import { restartWatcher } from "./watcher-esbuild-ctx";
import { logBuildErrorsOnce } from "../../utils/build-error-log";
import disposeBundlerContexts from "../bundler/dispose-bundler-contexts";
import isDevelopment from "../../utils/is-development";
// Single-flight: error recovery paths (grab-page-component retries, the
// watcher, post-build HMR pushes) all call fullRebuild, and each rebuild
// triggers serverPostBuildFn which can re-enter error handling. Without this
@@ -33,18 +35,17 @@ async function doFullRebuild(params) {
log.watch(msg);
}
global.BUNEXT_ROUTER.reload();
try {
await global.BUNEXT_BUNDLER_CTX?.dispose();
global.BUNEXT_BUNDLER_CTX = undefined;
await global.BUNEXT_SSR_BUNDLER_CTX?.dispose();
global.BUNEXT_SSR_BUNDLER_CTX = undefined;
}
catch (error) { }
await disposeBundlerContexts();
await allPagesESBuildContextBundler({
post_build_fn: async (params) => {
await serverPostBuildFn(params);
},
});
// Production never rebuilds incrementally; don't keep esbuild's
// build state alive for the rest of the process.
if (!isDevelopment()) {
await disposeBundlerContexts();
}
}
catch (error) {
logBuildErrorsOnce([{ text: error?.message || String(error) }], (line) => log.error(line));