Move ref commit effects inside switch statement
Only certain fiber types can have refs attached to them, so this moves the Ref effect logic out of the common path and into the corresponding branch of the layout phase's switch statement. The types of fibers this affects are host components and class components. Function components are not affected because they can only have a ref via useImperativeHandle, which has a different implementation. The experimental Scope type attaches its refs in the mutation phase, not the layout phase.
This commit is contained in:
parent
e225fa43ad
commit
b8c96b136d
|
@ -893,6 +893,12 @@ function commitLayoutEffectOnFiber(
|
||||||
// TODO: revisit this when we implement resuming.
|
// TODO: revisit this when we implement resuming.
|
||||||
commitCallbacks(updateQueue, instance);
|
commitCallbacks(updateQueue, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (finishedWork.flags & Ref) {
|
||||||
|
if (!offscreenSubtreeWasHidden) {
|
||||||
|
commitAttachRef(finishedWork);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case HostRoot: {
|
case HostRoot: {
|
||||||
|
@ -930,6 +936,11 @@ function commitLayoutEffectOnFiber(
|
||||||
commitMount(instance, type, props, finishedWork);
|
commitMount(instance, type, props, finishedWork);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (finishedWork.flags & Ref) {
|
||||||
|
if (!offscreenSubtreeWasHidden) {
|
||||||
|
commitAttachRef(finishedWork);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case HostText: {
|
case HostText: {
|
||||||
|
@ -1020,20 +1031,6 @@ function commitLayoutEffectOnFiber(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!offscreenSubtreeWasHidden) {
|
|
||||||
if (enableScopeAPI) {
|
|
||||||
// TODO: This is a temporary solution that allowed us to transition away
|
|
||||||
// from React Flare on www.
|
|
||||||
if (finishedWork.flags & Ref && finishedWork.tag !== ScopeComponent) {
|
|
||||||
commitAttachRef(finishedWork);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (finishedWork.flags & Ref) {
|
|
||||||
commitAttachRef(finishedWork);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function reappearLayoutEffectsOnFiber(node: Fiber) {
|
function reappearLayoutEffectsOnFiber(node: Fiber) {
|
||||||
|
|
|
@ -893,6 +893,12 @@ function commitLayoutEffectOnFiber(
|
||||||
// TODO: revisit this when we implement resuming.
|
// TODO: revisit this when we implement resuming.
|
||||||
commitCallbacks(updateQueue, instance);
|
commitCallbacks(updateQueue, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (finishedWork.flags & Ref) {
|
||||||
|
if (!offscreenSubtreeWasHidden) {
|
||||||
|
commitAttachRef(finishedWork);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case HostRoot: {
|
case HostRoot: {
|
||||||
|
@ -930,6 +936,11 @@ function commitLayoutEffectOnFiber(
|
||||||
commitMount(instance, type, props, finishedWork);
|
commitMount(instance, type, props, finishedWork);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (finishedWork.flags & Ref) {
|
||||||
|
if (!offscreenSubtreeWasHidden) {
|
||||||
|
commitAttachRef(finishedWork);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case HostText: {
|
case HostText: {
|
||||||
|
@ -1020,20 +1031,6 @@ function commitLayoutEffectOnFiber(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!offscreenSubtreeWasHidden) {
|
|
||||||
if (enableScopeAPI) {
|
|
||||||
// TODO: This is a temporary solution that allowed us to transition away
|
|
||||||
// from React Flare on www.
|
|
||||||
if (finishedWork.flags & Ref && finishedWork.tag !== ScopeComponent) {
|
|
||||||
commitAttachRef(finishedWork);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (finishedWork.flags & Ref) {
|
|
||||||
commitAttachRef(finishedWork);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function reappearLayoutEffectsOnFiber(node: Fiber) {
|
function reappearLayoutEffectsOnFiber(node: Fiber) {
|
||||||
|
|
Loading…
Reference in New Issue