Error handling bugfix: pass #1

This commit is contained in:
2026-10-02 07:04:22 +01:00
parent 39a5e91eeb
commit d8ea4f8e02
53 changed files with 1179 additions and 410 deletions
+33 -6
View File
@@ -1,9 +1,36 @@
import { log } from "../../utils/log";
import allPagesESBuildContextBundler from "../bundler/all-pages-esbuild-context-bundler";
import serverPostBuildFn from "./server-post-build-fn";
import watcherEsbuildCTX from "./watcher-esbuild-ctx";
import { restartWatcher } from "./watcher-esbuild-ctx";
import { logBuildErrorsOnce } from "../../utils/build-error-log";
// 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
// guard one broken page could fan out into cascading, overlapping rebuilds
// that leave the dev server unresponsive. Concurrent callers await the same
// in-flight rebuild instead of starting a new one.
let rebuild_in_progress: Promise<void> | undefined;
export default async function fullRebuild(params?: { msg?: string }) {
if (rebuild_in_progress) {
if (params?.msg) {
log.watch(`Rebuild already in progress, skipping: ${params.msg}`);
}
return rebuild_in_progress;
}
const run = doFullRebuild(params).finally(() => {
if (rebuild_in_progress === run) {
rebuild_in_progress = undefined;
}
});
rebuild_in_progress = run;
return run;
}
async function doFullRebuild(params?: { msg?: string }) {
try {
const { msg } = params || {};
@@ -29,14 +56,14 @@ export default async function fullRebuild(params?: { msg?: string }) {
},
});
} catch (error: any) {
log.error(error);
logBuildErrorsOnce(
[{ text: error?.message || String(error) }],
(line) => log.error(line),
);
} finally {
global.BUNEXT_RECOMPILING = false;
global.BUNEXT_IS_SERVER_COMPONENT = false;
}
if (global.BUNEXT_PAGES_SRC_WATCHER) {
global.BUNEXT_PAGES_SRC_WATCHER.close();
watcherEsbuildCTX();
}
restartWatcher();
}