Fix component name for React.lazy (#13443)

* Fix component name for React.lazy

* Fix lint
This commit is contained in:
Dan Abramov
2018-08-20 16:43:25 +01:00
committed by GitHub
parent 0beb2ee76b
commit 973496b40c
2 changed files with 26 additions and 6 deletions
@@ -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 () => {
+2 -6
View File
@@ -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);
}
}
}