@samitouri / QOS-React / commits / 2b3592331e

Pass `pendingProps` as argument in `createWorkInProgress` (#11296)

* move to pendingProps to args * update userFiber in ReactChildFiber * prettier it * prettier it * move expirationTime to the last * move expirationTime to the last on userFiber * Move assignment

zombieJ committed Oct 31, 2017 at 21:46 UTC 2b3592331efd4b41f19de521528f664b870393e5
3 files changed +37 -32
packages/react-reconciler/src/ReactChildFiber.js
+30 -27
@@ -301,11 +301,15 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
301 return existingChildren;
302 }
303
304 - function useFiber(fiber: Fiber, expirationTime: ExpirationTime): Fiber {
304 + function useFiber(
305 + fiber: Fiber,
306 + pendingProps: mixed,
307 + expirationTime: ExpirationTime,
308 + ): Fiber {
309 // We currently set sibling to null and index to 0 here because it is easy
310 // to forget to do before returning it. E.g. for the single child case.
311 if (shouldClone) {
308 - const clone = createWorkInProgress(fiber, expirationTime);
312 + const clone = createWorkInProgress(fiber, pendingProps, expirationTime);
313 clone.index = 0;
314 clone.sibling = null;
315 return clone;
@@ -317,6 +321,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
321 fiber.effectTag = NoEffect;
322 fiber.index = 0;
323 fiber.sibling = null;
324 + fiber.pendingProps = pendingProps;
325 return fiber;
326 }
327 }
@@ -375,8 +380,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
380 return created;
381 } else {
382 // Update
378 - const existing = useFiber(current, expirationTime);
379 - existing.pendingProps = textContent;
383 + const existing = useFiber(current, textContent, expirationTime);
384 existing.return = returnFiber;
385 return existing;
386 }
@@ -390,9 +394,8 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
394 ): Fiber {
395 if (current !== null && current.type === element.type) {
396 // Move based on index
393 - const existing = useFiber(current, expirationTime);
397 + const existing = useFiber(current, element.props, expirationTime);
398 existing.ref = coerceRef(current, element);
395 - existing.pendingProps = element.props;
399 existing.return = returnFiber;
400 if (__DEV__) {
401 existing._debugSource = element._source;
@@ -430,8 +433,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
433 return created;
434 } else {
435 // Move based on index
433 - const existing = useFiber(current, expirationTime);
434 - existing.pendingProps = call;
436 + const existing = useFiber(current, call, expirationTime);
437 existing.return = returnFiber;
438 return existing;
439 }
@@ -455,7 +457,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
457 return created;
458 } else {
459 // Move based on index
458 - const existing = useFiber(current, expirationTime);
460 + const existing = useFiber(current, null, expirationTime);
461 existing.type = returnNode.value;
462 existing.return = returnFiber;
463 return existing;
@@ -484,8 +486,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
486 return created;
487 } else {
488 // Update
487 - const existing = useFiber(current, expirationTime);
488 - existing.pendingProps = portal.children || [];
489 + const existing = useFiber(current, portal.children || [], expirationTime);
490 existing.return = returnFiber;
491 return existing;
492 }
@@ -510,8 +511,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
511 return created;
512 } else {
513 // Update
513 - const existing = useFiber(current, expirationTime);
514 - existing.pendingProps = fragment;
514 + const existing = useFiber(current, fragment, expirationTime);
515 existing.return = returnFiber;
516 return existing;
517 }
@@ -1225,8 +1225,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1225 // We already have an existing node so let's just update it and delete
1226 // the rest.
1227 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
1228 - const existing = useFiber(currentFirstChild, expirationTime);
1229 - existing.pendingProps = textContent;
1228 + const existing = useFiber(currentFirstChild, textContent, expirationTime);
1229 existing.return = returnFiber;
1230 return existing;
1231 }
@@ -1260,11 +1259,14 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1259 : child.type === element.type
1260 ) {
1261 deleteRemainingChildren(returnFiber, child.sibling);
1263 - const existing = useFiber(child, expirationTime);
1262 + const existing = useFiber(
1263 + child,
1264 + element.type === REACT_FRAGMENT_TYPE
1265 + ? element.props.children
1266 + : element.props,
1267 + expirationTime,
1268 + );
1269 existing.ref = coerceRef(child, element);
1265 - existing.pendingProps = element.type === REACT_FRAGMENT_TYPE
1266 - ? element.props.children
1267 - : element.props;
1270 existing.return = returnFiber;
1271 if (__DEV__) {
1272 existing._debugSource = element._source;
@@ -1316,8 +1318,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1318 if (child.key === key) {
1319 if (child.tag === CallComponent) {
1320 deleteRemainingChildren(returnFiber, child.sibling);
1319 - const existing = useFiber(child, expirationTime);
1320 - existing.pendingProps = call;
1321 + const existing = useFiber(child, call, expirationTime);
1322 existing.return = returnFiber;
1323 return existing;
1324 } else {
@@ -1350,7 +1351,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1351 if (child !== null) {
1352 if (child.tag === ReturnComponent) {
1353 deleteRemainingChildren(returnFiber, child.sibling);
1353 - const existing = useFiber(child, expirationTime);
1354 + const existing = useFiber(child, null, expirationTime);
1355 existing.type = returnNode.value;
1356 existing.return = returnFiber;
1357 return existing;
@@ -1387,8 +1388,11 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1388 child.stateNode.implementation === portal.implementation
1389 ) {
1390 deleteRemainingChildren(returnFiber, child.sibling);
1390 - const existing = useFiber(child, expirationTime);
1391 - existing.pendingProps = portal.children || [];
1391 + const existing = useFiber(
1392 + child,
1393 + portal.children || [],
1394 + expirationTime,
1395 + );
1396 existing.return = returnFiber;
1397 return existing;
1398 } else {
@@ -1578,10 +1582,9 @@ exports.cloneChildFibers = function(
1582 let currentChild = workInProgress.child;
1583 let newChild = createWorkInProgress(
1584 currentChild,
1585 + currentChild.pendingProps,
1586 currentChild.expirationTime,
1587 );
1583 - // TODO: Pass this as an argument, since it's easy to forget.
1584 - newChild.pendingProps = currentChild.pendingProps;
1588 workInProgress.child = newChild;
1589
1590 newChild.return = workInProgress;
@@ -1589,9 +1592,9 @@ exports.cloneChildFibers = function(
1592 currentChild = currentChild.sibling;
1593 newChild = newChild.sibling = createWorkInProgress(
1594 currentChild,
1595 + currentChild.pendingProps,
1596 currentChild.expirationTime,
1597 );
1594 - newChild.pendingProps = currentChild.pendingProps;
1598 newChild.return = workInProgress;
1599 }
1600 newChild.sibling = null;
packages/react-reconciler/src/ReactFiber.js
+2 -4
@@ -4,7 +4,6 @@
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 - * @flow
7 */
8
9 'use strict';
@@ -231,6 +230,7 @@ function shouldConstruct(Component) {
230 // This is used to create an alternate fiber to do work on.
231 exports.createWorkInProgress = function(
232 current: Fiber,
233 + pendingProps: any,
234 expirationTime: ExpirationTime,
235 ): Fiber {
236 let workInProgress = current.alternate;
@@ -269,15 +269,13 @@ exports.createWorkInProgress = function(
269 }
270
271 workInProgress.expirationTime = expirationTime;
272 + workInProgress.pendingProps = pendingProps;
273
274 workInProgress.child = current.child;
275 workInProgress.memoizedProps = current.memoizedProps;
276 workInProgress.memoizedState = current.memoizedState;
277 workInProgress.updateQueue = current.updateQueue;
278
278 - // pendingProps is set by the parent during reconciliation.
279 - // TODO: Pass this as an argument.
280 -
279 // These will be overridden during the parent's reconciliation
280 workInProgress.sibling = current.sibling;
281 workInProgress.index = current.index;
packages/react-reconciler/src/ReactFiberScheduler.js
+5 -1
@@ -804,7 +804,11 @@ module.exports = function<T, P, I, TI, PI, C, CC, CX, PL>(
804 resetContextStack();
805 nextRoot = root;
806 nextRenderExpirationTime = expirationTime;
807 - nextUnitOfWork = createWorkInProgress(nextRoot.current, expirationTime);
807 + nextUnitOfWork = createWorkInProgress(
808 + nextRoot.current,
809 + null,
810 + expirationTime,
811 + );
812 }
813
814 let didError = false;