Skip to content

Commit d931854

Browse files
committed
Leverage TextEncoderStream in html response
1 parent 597b648 commit d931854

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

feat/dependencies-of/api.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,18 @@ async function serveHtmlGraphPage(req: Request, modUrl: string, modSlug: string,
149149

150150
// Return the body in two parts, with a comment in between
151151
return new Response(ReadableStream.from((async function*() {
152-
const encoder = new TextEncoder();
153-
yield encoder.encode(pageHtml);
154152

155-
yield encoder.encode("\n<!-- now waiting for graph ... ");
153+
yield pageHtml;
154+
155+
yield "\n<!-- now waiting for graph ... ";
156156
const d0 = Date.now();
157157
const graphText = hideLoadMsg + await graphPromise;
158158
const millis = Date.now() - d0;
159-
yield encoder.encode(`completed in ${millis}ms -->\n\n`);
159+
yield `completed in ${millis}ms -->\n\n`;
160+
161+
yield graphText;
160162

161-
yield encoder.encode(graphText);
162-
}())), {
163+
}())).pipeThrough(new TextEncoderStream()), {
163164
headers: HtmlHeaders,
164165
});
165166
}

0 commit comments

Comments
 (0)