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' ;
@@ -167,17 +167,17 @@ const serverRenderReactComponent: typeof serverRenderReactComponentInternal = (o
167167 }
168168} ;
169169
170- const stringToStream = ( str : string ) => {
170+ const stringToStream = ( str : string ) : Readable => {
171171 const stream = new PassThrough ( ) ;
172172 stream . push ( str ) ;
173173 stream . push ( null ) ;
174174 return stream ;
175175} ;
176176
177- export const streamServerRenderedReactComponent = ( options : RenderParams ) => {
177+ export const streamServerRenderedReactComponent = ( options : RenderParams ) : Readable => {
178178 const { name, domNodeId, trace, props, railsContext, throwJsErrors } = options ;
179179
180- let renderResult : null | PassThrough = null ;
180+ let renderResult : null | Readable = null ;
181181
182182 try {
183183 const componentObj = ComponentRegistry . get ( name ) ;
@@ -199,8 +199,9 @@ See https://github.com/shakacode/react_on_rails#renderer-functions`);
199199 throw new Error ( 'Server rendering of streams is not supported for server render hashes or promises.' ) ;
200200 }
201201
202- renderResult = new PassThrough ( ) ;
203- ReactDOMServer . renderToPipeableStream ( reactRenderingResult ) . pipe ( renderResult ) ;
202+ const renderStream = new PassThrough ( ) ;
203+ ReactDOMServer . renderToPipeableStream ( reactRenderingResult ) . pipe ( renderStream ) ;
204+ renderResult = renderStream ;
204205
205206 // TODO: Add console replay script to the stream
206207 // Ensure to avoid console messages leaking between different components rendering
0 commit comments