Skip to content

Commit bdf8abc

Browse files
committed
Use _pendingVisibility to batch Offscreen visibility updates
1 parent fc6911a commit bdf8abc

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -685,24 +685,18 @@ function updateOffscreenComponent(
685685
) {
686686
const nextProps: OffscreenProps = workInProgress.pendingProps;
687687
const nextChildren = nextProps.children;
688+
const isPendingDetached = (workInProgress.stateNode._pendingVisibility & OffscreenDetached) !== 0;
688689

689690
const prevState: OffscreenState | null =
690691
current !== null ? current.memoizedState : null;
691692

692-
// Offscreen stores pending changes to visibility in `_pendingVisibility`. This is
693-
// to support batching of `attach` and `detach` calls.
694-
workInProgress.stateNode._visibility &= ~OffscreenDetached;
695-
workInProgress.stateNode._visibility |=
696-
workInProgress.stateNode._pendingVisibility & OffscreenDetached;
697-
698693
markRef(current, workInProgress);
699694

700695
if (
701696
nextProps.mode === 'hidden' ||
702697
(enableLegacyHidden &&
703698
nextProps.mode === 'unstable-defer-without-hiding') ||
704-
// TODO: remove read from stateNode.
705-
workInProgress.stateNode._visibility & OffscreenDetached
699+
isPendingDetached
706700
) {
707701
// Rendering a hidden tree.
708702

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,12 @@ function commitMutationEffectsOnFiber(
28792879
// TODO: Add explicit effect flag to set _current.
28802880
finishedWork.stateNode._current = finishedWork;
28812881

2882+
// Offscreen stores pending changes to visibility in `_pendingVisibility`. This is
2883+
// to support batching of `attach` and `detach` calls.
2884+
finishedWork.stateNode._visibility &= ~OffscreenDetached;
2885+
finishedWork.stateNode._visibility |=
2886+
finishedWork.stateNode._pendingVisibility & OffscreenDetached;
2887+
28822888
if (flags & Visibility) {
28832889
const offscreenInstance: OffscreenInstance = finishedWork.stateNode;
28842890

0 commit comments

Comments
 (0)