Skip to content

Commit fdfec40

Browse files
committed
Disable key warning when element used as type
This gets serialized as a tuple in the Flight protocol so we think it needs a key but it doesn't. It'll error later on the client. Fix test asserting lazy because it's not actually executing the rendering pass on the client since the transport is not live in Noop. Technically this doesn't error if the Shared Component renders something that can be a type since we actually resolve this component as if it is just some value.
1 parent eb947b5 commit fdfec40

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -692,14 +692,22 @@ describe('ReactFlight', () => {
692692

693693
const transport = ReactNoopFlightServer.render(<ServerComponent />);
694694

695-
await act(async () => {
696-
const rootModel = await ReactNoopFlightClient.read(transport);
697-
ReactNoop.render(rootModel);
698-
});
699-
expect(ReactNoop).toMatchRenderedOutput('Loading...');
700-
spyOnDevAndProd(console, 'error').mockImplementation(() => {});
701695
await load();
702-
expect(console.error).toHaveBeenCalledTimes(1);
696+
697+
await expect(async () => {
698+
await act(async () => {
699+
const rootModel = await ReactNoopFlightClient.read(transport);
700+
ReactNoop.render(rootModel);
701+
});
702+
}).rejects.toThrow(
703+
__DEV__
704+
? 'Element type is invalid: expected a string (for built-in components) or a class/function ' +
705+
'(for composite components) but got: <div />. ' +
706+
'Did you accidentally export a JSX literal instead of a component?'
707+
: 'Element type is invalid: expected a string (for built-in components) or a class/function ' +
708+
'(for composite components) but got: object.',
709+
);
710+
expect(ReactNoop).toMatchRenderedOutput(null);
703711
});
704712

705713
it('can render a lazy element', async () => {

packages/react-server/src/ReactFlightServer.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ import {
110110
} from 'shared/ReactSymbols';
111111

112112
import {
113-
describeValueForErrorMessage,
114113
describeObjectForErrorMessage,
115114
isSimpleObject,
116115
jsxPropsParents,
@@ -1591,6 +1590,14 @@ function renderElement(
15911590
validated,
15921591
);
15931592
}
1593+
case REACT_ELEMENT_TYPE: {
1594+
// This is invalid but we'll let the client determine that it is.
1595+
if (__DEV__) {
1596+
// Disable the key warning that would happen otherwise because this
1597+
// element gets serialized inside an array. We'll error later anyway.
1598+
type._store.validated = 1;
1599+
}
1600+
}
15941601
}
15951602
}
15961603
// For anything else, try it on the client instead.

0 commit comments

Comments
 (0)