@@ -44,20 +44,22 @@ var {
4444 Callback,
4545} = ReactTypeOfSideEffect ;
4646
47- module . exports = function < T , P , I , TI , C > (
48- config : HostConfig < T , P , I , TI , C > ,
49- hostContext : HostContext < I , C > ,
47+ module . exports = function < T , P , I , TI , C , CX > (
48+ config : HostConfig < T , P , I , TI , C , CX > ,
49+ hostContext : HostContext < C , CX > ,
5050) {
5151 const {
52+ createInstance,
53+ createTextInstance,
5254 appendInitialChild,
5355 finalizeInitialChildren,
5456 prepareUpdate,
5557 } = config ;
5658
5759 const {
58- getRootHostContainerOnStack ,
59- getHostContainerOnStack ,
60- popHostContainer ,
60+ getRootHostContainer ,
61+ maybePopHostContext ,
62+ getCurrentHostContext ,
6163 restoreHostContextFromPortal,
6264 } = hostContext ;
6365
@@ -212,15 +214,8 @@ module.exports = function<T, P, I, TI, C>(
212214 return null;
213215 }
214216 case HostComponent :
215- const instance : I = workInProgress . stateNode ;
216- if ( ! instance ) {
217- throw new Error ( 'Expected host instance to be created in begin phase.' ) ;
218- }
219- if (instance === getHostContainerOnStack()) {
220- popHostContainer ( ) ;
221- }
222217 let newProps = workInProgress . pendingProps ;
223- if (current) {
218+ if ( current && workInProgress . stateNode != null ) {
224219 // If we have an alternate, that means this is an update and we need to
225220 // schedule a side-effect to do the updates.
226221 const oldProps = current . memoizedProps ;
@@ -231,6 +226,7 @@ module.exports = function<T, P, I, TI, C>(
231226 if ( ! newProps ) {
232227 newProps = workInProgress . memoizedProps || oldProps ;
233228 }
229+ const instance : I = workInProgress.stateNode;
234230 if (prepareUpdate(instance, oldProps, newProps)) {
235231 // This returns true if there was something to update.
236232 markUpdate ( workInProgress ) ;
@@ -245,29 +241,35 @@ module.exports = function<T, P, I, TI, C>(
245241 }
246242 }
247243
248- const rootContainerInstance = getRootHostContainerOnStack ( ) ;
249- if ( rootContainerInstance == null ) {
250- throw new Error ( 'Expected to find a root instance on the host stack.' ) ;
251- }
252- // TODO: Keep the instance on a context "stack" as the parent.
253- // Then append children as we go in beginWork or completeWork
254- // depending on we want to add then top-> down or bottom - > up .
255- // Top->down is faster in IE11.
256- // Finally, finalizeInitialChildren here in completeWork.
244+ const rootContainerInstance = getRootHostContainer ( ) ;
245+ const currentHostContext = getCurrentHostContext ( ) ;
246+ // TODO: Move createInstance to beginWork and keep it on a context
247+ // "stack" as the parent. Then append children as we go in beginWork
248+ // or completeWork depending on we want to add then top->down or
249+ // bottom->up. Top->down is faster in IE11.
250+ const instance = createInstance (
251+ workInProgress . type ,
252+ newProps ,
253+ rootContainerInstance ,
254+ currentHostContext ,
255+ workInProgress
256+ ) ;
257257 appendAllChildren ( instance , workInProgress ) ;
258258 finalizeInitialChildren ( instance , newProps , rootContainerInstance ) ;
259259
260+ workInProgress . stateNode = instance ;
260261 if ( workInProgress . ref ) {
261262 // If there is a ref on a host node we need to schedule a callback
262263 markUpdate ( workInProgress ) ;
263264 }
264265 }
266+ maybePopHostContext ( workInProgress ) ;
265267 workInProgress . memoizedProps = newProps ;
266268 return null ;
267269 case HostText :
268270 let newText = workInProgress . pendingProps ;
269271 if ( current && workInProgress . stateNode != null ) {
270- const oldText = current . memoizedProps ;
272+ const oldText = current . memoizedProps ;
271273 if ( newText === null ) {
272274 // If this was a bail out we need to fall back to memoized text.
273275 // This works the same way as HostComponent.
@@ -281,6 +283,17 @@ module.exports = function<T, P, I, TI, C>(
281283 if ( oldText !== newText ) {
282284 markUpdate ( workInProgress ) ;
283285 }
286+ } else {
287+ if ( typeof newText !== 'string' ) {
288+ if ( workInProgress . stateNode === null ) {
289+ throw new Error ( 'We must have new props for new mounts.' ) ;
290+ } else {
291+ // This can happen when we abort work.
292+ return null ;
293+ }
294+ }
295+ const textInstance = createTextInstance ( newText , workInProgress ) ;
296+ workInProgress . stateNode = textInstance ;
284297 }
285298 workInProgress . memoizedProps = newText ;
286299 return null ;
0 commit comments