Skip to content

React 16.6.3 silently swallows an exception in ReactDOMServer.renderToNodeStream() #14331

Closed
@asyncmax

Description

@asyncmax

This is reproducible with the following snippet:

"use strict";

const React = require("react");
const ReactDOMServer = require("react-dom/server");

function Hello() {
  throw new Error("foo");
  return React.createElement("div", null, "Hello, world!");
}

const stream = ReactDOMServer.renderToNodeStream(React.createElement(Hello));

stream.on("data", chunk => {
  console.log(chunk.toString());
});

stream.on("end", () => {
  console.log("-- done --");
});

stream.on("error", err => {
  console.error(err);
});

React 16.6.1 emits an error event as expected, but React 16.6.3 silently swallows an exception, leaving the stream in a broken state in which it never ends.

This problem appears to be caused by this modification in ReactDOMNodeStreamRenderer.js:

b545546#diff-1090c7a359d6dc602b62ac38b66697b3L25

Here, stream.destroy gets called with an exception object but the actual handler stream._destroy doesn't use it anywhere which results in ignoring the exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions