mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Pass current instead of picking it up from alternate
This colocates the reliance on alternate with the scheduler, so that we have the option to not use this, or more easily break apart the initial mount phase into an optimized path.
This commit is contained in:
@@ -236,11 +236,10 @@ function cloneSiblings(current : Fiber, workInProgress : Fiber, returnFiber : Fi
|
||||
workInProgress.sibling = null;
|
||||
}
|
||||
|
||||
exports.cloneChildFibers = function(workInProgress : Fiber) {
|
||||
exports.cloneChildFibers = function(current : ?Fiber, workInProgress : Fiber) {
|
||||
if (!workInProgress.child) {
|
||||
return;
|
||||
}
|
||||
const current = workInProgress.alternate;
|
||||
if (!current || workInProgress.child !== current.child) {
|
||||
// If there is no alternate, then we don't need to clone the children.
|
||||
// If the children of the alternate fiber is a different set, then we don't
|
||||
|
||||
@@ -166,15 +166,15 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
|
||||
if (typeof value === 'object' && value && typeof value.render === 'function') {
|
||||
// Proceed under the assumption that this is a class instance
|
||||
workInProgress.tag = ClassComponent;
|
||||
if (workInProgress.alternate) {
|
||||
workInProgress.alternate.tag = ClassComponent;
|
||||
if (current) {
|
||||
current.tag = ClassComponent;
|
||||
}
|
||||
value = value.render();
|
||||
} else {
|
||||
// Proceed under the assumption that this is a functional component
|
||||
workInProgress.tag = FunctionalComponent;
|
||||
if (workInProgress.alternate) {
|
||||
workInProgress.alternate.tag = FunctionalComponent;
|
||||
if (current) {
|
||||
current.tag = FunctionalComponent;
|
||||
}
|
||||
}
|
||||
reconcileChildren(current, workInProgress, value);
|
||||
@@ -225,7 +225,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
cloneChildFibers(workInProgress);
|
||||
cloneChildFibers(current, workInProgress);
|
||||
markChildAsProgressed(current, workInProgress, priorityLevel);
|
||||
return workInProgress.child;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
|
||||
const updateContainer = config.updateContainer;
|
||||
const commitUpdate = config.commitUpdate;
|
||||
|
||||
function commitWork(finishedWork : Fiber) : void {
|
||||
function commitWork(current : ?Fiber, finishedWork : Fiber) : void {
|
||||
switch (finishedWork.tag) {
|
||||
case ClassComponent: {
|
||||
// TODO: Fire componentDidMount/componentDidUpdate, update refs
|
||||
@@ -43,14 +43,13 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
|
||||
return;
|
||||
}
|
||||
case HostComponent: {
|
||||
if (finishedWork.stateNode == null || !finishedWork.alternate) {
|
||||
if (finishedWork.stateNode == null || !current) {
|
||||
throw new Error('This should only be done during updates.');
|
||||
}
|
||||
// Commit the work prepared earlier.
|
||||
const child = finishedWork.child;
|
||||
const children = (child && !child.sibling) ? (child.output : ?Fiber | I) : child;
|
||||
const newProps = finishedWork.memoizedProps;
|
||||
const current = finishedWork.alternate;
|
||||
const oldProps = current.memoizedProps;
|
||||
const instance : I = finishedWork.stateNode;
|
||||
commitUpdate(instance, oldProps, newProps, children);
|
||||
|
||||
@@ -89,7 +89,8 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
|
||||
// TODO: Error handling.
|
||||
let effectfulFiber = finishedWork.firstEffect;
|
||||
while (effectfulFiber) {
|
||||
commitWork(effectfulFiber);
|
||||
const current = effectfulFiber.alternate;
|
||||
commitWork(current, effectfulFiber);
|
||||
const next = effectfulFiber.nextEffect;
|
||||
// Ensure that we clean these up so that we don't accidentally keep them.
|
||||
// I'm not actually sure this matters because we can't reset firstEffect
|
||||
|
||||
Reference in New Issue
Block a user