@samitouri / QOS-React-1 / commits / c3cdbec0a7

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

Sebastian Markbåge committed Jul 8, 2024 at 22:51 UTC c3cdbec0a78d39b5ff7329384cb41c4573a38212
4 files changed +10 -5
packages/react-client/src/ReactFlightReplyClient.js
+2 -1
@@ -692,7 +692,8 @@ export function processReply(
692 if (temporaryReferences === undefined) {
693 throw new Error(
694 '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) : ''),
697 );
698 }
699 // We will have written this object to the temporary reference set above
packages/react-client/src/__tests__/ReactFlight-test.js
+4 -1
@@ -1482,7 +1482,10 @@ describe('ReactFlight', () => {
1482
1483 expect(errors).toEqual([
1484 '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' + ' ^^'),
1489 ]);
1490 });
1491
packages/react-server/src/ReactFlightServer.js
+2 -1
@@ -2615,7 +2615,8 @@ function renderModelDestructive(
2615 ) {
2616 throw new Error(
2617 '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),
2620 );
2621 }
2622 if (__DEV__) {
scripts/error-codes/codes.json
+2 -2
@@ -483,8 +483,8 @@
483 "495": "Cannot taint a %s because the value is too general and not unique enough to block globally.",
484 "496": "Only objects or functions can be passed to taintObjectReference. Try taintUniqueValue instead.",
485 "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",
488 "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.",
489 "501": "The render was aborted with postpone when the shell is incomplete. Reason: %s",
490 "502": "Cannot read a Client Context from a Server Component.",