Skip to content

Commit 44ac5d8

Browse files
authored
Merge pull request #62 from Ibadichan/update-react-streaming-ssr-example-2
Removed multistream and readableString usage from react SSR
2 parents 5125640 + e709eb6 commit 44ac5d8

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

README.md

+6-21
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,8 @@ app.use('*', async (req, res) => {
233233
// entry-server.js
234234
import React from 'react';
235235
import { renderToPipeableStream } from 'react-dom/server';
236-
import MultiStream from 'multistream';
237-
import { Readable } from 'node:stream';
238236
import App from './App';
239237

240-
// small utility for "readable" streams
241-
const readableString = string => {
242-
const s = new Readable();
243-
s.push(string);
244-
s.push(null);
245-
s._read = () => true;
246-
return s;
247-
};
248-
249238
const ABORT_DELAY = 10000;
250239

251240
async function renderApp({ res, styledStream }) {
@@ -265,19 +254,15 @@ async function renderApp({ res, styledStream }) {
265254

266255
// allow client to start loading js bundle
267256
res.write(`<!DOCTYPE html><html><head><script defer src="client.js"></script></head><body><div id="root">`);
268-
269-
const endStream = readableString('</div></body></html>');
270-
271-
// concatenate all streams together
272-
const streams = [
273-
styledStream, // the main content
274-
endStream, // closing tags
275-
];
276-
277-
new MultiStream(streams).pipe(res);
278257

258+
styledStream.pipe(res, { end: false });
259+
279260
// start by piping react and styled transform stream
280261
pipe(styledStream);
262+
263+
styledStream.on('end', () => {
264+
res.end('</div></body></html>');
265+
});
281266
},
282267
onError(error) {
283268
didError = true;

0 commit comments

Comments
 (0)