MCPcopy Create free account
hub / github.com/plotly/dash / reconcileChildrenArray

Function reconcileChildrenArray

dash/deps/react-dom@18.3.1.js:13554–13719  ·  view source on GitHub ↗
(returnFiber, currentFirstChild, newChildren, lanes)

Source from the content-addressed store, hash-verified

13552 }
13553
13554 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, lanes) {
13555 // This algorithm can't optimize by searching from both ends since we
13556 // don't have backpointers on fibers. I'm trying to see how far we can get
13557 // with that model. If it ends up not being worth the tradeoffs, we can
13558 // add it later.
13559 // Even with a two ended optimization, we'd want to optimize for the case
13560 // where there are few changes and brute force the comparison instead of
13561 // going for the Map. It'd like to explore hitting that path first in
13562 // forward-only mode and only go for the Map once we notice that we need
13563 // lots of look ahead. This doesn't handle reversal as well as two ended
13564 // search but that's unusual. Besides, for the two ended optimization to
13565 // work on Iterables, we'd need to copy the whole set.
13566 // In this first iteration, we'll just live with hitting the bad case
13567 // (adding everything to a Map) in for every insert/move.
13568 // If you change this code, also update reconcileChildrenIterator() which
13569 // uses the same algorithm.
13570 {
13571 // First, validate keys.
13572 var knownKeys = null;
13573
13574 for (var i = 0; i < newChildren.length; i++) {
13575 var child = newChildren[i];
13576 knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
13577 }
13578 }
13579
13580 var resultingFirstChild = null;
13581 var previousNewFiber = null;
13582 var oldFiber = currentFirstChild;
13583 var lastPlacedIndex = 0;
13584 var newIdx = 0;
13585 var nextOldFiber = null;
13586
13587 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
13588 if (oldFiber.index > newIdx) {
13589 nextOldFiber = oldFiber;
13590 oldFiber = null;
13591 } else {
13592 nextOldFiber = oldFiber.sibling;
13593 }
13594
13595 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], lanes);
13596
13597 if (newFiber === null) {
13598 // TODO: This breaks on empty slots like null children. That's
13599 // unfortunate because it triggers the slow path all the time. We need
13600 // a better way to communicate whether this was a miss or null,
13601 // boolean, undefined, etc.
13602 if (oldFiber === null) {
13603 oldFiber = nextOldFiber;
13604 }
13605
13606 break;
13607 }
13608
13609 if (shouldTrackSideEffects) {
13610 if (oldFiber && newFiber.alternate === null) {
13611 // We matched the slot, but we didn't reuse the existing fiber, so we

Callers 1

reconcileChildFibersFunction · 0.70

Calls 11

warnOnInvalidKeyFunction · 0.70
updateSlotFunction · 0.70
deleteChildFunction · 0.70
placeChildFunction · 0.70
deleteRemainingChildrenFunction · 0.70
getIsHydratingFunction · 0.70
pushTreeForkFunction · 0.70
createChildFunction · 0.70
mapRemainingChildrenFunction · 0.70
updateFromMapFunction · 0.70
deleteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…