mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix component name for React.lazy (#13443)
* Fix component name for React.lazy * Fix lint
This commit is contained in:
@@ -1576,6 +1576,30 @@ describe('ReactSuspense', () => {
|
||||
span('C'),
|
||||
]);
|
||||
});
|
||||
|
||||
it('includes lazy-loaded component in warning stack', async () => {
|
||||
const LazyFoo = lazy(() => {
|
||||
ReactNoop.yield('Started loading');
|
||||
const Foo = props => (
|
||||
<div>{[<Text text="A" />, <Text text="B" />]}</div>
|
||||
);
|
||||
return Promise.resolve(Foo);
|
||||
});
|
||||
|
||||
ReactNoop.render(
|
||||
<Placeholder fallback={<Text text="Loading..." />}>
|
||||
<LazyFoo />
|
||||
</Placeholder>,
|
||||
);
|
||||
expect(ReactNoop.flush()).toEqual(['Started loading', 'Loading...']);
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
|
||||
await LazyFoo;
|
||||
expect(() => {
|
||||
expect(ReactNoop.flush()).toEqual(['A', 'B']);
|
||||
}).toWarnDev(' in Text (at **)\n' + ' in Foo (at **)');
|
||||
expect(ReactNoop.getChildren()).toEqual([div(span('A'), span('B'))]);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not call lifecycles of a suspended component', async () => {
|
||||
|
||||
@@ -21,10 +21,7 @@ import {
|
||||
REACT_STRICT_MODE_TYPE,
|
||||
REACT_PLACEHOLDER_TYPE,
|
||||
} from 'shared/ReactSymbols';
|
||||
import {
|
||||
getResultFromResolvedThenable,
|
||||
refineResolvedThenable,
|
||||
} from 'shared/ReactLazyComponent';
|
||||
import {refineResolvedThenable} from 'shared/ReactLazyComponent';
|
||||
|
||||
function getComponentName(type: mixed): string | null {
|
||||
if (type == null) {
|
||||
@@ -77,8 +74,7 @@ function getComponentName(type: mixed): string | null {
|
||||
const thenable: Thenable<mixed> = (type: any);
|
||||
const resolvedThenable = refineResolvedThenable(thenable);
|
||||
if (resolvedThenable) {
|
||||
const Component = getResultFromResolvedThenable(resolvedThenable);
|
||||
return getComponentName(Component);
|
||||
return getComponentName(resolvedThenable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user