mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
stuff
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ if (typeof IS_BUN_DEVELOPMENT !== "boolean") {
|
||||
export type RequestContext = {
|
||||
responseOptions: ResponseInit;
|
||||
streamingStarted?: boolean;
|
||||
abortNonStreaming: (path: string, params: Record<string, string> | null) => {};
|
||||
abortNonStreaming?: (path: string, params: Record<string, string> | 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,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user