Skip to content

Commit bd5c1c7

Browse files
committed
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 3b201dd commit bd5c1c7

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 5 additions & 0 deletions
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/src/ReactFlightServer.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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)