Skip to content

Commit bc1d261

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 f973ad4 commit bc1d261

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -690,14 +690,19 @@ describe('ReactFlight', () => {
690690

691691
const transport = ReactNoopFlightServer.render(<ServerComponent />);
692692

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

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

packages/react-server/src/ReactFlightServer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,14 @@ function renderElement(
15911591
validated,
15921592
);
15931593
}
1594+
case REACT_ELEMENT_TYPE: {
1595+
// This is invalid but we'll let the client determine that it is.
1596+
if (__DEV__) {
1597+
// Disable the key warning that would happen otherwise because this
1598+
// element gets serialized inside an array. We'll error later anyway.
1599+
type._store.validated = 1;
1600+
}
1601+
}
15941602
}
15951603
}
15961604
// For anything else, try it on the client instead.

0 commit comments

Comments
 (0)