MCPcopy Create free account
hub / github.com/ethanniser/the-beth-stack / renderToStream

Function renderToStream

packages/beth-stack/src/jsx/render.ts:33–55  ·  view source on GitHub ↗
(
  lazyHtml: T,
)

Source from the content-addressed store, hash-verified

31}
32
33export function renderToStream<T extends () => JSX.Element>(
34 lazyHtml: T,
35): ReadableStream<string> {
36 BETH_GLOBAL_RENDER_CACHE.reset();
37 const stream = new ReadableStream<string>({
38 start(c) {
39 BETH_GLOBAL_RENDER_CACHE.streamController = c;
40 lazyHtml()
41 .then((data) => {
42 BETH_GLOBAL_RENDER_CACHE.streamController?.enqueue(data);
43 BETH_GLOBAL_RENDER_CACHE.checkIfEndAndClose();
44 })
45 .catch((error) => {
46 console.error("Error in promise:", error);
47 // Handle error appropriately
48 BETH_GLOBAL_RENDER_CACHE.streamController?.error(error);
49 BETH_GLOBAL_RENDER_CACHE.closeNow();
50 });
51 },
52 });
53
54 return stream;
55}

Callers 2

render.test.tsxFile · 0.90
renderToStreamResponseFunction · 0.85

Calls 1

resetMethod · 0.80

Tested by

no test coverage detected