Skip to content

Commit e08eb2b

Browse files
committed
fix: delay portal rendering to avoid infinite loop
1 parent 2876227 commit e08eb2b

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"react": "16.6.0-alpha.8af6728",
8282
"react-dom": "16.6.0-alpha.8af6728",
8383
"react-native": "~0.57.4",
84+
"react-native-testing-library": "^1.5.0",
8485
"react-native-vector-icons": "~6.0.2",
8586
"react-test-renderer": "16.6.0-alpha.8af6728",
8687
"release-it": "^7.6.2",

src/components/Portal/PortalConsumer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type Props = {|
1010
|};
1111

1212
export default class PortalConsumer extends React.Component<Props> {
13-
componentDidMount() {
13+
async componentDidMount() {
1414
if (!this.props.manager) {
1515
throw new Error(
1616
'Looks like you forgot to wrap your root component with `Provider` component from `react-native-paper`.\n\n' +
@@ -19,6 +19,9 @@ export default class PortalConsumer extends React.Component<Props> {
1919
);
2020
}
2121

22+
// Delay updating to prevent React from going to infinite loop
23+
await Promise.resolve();
24+
2225
this._key = this.props.manager.mount(this.props.children);
2326
}
2427

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/* @flow */
22

33
import * as React from 'react';
4-
import renderer from 'react-test-renderer';
4+
import { render, waitForElement } from 'react-native-testing-library';
55
import { Text } from 'react-native';
66
import Portal from '../Portal/Portal';
77

8-
it('renders portal with siblings', () => {
9-
const tree = renderer
10-
.create(
11-
<Portal.Host>
12-
<Text>Outside content</Text>
13-
<Portal>
14-
<Text>Portal content</Text>
15-
</Portal>
16-
</Portal.Host>
17-
)
18-
.toJSON();
8+
it('renders portal with siblings', async () => {
9+
const { toJSON, getByTestId } = render(
10+
<Portal.Host>
11+
<Text>Outside content</Text>
12+
<Portal>
13+
<Text testID="content">Portal content</Text>
14+
</Portal>
15+
</Portal.Host>
16+
);
1917

20-
expect(tree).toMatchSnapshot();
18+
await waitForElement(() => getByTestId('content'));
19+
20+
expect(toJSON()).toMatchSnapshot();
2121
});

src/components/__tests__/__snapshots__/Portal.test.js.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ Array [
2727
}
2828
}
2929
>
30-
<Text>
30+
<Text
31+
testID="content"
32+
>
3133
Portal content
3234
</Text>
3335
</View>,

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7402,6 +7402,13 @@ react-lifecycles-compat@^3.0.4:
74027402
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
74037403
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
74047404

7405+
react-native-testing-library@^1.5.0:
7406+
version "1.5.0"
7407+
resolved "https://registry.yarnpkg.com/react-native-testing-library/-/react-native-testing-library-1.5.0.tgz#02762bf8cb5c1295a220d5e5d40ffc2ebecf31da"
7408+
integrity sha512-ivS0K0uu8PnAU1DPi2LobZMDcWqQFZUFFP2NiGA1wFKgsGuv2zIGuiBY8mJVAtU2FnPMyVDfg5rL6XoyyCj+jg==
7409+
dependencies:
7410+
pretty-format "^23.6.0"
7411+
74057412
react-native-vector-icons@~6.0.2:
74067413
version "6.0.2"
74077414
resolved "https://registry.yarnpkg.com/react-native-vector-icons/-/react-native-vector-icons-6.0.2.tgz#826252a72d648cf957d46ada8df890318dac53e1"

0 commit comments

Comments
 (0)