Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fizz] Allow passing a reason to abortStream #26992

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,22 @@ 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(error) {
errors.push(error);
},
},
);
ReactDOMServer.abortStream(stream, theError);
expect(errors).toEqual([theError]);
});
});