Skip to content

Commit

Permalink
Defer fatal errors in Flight too
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Sep 28, 2021
1 parent e3225af commit 82e00d5
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type Segment = {
};

export type Request = {
status: 0 | 1 | 2,
fatalError: mixed,
destination: null | Destination,
bundlerConfig: BundlerConfig,
cache: Map<Function, mixed>,
Expand All @@ -90,16 +92,23 @@ export type Request = {
const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;

function defaultErrorHandler(error: mixed) {
console['error'](error); // Don't transform to our wrapper
console['error'](error);
// Don't transform to our wrapper
}

const OPEN = 0;
const CLOSING = 1;
const CLOSED = 2;

export function createRequest(
model: ReactModel,
bundlerConfig: BundlerConfig,
onError: void | ((error: mixed) => void),
): Request {
const pingedSegments = [];
const request = {
status: 0,
fatalError: null,
destination: null,
bundlerConfig,
cache: new Map(),
Expand Down Expand Up @@ -602,7 +611,11 @@ function reportError(request: Request, error: mixed): void {
function fatalError(request: Request, error: mixed): void {
// This is called outside error handling code such as if an error happens in React internals.
if (request.destination !== null) {
request.status = CLOSED;
closeWithError(request.destination, error);
} else {
request.status = CLOSING;
request.fatalError = error;
}
}

Expand Down Expand Up @@ -768,6 +781,14 @@ export function startWork(request: Request): void {
}

export function startFlowing(request: Request, destination: Destination): void {
if (request.status === CLOSING) {
request.status = CLOSED;
closeWithError(destination, request.fatalError);
return;
}
if (request.status === CLOSED) {
return;
}
request.destination = destination;
try {
flushCompletedChunks(request, destination);
Expand Down

0 comments on commit 82e00d5

Please sign in to comment.