Skip to content

Commit

Permalink
move resource acquisition to mutation phase (facebook#25500)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff authored and mofeiZ committed Dec 5, 2022
1 parent 9b13c7e commit a8c497e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
26 changes: 13 additions & 13 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,19 +1086,6 @@ function commitLayoutEffectOnFiber(
committedLanes,
);

if (flags & Update) {
const newResource = finishedWork.memoizedState;
if (current !== null) {
const currentResource = current.memoizedState;
if (currentResource !== newResource) {
releaseResource(currentResource);
}
}
finishedWork.stateNode = newResource
? acquireResource(newResource)
: null;
}

if (flags & Ref) {
safelyAttachRef(finishedWork, finishedWork.return);
}
Expand Down Expand Up @@ -2614,6 +2601,19 @@ function commitMutationEffectsOnFiber(
safelyDetachRef(current, current.return);
}
}

if (flags & Update) {
const newResource = finishedWork.memoizedState;
if (current !== null) {
const currentResource = current.memoizedState;
if (currentResource !== newResource) {
releaseResource(currentResource);
}
}
finishedWork.stateNode = newResource
? acquireResource(newResource)
: null;
}
return;
}
}
Expand Down
26 changes: 13 additions & 13 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,19 +1086,6 @@ function commitLayoutEffectOnFiber(
committedLanes,
);

if (flags & Update) {
const newResource = finishedWork.memoizedState;
if (current !== null) {
const currentResource = current.memoizedState;
if (currentResource !== newResource) {
releaseResource(currentResource);
}
}
finishedWork.stateNode = newResource
? acquireResource(newResource)
: null;
}

if (flags & Ref) {
safelyAttachRef(finishedWork, finishedWork.return);
}
Expand Down Expand Up @@ -2614,6 +2601,19 @@ function commitMutationEffectsOnFiber(
safelyDetachRef(current, current.return);
}
}

if (flags & Update) {
const newResource = finishedWork.memoizedState;
if (current !== null) {
const currentResource = current.memoizedState;
if (currentResource !== newResource) {
releaseResource(currentResource);
}
}
finishedWork.stateNode = newResource
? acquireResource(newResource)
: null;
}
return;
}
}
Expand Down

0 comments on commit a8c497e

Please sign in to comment.