From 1b22d49ae8945680dee4fd01e3fbb78b1e443e01 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 17 Nov 2017 13:30:06 -0800 Subject: [PATCH] renderApplication() supports async initial render Reviewed By: sahrens Differential Revision: D6339469 fbshipit-source-id: d832de936c50edcdc6953b72b5ad18ce1b652187 --- Libraries/ReactNative/renderApplication.js | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Libraries/ReactNative/renderApplication.js b/Libraries/ReactNative/renderApplication.js index a1e96f30dbb3ca..41e25c1c1ccc7f 100644 --- a/Libraries/ReactNative/renderApplication.js +++ b/Libraries/ReactNative/renderApplication.js @@ -30,12 +30,32 @@ function renderApplication( ) { invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag); - ReactNative.render( + let renderable = ( - , - rootTag, + ); + + // If the root component is async, the user probably wants the initial render + // to be async also. To do this, wrap AppContainer with an async marker. + // For more info see https://fburl.com/tjpe0gpx + if ( + RootComponent.prototype != null && + RootComponent.prototype.unstable_isAsyncReactComponent === true + ) { + // $FlowFixMe This is not yet part of the official public API + class AppContainerAsyncWrapper extends React.unstable_AsyncComponent { + render() { + return this.props.children; + } + } + + renderable = ( + {renderable} + ); + } + + ReactNative.render(renderable, rootTag); } module.exports = renderApplication;