How to use throwOnInvalidObjectType method in Playwright Internal

Best JavaScript code snippet using playwright-internal

4cb8b9d0ed5f067ca4dd9e921b4190df7c25aaReactChildFiber.js

Source:4cb8b9d0ed5f067ca4dd9e921b4190df7c25aaReactChildFiber.js Github

copy

Full Screen

...71 }72 }73 return mixedRef;74}75function throwOnInvalidObjectType(returnFiber, newChild) {76 if (returnFiber.type !== 'textarea') {77 var addendum = '';78 if (__DEV__) {79 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.';80 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;81 if (owner && typeof owner.tag === 'number') {82 var name = getComponentName(owner);83 if (name) {84 addendum += '\n\nCheck the render method of `' + name + '`.';85 }86 }87 }88 invariant(false, 'Objects are not valid as a React child (found: %s).%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum);89 }90}91function ChildReconciler(shouldClone, shouldTrackSideEffects) {92 function deleteChild(returnFiber, childToDelete) {93 if (!shouldTrackSideEffects) {94 return;95 }96 if (!shouldClone) {97 if (childToDelete.alternate === null) {98 return;99 }100 childToDelete = childToDelete.alternate;101 }102 var last = returnFiber.progressedLastDeletion;103 if (last !== null) {104 last.nextEffect = childToDelete;105 returnFiber.progressedLastDeletion = childToDelete;106 } else {107 returnFiber.progressedFirstDeletion = returnFiber.progressedLastDeletion = childToDelete;108 }109 childToDelete.nextEffect = null;110 childToDelete.effectTag = Deletion;111 }112 function deleteRemainingChildren(returnFiber, currentFirstChild) {113 if (!shouldTrackSideEffects) {114 return null;115 }116 var childToDelete = currentFirstChild;117 while (childToDelete !== null) {118 deleteChild(returnFiber, childToDelete);119 childToDelete = childToDelete.sibling;120 }121 return null;122 }123 function mapRemainingChildren(returnFiber, currentFirstChild) {124 var existingChildren = new Map();125 var existingChild = currentFirstChild;126 while (existingChild !== null) {127 if (existingChild.key !== null) {128 existingChildren.set(existingChild.key, existingChild);129 } else {130 existingChildren.set(existingChild.index, existingChild);131 }132 existingChild = existingChild.sibling;133 }134 return existingChildren;135 }136 function useFiber(fiber, priority) {137 if (shouldClone) {138 var clone = cloneFiber(fiber, priority);139 clone.index = 0;140 clone.sibling = null;141 return clone;142 } else {143 fiber.pendingWorkPriority = priority;144 fiber.effectTag = NoEffect;145 fiber.index = 0;146 fiber.sibling = null;147 return fiber;148 }149 }150 function placeChild(newFiber, lastPlacedIndex, newIndex) {151 newFiber.index = newIndex;152 if (!shouldTrackSideEffects) {153 return lastPlacedIndex;154 }155 var current = newFiber.alternate;156 if (current !== null) {157 var oldIndex = current.index;158 if (oldIndex < lastPlacedIndex) {159 newFiber.effectTag = Placement;160 return lastPlacedIndex;161 } else {162 return oldIndex;163 }164 } else {165 newFiber.effectTag = Placement;166 return lastPlacedIndex;167 }168 }169 function placeSingleChild(newFiber) {170 if (shouldTrackSideEffects && newFiber.alternate === null) {171 newFiber.effectTag = Placement;172 }173 return newFiber;174 }175 function updateTextNode(returnFiber, current, textContent, priority) {176 if (current === null || current.tag !== HostText) {177 var created = createFiberFromText(textContent, priority);178 created.return = returnFiber;179 return created;180 } else {181 var existing = useFiber(current, priority);182 existing.pendingProps = textContent;183 existing.return = returnFiber;184 return existing;185 }186 }187 function updateElement(returnFiber, current, element, priority) {188 if (current === null || current.type !== element.type) {189 var created = createFiberFromElement(element, priority);190 created.ref = coerceRef(current, element);191 created.return = returnFiber;192 return created;193 } else {194 var existing = useFiber(current, priority);195 existing.ref = coerceRef(current, element);196 existing.pendingProps = element.props;197 existing.return = returnFiber;198 if (__DEV__) {199 existing._debugSource = element._source;200 existing._debugOwner = element._owner;201 }202 return existing;203 }204 }205 function updateCoroutine(returnFiber, current, coroutine, priority) {206 if (current === null || current.tag !== CoroutineComponent) {207 var created = createFiberFromCoroutine(coroutine, priority);208 created.return = returnFiber;209 return created;210 } else {211 var existing = useFiber(current, priority);212 existing.pendingProps = coroutine;213 existing.return = returnFiber;214 return existing;215 }216 }217 function updateYield(returnFiber, current, yieldNode, priority) {218 if (current === null || current.tag !== YieldComponent) {219 var created = createFiberFromYield(yieldNode, priority);220 created.type = yieldNode.value;221 created.return = returnFiber;222 return created;223 } else {224 var existing = useFiber(current, priority);225 existing.type = yieldNode.value;226 existing.return = returnFiber;227 return existing;228 }229 }230 function updatePortal(returnFiber, current, portal, priority) {231 if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {232 var created = createFiberFromPortal(portal, priority);233 created.return = returnFiber;234 return created;235 } else {236 var existing = useFiber(current, priority);237 existing.pendingProps = portal.children || [];238 existing.return = returnFiber;239 return existing;240 }241 }242 function updateFragment(returnFiber, current, fragment, priority) {243 if (current === null || current.tag !== Fragment) {244 var created = createFiberFromFragment(fragment, priority);245 created.return = returnFiber;246 return created;247 } else {248 var existing = useFiber(current, priority);249 existing.pendingProps = fragment;250 existing.return = returnFiber;251 return existing;252 }253 }254 function createChild(returnFiber, newChild, priority) {255 if (typeof newChild === 'string' || typeof newChild === 'number') {256 var created = createFiberFromText('' + newChild, priority);257 created.return = returnFiber;258 return created;259 }260 if (typeof newChild === 'object' && newChild !== null) {261 switch (newChild.$$typeof) {262 case REACT_ELEMENT_TYPE:263 {264 var _created = createFiberFromElement(newChild, priority);265 _created.ref = coerceRef(null, newChild);266 _created.return = returnFiber;267 return _created;268 }269 case REACT_COROUTINE_TYPE:270 {271 var _created2 = createFiberFromCoroutine(newChild, priority);272 _created2.return = returnFiber;273 return _created2;274 }275 case REACT_YIELD_TYPE:276 {277 var _created3 = createFiberFromYield(newChild, priority);278 _created3.type = newChild.value;279 _created3.return = returnFiber;280 return _created3;281 }282 case REACT_PORTAL_TYPE:283 {284 var _created4 = createFiberFromPortal(newChild, priority);285 _created4.return = returnFiber;286 return _created4;287 }288 }289 if (isArray(newChild) || getIteratorFn(newChild)) {290 var _created5 = createFiberFromFragment(newChild, priority);291 _created5.return = returnFiber;292 return _created5;293 }294 throwOnInvalidObjectType(returnFiber, newChild);295 }296 return null;297 }298 function updateSlot(returnFiber, oldFiber, newChild, priority) {299 var key = oldFiber !== null ? oldFiber.key : null;300 if (typeof newChild === 'string' || typeof newChild === 'number') {301 if (key !== null) {302 return null;303 }304 return updateTextNode(returnFiber, oldFiber, '' + newChild, priority);305 }306 if (typeof newChild === 'object' && newChild !== null) {307 switch (newChild.$$typeof) {308 case REACT_ELEMENT_TYPE:309 {310 if (newChild.key === key) {311 return updateElement(returnFiber, oldFiber, newChild, priority);312 } else {313 return null;314 }315 }316 case REACT_COROUTINE_TYPE:317 {318 if (newChild.key === key) {319 return updateCoroutine(returnFiber, oldFiber, newChild, priority);320 } else {321 return null;322 }323 }324 case REACT_YIELD_TYPE:325 {326 if (key === null) {327 return updateYield(returnFiber, oldFiber, newChild, priority);328 } else {329 return null;330 }331 }332 case REACT_PORTAL_TYPE:333 {334 if (newChild.key === key) {335 return updatePortal(returnFiber, oldFiber, newChild, priority);336 } else {337 return null;338 }339 }340 }341 if (isArray(newChild) || getIteratorFn(newChild)) {342 if (key !== null) {343 return null;344 }345 return updateFragment(returnFiber, oldFiber, newChild, priority);346 }347 throwOnInvalidObjectType(returnFiber, newChild);348 }349 return null;350 }351 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, priority) {352 if (typeof newChild === 'string' || typeof newChild === 'number') {353 var matchedFiber = existingChildren.get(newIdx) || null;354 return updateTextNode(returnFiber, matchedFiber, '' + newChild, priority);355 }356 if (typeof newChild === 'object' && newChild !== null) {357 switch (newChild.$$typeof) {358 case REACT_ELEMENT_TYPE:359 {360 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;361 return updateElement(returnFiber, _matchedFiber, newChild, priority);362 }363 case REACT_COROUTINE_TYPE:364 {365 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;366 return updateCoroutine(returnFiber, _matchedFiber2, newChild, priority);367 }368 case REACT_YIELD_TYPE:369 {370 var _matchedFiber3 = existingChildren.get(newIdx) || null;371 return updateYield(returnFiber, _matchedFiber3, newChild, priority);372 }373 case REACT_PORTAL_TYPE:374 {375 var _matchedFiber4 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;376 return updatePortal(returnFiber, _matchedFiber4, newChild, priority);377 }378 }379 if (isArray(newChild) || getIteratorFn(newChild)) {380 var _matchedFiber5 = existingChildren.get(newIdx) || null;381 return updateFragment(returnFiber, _matchedFiber5, newChild, priority);382 }383 throwOnInvalidObjectType(returnFiber, newChild);384 }385 return null;386 }387 function warnOnDuplicateKey(child, knownKeys) {388 if (__DEV__) {389 if (typeof child !== 'object' || child === null) {390 return knownKeys;391 }392 switch (child.$$typeof) {393 case REACT_ELEMENT_TYPE:394 case REACT_COROUTINE_TYPE:395 case REACT_PORTAL_TYPE:396 var key = child.key;397 if (typeof key !== 'string') {398 break;399 }400 if (knownKeys === null) {401 knownKeys = new Set();402 knownKeys.add(key);403 break;404 }405 if (!knownKeys.has(key)) {406 knownKeys.add(key);407 break;408 }409 warning(false, 'Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, ' + 'only the first child will be used.%s', key, getCurrentFiberStackAddendum());410 break;411 default:412 break;413 }414 }415 return knownKeys;416 }417 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, priority) {418 if (__DEV__) {419 var knownKeys = null;420 for (var i = 0; i < newChildren.length; i++) {421 var child = newChildren[i];422 knownKeys = warnOnDuplicateKey(child, knownKeys);423 }424 }425 var resultingFirstChild = null;426 var previousNewFiber = null;427 var oldFiber = currentFirstChild;428 var lastPlacedIndex = 0;429 var newIdx = 0;430 var nextOldFiber = null;431 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {432 if (oldFiber.index > newIdx) {433 nextOldFiber = oldFiber;434 oldFiber = null;435 } else {436 nextOldFiber = oldFiber.sibling;437 }438 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], priority);439 if (newFiber === null) {440 if (oldFiber === null) {441 oldFiber = nextOldFiber;442 }443 break;444 }445 if (shouldTrackSideEffects) {446 if (oldFiber && newFiber.alternate === null) {447 deleteChild(returnFiber, oldFiber);448 }449 }450 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);451 if (previousNewFiber === null) {452 resultingFirstChild = newFiber;453 } else {454 previousNewFiber.sibling = newFiber;455 }456 previousNewFiber = newFiber;457 oldFiber = nextOldFiber;458 }459 if (newIdx === newChildren.length) {460 deleteRemainingChildren(returnFiber, oldFiber);461 return resultingFirstChild;462 }463 if (oldFiber === null) {464 for (; newIdx < newChildren.length; newIdx++) {465 var _newFiber = createChild(returnFiber, newChildren[newIdx], priority);466 if (!_newFiber) {467 continue;468 }469 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);470 if (previousNewFiber === null) {471 resultingFirstChild = _newFiber;472 } else {473 previousNewFiber.sibling = _newFiber;474 }475 previousNewFiber = _newFiber;476 }477 return resultingFirstChild;478 }479 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);480 for (; newIdx < newChildren.length; newIdx++) {481 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], priority);482 if (_newFiber2) {483 if (shouldTrackSideEffects) {484 if (_newFiber2.alternate !== null) {485 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);486 }487 }488 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);489 if (previousNewFiber === null) {490 resultingFirstChild = _newFiber2;491 } else {492 previousNewFiber.sibling = _newFiber2;493 }494 previousNewFiber = _newFiber2;495 }496 }497 if (shouldTrackSideEffects) {498 existingChildren.forEach(function (child) {499 return deleteChild(returnFiber, child);500 });501 }502 return resultingFirstChild;503 }504 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, priority) {505 var iteratorFn = getIteratorFn(newChildrenIterable);506 invariant(typeof iteratorFn === 'function', 'An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');507 if (__DEV__) {508 if (typeof newChildrenIterable.entries === 'function') {509 var possibleMap = newChildrenIterable;510 if (possibleMap.entries === iteratorFn) {511 var mapsAsChildrenAddendum = '';512 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;513 if (owner && typeof owner.tag === 'number') {514 var mapsAsChildrenOwnerName = getComponentName(owner);515 if (mapsAsChildrenOwnerName) {516 mapsAsChildrenAddendum = '\n\nCheck the render method of `' + mapsAsChildrenOwnerName + '`.';517 }518 }519 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', mapsAsChildrenAddendum);520 didWarnAboutMaps = true;521 }522 }523 var _newChildren = iteratorFn.call(newChildrenIterable);524 if (_newChildren) {525 var knownKeys = null;526 var _step = _newChildren.next();527 for (; !_step.done; _step = _newChildren.next()) {528 var child = _step.value;529 knownKeys = warnOnDuplicateKey(child, knownKeys);530 }531 }532 }533 var newChildren = iteratorFn.call(newChildrenIterable);534 invariant(newChildren != null, 'An iterable object provided no iterator.');535 var resultingFirstChild = null;536 var previousNewFiber = null;537 var oldFiber = currentFirstChild;538 var lastPlacedIndex = 0;539 var newIdx = 0;540 var nextOldFiber = null;541 var step = newChildren.next();542 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {543 if (oldFiber.index > newIdx) {544 nextOldFiber = oldFiber;545 oldFiber = null;546 } else {547 nextOldFiber = oldFiber.sibling;548 }549 var newFiber = updateSlot(returnFiber, oldFiber, step.value, priority);550 if (newFiber === null) {551 if (!oldFiber) {552 oldFiber = nextOldFiber;553 }554 break;555 }556 if (shouldTrackSideEffects) {557 if (oldFiber && newFiber.alternate === null) {558 deleteChild(returnFiber, oldFiber);559 }560 }561 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);562 if (previousNewFiber === null) {563 resultingFirstChild = newFiber;564 } else {565 previousNewFiber.sibling = newFiber;566 }567 previousNewFiber = newFiber;568 oldFiber = nextOldFiber;569 }570 if (step.done) {571 deleteRemainingChildren(returnFiber, oldFiber);572 return resultingFirstChild;573 }574 if (oldFiber === null) {575 for (; !step.done; newIdx++, step = newChildren.next()) {576 var _newFiber3 = createChild(returnFiber, step.value, priority);577 if (_newFiber3 === null) {578 continue;579 }580 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);581 if (previousNewFiber === null) {582 resultingFirstChild = _newFiber3;583 } else {584 previousNewFiber.sibling = _newFiber3;585 }586 previousNewFiber = _newFiber3;587 }588 return resultingFirstChild;589 }590 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);591 for (; !step.done; newIdx++, step = newChildren.next()) {592 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, priority);593 if (_newFiber4 !== null) {594 if (shouldTrackSideEffects) {595 if (_newFiber4.alternate !== null) {596 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);597 }598 }599 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);600 if (previousNewFiber === null) {601 resultingFirstChild = _newFiber4;602 } else {603 previousNewFiber.sibling = _newFiber4;604 }605 previousNewFiber = _newFiber4;606 }607 }608 if (shouldTrackSideEffects) {609 existingChildren.forEach(function (child) {610 return deleteChild(returnFiber, child);611 });612 }613 return resultingFirstChild;614 }615 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, priority) {616 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {617 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);618 var existing = useFiber(currentFirstChild, priority);619 existing.pendingProps = textContent;620 existing.return = returnFiber;621 return existing;622 }623 deleteRemainingChildren(returnFiber, currentFirstChild);624 var created = createFiberFromText(textContent, priority);625 created.return = returnFiber;626 return created;627 }628 function reconcileSingleElement(returnFiber, currentFirstChild, element, priority) {629 var key = element.key;630 var child = currentFirstChild;631 while (child !== null) {632 if (child.key === key) {633 if (child.type === element.type) {634 deleteRemainingChildren(returnFiber, child.sibling);635 var existing = useFiber(child, priority);636 existing.ref = coerceRef(child, element);637 existing.pendingProps = element.props;638 existing.return = returnFiber;639 if (__DEV__) {640 existing._debugSource = element._source;641 existing._debugOwner = element._owner;642 }643 return existing;644 } else {645 deleteRemainingChildren(returnFiber, child);646 break;647 }648 } else {649 deleteChild(returnFiber, child);650 }651 child = child.sibling;652 }653 var created = createFiberFromElement(element, priority);654 created.ref = coerceRef(currentFirstChild, element);655 created.return = returnFiber;656 return created;657 }658 function reconcileSingleCoroutine(returnFiber, currentFirstChild, coroutine, priority) {659 var key = coroutine.key;660 var child = currentFirstChild;661 while (child !== null) {662 if (child.key === key) {663 if (child.tag === CoroutineComponent) {664 deleteRemainingChildren(returnFiber, child.sibling);665 var existing = useFiber(child, priority);666 existing.pendingProps = coroutine;667 existing.return = returnFiber;668 return existing;669 } else {670 deleteRemainingChildren(returnFiber, child);671 break;672 }673 } else {674 deleteChild(returnFiber, child);675 }676 child = child.sibling;677 }678 var created = createFiberFromCoroutine(coroutine, priority);679 created.return = returnFiber;680 return created;681 }682 function reconcileSingleYield(returnFiber, currentFirstChild, yieldNode, priority) {683 var child = currentFirstChild;684 if (child !== null) {685 if (child.tag === YieldComponent) {686 deleteRemainingChildren(returnFiber, child.sibling);687 var existing = useFiber(child, priority);688 existing.type = yieldNode.value;689 existing.return = returnFiber;690 return existing;691 } else {692 deleteRemainingChildren(returnFiber, child);693 }694 }695 var created = createFiberFromYield(yieldNode, priority);696 created.type = yieldNode.value;697 created.return = returnFiber;698 return created;699 }700 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, priority) {701 var key = portal.key;702 var child = currentFirstChild;703 while (child !== null) {704 if (child.key === key) {705 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {706 deleteRemainingChildren(returnFiber, child.sibling);707 var existing = useFiber(child, priority);708 existing.pendingProps = portal.children || [];709 existing.return = returnFiber;710 return existing;711 } else {712 deleteRemainingChildren(returnFiber, child);713 break;714 }715 } else {716 deleteChild(returnFiber, child);717 }718 child = child.sibling;719 }720 var created = createFiberFromPortal(portal, priority);721 created.return = returnFiber;722 return created;723 }724 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, priority) {725 var disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;726 var isObject = typeof newChild === 'object' && newChild !== null;727 if (isObject) {728 if (disableNewFiberFeatures) {729 switch (newChild.$$typeof) {730 case REACT_ELEMENT_TYPE:731 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));732 case REACT_PORTAL_TYPE:733 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));734 }735 } else {736 switch (newChild.$$typeof) {737 case REACT_ELEMENT_TYPE:738 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));739 case REACT_COROUTINE_TYPE:740 return placeSingleChild(reconcileSingleCoroutine(returnFiber, currentFirstChild, newChild, priority));741 case REACT_YIELD_TYPE:742 return placeSingleChild(reconcileSingleYield(returnFiber, currentFirstChild, newChild, priority));743 case REACT_PORTAL_TYPE:744 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));745 }746 }747 }748 if (disableNewFiberFeatures) {749 switch (returnFiber.tag) {750 case ClassComponent:751 {752 if (__DEV__) {753 var instance = returnFiber.stateNode;754 if (instance.render._isMockFunction && typeof newChild === 'undefined') {755 break;756 }757 }758 var Component = returnFiber.type;759 invariant(newChild === null || newChild === false, '%s.render(): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', Component.displayName || Component.name || 'Component');760 break;761 }762 case FunctionalComponent:763 {764 var _Component = returnFiber.type;765 invariant(newChild === null || newChild === false, '%s(...): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', _Component.displayName || _Component.name || 'Component');766 break;767 }768 }769 }770 if (typeof newChild === 'string' || typeof newChild === 'number') {771 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, priority));772 }773 if (isArray(newChild)) {774 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, priority);775 }776 if (getIteratorFn(newChild)) {777 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, priority);778 }779 if (isObject) {780 throwOnInvalidObjectType(returnFiber, newChild);781 }782 if (!disableNewFiberFeatures && typeof newChild === 'undefined') {783 switch (returnFiber.tag) {784 case ClassComponent:785 {786 if (__DEV__) {787 var _instance = returnFiber.stateNode;788 if (_instance.render._isMockFunction) {789 break;790 }791 }792 }793 case FunctionalComponent:794 {...

Full Screen

Full Screen

ce6df42c5b933ee2ca14358e199c7078c8e06aReactChildFiber.js

Source:ce6df42c5b933ee2ca14358e199c7078c8e06aReactChildFiber.js Github

copy

Full Screen

...71 }72 }73 return mixedRef;74}75function throwOnInvalidObjectType(returnFiber, newChild) {76 if (returnFiber.type !== 'textarea') {77 var addendum = '';78 if (__DEV__) {79 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.';80 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;81 if (owner && typeof owner.tag === 'number') {82 var name = getComponentName(owner);83 if (name) {84 addendum += '\n\nCheck the render method of `' + name + '`.';85 }86 }87 }88 invariant(false, 'Objects are not valid as a React child (found: %s).%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum);89 }90}91function ChildReconciler(shouldClone, shouldTrackSideEffects) {92 function deleteChild(returnFiber, childToDelete) {93 if (!shouldTrackSideEffects) {94 return;95 }96 if (!shouldClone) {97 if (childToDelete.alternate === null) {98 return;99 }100 childToDelete = childToDelete.alternate;101 }102 var last = returnFiber.progressedLastDeletion;103 if (last !== null) {104 last.nextEffect = childToDelete;105 returnFiber.progressedLastDeletion = childToDelete;106 } else {107 returnFiber.progressedFirstDeletion = returnFiber.progressedLastDeletion = childToDelete;108 }109 childToDelete.nextEffect = null;110 childToDelete.effectTag = Deletion;111 }112 function deleteRemainingChildren(returnFiber, currentFirstChild) {113 if (!shouldTrackSideEffects) {114 return null;115 }116 var childToDelete = currentFirstChild;117 while (childToDelete !== null) {118 deleteChild(returnFiber, childToDelete);119 childToDelete = childToDelete.sibling;120 }121 return null;122 }123 function mapRemainingChildren(returnFiber, currentFirstChild) {124 var existingChildren = new Map();125 var existingChild = currentFirstChild;126 while (existingChild !== null) {127 if (existingChild.key !== null) {128 existingChildren.set(existingChild.key, existingChild);129 } else {130 existingChildren.set(existingChild.index, existingChild);131 }132 existingChild = existingChild.sibling;133 }134 return existingChildren;135 }136 function useFiber(fiber, priority) {137 if (shouldClone) {138 var clone = cloneFiber(fiber, priority);139 clone.index = 0;140 clone.sibling = null;141 return clone;142 } else {143 fiber.pendingWorkPriority = priority;144 fiber.effectTag = NoEffect;145 fiber.index = 0;146 fiber.sibling = null;147 return fiber;148 }149 }150 function placeChild(newFiber, lastPlacedIndex, newIndex) {151 newFiber.index = newIndex;152 if (!shouldTrackSideEffects) {153 return lastPlacedIndex;154 }155 var current = newFiber.alternate;156 if (current !== null) {157 var oldIndex = current.index;158 if (oldIndex < lastPlacedIndex) {159 newFiber.effectTag = Placement;160 return lastPlacedIndex;161 } else {162 return oldIndex;163 }164 } else {165 newFiber.effectTag = Placement;166 return lastPlacedIndex;167 }168 }169 function placeSingleChild(newFiber) {170 if (shouldTrackSideEffects && newFiber.alternate === null) {171 newFiber.effectTag = Placement;172 }173 return newFiber;174 }175 function updateTextNode(returnFiber, current, textContent, priority) {176 if (current === null || current.tag !== HostText) {177 var created = createFiberFromText(textContent, priority);178 created.return = returnFiber;179 return created;180 } else {181 var existing = useFiber(current, priority);182 existing.pendingProps = textContent;183 existing.return = returnFiber;184 return existing;185 }186 }187 function updateElement(returnFiber, current, element, priority) {188 if (current === null || current.type !== element.type) {189 var created = createFiberFromElement(element, priority);190 created.ref = coerceRef(current, element);191 created.return = returnFiber;192 return created;193 } else {194 var existing = useFiber(current, priority);195 existing.ref = coerceRef(current, element);196 existing.pendingProps = element.props;197 existing.return = returnFiber;198 if (__DEV__) {199 existing._debugSource = element._source;200 existing._debugOwner = element._owner;201 }202 return existing;203 }204 }205 function updateCoroutine(returnFiber, current, coroutine, priority) {206 if (current === null || current.tag !== CoroutineComponent) {207 var created = createFiberFromCoroutine(coroutine, priority);208 created.return = returnFiber;209 return created;210 } else {211 var existing = useFiber(current, priority);212 existing.pendingProps = coroutine;213 existing.return = returnFiber;214 return existing;215 }216 }217 function updateYield(returnFiber, current, yieldNode, priority) {218 if (current === null || current.tag !== YieldComponent) {219 var created = createFiberFromYield(yieldNode, priority);220 created.type = yieldNode.value;221 created.return = returnFiber;222 return created;223 } else {224 var existing = useFiber(current, priority);225 existing.type = yieldNode.value;226 existing.return = returnFiber;227 return existing;228 }229 }230 function updatePortal(returnFiber, current, portal, priority) {231 if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {232 var created = createFiberFromPortal(portal, priority);233 created.return = returnFiber;234 return created;235 } else {236 var existing = useFiber(current, priority);237 existing.pendingProps = portal.children || [];238 existing.return = returnFiber;239 return existing;240 }241 }242 function updateFragment(returnFiber, current, fragment, priority) {243 if (current === null || current.tag !== Fragment) {244 var created = createFiberFromFragment(fragment, priority);245 created.return = returnFiber;246 return created;247 } else {248 var existing = useFiber(current, priority);249 existing.pendingProps = fragment;250 existing.return = returnFiber;251 return existing;252 }253 }254 function createChild(returnFiber, newChild, priority) {255 if (typeof newChild === 'string' || typeof newChild === 'number') {256 var created = createFiberFromText('' + newChild, priority);257 created.return = returnFiber;258 return created;259 }260 if (typeof newChild === 'object' && newChild !== null) {261 switch (newChild.$$typeof) {262 case REACT_ELEMENT_TYPE:263 {264 var _created = createFiberFromElement(newChild, priority);265 _created.ref = coerceRef(null, newChild);266 _created.return = returnFiber;267 return _created;268 }269 case REACT_COROUTINE_TYPE:270 {271 var _created2 = createFiberFromCoroutine(newChild, priority);272 _created2.return = returnFiber;273 return _created2;274 }275 case REACT_YIELD_TYPE:276 {277 var _created3 = createFiberFromYield(newChild, priority);278 _created3.type = newChild.value;279 _created3.return = returnFiber;280 return _created3;281 }282 case REACT_PORTAL_TYPE:283 {284 var _created4 = createFiberFromPortal(newChild, priority);285 _created4.return = returnFiber;286 return _created4;287 }288 }289 if (isArray(newChild) || getIteratorFn(newChild)) {290 var _created5 = createFiberFromFragment(newChild, priority);291 _created5.return = returnFiber;292 return _created5;293 }294 throwOnInvalidObjectType(returnFiber, newChild);295 }296 return null;297 }298 function updateSlot(returnFiber, oldFiber, newChild, priority) {299 var key = oldFiber !== null ? oldFiber.key : null;300 if (typeof newChild === 'string' || typeof newChild === 'number') {301 if (key !== null) {302 return null;303 }304 return updateTextNode(returnFiber, oldFiber, '' + newChild, priority);305 }306 if (typeof newChild === 'object' && newChild !== null) {307 switch (newChild.$$typeof) {308 case REACT_ELEMENT_TYPE:309 {310 if (newChild.key === key) {311 return updateElement(returnFiber, oldFiber, newChild, priority);312 } else {313 return null;314 }315 }316 case REACT_COROUTINE_TYPE:317 {318 if (newChild.key === key) {319 return updateCoroutine(returnFiber, oldFiber, newChild, priority);320 } else {321 return null;322 }323 }324 case REACT_YIELD_TYPE:325 {326 if (key === null) {327 return updateYield(returnFiber, oldFiber, newChild, priority);328 } else {329 return null;330 }331 }332 case REACT_PORTAL_TYPE:333 {334 if (newChild.key === key) {335 return updatePortal(returnFiber, oldFiber, newChild, priority);336 } else {337 return null;338 }339 }340 }341 if (isArray(newChild) || getIteratorFn(newChild)) {342 if (key !== null) {343 return null;344 }345 return updateFragment(returnFiber, oldFiber, newChild, priority);346 }347 throwOnInvalidObjectType(returnFiber, newChild);348 }349 return null;350 }351 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, priority) {352 if (typeof newChild === 'string' || typeof newChild === 'number') {353 var matchedFiber = existingChildren.get(newIdx) || null;354 return updateTextNode(returnFiber, matchedFiber, '' + newChild, priority);355 }356 if (typeof newChild === 'object' && newChild !== null) {357 switch (newChild.$$typeof) {358 case REACT_ELEMENT_TYPE:359 {360 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;361 return updateElement(returnFiber, _matchedFiber, newChild, priority);362 }363 case REACT_COROUTINE_TYPE:364 {365 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;366 return updateCoroutine(returnFiber, _matchedFiber2, newChild, priority);367 }368 case REACT_YIELD_TYPE:369 {370 var _matchedFiber3 = existingChildren.get(newIdx) || null;371 return updateYield(returnFiber, _matchedFiber3, newChild, priority);372 }373 case REACT_PORTAL_TYPE:374 {375 var _matchedFiber4 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;376 return updatePortal(returnFiber, _matchedFiber4, newChild, priority);377 }378 }379 if (isArray(newChild) || getIteratorFn(newChild)) {380 var _matchedFiber5 = existingChildren.get(newIdx) || null;381 return updateFragment(returnFiber, _matchedFiber5, newChild, priority);382 }383 throwOnInvalidObjectType(returnFiber, newChild);384 }385 return null;386 }387 function warnOnDuplicateKey(child, knownKeys) {388 if (__DEV__) {389 if (typeof child !== 'object' || child === null) {390 return knownKeys;391 }392 switch (child.$$typeof) {393 case REACT_ELEMENT_TYPE:394 case REACT_COROUTINE_TYPE:395 case REACT_PORTAL_TYPE:396 var key = child.key;397 if (typeof key !== 'string') {398 break;399 }400 if (knownKeys === null) {401 knownKeys = new Set();402 knownKeys.add(key);403 break;404 }405 if (!knownKeys.has(key)) {406 knownKeys.add(key);407 break;408 }409 warning(false, 'Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, ' + 'only the first child will be used.%s', key, getCurrentFiberStackAddendum());410 break;411 default:412 break;413 }414 }415 return knownKeys;416 }417 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, priority) {418 if (__DEV__) {419 var knownKeys = null;420 for (var i = 0; i < newChildren.length; i++) {421 var child = newChildren[i];422 knownKeys = warnOnDuplicateKey(child, knownKeys);423 }424 }425 var resultingFirstChild = null;426 var previousNewFiber = null;427 var oldFiber = currentFirstChild;428 var lastPlacedIndex = 0;429 var newIdx = 0;430 var nextOldFiber = null;431 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {432 if (oldFiber.index > newIdx) {433 nextOldFiber = oldFiber;434 oldFiber = null;435 } else {436 nextOldFiber = oldFiber.sibling;437 }438 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], priority);439 if (newFiber === null) {440 if (oldFiber === null) {441 oldFiber = nextOldFiber;442 }443 break;444 }445 if (shouldTrackSideEffects) {446 if (oldFiber && newFiber.alternate === null) {447 deleteChild(returnFiber, oldFiber);448 }449 }450 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);451 if (previousNewFiber === null) {452 resultingFirstChild = newFiber;453 } else {454 previousNewFiber.sibling = newFiber;455 }456 previousNewFiber = newFiber;457 oldFiber = nextOldFiber;458 }459 if (newIdx === newChildren.length) {460 deleteRemainingChildren(returnFiber, oldFiber);461 return resultingFirstChild;462 }463 if (oldFiber === null) {464 for (; newIdx < newChildren.length; newIdx++) {465 var _newFiber = createChild(returnFiber, newChildren[newIdx], priority);466 if (!_newFiber) {467 continue;468 }469 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);470 if (previousNewFiber === null) {471 resultingFirstChild = _newFiber;472 } else {473 previousNewFiber.sibling = _newFiber;474 }475 previousNewFiber = _newFiber;476 }477 return resultingFirstChild;478 }479 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);480 for (; newIdx < newChildren.length; newIdx++) {481 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], priority);482 if (_newFiber2) {483 if (shouldTrackSideEffects) {484 if (_newFiber2.alternate !== null) {485 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);486 }487 }488 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);489 if (previousNewFiber === null) {490 resultingFirstChild = _newFiber2;491 } else {492 previousNewFiber.sibling = _newFiber2;493 }494 previousNewFiber = _newFiber2;495 }496 }497 if (shouldTrackSideEffects) {498 existingChildren.forEach(function (child) {499 return deleteChild(returnFiber, child);500 });501 }502 return resultingFirstChild;503 }504 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, priority) {505 var iteratorFn = getIteratorFn(newChildrenIterable);506 invariant(typeof iteratorFn === 'function', 'An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');507 if (__DEV__) {508 if (typeof newChildrenIterable.entries === 'function') {509 var possibleMap = newChildrenIterable;510 if (possibleMap.entries === iteratorFn) {511 var mapsAsChildrenAddendum = '';512 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;513 if (owner && typeof owner.tag === 'number') {514 var mapsAsChildrenOwnerName = getComponentName(owner);515 if (mapsAsChildrenOwnerName) {516 mapsAsChildrenAddendum = '\n\nCheck the render method of `' + mapsAsChildrenOwnerName + '`.';517 }518 }519 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', mapsAsChildrenAddendum);520 didWarnAboutMaps = true;521 }522 }523 var _newChildren = iteratorFn.call(newChildrenIterable);524 if (_newChildren) {525 var knownKeys = null;526 var _step = _newChildren.next();527 for (; !_step.done; _step = _newChildren.next()) {528 var child = _step.value;529 knownKeys = warnOnDuplicateKey(child, knownKeys);530 }531 }532 }533 var newChildren = iteratorFn.call(newChildrenIterable);534 invariant(newChildren != null, 'An iterable object provided no iterator.');535 var resultingFirstChild = null;536 var previousNewFiber = null;537 var oldFiber = currentFirstChild;538 var lastPlacedIndex = 0;539 var newIdx = 0;540 var nextOldFiber = null;541 var step = newChildren.next();542 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {543 if (oldFiber.index > newIdx) {544 nextOldFiber = oldFiber;545 oldFiber = null;546 } else {547 nextOldFiber = oldFiber.sibling;548 }549 var newFiber = updateSlot(returnFiber, oldFiber, step.value, priority);550 if (newFiber === null) {551 if (!oldFiber) {552 oldFiber = nextOldFiber;553 }554 break;555 }556 if (shouldTrackSideEffects) {557 if (oldFiber && newFiber.alternate === null) {558 deleteChild(returnFiber, oldFiber);559 }560 }561 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);562 if (previousNewFiber === null) {563 resultingFirstChild = newFiber;564 } else {565 previousNewFiber.sibling = newFiber;566 }567 previousNewFiber = newFiber;568 oldFiber = nextOldFiber;569 }570 if (step.done) {571 deleteRemainingChildren(returnFiber, oldFiber);572 return resultingFirstChild;573 }574 if (oldFiber === null) {575 for (; !step.done; newIdx++, step = newChildren.next()) {576 var _newFiber3 = createChild(returnFiber, step.value, priority);577 if (_newFiber3 === null) {578 continue;579 }580 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);581 if (previousNewFiber === null) {582 resultingFirstChild = _newFiber3;583 } else {584 previousNewFiber.sibling = _newFiber3;585 }586 previousNewFiber = _newFiber3;587 }588 return resultingFirstChild;589 }590 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);591 for (; !step.done; newIdx++, step = newChildren.next()) {592 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, priority);593 if (_newFiber4 !== null) {594 if (shouldTrackSideEffects) {595 if (_newFiber4.alternate !== null) {596 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);597 }598 }599 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);600 if (previousNewFiber === null) {601 resultingFirstChild = _newFiber4;602 } else {603 previousNewFiber.sibling = _newFiber4;604 }605 previousNewFiber = _newFiber4;606 }607 }608 if (shouldTrackSideEffects) {609 existingChildren.forEach(function (child) {610 return deleteChild(returnFiber, child);611 });612 }613 return resultingFirstChild;614 }615 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, priority) {616 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {617 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);618 var existing = useFiber(currentFirstChild, priority);619 existing.pendingProps = textContent;620 existing.return = returnFiber;621 return existing;622 }623 deleteRemainingChildren(returnFiber, currentFirstChild);624 var created = createFiberFromText(textContent, priority);625 created.return = returnFiber;626 return created;627 }628 function reconcileSingleElement(returnFiber, currentFirstChild, element, priority) {629 var key = element.key;630 var child = currentFirstChild;631 while (child !== null) {632 if (child.key === key) {633 if (child.type === element.type) {634 deleteRemainingChildren(returnFiber, child.sibling);635 var existing = useFiber(child, priority);636 existing.ref = coerceRef(child, element);637 existing.pendingProps = element.props;638 existing.return = returnFiber;639 if (__DEV__) {640 existing._debugSource = element._source;641 existing._debugOwner = element._owner;642 }643 return existing;644 } else {645 deleteRemainingChildren(returnFiber, child);646 break;647 }648 } else {649 deleteChild(returnFiber, child);650 }651 child = child.sibling;652 }653 var created = createFiberFromElement(element, priority);654 created.ref = coerceRef(currentFirstChild, element);655 created.return = returnFiber;656 return created;657 }658 function reconcileSingleCoroutine(returnFiber, currentFirstChild, coroutine, priority) {659 var key = coroutine.key;660 var child = currentFirstChild;661 while (child !== null) {662 if (child.key === key) {663 if (child.tag === CoroutineComponent) {664 deleteRemainingChildren(returnFiber, child.sibling);665 var existing = useFiber(child, priority);666 existing.pendingProps = coroutine;667 existing.return = returnFiber;668 return existing;669 } else {670 deleteRemainingChildren(returnFiber, child);671 break;672 }673 } else {674 deleteChild(returnFiber, child);675 }676 child = child.sibling;677 }678 var created = createFiberFromCoroutine(coroutine, priority);679 created.return = returnFiber;680 return created;681 }682 function reconcileSingleYield(returnFiber, currentFirstChild, yieldNode, priority) {683 var child = currentFirstChild;684 if (child !== null) {685 if (child.tag === YieldComponent) {686 deleteRemainingChildren(returnFiber, child.sibling);687 var existing = useFiber(child, priority);688 existing.type = yieldNode.value;689 existing.return = returnFiber;690 return existing;691 } else {692 deleteRemainingChildren(returnFiber, child);693 }694 }695 var created = createFiberFromYield(yieldNode, priority);696 created.type = yieldNode.value;697 created.return = returnFiber;698 return created;699 }700 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, priority) {701 var key = portal.key;702 var child = currentFirstChild;703 while (child !== null) {704 if (child.key === key) {705 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {706 deleteRemainingChildren(returnFiber, child.sibling);707 var existing = useFiber(child, priority);708 existing.pendingProps = portal.children || [];709 existing.return = returnFiber;710 return existing;711 } else {712 deleteRemainingChildren(returnFiber, child);713 break;714 }715 } else {716 deleteChild(returnFiber, child);717 }718 child = child.sibling;719 }720 var created = createFiberFromPortal(portal, priority);721 created.return = returnFiber;722 return created;723 }724 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, priority) {725 var disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;726 var isObject = typeof newChild === 'object' && newChild !== null;727 if (isObject) {728 if (disableNewFiberFeatures) {729 switch (newChild.$$typeof) {730 case REACT_ELEMENT_TYPE:731 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));732 case REACT_PORTAL_TYPE:733 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));734 }735 } else {736 switch (newChild.$$typeof) {737 case REACT_ELEMENT_TYPE:738 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));739 case REACT_COROUTINE_TYPE:740 return placeSingleChild(reconcileSingleCoroutine(returnFiber, currentFirstChild, newChild, priority));741 case REACT_YIELD_TYPE:742 return placeSingleChild(reconcileSingleYield(returnFiber, currentFirstChild, newChild, priority));743 case REACT_PORTAL_TYPE:744 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));745 }746 }747 }748 if (disableNewFiberFeatures) {749 switch (returnFiber.tag) {750 case ClassComponent:751 {752 if (__DEV__) {753 var instance = returnFiber.stateNode;754 if (instance.render._isMockFunction && typeof newChild === 'undefined') {755 break;756 }757 }758 var Component = returnFiber.type;759 invariant(newChild === null || newChild === false, '%s.render(): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', Component.displayName || Component.name || 'Component');760 break;761 }762 case FunctionalComponent:763 {764 var _Component = returnFiber.type;765 invariant(newChild === null || newChild === false, '%s(...): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', _Component.displayName || _Component.name || 'Component');766 break;767 }768 }769 }770 if (typeof newChild === 'string' || typeof newChild === 'number') {771 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, priority));772 }773 if (isArray(newChild)) {774 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, priority);775 }776 if (getIteratorFn(newChild)) {777 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, priority);778 }779 if (isObject) {780 throwOnInvalidObjectType(returnFiber, newChild);781 }782 if (!disableNewFiberFeatures && typeof newChild === 'undefined') {783 switch (returnFiber.tag) {784 case ClassComponent:785 {786 if (__DEV__) {787 var _instance = returnFiber.stateNode;788 if (_instance.render._isMockFunction) {789 break;790 }791 }792 }793 case FunctionalComponent:794 {...

Full Screen

Full Screen

b81b7ed169eab82c9b5e9419bb967395a5c0e8ReactChildFiber.js

Source:b81b7ed169eab82c9b5e9419bb967395a5c0e8ReactChildFiber.js Github

copy

Full Screen

...71 }72 }73 return mixedRef;74}75function throwOnInvalidObjectType(returnFiber, newChild) {76 if (returnFiber.type !== 'textarea') {77 var addendum = '';78 if (__DEV__) {79 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.';80 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;81 if (owner && typeof owner.tag === 'number') {82 var name = getComponentName(owner);83 if (name) {84 addendum += '\n\nCheck the render method of `' + name + '`.';85 }86 }87 }88 invariant(false, 'Objects are not valid as a React child (found: %s).%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum);89 }90}91function ChildReconciler(shouldClone, shouldTrackSideEffects) {92 function deleteChild(returnFiber, childToDelete) {93 if (!shouldTrackSideEffects) {94 return;95 }96 if (!shouldClone) {97 if (childToDelete.alternate === null) {98 return;99 }100 childToDelete = childToDelete.alternate;101 }102 var last = returnFiber.progressedLastDeletion;103 if (last !== null) {104 last.nextEffect = childToDelete;105 returnFiber.progressedLastDeletion = childToDelete;106 } else {107 returnFiber.progressedFirstDeletion = returnFiber.progressedLastDeletion = childToDelete;108 }109 childToDelete.nextEffect = null;110 childToDelete.effectTag = Deletion;111 }112 function deleteRemainingChildren(returnFiber, currentFirstChild) {113 if (!shouldTrackSideEffects) {114 return null;115 }116 var childToDelete = currentFirstChild;117 while (childToDelete !== null) {118 deleteChild(returnFiber, childToDelete);119 childToDelete = childToDelete.sibling;120 }121 return null;122 }123 function mapRemainingChildren(returnFiber, currentFirstChild) {124 var existingChildren = new Map();125 var existingChild = currentFirstChild;126 while (existingChild !== null) {127 if (existingChild.key !== null) {128 existingChildren.set(existingChild.key, existingChild);129 } else {130 existingChildren.set(existingChild.index, existingChild);131 }132 existingChild = existingChild.sibling;133 }134 return existingChildren;135 }136 function useFiber(fiber, priority) {137 if (shouldClone) {138 var clone = cloneFiber(fiber, priority);139 clone.index = 0;140 clone.sibling = null;141 return clone;142 } else {143 fiber.pendingWorkPriority = priority;144 fiber.effectTag = NoEffect;145 fiber.index = 0;146 fiber.sibling = null;147 return fiber;148 }149 }150 function placeChild(newFiber, lastPlacedIndex, newIndex) {151 newFiber.index = newIndex;152 if (!shouldTrackSideEffects) {153 return lastPlacedIndex;154 }155 var current = newFiber.alternate;156 if (current !== null) {157 var oldIndex = current.index;158 if (oldIndex < lastPlacedIndex) {159 newFiber.effectTag = Placement;160 return lastPlacedIndex;161 } else {162 return oldIndex;163 }164 } else {165 newFiber.effectTag = Placement;166 return lastPlacedIndex;167 }168 }169 function placeSingleChild(newFiber) {170 if (shouldTrackSideEffects && newFiber.alternate === null) {171 newFiber.effectTag = Placement;172 }173 return newFiber;174 }175 function updateTextNode(returnFiber, current, textContent, priority) {176 if (current === null || current.tag !== HostText) {177 var created = createFiberFromText(textContent, priority);178 created.return = returnFiber;179 return created;180 } else {181 var existing = useFiber(current, priority);182 existing.pendingProps = textContent;183 existing.return = returnFiber;184 return existing;185 }186 }187 function updateElement(returnFiber, current, element, priority) {188 if (current === null || current.type !== element.type) {189 var created = createFiberFromElement(element, priority);190 created.ref = coerceRef(current, element);191 created.return = returnFiber;192 return created;193 } else {194 var existing = useFiber(current, priority);195 existing.ref = coerceRef(current, element);196 existing.pendingProps = element.props;197 existing.return = returnFiber;198 if (__DEV__) {199 existing._debugSource = element._source;200 existing._debugOwner = element._owner;201 }202 return existing;203 }204 }205 function updateCoroutine(returnFiber, current, coroutine, priority) {206 if (current === null || current.tag !== CoroutineComponent) {207 var created = createFiberFromCoroutine(coroutine, priority);208 created.return = returnFiber;209 return created;210 } else {211 var existing = useFiber(current, priority);212 existing.pendingProps = coroutine;213 existing.return = returnFiber;214 return existing;215 }216 }217 function updateYield(returnFiber, current, yieldNode, priority) {218 if (current === null || current.tag !== YieldComponent) {219 var created = createFiberFromYield(yieldNode, priority);220 created.type = yieldNode.value;221 created.return = returnFiber;222 return created;223 } else {224 var existing = useFiber(current, priority);225 existing.type = yieldNode.value;226 existing.return = returnFiber;227 return existing;228 }229 }230 function updatePortal(returnFiber, current, portal, priority) {231 if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {232 var created = createFiberFromPortal(portal, priority);233 created.return = returnFiber;234 return created;235 } else {236 var existing = useFiber(current, priority);237 existing.pendingProps = portal.children || [];238 existing.return = returnFiber;239 return existing;240 }241 }242 function updateFragment(returnFiber, current, fragment, priority) {243 if (current === null || current.tag !== Fragment) {244 var created = createFiberFromFragment(fragment, priority);245 created.return = returnFiber;246 return created;247 } else {248 var existing = useFiber(current, priority);249 existing.pendingProps = fragment;250 existing.return = returnFiber;251 return existing;252 }253 }254 function createChild(returnFiber, newChild, priority) {255 if (typeof newChild === 'string' || typeof newChild === 'number') {256 var created = createFiberFromText('' + newChild, priority);257 created.return = returnFiber;258 return created;259 }260 if (typeof newChild === 'object' && newChild !== null) {261 switch (newChild.$$typeof) {262 case REACT_ELEMENT_TYPE:263 {264 var _created = createFiberFromElement(newChild, priority);265 _created.ref = coerceRef(null, newChild);266 _created.return = returnFiber;267 return _created;268 }269 case REACT_COROUTINE_TYPE:270 {271 var _created2 = createFiberFromCoroutine(newChild, priority);272 _created2.return = returnFiber;273 return _created2;274 }275 case REACT_YIELD_TYPE:276 {277 var _created3 = createFiberFromYield(newChild, priority);278 _created3.type = newChild.value;279 _created3.return = returnFiber;280 return _created3;281 }282 case REACT_PORTAL_TYPE:283 {284 var _created4 = createFiberFromPortal(newChild, priority);285 _created4.return = returnFiber;286 return _created4;287 }288 }289 if (isArray(newChild) || getIteratorFn(newChild)) {290 var _created5 = createFiberFromFragment(newChild, priority);291 _created5.return = returnFiber;292 return _created5;293 }294 throwOnInvalidObjectType(returnFiber, newChild);295 }296 return null;297 }298 function updateSlot(returnFiber, oldFiber, newChild, priority) {299 var key = oldFiber !== null ? oldFiber.key : null;300 if (typeof newChild === 'string' || typeof newChild === 'number') {301 if (key !== null) {302 return null;303 }304 return updateTextNode(returnFiber, oldFiber, '' + newChild, priority);305 }306 if (typeof newChild === 'object' && newChild !== null) {307 switch (newChild.$$typeof) {308 case REACT_ELEMENT_TYPE:309 {310 if (newChild.key === key) {311 return updateElement(returnFiber, oldFiber, newChild, priority);312 } else {313 return null;314 }315 }316 case REACT_COROUTINE_TYPE:317 {318 if (newChild.key === key) {319 return updateCoroutine(returnFiber, oldFiber, newChild, priority);320 } else {321 return null;322 }323 }324 case REACT_YIELD_TYPE:325 {326 if (key === null) {327 return updateYield(returnFiber, oldFiber, newChild, priority);328 } else {329 return null;330 }331 }332 case REACT_PORTAL_TYPE:333 {334 if (newChild.key === key) {335 return updatePortal(returnFiber, oldFiber, newChild, priority);336 } else {337 return null;338 }339 }340 }341 if (isArray(newChild) || getIteratorFn(newChild)) {342 if (key !== null) {343 return null;344 }345 return updateFragment(returnFiber, oldFiber, newChild, priority);346 }347 throwOnInvalidObjectType(returnFiber, newChild);348 }349 return null;350 }351 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, priority) {352 if (typeof newChild === 'string' || typeof newChild === 'number') {353 var matchedFiber = existingChildren.get(newIdx) || null;354 return updateTextNode(returnFiber, matchedFiber, '' + newChild, priority);355 }356 if (typeof newChild === 'object' && newChild !== null) {357 switch (newChild.$$typeof) {358 case REACT_ELEMENT_TYPE:359 {360 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;361 return updateElement(returnFiber, _matchedFiber, newChild, priority);362 }363 case REACT_COROUTINE_TYPE:364 {365 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;366 return updateCoroutine(returnFiber, _matchedFiber2, newChild, priority);367 }368 case REACT_YIELD_TYPE:369 {370 var _matchedFiber3 = existingChildren.get(newIdx) || null;371 return updateYield(returnFiber, _matchedFiber3, newChild, priority);372 }373 case REACT_PORTAL_TYPE:374 {375 var _matchedFiber4 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;376 return updatePortal(returnFiber, _matchedFiber4, newChild, priority);377 }378 }379 if (isArray(newChild) || getIteratorFn(newChild)) {380 var _matchedFiber5 = existingChildren.get(newIdx) || null;381 return updateFragment(returnFiber, _matchedFiber5, newChild, priority);382 }383 throwOnInvalidObjectType(returnFiber, newChild);384 }385 return null;386 }387 function warnOnDuplicateKey(child, knownKeys) {388 if (__DEV__) {389 if (typeof child !== 'object' || child === null) {390 return knownKeys;391 }392 switch (child.$$typeof) {393 case REACT_ELEMENT_TYPE:394 case REACT_COROUTINE_TYPE:395 case REACT_PORTAL_TYPE:396 var key = child.key;397 if (typeof key !== 'string') {398 break;399 }400 if (knownKeys === null) {401 knownKeys = new Set();402 knownKeys.add(key);403 break;404 }405 if (!knownKeys.has(key)) {406 knownKeys.add(key);407 break;408 }409 warning(false, 'Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, ' + 'only the first child will be used.%s', key, getCurrentFiberStackAddendum());410 break;411 default:412 break;413 }414 }415 return knownKeys;416 }417 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, priority) {418 if (__DEV__) {419 var knownKeys = null;420 for (var i = 0; i < newChildren.length; i++) {421 var child = newChildren[i];422 knownKeys = warnOnDuplicateKey(child, knownKeys);423 }424 }425 var resultingFirstChild = null;426 var previousNewFiber = null;427 var oldFiber = currentFirstChild;428 var lastPlacedIndex = 0;429 var newIdx = 0;430 var nextOldFiber = null;431 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {432 if (oldFiber.index > newIdx) {433 nextOldFiber = oldFiber;434 oldFiber = null;435 } else {436 nextOldFiber = oldFiber.sibling;437 }438 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], priority);439 if (newFiber === null) {440 if (oldFiber === null) {441 oldFiber = nextOldFiber;442 }443 break;444 }445 if (shouldTrackSideEffects) {446 if (oldFiber && newFiber.alternate === null) {447 deleteChild(returnFiber, oldFiber);448 }449 }450 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);451 if (previousNewFiber === null) {452 resultingFirstChild = newFiber;453 } else {454 previousNewFiber.sibling = newFiber;455 }456 previousNewFiber = newFiber;457 oldFiber = nextOldFiber;458 }459 if (newIdx === newChildren.length) {460 deleteRemainingChildren(returnFiber, oldFiber);461 return resultingFirstChild;462 }463 if (oldFiber === null) {464 for (; newIdx < newChildren.length; newIdx++) {465 var _newFiber = createChild(returnFiber, newChildren[newIdx], priority);466 if (!_newFiber) {467 continue;468 }469 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);470 if (previousNewFiber === null) {471 resultingFirstChild = _newFiber;472 } else {473 previousNewFiber.sibling = _newFiber;474 }475 previousNewFiber = _newFiber;476 }477 return resultingFirstChild;478 }479 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);480 for (; newIdx < newChildren.length; newIdx++) {481 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], priority);482 if (_newFiber2) {483 if (shouldTrackSideEffects) {484 if (_newFiber2.alternate !== null) {485 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);486 }487 }488 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);489 if (previousNewFiber === null) {490 resultingFirstChild = _newFiber2;491 } else {492 previousNewFiber.sibling = _newFiber2;493 }494 previousNewFiber = _newFiber2;495 }496 }497 if (shouldTrackSideEffects) {498 existingChildren.forEach(function (child) {499 return deleteChild(returnFiber, child);500 });501 }502 return resultingFirstChild;503 }504 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, priority) {505 var iteratorFn = getIteratorFn(newChildrenIterable);506 invariant(typeof iteratorFn === 'function', 'An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');507 if (__DEV__) {508 if (typeof newChildrenIterable.entries === 'function') {509 var possibleMap = newChildrenIterable;510 if (possibleMap.entries === iteratorFn) {511 var mapsAsChildrenAddendum = '';512 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;513 if (owner && typeof owner.tag === 'number') {514 var mapsAsChildrenOwnerName = getComponentName(owner);515 if (mapsAsChildrenOwnerName) {516 mapsAsChildrenAddendum = '\n\nCheck the render method of `' + mapsAsChildrenOwnerName + '`.';517 }518 }519 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', mapsAsChildrenAddendum);520 didWarnAboutMaps = true;521 }522 }523 var _newChildren = iteratorFn.call(newChildrenIterable);524 if (_newChildren) {525 var knownKeys = null;526 var _step = _newChildren.next();527 for (; !_step.done; _step = _newChildren.next()) {528 var child = _step.value;529 knownKeys = warnOnDuplicateKey(child, knownKeys);530 }531 }532 }533 var newChildren = iteratorFn.call(newChildrenIterable);534 invariant(newChildren != null, 'An iterable object provided no iterator.');535 var resultingFirstChild = null;536 var previousNewFiber = null;537 var oldFiber = currentFirstChild;538 var lastPlacedIndex = 0;539 var newIdx = 0;540 var nextOldFiber = null;541 var step = newChildren.next();542 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {543 if (oldFiber.index > newIdx) {544 nextOldFiber = oldFiber;545 oldFiber = null;546 } else {547 nextOldFiber = oldFiber.sibling;548 }549 var newFiber = updateSlot(returnFiber, oldFiber, step.value, priority);550 if (newFiber === null) {551 if (!oldFiber) {552 oldFiber = nextOldFiber;553 }554 break;555 }556 if (shouldTrackSideEffects) {557 if (oldFiber && newFiber.alternate === null) {558 deleteChild(returnFiber, oldFiber);559 }560 }561 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);562 if (previousNewFiber === null) {563 resultingFirstChild = newFiber;564 } else {565 previousNewFiber.sibling = newFiber;566 }567 previousNewFiber = newFiber;568 oldFiber = nextOldFiber;569 }570 if (step.done) {571 deleteRemainingChildren(returnFiber, oldFiber);572 return resultingFirstChild;573 }574 if (oldFiber === null) {575 for (; !step.done; newIdx++, step = newChildren.next()) {576 var _newFiber3 = createChild(returnFiber, step.value, priority);577 if (_newFiber3 === null) {578 continue;579 }580 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);581 if (previousNewFiber === null) {582 resultingFirstChild = _newFiber3;583 } else {584 previousNewFiber.sibling = _newFiber3;585 }586 previousNewFiber = _newFiber3;587 }588 return resultingFirstChild;589 }590 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);591 for (; !step.done; newIdx++, step = newChildren.next()) {592 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, priority);593 if (_newFiber4 !== null) {594 if (shouldTrackSideEffects) {595 if (_newFiber4.alternate !== null) {596 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);597 }598 }599 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);600 if (previousNewFiber === null) {601 resultingFirstChild = _newFiber4;602 } else {603 previousNewFiber.sibling = _newFiber4;604 }605 previousNewFiber = _newFiber4;606 }607 }608 if (shouldTrackSideEffects) {609 existingChildren.forEach(function (child) {610 return deleteChild(returnFiber, child);611 });612 }613 return resultingFirstChild;614 }615 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, priority) {616 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {617 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);618 var existing = useFiber(currentFirstChild, priority);619 existing.pendingProps = textContent;620 existing.return = returnFiber;621 return existing;622 }623 deleteRemainingChildren(returnFiber, currentFirstChild);624 var created = createFiberFromText(textContent, priority);625 created.return = returnFiber;626 return created;627 }628 function reconcileSingleElement(returnFiber, currentFirstChild, element, priority) {629 var key = element.key;630 var child = currentFirstChild;631 while (child !== null) {632 if (child.key === key) {633 if (child.type === element.type) {634 deleteRemainingChildren(returnFiber, child.sibling);635 var existing = useFiber(child, priority);636 existing.ref = coerceRef(child, element);637 existing.pendingProps = element.props;638 existing.return = returnFiber;639 if (__DEV__) {640 existing._debugSource = element._source;641 existing._debugOwner = element._owner;642 }643 return existing;644 } else {645 deleteRemainingChildren(returnFiber, child);646 break;647 }648 } else {649 deleteChild(returnFiber, child);650 }651 child = child.sibling;652 }653 var created = createFiberFromElement(element, priority);654 created.ref = coerceRef(currentFirstChild, element);655 created.return = returnFiber;656 return created;657 }658 function reconcileSingleCoroutine(returnFiber, currentFirstChild, coroutine, priority) {659 var key = coroutine.key;660 var child = currentFirstChild;661 while (child !== null) {662 if (child.key === key) {663 if (child.tag === CoroutineComponent) {664 deleteRemainingChildren(returnFiber, child.sibling);665 var existing = useFiber(child, priority);666 existing.pendingProps = coroutine;667 existing.return = returnFiber;668 return existing;669 } else {670 deleteRemainingChildren(returnFiber, child);671 break;672 }673 } else {674 deleteChild(returnFiber, child);675 }676 child = child.sibling;677 }678 var created = createFiberFromCoroutine(coroutine, priority);679 created.return = returnFiber;680 return created;681 }682 function reconcileSingleYield(returnFiber, currentFirstChild, yieldNode, priority) {683 var child = currentFirstChild;684 if (child !== null) {685 if (child.tag === YieldComponent) {686 deleteRemainingChildren(returnFiber, child.sibling);687 var existing = useFiber(child, priority);688 existing.type = yieldNode.value;689 existing.return = returnFiber;690 return existing;691 } else {692 deleteRemainingChildren(returnFiber, child);693 }694 }695 var created = createFiberFromYield(yieldNode, priority);696 created.type = yieldNode.value;697 created.return = returnFiber;698 return created;699 }700 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, priority) {701 var key = portal.key;702 var child = currentFirstChild;703 while (child !== null) {704 if (child.key === key) {705 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {706 deleteRemainingChildren(returnFiber, child.sibling);707 var existing = useFiber(child, priority);708 existing.pendingProps = portal.children || [];709 existing.return = returnFiber;710 return existing;711 } else {712 deleteRemainingChildren(returnFiber, child);713 break;714 }715 } else {716 deleteChild(returnFiber, child);717 }718 child = child.sibling;719 }720 var created = createFiberFromPortal(portal, priority);721 created.return = returnFiber;722 return created;723 }724 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, priority) {725 var disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;726 var isObject = typeof newChild === 'object' && newChild !== null;727 if (isObject) {728 if (disableNewFiberFeatures) {729 switch (newChild.$$typeof) {730 case REACT_ELEMENT_TYPE:731 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));732 case REACT_PORTAL_TYPE:733 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));734 }735 } else {736 switch (newChild.$$typeof) {737 case REACT_ELEMENT_TYPE:738 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));739 case REACT_COROUTINE_TYPE:740 return placeSingleChild(reconcileSingleCoroutine(returnFiber, currentFirstChild, newChild, priority));741 case REACT_YIELD_TYPE:742 return placeSingleChild(reconcileSingleYield(returnFiber, currentFirstChild, newChild, priority));743 case REACT_PORTAL_TYPE:744 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));745 }746 }747 }748 if (disableNewFiberFeatures) {749 switch (returnFiber.tag) {750 case ClassComponent:751 {752 if (__DEV__) {753 var instance = returnFiber.stateNode;754 if (instance.render._isMockFunction && typeof newChild === 'undefined') {755 break;756 }757 }758 var Component = returnFiber.type;759 invariant(newChild === null || newChild === false, '%s.render(): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', Component.displayName || Component.name || 'Component');760 break;761 }762 case FunctionalComponent:763 {764 var _Component = returnFiber.type;765 invariant(newChild === null || newChild === false, '%s(...): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', _Component.displayName || _Component.name || 'Component');766 break;767 }768 }769 }770 if (typeof newChild === 'string' || typeof newChild === 'number') {771 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, priority));772 }773 if (isArray(newChild)) {774 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, priority);775 }776 if (getIteratorFn(newChild)) {777 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, priority);778 }779 if (isObject) {780 throwOnInvalidObjectType(returnFiber, newChild);781 }782 if (!disableNewFiberFeatures && typeof newChild === 'undefined') {783 switch (returnFiber.tag) {784 case ClassComponent:785 {786 if (__DEV__) {787 var _instance = returnFiber.stateNode;788 if (_instance.render._isMockFunction) {789 break;790 }791 }792 }793 case FunctionalComponent:794 {...

Full Screen

Full Screen

e63021211ff1285ea5ebde3b43f29d1ef7586aReactChildFiber.js

Source:e63021211ff1285ea5ebde3b43f29d1ef7586aReactChildFiber.js Github

copy

Full Screen

...71 }72 }73 return mixedRef;74}75function throwOnInvalidObjectType(returnFiber, newChild) {76 if (returnFiber.type !== 'textarea') {77 var addendum = '';78 if (__DEV__) {79 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.';80 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;81 if (owner && typeof owner.tag === 'number') {82 var name = getComponentName(owner);83 if (name) {84 addendum += '\n\nCheck the render method of `' + name + '`.';85 }86 }87 }88 invariant(false, 'Objects are not valid as a React child (found: %s).%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum);89 }90}91function ChildReconciler(shouldClone, shouldTrackSideEffects) {92 function deleteChild(returnFiber, childToDelete) {93 if (!shouldTrackSideEffects) {94 return;95 }96 if (!shouldClone) {97 if (childToDelete.alternate === null) {98 return;99 }100 childToDelete = childToDelete.alternate;101 }102 var last = returnFiber.progressedLastDeletion;103 if (last !== null) {104 last.nextEffect = childToDelete;105 returnFiber.progressedLastDeletion = childToDelete;106 } else {107 returnFiber.progressedFirstDeletion = returnFiber.progressedLastDeletion = childToDelete;108 }109 childToDelete.nextEffect = null;110 childToDelete.effectTag = Deletion;111 }112 function deleteRemainingChildren(returnFiber, currentFirstChild) {113 if (!shouldTrackSideEffects) {114 return null;115 }116 var childToDelete = currentFirstChild;117 while (childToDelete !== null) {118 deleteChild(returnFiber, childToDelete);119 childToDelete = childToDelete.sibling;120 }121 return null;122 }123 function mapRemainingChildren(returnFiber, currentFirstChild) {124 var existingChildren = new Map();125 var existingChild = currentFirstChild;126 while (existingChild !== null) {127 if (existingChild.key !== null) {128 existingChildren.set(existingChild.key, existingChild);129 } else {130 existingChildren.set(existingChild.index, existingChild);131 }132 existingChild = existingChild.sibling;133 }134 return existingChildren;135 }136 function useFiber(fiber, priority) {137 if (shouldClone) {138 var clone = cloneFiber(fiber, priority);139 clone.index = 0;140 clone.sibling = null;141 return clone;142 } else {143 fiber.pendingWorkPriority = priority;144 fiber.effectTag = NoEffect;145 fiber.index = 0;146 fiber.sibling = null;147 return fiber;148 }149 }150 function placeChild(newFiber, lastPlacedIndex, newIndex) {151 newFiber.index = newIndex;152 if (!shouldTrackSideEffects) {153 return lastPlacedIndex;154 }155 var current = newFiber.alternate;156 if (current !== null) {157 var oldIndex = current.index;158 if (oldIndex < lastPlacedIndex) {159 newFiber.effectTag = Placement;160 return lastPlacedIndex;161 } else {162 return oldIndex;163 }164 } else {165 newFiber.effectTag = Placement;166 return lastPlacedIndex;167 }168 }169 function placeSingleChild(newFiber) {170 if (shouldTrackSideEffects && newFiber.alternate === null) {171 newFiber.effectTag = Placement;172 }173 return newFiber;174 }175 function updateTextNode(returnFiber, current, textContent, priority) {176 if (current === null || current.tag !== HostText) {177 var created = createFiberFromText(textContent, priority);178 created.return = returnFiber;179 return created;180 } else {181 var existing = useFiber(current, priority);182 existing.pendingProps = textContent;183 existing.return = returnFiber;184 return existing;185 }186 }187 function updateElement(returnFiber, current, element, priority) {188 if (current === null || current.type !== element.type) {189 var created = createFiberFromElement(element, priority);190 created.ref = coerceRef(current, element);191 created.return = returnFiber;192 return created;193 } else {194 var existing = useFiber(current, priority);195 existing.ref = coerceRef(current, element);196 existing.pendingProps = element.props;197 existing.return = returnFiber;198 if (__DEV__) {199 existing._debugSource = element._source;200 existing._debugOwner = element._owner;201 }202 return existing;203 }204 }205 function updateCoroutine(returnFiber, current, coroutine, priority) {206 if (current === null || current.tag !== CoroutineComponent) {207 var created = createFiberFromCoroutine(coroutine, priority);208 created.return = returnFiber;209 return created;210 } else {211 var existing = useFiber(current, priority);212 existing.pendingProps = coroutine;213 existing.return = returnFiber;214 return existing;215 }216 }217 function updateYield(returnFiber, current, yieldNode, priority) {218 if (current === null || current.tag !== YieldComponent) {219 var created = createFiberFromYield(yieldNode, priority);220 created.type = yieldNode.value;221 created.return = returnFiber;222 return created;223 } else {224 var existing = useFiber(current, priority);225 existing.type = yieldNode.value;226 existing.return = returnFiber;227 return existing;228 }229 }230 function updatePortal(returnFiber, current, portal, priority) {231 if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {232 var created = createFiberFromPortal(portal, priority);233 created.return = returnFiber;234 return created;235 } else {236 var existing = useFiber(current, priority);237 existing.pendingProps = portal.children || [];238 existing.return = returnFiber;239 return existing;240 }241 }242 function updateFragment(returnFiber, current, fragment, priority) {243 if (current === null || current.tag !== Fragment) {244 var created = createFiberFromFragment(fragment, priority);245 created.return = returnFiber;246 return created;247 } else {248 var existing = useFiber(current, priority);249 existing.pendingProps = fragment;250 existing.return = returnFiber;251 return existing;252 }253 }254 function createChild(returnFiber, newChild, priority) {255 if (typeof newChild === 'string' || typeof newChild === 'number') {256 var created = createFiberFromText('' + newChild, priority);257 created.return = returnFiber;258 return created;259 }260 if (typeof newChild === 'object' && newChild !== null) {261 switch (newChild.$$typeof) {262 case REACT_ELEMENT_TYPE:263 {264 var _created = createFiberFromElement(newChild, priority);265 _created.ref = coerceRef(null, newChild);266 _created.return = returnFiber;267 return _created;268 }269 case REACT_COROUTINE_TYPE:270 {271 var _created2 = createFiberFromCoroutine(newChild, priority);272 _created2.return = returnFiber;273 return _created2;274 }275 case REACT_YIELD_TYPE:276 {277 var _created3 = createFiberFromYield(newChild, priority);278 _created3.type = newChild.value;279 _created3.return = returnFiber;280 return _created3;281 }282 case REACT_PORTAL_TYPE:283 {284 var _created4 = createFiberFromPortal(newChild, priority);285 _created4.return = returnFiber;286 return _created4;287 }288 }289 if (isArray(newChild) || getIteratorFn(newChild)) {290 var _created5 = createFiberFromFragment(newChild, priority);291 _created5.return = returnFiber;292 return _created5;293 }294 throwOnInvalidObjectType(returnFiber, newChild);295 }296 return null;297 }298 function updateSlot(returnFiber, oldFiber, newChild, priority) {299 var key = oldFiber !== null ? oldFiber.key : null;300 if (typeof newChild === 'string' || typeof newChild === 'number') {301 if (key !== null) {302 return null;303 }304 return updateTextNode(returnFiber, oldFiber, '' + newChild, priority);305 }306 if (typeof newChild === 'object' && newChild !== null) {307 switch (newChild.$$typeof) {308 case REACT_ELEMENT_TYPE:309 {310 if (newChild.key === key) {311 return updateElement(returnFiber, oldFiber, newChild, priority);312 } else {313 return null;314 }315 }316 case REACT_COROUTINE_TYPE:317 {318 if (newChild.key === key) {319 return updateCoroutine(returnFiber, oldFiber, newChild, priority);320 } else {321 return null;322 }323 }324 case REACT_YIELD_TYPE:325 {326 if (key === null) {327 return updateYield(returnFiber, oldFiber, newChild, priority);328 } else {329 return null;330 }331 }332 case REACT_PORTAL_TYPE:333 {334 if (newChild.key === key) {335 return updatePortal(returnFiber, oldFiber, newChild, priority);336 } else {337 return null;338 }339 }340 }341 if (isArray(newChild) || getIteratorFn(newChild)) {342 if (key !== null) {343 return null;344 }345 return updateFragment(returnFiber, oldFiber, newChild, priority);346 }347 throwOnInvalidObjectType(returnFiber, newChild);348 }349 return null;350 }351 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, priority) {352 if (typeof newChild === 'string' || typeof newChild === 'number') {353 var matchedFiber = existingChildren.get(newIdx) || null;354 return updateTextNode(returnFiber, matchedFiber, '' + newChild, priority);355 }356 if (typeof newChild === 'object' && newChild !== null) {357 switch (newChild.$$typeof) {358 case REACT_ELEMENT_TYPE:359 {360 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;361 return updateElement(returnFiber, _matchedFiber, newChild, priority);362 }363 case REACT_COROUTINE_TYPE:364 {365 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;366 return updateCoroutine(returnFiber, _matchedFiber2, newChild, priority);367 }368 case REACT_YIELD_TYPE:369 {370 var _matchedFiber3 = existingChildren.get(newIdx) || null;371 return updateYield(returnFiber, _matchedFiber3, newChild, priority);372 }373 case REACT_PORTAL_TYPE:374 {375 var _matchedFiber4 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;376 return updatePortal(returnFiber, _matchedFiber4, newChild, priority);377 }378 }379 if (isArray(newChild) || getIteratorFn(newChild)) {380 var _matchedFiber5 = existingChildren.get(newIdx) || null;381 return updateFragment(returnFiber, _matchedFiber5, newChild, priority);382 }383 throwOnInvalidObjectType(returnFiber, newChild);384 }385 return null;386 }387 function warnOnDuplicateKey(child, knownKeys) {388 if (__DEV__) {389 if (typeof child !== 'object' || child === null) {390 return knownKeys;391 }392 switch (child.$$typeof) {393 case REACT_ELEMENT_TYPE:394 case REACT_COROUTINE_TYPE:395 case REACT_PORTAL_TYPE:396 var key = child.key;397 if (typeof key !== 'string') {398 break;399 }400 if (knownKeys === null) {401 knownKeys = new Set();402 knownKeys.add(key);403 break;404 }405 if (!knownKeys.has(key)) {406 knownKeys.add(key);407 break;408 }409 warning(false, 'Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, ' + 'only the first child will be used.%s', key, getCurrentFiberStackAddendum());410 break;411 default:412 break;413 }414 }415 return knownKeys;416 }417 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, priority) {418 if (__DEV__) {419 var knownKeys = null;420 for (var i = 0; i < newChildren.length; i++) {421 var child = newChildren[i];422 knownKeys = warnOnDuplicateKey(child, knownKeys);423 }424 }425 var resultingFirstChild = null;426 var previousNewFiber = null;427 var oldFiber = currentFirstChild;428 var lastPlacedIndex = 0;429 var newIdx = 0;430 var nextOldFiber = null;431 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {432 if (oldFiber.index > newIdx) {433 nextOldFiber = oldFiber;434 oldFiber = null;435 } else {436 nextOldFiber = oldFiber.sibling;437 }438 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], priority);439 if (newFiber === null) {440 if (oldFiber === null) {441 oldFiber = nextOldFiber;442 }443 break;444 }445 if (shouldTrackSideEffects) {446 if (oldFiber && newFiber.alternate === null) {447 deleteChild(returnFiber, oldFiber);448 }449 }450 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);451 if (previousNewFiber === null) {452 resultingFirstChild = newFiber;453 } else {454 previousNewFiber.sibling = newFiber;455 }456 previousNewFiber = newFiber;457 oldFiber = nextOldFiber;458 }459 if (newIdx === newChildren.length) {460 deleteRemainingChildren(returnFiber, oldFiber);461 return resultingFirstChild;462 }463 if (oldFiber === null) {464 for (; newIdx < newChildren.length; newIdx++) {465 var _newFiber = createChild(returnFiber, newChildren[newIdx], priority);466 if (!_newFiber) {467 continue;468 }469 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);470 if (previousNewFiber === null) {471 resultingFirstChild = _newFiber;472 } else {473 previousNewFiber.sibling = _newFiber;474 }475 previousNewFiber = _newFiber;476 }477 return resultingFirstChild;478 }479 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);480 for (; newIdx < newChildren.length; newIdx++) {481 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], priority);482 if (_newFiber2) {483 if (shouldTrackSideEffects) {484 if (_newFiber2.alternate !== null) {485 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);486 }487 }488 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);489 if (previousNewFiber === null) {490 resultingFirstChild = _newFiber2;491 } else {492 previousNewFiber.sibling = _newFiber2;493 }494 previousNewFiber = _newFiber2;495 }496 }497 if (shouldTrackSideEffects) {498 existingChildren.forEach(function (child) {499 return deleteChild(returnFiber, child);500 });501 }502 return resultingFirstChild;503 }504 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, priority) {505 var iteratorFn = getIteratorFn(newChildrenIterable);506 invariant(typeof iteratorFn === 'function', 'An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');507 if (__DEV__) {508 if (typeof newChildrenIterable.entries === 'function') {509 var possibleMap = newChildrenIterable;510 if (possibleMap.entries === iteratorFn) {511 var mapsAsChildrenAddendum = '';512 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;513 if (owner && typeof owner.tag === 'number') {514 var mapsAsChildrenOwnerName = getComponentName(owner);515 if (mapsAsChildrenOwnerName) {516 mapsAsChildrenAddendum = '\n\nCheck the render method of `' + mapsAsChildrenOwnerName + '`.';517 }518 }519 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', mapsAsChildrenAddendum);520 didWarnAboutMaps = true;521 }522 }523 var _newChildren = iteratorFn.call(newChildrenIterable);524 if (_newChildren) {525 var knownKeys = null;526 var _step = _newChildren.next();527 for (; !_step.done; _step = _newChildren.next()) {528 var child = _step.value;529 knownKeys = warnOnDuplicateKey(child, knownKeys);530 }531 }532 }533 var newChildren = iteratorFn.call(newChildrenIterable);534 invariant(newChildren != null, 'An iterable object provided no iterator.');535 var resultingFirstChild = null;536 var previousNewFiber = null;537 var oldFiber = currentFirstChild;538 var lastPlacedIndex = 0;539 var newIdx = 0;540 var nextOldFiber = null;541 var step = newChildren.next();542 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {543 if (oldFiber.index > newIdx) {544 nextOldFiber = oldFiber;545 oldFiber = null;546 } else {547 nextOldFiber = oldFiber.sibling;548 }549 var newFiber = updateSlot(returnFiber, oldFiber, step.value, priority);550 if (newFiber === null) {551 if (!oldFiber) {552 oldFiber = nextOldFiber;553 }554 break;555 }556 if (shouldTrackSideEffects) {557 if (oldFiber && newFiber.alternate === null) {558 deleteChild(returnFiber, oldFiber);559 }560 }561 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);562 if (previousNewFiber === null) {563 resultingFirstChild = newFiber;564 } else {565 previousNewFiber.sibling = newFiber;566 }567 previousNewFiber = newFiber;568 oldFiber = nextOldFiber;569 }570 if (step.done) {571 deleteRemainingChildren(returnFiber, oldFiber);572 return resultingFirstChild;573 }574 if (oldFiber === null) {575 for (; !step.done; newIdx++, step = newChildren.next()) {576 var _newFiber3 = createChild(returnFiber, step.value, priority);577 if (_newFiber3 === null) {578 continue;579 }580 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);581 if (previousNewFiber === null) {582 resultingFirstChild = _newFiber3;583 } else {584 previousNewFiber.sibling = _newFiber3;585 }586 previousNewFiber = _newFiber3;587 }588 return resultingFirstChild;589 }590 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);591 for (; !step.done; newIdx++, step = newChildren.next()) {592 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, priority);593 if (_newFiber4 !== null) {594 if (shouldTrackSideEffects) {595 if (_newFiber4.alternate !== null) {596 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);597 }598 }599 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);600 if (previousNewFiber === null) {601 resultingFirstChild = _newFiber4;602 } else {603 previousNewFiber.sibling = _newFiber4;604 }605 previousNewFiber = _newFiber4;606 }607 }608 if (shouldTrackSideEffects) {609 existingChildren.forEach(function (child) {610 return deleteChild(returnFiber, child);611 });612 }613 return resultingFirstChild;614 }615 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, priority) {616 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {617 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);618 var existing = useFiber(currentFirstChild, priority);619 existing.pendingProps = textContent;620 existing.return = returnFiber;621 return existing;622 }623 deleteRemainingChildren(returnFiber, currentFirstChild);624 var created = createFiberFromText(textContent, priority);625 created.return = returnFiber;626 return created;627 }628 function reconcileSingleElement(returnFiber, currentFirstChild, element, priority) {629 var key = element.key;630 var child = currentFirstChild;631 while (child !== null) {632 if (child.key === key) {633 if (child.type === element.type) {634 deleteRemainingChildren(returnFiber, child.sibling);635 var existing = useFiber(child, priority);636 existing.ref = coerceRef(child, element);637 existing.pendingProps = element.props;638 existing.return = returnFiber;639 if (__DEV__) {640 existing._debugSource = element._source;641 existing._debugOwner = element._owner;642 }643 return existing;644 } else {645 deleteRemainingChildren(returnFiber, child);646 break;647 }648 } else {649 deleteChild(returnFiber, child);650 }651 child = child.sibling;652 }653 var created = createFiberFromElement(element, priority);654 created.ref = coerceRef(currentFirstChild, element);655 created.return = returnFiber;656 return created;657 }658 function reconcileSingleCoroutine(returnFiber, currentFirstChild, coroutine, priority) {659 var key = coroutine.key;660 var child = currentFirstChild;661 while (child !== null) {662 if (child.key === key) {663 if (child.tag === CoroutineComponent) {664 deleteRemainingChildren(returnFiber, child.sibling);665 var existing = useFiber(child, priority);666 existing.pendingProps = coroutine;667 existing.return = returnFiber;668 return existing;669 } else {670 deleteRemainingChildren(returnFiber, child);671 break;672 }673 } else {674 deleteChild(returnFiber, child);675 }676 child = child.sibling;677 }678 var created = createFiberFromCoroutine(coroutine, priority);679 created.return = returnFiber;680 return created;681 }682 function reconcileSingleYield(returnFiber, currentFirstChild, yieldNode, priority) {683 var child = currentFirstChild;684 if (child !== null) {685 if (child.tag === YieldComponent) {686 deleteRemainingChildren(returnFiber, child.sibling);687 var existing = useFiber(child, priority);688 existing.type = yieldNode.value;689 existing.return = returnFiber;690 return existing;691 } else {692 deleteRemainingChildren(returnFiber, child);693 }694 }695 var created = createFiberFromYield(yieldNode, priority);696 created.type = yieldNode.value;697 created.return = returnFiber;698 return created;699 }700 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, priority) {701 var key = portal.key;702 var child = currentFirstChild;703 while (child !== null) {704 if (child.key === key) {705 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {706 deleteRemainingChildren(returnFiber, child.sibling);707 var existing = useFiber(child, priority);708 existing.pendingProps = portal.children || [];709 existing.return = returnFiber;710 return existing;711 } else {712 deleteRemainingChildren(returnFiber, child);713 break;714 }715 } else {716 deleteChild(returnFiber, child);717 }718 child = child.sibling;719 }720 var created = createFiberFromPortal(portal, priority);721 created.return = returnFiber;722 return created;723 }724 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, priority) {725 var disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;726 var isObject = typeof newChild === 'object' && newChild !== null;727 if (isObject) {728 if (disableNewFiberFeatures) {729 switch (newChild.$$typeof) {730 case REACT_ELEMENT_TYPE:731 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));732 case REACT_PORTAL_TYPE:733 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));734 }735 } else {736 switch (newChild.$$typeof) {737 case REACT_ELEMENT_TYPE:738 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));739 case REACT_COROUTINE_TYPE:740 return placeSingleChild(reconcileSingleCoroutine(returnFiber, currentFirstChild, newChild, priority));741 case REACT_YIELD_TYPE:742 return placeSingleChild(reconcileSingleYield(returnFiber, currentFirstChild, newChild, priority));743 case REACT_PORTAL_TYPE:744 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));745 }746 }747 }748 if (disableNewFiberFeatures) {749 switch (returnFiber.tag) {750 case ClassComponent:751 {752 if (__DEV__) {753 var instance = returnFiber.stateNode;754 if (instance.render._isMockFunction && typeof newChild === 'undefined') {755 break;756 }757 }758 var Component = returnFiber.type;759 invariant(newChild === null || newChild === false, '%s.render(): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', Component.displayName || Component.name || 'Component');760 break;761 }762 case FunctionalComponent:763 {764 var _Component = returnFiber.type;765 invariant(newChild === null || newChild === false, '%s(...): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', _Component.displayName || _Component.name || 'Component');766 break;767 }768 }769 }770 if (typeof newChild === 'string' || typeof newChild === 'number') {771 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, priority));772 }773 if (isArray(newChild)) {774 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, priority);775 }776 if (getIteratorFn(newChild)) {777 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, priority);778 }779 if (isObject) {780 throwOnInvalidObjectType(returnFiber, newChild);781 }782 if (!disableNewFiberFeatures && typeof newChild === 'undefined') {783 switch (returnFiber.tag) {784 case ClassComponent:785 {786 if (__DEV__) {787 var _instance = returnFiber.stateNode;788 if (_instance.render._isMockFunction) {789 break;790 }791 }792 }793 case FunctionalComponent:794 {...

Full Screen

Full Screen

2777a7e15608de56c000ecbbdfa33c57bd5a43ReactChildFiber.js

Source:2777a7e15608de56c000ecbbdfa33c57bd5a43ReactChildFiber.js Github

copy

Full Screen

...71 }72 }73 return mixedRef;74}75function throwOnInvalidObjectType(returnFiber, newChild) {76 if (returnFiber.type !== 'textarea') {77 var addendum = '';78 if (__DEV__) {79 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.';80 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;81 if (owner && typeof owner.tag === 'number') {82 var name = getComponentName(owner);83 if (name) {84 addendum += '\n\nCheck the render method of `' + name + '`.';85 }86 }87 }88 invariant(false, 'Objects are not valid as a React child (found: %s).%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum);89 }90}91function ChildReconciler(shouldClone, shouldTrackSideEffects) {92 function deleteChild(returnFiber, childToDelete) {93 if (!shouldTrackSideEffects) {94 return;95 }96 if (!shouldClone) {97 if (childToDelete.alternate === null) {98 return;99 }100 childToDelete = childToDelete.alternate;101 }102 var last = returnFiber.progressedLastDeletion;103 if (last !== null) {104 last.nextEffect = childToDelete;105 returnFiber.progressedLastDeletion = childToDelete;106 } else {107 returnFiber.progressedFirstDeletion = returnFiber.progressedLastDeletion = childToDelete;108 }109 childToDelete.nextEffect = null;110 childToDelete.effectTag = Deletion;111 }112 function deleteRemainingChildren(returnFiber, currentFirstChild) {113 if (!shouldTrackSideEffects) {114 return null;115 }116 var childToDelete = currentFirstChild;117 while (childToDelete !== null) {118 deleteChild(returnFiber, childToDelete);119 childToDelete = childToDelete.sibling;120 }121 return null;122 }123 function mapRemainingChildren(returnFiber, currentFirstChild) {124 var existingChildren = new Map();125 var existingChild = currentFirstChild;126 while (existingChild !== null) {127 if (existingChild.key !== null) {128 existingChildren.set(existingChild.key, existingChild);129 } else {130 existingChildren.set(existingChild.index, existingChild);131 }132 existingChild = existingChild.sibling;133 }134 return existingChildren;135 }136 function useFiber(fiber, priority) {137 if (shouldClone) {138 var clone = cloneFiber(fiber, priority);139 clone.index = 0;140 clone.sibling = null;141 return clone;142 } else {143 fiber.pendingWorkPriority = priority;144 fiber.effectTag = NoEffect;145 fiber.index = 0;146 fiber.sibling = null;147 return fiber;148 }149 }150 function placeChild(newFiber, lastPlacedIndex, newIndex) {151 newFiber.index = newIndex;152 if (!shouldTrackSideEffects) {153 return lastPlacedIndex;154 }155 var current = newFiber.alternate;156 if (current !== null) {157 var oldIndex = current.index;158 if (oldIndex < lastPlacedIndex) {159 newFiber.effectTag = Placement;160 return lastPlacedIndex;161 } else {162 return oldIndex;163 }164 } else {165 newFiber.effectTag = Placement;166 return lastPlacedIndex;167 }168 }169 function placeSingleChild(newFiber) {170 if (shouldTrackSideEffects && newFiber.alternate === null) {171 newFiber.effectTag = Placement;172 }173 return newFiber;174 }175 function updateTextNode(returnFiber, current, textContent, priority) {176 if (current === null || current.tag !== HostText) {177 var created = createFiberFromText(textContent, priority);178 created.return = returnFiber;179 return created;180 } else {181 var existing = useFiber(current, priority);182 existing.pendingProps = textContent;183 existing.return = returnFiber;184 return existing;185 }186 }187 function updateElement(returnFiber, current, element, priority) {188 if (current === null || current.type !== element.type) {189 var created = createFiberFromElement(element, priority);190 created.ref = coerceRef(current, element);191 created.return = returnFiber;192 return created;193 } else {194 var existing = useFiber(current, priority);195 existing.ref = coerceRef(current, element);196 existing.pendingProps = element.props;197 existing.return = returnFiber;198 if (__DEV__) {199 existing._debugSource = element._source;200 existing._debugOwner = element._owner;201 }202 return existing;203 }204 }205 function updateCoroutine(returnFiber, current, coroutine, priority) {206 if (current === null || current.tag !== CoroutineComponent) {207 var created = createFiberFromCoroutine(coroutine, priority);208 created.return = returnFiber;209 return created;210 } else {211 var existing = useFiber(current, priority);212 existing.pendingProps = coroutine;213 existing.return = returnFiber;214 return existing;215 }216 }217 function updateYield(returnFiber, current, yieldNode, priority) {218 if (current === null || current.tag !== YieldComponent) {219 var created = createFiberFromYield(yieldNode, priority);220 created.type = yieldNode.value;221 created.return = returnFiber;222 return created;223 } else {224 var existing = useFiber(current, priority);225 existing.type = yieldNode.value;226 existing.return = returnFiber;227 return existing;228 }229 }230 function updatePortal(returnFiber, current, portal, priority) {231 if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {232 var created = createFiberFromPortal(portal, priority);233 created.return = returnFiber;234 return created;235 } else {236 var existing = useFiber(current, priority);237 existing.pendingProps = portal.children || [];238 existing.return = returnFiber;239 return existing;240 }241 }242 function updateFragment(returnFiber, current, fragment, priority) {243 if (current === null || current.tag !== Fragment) {244 var created = createFiberFromFragment(fragment, priority);245 created.return = returnFiber;246 return created;247 } else {248 var existing = useFiber(current, priority);249 existing.pendingProps = fragment;250 existing.return = returnFiber;251 return existing;252 }253 }254 function createChild(returnFiber, newChild, priority) {255 if (typeof newChild === 'string' || typeof newChild === 'number') {256 var created = createFiberFromText('' + newChild, priority);257 created.return = returnFiber;258 return created;259 }260 if (typeof newChild === 'object' && newChild !== null) {261 switch (newChild.$$typeof) {262 case REACT_ELEMENT_TYPE:263 {264 var _created = createFiberFromElement(newChild, priority);265 _created.ref = coerceRef(null, newChild);266 _created.return = returnFiber;267 return _created;268 }269 case REACT_COROUTINE_TYPE:270 {271 var _created2 = createFiberFromCoroutine(newChild, priority);272 _created2.return = returnFiber;273 return _created2;274 }275 case REACT_YIELD_TYPE:276 {277 var _created3 = createFiberFromYield(newChild, priority);278 _created3.type = newChild.value;279 _created3.return = returnFiber;280 return _created3;281 }282 case REACT_PORTAL_TYPE:283 {284 var _created4 = createFiberFromPortal(newChild, priority);285 _created4.return = returnFiber;286 return _created4;287 }288 }289 if (isArray(newChild) || getIteratorFn(newChild)) {290 var _created5 = createFiberFromFragment(newChild, priority);291 _created5.return = returnFiber;292 return _created5;293 }294 throwOnInvalidObjectType(returnFiber, newChild);295 }296 return null;297 }298 function updateSlot(returnFiber, oldFiber, newChild, priority) {299 var key = oldFiber !== null ? oldFiber.key : null;300 if (typeof newChild === 'string' || typeof newChild === 'number') {301 if (key !== null) {302 return null;303 }304 return updateTextNode(returnFiber, oldFiber, '' + newChild, priority);305 }306 if (typeof newChild === 'object' && newChild !== null) {307 switch (newChild.$$typeof) {308 case REACT_ELEMENT_TYPE:309 {310 if (newChild.key === key) {311 return updateElement(returnFiber, oldFiber, newChild, priority);312 } else {313 return null;314 }315 }316 case REACT_COROUTINE_TYPE:317 {318 if (newChild.key === key) {319 return updateCoroutine(returnFiber, oldFiber, newChild, priority);320 } else {321 return null;322 }323 }324 case REACT_YIELD_TYPE:325 {326 if (key === null) {327 return updateYield(returnFiber, oldFiber, newChild, priority);328 } else {329 return null;330 }331 }332 case REACT_PORTAL_TYPE:333 {334 if (newChild.key === key) {335 return updatePortal(returnFiber, oldFiber, newChild, priority);336 } else {337 return null;338 }339 }340 }341 if (isArray(newChild) || getIteratorFn(newChild)) {342 if (key !== null) {343 return null;344 }345 return updateFragment(returnFiber, oldFiber, newChild, priority);346 }347 throwOnInvalidObjectType(returnFiber, newChild);348 }349 return null;350 }351 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, priority) {352 if (typeof newChild === 'string' || typeof newChild === 'number') {353 var matchedFiber = existingChildren.get(newIdx) || null;354 return updateTextNode(returnFiber, matchedFiber, '' + newChild, priority);355 }356 if (typeof newChild === 'object' && newChild !== null) {357 switch (newChild.$$typeof) {358 case REACT_ELEMENT_TYPE:359 {360 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;361 return updateElement(returnFiber, _matchedFiber, newChild, priority);362 }363 case REACT_COROUTINE_TYPE:364 {365 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;366 return updateCoroutine(returnFiber, _matchedFiber2, newChild, priority);367 }368 case REACT_YIELD_TYPE:369 {370 var _matchedFiber3 = existingChildren.get(newIdx) || null;371 return updateYield(returnFiber, _matchedFiber3, newChild, priority);372 }373 case REACT_PORTAL_TYPE:374 {375 var _matchedFiber4 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;376 return updatePortal(returnFiber, _matchedFiber4, newChild, priority);377 }378 }379 if (isArray(newChild) || getIteratorFn(newChild)) {380 var _matchedFiber5 = existingChildren.get(newIdx) || null;381 return updateFragment(returnFiber, _matchedFiber5, newChild, priority);382 }383 throwOnInvalidObjectType(returnFiber, newChild);384 }385 return null;386 }387 function warnOnDuplicateKey(child, knownKeys) {388 if (__DEV__) {389 if (typeof child !== 'object' || child === null) {390 return knownKeys;391 }392 switch (child.$$typeof) {393 case REACT_ELEMENT_TYPE:394 case REACT_COROUTINE_TYPE:395 case REACT_PORTAL_TYPE:396 var key = child.key;397 if (typeof key !== 'string') {398 break;399 }400 if (knownKeys === null) {401 knownKeys = new Set();402 knownKeys.add(key);403 break;404 }405 if (!knownKeys.has(key)) {406 knownKeys.add(key);407 break;408 }409 warning(false, 'Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, ' + 'only the first child will be used.%s', key, getCurrentFiberStackAddendum());410 break;411 default:412 break;413 }414 }415 return knownKeys;416 }417 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, priority) {418 if (__DEV__) {419 var knownKeys = null;420 for (var i = 0; i < newChildren.length; i++) {421 var child = newChildren[i];422 knownKeys = warnOnDuplicateKey(child, knownKeys);423 }424 }425 var resultingFirstChild = null;426 var previousNewFiber = null;427 var oldFiber = currentFirstChild;428 var lastPlacedIndex = 0;429 var newIdx = 0;430 var nextOldFiber = null;431 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {432 if (oldFiber.index > newIdx) {433 nextOldFiber = oldFiber;434 oldFiber = null;435 } else {436 nextOldFiber = oldFiber.sibling;437 }438 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], priority);439 if (newFiber === null) {440 if (oldFiber === null) {441 oldFiber = nextOldFiber;442 }443 break;444 }445 if (shouldTrackSideEffects) {446 if (oldFiber && newFiber.alternate === null) {447 deleteChild(returnFiber, oldFiber);448 }449 }450 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);451 if (previousNewFiber === null) {452 resultingFirstChild = newFiber;453 } else {454 previousNewFiber.sibling = newFiber;455 }456 previousNewFiber = newFiber;457 oldFiber = nextOldFiber;458 }459 if (newIdx === newChildren.length) {460 deleteRemainingChildren(returnFiber, oldFiber);461 return resultingFirstChild;462 }463 if (oldFiber === null) {464 for (; newIdx < newChildren.length; newIdx++) {465 var _newFiber = createChild(returnFiber, newChildren[newIdx], priority);466 if (!_newFiber) {467 continue;468 }469 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);470 if (previousNewFiber === null) {471 resultingFirstChild = _newFiber;472 } else {473 previousNewFiber.sibling = _newFiber;474 }475 previousNewFiber = _newFiber;476 }477 return resultingFirstChild;478 }479 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);480 for (; newIdx < newChildren.length; newIdx++) {481 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], priority);482 if (_newFiber2) {483 if (shouldTrackSideEffects) {484 if (_newFiber2.alternate !== null) {485 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);486 }487 }488 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);489 if (previousNewFiber === null) {490 resultingFirstChild = _newFiber2;491 } else {492 previousNewFiber.sibling = _newFiber2;493 }494 previousNewFiber = _newFiber2;495 }496 }497 if (shouldTrackSideEffects) {498 existingChildren.forEach(function (child) {499 return deleteChild(returnFiber, child);500 });501 }502 return resultingFirstChild;503 }504 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, priority) {505 var iteratorFn = getIteratorFn(newChildrenIterable);506 invariant(typeof iteratorFn === 'function', 'An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');507 if (__DEV__) {508 if (typeof newChildrenIterable.entries === 'function') {509 var possibleMap = newChildrenIterable;510 if (possibleMap.entries === iteratorFn) {511 var mapsAsChildrenAddendum = '';512 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;513 if (owner && typeof owner.tag === 'number') {514 var mapsAsChildrenOwnerName = getComponentName(owner);515 if (mapsAsChildrenOwnerName) {516 mapsAsChildrenAddendum = '\n\nCheck the render method of `' + mapsAsChildrenOwnerName + '`.';517 }518 }519 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', mapsAsChildrenAddendum);520 didWarnAboutMaps = true;521 }522 }523 var _newChildren = iteratorFn.call(newChildrenIterable);524 if (_newChildren) {525 var knownKeys = null;526 var _step = _newChildren.next();527 for (; !_step.done; _step = _newChildren.next()) {528 var child = _step.value;529 knownKeys = warnOnDuplicateKey(child, knownKeys);530 }531 }532 }533 var newChildren = iteratorFn.call(newChildrenIterable);534 invariant(newChildren != null, 'An iterable object provided no iterator.');535 var resultingFirstChild = null;536 var previousNewFiber = null;537 var oldFiber = currentFirstChild;538 var lastPlacedIndex = 0;539 var newIdx = 0;540 var nextOldFiber = null;541 var step = newChildren.next();542 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {543 if (oldFiber.index > newIdx) {544 nextOldFiber = oldFiber;545 oldFiber = null;546 } else {547 nextOldFiber = oldFiber.sibling;548 }549 var newFiber = updateSlot(returnFiber, oldFiber, step.value, priority);550 if (newFiber === null) {551 if (!oldFiber) {552 oldFiber = nextOldFiber;553 }554 break;555 }556 if (shouldTrackSideEffects) {557 if (oldFiber && newFiber.alternate === null) {558 deleteChild(returnFiber, oldFiber);559 }560 }561 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);562 if (previousNewFiber === null) {563 resultingFirstChild = newFiber;564 } else {565 previousNewFiber.sibling = newFiber;566 }567 previousNewFiber = newFiber;568 oldFiber = nextOldFiber;569 }570 if (step.done) {571 deleteRemainingChildren(returnFiber, oldFiber);572 return resultingFirstChild;573 }574 if (oldFiber === null) {575 for (; !step.done; newIdx++, step = newChildren.next()) {576 var _newFiber3 = createChild(returnFiber, step.value, priority);577 if (_newFiber3 === null) {578 continue;579 }580 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);581 if (previousNewFiber === null) {582 resultingFirstChild = _newFiber3;583 } else {584 previousNewFiber.sibling = _newFiber3;585 }586 previousNewFiber = _newFiber3;587 }588 return resultingFirstChild;589 }590 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);591 for (; !step.done; newIdx++, step = newChildren.next()) {592 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, priority);593 if (_newFiber4 !== null) {594 if (shouldTrackSideEffects) {595 if (_newFiber4.alternate !== null) {596 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);597 }598 }599 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);600 if (previousNewFiber === null) {601 resultingFirstChild = _newFiber4;602 } else {603 previousNewFiber.sibling = _newFiber4;604 }605 previousNewFiber = _newFiber4;606 }607 }608 if (shouldTrackSideEffects) {609 existingChildren.forEach(function (child) {610 return deleteChild(returnFiber, child);611 });612 }613 return resultingFirstChild;614 }615 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, priority) {616 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {617 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);618 var existing = useFiber(currentFirstChild, priority);619 existing.pendingProps = textContent;620 existing.return = returnFiber;621 return existing;622 }623 deleteRemainingChildren(returnFiber, currentFirstChild);624 var created = createFiberFromText(textContent, priority);625 created.return = returnFiber;626 return created;627 }628 function reconcileSingleElement(returnFiber, currentFirstChild, element, priority) {629 var key = element.key;630 var child = currentFirstChild;631 while (child !== null) {632 if (child.key === key) {633 if (child.type === element.type) {634 deleteRemainingChildren(returnFiber, child.sibling);635 var existing = useFiber(child, priority);636 existing.ref = coerceRef(child, element);637 existing.pendingProps = element.props;638 existing.return = returnFiber;639 if (__DEV__) {640 existing._debugSource = element._source;641 existing._debugOwner = element._owner;642 }643 return existing;644 } else {645 deleteRemainingChildren(returnFiber, child);646 break;647 }648 } else {649 deleteChild(returnFiber, child);650 }651 child = child.sibling;652 }653 var created = createFiberFromElement(element, priority);654 created.ref = coerceRef(currentFirstChild, element);655 created.return = returnFiber;656 return created;657 }658 function reconcileSingleCoroutine(returnFiber, currentFirstChild, coroutine, priority) {659 var key = coroutine.key;660 var child = currentFirstChild;661 while (child !== null) {662 if (child.key === key) {663 if (child.tag === CoroutineComponent) {664 deleteRemainingChildren(returnFiber, child.sibling);665 var existing = useFiber(child, priority);666 existing.pendingProps = coroutine;667 existing.return = returnFiber;668 return existing;669 } else {670 deleteRemainingChildren(returnFiber, child);671 break;672 }673 } else {674 deleteChild(returnFiber, child);675 }676 child = child.sibling;677 }678 var created = createFiberFromCoroutine(coroutine, priority);679 created.return = returnFiber;680 return created;681 }682 function reconcileSingleYield(returnFiber, currentFirstChild, yieldNode, priority) {683 var child = currentFirstChild;684 if (child !== null) {685 if (child.tag === YieldComponent) {686 deleteRemainingChildren(returnFiber, child.sibling);687 var existing = useFiber(child, priority);688 existing.type = yieldNode.value;689 existing.return = returnFiber;690 return existing;691 } else {692 deleteRemainingChildren(returnFiber, child);693 }694 }695 var created = createFiberFromYield(yieldNode, priority);696 created.type = yieldNode.value;697 created.return = returnFiber;698 return created;699 }700 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, priority) {701 var key = portal.key;702 var child = currentFirstChild;703 while (child !== null) {704 if (child.key === key) {705 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {706 deleteRemainingChildren(returnFiber, child.sibling);707 var existing = useFiber(child, priority);708 existing.pendingProps = portal.children || [];709 existing.return = returnFiber;710 return existing;711 } else {712 deleteRemainingChildren(returnFiber, child);713 break;714 }715 } else {716 deleteChild(returnFiber, child);717 }718 child = child.sibling;719 }720 var created = createFiberFromPortal(portal, priority);721 created.return = returnFiber;722 return created;723 }724 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, priority) {725 var disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;726 var isObject = typeof newChild === 'object' && newChild !== null;727 if (isObject) {728 if (disableNewFiberFeatures) {729 switch (newChild.$$typeof) {730 case REACT_ELEMENT_TYPE:731 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));732 case REACT_PORTAL_TYPE:733 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));734 }735 } else {736 switch (newChild.$$typeof) {737 case REACT_ELEMENT_TYPE:738 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));739 case REACT_COROUTINE_TYPE:740 return placeSingleChild(reconcileSingleCoroutine(returnFiber, currentFirstChild, newChild, priority));741 case REACT_YIELD_TYPE:742 return placeSingleChild(reconcileSingleYield(returnFiber, currentFirstChild, newChild, priority));743 case REACT_PORTAL_TYPE:744 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));745 }746 }747 }748 if (disableNewFiberFeatures) {749 switch (returnFiber.tag) {750 case ClassComponent:751 {752 if (__DEV__) {753 var instance = returnFiber.stateNode;754 if (instance.render._isMockFunction && typeof newChild === 'undefined') {755 break;756 }757 }758 var Component = returnFiber.type;759 invariant(newChild === null || newChild === false, '%s.render(): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', Component.displayName || Component.name || 'Component');760 break;761 }762 case FunctionalComponent:763 {764 var _Component = returnFiber.type;765 invariant(newChild === null || newChild === false, '%s(...): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', _Component.displayName || _Component.name || 'Component');766 break;767 }768 }769 }770 if (typeof newChild === 'string' || typeof newChild === 'number') {771 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, priority));772 }773 if (isArray(newChild)) {774 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, priority);775 }776 if (getIteratorFn(newChild)) {777 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, priority);778 }779 if (isObject) {780 throwOnInvalidObjectType(returnFiber, newChild);781 }782 if (!disableNewFiberFeatures && typeof newChild === 'undefined') {783 switch (returnFiber.tag) {784 case ClassComponent:785 {786 if (__DEV__) {787 var _instance = returnFiber.stateNode;788 if (_instance.render._isMockFunction) {789 break;790 }791 }792 }793 case FunctionalComponent:794 {...

Full Screen

Full Screen

72ad6676c5f8c20c2282779de202a472dade38ReactChildFiber.js

Source:72ad6676c5f8c20c2282779de202a472dade38ReactChildFiber.js Github

copy

Full Screen

...71 }72 }73 return mixedRef;74}75function throwOnInvalidObjectType(returnFiber, newChild) {76 if (returnFiber.type !== 'textarea') {77 var addendum = '';78 if (__DEV__) {79 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.';80 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;81 if (owner && typeof owner.tag === 'number') {82 var name = getComponentName(owner);83 if (name) {84 addendum += '\n\nCheck the render method of `' + name + '`.';85 }86 }87 }88 invariant(false, 'Objects are not valid as a React child (found: %s).%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum);89 }90}91function ChildReconciler(shouldClone, shouldTrackSideEffects) {92 function deleteChild(returnFiber, childToDelete) {93 if (!shouldTrackSideEffects) {94 return;95 }96 if (!shouldClone) {97 if (childToDelete.alternate === null) {98 return;99 }100 childToDelete = childToDelete.alternate;101 }102 var last = returnFiber.progressedLastDeletion;103 if (last !== null) {104 last.nextEffect = childToDelete;105 returnFiber.progressedLastDeletion = childToDelete;106 } else {107 returnFiber.progressedFirstDeletion = returnFiber.progressedLastDeletion = childToDelete;108 }109 childToDelete.nextEffect = null;110 childToDelete.effectTag = Deletion;111 }112 function deleteRemainingChildren(returnFiber, currentFirstChild) {113 if (!shouldTrackSideEffects) {114 return null;115 }116 var childToDelete = currentFirstChild;117 while (childToDelete !== null) {118 deleteChild(returnFiber, childToDelete);119 childToDelete = childToDelete.sibling;120 }121 return null;122 }123 function mapRemainingChildren(returnFiber, currentFirstChild) {124 var existingChildren = new Map();125 var existingChild = currentFirstChild;126 while (existingChild !== null) {127 if (existingChild.key !== null) {128 existingChildren.set(existingChild.key, existingChild);129 } else {130 existingChildren.set(existingChild.index, existingChild);131 }132 existingChild = existingChild.sibling;133 }134 return existingChildren;135 }136 function useFiber(fiber, priority) {137 if (shouldClone) {138 var clone = cloneFiber(fiber, priority);139 clone.index = 0;140 clone.sibling = null;141 return clone;142 } else {143 fiber.pendingWorkPriority = priority;144 fiber.effectTag = NoEffect;145 fiber.index = 0;146 fiber.sibling = null;147 return fiber;148 }149 }150 function placeChild(newFiber, lastPlacedIndex, newIndex) {151 newFiber.index = newIndex;152 if (!shouldTrackSideEffects) {153 return lastPlacedIndex;154 }155 var current = newFiber.alternate;156 if (current !== null) {157 var oldIndex = current.index;158 if (oldIndex < lastPlacedIndex) {159 newFiber.effectTag = Placement;160 return lastPlacedIndex;161 } else {162 return oldIndex;163 }164 } else {165 newFiber.effectTag = Placement;166 return lastPlacedIndex;167 }168 }169 function placeSingleChild(newFiber) {170 if (shouldTrackSideEffects && newFiber.alternate === null) {171 newFiber.effectTag = Placement;172 }173 return newFiber;174 }175 function updateTextNode(returnFiber, current, textContent, priority) {176 if (current === null || current.tag !== HostText) {177 var created = createFiberFromText(textContent, priority);178 created.return = returnFiber;179 return created;180 } else {181 var existing = useFiber(current, priority);182 existing.pendingProps = textContent;183 existing.return = returnFiber;184 return existing;185 }186 }187 function updateElement(returnFiber, current, element, priority) {188 if (current === null || current.type !== element.type) {189 var created = createFiberFromElement(element, priority);190 created.ref = coerceRef(current, element);191 created.return = returnFiber;192 return created;193 } else {194 var existing = useFiber(current, priority);195 existing.ref = coerceRef(current, element);196 existing.pendingProps = element.props;197 existing.return = returnFiber;198 if (__DEV__) {199 existing._debugSource = element._source;200 existing._debugOwner = element._owner;201 }202 return existing;203 }204 }205 function updateCoroutine(returnFiber, current, coroutine, priority) {206 if (current === null || current.tag !== CoroutineComponent) {207 var created = createFiberFromCoroutine(coroutine, priority);208 created.return = returnFiber;209 return created;210 } else {211 var existing = useFiber(current, priority);212 existing.pendingProps = coroutine;213 existing.return = returnFiber;214 return existing;215 }216 }217 function updateYield(returnFiber, current, yieldNode, priority) {218 if (current === null || current.tag !== YieldComponent) {219 var created = createFiberFromYield(yieldNode, priority);220 created.type = yieldNode.value;221 created.return = returnFiber;222 return created;223 } else {224 var existing = useFiber(current, priority);225 existing.type = yieldNode.value;226 existing.return = returnFiber;227 return existing;228 }229 }230 function updatePortal(returnFiber, current, portal, priority) {231 if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {232 var created = createFiberFromPortal(portal, priority);233 created.return = returnFiber;234 return created;235 } else {236 var existing = useFiber(current, priority);237 existing.pendingProps = portal.children || [];238 existing.return = returnFiber;239 return existing;240 }241 }242 function updateFragment(returnFiber, current, fragment, priority) {243 if (current === null || current.tag !== Fragment) {244 var created = createFiberFromFragment(fragment, priority);245 created.return = returnFiber;246 return created;247 } else {248 var existing = useFiber(current, priority);249 existing.pendingProps = fragment;250 existing.return = returnFiber;251 return existing;252 }253 }254 function createChild(returnFiber, newChild, priority) {255 if (typeof newChild === 'string' || typeof newChild === 'number') {256 var created = createFiberFromText('' + newChild, priority);257 created.return = returnFiber;258 return created;259 }260 if (typeof newChild === 'object' && newChild !== null) {261 switch (newChild.$$typeof) {262 case REACT_ELEMENT_TYPE:263 {264 var _created = createFiberFromElement(newChild, priority);265 _created.ref = coerceRef(null, newChild);266 _created.return = returnFiber;267 return _created;268 }269 case REACT_COROUTINE_TYPE:270 {271 var _created2 = createFiberFromCoroutine(newChild, priority);272 _created2.return = returnFiber;273 return _created2;274 }275 case REACT_YIELD_TYPE:276 {277 var _created3 = createFiberFromYield(newChild, priority);278 _created3.type = newChild.value;279 _created3.return = returnFiber;280 return _created3;281 }282 case REACT_PORTAL_TYPE:283 {284 var _created4 = createFiberFromPortal(newChild, priority);285 _created4.return = returnFiber;286 return _created4;287 }288 }289 if (isArray(newChild) || getIteratorFn(newChild)) {290 var _created5 = createFiberFromFragment(newChild, priority);291 _created5.return = returnFiber;292 return _created5;293 }294 throwOnInvalidObjectType(returnFiber, newChild);295 }296 return null;297 }298 function updateSlot(returnFiber, oldFiber, newChild, priority) {299 var key = oldFiber !== null ? oldFiber.key : null;300 if (typeof newChild === 'string' || typeof newChild === 'number') {301 if (key !== null) {302 return null;303 }304 return updateTextNode(returnFiber, oldFiber, '' + newChild, priority);305 }306 if (typeof newChild === 'object' && newChild !== null) {307 switch (newChild.$$typeof) {308 case REACT_ELEMENT_TYPE:309 {310 if (newChild.key === key) {311 return updateElement(returnFiber, oldFiber, newChild, priority);312 } else {313 return null;314 }315 }316 case REACT_COROUTINE_TYPE:317 {318 if (newChild.key === key) {319 return updateCoroutine(returnFiber, oldFiber, newChild, priority);320 } else {321 return null;322 }323 }324 case REACT_YIELD_TYPE:325 {326 if (key === null) {327 return updateYield(returnFiber, oldFiber, newChild, priority);328 } else {329 return null;330 }331 }332 case REACT_PORTAL_TYPE:333 {334 if (newChild.key === key) {335 return updatePortal(returnFiber, oldFiber, newChild, priority);336 } else {337 return null;338 }339 }340 }341 if (isArray(newChild) || getIteratorFn(newChild)) {342 if (key !== null) {343 return null;344 }345 return updateFragment(returnFiber, oldFiber, newChild, priority);346 }347 throwOnInvalidObjectType(returnFiber, newChild);348 }349 return null;350 }351 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, priority) {352 if (typeof newChild === 'string' || typeof newChild === 'number') {353 var matchedFiber = existingChildren.get(newIdx) || null;354 return updateTextNode(returnFiber, matchedFiber, '' + newChild, priority);355 }356 if (typeof newChild === 'object' && newChild !== null) {357 switch (newChild.$$typeof) {358 case REACT_ELEMENT_TYPE:359 {360 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;361 return updateElement(returnFiber, _matchedFiber, newChild, priority);362 }363 case REACT_COROUTINE_TYPE:364 {365 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;366 return updateCoroutine(returnFiber, _matchedFiber2, newChild, priority);367 }368 case REACT_YIELD_TYPE:369 {370 var _matchedFiber3 = existingChildren.get(newIdx) || null;371 return updateYield(returnFiber, _matchedFiber3, newChild, priority);372 }373 case REACT_PORTAL_TYPE:374 {375 var _matchedFiber4 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;376 return updatePortal(returnFiber, _matchedFiber4, newChild, priority);377 }378 }379 if (isArray(newChild) || getIteratorFn(newChild)) {380 var _matchedFiber5 = existingChildren.get(newIdx) || null;381 return updateFragment(returnFiber, _matchedFiber5, newChild, priority);382 }383 throwOnInvalidObjectType(returnFiber, newChild);384 }385 return null;386 }387 function warnOnDuplicateKey(child, knownKeys) {388 if (__DEV__) {389 if (typeof child !== 'object' || child === null) {390 return knownKeys;391 }392 switch (child.$$typeof) {393 case REACT_ELEMENT_TYPE:394 case REACT_COROUTINE_TYPE:395 case REACT_PORTAL_TYPE:396 var key = child.key;397 if (typeof key !== 'string') {398 break;399 }400 if (knownKeys === null) {401 knownKeys = new Set();402 knownKeys.add(key);403 break;404 }405 if (!knownKeys.has(key)) {406 knownKeys.add(key);407 break;408 }409 warning(false, 'Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, ' + 'only the first child will be used.%s', key, getCurrentFiberStackAddendum());410 break;411 default:412 break;413 }414 }415 return knownKeys;416 }417 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, priority) {418 if (__DEV__) {419 var knownKeys = null;420 for (var i = 0; i < newChildren.length; i++) {421 var child = newChildren[i];422 knownKeys = warnOnDuplicateKey(child, knownKeys);423 }424 }425 var resultingFirstChild = null;426 var previousNewFiber = null;427 var oldFiber = currentFirstChild;428 var lastPlacedIndex = 0;429 var newIdx = 0;430 var nextOldFiber = null;431 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {432 if (oldFiber.index > newIdx) {433 nextOldFiber = oldFiber;434 oldFiber = null;435 } else {436 nextOldFiber = oldFiber.sibling;437 }438 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], priority);439 if (newFiber === null) {440 if (oldFiber === null) {441 oldFiber = nextOldFiber;442 }443 break;444 }445 if (shouldTrackSideEffects) {446 if (oldFiber && newFiber.alternate === null) {447 deleteChild(returnFiber, oldFiber);448 }449 }450 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);451 if (previousNewFiber === null) {452 resultingFirstChild = newFiber;453 } else {454 previousNewFiber.sibling = newFiber;455 }456 previousNewFiber = newFiber;457 oldFiber = nextOldFiber;458 }459 if (newIdx === newChildren.length) {460 deleteRemainingChildren(returnFiber, oldFiber);461 return resultingFirstChild;462 }463 if (oldFiber === null) {464 for (; newIdx < newChildren.length; newIdx++) {465 var _newFiber = createChild(returnFiber, newChildren[newIdx], priority);466 if (!_newFiber) {467 continue;468 }469 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);470 if (previousNewFiber === null) {471 resultingFirstChild = _newFiber;472 } else {473 previousNewFiber.sibling = _newFiber;474 }475 previousNewFiber = _newFiber;476 }477 return resultingFirstChild;478 }479 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);480 for (; newIdx < newChildren.length; newIdx++) {481 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], priority);482 if (_newFiber2) {483 if (shouldTrackSideEffects) {484 if (_newFiber2.alternate !== null) {485 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);486 }487 }488 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);489 if (previousNewFiber === null) {490 resultingFirstChild = _newFiber2;491 } else {492 previousNewFiber.sibling = _newFiber2;493 }494 previousNewFiber = _newFiber2;495 }496 }497 if (shouldTrackSideEffects) {498 existingChildren.forEach(function (child) {499 return deleteChild(returnFiber, child);500 });501 }502 return resultingFirstChild;503 }504 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, priority) {505 var iteratorFn = getIteratorFn(newChildrenIterable);506 invariant(typeof iteratorFn === 'function', 'An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');507 if (__DEV__) {508 if (typeof newChildrenIterable.entries === 'function') {509 var possibleMap = newChildrenIterable;510 if (possibleMap.entries === iteratorFn) {511 var mapsAsChildrenAddendum = '';512 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;513 if (owner && typeof owner.tag === 'number') {514 var mapsAsChildrenOwnerName = getComponentName(owner);515 if (mapsAsChildrenOwnerName) {516 mapsAsChildrenAddendum = '\n\nCheck the render method of `' + mapsAsChildrenOwnerName + '`.';517 }518 }519 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', mapsAsChildrenAddendum);520 didWarnAboutMaps = true;521 }522 }523 var _newChildren = iteratorFn.call(newChildrenIterable);524 if (_newChildren) {525 var knownKeys = null;526 var _step = _newChildren.next();527 for (; !_step.done; _step = _newChildren.next()) {528 var child = _step.value;529 knownKeys = warnOnDuplicateKey(child, knownKeys);530 }531 }532 }533 var newChildren = iteratorFn.call(newChildrenIterable);534 invariant(newChildren != null, 'An iterable object provided no iterator.');535 var resultingFirstChild = null;536 var previousNewFiber = null;537 var oldFiber = currentFirstChild;538 var lastPlacedIndex = 0;539 var newIdx = 0;540 var nextOldFiber = null;541 var step = newChildren.next();542 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {543 if (oldFiber.index > newIdx) {544 nextOldFiber = oldFiber;545 oldFiber = null;546 } else {547 nextOldFiber = oldFiber.sibling;548 }549 var newFiber = updateSlot(returnFiber, oldFiber, step.value, priority);550 if (newFiber === null) {551 if (!oldFiber) {552 oldFiber = nextOldFiber;553 }554 break;555 }556 if (shouldTrackSideEffects) {557 if (oldFiber && newFiber.alternate === null) {558 deleteChild(returnFiber, oldFiber);559 }560 }561 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);562 if (previousNewFiber === null) {563 resultingFirstChild = newFiber;564 } else {565 previousNewFiber.sibling = newFiber;566 }567 previousNewFiber = newFiber;568 oldFiber = nextOldFiber;569 }570 if (step.done) {571 deleteRemainingChildren(returnFiber, oldFiber);572 return resultingFirstChild;573 }574 if (oldFiber === null) {575 for (; !step.done; newIdx++, step = newChildren.next()) {576 var _newFiber3 = createChild(returnFiber, step.value, priority);577 if (_newFiber3 === null) {578 continue;579 }580 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);581 if (previousNewFiber === null) {582 resultingFirstChild = _newFiber3;583 } else {584 previousNewFiber.sibling = _newFiber3;585 }586 previousNewFiber = _newFiber3;587 }588 return resultingFirstChild;589 }590 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);591 for (; !step.done; newIdx++, step = newChildren.next()) {592 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, priority);593 if (_newFiber4 !== null) {594 if (shouldTrackSideEffects) {595 if (_newFiber4.alternate !== null) {596 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);597 }598 }599 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);600 if (previousNewFiber === null) {601 resultingFirstChild = _newFiber4;602 } else {603 previousNewFiber.sibling = _newFiber4;604 }605 previousNewFiber = _newFiber4;606 }607 }608 if (shouldTrackSideEffects) {609 existingChildren.forEach(function (child) {610 return deleteChild(returnFiber, child);611 });612 }613 return resultingFirstChild;614 }615 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, priority) {616 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {617 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);618 var existing = useFiber(currentFirstChild, priority);619 existing.pendingProps = textContent;620 existing.return = returnFiber;621 return existing;622 }623 deleteRemainingChildren(returnFiber, currentFirstChild);624 var created = createFiberFromText(textContent, priority);625 created.return = returnFiber;626 return created;627 }628 function reconcileSingleElement(returnFiber, currentFirstChild, element, priority) {629 var key = element.key;630 var child = currentFirstChild;631 while (child !== null) {632 if (child.key === key) {633 if (child.type === element.type) {634 deleteRemainingChildren(returnFiber, child.sibling);635 var existing = useFiber(child, priority);636 existing.ref = coerceRef(child, element);637 existing.pendingProps = element.props;638 existing.return = returnFiber;639 if (__DEV__) {640 existing._debugSource = element._source;641 existing._debugOwner = element._owner;642 }643 return existing;644 } else {645 deleteRemainingChildren(returnFiber, child);646 break;647 }648 } else {649 deleteChild(returnFiber, child);650 }651 child = child.sibling;652 }653 var created = createFiberFromElement(element, priority);654 created.ref = coerceRef(currentFirstChild, element);655 created.return = returnFiber;656 return created;657 }658 function reconcileSingleCoroutine(returnFiber, currentFirstChild, coroutine, priority) {659 var key = coroutine.key;660 var child = currentFirstChild;661 while (child !== null) {662 if (child.key === key) {663 if (child.tag === CoroutineComponent) {664 deleteRemainingChildren(returnFiber, child.sibling);665 var existing = useFiber(child, priority);666 existing.pendingProps = coroutine;667 existing.return = returnFiber;668 return existing;669 } else {670 deleteRemainingChildren(returnFiber, child);671 break;672 }673 } else {674 deleteChild(returnFiber, child);675 }676 child = child.sibling;677 }678 var created = createFiberFromCoroutine(coroutine, priority);679 created.return = returnFiber;680 return created;681 }682 function reconcileSingleYield(returnFiber, currentFirstChild, yieldNode, priority) {683 var child = currentFirstChild;684 if (child !== null) {685 if (child.tag === YieldComponent) {686 deleteRemainingChildren(returnFiber, child.sibling);687 var existing = useFiber(child, priority);688 existing.type = yieldNode.value;689 existing.return = returnFiber;690 return existing;691 } else {692 deleteRemainingChildren(returnFiber, child);693 }694 }695 var created = createFiberFromYield(yieldNode, priority);696 created.type = yieldNode.value;697 created.return = returnFiber;698 return created;699 }700 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, priority) {701 var key = portal.key;702 var child = currentFirstChild;703 while (child !== null) {704 if (child.key === key) {705 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {706 deleteRemainingChildren(returnFiber, child.sibling);707 var existing = useFiber(child, priority);708 existing.pendingProps = portal.children || [];709 existing.return = returnFiber;710 return existing;711 } else {712 deleteRemainingChildren(returnFiber, child);713 break;714 }715 } else {716 deleteChild(returnFiber, child);717 }718 child = child.sibling;719 }720 var created = createFiberFromPortal(portal, priority);721 created.return = returnFiber;722 return created;723 }724 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, priority) {725 var disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;726 var isObject = typeof newChild === 'object' && newChild !== null;727 if (isObject) {728 if (disableNewFiberFeatures) {729 switch (newChild.$$typeof) {730 case REACT_ELEMENT_TYPE:731 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));732 case REACT_PORTAL_TYPE:733 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));734 }735 } else {736 switch (newChild.$$typeof) {737 case REACT_ELEMENT_TYPE:738 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, priority));739 case REACT_COROUTINE_TYPE:740 return placeSingleChild(reconcileSingleCoroutine(returnFiber, currentFirstChild, newChild, priority));741 case REACT_YIELD_TYPE:742 return placeSingleChild(reconcileSingleYield(returnFiber, currentFirstChild, newChild, priority));743 case REACT_PORTAL_TYPE:744 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, priority));745 }746 }747 }748 if (disableNewFiberFeatures) {749 switch (returnFiber.tag) {750 case ClassComponent:751 {752 if (__DEV__) {753 var instance = returnFiber.stateNode;754 if (instance.render._isMockFunction && typeof newChild === 'undefined') {755 break;756 }757 }758 var Component = returnFiber.type;759 invariant(newChild === null || newChild === false, '%s.render(): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', Component.displayName || Component.name || 'Component');760 break;761 }762 case FunctionalComponent:763 {764 var _Component = returnFiber.type;765 invariant(newChild === null || newChild === false, '%s(...): A valid React element (or null) must be returned. ' + 'You may have returned undefined, an array or some other ' + 'invalid object.', _Component.displayName || _Component.name || 'Component');766 break;767 }768 }769 }770 if (typeof newChild === 'string' || typeof newChild === 'number') {771 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, priority));772 }773 if (isArray(newChild)) {774 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, priority);775 }776 if (getIteratorFn(newChild)) {777 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, priority);778 }779 if (isObject) {780 throwOnInvalidObjectType(returnFiber, newChild);781 }782 if (!disableNewFiberFeatures && typeof newChild === 'undefined') {783 switch (returnFiber.tag) {784 case ClassComponent:785 {786 if (__DEV__) {787 var _instance = returnFiber.stateNode;788 if (_instance.render._isMockFunction) {789 break;790 }791 }792 }793 case FunctionalComponent:794 {...

Full Screen

Full Screen

reconcileChildren.js

Source:reconcileChildren.js Github

copy

Full Screen

...70 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);71 }7273 if (isObject) {74 throwOnInvalidObjectType(returnFiber, newChild);75 }7677 {78 if (typeof newChild === 'function') {79 warnOnFunctionType();80 }81 }82 if (typeof newChild === 'undefined') {83 // If the new child is undefined, and the return fiber is a composite84 // component, throw an error. If Fiber return types are disabled,85 // we already threw above.86 switch (returnFiber.tag) {87 case ClassComponent:88 {89 {90 var instance = returnFiber.stateNode;91 if (instance.render._isMockFunction) {92 // We allow auto-mocks to proceed as if they're returning null.93 break;94 }95 }96 }97 // Intentionally fall through to the next case, which handles both98 // functions and classes99 // eslint-disable-next-lined no-fallthrough100 case FunctionalComponent:101 {102 var Component = returnFiber.type;103 invariant(false, '%s(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.', Component.displayName || Component.name || 'Component');104 }105 }106 }107108 // Remaining cases are all treated as empty.109 return deleteRemainingChildren(returnFiber, currentFirstChild);110}111112// 调和单个 react element113function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {114 var key = element.key;115 var child = currentFirstChild;116117 // 更新118 while (child !== null) {119 // TODO: If key === null and child.key === null, then this only applies to120 // the first item in the list.121 if (child.key === key) {122 if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.type === element.type) {123124 // key 相同 type 相同,清除workInProgress除当前fiber子节点外的所有子节点125 deleteRemainingChildren(returnFiber, child.sibling);126127 // 创建一个当前child的workInProgress128 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);129 existing.ref = coerceRef(returnFiber, child, element);130 existing['return'] = returnFiber;131 {132 existing._debugSource = element._source;133 existing._debugOwner = element._owner;134 }135 return existing;136 } else {137 // key相同,type不同,清除所有子节点138 deleteRemainingChildren(returnFiber, child);139 break;140 }141 } else {142 // 如果key不相同,直接从当前的workInProgress清除当前fiber子节点,继续处理下一个子节点143 deleteChild(returnFiber, child);144 }145 child = child.sibling;146 }147148 if (element.type === REACT_FRAGMENT_TYPE) {149 // fragment150 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);151 created['return'] = returnFiber;152 return created;153 } else {154155 // 创建子级 fiber ../Fiber.js156 // 根据子组件类型创建fiber157 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);158 // ref相关暂时忽略159 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);160 // 关联父级 fiber,模拟函数栈调用,子级函数执行完成,调用栈返回父级161 _created4['return'] = returnFiber;162 return _created4;163 }164}165166167168// 调和多个子级fiber的更新,看的头昏脑涨才看明白的算法169// 首次插入的时候,直接生成子节点,添加fiber.index 不解释170// 更新的时候171// 从第一个子节点开始处理,跟新的childList列表中的第一个元素比较,如果key匹配,更新,开始处理第二个节点,依次类推,一旦不匹配,跳出循环,从当前节点开始向后,全部添加到Map当中,遍历map和剩余的childList,存在既更新,不存在既新建,childList遍历完成之后,如果map当中还存在子节点,添加到删除列表172function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {173 // This algorithm can't optimize by searching from boths ends since we174 // don't have backpointers on fibers. I'm trying to see how far we can get175 // with that model. If it ends up not being worth the tradeoffs, we can176 // add it later.177178 // Even with a two ended optimization, we'd want to optimize for the case179 // where there are few changes and brute force the comparison instead of180 // going for the Map. It'd like to explore hitting that path first in181 // forward-only mode and only go for the Map once we notice that we need182 // lots of look ahead. This doesn't handle reversal as well as two ended183 // search but that's unusual. Besides, for the two ended optimization to184 // work on Iterables, we'd need to copy the whole set.185186 // In this first iteration, we'll just live with hitting the bad case187 // (adding everything to a Map) in for every insert/move.188189 // If you change this code, also update reconcileChildrenIterator() which190 // uses the same algorithm.191192 {193 // First, validate keys.194 var knownKeys = null;195 for (var i = 0; i < newChildren.length; i++) {196 var child = newChildren[i];197 knownKeys = warnOnInvalidKey(child, knownKeys);198 }199 }200 201 var resultingFirstChild = null;202 var previousNewFiber = null;203204 var oldFiber = currentFirstChild;205 var lastPlacedIndex = 0;206 var newIdx = 0;207 var nextOldFiber = null;208209 // 首次渲染的时候 oldFiber为null,否则为 returnFiber的第一个子节点210 // 所有fiber新建的时候 index 都是 0,只有在 reconcileChildrenArray 或 reconcileChildrenIterator之后,index才有可能更改211 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {212 // 如果oldFiber和newFiber index 相同或较小,说明是同一个位置,相互比较,否则跳出循环213 if (oldFiber.index > newIdx) {214 nextOldFiber = oldFiber;215 oldFiber = null;216 } else {217 nextOldFiber = oldFiber.sibling;218 }219 // 220 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);221 if (newFiber === null) {222 // TODO: This breaks on empty slots like null children. That's223 // unfortunate because it triggers the slow path all the time. We need224 // a better way to communicate whether this was a miss or null,225 // boolean, undefined, etc.226 if (oldFiber === null) {227 oldFiber = nextOldFiber;228 }229 break;230 }231 // 232 if (shouldTrackSideEffects) {233 if (oldFiber && newFiber.alternate === null) {234 // We matched the slot, but we didn't reuse the existing fiber, so we235 // need to delete the existing child.236 deleteChild(returnFiber, oldFiber);237 }238 }239 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);240 if (previousNewFiber === null) {241 // TODO: Move out of the loop. This only happens for the first run.242 resultingFirstChild = newFiber;243 } else {244 // TODO: Defer siblings if we're not at the right index for this slot.245 // I.e. if we had null values before, then we want to defer this246 // for each null value. However, we also don't want to call updateSlot247 // with the previous one.248 previousNewFiber.sibling = newFiber;249 }250 previousNewFiber = newFiber;251 oldFiber = nextOldFiber;252 }253254 if (newIdx === newChildren.length) {255 // We've reached the end of the new children. We can delete the rest.256 // 已经处理到新的子节点末尾,将oldFiber及后面的兄弟节点清除257 deleteRemainingChildren(returnFiber, oldFiber);258 return resultingFirstChild;259 }260261 // 没有子节点,或者oldFiber原先的兄弟子节点全部更新完成,从当前的newIndx开始,将剩余的newChild全部插入,并按照当前的插入顺序赋值 fiber.index262 if (oldFiber === null) {263 // If we don't have any more existing children we can choose a fast path264 // since the rest will all be insertions.265266 // 267 for (; newIdx < newChildren.length; newIdx++) {268 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);269 if (!_newFiber) {270 continue;271 }272 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);273 if (previousNewFiber === null) {274 // TODO: Move out of the loop. This only happens for the first run.275 resultingFirstChild = _newFiber;276 } else {277 previousNewFiber.sibling = _newFiber;278 }279 previousNewFiber = _newFiber;280 }281 return resultingFirstChild;282 }283284 // Add all children to a key map for quick lookups.285 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);286287 // Keep scanning and use the map to restore deleted items as moves.288 for (; newIdx < newChildren.length; newIdx++) {289 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);290 if (_newFiber2) {291 if (shouldTrackSideEffects) {292 if (_newFiber2.alternate !== null) {293 // The new fiber is a work in progress, but if there exists a294 // current, that means that we reused the fiber. We need to delete295 // it from the child list so that we don't add it to the deletion296 // list.297 existingChildren['delete'](_newFiber2.key === null ? newIdx : _newFiber2.key);298 }299 }300 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);301 if (previousNewFiber === null) {302 resultingFirstChild = _newFiber2;303 } else {304 previousNewFiber.sibling = _newFiber2;305 }306 previousNewFiber = _newFiber2;307 }308 }309310 if (shouldTrackSideEffects) {311 // Any existing children that weren't consumed above were deleted. We need312 // to add them to the deletion list.313 existingChildren.forEach(function (child) {314 return deleteChild(returnFiber, child);315 });316 }317318 return resultingFirstChild;319}320321// 从map中更新newChild322function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {323 if (typeof newChild === 'string' || typeof newChild === 'number') {324 // Text nodes don't have keys, so we neither have to check the old nor325 // new node for the key. If both are text nodes, they match.326 var matchedFiber = existingChildren.get(newIdx) || null;327 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);328 }329330 if (typeof newChild === 'object' && newChild !== null) {331 switch (newChild.$$typeof) {332 case REACT_ELEMENT_TYPE:333 {334 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;335 if (newChild.type === REACT_FRAGMENT_TYPE) {336 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);337 }338 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);339 }340 case REACT_PORTAL_TYPE:341 {342 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;343 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);344 }345 }346347 if (isArray$1(newChild) || getIteratorFn(newChild)) {348 var _matchedFiber3 = existingChildren.get(newIdx) || null;349 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);350 }351352 throwOnInvalidObjectType(returnFiber, newChild);353 }354355 {356 if (typeof newChild === 'function') {357 warnOnFunctionType();358 }359 }360361 return null;362 }363364365 // 删除fiber调和366 function deleteChild(returnFiber, childToDelete) {367 if (!shouldTrackSideEffects) {368 // Noop.369 return;370 }371 // Deletions are added in reversed order so we add it to the front.372 // At this point, the return fiber's effect list is empty except for373 // deletions, so we can just append the deletion to the list. The remaining374 // effects aren't added until the complete phase. Once we implement375 // resuming, this may not be true.376377 // 把当前的fiber添加到returnFiber的副作用链末尾,由于在当前调度器工作时间节点,returnFiber的副作用链尾空,在调和结束阶段,即提交的前一步,才会把剩余的副作用添加,因此,删除操作最终会在returnFiber的副作用链首部378 var last = returnFiber.lastEffect;379 if (last !== null) {380 last.nextEffect = childToDelete;381 returnFiber.lastEffect = childToDelete;382 } else {383 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;384 }385 childToDelete.nextEffect = null;386 childToDelete.effectTag = Deletion;387 }388389//创建fiber子节点390function createChild(returnFiber, newChild, expirationTime) {391 if (typeof newChild === 'string' || typeof newChild === 'number') {392 // Text nodes don't have keys. If the previous node is implicitly keyed393 // we can continue to replace it without aborting even if it is not a text394 // node.395 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);396 created['return'] = returnFiber;397 return created;398 }399400 if (typeof newChild === 'object' && newChild !== null) {401 switch (newChild.$$typeof) {402 case REACT_ELEMENT_TYPE:403 {404 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);405 _created.ref = coerceRef(returnFiber, null, newChild);406 _created['return'] = returnFiber;407 return _created;408 }409 case REACT_PORTAL_TYPE:410 {411 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);412 _created2['return'] = returnFiber;413 return _created2;414 }415 }416417 if (isArray$1(newChild) || getIteratorFn(newChild)) {418 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);419 _created3['return'] = returnFiber;420 return _created3;421 }422423 throwOnInvalidObjectType(returnFiber, newChild);424 }425426 {427 if (typeof newChild === 'function') {428 warnOnFunctionType();429 }430 }431432 return null;433}434435// 处理子fiber的index(正确位置)436function placeChild(newFiber, lastPlacedIndex, newIndex) {437 // 赋值 fiber.index438 newFiber.index = newIndex;439 if (!shouldTrackSideEffects) {440 // 直接插入,不需要任何多余的操作441 // Noop.442 return lastPlacedIndex;443 }444445 // 在placeChild方法内,fiber的创建或者更新属性都已经完成,所以446 var current = newFiber.alternate;447448 if (current !== null) {449 // 更新 current是稳定的fiber450451 var oldIndex = current.index;452 if (oldIndex < lastPlacedIndex) {453 // This is a move.454 // 需要向前移动,添加占位副作用455 newFiber.effectTag = Placement;456 return lastPlacedIndex;457 } else {458 // 原来位置靠后,不用处理459 // This item can stay in place.460 return oldIndex;461 }462 } else {463 // This is an insertion.464 // 插入 465 newFiber.effectTag = Placement;466 return lastPlacedIndex;467 }468}469470function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {471 // Update the fiber if the keys match, otherwise return null.472473 // 如果key匹配,更新,其他情况不做处理474475 var key = oldFiber !== null ? oldFiber.key : null;476477 if (typeof newChild === 'string' || typeof newChild === 'number') {478 // Text nodes don't have keys. If the previous node is implicitly keyed479 // we can continue to replace it without aborting even if it is not a text480 // node.481482 // oldFilber 存在key ,并且 newChild 是文本,直接返回,不做处理483 if (key !== null) {484 return null;485 }486 // oldFilber 没有key ,并且 newChild 是文本, 更新oldFiber487 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);488 }489490 if (typeof newChild === 'object' && newChild !== null) {491 switch (newChild.$$typeof) {492 // react element493 case REACT_ELEMENT_TYPE:494 {495 // key 相同,更新496 if (newChild.key === key) {497 if (newChild.type === REACT_FRAGMENT_TYPE) {498 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);499 }500 return updateElement(returnFiber, oldFiber, newChild, expirationTime);501 } else {502 // 否则503 return null;504 }505 }506 case REACT_PORTAL_TYPE:507 {508 if (newChild.key === key) {509 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);510 } else {511 return null;512 }513 }514 }515516 // 数组子节点517 if (isArray$1(newChild) || getIteratorFn(newChild)) {518 if (key !== null) {519 return null;520 }521522 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);523 }524525 throwOnInvalidObjectType(returnFiber, newChild);526 }527528 {529 if (typeof newChild === 'function') {530 warnOnFunctionType();531 }532 }533534 return null;535}536537// 更新fiber538function updateElement(returnFiber, current, element, expirationTime) {539 if (current !== null && current.type === element.type) { ...

Full Screen

Full Screen

error.jsx

Source:error.jsx Github

copy

Full Screen

1// modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:17008 Uncaught Error: Objects are not valid as a React child (found: object with keys {title, url}). If you meant to render a collection of children, use an array instead.2// in li (created by Task)3// in Task (created by Info)4// in ul (created by Info)5// in div (created by Info)6// in Info (created by App)7// in div (created by App)8// in App9// at throwOnInvalidObjectType (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:17008)10// at createChild (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:17246)11// at reconcileChildrenArray (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:17495)12// at reconcileChildFibers (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:17900)13// at reconcileChildren (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:20357)14// at updateHostComponent (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:20897)15// at beginWork (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:22222)16// at HTMLUnknownElement.callCallback (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:3783)17// at Object.invokeGuardedCallbackDev (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:3832)18// at invokeGuardedCallback (modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:3887)19// throwOnInvalidObjectType @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1700820// createChild @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1724621// reconcileChildrenArray @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1749522// reconcileChildFibers @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1790023// reconcileChildren @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2035724// updateHostComponent @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2089725// beginWork @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2222226// callCallback @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:378327// invokeGuardedCallbackDev @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:383228// invokeGuardedCallback @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:388729// beginWork$1 @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2679830// performUnitOfWork @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2574931// workLoopSync @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2572532// performSyncWorkOnRoot @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2535133// (anonymous) @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1468434// unstable_runWithPriority @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2933735// runWithPriority$1 @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1463436// flushSyncCallbackQueueImpl @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1467937// flushSyncCallbackQueue @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1466738// scheduleUpdateOnFiber @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:2479439// dispatchAction @ modules.js?hash=7274f2fab27ca6dd1243876db6df82b8b23ca03f:1925540// (anonymous) @ useTracker.ts:7341// _compute @ tracker.js:30842// _recompute @ tracker.js:32443// Tracker._runFlush @ tracker.js:49544// onGlobalMessage @ meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:51545// postMessage (async)46// setImmediate @ meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:53547// requireFlush @ tracker.js:12948// invalidate @ tracker.js:26449// changed @ tracker.js:42250// (anonymous) @ cursor.js:29351// SQp.runTask @ meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:84952// SQp.flush @ meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:87853// SQp.drain @ meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:88754// resumeObservers @ local_collection.js:30655// endUpdate @ collection.js:23956// store.<computed> @ livedata_connection.js:31257// (anonymous) @ livedata_connection.js:120658// _performWrites @ livedata_connection.js:120559// _flushBufferedWrites @ livedata_connection.js:116260// (anonymous) @ meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:123461// setTimeout (async)62// _livedata_data @ livedata_connection.js:114363// onMessage @ livedata_connection.js:165564// (anonymous) @ browser.js:18665// forEachCallback @ common.js:3066// socket.onmessage @ browser.js:18567// REventTarget.dispatchEvent @ sockjs-0.3.4.js:8768// SockJS._dispatchMessage @ sockjs-0.3.4.js:107869// SockJS._didMessage @ sockjs-0.3.4.js:113870// that.ws.onmessage @ sockjs-0.3.4.js:128571// 5react_devtools_backend.js:2560 The above error occurred in the <li> component:72// in li (created by Task)73// in Task (created by Info)74// in ul (created by Info)75// in div (created by Info)76// in Info (created by App)77// in div (created by App)78// in App79// Consider adding an error boundary to your tree to customize error handling behavior....

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium, webkit, firefox } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('text=Get started');7 await browser.close();8})();9import { PlaywrightTestConfig, devices } from '@playwright/test';10const config: PlaywrightTestConfig = {11 use: {12 viewport: { width: 1280, height: 720 },13 },14 {15 use: {16 },17 },18 {19 use: {20 },21 },22 {23 use: {24 },25 },26};27export default config;28const { devices } = require('@playwright/test');29const config = {30 use: {31 viewport: { width: 1280, height: 720 },32 },33 {34 use: {35 },36 },37 {38 use: {39 },40 },41 {42 use: {43 },44 },45};46module.exports = config;47const { devices } = require('@playwright/test');48const config = {49 use: {50 viewport: { width: 1280, height: 720 },51 },52 {53 use: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');2const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');3const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');4const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');5const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');6const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');7const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');8const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');9const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');10const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');11const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');12const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');13const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');14const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');15const { throwOnInvalidObjectType } = require('playwright/lib/utils/stackTrace');16const {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { throwOnInvalidObjectType } = require('playwright/lib/server/objects');2throwOnInvalidObjectType('Page', page);3throwOnInvalidObjectType('Frame', frame);4throwOnInvalidObjectType('ElementHandle', elementHandle);5const { throwOnInvalidPage } = require('playwright/lib/server/objects');6throwOnInvalidPage(page);7const { throwOnInvalidFrame } = require('playwright/lib/server/objects');8throwOnInvalidFrame(frame);9const { throwOnInvalidElementHandle } = require('playwright/lib/server/objects');10throwOnInvalidElementHandle(elementHandle);11const { throwOnInvalidRequest } = require('playwright/lib/server/objects');12throwOnInvalidRequest(request);13const { throwOnInvalidResponse } = require('playwright/lib/server/objects');14throwOnInvalidResponse(response);15const { throwOnInvalidRoute } = require('playwright/lib/server/objects');16throwOnInvalidRoute(route);17const { throwOnInvalidJSHandle } = require('playwright/lib/server/objects');18throwOnInvalidJSHandle(jsHandle);19const { throwOnInvalidWorker } = require('playwright/lib/server/objects');20throwOnInvalidWorker(worker);21const { throwOnInvalidBinding } = require('playwright/lib/server/objects');22throwOnInvalidBinding(binding);23const { throwOnInvalidTimeout } = require('playwright/lib/server/objects');24throwOnInvalidTimeout(timeout);25const { throwOnInvalidState } = require('playwright/lib/server/objects');26throwOnInvalidState(state);27const { throwOnInvalidBrowserType } =

Full Screen

Using AI Code Generation

copy

Full Screen

1const { throwOnInvalidObjectType } = require('playwright/lib/helper');2const { assert } = require('chai');3describe('test', function() {4 it('test', async function() {5 assert.throws(() => {6 throwOnInvalidObjectType('test', 'test', 'object', 'string');7 }, 'test: expected object, but got string');8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { throwOnInvalidObjectType } = require('playwright/lib/internal/stackTrace.js');2throwOnInvalidObjectType('string', 'string', 'string');3throwOnInvalidObjectType('string', 'string', 'string', 'string');4const { throwOnInvalidValue } = require('playwright/lib/internal/stackTrace.js');5throwOnInvalidValue('string', 'string', 'string');6throwOnInvalidValue('string', 'string', 'string', 'string');7const { validateBrowserContextOptions } = require('playwright/lib/internal/stackTrace.js');8validateBrowserContextOptions('string');9validateBrowserContextOptions('string', 'string');10const { validateBrowserOptions } = require('playwright/lib/internal/stackTrace.js');11validateBrowserOptions('string');12validateBrowserOptions('string', 'string');13const { validateBrowserTypeOptions } = require('playwright/lib/internal/stackTrace.js');14validateBrowserTypeOptions('string');15validateBrowserTypeOptions('string', 'string');16const { validateBrowserTypeLaunchOptions } = require('playwright/lib/internal/stackTrace.js');17validateBrowserTypeLaunchOptions('string');18validateBrowserTypeLaunchOptions('string', 'string');19const { validateContextOptions } = require('playwright/lib/internal/stackTrace.js');20validateContextOptions('string');21validateContextOptions('string', 'string');22const { validateDeviceDescriptors } = require('playwright/lib/internal/stackTrace.js');23validateDeviceDescriptors('string');24const { validateLogOptions } = require('playwright/lib/internal/stackTrace.js');25validateLogOptions('string');26validateLogOptions('string', 'string');27const { validateProxySettings } = require('playwright/lib/internal/stackTrace.js');28validateProxySettings('string');29validateProxySettings('string', 'string');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { throwOnInvalidObjectType } = require("@playwright/test/lib/utils/utils");2throwOnInvalidObjectType('test', 'test', 'test');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.close();9 await context.close();10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 await page.close();18 await context.close();19 await browser.close();20})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful