@@ -34,7 +34,7 @@ export const createReadableStreamFromElement: CreateReadableStreamFromElement =
3434
3535 const sheet = new ServerStyleSheet ( ) ;
3636
37- const chunkVec : string [ ] = [ ] ;
37+ const chunkVec : Buffer [ ] = [ ] ;
3838
3939 const root = sheet . collectStyles ( rootElement ) ;
4040
@@ -62,15 +62,19 @@ export const createReadableStreamFromElement: CreateReadableStreamFromElement =
6262 transform ( chunk , _encoding , callback ) {
6363 try {
6464 if ( shellChunkStatus !== ShellChunkStatus . FINISH ) {
65- chunkVec . push ( chunk . toString ( ) ) ;
65+ chunkVec . push (
66+ Buffer . isBuffer ( chunk ) ? chunk : Buffer . from ( chunk ) ,
67+ ) ;
6668 /**
6769 * The shell content of App may be splitted by multiple chunks to transform,
6870 * when any node value's size is larger than the React limitation, refer to:
6971 * https://github.com/facebook/react/blob/v18.2.0/packages/react-server/src/ReactServerStreamConfigNode.js#L53.
7072 * So we use the `SHELL_STREAM_END_MARK` to mark the shell content' tail.
7173 */
72- let concatedChunk = chunkVec . join ( '' ) ;
73- if ( concatedChunk . includes ( ESCAPED_SHELL_STREAM_END_MARK ) ) {
74+ const chunkStr = chunk . toString ( 'utf-8' ) ;
75+ if ( chunkStr . includes ( ESCAPED_SHELL_STREAM_END_MARK ) ) {
76+ let concatedChunk =
77+ Buffer . concat ( chunkVec ) . toString ( 'utf-8' ) ;
7478 concatedChunk = concatedChunk . replace (
7579 ESCAPED_SHELL_STREAM_END_MARK ,
7680 '' ,
0 commit comments