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
This commit is contained in:
Brian Vaughn
2017-01-13 15:32:49 -08:00
committed by GitHub
parent be0de3455b
commit 7817eb08f3
2 changed files with 9 additions and 7 deletions

View File

@@ -57,7 +57,10 @@ findDOMNode._injectFiber(function(fiber: Fiber) {
type DOMContainerElement = Element & { _reactRootContainer: ?Object };
type Container = Element;
type Props = { children ?: mixed };
type Props = {
autoFocus ?: boolean,
children ?: mixed,
};
type Instance = Element;
type TextInstance = Text;
@@ -105,7 +108,7 @@ function shouldAutoFocusHostComponent(
case 'input':
case 'select':
case 'textarea':
return !!(props : any).autoFocus;
return !!props.autoFocus;
}
return false;
}
@@ -223,9 +226,7 @@ var DOMRenderer = ReactFiberReconciler({
rootContainerInstance : Container,
internalInstanceHandle : Object,
) : void {
if (shouldAutoFocusHostComponent(type, newProps)) {
(domElement : any).focus();
}
((domElement : any) : HTMLButtonElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement).focus();
},
commitUpdate(

View File

@@ -39,6 +39,7 @@ var {
Fragment,
} = ReactTypeOfWork;
var {
Ref,
Update,
} = ReactTypeOfSideEffect;
@@ -233,13 +234,13 @@ module.exports = function<T, P, I, TI, PI, C, CX>(
// (eg DOM renderer supports auto-focus for certain elements).
// Make sure such renderers get scheduled for later work.
if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance)) {
workInProgress.effectTag |= Update;
markUpdate(workInProgress);
}
workInProgress.stateNode = instance;
if (workInProgress.ref) {
// If there is a ref on a host node we need to schedule a callback
markUpdate(workInProgress);
workInProgress.effectTag |= Ref;
}
}
return null;