Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EmilsWebbod opened this issue Apr 28, 2023 · 0 comments

Comments

@EmilsWebbod
Copy link

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`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant