Skip to content

Commit

Permalink
move resource acquisition to mutation phase (#25500)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff authored Oct 17, 2022
1 parent 500bea5 commit 71f2c8c
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 @@ -1089,19 +1089,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 @@ -2617,6 +2604,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 @@ -1089,19 +1089,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 @@ -2617,6 +2604,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

1 comment on commit 71f2c8c

@YEL-59
Copy link

@YEL-59 YEL-59 commented on 71f2c8c Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

owao that is really cool!

Please sign in to comment.