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>
Andrew Clark committed
Jul 23, 2018 at 17:47 UTC
ca0941fce3a03592530f6111f77cbc9c0daf79af
1 file changed
+31
packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js
+31
@@ -1314,6 +1314,37 @@ describe('ReactSuspense', () => {
1314
1315
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
1316
});
1317
+
1318
+ it('does not infinite loop if fallback contains lifecycle method', async () => {
1319
+ class Fallback extends React.Component {
1320
+ state = {
1321
+ name: 'foo',
1322
+ };
1323
+ componentDidMount() {
1324
+ this.setState({
1325
+ name: 'bar',
1326
+ });
1327
+ }
1328
+ render() {
1329
+ return <Text text="Loading..." />;
1330
+ }
1331
+ }
1332
+
1333
+ class Demo extends React.Component {
1334
+ render() {
1335
+ return (
1336
+ <Placeholder fallback={<Fallback />}>
1337
+ <AsyncText text="Hi" ms={100} />
1338
+ </Placeholder>
1339
+ );
1340
+ }
1341
+ }
1342
+
1343
+ ReactNoop.renderLegacySyncRoot(<Demo />);
1344
+ expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
1345
+ await advanceTimers(100);
1346
+ expect(ReactNoop.getChildren()).toEqual([span('Hi')]);
1347
+ });
1348
});
1349
1350
it('does not call lifecycles of a suspended component', async () => {