From e709eb6c125884c9bf6c5d49ec87e52f1457ab20 Mon Sep 17 00:00:00 2001 From: Ivan Badicean Date: Fri, 29 Mar 2024 10:03:11 +0200 Subject: [PATCH] Removed multistream and readableString usage --- README.md | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c4814fc..2997bbe 100644 --- a/README.md +++ b/README.md @@ -233,19 +233,8 @@ app.use('*', async (req, res) => { // entry-server.js import React from 'react'; import { renderToPipeableStream } from 'react-dom/server'; -import MultiStream from 'multistream'; -import { Readable } from 'node:stream'; import App from './App'; -// small utility for "readable" streams -const readableString = string => { - const s = new Readable(); - s.push(string); - s.push(null); - s._read = () => true; - return s; -}; - const ABORT_DELAY = 10000; async function renderApp({ res, styledStream }) { @@ -265,19 +254,15 @@ async function renderApp({ res, styledStream }) { // allow client to start loading js bundle res.write(`
`); - - const endStream = readableString('
'); - - // concatenate all streams together - const streams = [ - styledStream, // the main content - endStream, // closing tags - ]; - - new MultiStream(streams).pipe(res); + styledStream.pipe(res, { end: false }); + // start by piping react and styled transform stream pipe(styledStream); + + styledStream.on('end', () => { + res.end(''); + }); }, onError(error) { didError = true;