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
Brian Vaughn committed
Jan 13, 2017 at 15:32 UTC
7817eb08f3dee835d2b8a8d86aaef5bdc370c5b4
2 files changed
+9
-7
src/renderers/dom/fiber/ReactDOMFiber.js
+6
-5
@@ -57,7 +57,10 @@ findDOMNode._injectFiber(function(fiber: Fiber) {
57
type DOMContainerElement = Element & { _reactRootContainer: ?Object };
58
59
type Container = Element;
60
-type Props = { children ?: mixed };
60
+type Props = {
61
+ autoFocus ?: boolean,
62
+ children ?: mixed,
63
+};
64
type Instance = Element;
65
type TextInstance = Text;
66
@@ -105,7 +108,7 @@ function shouldAutoFocusHostComponent(
108
case 'input':
109
case 'select':
110
case 'textarea':
108
- return !!(props : any).autoFocus;
111
+ return !!props.autoFocus;
112
}
113
return false;
114
}
@@ -223,9 +226,7 @@ var DOMRenderer = ReactFiberReconciler({
226
rootContainerInstance : Container,
227
internalInstanceHandle : Object,
228
) : void {
226
- if (shouldAutoFocusHostComponent(type, newProps)) {
227
- (domElement : any).focus();
228
- }
229
+ ((domElement : any) : HTMLButtonElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement).focus();
230
},
231
232
commitUpdate(
src/renderers/shared/fiber/ReactFiberCompleteWork.js
+3
-2
@@ -39,6 +39,7 @@ var {
39
Fragment,
40
} = ReactTypeOfWork;
41
var {
42
+ Ref,
43
Update,
44
} = ReactTypeOfSideEffect;
45
@@ -233,13 +234,13 @@ module.exports = function<T, P, I, TI, PI, C, CX>(
234
// (eg DOM renderer supports auto-focus for certain elements).
235
// Make sure such renderers get scheduled for later work.
236
if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance)) {
236
- workInProgress.effectTag |= Update;
237
+ markUpdate(workInProgress);
238
}
239
240
workInProgress.stateNode = instance;
241
if (workInProgress.ref) {
242
// If there is a ref on a host node we need to schedule a callback
242
- markUpdate(workInProgress);
243
+ workInProgress.effectTag |= Ref;
244
}
245
}
246
return null;