MCPcopy
hub / github.com/facebook/react / resetWorkInProgress

Function resetWorkInProgress

packages/react-reconciler/src/ReactFiber.js:439–519  ·  view source on GitHub ↗
(
  workInProgress: Fiber,
  renderLanes: Lanes,
)

Source from the content-addressed store, hash-verified

437
438// Used to reuse a Fiber for a second pass.
439export function resetWorkInProgress(
440 workInProgress: Fiber,
441 renderLanes: Lanes,
442): Fiber {
443 // This resets the Fiber to what createFiber or createWorkInProgress would
444 // have set the values to before during the first pass. Ideally this wouldn't
445 // be necessary but unfortunately many code paths reads from the workInProgress
446 // when they should be reading from current and writing to workInProgress.
447
448 // We assume pendingProps, index, key, ref, return are still untouched to
449 // avoid doing another reconciliation.
450
451 // Reset the effect flags but keep any Placement tags, since that's something
452 // that child fiber is setting, not the reconciliation.
453 workInProgress.flags &= StaticMask | Placement;
454
455 // The effects are no longer valid.
456
457 const current = workInProgress.alternate;
458 if (current === null) {
459 // Reset to createFiber's initial values.
460 workInProgress.childLanes = NoLanes;
461 workInProgress.lanes = renderLanes;
462
463 workInProgress.child = null;
464 workInProgress.subtreeFlags = NoFlags;
465 workInProgress.memoizedProps = null;
466 workInProgress.memoizedState = null;
467 workInProgress.updateQueue = null;
468
469 workInProgress.dependencies = null;
470
471 workInProgress.stateNode = null;
472
473 if (enableProfilerTimer) {
474 // Note: We don't reset the actualTime counts. It's useful to accumulate
475 // actual time across multiple render passes.
476 workInProgress.selfBaseDuration = 0;
477 workInProgress.treeBaseDuration = 0;
478 }
479 } else {
480 // Reset to the cloned values that createWorkInProgress would've.
481 workInProgress.childLanes = current.childLanes;
482 workInProgress.lanes = current.lanes;
483
484 workInProgress.child = current.child;
485 workInProgress.subtreeFlags = NoFlags;
486 workInProgress.deletions = null;
487 workInProgress.memoizedProps = current.memoizedProps;
488 workInProgress.memoizedState = current.memoizedState;
489 workInProgress.updateQueue = current.updateQueue;
490 // Needed because Blocks store data on type.
491 workInProgress.type = current.type;
492
493 // Clone the dependencies object. This is mutated during the render phase, so
494 // it cannot be shared with the current fiber.
495 const currentDependencies = current.dependencies;
496 workInProgress.dependencies =

Callers 2

replayBeginWorkFunction · 0.90
resetChildFibersFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected