Skip to content

spdy with ReactDOMServer.renderToPipeableStream stops after streaming 2048 bytes. #398

@EmilsWebbod

Description

@EmilsWebbod

Got a really strange issue that boggles my brain.
This is only connected to spdy. If i use http2.createSecureServer it works fine.

Seems like spdy stops streaming after 2048 bytes.
image
image

Even more strange. It works fine when i add a simple console.log after the stream.pipe(res); function.
Added a simple code to test with.

Running Node v18.16.0.
"react": "^18.2.0",
"react-dom": "^18.2.0",
"spdy": "^4.0.2"

const React = require('react');
const ReactDOMServer = require('react-dom/server');
const spdy = require('spdy');
const fs = require("fs");
const path = require("path");

const fail = true;
// Fails if buffersize is 229. Works if buffersize is 228....
const buffer = new Buffer(fail ? 229 : 228);

const server = spdy.createServer(
  {
    key: fs.readFileSync(path.join('keys', 'server.key')),
    cert: fs.readFileSync(path.join('keys', 'server.crt')),
    ca: fs.readFileSync(path.join('keys', 'ca.crt')),
    spdy: {
      protocols: ['h2'],
    },
    requestCert: true,
    rejectUnauthorized: false,
  },
  (req, res) => {
    res.setHeader('Content-type', 'text/html');
    const stream = ReactDOMServer.renderToPipeableStream(buffer, {
      onShellReady: () => {
        stream.pipe(res);
        // Adding console.log here fixes the problem with buffer size. Then it works fine with >228
        // console.log(); // This actually fixes the problem and ends the stream.
      },
      onShellError: (err) => {
        console.error(err);
        res.send('<h1>onShellError</h1>')
      },
      onError: (err) => {
        console.error(err);
        res.send('<h1>onError</h1>')
      },
      onAllReady: () => {
        res.end();
      }
    });
  }
);

server.listen(1335, () => {
  console.log(`Server listening on port 1335`);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions