Skip to content

Commit 1b22d49

Browse files
Brian Vaughnfacebook-github-bot
Brian Vaughn
authored andcommitted
renderApplication() supports async initial render
Reviewed By: sahrens Differential Revision: D6339469 fbshipit-source-id: d832de936c50edcdc6953b72b5ad18ce1b652187
1 parent ad89ea7 commit 1b22d49

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Libraries/ReactNative/renderApplication.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,32 @@ function renderApplication<Props: Object>(
3030
) {
3131
invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag);
3232

33-
ReactNative.render(
33+
let renderable = (
3434
<AppContainer rootTag={rootTag} WrapperComponent={WrapperComponent}>
3535
<RootComponent {...initialProps} rootTag={rootTag} />
36-
</AppContainer>,
37-
rootTag,
36+
</AppContainer>
3837
);
38+
39+
// If the root component is async, the user probably wants the initial render
40+
// to be async also. To do this, wrap AppContainer with an async marker.
41+
// For more info see https://fburl.com/tjpe0gpx
42+
if (
43+
RootComponent.prototype != null &&
44+
RootComponent.prototype.unstable_isAsyncReactComponent === true
45+
) {
46+
// $FlowFixMe This is not yet part of the official public API
47+
class AppContainerAsyncWrapper extends React.unstable_AsyncComponent {
48+
render() {
49+
return this.props.children;
50+
}
51+
}
52+
53+
renderable = (
54+
<AppContainerAsyncWrapper>{renderable}</AppContainerAsyncWrapper>
55+
);
56+
}
57+
58+
ReactNative.render(renderable, rootTag);
3959
}
4060

4161
module.exports = renderApplication;

0 commit comments

Comments
 (0)