Skip to content

Commit 110a01f

Browse files
committed
have abort path run through onError
1 parent 5eedbfd commit 110a01f

File tree

5 files changed

+72
-8
lines changed

5 files changed

+72
-8
lines changed

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,9 +1047,15 @@ describe('ReactDOMFizzServer', () => {
10471047
);
10481048
}
10491049

1050+
const loggedErrors = [];
1051+
function onError(error) {
1052+
loggedErrors.push(error);
1053+
return `Hash of (${error.message})`;
1054+
}
1055+
10501056
let controls;
10511057
await act(async () => {
1052-
controls = ReactDOMFizzServer.renderToPipeableStream(<App />);
1058+
controls = ReactDOMFizzServer.renderToPipeableStream(<App />, {onError});
10531059
controls.pipe(writable);
10541060
});
10551061

@@ -1077,7 +1083,9 @@ describe('ReactDOMFizzServer', () => {
10771083
expectErrors(
10781084
errors,
10791085
['This Suspense boundary was aborted by the server'],
1080-
['This Suspense boundary was aborted by the server'],
1086+
[
1087+
'The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.',
1088+
],
10811089
);
10821090
expect(getVisibleChildren(container)).toEqual(<div>Loading...</div>);
10831091

packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,30 @@ describe('ReactDOMFizzServer', () => {
193193

194194
// @gate experimental
195195
it('should be able to complete by aborting even if the promise never resolves', async () => {
196+
const errors = [];
196197
const controller = new AbortController();
197198
const stream = await ReactDOMFizzServer.renderToReadableStream(
198199
<div>
199200
<Suspense fallback={<div>Loading</div>}>
200201
<InfiniteSuspend />
201202
</Suspense>
202203
</div>,
203-
{signal: controller.signal},
204+
{
205+
signal: controller.signal,
206+
onError(x) {
207+
errors.push(x.message);
208+
},
209+
},
204210
);
205211

206212
controller.abort();
207213

208214
const result = await readResult(stream);
209215
expect(result).toContain('Loading');
216+
217+
expect(errors).toEqual([
218+
'This Suspense boundary was aborted by the server',
219+
]);
210220
});
211221

212222
// @gate experimental
@@ -223,12 +233,18 @@ describe('ReactDOMFizzServer', () => {
223233
rendered = true;
224234
return 'Done';
225235
}
236+
const errors = [];
226237
const stream = await ReactDOMFizzServer.renderToReadableStream(
227238
<div>
228239
<Suspense fallback={<div>Loading</div>}>
229240
<Wait /> />
230241
</Suspense>
231242
</div>,
243+
{
244+
onError(x) {
245+
errors.push(x.message);
246+
},
247+
},
232248
);
233249

234250
stream.allReady.then(() => (isComplete = true));
@@ -239,6 +255,10 @@ describe('ReactDOMFizzServer', () => {
239255
const reader = stream.getReader();
240256
reader.cancel();
241257

258+
expect(errors).toEqual([
259+
'This Suspense boundary was aborted by the server',
260+
]);
261+
242262
hasLoaded = true;
243263
resolve();
244264

packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('ReactDOMFizzServer', () => {
211211

212212
{
213213
onError(x) {
214-
reportedErrors.push(x);
214+
reportedErrors.push(x.message);
215215
},
216216
onShellError(x) {
217217
reportedShellErrors.push(x);
@@ -224,7 +224,10 @@ describe('ReactDOMFizzServer', () => {
224224

225225
expect(output.error).toBe(theError);
226226
expect(output.result).toBe('');
227-
expect(reportedErrors).toEqual([theError]);
227+
expect(reportedErrors).toEqual([
228+
theError.message,
229+
'This Suspense boundary was aborted by the server',
230+
]);
228231
expect(reportedShellErrors).toEqual([theError]);
229232
});
230233

@@ -289,6 +292,7 @@ describe('ReactDOMFizzServer', () => {
289292
// @gate experimental
290293
it('should be able to complete by aborting even if the promise never resolves', async () => {
291294
let isCompleteCalls = 0;
295+
const errors = [];
292296
const {writable, output, completed} = getTestWritable();
293297
const {pipe, abort} = ReactDOMFizzServer.renderToPipeableStream(
294298
<div>
@@ -298,6 +302,9 @@ describe('ReactDOMFizzServer', () => {
298302
</div>,
299303

300304
{
305+
onError(x) {
306+
errors.push(x.message);
307+
},
301308
onAllReady() {
302309
isCompleteCalls++;
303310
},
@@ -314,6 +321,9 @@ describe('ReactDOMFizzServer', () => {
314321

315322
await completed;
316323

324+
expect(errors).toEqual([
325+
'This Suspense boundary was aborted by the server',
326+
]);
317327
expect(output.error).toBe(undefined);
318328
expect(output.result).toContain('Loading');
319329
expect(isCompleteCalls).toBe(1);
@@ -322,6 +332,7 @@ describe('ReactDOMFizzServer', () => {
322332
// @gate experimental
323333
it('should be able to complete by abort when the fallback is also suspended', async () => {
324334
let isCompleteCalls = 0;
335+
const errors = [];
325336
const {writable, output, completed} = getTestWritable();
326337
const {pipe, abort} = ReactDOMFizzServer.renderToPipeableStream(
327338
<div>
@@ -333,6 +344,9 @@ describe('ReactDOMFizzServer', () => {
333344
</div>,
334345

335346
{
347+
onError(x) {
348+
errors.push(x.message);
349+
},
336350
onAllReady() {
337351
isCompleteCalls++;
338352
},
@@ -349,6 +363,11 @@ describe('ReactDOMFizzServer', () => {
349363

350364
await completed;
351365

366+
expect(errors).toEqual([
367+
// There are two boundaries that abort
368+
'This Suspense boundary was aborted by the server',
369+
'This Suspense boundary was aborted by the server',
370+
]);
352371
expect(output.error).toBe(undefined);
353372
expect(output.result).toContain('Loading');
354373
expect(isCompleteCalls).toBe(1);
@@ -552,6 +571,7 @@ describe('ReactDOMFizzServer', () => {
552571
rendered = true;
553572
return 'Done';
554573
}
574+
const errors = [];
555575
const {writable, completed} = getTestWritable();
556576
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
557577
<div>
@@ -560,6 +580,9 @@ describe('ReactDOMFizzServer', () => {
560580
</Suspense>
561581
</div>,
562582
{
583+
onError(x) {
584+
errors.push(x.message);
585+
},
563586
onAllReady() {
564587
isComplete = true;
565588
},
@@ -579,6 +602,9 @@ describe('ReactDOMFizzServer', () => {
579602

580603
await completed;
581604

605+
expect(errors).toEqual([
606+
'This Suspense boundary was aborted by the server',
607+
]);
582608
expect(rendered).toBe(false);
583609
expect(isComplete).toBe(true);
584610
});

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ describe('ReactDOMServerFB', () => {
171171
});
172172

173173
it('should be able to complete by aborting even if the promise never resolves', () => {
174+
const errors = [];
174175
const stream = ReactDOMServer.renderToStream(
175176
<div>
176177
<Suspense fallback={<div>Loading</div>}>
@@ -179,7 +180,7 @@ describe('ReactDOMServerFB', () => {
179180
</div>,
180181
{
181182
onError(x) {
182-
console.error(x);
183+
errors.push(x.message);
183184
},
184185
},
185186
);
@@ -191,5 +192,9 @@ describe('ReactDOMServerFB', () => {
191192

192193
const remaining = readResult(stream);
193194
expect(remaining).toEqual('');
195+
196+
expect(errors).toEqual([
197+
'This Suspense boundary was aborted by the server',
198+
]);
194199
});
195200
});

packages/react-server/src/ReactFizzServer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,13 @@ function abortTask(task: Task): void {
14991499

15001500
if (!boundary.forceClientRender) {
15011501
boundary.forceClientRender = true;
1502-
boundary.errorMessage =
1503-
'This Suspense boundary was aborted by the server';
1502+
const error = new Error(
1503+
'This Suspense boundary was aborted by the server',
1504+
);
1505+
boundary.errorHash = request.onError(error);
1506+
if (__DEV__) {
1507+
captureBoundaryErrorDetailsDev(boundary, error);
1508+
}
15041509
if (boundary.parentFlushed) {
15051510
request.clientRenderedBoundaries.push(boundary);
15061511
}

0 commit comments

Comments
 (0)