Skip to content

Commit

Permalink
Add isHidden to OffscreenInstance
Browse files Browse the repository at this point in the history
We need to be able to read whether an offscreen tree is hidden from
an imperative event. We can store this on its OffscreenInstance.

We were already scheduling a commit effect whenever the visibility
changes, in order to toggle the inner effects. So we can reuse that.
  • Loading branch information
acdlite committed Jun 7, 2022
1 parent 7e8a020 commit 82f903f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiber.new.js
Expand Up @@ -715,7 +715,9 @@ export function createFiberFromOffscreen(
const fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
fiber.elementType = REACT_OFFSCREEN_TYPE;
fiber.lanes = lanes;
const primaryChildInstance: OffscreenInstance = {};
const primaryChildInstance: OffscreenInstance = {
isHidden: false,
};
fiber.stateNode = primaryChildInstance;
return fiber;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiber.old.js
Expand Up @@ -715,7 +715,9 @@ export function createFiberFromOffscreen(
const fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
fiber.elementType = REACT_OFFSCREEN_TYPE;
fiber.lanes = lanes;
const primaryChildInstance: OffscreenInstance = {};
const primaryChildInstance: OffscreenInstance = {
isHidden: false,
};
fiber.stateNode = primaryChildInstance;
return fiber;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Expand Up @@ -2354,10 +2354,15 @@ function commitMutationEffectsOnFiber(
commitReconciliationEffects(finishedWork);

if (flags & Visibility) {
const instance: OffscreenInstance = finishedWork.stateNode;
const newState: OffscreenState | null = finishedWork.memoizedState;
const isHidden = newState !== null;
const offscreenBoundary: Fiber = finishedWork;

// Track the current state on the Offscreen instance so we can
// read it during an event
instance.isHidden = isHidden;

if (enableSuspenseLayoutEffectSemantics) {
if (isHidden) {
if (!wasHidden) {
Expand Down
5 changes: 5 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Expand Up @@ -2354,10 +2354,15 @@ function commitMutationEffectsOnFiber(
commitReconciliationEffects(finishedWork);

if (flags & Visibility) {
const instance: OffscreenInstance = finishedWork.stateNode;
const newState: OffscreenState | null = finishedWork.memoizedState;
const isHidden = newState !== null;
const offscreenBoundary: Fiber = finishedWork;

// Track the current state on the Offscreen instance so we can
// read it during an event
instance.isHidden = isHidden;

if (enableSuspenseLayoutEffectSemantics) {
if (isHidden) {
if (!wasHidden) {
Expand Down
Expand Up @@ -38,4 +38,6 @@ export type OffscreenQueue = {|
transitions: Array<Transition> | null,
|} | null;

export type OffscreenInstance = {};
export type OffscreenInstance = {|
isHidden: boolean,
|};

0 comments on commit 82f903f

Please sign in to comment.