From 3906407e5dc89bb7b2605af6a4b2ccd424d4fa04 Mon Sep 17 00:00:00 2001 From: Zack Radisic <56137411+zackradisic@users.noreply.github.com> Date: Wed, 20 Aug 2025 15:07:39 -0700 Subject: [PATCH] stuff --- src/bake/bun-framework-react/server.tsx | 14 +++++++++----- src/bake/hmr-runtime-server.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/bake/bun-framework-react/server.tsx b/src/bake/bun-framework-react/server.tsx index 8d8cd882b9..009a8ae575 100644 --- a/src/bake/bun-framework-react/server.tsx +++ b/src/bake/bun-framework-react/server.tsx @@ -137,18 +137,22 @@ export async function render( ...responseOptions, }); } else { - // TODO: this seems shitty + // TODO: this is bad and could be done way better + // Buffer the entire response and return it all at once const htmlStream = renderToHtml(rscPayload, meta.modules, signal); const chunks: Uint8Array[] = []; const reader = htmlStream.getReader(); try { - while (true) { + let keepGoing = true; + do { const { done, value } = await reader.read(); - if (done) break; - chunks.push(value); - } + keepGoing = !done; + if (!done) { + chunks.push(value); + } + } while (keepGoing); } finally { reader.releaseLock(); } diff --git a/src/bake/hmr-runtime-server.ts b/src/bake/hmr-runtime-server.ts index 11ddb0c961..1b69284a71 100644 --- a/src/bake/hmr-runtime-server.ts +++ b/src/bake/hmr-runtime-server.ts @@ -13,7 +13,7 @@ if (typeof IS_BUN_DEVELOPMENT !== "boolean") { export type RequestContext = { responseOptions: ResponseInit; streamingStarted?: boolean; - abortNonStreaming: (path: string, params: Record | null) => {}; + abortNonStreaming?: (path: string, params: Record | null) => {}; }; // Create the AsyncLocalStorage instance for propagating response options @@ -81,9 +81,13 @@ server_exports = { requestWithCookies.cookies = req.cookies || new Bun.CookieMap(req.headers.get("Cookie") || ""); } + let storeValue: RequestContext = { + responseOptions: {}, + }; + // Run the renderer inside the AsyncLocalStorage context // This allows Response constructors to access the stored options - const response = await responseOptionsALS.run({}, async () => { + const response = await responseOptionsALS.run(storeValue, async () => { return await serverRenderer( requestWithCookies, {