Skip to content

Commit 1f49366

Browse files
authored
[Fizz] Allow passing a reason to abortStream (facebook#26992)
## Summary Currently `ReactFizzServer.abort` allows you to pass in the a `reason` error, which then gets passed to the `onError` handler for each task that ends up getting aborted. This adds in the ability to pass down that same `reason` error to `ReactDOMServerFB.abortStream` as well. ## How did you test this change? Added a test case to ReactDOMServerFB-test.internal.js
1 parent b775564 commit 1f49366

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/react-server-dom-fb/src/ReactDOMServerFB.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ function renderToStream(children: ReactNodeList, options: Options): Stream {
8181
};
8282
}
8383

84-
function abortStream(stream: Stream): void {
85-
abort(stream.request);
84+
function abortStream(stream: Stream, reason: mixed): void {
85+
abort(stream.request, reason);
8686
}
8787

8888
function renderNextChunk(stream: Stream): string {

packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,22 @@ describe('ReactDOMServerFB', () => {
195195
'The render was aborted by the server without a reason.',
196196
]);
197197
});
198+
199+
it('should allow setting an abort reason', () => {
200+
const errors = [];
201+
const stream = ReactDOMServer.renderToStream(
202+
<div>
203+
<Suspense fallback={<div>Loading</div>}>
204+
<InfiniteSuspend />
205+
</Suspense>
206+
</div>,
207+
{
208+
onError(error) {
209+
errors.push(error);
210+
},
211+
},
212+
);
213+
ReactDOMServer.abortStream(stream, theError);
214+
expect(errors).toEqual([theError]);
215+
});
198216
});

0 commit comments

Comments
 (0)