From e94f924244bef864a8514fc5d2101859e3d4958b Mon Sep 17 00:00:00 2001 From: Karim Piyar Ali Date: Thu, 15 Jun 2023 11:58:48 -0700 Subject: [PATCH 1/2] [Fizz] Allow passing a reason to `abortStream` --- .../src/ReactDOMServerFB.js | 4 ++-- .../ReactDOMServerFB-test.internal.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/react-server-dom-fb/src/ReactDOMServerFB.js b/packages/react-server-dom-fb/src/ReactDOMServerFB.js index bdf4dcedaee0b..96c8a1c9065fa 100644 --- a/packages/react-server-dom-fb/src/ReactDOMServerFB.js +++ b/packages/react-server-dom-fb/src/ReactDOMServerFB.js @@ -79,8 +79,8 @@ function renderToStream(children: ReactNodeList, options: Options): Stream { }; } -function abortStream(stream: Stream): void { - abort(stream.request); +function abortStream(stream: Stream, reason: mixed): void { + abort(stream.request, reason); } function renderNextChunk(stream: Stream): string { diff --git a/packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js b/packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js index 8e6ff121cc952..bc1b92db9e648 100644 --- a/packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js +++ b/packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js @@ -195,4 +195,23 @@ describe('ReactDOMServerFB', () => { 'The render was aborted by the server without a reason.', ]); }); + + it('should allow setting an abort reason', () => { + const errors = []; + const stream = ReactDOMServer.renderToStream( +
+ Loading
}> + + + , + { + onError(x) { + errors.push(x.message); + }, + }, + ); + const reason = 'Test abort reason'; + ReactDOMServer.abortStream(stream, new Error(reason)); + expect(errors).toEqual([reason]); + }); }); From 0ab48286ea49084ba791b8c5c6bdb17cbb78e6e5 Mon Sep 17 00:00:00 2001 From: Karim Piyar Ali Date: Thu, 22 Jun 2023 15:53:21 -0700 Subject: [PATCH 2/2] Re-use existing error in test --- .../src/__tests__/ReactDOMServerFB-test.internal.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js b/packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js index bc1b92db9e648..7b3460066405b 100644 --- a/packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js +++ b/packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js @@ -205,13 +205,12 @@ describe('ReactDOMServerFB', () => { , { - onError(x) { - errors.push(x.message); + onError(error) { + errors.push(error); }, }, ); - const reason = 'Test abort reason'; - ReactDOMServer.abortStream(stream, new Error(reason)); - expect(errors).toEqual([reason]); + ReactDOMServer.abortStream(stream, theError); + expect(errors).toEqual([theError]); }); });