1
1
import ReactDOMServer from 'react-dom/server' ;
2
- import { PassThrough } from 'stream' ;
2
+ import { PassThrough , Readable } from 'stream' ;
3
3
import type { ReactElement } from 'react' ;
4
4
5
5
import ComponentRegistry from './ComponentRegistry' ;
@@ -167,17 +167,17 @@ const serverRenderReactComponent: typeof serverRenderReactComponentInternal = (o
167
167
}
168
168
} ;
169
169
170
- const stringToStream = ( str : string ) => {
170
+ const stringToStream = ( str : string ) : Readable => {
171
171
const stream = new PassThrough ( ) ;
172
172
stream . push ( str ) ;
173
173
stream . push ( null ) ;
174
174
return stream ;
175
175
} ;
176
176
177
- export const streamServerRenderedReactComponent = ( options : RenderParams ) => {
177
+ export const streamServerRenderedReactComponent = ( options : RenderParams ) : Readable => {
178
178
const { name, domNodeId, trace, props, railsContext, throwJsErrors } = options ;
179
179
180
- let renderResult : null | PassThrough = null ;
180
+ let renderResult : null | Readable = null ;
181
181
182
182
try {
183
183
const componentObj = ComponentRegistry . get ( name ) ;
@@ -199,8 +199,9 @@ See https://github.com/shakacode/react_on_rails#renderer-functions`);
199
199
throw new Error ( 'Server rendering of streams is not supported for server render hashes or promises.' ) ;
200
200
}
201
201
202
- renderResult = new PassThrough ( ) ;
203
- ReactDOMServer . renderToPipeableStream ( reactRenderingResult ) . pipe ( renderResult ) ;
202
+ const renderStream = new PassThrough ( ) ;
203
+ ReactDOMServer . renderToPipeableStream ( reactRenderingResult ) . pipe ( renderStream ) ;
204
+ renderResult = renderStream ;
204
205
205
206
// TODO: Add console replay script to the stream
206
207
// Ensure to avoid console messages leaking between different components rendering
0 commit comments