Skip to content

Commit ee3ef3a

Browse files
voxpellidigli
authored andcommitted
Fix regression: Errors not emitted in streams (#14314)
Regression introduced in #14182 resulted in errors no longer being emitted on streams, breaking many consumers. Co-authored-by: Elliot Jalgard <[email protected]>
1 parent 33f6f5e commit ee3ef3a

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

packages/react-dom/src/__tests__/ReactServerRendering-test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,52 @@ describe('ReactDOMServer', () => {
556556
});
557557
});
558558

559+
describe('renderToNodeStream', () => {
560+
it('should generate simple markup', () => {
561+
const SuccessfulElement = React.createElement(() => <img />);
562+
const response = ReactDOMServer.renderToNodeStream(SuccessfulElement);
563+
expect(response.read().toString()).toMatch(
564+
new RegExp('<img data-reactroot=""' + '/>'),
565+
);
566+
});
567+
568+
it('should handle errors correctly', () => {
569+
const FailingElement = React.createElement(() => {
570+
throw new Error('An Error');
571+
});
572+
const response = ReactDOMServer.renderToNodeStream(FailingElement);
573+
return new Promise(resolve => {
574+
response.once('error', () => {
575+
resolve();
576+
});
577+
expect(response.read()).toBeNull();
578+
});
579+
});
580+
});
581+
582+
describe('renderToStaticNodeStream', () => {
583+
it('should generate simple markup', () => {
584+
const SuccessfulElement = React.createElement(() => <img />);
585+
const response = ReactDOMServer.renderToStaticNodeStream(
586+
SuccessfulElement,
587+
);
588+
expect(response.read().toString()).toMatch(new RegExp('<img' + '/>'));
589+
});
590+
591+
it('should handle errors correctly', () => {
592+
const FailingElement = React.createElement(() => {
593+
throw new Error('An Error');
594+
});
595+
const response = ReactDOMServer.renderToStaticNodeStream(FailingElement);
596+
return new Promise(resolve => {
597+
response.once('error', () => {
598+
resolve();
599+
});
600+
expect(response.read()).toBeNull();
601+
});
602+
});
603+
});
604+
559605
it('warns with a no-op when an async setState is triggered', () => {
560606
class Foo extends React.Component {
561607
UNSAFE_componentWillMount() {

packages/react-dom/src/server/ReactDOMNodeStreamRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class ReactMarkupReadableStream extends Readable {
1818
this.partialRenderer = new ReactPartialRenderer(element, makeStaticMarkup);
1919
}
2020

21-
_destroy() {
21+
_destroy(err, callback) {
2222
this.partialRenderer.destroy();
23+
callback(err);
2324
}
2425

2526
_read(size) {

0 commit comments

Comments
 (0)