UNPKG

rwsdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

19 lines (18 loc) 1.28 kB
/** * A utility to orchestrate and interleave two ReadableStreams (a document shell and an app shell) * based on a set of markers within their content. This is designed to solve a specific * race condition in streaming Server-Side Rendering (SSR) with Suspense. * * The logic is as follows: * 1. Stream the document until a start marker is found. * 2. Switch to the app stream and stream it until an end marker is found. This is the non-suspended shell. * 3. Switch back to the document stream and stream it until the closing body tag. This sends the client script. * 4. Switch back to the app stream and stream the remainder (the suspended content). * 5. Switch back to the document stream and stream the remainder (closing body and html tags). * * @param outerHtml The stream for the document shell (`<Document>`). * @param innerHtml The stream for the application's content. * @param startMarker The marker in the document to start injecting the app. * @param endMarker The marker in the app stream that signals the end of the initial, non-suspended render. */ export declare function stitchDocumentAndAppStreams(outerHtml: ReadableStream<Uint8Array>, innerHtml: ReadableStream<Uint8Array>, startMarker: string, endMarker: string): ReadableStream<Uint8Array>;