@samitouri / QOS-React-2 / commits / 8d1b057ec1

[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.

Sebastian Markbåge committed Aug 31, 2022 at 18:40 UTC 8d1b057ec1394cecdbc5a63b1c8b2cd443afa7b2
4 files changed +16 -4
packages/react-client/src/ReactFlightClient.js
+5
@@ -312,6 +312,11 @@ export function parseModelString(
312 } else {
313 const id = parseInt(value.substring(1), 16);
314 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 + }
320 return readChunk(chunk);
321 }
322 }
packages/react-server-dom-webpack/src/ReactFlightDOMClient.js
+8 -2
@@ -35,12 +35,18 @@ function startReadingFromStream(
35 }
36 const buffer: Uint8Array = (value: any);
37 processBinaryChunk(response, buffer);
38 - return reader.read().then(progress, error);
38 + return reader
39 + .read()
40 + .then(progress)
41 + .catch(error);
42 }
43 function error(e) {
44 reportGlobalError(response, e);
45 }
43 - reader.read().then(progress, error);
46 + reader
47 + .read()
48 + .then(progress)
49 + .catch(error);
50 }
51
52 function createFromReadableStream(
packages/react-server/src/ReactFlightServer.js
+1 -1
@@ -902,7 +902,7 @@ function abortTask(task: Task, request: Request, errorId: number): void {
902 // has a single value referencing the error.
903 const ref = serializeByValueID(errorId);
904 const processedChunk = processReferenceChunk(request, task.id, ref);
905 - request.completedJSONChunks.push(processedChunk);
905 + request.completedErrorChunks.push(processedChunk);
906 }
907
908 function flushCompletedChunks(
scripts/error-codes/codes.json
+2 -1
@@ -423,5 +423,6 @@
423 "435": "Unexpected Suspense handler tag (%s). This is a bug in React.",
424 "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\".",
425 "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."
428 }