mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
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 () => {
|
||||
|
||||
Reference in New Issue
Block a user