Skip to content

Commit

Permalink
[Fizz] Allow passing a reason to abortStream
Browse files Browse the repository at this point in the history
  • Loading branch information
KarimP committed Jun 22, 2023
1 parent c8deb5d commit e94f924
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/react-server-dom-fb/src/ReactDOMServerFB.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<div>
<Suspense fallback={<div>Loading</div>}>
<InfiniteSuspend />
</Suspense>
</div>,
{
onError(x) {
errors.push(x.message);
},
},
);
const reason = 'Test abort reason';
ReactDOMServer.abortStream(stream, new Error(reason));
expect(errors).toEqual([reason]);
});
});

0 comments on commit e94f924

Please sign in to comment.