@@ -63,7 +63,7 @@ export const createReadableStreamFromElement: CreateReadableStreamFromElement =
6363 }
6464 } ) ;
6565
66- const chunkVec : string [ ] = [ ] ;
66+ const chunkVec : Buffer [ ] = [ ] ;
6767
6868 return new Promise ( resolve => {
6969 const { pipe : reactStreamingPipe } = renderToPipeableStream (
@@ -94,17 +94,19 @@ export const createReadableStreamFromElement: CreateReadableStreamFromElement =
9494 transform ( chunk , _encoding , callback ) {
9595 try {
9696 if ( shellChunkStatus !== ShellChunkStatus . FINISH ) {
97- chunkVec . push ( chunk . toString ( ) ) ;
98- /**
97+ chunkVec . push (
98+ Buffer . isBuffer ( chunk ) ? chunk : Buffer . from ( chunk ) ,
99+ ) ; /**
99100 * The shell content of App may be splitted by multiple chunks to transform,
100101 * when any node value's size is larger than the React limitation, refer to:
101102 * https://github.com/facebook/react/blob/v18.2.0/packages/react-server/src/ReactServerStreamConfigNode.js#L53.
102103 * So we use the `SHELL_STREAM_END_MARK` to mark the shell content' tail.
103104 */
104- let concatedChunk = chunkVec . join ( '' ) ;
105- if (
106- concatedChunk . includes ( ESCAPED_SHELL_STREAM_END_MARK )
107- ) {
105+ const chunkStr = chunk . toString ( 'utf-8' ) ;
106+ if ( chunkStr . includes ( ESCAPED_SHELL_STREAM_END_MARK ) ) {
107+ let concatedChunk = Buffer . concat (
108+ chunkVec as any ,
109+ ) . toString ( 'utf-8' ) ;
108110 concatedChunk = concatedChunk . replace (
109111 ESCAPED_SHELL_STREAM_END_MARK ,
110112 '' ,
0 commit comments