Add regression test for Placeholder fallbacks with lifecycle methods (#13254)

Found by @rhagigi

Co-authored-by: Royi Hagigi <rhagigi@gmail.com>
Co-authored-by: Andrew Clark <acdlite@me.com>
This commit is contained in:
Andrew Clark
2018-07-23 17:47:40 -07:00
committed by GitHub
co-authored by Royi Hagigi
parent a32c727f2e
commit ca0941fce3
@@ -1314,6 +1314,37 @@ describe('ReactSuspense', () => {
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
});
it('does not infinite loop if fallback contains lifecycle method', async () => {
class Fallback extends React.Component {
state = {
name: 'foo',
};
componentDidMount() {
this.setState({
name: 'bar',
});
}
render() {
return <Text text="Loading..." />;
}
}
class Demo extends React.Component {
render() {
return (
<Placeholder fallback={<Fallback />}>
<AsyncText text="Hi" ms={100} />
</Placeholder>
);
}
}
ReactNoop.renderLegacySyncRoot(<Demo />);
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
await advanceTimers(100);
expect(ReactNoop.getChildren()).toEqual([span('Hi')]);
});
});
it('does not call lifecycles of a suspended component', async () => {