Skip to content

Commit f189031

Browse files
committed
Move Offscreen manual check to a function
1 parent 290f8e0 commit f189031

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
2222
import type {UpdateQueue} from './ReactFiberClassUpdateQueue.new';
2323
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.new';
2424
import type {Wakeable} from 'shared/ReactTypes';
25-
import type {
25+
import {
2626
OffscreenState,
2727
OffscreenInstance,
2828
OffscreenQueue,
2929
OffscreenProps,
30+
isOffscreenManual,
3031
} from './ReactFiberOffscreenComponent';
3132
import type {HookFlags} from './ReactHookEffectTags';
3233
import type {Cache} from './ReactFiberCacheComponent.new';
@@ -2896,10 +2897,7 @@ function commitMutationEffectsOnFiber(
28962897
}
28972898

28982899
// Offscreen with manual mode manages visibility manually.
2899-
const shouldControlChildrenVisibility =
2900-
finishedWork.memoizedProps === null ||
2901-
finishedWork.memoizedProps.mode !== 'manual';
2902-
if (supportsMutation && shouldControlChildrenVisibility) {
2900+
if (supportsMutation && !isOffscreenManual(finishedWork)) {
29032901
// TODO: This needs to run whenever there's an insertion or update
29042902
// inside a hidden Offscreen tree.
29052903
hideOrUnhideAllChildren(offscreenBoundary, isHidden);

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
2222
import type {UpdateQueue} from './ReactFiberClassUpdateQueue.old';
2323
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old';
2424
import type {Wakeable} from 'shared/ReactTypes';
25-
import type {
25+
import {
2626
OffscreenState,
2727
OffscreenInstance,
2828
OffscreenQueue,
2929
OffscreenProps,
30+
isOffscreenManual,
3031
} from './ReactFiberOffscreenComponent';
3132
import type {HookFlags} from './ReactHookEffectTags';
3233
import type {Cache} from './ReactFiberCacheComponent.old';
@@ -2896,10 +2897,7 @@ function commitMutationEffectsOnFiber(
28962897
}
28972898

28982899
// Offscreen with manual mode manages visibility manually.
2899-
const shouldControlChildrenVisibility =
2900-
finishedWork.memoizedProps === null ||
2901-
finishedWork.memoizedProps.mode !== 'manual';
2902-
if (supportsMutation && shouldControlChildrenVisibility) {
2900+
if (supportsMutation && !isOffscreenManual(finishedWork)) {
29032901
// TODO: This needs to run whenever there's an insertion or update
29042902
// inside a hidden Offscreen tree.
29052903
hideOrUnhideAllChildren(offscreenBoundary, isHidden);

packages/react-reconciler/src/ReactFiberCompleteWork.new.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
SuspenseState,
2828
SuspenseListRenderState,
2929
} from './ReactFiberSuspenseComponent.new';
30-
import type {OffscreenState} from './ReactFiberOffscreenComponent';
30+
import {isOffscreenManual, OffscreenState} from './ReactFiberOffscreenComponent';
3131
import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent.new';
3232
import type {Cache} from './ReactFiberCacheComponent.new';
3333
import {
@@ -429,8 +429,7 @@ if (supportsMutation) {
429429
child.return = node;
430430
}
431431
// If Offscreen is not in manual mode, detached tree is hidden from user space.
432-
const _needsVisibilityToggle =
433-
node.memoizedProps === null || node.memoizedProps.mode !== 'manual';
432+
const _needsVisibilityToggle = !isOffscreenManual(node);
434433
appendAllChildrenToContainer(
435434
containerChildSet,
436435
node,

packages/react-reconciler/src/ReactFiberCompleteWork.old.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
SuspenseState,
2828
SuspenseListRenderState,
2929
} from './ReactFiberSuspenseComponent.old';
30-
import type {OffscreenState} from './ReactFiberOffscreenComponent';
30+
import {isOffscreenManual, OffscreenState} from './ReactFiberOffscreenComponent';
3131
import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent.old';
3232
import type {Cache} from './ReactFiberCacheComponent.old';
3333
import {
@@ -429,8 +429,7 @@ if (supportsMutation) {
429429
child.return = node;
430430
}
431431
// If Offscreen is not in manual mode, detached tree is hidden from user space.
432-
const _needsVisibilityToggle =
433-
node.memoizedProps === null || node.memoizedProps.mode !== 'manual';
432+
const _needsVisibilityToggle = !isOffscreenManual(node);
434433
appendAllChildrenToContainer(
435434
containerChildSet,
436435
node,

packages/react-reconciler/src/ReactFiberOffscreenComponent.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ export type OffscreenInstance = {
6262

6363
// TODO: attach
6464
};
65+
66+
67+
export function isOffscreenManual(offscreenFiber: Fiber): boolean {
68+
return offscreenFiber.memoizedProps !== null &&
69+
offscreenFiber.memoizedProps.mode === 'manual';
70+
}

scripts/error-codes/codes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,5 +441,5 @@
441441
"453": "React expected a <head> element (document.head) to exist in the Document but one was not found. React never removes the head for any Document it renders into so the cause is likely in some other script running on this page.",
442442
"454": "React expected a <body> element (document.body) to exist in the Document but one was not found. React never removes the body for any Document it renders into so the cause is likely in some other script running on this page.",
443443
"455": "This CacheSignal was requested outside React which means that it is immediately aborted.",
444-
"456": "Calling Offscreen.detach before instance handle has been set.",
444+
"456": "Calling Offscreen.detach before instance handle has been set."
445445
}

0 commit comments

Comments
 (0)