Skip to content

Commit aa99216

Browse files
committed
Test component names of lazy Blocks
1 parent cdb1df3 commit aa99216

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

packages/react-reconciler/src/__tests__/ReactBlocks-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,43 @@ describe('ReactBlocks', () => {
4949
};
5050
});
5151

52+
it.experimental('prints the name of the render function in warnings', () => {
53+
function Query(firstName) {
54+
return {
55+
name: firstName,
56+
};
57+
}
58+
59+
function User(props, data) {
60+
let array = [<span>{data.name}</span>];
61+
return <div>{array}</div>;
62+
}
63+
64+
function App({Component}) {
65+
return (
66+
<Suspense fallback={'Loading...'}>
67+
<Component name="Name" />
68+
</Suspense>
69+
);
70+
}
71+
72+
let loadUser = block(Query, User);
73+
74+
expect(() => {
75+
ReactNoop.act(() => {
76+
ReactNoop.render(<App Component={loadUser()} />);
77+
});
78+
}).toErrorDev(
79+
'Warning: Each child in a list should have a unique ' +
80+
'"key" prop.\n\nCheck the render method of `User`. See ' +
81+
'https://fb.me/react-warning-keys for more information.\n' +
82+
' in span (at **)\n' +
83+
' in User (at **)\n' +
84+
' in Suspense (at **)\n' +
85+
' in App (at **)',
86+
);
87+
});
88+
5289
it.experimental('renders a component with a suspending query', async () => {
5390
function Query(id) {
5491
return {

packages/shared/getComponentName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function getComponentName(type: mixed): string | null {
8787
case REACT_MEMO_TYPE:
8888
return getComponentName(type.type);
8989
case REACT_BLOCK_TYPE:
90-
return getComponentName(type.render);
90+
return getComponentName(type._render);
9191
case REACT_LAZY_TYPE: {
9292
const lazyComponent: LazyComponent<any, any> = (type: any);
9393
let payload = lazyComponent._payload;

0 commit comments

Comments
 (0)