Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions packages/react-reconciler/src/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,15 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return existingChildren;
}

function useFiber(fiber: Fiber, expirationTime: ExpirationTime): Fiber {
function useFiber(
fiber: Fiber,
expirationTime: ExpirationTime,
pendingProps: any,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to mixed instead of any?

): Fiber {
// We currently set sibling to null and index to 0 here because it is easy
// to forget to do before returning it. E.g. for the single child case.
if (shouldClone) {
const clone = createWorkInProgress(fiber, expirationTime);
const clone = createWorkInProgress(fiber, expirationTime, pendingProps);
clone.index = 0;
clone.sibling = null;
return clone;
Expand All @@ -304,6 +308,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
fiber.effectTag = NoEffect;
fiber.index = 0;
fiber.sibling = null;
fiber.pendingProps = pendingProps;
return fiber;
}
}
Expand Down Expand Up @@ -362,8 +367,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return created;
} else {
// Update
const existing = useFiber(current, expirationTime);
existing.pendingProps = textContent;
const existing = useFiber(current, expirationTime, textContent);
existing.return = returnFiber;
return existing;
}
Expand All @@ -387,9 +391,8 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return created;
} else {
// Move based on index
const existing = useFiber(current, expirationTime);
const existing = useFiber(current, expirationTime, element.props);
existing.ref = coerceRef(current, element);
existing.pendingProps = element.props;
existing.return = returnFiber;
if (__DEV__) {
existing._debugSource = element._source;
Expand Down Expand Up @@ -417,8 +420,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return created;
} else {
// Move based on index
const existing = useFiber(current, expirationTime);
existing.pendingProps = coroutine;
const existing = useFiber(current, expirationTime, coroutine);
existing.return = returnFiber;
return existing;
}
Expand All @@ -442,7 +444,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return created;
} else {
// Move based on index
const existing = useFiber(current, expirationTime);
const existing = useFiber(current, expirationTime, null);
existing.type = yieldNode.value;
existing.return = returnFiber;
return existing;
Expand Down Expand Up @@ -471,8 +473,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return created;
} else {
// Update
const existing = useFiber(current, expirationTime);
existing.pendingProps = portal.children || [];
const existing = useFiber(current, expirationTime, portal.children || []);
existing.return = returnFiber;
return existing;
}
Expand All @@ -495,8 +496,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return created;
} else {
// Update
const existing = useFiber(current, expirationTime);
existing.pendingProps = fragment;
const existing = useFiber(current, expirationTime, fragment);
existing.return = returnFiber;
return existing;
}
Expand Down Expand Up @@ -1174,8 +1174,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
// We already have an existing node so let's just update it and delete
// the rest.
deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
const existing = useFiber(currentFirstChild, expirationTime);
existing.pendingProps = textContent;
const existing = useFiber(currentFirstChild, expirationTime, textContent);
existing.return = returnFiber;
return existing;
}
Expand Down Expand Up @@ -1205,9 +1204,8 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
if (child.key === key) {
if (child.type === element.type) {
deleteRemainingChildren(returnFiber, child.sibling);
const existing = useFiber(child, expirationTime);
const existing = useFiber(child, expirationTime, element.props);
existing.ref = coerceRef(child, element);
existing.pendingProps = element.props;
existing.return = returnFiber;
if (__DEV__) {
existing._debugSource = element._source;
Expand Down Expand Up @@ -1248,8 +1246,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
if (child.key === key) {
if (child.tag === CoroutineComponent) {
deleteRemainingChildren(returnFiber, child.sibling);
const existing = useFiber(child, expirationTime);
existing.pendingProps = coroutine;
const existing = useFiber(child, expirationTime, coroutine);
existing.return = returnFiber;
return existing;
} else {
Expand Down Expand Up @@ -1282,7 +1279,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
if (child !== null) {
if (child.tag === YieldComponent) {
deleteRemainingChildren(returnFiber, child.sibling);
const existing = useFiber(child, expirationTime);
const existing = useFiber(child, expirationTime, null);
existing.type = yieldNode.value;
existing.return = returnFiber;
return existing;
Expand Down Expand Up @@ -1319,8 +1316,11 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
child.stateNode.implementation === portal.implementation
) {
deleteRemainingChildren(returnFiber, child.sibling);
const existing = useFiber(child, expirationTime);
existing.pendingProps = portal.children || [];
const existing = useFiber(
child,
expirationTime,
portal.children || [],
);
existing.return = returnFiber;
return existing;
} else {
Expand Down Expand Up @@ -1499,9 +1499,8 @@ exports.cloneChildFibers = function(
let newChild = createWorkInProgress(
currentChild,
currentChild.expirationTime,
currentChild.pendingProps,
);
// TODO: Pass this as an argument, since it's easy to forget.
newChild.pendingProps = currentChild.pendingProps;
workInProgress.child = newChild;

newChild.return = workInProgress;
Expand All @@ -1510,8 +1509,8 @@ exports.cloneChildFibers = function(
newChild = newChild.sibling = createWorkInProgress(
currentChild,
currentChild.expirationTime,
currentChild.pendingProps,
);
newChild.pendingProps = currentChild.pendingProps;
newChild.return = workInProgress;
}
newChild.sibling = null;
Expand Down
3 changes: 2 additions & 1 deletion packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function shouldConstruct(Component) {
exports.createWorkInProgress = function(
current: Fiber,
expirationTime: ExpirationTime,
pendingProps: any,
): Fiber {
let workInProgress = current.alternate;
if (workInProgress === null) {
Expand Down Expand Up @@ -279,7 +280,7 @@ exports.createWorkInProgress = function(
workInProgress.updateQueue = current.updateQueue;

// pendingProps is set by the parent during reconciliation.
// TODO: Pass this as an argument.
workInProgress.pendingProps = pendingProps;

// These will be overridden during the parent's reconciliation
workInProgress.sibling = current.sibling;
Expand Down
6 changes: 5 additions & 1 deletion packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,11 @@ module.exports = function<T, P, I, TI, PI, C, CC, CX, PL>(
resetContextStack();
nextRoot = root;
nextRenderExpirationTime = expirationTime;
nextUnitOfWork = createWorkInProgress(nextRoot.current, expirationTime);
nextUnitOfWork = createWorkInProgress(
nextRoot.current,
expirationTime,
null,
);
}

let didError = false;
Expand Down