4141} = require ( 'ReactPriorityLevel' ) ;
4242
4343var {
44- Focus,
4544 NoEffect,
4645 Placement,
4746 Update,
@@ -76,7 +75,12 @@ var timeHeuristicForUnitOfWork = 1;
7675
7776module . exports = function < T , P , I , TI , C , CX > ( config : HostConfig < T , P , I , TI , C , CX > ) {
7877 const hostContext = ReactFiberHostContext ( config ) ;
79- const { popHostContainer, popHostContext, resetHostContainer } = hostContext ;
78+ const {
79+ getRootHostContainer,
80+ popHostContainer,
81+ popHostContext,
82+ resetHostContainer,
83+ } = hostContext ;
8084 const { beginWork, beginFailedWork } = ReactFiberBeginWork (
8185 config ,
8286 hostContext ,
@@ -96,7 +100,7 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
96100 useSyncScheduling,
97101 prepareForCommit,
98102 resetAfterCommit,
99- focusHostComponent ,
103+ commitInitialEffects ,
100104 } = config ;
101105
102106 // The priority level to use when scheduling an update.
@@ -285,12 +289,23 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
285289 }
286290 }
287291
288- function commitAllLifeCycles ( ) {
292+ function commitAllLifeCyclesAndApplyInitialEffects ( ) {
289293 while ( nextEffect ) {
290294 const current = nextEffect . alternate ;
291295
292- if ( nextEffect . effectTag & Focus ) {
293- focusHostComponent ( nextEffect . stateNode ) ;
296+ // Renderers may schedule work to be done after host components are mounted
297+ // (eg DOM renderer may schedule auto-focus for inputs and form controls).
298+ // These effects should only be committed when components are first mounted,
299+ // aka when there is no current/alternate.
300+ if (
301+ ! current &&
302+ nextEffect . effectTag & Update
303+ ) {
304+ const type = nextEffect . type ;
305+ const props = nextEffect . memoizedProps ;
306+ const instance : I = nextEffect . stateNode ;
307+ const rootContainerInstance = getRootHostContainer ( ) ;
308+ commitInitialEffects ( instance , type , props , rootContainerInstance , nextEffect ) ;
294309 }
295310
296311 // Use Task priority for lifecycle updates
@@ -378,11 +393,11 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
378393 // In the second pass we'll perform all life-cycles and ref callbacks.
379394 // Life-cycles happen as a separate pass so that all placements, updates,
380395 // and deletions in the entire tree have already been invoked.
381- // This pass also triggers focus since components must be mounted first .
396+ // This pass also triggers any renderer-specific initial effects .
382397 nextEffect = firstEffect ;
383398 while ( nextEffect ) {
384399 try {
385- commitAllLifeCycles ( finishedWork , nextEffect ) ;
400+ commitAllLifeCyclesAndApplyInitialEffects ( finishedWork , nextEffect ) ;
386401 } catch ( error ) {
387402 if ( ! nextEffect ) {
388403 throw new Error ( 'Should have nextEffect.' ) ;
0 commit comments