Skip to content

Commit 7817eb0

Browse files
authored
Replaced an Update effect in complete phase with a Ref effect
Also removed an unnecessary conditional check and improved a flow cast. Relates originally to PRs #8646 and #8685
1 parent be0de34 commit 7817eb0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/renderers/dom/fiber/ReactDOMFiber.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ findDOMNode._injectFiber(function(fiber: Fiber) {
5757
type DOMContainerElement = Element & { _reactRootContainer: ?Object };
5858

5959
type Container = Element;
60-
type Props = { children ?: mixed };
60+
type Props = {
61+
autoFocus ?: boolean,
62+
children ?: mixed,
63+
};
6164
type Instance = Element;
6265
type TextInstance = Text;
6366

@@ -105,7 +108,7 @@ function shouldAutoFocusHostComponent(
105108
case 'input':
106109
case 'select':
107110
case 'textarea':
108-
return !!(props : any).autoFocus;
111+
return !!props.autoFocus;
109112
}
110113
return false;
111114
}
@@ -223,9 +226,7 @@ var DOMRenderer = ReactFiberReconciler({
223226
rootContainerInstance : Container,
224227
internalInstanceHandle : Object,
225228
) : void {
226-
if (shouldAutoFocusHostComponent(type, newProps)) {
227-
(domElement : any).focus();
228-
}
229+
((domElement : any) : HTMLButtonElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement).focus();
229230
},
230231

231232
commitUpdate(

src/renderers/shared/fiber/ReactFiberCompleteWork.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var {
3939
Fragment,
4040
} = ReactTypeOfWork;
4141
var {
42+
Ref,
4243
Update,
4344
} = ReactTypeOfSideEffect;
4445

@@ -233,13 +234,13 @@ module.exports = function<T, P, I, TI, PI, C, CX>(
233234
// (eg DOM renderer supports auto-focus for certain elements).
234235
// Make sure such renderers get scheduled for later work.
235236
if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance)) {
236-
workInProgress.effectTag |= Update;
237+
markUpdate(workInProgress);
237238
}
238239

239240
workInProgress.stateNode = instance;
240241
if (workInProgress.ref) {
241242
// If there is a ref on a host node we need to schedule a callback
242-
markUpdate(workInProgress);
243+
workInProgress.effectTag |= Ref;
243244
}
244245
}
245246
return null;

0 commit comments

Comments
 (0)