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' ;
@@ -185,17 +185,17 @@ const serverRenderReactComponent: typeof serverRenderReactComponentInternal = (o
185185 return result ;
186186} ;
187187
188- const stringToStream = ( str : string ) => {
188+ const stringToStream = ( str : string ) : Readable => {
189189 const stream = new PassThrough ( ) ;
190190 stream . push ( str ) ;
191191 stream . push ( null ) ;
192192 return stream ;
193193} ;
194194
195- export const streamServerRenderedReactComponent = ( options : RenderParams ) => {
195+ export const streamServerRenderedReactComponent = ( options : RenderParams ) : Readable => {
196196 const { name, domNodeId, trace, props, railsContext, throwJsErrors } = options ;
197197
198- let renderResult : null | PassThrough = null ;
198+ let renderResult : null | Readable = null ;
199199
200200 try {
201201 const componentObj = ComponentRegistry . get ( name ) ;
@@ -217,8 +217,9 @@ See https://github.com/shakacode/react_on_rails#renderer-functions`);
217217 throw new Error ( 'Server rendering of streams is not supported for server render hashes or promises.' ) ;
218218 }
219219
220- renderResult = new PassThrough ( ) ;
221- ReactDOMServer . renderToPipeableStream ( reactRenderingResult ) . pipe ( renderResult ) ;
220+ const renderStream = new PassThrough ( ) ;
221+ ReactDOMServer . renderToPipeableStream ( reactRenderingResult ) . pipe ( renderStream ) ;
222+ renderResult = renderStream ;
222223
223224 // TODO: Add console replay script to the stream
224225 // Ensure to avoid console messages leaking between different components rendering
0 commit comments