From e2a6545e29dd5fe4d63c501f41e5fbc714a9c545 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 1 May 2025 02:07:08 -0700 Subject: [PATCH] Update hmr-runtime-client.ts --- src/bake/hmr-runtime-client.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bake/hmr-runtime-client.ts b/src/bake/hmr-runtime-client.ts index bc356447d9..a227ca48b0 100644 --- a/src/bake/hmr-runtime-client.ts +++ b/src/bake/hmr-runtime-client.ts @@ -18,6 +18,8 @@ import { editCssContent, editCssArray } from "./client/css-reloader"; import { td } from "./shared"; import { addMapping, SourceMapURL } from "./client/stack-trace"; +const consoleErrorWithoutInspector = console.error; + if (typeof IS_BUN_DEVELOPMENT !== "boolean") { throw new Error("DCE is configured incorrectly"); } @@ -250,13 +252,12 @@ window.addEventListener("unhandledrejection", event => { // }, // }) // + let isStreamingConsoleLogFromBrowserToServer = document.querySelector("meta[name='bun:echo-console-log']"); if (isStreamingConsoleLogFromBrowserToServer) { // Ensure it only runs once, and avoid the extra noise in the HTML. isStreamingConsoleLogFromBrowserToServer.remove(); - const originalLog = console.log; - const originalError = console.error; function websocketInspect(logLevel: "l" | "e", values: any[]) { let str = "l" + logLevel; @@ -285,9 +286,9 @@ if (isStreamingConsoleLogFromBrowserToServer) { }; } - if (typeof originalError === "function") { + if (typeof consoleErrorWithoutInspector === "function") { console.error = function error(...args: any[]) { - originalError(...args); + consoleErrorWithoutInspector(...args); websocketInspect("e", args); }; } @@ -304,6 +305,8 @@ try { emitEvent("bun:ready", null); } catch (e) { - console.error(e); + // Use consoleErrorWithoutInspector to avoid double-reporting errors. + consoleErrorWithoutInspector(e); + onRuntimeError(e, true, false); }