mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Log Fragment name when trying to render a lazy fragment (#30372)
This commit is contained in:
+3
-1
@@ -1891,11 +1891,13 @@ function mountLazyComponent(
|
||||
}
|
||||
}
|
||||
|
||||
const loggedComponent = getComponentNameFromType(Component) || Component;
|
||||
|
||||
// This message intentionally doesn't mention ForwardRef or MemoComponent
|
||||
// because the fact that it's a separate type of work is an
|
||||
// implementation detail.
|
||||
throw new Error(
|
||||
`Element type is invalid. Received a promise that resolves to: ${Component}. ` +
|
||||
`Element type is invalid. Received a promise that resolves to: ${loggedComponent}. ` +
|
||||
`Lazy element type must resolve to a class or function.${hint}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -757,6 +757,32 @@ describe('ReactLazy', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('throws with a useful error when wrapping fragment with lazy()', async () => {
|
||||
const BadLazy = lazy(() => fakeImport(React.Fragment));
|
||||
|
||||
const root = ReactTestRenderer.create(
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
<BadLazy />
|
||||
</Suspense>,
|
||||
{
|
||||
unstable_isConcurrent: true,
|
||||
},
|
||||
);
|
||||
|
||||
await waitForAll(['Loading...']);
|
||||
|
||||
await resolveFakeImport(React.Fragment);
|
||||
root.update(
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
<BadLazy />
|
||||
</Suspense>,
|
||||
);
|
||||
await waitForThrow(
|
||||
'Element type is invalid. Received a promise that resolves to: Fragment. ' +
|
||||
'Lazy element type must resolve to a class or function.',
|
||||
);
|
||||
});
|
||||
|
||||
it('throws with a useful error when wrapping lazy() multiple times', async () => {
|
||||
const Lazy1 = lazy(() => fakeImport(Text));
|
||||
const Lazy2 = lazy(() => fakeImport(Lazy1));
|
||||
|
||||
Reference in New Issue
Block a user