-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land forked reconciler changes (#24878)
This applies forked changes from the "new" reconciler to the "old" one. Includes: - 67de5e3 [FORKED] Hidden trees should capture Suspense - 6ab05ee [FORKED] Track nearest Suspense handler on stack - 051ac55 [FORKED] Add HiddenContext to track if subtree is hidden
- Loading branch information
Showing
11 changed files
with
634 additions
and
386 deletions.
There are no files selected for viewing
359 changes: 223 additions & 136 deletions
359
packages/react-reconciler/src/ReactFiberBeginWork.old.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 70 additions & 1 deletion
71
packages/react-reconciler/src/ReactFiberHiddenContext.old.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,70 @@ | ||
// Intentionally blank. File only exists in new reconciler fork. | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {Fiber} from './ReactInternalTypes'; | ||
import type {StackCursor} from './ReactFiberStack.old'; | ||
import type {Lanes} from './ReactFiberLane.old'; | ||
|
||
import {createCursor, push, pop} from './ReactFiberStack.old'; | ||
|
||
import {getRenderLanes, setRenderLanes} from './ReactFiberWorkLoop.old'; | ||
import {NoLanes, mergeLanes} from './ReactFiberLane.old'; | ||
|
||
// TODO: Remove `renderLanes` context in favor of hidden context | ||
type HiddenContext = { | ||
// Represents the lanes that must be included when processing updates in | ||
// order to reveal the hidden content. | ||
// TODO: Remove `subtreeLanes` context from work loop in favor of this one. | ||
baseLanes: number, | ||
}; | ||
|
||
// TODO: This isn't being used yet, but it's intended to replace the | ||
// InvisibleParentContext that is currently managed by SuspenseContext. | ||
export const currentTreeHiddenStackCursor: StackCursor<HiddenContext | null> = createCursor( | ||
null, | ||
); | ||
export const prevRenderLanesStackCursor: StackCursor<Lanes> = createCursor( | ||
NoLanes, | ||
); | ||
|
||
export function pushHiddenContext(fiber: Fiber, context: HiddenContext): void { | ||
const prevRenderLanes = getRenderLanes(); | ||
push(prevRenderLanesStackCursor, prevRenderLanes, fiber); | ||
push(currentTreeHiddenStackCursor, context, fiber); | ||
|
||
// When rendering a subtree that's currently hidden, we must include all | ||
// lanes that would have rendered if the hidden subtree hadn't been deferred. | ||
// That is, in order to reveal content from hidden -> visible, we must commit | ||
// all the updates that we skipped when we originally hid the tree. | ||
setRenderLanes(mergeLanes(prevRenderLanes, context.baseLanes)); | ||
} | ||
|
||
export function reuseHiddenContextOnStack(fiber: Fiber): void { | ||
// This subtree is not currently hidden, so we don't need to add any lanes | ||
// to the render lanes. But we still need to push something to avoid a | ||
// context mismatch. Reuse the existing context on the stack. | ||
push(prevRenderLanesStackCursor, getRenderLanes(), fiber); | ||
push( | ||
currentTreeHiddenStackCursor, | ||
currentTreeHiddenStackCursor.current, | ||
fiber, | ||
); | ||
} | ||
|
||
export function popHiddenContext(fiber: Fiber): void { | ||
// Restore the previous render lanes from the stack | ||
setRenderLanes(prevRenderLanesStackCursor.current); | ||
|
||
pop(currentTreeHiddenStackCursor, fiber); | ||
pop(prevRenderLanesStackCursor, fiber); | ||
} | ||
|
||
export function isCurrentTreeHidden() { | ||
return currentTreeHiddenStackCursor.current !== null; | ||
} |
Oops, something went wrong.