Fix memory leak in dev server
This commit is contained in:
@@ -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
|
||||
@@ -42,19 +44,19 @@ async function doFullRebuild(params?: { msg?: string }) {
|
||||
|
||||
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: any) {
|
||||
logBuildErrorsOnce(
|
||||
[{ text: error?.message || String(error) }],
|
||||
|
||||
Reference in New Issue
Block a user