Skip to content

Commit c3cdbec

Browse files
authored
[Flight] Add context for non null prototype error (#30293)
We already added this for other thrown errors, not just console.errors. There's a production form of this. We just missed adding this context. Mainly the best context is the line number though which comes from owner stacks.
1 parent 491a4ea commit c3cdbec

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

packages/react-client/src/ReactFlightReplyClient.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ export function processReply(
692692
if (temporaryReferences === undefined) {
693693
throw new Error(
694694
'Only plain objects, and a few built-ins, can be passed to Server Actions. ' +
695-
'Classes or null prototypes are not supported.',
695+
'Classes or null prototypes are not supported.' +
696+
(__DEV__ ? describeObjectForErrorMessage(parent, key) : ''),
696697
);
697698
}
698699
// We will have written this object to the temporary reference set above

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,10 @@ describe('ReactFlight', () => {
14821482

14831483
expect(errors).toEqual([
14841484
'Only plain objects, and a few built-ins, can be passed to Client Components ' +
1485-
'from Server Components. Classes or null prototypes are not supported.',
1485+
'from Server Components. Classes or null prototypes are not supported.' +
1486+
(__DEV__
1487+
? '\n' + ' <input value={{}}>\n' + ' ^^^^'
1488+
: '\n' + ' {value: {}}\n' + ' ^^'),
14861489
]);
14871490
});
14881491

packages/react-server/src/ReactFlightServer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2615,7 +2615,8 @@ function renderModelDestructive(
26152615
) {
26162616
throw new Error(
26172617
'Only plain objects, and a few built-ins, can be passed to Client Components ' +
2618-
'from Server Components. Classes or null prototypes are not supported.',
2618+
'from Server Components. Classes or null prototypes are not supported.' +
2619+
describeObjectForErrorMessage(parent, parentPropertyName),
26192620
);
26202621
}
26212622
if (__DEV__) {

scripts/error-codes/codes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@
483483
"495": "Cannot taint a %s because the value is too general and not unique enough to block globally.",
484484
"496": "Only objects or functions can be passed to taintObjectReference. Try taintUniqueValue instead.",
485485
"497": "Only objects or functions can be passed to taintObjectReference.",
486-
"498": "Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported.",
487-
"499": "Only plain objects, and a few built-ins, can be passed to Server Actions. Classes or null prototypes are not supported.",
486+
"498": "Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported.%s",
487+
"499": "Only plain objects, and a few built-ins, can be passed to Server Actions. Classes or null prototypes are not supported.%s",
488488
"500": "React expected a headers state to exist when emitEarlyPreloads was called but did not find it. This suggests emitEarlyPreloads was called more than once per request. This is a bug in React.",
489489
"501": "The render was aborted with postpone when the shell is incomplete. Reason: %s",
490490
"502": "Cannot read a Client Context from a Server Component.",

0 commit comments

Comments
 (0)