11import ReactDOMServer from 'react-dom/server' ;
2- import { PassThrough } from 'stream' ;
2+ import { PassThrough , Readable } from 'stream' ;
33import type { ReactElement } from 'react' ;
44
55import ComponentRegistry from './ComponentRegistry' ;
@@ -193,17 +193,17 @@ const serverRenderReactComponent: typeof serverRenderReactComponentInternal = (o
193193 }
194194} ;
195195
196- const stringToStream = ( str : string ) => {
196+ const stringToStream = ( str : string ) : Readable => {
197197 const stream = new PassThrough ( ) ;
198198 stream . push ( str ) ;
199199 stream . push ( null ) ;
200200 return stream ;
201201} ;
202202
203- export const streamServerRenderedReactComponent = ( options : RenderParams ) => {
203+ export const streamServerRenderedReactComponent = ( options : RenderParams ) : Readable => {
204204 const { name, domNodeId, trace, props, railsContext, throwJsErrors } = options ;
205205
206- let renderResult : null | PassThrough = null ;
206+ let renderResult : null | Readable = null ;
207207
208208 try {
209209 const componentObj = ComponentRegistry . get ( name ) ;
@@ -225,8 +225,9 @@ See https://github.com/shakacode/react_on_rails#renderer-functions`);
225225 throw new Error ( 'Server rendering of streams is not supported for server render hashes or promises.' ) ;
226226 }
227227
228- renderResult = new PassThrough ( ) ;
229- ReactDOMServer . renderToPipeableStream ( reactRenderingResult ) . pipe ( renderResult ) ;
228+ const renderStream = new PassThrough ( ) ;
229+ ReactDOMServer . renderToPipeableStream ( reactRenderingResult ) . pipe ( renderStream ) ;
230+ renderResult = renderStream ;
230231
231232 // TODO: Add console replay script to the stream
232233 // Ensure to avoid console messages leaking between different components rendering
0 commit comments