435
onFatalError: (error: mixed) => void,
436
// Aborted once the render ends, whether it completed, failed fatally or was
437
// aborted. Bounds the lifetime of anything that must not outlive the render.
438
- renderLifetimeController: AbortController,
438
+ // Null until attachAbortSignal creates it, so a render that is given no
439
+ // signal constructs no controller.
440
+ renderLifetimeController: null | AbortController,
441
// Form state that was the result of an MPA submission, if it was provided.
442
formState: null | ReactFormState<any, any>,
443
// DEV-only, warning dedupe
591
this.onShellReady = onShellReady === undefined ? noop : onShellReady;
592
this.onShellError = onShellError === undefined ? noop : onShellError;
593
this.onFatalError = onFatalError === undefined ? noop : onFatalError;
592
- this.renderLifetimeController = new AbortController();
594
+ this.renderLifetimeController = null;
595
this.formState = formState === undefined ? null : formState;
596
if (__DEV__) {
597
this.didWarnForKey = null;
1457
}
1458
onFatalError(error);
1459
}
1458
- request.renderLifetimeController.abort(RENDER_ENDED);
1460
+ endRenderLifetime(request);
1461
if (request.destination !== null) {
1462
request.status = CLOSED;
1463
closeWithError(request.destination, error);
6354
}
6355
}
6356
// We're done.
6355
- request.renderLifetimeController.abort(RENDER_ENDED);
6357
+ endRenderLifetime(request);
6358
request.status = CLOSED;
6359
close(destination);
6360
// We need to stop flowing now because we do not want any async contexts which might call
6518
}
6519
}
6520
6521
+function endRenderLifetime(request: Request): void {
6522
+ const renderLifetimeController = request.renderLifetimeController;
6523
+ if (renderLifetimeController !== null) {
6524
+ renderLifetimeController.abort(RENDER_ENDED);
6525
+ }
6526
+}
6527
+
6528
// Aborts the request when the caller's signal aborts. The render lifetime
6529
// bounds the listener, so the runtime removes the listener as soon as the
6530
// render ends. From that point on abort() returns early, so the listener has
6542
abort(request, signal.reason);
6543
return;
6544
}
6545
+ const renderLifetimeController = new AbortController();
6546
+ request.renderLifetimeController = renderLifetimeController;
6547
signal.addEventListener(
6548
'abort',
6549
() => {
6550
abort(request, signal.reason);
6551
},
6541
- {signal: request.renderLifetimeController.signal},
6552
+ {signal: renderLifetimeController.signal},
6553
);
6554
}
6555
6563
// can be aborted. in practice this makes abort callable at most once per render.
6564
return;
6565
}
6555
- request.renderLifetimeController.abort(RENDER_ENDED);
6566
+ endRenderLifetime(request);
6567
const isRecoverableReason =
6568
typeof reason === 'object' &&
6569
reason !== null &&