Skip to content

Commit 8d1b057

Browse files
authored
[Flight] Minor error handling fixes (#25151)
* Fix error handling when the Flight client itself errors * Serialize references to errors in the error priority queue It doesn't make sense to emit references to future values at higher pri than the value that they're referencing. This ensures that we don't emit hard forward references to values that don't yet exist.
1 parent 7e5322c commit 8d1b057

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

packages/react-client/src/ReactFlightClient.js

+5
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ export function parseModelString(
312312
} else {
313313
const id = parseInt(value.substring(1), 16);
314314
const chunk = getChunk(response, id);
315+
if (chunk._status === PENDING) {
316+
throw new Error(
317+
"We didn't expect to see a forward reference. This is a bug in the React Server.",
318+
);
319+
}
315320
return readChunk(chunk);
316321
}
317322
}

packages/react-server-dom-webpack/src/ReactFlightDOMClient.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ function startReadingFromStream(
3535
}
3636
const buffer: Uint8Array = (value: any);
3737
processBinaryChunk(response, buffer);
38-
return reader.read().then(progress, error);
38+
return reader
39+
.read()
40+
.then(progress)
41+
.catch(error);
3942
}
4043
function error(e) {
4144
reportGlobalError(response, e);
4245
}
43-
reader.read().then(progress, error);
46+
reader
47+
.read()
48+
.then(progress)
49+
.catch(error);
4450
}
4551

4652
function createFromReadableStream(

packages/react-server/src/ReactFlightServer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ function abortTask(task: Task, request: Request, errorId: number): void {
902902
// has a single value referencing the error.
903903
const ref = serializeByValueID(errorId);
904904
const processedChunk = processReferenceChunk(request, task.id, ref);
905-
request.completedJSONChunks.push(processedChunk);
905+
request.completedErrorChunks.push(processedChunk);
906906
}
907907

908908
function flushCompletedChunks(

scripts/error-codes/codes.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -423,5 +423,6 @@
423423
"435": "Unexpected Suspense handler tag (%s). This is a bug in React.",
424424
"436": "Stylesheet resources need a unique representation in the DOM while hydrating and more than one matching DOM Node was found. To fix, ensure you are only rendering one stylesheet link with an href attribute of \"%s\".",
425425
"437": "the \"precedence\" prop for links to stylesheets expects to receive a string but received something of type \"%s\" instead.",
426-
"438": "An unsupported type was passed to use(): %s"
426+
"438": "An unsupported type was passed to use(): %s",
427+
"439": "We didn't expect to see a forward reference. This is a bug in the React Server."
427428
}

0 commit comments

Comments
 (0)