Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,13 +938,29 @@ describe('ReactFlight', () => {
});
});

// @gate renameElementSymbol
it('should emit descriptions of errors in dev', async () => {
const ClientErrorBoundary = clientReference(ErrorBoundary);

function Throw({value}) {
throw value;
}

function RenderInlined() {
const inlinedElement = {
$$typeof: Symbol.for('react.element'),
type: () => {},
key: null,
ref: null,
props: {},
_owner: null,
};
return inlinedElement;
}

// We wrap in lazy to ensure the errors throws lazily.
const LazyInlined = React.lazy(async () => ({default: RenderInlined}));

const testCases = (
<>
<ClientErrorBoundary expectedMessage="This is a real Error.">
Expand Down Expand Up @@ -1010,6 +1026,18 @@ describe('ReactFlight', () => {
<Throw value={['array']} />
</div>
</ClientErrorBoundary>
<ClientErrorBoundary
expectedMessage={
'A React Element from an older version of React was rendered. ' +
'This is not supported. It can happen if:\n' +
'- Multiple copies of the "react" package is used.\n' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'- Multiple copies of the "react" package is used.\n' +
'- Multiple copies of the "react" package are used.\n' +

'- A library pre-bundled an old copy of "react" or "react/jsx-runtime".\n' +
'- A compiler tries to "inline" JSX instead of using the runtime.'
}>
<div>
<LazyInlined />
</div>
</ClientErrorBoundary>
</>
);

Expand Down
10 changes: 10 additions & 0 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import {resolveOwner, setCurrentOwner} from './flight/ReactFlightCurrentOwner';
import {
getIteratorFn,
REACT_ELEMENT_TYPE,
REACT_LEGACY_ELEMENT_TYPE,
REACT_FORWARD_REF_TYPE,
REACT_FRAGMENT_TYPE,
REACT_LAZY_TYPE,
Expand Down Expand Up @@ -2004,6 +2005,15 @@ function renderModelDestructive(
resolvedModel,
);
}
case REACT_LEGACY_ELEMENT_TYPE: {
throw new Error(
'A React Element from an older version of React was rendered. ' +
'This is not supported. It can happen if:\n' +
'- Multiple copies of the "react" package is used.\n' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'- Multiple copies of the "react" package is used.\n' +
'- Multiple copies of the "react" package are used.\n' +

'- A library pre-bundled an old copy of "react" or "react/jsx-runtime".\n' +
'- A compiler tries to "inline" JSX instead of using the runtime.',
);
}
}

if (isClientReference(value)) {
Expand Down