[Fizz] Allow passing a reason to `abortStream` (#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
Karim Piyar Ali committed
Sep 20, 2023 at 13:41 UTC
1f4936660dcaba2e5722013f0ad12d7369543a9f
2 files changed
+20
-2
packages/react-server-dom-fb/src/ReactDOMServerFB.js
+2
-2
@@ -81,8 +81,8 @@ function renderToStream(children: ReactNodeList, options: Options): Stream {
81
};
82
}
83
84
-function abortStream(stream: Stream): void {
85
- abort(stream.request);
84
+function abortStream(stream: Stream, reason: mixed): void {
85
+ abort(stream.request, reason);
86
}
87
88
function renderNextChunk(stream: Stream): string {
packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js
+18
@@ -195,4 +195,22 @@ describe('ReactDOMServerFB', () => {
195
'The render was aborted by the server without a reason.',
196
]);
197
});
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
+ });
216
});