( lazyHtml: T, )
| 31 | } |
| 32 | |
| 33 | export 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 | } |
no test coverage detected