Bugfixes. Documentation update.

This commit is contained in:
2026-03-21 08:10:02 +01:00
parent 98d3cf7da7
commit 5c53e94a3e
9 changed files with 209 additions and 28 deletions
+9
View File
@@ -17,6 +17,7 @@ export default async function ({ req }: Params): Promise<Response> {
: undefined;
let controller: ReadableStreamDefaultController<string>;
let heartbeat: ReturnType<typeof setInterval>;
const stream = new ReadableStream<string>({
start(c) {
controller = c;
@@ -25,8 +26,16 @@ export default async function ({ req }: Params): Promise<Response> {
page_url: referer_url.href,
target_map,
});
heartbeat = setInterval(() => {
try {
c.enqueue(": keep-alive\n\n");
} catch {
clearInterval(heartbeat);
}
}, 5000);
},
cancel() {
clearInterval(heartbeat);
const targetControllerIndex = global.HMR_CONTROLLERS.findIndex(
(c) => c.controller == controller,
);
@@ -28,6 +28,7 @@ export default async function (params?: Params) {
script += `window.addEventListener("unhandledrejection", (e) => __bunext_show_error(String(e.reason?.message ?? e.reason), "", e.reason?.stack ?? ""));\n\n`;
script += `const hmr = new EventSource("/__hmr");\n`;
script += `window.BUNEXT_HMR = hmr;\n`;
script += `window.addEventListener("beforeunload", () => hmr.close());\n`;
script += `hmr.addEventListener("update", async (event) => {\n`;
script += ` if (event?.data) {\n`;