code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function tryToClaimNextHydratableInstance(fiber) {
if (!isHydrating) {
return;
}
var nextInstance = nextHydratableInstance;
if (!nextInstance) {
if (shouldClientRenderOnMismatch(fiber)) {
warnNonhydratedInstance(hydrationParentFiber, fiber);
throwOnHydrationMismatch();
} // Nothing to hydrate. Make it an insertion.
insertNonHydratedInstance(hydrationParentFiber, fiber);
isHydrating = false;
hydrationParentFiber = fiber;
return;
}
var firstAttemptedInstance = nextInstance;
if (!tryHydrate(fiber, nextInstance)) {
if (shouldClientRenderOnMismatch(fiber)) {
warnNonhydratedInstance(hydrationParentFiber, fiber);
throwOnHydrationMismatch();
} // If we can't hydrate this instance let's try the next one.
// We use this as a heuristic. It's based on intuition and not data so it
// might be flawed or unnecessary.
nextInstance = getNextHydratableSibling(firstAttemptedInstance);
var prevHydrationParentFiber = hydrationParentFiber;
if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
// Nothing to hydrate. Make it an insertion.
insertNonHydratedInstance(hydrationParentFiber, fiber);
isHydrating = false;
hydrationParentFiber = fiber;
return;
} // We matched the next one, we'll now assume that the first one was
// superfluous and we'll delete it. Since we can't eagerly delete it
// we'll have to schedule a deletion. To do that, this node needs a dummy
// fiber associated with it.
deleteHydratableInstance(prevHydrationParentFiber, firstAttemptedInstance);
}
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
tryToClaimNextHydratableInstance
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
var instance = fiber.stateNode;
var shouldWarnIfMismatchDev = !didSuspendOrErrorDEV;
var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber, shouldWarnIfMismatchDev); // TODO: Type this specific to this type of component.
fiber.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
// is a new ref we mark this as an update.
if (updatePayload !== null) {
return true;
}
return false;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
prepareToHydrateHostInstance
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function prepareToHydrateHostTextInstance(fiber) {
var textInstance = fiber.stateNode;
var textContent = fiber.memoizedProps;
var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
if (shouldUpdate) {
// We assume that prepareToHydrateHostTextInstance is called in a context where the
// hydration parent is the parent host component of this host text.
var returnFiber = hydrationParentFiber;
if (returnFiber !== null) {
switch (returnFiber.tag) {
case HostRoot:
{
var parentContainer = returnFiber.stateNode.containerInfo;
var isConcurrentMode = (returnFiber.mode & ConcurrentMode) !== NoMode;
didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent, // TODO: Delete this argument when we remove the legacy root API.
isConcurrentMode);
break;
}
case HostComponent:
{
var parentType = returnFiber.type;
var parentProps = returnFiber.memoizedProps;
var parentInstance = returnFiber.stateNode;
var _isConcurrentMode2 = (returnFiber.mode & ConcurrentMode) !== NoMode;
didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent, // TODO: Delete this argument when we remove the legacy root API.
_isConcurrentMode2);
break;
}
}
}
}
return shouldUpdate;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
prepareToHydrateHostTextInstance
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function prepareToHydrateHostSuspenseInstance(fiber) {
var suspenseState = fiber.memoizedState;
var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
if (!suspenseInstance) {
throw new Error('Expected to have a hydrated suspense instance. ' + 'This error is likely caused by a bug in React. Please file an issue.');
}
hydrateSuspenseInstance(suspenseInstance, fiber);
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
prepareToHydrateHostSuspenseInstance
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function skipPastDehydratedSuspenseInstance(fiber) {
var suspenseState = fiber.memoizedState;
var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
if (!suspenseInstance) {
throw new Error('Expected to have a hydrated suspense instance. ' + 'This error is likely caused by a bug in React. Please file an issue.');
}
return getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
skipPastDehydratedSuspenseInstance
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function popToNextHostParent(fiber) {
var parent = fiber.return;
while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== SuspenseComponent) {
parent = parent.return;
}
hydrationParentFiber = parent;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
popToNextHostParent
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function popHydrationState(fiber) {
if (fiber !== hydrationParentFiber) {
// We're deeper than the current hydration context, inside an inserted
// tree.
return false;
}
if (!isHydrating) {
// If we're not currently hydrating but we're in a hydration context, then
// we were an insertion and now need to pop up reenter hydration of our
// siblings.
popToNextHostParent(fiber);
isHydrating = true;
return false;
} // If we have any remaining hydratable nodes, we need to delete them now.
// We only do this deeper than head and body since they tend to have random
// other nodes in them. We also ignore components with pure text content in
// side of them. We also don't delete anything inside the root container.
if (fiber.tag !== HostRoot && (fiber.tag !== HostComponent || shouldDeleteUnhydratedTailInstances(fiber.type) && !shouldSetTextContent(fiber.type, fiber.memoizedProps))) {
var nextInstance = nextHydratableInstance;
if (nextInstance) {
if (shouldClientRenderOnMismatch(fiber)) {
warnIfUnhydratedTailNodes(fiber);
throwOnHydrationMismatch();
} else {
while (nextInstance) {
deleteHydratableInstance(fiber, nextInstance);
nextInstance = getNextHydratableSibling(nextInstance);
}
}
}
}
popToNextHostParent(fiber);
if (fiber.tag === SuspenseComponent) {
nextHydratableInstance = skipPastDehydratedSuspenseInstance(fiber);
} else {
nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
}
return true;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
popHydrationState
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function hasUnhydratedTailNodes() {
return isHydrating && nextHydratableInstance !== null;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
hasUnhydratedTailNodes
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function warnIfUnhydratedTailNodes(fiber) {
var nextInstance = nextHydratableInstance;
while (nextInstance) {
warnUnhydratedInstance(fiber, nextInstance);
nextInstance = getNextHydratableSibling(nextInstance);
}
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
warnIfUnhydratedTailNodes
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function resetHydrationState() {
hydrationParentFiber = null;
nextHydratableInstance = null;
isHydrating = false;
didSuspendOrErrorDEV = false;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
resetHydrationState
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function upgradeHydrationErrorsToRecoverable() {
if (hydrationErrors !== null) {
// Successfully completed a forced client render. The errors that occurred
// during the hydration attempt are now recovered. We will log them in
// commit phase, once the entire tree has finished.
queueRecoverableErrors(hydrationErrors);
hydrationErrors = null;
}
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
upgradeHydrationErrorsToRecoverable
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function getIsHydrating() {
return isHydrating;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
getIsHydrating
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function queueHydrationError(error) {
if (hydrationErrors === null) {
hydrationErrors = [error];
} else {
hydrationErrors.push(error);
}
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
queueHydrationError
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function requestCurrentTransition() {
return ReactCurrentBatchConfig$1.transition;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
requestCurrentTransition
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
findStrictRoot = function (fiber) {
var maybeStrictRoot = null;
var node = fiber;
while (node !== null) {
if (node.mode & StrictLegacyMode) {
maybeStrictRoot = node;
}
node = node.return;
}
return maybeStrictRoot;
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
findStrictRoot
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
setToSortedString = function (set) {
var array = [];
set.forEach(function (value) {
array.push(value);
});
return array.sort().join(', ');
}
|
Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
DOM node.
|
setToSortedString
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function isReactClass(type) {
return type.prototype && type.prototype.isReactComponent;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
isReactClass
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function coerceRef(returnFiber, current, element) {
var mixedRef = element.ref;
if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
{
// TODO: Clean this up once we turn on the string ref warning for
// everyone, because the strict mode case will no longer be relevant
if ((returnFiber.mode & StrictLegacyMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
// because these cannot be automatically converted to an arrow function
// using a codemod. Therefore, we don't have to warn about string refs again.
!(element._owner && element._self && element._owner.stateNode !== element._self) && // Will already throw with "Function components cannot have string refs"
!(element._owner && element._owner.tag !== ClassComponent) && // Will already warn with "Function components cannot be given refs"
!(typeof element.type === 'function' && !isReactClass(element.type)) && // Will already throw with "Element ref was specified as a string (someStringRef) but no owner was set"
element._owner) {
var componentName = getComponentNameFromFiber(returnFiber) || 'Component';
if (!didWarnAboutStringRefs[componentName]) {
{
error('Component "%s" contains the string ref "%s". Support for string refs ' + 'will be removed in a future major release. We recommend using ' + 'useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', componentName, mixedRef);
}
didWarnAboutStringRefs[componentName] = true;
}
}
}
if (element._owner) {
var owner = element._owner;
var inst;
if (owner) {
var ownerFiber = owner;
if (ownerFiber.tag !== ClassComponent) {
throw new Error('Function components cannot have string refs. ' + 'We recommend using useRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref');
}
inst = ownerFiber.stateNode;
}
if (!inst) {
throw new Error("Missing owner for string ref " + mixedRef + ". This error is likely caused by a " + 'bug in React. Please file an issue.');
} // Assigning this to a const so Flow knows it won't change in the closure
var resolvedInst = inst;
{
checkPropStringCoercion(mixedRef, 'ref');
}
var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
if (current !== null && current.ref !== null && typeof current.ref === 'function' && current.ref._stringRef === stringRef) {
return current.ref;
}
var ref = function (value) {
var refs = resolvedInst.refs;
if (value === null) {
delete refs[stringRef];
} else {
refs[stringRef] = value;
}
};
ref._stringRef = stringRef;
return ref;
} else {
if (typeof mixedRef !== 'string') {
throw new Error('Expected ref to be a function, a string, an object returned by React.createRef(), or null.');
}
if (!element._owner) {
throw new Error("Element ref was specified as a string (" + mixedRef + ") but no owner was set. This could happen for one of" + ' the following reasons:\n' + '1. You may be adding a ref to a function component\n' + "2. You may be adding a ref to a component that was not created inside a component's render method\n" + '3. You have multiple copies of React loaded\n' + 'See https://reactjs.org/link/refs-must-have-owner for more information.');
}
}
}
return mixedRef;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
coerceRef
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
ref = function (value) {
var refs = resolvedInst.refs;
if (value === null) {
delete refs[stringRef];
} else {
refs[stringRef] = value;
}
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
ref
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function throwOnInvalidObjectType(returnFiber, newChild) {
var childString = Object.prototype.toString.call(newChild);
throw new Error("Objects are not valid as a React child (found: " + (childString === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : childString) + "). " + 'If you meant to render a collection of children, use an array ' + 'instead.');
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
throwOnInvalidObjectType
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function warnOnFunctionType(returnFiber) {
{
var componentName = getComponentNameFromFiber(returnFiber) || 'Component';
if (ownerHasFunctionTypeWarning[componentName]) {
return;
}
ownerHasFunctionTypeWarning[componentName] = true;
error('Functions are not valid as a React child. This may happen if ' + 'you return a Component instead of <Component /> from render. ' + 'Or maybe you meant to call this function rather than return it.');
}
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
warnOnFunctionType
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function resolveLazy(lazyType) {
var payload = lazyType._payload;
var init = lazyType._init;
return init(payload);
} // This wrapper function exists because I expect to clone the code in each path
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
resolveLazy
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function deleteChild(returnFiber, childToDelete) {
if (!shouldTrackSideEffects) {
// Noop.
return;
}
var deletions = returnFiber.deletions;
if (deletions === null) {
returnFiber.deletions = [childToDelete];
returnFiber.flags |= ChildDeletion;
} else {
deletions.push(childToDelete);
}
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
deleteChild
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function deleteRemainingChildren(returnFiber, currentFirstChild) {
if (!shouldTrackSideEffects) {
// Noop.
return null;
} // TODO: For the shouldClone case, this could be micro-optimized a bit by
// assuming that after the first child we've already added everything.
var childToDelete = currentFirstChild;
while (childToDelete !== null) {
deleteChild(returnFiber, childToDelete);
childToDelete = childToDelete.sibling;
}
return null;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
deleteRemainingChildren
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function mapRemainingChildren(returnFiber, currentFirstChild) {
// Add the remaining children to a temporary map so that we can find them by
// keys quickly. Implicit (null) keys get added to this set with their index
// instead.
var existingChildren = new Map();
var existingChild = currentFirstChild;
while (existingChild !== null) {
if (existingChild.key !== null) {
existingChildren.set(existingChild.key, existingChild);
} else {
existingChildren.set(existingChild.index, existingChild);
}
existingChild = existingChild.sibling;
}
return existingChildren;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
mapRemainingChildren
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function useFiber(fiber, pendingProps) {
// We currently set sibling to null and index to 0 here because it is easy
// to forget to do before returning it. E.g. for the single child case.
var clone = createWorkInProgress(fiber, pendingProps);
clone.index = 0;
clone.sibling = null;
return clone;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
useFiber
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function placeChild(newFiber, lastPlacedIndex, newIndex) {
newFiber.index = newIndex;
if (!shouldTrackSideEffects) {
// During hydration, the useId algorithm needs to know which fibers are
// part of a list of children (arrays, iterators).
newFiber.flags |= Forked;
return lastPlacedIndex;
}
var current = newFiber.alternate;
if (current !== null) {
var oldIndex = current.index;
if (oldIndex < lastPlacedIndex) {
// This is a move.
newFiber.flags |= Placement;
return lastPlacedIndex;
} else {
// This item can stay in place.
return oldIndex;
}
} else {
// This is an insertion.
newFiber.flags |= Placement;
return lastPlacedIndex;
}
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
placeChild
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function placeSingleChild(newFiber) {
// This is simpler for the single child case. We only need to do a
// placement for inserting new children.
if (shouldTrackSideEffects && newFiber.alternate === null) {
newFiber.flags |= Placement;
}
return newFiber;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
placeSingleChild
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function updateTextNode(returnFiber, current, textContent, lanes) {
if (current === null || current.tag !== HostText) {
// Insert
var created = createFiberFromText(textContent, returnFiber.mode, lanes);
created.return = returnFiber;
return created;
} else {
// Update
var existing = useFiber(current, textContent);
existing.return = returnFiber;
return existing;
}
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
updateTextNode
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function updateElement(returnFiber, current, element, lanes) {
var elementType = element.type;
if (elementType === REACT_FRAGMENT_TYPE) {
return updateFragment(returnFiber, current, element.props.children, lanes, element.key);
}
if (current !== null) {
if (current.elementType === elementType || ( // Keep this check inline so it only runs on the false path:
isCompatibleFamilyForHotReloading(current, element) ) || // Lazy types should reconcile their resolved type.
// We need to do this after the Hot Reloading check above,
// because hot reloading has different semantics than prod because
// it doesn't resuspend. So we can't let the call below suspend.
typeof elementType === 'object' && elementType !== null && elementType.$$typeof === REACT_LAZY_TYPE && resolveLazy(elementType) === current.type) {
// Move based on index
var existing = useFiber(current, element.props);
existing.ref = coerceRef(returnFiber, current, element);
existing.return = returnFiber;
{
existing._debugSource = element._source;
existing._debugOwner = element._owner;
}
return existing;
}
} // Insert
var created = createFiberFromElement(element, returnFiber.mode, lanes);
created.ref = coerceRef(returnFiber, current, element);
created.return = returnFiber;
return created;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
updateElement
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function updatePortal(returnFiber, current, portal, lanes) {
if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {
// Insert
var created = createFiberFromPortal(portal, returnFiber.mode, lanes);
created.return = returnFiber;
return created;
} else {
// Update
var existing = useFiber(current, portal.children || []);
existing.return = returnFiber;
return existing;
}
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
updatePortal
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function updateFragment(returnFiber, current, fragment, lanes, key) {
if (current === null || current.tag !== Fragment) {
// Insert
var created = createFiberFromFragment(fragment, returnFiber.mode, lanes, key);
created.return = returnFiber;
return created;
} else {
// Update
var existing = useFiber(current, fragment);
existing.return = returnFiber;
return existing;
}
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
updateFragment
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function createChild(returnFiber, newChild, lanes) {
if (typeof newChild === 'string' && newChild !== '' || typeof newChild === 'number') {
// Text nodes don't have keys. If the previous node is implicitly keyed
// we can continue to replace it without aborting even if it is not a text
// node.
var created = createFiberFromText('' + newChild, returnFiber.mode, lanes);
created.return = returnFiber;
return created;
}
if (typeof newChild === 'object' && newChild !== null) {
switch (newChild.$$typeof) {
case REACT_ELEMENT_TYPE:
{
var _created = createFiberFromElement(newChild, returnFiber.mode, lanes);
_created.ref = coerceRef(returnFiber, null, newChild);
_created.return = returnFiber;
return _created;
}
case REACT_PORTAL_TYPE:
{
var _created2 = createFiberFromPortal(newChild, returnFiber.mode, lanes);
_created2.return = returnFiber;
return _created2;
}
case REACT_LAZY_TYPE:
{
var payload = newChild._payload;
var init = newChild._init;
return createChild(returnFiber, init(payload), lanes);
}
}
if (isArray(newChild) || getIteratorFn(newChild)) {
var _created3 = createFiberFromFragment(newChild, returnFiber.mode, lanes, null);
_created3.return = returnFiber;
return _created3;
}
throwOnInvalidObjectType(returnFiber, newChild);
}
{
if (typeof newChild === 'function') {
warnOnFunctionType(returnFiber);
}
}
return null;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
createChild
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function updateSlot(returnFiber, oldFiber, newChild, lanes) {
// Update the fiber if the keys match, otherwise return null.
var key = oldFiber !== null ? oldFiber.key : null;
if (typeof newChild === 'string' && newChild !== '' || typeof newChild === 'number') {
// Text nodes don't have keys. If the previous node is implicitly keyed
// we can continue to replace it without aborting even if it is not a text
// node.
if (key !== null) {
return null;
}
return updateTextNode(returnFiber, oldFiber, '' + newChild, lanes);
}
if (typeof newChild === 'object' && newChild !== null) {
switch (newChild.$$typeof) {
case REACT_ELEMENT_TYPE:
{
if (newChild.key === key) {
return updateElement(returnFiber, oldFiber, newChild, lanes);
} else {
return null;
}
}
case REACT_PORTAL_TYPE:
{
if (newChild.key === key) {
return updatePortal(returnFiber, oldFiber, newChild, lanes);
} else {
return null;
}
}
case REACT_LAZY_TYPE:
{
var payload = newChild._payload;
var init = newChild._init;
return updateSlot(returnFiber, oldFiber, init(payload), lanes);
}
}
if (isArray(newChild) || getIteratorFn(newChild)) {
if (key !== null) {
return null;
}
return updateFragment(returnFiber, oldFiber, newChild, lanes, null);
}
throwOnInvalidObjectType(returnFiber, newChild);
}
{
if (typeof newChild === 'function') {
warnOnFunctionType(returnFiber);
}
}
return null;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
updateSlot
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function updateFromMap(existingChildren, returnFiber, newIdx, newChild, lanes) {
if (typeof newChild === 'string' && newChild !== '' || typeof newChild === 'number') {
// Text nodes don't have keys, so we neither have to check the old nor
// new node for the key. If both are text nodes, they match.
var matchedFiber = existingChildren.get(newIdx) || null;
return updateTextNode(returnFiber, matchedFiber, '' + newChild, lanes);
}
if (typeof newChild === 'object' && newChild !== null) {
switch (newChild.$$typeof) {
case REACT_ELEMENT_TYPE:
{
var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
return updateElement(returnFiber, _matchedFiber, newChild, lanes);
}
case REACT_PORTAL_TYPE:
{
var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
return updatePortal(returnFiber, _matchedFiber2, newChild, lanes);
}
case REACT_LAZY_TYPE:
var payload = newChild._payload;
var init = newChild._init;
return updateFromMap(existingChildren, returnFiber, newIdx, init(payload), lanes);
}
if (isArray(newChild) || getIteratorFn(newChild)) {
var _matchedFiber3 = existingChildren.get(newIdx) || null;
return updateFragment(returnFiber, _matchedFiber3, newChild, lanes, null);
}
throwOnInvalidObjectType(returnFiber, newChild);
}
{
if (typeof newChild === 'function') {
warnOnFunctionType(returnFiber);
}
}
return null;
}
|
Warn if there's no key explicitly set on dynamic arrays of children or
object keys are not valid. This allows us to keep track of children between
updates.
|
updateFromMap
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, lanes) {
// This algorithm can't optimize by searching from both ends since we
// don't have backpointers on fibers. I'm trying to see how far we can get
// with that model. If it ends up not being worth the tradeoffs, we can
// add it later.
// Even with a two ended optimization, we'd want to optimize for the case
// where there are few changes and brute force the comparison instead of
// going for the Map. It'd like to explore hitting that path first in
// forward-only mode and only go for the Map once we notice that we need
// lots of look ahead. This doesn't handle reversal as well as two ended
// search but that's unusual. Besides, for the two ended optimization to
// work on Iterables, we'd need to copy the whole set.
// In this first iteration, we'll just live with hitting the bad case
// (adding everything to a Map) in for every insert/move.
// If you change this code, also update reconcileChildrenIterator() which
// uses the same algorithm.
{
// First, validate keys.
var knownKeys = null;
for (var i = 0; i < newChildren.length; i++) {
var child = newChildren[i];
knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
}
}
var resultingFirstChild = null;
var previousNewFiber = null;
var oldFiber = currentFirstChild;
var lastPlacedIndex = 0;
var newIdx = 0;
var nextOldFiber = null;
for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
if (oldFiber.index > newIdx) {
nextOldFiber = oldFiber;
oldFiber = null;
} else {
nextOldFiber = oldFiber.sibling;
}
var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], lanes);
if (newFiber === null) {
// TODO: This breaks on empty slots like null children. That's
// unfortunate because it triggers the slow path all the time. We need
// a better way to communicate whether this was a miss or null,
// boolean, undefined, etc.
if (oldFiber === null) {
oldFiber = nextOldFiber;
}
break;
}
if (shouldTrackSideEffects) {
if (oldFiber && newFiber.alternate === null) {
// We matched the slot, but we didn't reuse the existing fiber, so we
// need to delete the existing child.
deleteChild(returnFiber, oldFiber);
}
}
lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
if (previousNewFiber === null) {
// TODO: Move out of the loop. This only happens for the first run.
resultingFirstChild = newFiber;
} else {
// TODO: Defer siblings if we're not at the right index for this slot.
// I.e. if we had null values before, then we want to defer this
// for each null value. However, we also don't want to call updateSlot
// with the previous one.
previousNewFiber.sibling = newFiber;
}
previousNewFiber = newFiber;
oldFiber = nextOldFiber;
}
if (newIdx === newChildren.length) {
// We've reached the end of the new children. We can delete the rest.
deleteRemainingChildren(returnFiber, oldFiber);
if (getIsHydrating()) {
var numberOfForks = newIdx;
pushTreeFork(returnFiber, numberOfForks);
}
return resultingFirstChild;
}
if (oldFiber === null) {
// If we don't have any more existing children we can choose a fast path
// since the rest will all be insertions.
for (; newIdx < newChildren.length; newIdx++) {
var _newFiber = createChild(returnFiber, newChildren[newIdx], lanes);
if (_newFiber === null) {
continue;
}
lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
if (previousNewFiber === null) {
// TODO: Move out of the loop. This only happens for the first run.
resultingFirstChild = _newFiber;
} else {
previousNewFiber.sibling = _newFiber;
}
previousNewFiber = _newFiber;
}
if (getIsHydrating()) {
var _numberOfForks = newIdx;
pushTreeFork(returnFiber, _numberOfForks);
}
return resultingFirstChild;
} // Add all children to a key map for quick lookups.
var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
for (; newIdx < newChildren.length; newIdx++) {
var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], lanes);
if (_newFiber2 !== null) {
if (shouldTrackSideEffects) {
if (_newFiber2.alternate !== null) {
// The new fiber is a work in progress, but if there exists a
// current, that means that we reused the fiber. We need to delete
// it from the child list so that we don't add it to the deletion
// list.
existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
}
}
lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
if (previousNewFiber === null) {
resultingFirstChild = _newFiber2;
} else {
previousNewFiber.sibling = _newFiber2;
}
previousNewFiber = _newFiber2;
}
}
if (shouldTrackSideEffects) {
// Any existing children that weren't consumed above were deleted. We need
// to add them to the deletion list.
existingChildren.forEach(function (child) {
return deleteChild(returnFiber, child);
});
}
if (getIsHydrating()) {
var _numberOfForks2 = newIdx;
pushTreeFork(returnFiber, _numberOfForks2);
}
return resultingFirstChild;
}
|
Warns if there is a duplicate or missing key
|
reconcileChildrenArray
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, lanes) {
// This is the same implementation as reconcileChildrenArray(),
// but using the iterator instead.
var iteratorFn = getIteratorFn(newChildrenIterable);
if (typeof iteratorFn !== 'function') {
throw new Error('An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');
}
{
// We don't support rendering Generators because it's a mutation.
// See https://github.com/facebook/react/issues/12995
if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
newChildrenIterable[Symbol.toStringTag] === 'Generator') {
if (!didWarnAboutGenerators) {
error('Using Generators as children is unsupported and will likely yield ' + 'unexpected results because enumerating a generator mutates it. ' + 'You may convert it to an array with `Array.from()` or the ' + '`[...spread]` operator before rendering. Keep in mind ' + 'you might need to polyfill these features for older browsers.');
}
didWarnAboutGenerators = true;
} // Warn about using Maps as children
if (newChildrenIterable.entries === iteratorFn) {
if (!didWarnAboutMaps) {
error('Using Maps as children is not supported. ' + 'Use an array of keyed ReactElements instead.');
}
didWarnAboutMaps = true;
} // First, validate keys.
// We'll get a different iterator later for the main pass.
var _newChildren = iteratorFn.call(newChildrenIterable);
if (_newChildren) {
var knownKeys = null;
var _step = _newChildren.next();
for (; !_step.done; _step = _newChildren.next()) {
var child = _step.value;
knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
}
}
}
var newChildren = iteratorFn.call(newChildrenIterable);
if (newChildren == null) {
throw new Error('An iterable object provided no iterator.');
}
var resultingFirstChild = null;
var previousNewFiber = null;
var oldFiber = currentFirstChild;
var lastPlacedIndex = 0;
var newIdx = 0;
var nextOldFiber = null;
var step = newChildren.next();
for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
if (oldFiber.index > newIdx) {
nextOldFiber = oldFiber;
oldFiber = null;
} else {
nextOldFiber = oldFiber.sibling;
}
var newFiber = updateSlot(returnFiber, oldFiber, step.value, lanes);
if (newFiber === null) {
// TODO: This breaks on empty slots like null children. That's
// unfortunate because it triggers the slow path all the time. We need
// a better way to communicate whether this was a miss or null,
// boolean, undefined, etc.
if (oldFiber === null) {
oldFiber = nextOldFiber;
}
break;
}
if (shouldTrackSideEffects) {
if (oldFiber && newFiber.alternate === null) {
// We matched the slot, but we didn't reuse the existing fiber, so we
// need to delete the existing child.
deleteChild(returnFiber, oldFiber);
}
}
lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
if (previousNewFiber === null) {
// TODO: Move out of the loop. This only happens for the first run.
resultingFirstChild = newFiber;
} else {
// TODO: Defer siblings if we're not at the right index for this slot.
// I.e. if we had null values before, then we want to defer this
// for each null value. However, we also don't want to call updateSlot
// with the previous one.
previousNewFiber.sibling = newFiber;
}
previousNewFiber = newFiber;
oldFiber = nextOldFiber;
}
if (step.done) {
// We've reached the end of the new children. We can delete the rest.
deleteRemainingChildren(returnFiber, oldFiber);
if (getIsHydrating()) {
var numberOfForks = newIdx;
pushTreeFork(returnFiber, numberOfForks);
}
return resultingFirstChild;
}
if (oldFiber === null) {
// If we don't have any more existing children we can choose a fast path
// since the rest will all be insertions.
for (; !step.done; newIdx++, step = newChildren.next()) {
var _newFiber3 = createChild(returnFiber, step.value, lanes);
if (_newFiber3 === null) {
continue;
}
lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
if (previousNewFiber === null) {
// TODO: Move out of the loop. This only happens for the first run.
resultingFirstChild = _newFiber3;
} else {
previousNewFiber.sibling = _newFiber3;
}
previousNewFiber = _newFiber3;
}
if (getIsHydrating()) {
var _numberOfForks3 = newIdx;
pushTreeFork(returnFiber, _numberOfForks3);
}
return resultingFirstChild;
} // Add all children to a key map for quick lookups.
var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
for (; !step.done; newIdx++, step = newChildren.next()) {
var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, lanes);
if (_newFiber4 !== null) {
if (shouldTrackSideEffects) {
if (_newFiber4.alternate !== null) {
// The new fiber is a work in progress, but if there exists a
// current, that means that we reused the fiber. We need to delete
// it from the child list so that we don't add it to the deletion
// list.
existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
}
}
lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
if (previousNewFiber === null) {
resultingFirstChild = _newFiber4;
} else {
previousNewFiber.sibling = _newFiber4;
}
previousNewFiber = _newFiber4;
}
}
if (shouldTrackSideEffects) {
// Any existing children that weren't consumed above were deleted. We need
// to add them to the deletion list.
existingChildren.forEach(function (child) {
return deleteChild(returnFiber, child);
});
}
if (getIsHydrating()) {
var _numberOfForks4 = newIdx;
pushTreeFork(returnFiber, _numberOfForks4);
}
return resultingFirstChild;
}
|
Warns if there is a duplicate or missing key
|
reconcileChildrenIterator
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, lanes) {
// There's no need to check for keys on text nodes since we don't have a
// way to define them.
if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
// We already have an existing node so let's just update it and delete
// the rest.
deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
var existing = useFiber(currentFirstChild, textContent);
existing.return = returnFiber;
return existing;
} // The existing first child is not a text node so we need to create one
// and delete the existing ones.
deleteRemainingChildren(returnFiber, currentFirstChild);
var created = createFiberFromText(textContent, returnFiber.mode, lanes);
created.return = returnFiber;
return created;
}
|
Warns if there is a duplicate or missing key
|
reconcileSingleTextNode
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function reconcileSingleElement(returnFiber, currentFirstChild, element, lanes) {
var key = element.key;
var child = currentFirstChild;
while (child !== null) {
// TODO: If key === null and child.key === null, then this only applies to
// the first item in the list.
if (child.key === key) {
var elementType = element.type;
if (elementType === REACT_FRAGMENT_TYPE) {
if (child.tag === Fragment) {
deleteRemainingChildren(returnFiber, child.sibling);
var existing = useFiber(child, element.props.children);
existing.return = returnFiber;
{
existing._debugSource = element._source;
existing._debugOwner = element._owner;
}
return existing;
}
} else {
if (child.elementType === elementType || ( // Keep this check inline so it only runs on the false path:
isCompatibleFamilyForHotReloading(child, element) ) || // Lazy types should reconcile their resolved type.
// We need to do this after the Hot Reloading check above,
// because hot reloading has different semantics than prod because
// it doesn't resuspend. So we can't let the call below suspend.
typeof elementType === 'object' && elementType !== null && elementType.$$typeof === REACT_LAZY_TYPE && resolveLazy(elementType) === child.type) {
deleteRemainingChildren(returnFiber, child.sibling);
var _existing = useFiber(child, element.props);
_existing.ref = coerceRef(returnFiber, child, element);
_existing.return = returnFiber;
{
_existing._debugSource = element._source;
_existing._debugOwner = element._owner;
}
return _existing;
}
} // Didn't match.
deleteRemainingChildren(returnFiber, child);
break;
} else {
deleteChild(returnFiber, child);
}
child = child.sibling;
}
if (element.type === REACT_FRAGMENT_TYPE) {
var created = createFiberFromFragment(element.props.children, returnFiber.mode, lanes, element.key);
created.return = returnFiber;
return created;
} else {
var _created4 = createFiberFromElement(element, returnFiber.mode, lanes);
_created4.ref = coerceRef(returnFiber, currentFirstChild, element);
_created4.return = returnFiber;
return _created4;
}
}
|
Warns if there is a duplicate or missing key
|
reconcileSingleElement
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function reconcileSinglePortal(returnFiber, currentFirstChild, portal, lanes) {
var key = portal.key;
var child = currentFirstChild;
while (child !== null) {
// TODO: If key === null and child.key === null, then this only applies to
// the first item in the list.
if (child.key === key) {
if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
deleteRemainingChildren(returnFiber, child.sibling);
var existing = useFiber(child, portal.children || []);
existing.return = returnFiber;
return existing;
} else {
deleteRemainingChildren(returnFiber, child);
break;
}
} else {
deleteChild(returnFiber, child);
}
child = child.sibling;
}
var created = createFiberFromPortal(portal, returnFiber.mode, lanes);
created.return = returnFiber;
return created;
} // This API will tag the children with the side-effect of the reconciliation
|
Warns if there is a duplicate or missing key
|
reconcileSinglePortal
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function reconcileChildFibers(returnFiber, currentFirstChild, newChild, lanes) {
// This function is not recursive.
// If the top level item is an array, we treat it as a set of children,
// not as a fragment. Nested arrays on the other hand will be treated as
// fragment nodes. Recursion happens at the normal flow.
// Handle top level unkeyed fragments as if they were arrays.
// This leads to an ambiguity between <>{[...]}</> and <>...</>.
// We treat the ambiguous cases above the same.
var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
if (isUnkeyedTopLevelFragment) {
newChild = newChild.props.children;
} // Handle object types
if (typeof newChild === 'object' && newChild !== null) {
switch (newChild.$$typeof) {
case REACT_ELEMENT_TYPE:
return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, lanes));
case REACT_PORTAL_TYPE:
return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, lanes));
case REACT_LAZY_TYPE:
var payload = newChild._payload;
var init = newChild._init; // TODO: This function is supposed to be non-recursive.
return reconcileChildFibers(returnFiber, currentFirstChild, init(payload), lanes);
}
if (isArray(newChild)) {
return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, lanes);
}
if (getIteratorFn(newChild)) {
return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, lanes);
}
throwOnInvalidObjectType(returnFiber, newChild);
}
if (typeof newChild === 'string' && newChild !== '' || typeof newChild === 'number') {
return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, lanes));
}
{
if (typeof newChild === 'function') {
warnOnFunctionType(returnFiber);
}
} // Remaining cases are all treated as empty.
return deleteRemainingChildren(returnFiber, currentFirstChild);
}
|
Warns if there is a duplicate or missing key
|
reconcileChildFibers
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function cloneChildFibers(current, workInProgress) {
if (current !== null && workInProgress.child !== current.child) {
throw new Error('Resuming work not yet implemented.');
}
if (workInProgress.child === null) {
return;
}
var currentChild = workInProgress.child;
var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
workInProgress.child = newChild;
newChild.return = workInProgress;
while (currentChild.sibling !== null) {
currentChild = currentChild.sibling;
newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps);
newChild.return = workInProgress;
}
newChild.sibling = null;
} // Reset a workInProgress child set to prepare it for a second pass.
|
Warns if there is a duplicate or missing key
|
cloneChildFibers
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function resetChildFibers(workInProgress, lanes) {
var child = workInProgress.child;
while (child !== null) {
resetWorkInProgress(child, lanes);
child = child.sibling;
}
}
|
Warns if there is a duplicate or missing key
|
resetChildFibers
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function resetContextDependencies() {
// This is called right before React yields execution, to ensure `readContext`
// cannot be called outside the render phase.
currentlyRenderingFiber = null;
lastContextDependency = null;
lastFullyObservedContext = null;
{
isDisallowedContextReadInDEV = false;
}
}
|
Warns if there is a duplicate or missing key
|
resetContextDependencies
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function enterDisallowedContextReadInDEV() {
{
isDisallowedContextReadInDEV = true;
}
}
|
Warns if there is a duplicate or missing key
|
enterDisallowedContextReadInDEV
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function exitDisallowedContextReadInDEV() {
{
isDisallowedContextReadInDEV = false;
}
}
|
Warns if there is a duplicate or missing key
|
exitDisallowedContextReadInDEV
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function pushProvider(providerFiber, context, nextValue) {
{
push(valueCursor, context._currentValue, providerFiber);
context._currentValue = nextValue;
{
if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
}
context._currentRenderer = rendererSigil;
}
}
}
|
Warns if there is a duplicate or missing key
|
pushProvider
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function popProvider(context, providerFiber) {
var currentValue = valueCursor.current;
pop(valueCursor, providerFiber);
{
{
context._currentValue = currentValue;
}
}
}
|
Warns if there is a duplicate or missing key
|
popProvider
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function scheduleContextWorkOnParentPath(parent, renderLanes, propagationRoot) {
// Update the child lanes of all the ancestors, including the alternates.
var node = parent;
while (node !== null) {
var alternate = node.alternate;
if (!isSubsetOfLanes(node.childLanes, renderLanes)) {
node.childLanes = mergeLanes(node.childLanes, renderLanes);
if (alternate !== null) {
alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
}
} else if (alternate !== null && !isSubsetOfLanes(alternate.childLanes, renderLanes)) {
alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
}
if (node === propagationRoot) {
break;
}
node = node.return;
}
{
if (node !== propagationRoot) {
error('Expected to find the propagation root when scheduling context work. ' + 'This error is likely caused by a bug in React. Please file an issue.');
}
}
}
|
Warns if there is a duplicate or missing key
|
scheduleContextWorkOnParentPath
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function propagateContextChange(workInProgress, context, renderLanes) {
{
propagateContextChange_eager(workInProgress, context, renderLanes);
}
}
|
Warns if there is a duplicate or missing key
|
propagateContextChange
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function propagateContextChange_eager(workInProgress, context, renderLanes) {
var fiber = workInProgress.child;
if (fiber !== null) {
// Set the return pointer of the child to the work-in-progress fiber.
fiber.return = workInProgress;
}
while (fiber !== null) {
var nextFiber = void 0; // Visit this fiber.
var list = fiber.dependencies;
if (list !== null) {
nextFiber = fiber.child;
var dependency = list.firstContext;
while (dependency !== null) {
// Check if the context matches.
if (dependency.context === context) {
// Match! Schedule an update on this fiber.
if (fiber.tag === ClassComponent) {
// Schedule a force update on the work-in-progress.
var lane = pickArbitraryLane(renderLanes);
var update = createUpdate(NoTimestamp, lane);
update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
// update to the current fiber, too, which means it will persist even if
// this render is thrown away. Since it's a race condition, not sure it's
// worth fixing.
// Inlined `enqueueUpdate` to remove interleaved update check
var updateQueue = fiber.updateQueue;
if (updateQueue === null) ; else {
var sharedQueue = updateQueue.shared;
var pending = sharedQueue.pending;
if (pending === null) {
// This is the first update. Create a circular list.
update.next = update;
} else {
update.next = pending.next;
pending.next = update;
}
sharedQueue.pending = update;
}
}
fiber.lanes = mergeLanes(fiber.lanes, renderLanes);
var alternate = fiber.alternate;
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleContextWorkOnParentPath(fiber.return, renderLanes, workInProgress); // Mark the updated lanes on the list, too.
list.lanes = mergeLanes(list.lanes, renderLanes); // Since we already found a match, we can stop traversing the
// dependency list.
break;
}
dependency = dependency.next;
}
} else if (fiber.tag === ContextProvider) {
// Don't scan deeper if this is a matching provider
nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
} else if (fiber.tag === DehydratedFragment) {
// If a dehydrated suspense boundary is in this subtree, we don't know
// if it will have any context consumers in it. The best we can do is
// mark it as having updates.
var parentSuspense = fiber.return;
if (parentSuspense === null) {
throw new Error('We just came from a parent so we must have had a parent. This is a bug in React.');
}
parentSuspense.lanes = mergeLanes(parentSuspense.lanes, renderLanes);
var _alternate = parentSuspense.alternate;
if (_alternate !== null) {
_alternate.lanes = mergeLanes(_alternate.lanes, renderLanes);
} // This is intentionally passing this fiber as the parent
// because we want to schedule this fiber as having work
// on its children. We'll use the childLanes on
// this fiber to indicate that a context has changed.
scheduleContextWorkOnParentPath(parentSuspense, renderLanes, workInProgress);
nextFiber = fiber.sibling;
} else {
// Traverse down.
nextFiber = fiber.child;
}
if (nextFiber !== null) {
// Set the return pointer of the child to the work-in-progress fiber.
nextFiber.return = fiber;
} else {
// No child. Traverse to next sibling.
nextFiber = fiber;
while (nextFiber !== null) {
if (nextFiber === workInProgress) {
// We're back to the root of this subtree. Exit.
nextFiber = null;
break;
}
var sibling = nextFiber.sibling;
if (sibling !== null) {
// Set the return pointer of the sibling to the work-in-progress fiber.
sibling.return = nextFiber.return;
nextFiber = sibling;
break;
} // No more siblings. Traverse up.
nextFiber = nextFiber.return;
}
}
fiber = nextFiber;
}
}
|
Warns if there is a duplicate or missing key
|
propagateContextChange_eager
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function prepareToReadContext(workInProgress, renderLanes) {
currentlyRenderingFiber = workInProgress;
lastContextDependency = null;
lastFullyObservedContext = null;
var dependencies = workInProgress.dependencies;
if (dependencies !== null) {
{
var firstContext = dependencies.firstContext;
if (firstContext !== null) {
if (includesSomeLane(dependencies.lanes, renderLanes)) {
// Context list has a pending update. Mark that this fiber performed work.
markWorkInProgressReceivedUpdate();
} // Reset the work-in-progress list
dependencies.firstContext = null;
}
}
}
}
|
Warns if there is a duplicate or missing key
|
prepareToReadContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function readContext(context) {
{
// This warning would fire if you read context inside a Hook like useMemo.
// Unlike the class check below, it's not enforced in production for perf.
if (isDisallowedContextReadInDEV) {
error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
}
}
var value = context._currentValue ;
if (lastFullyObservedContext === context) ; else {
var contextItem = {
context: context,
memoizedValue: value,
next: null
};
if (lastContextDependency === null) {
if (currentlyRenderingFiber === null) {
throw new Error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
} // This is the first dependency for this component. Create a new list.
lastContextDependency = contextItem;
currentlyRenderingFiber.dependencies = {
lanes: NoLanes,
firstContext: contextItem
};
} else {
// Append a new context item.
lastContextDependency = lastContextDependency.next = contextItem;
}
}
return value;
}
|
Warns if there is a duplicate or missing key
|
readContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function pushConcurrentUpdateQueue(queue) {
if (concurrentQueues === null) {
concurrentQueues = [queue];
} else {
concurrentQueues.push(queue);
}
}
|
Warns if there is a duplicate or missing key
|
pushConcurrentUpdateQueue
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function finishQueueingConcurrentUpdates() {
// Transfer the interleaved updates onto the main queue. Each queue has a
// `pending` field and an `interleaved` field. When they are not null, they
// point to the last node in a circular linked list. We need to append the
// interleaved list to the end of the pending list by joining them into a
// single, circular list.
if (concurrentQueues !== null) {
for (var i = 0; i < concurrentQueues.length; i++) {
var queue = concurrentQueues[i];
var lastInterleavedUpdate = queue.interleaved;
if (lastInterleavedUpdate !== null) {
queue.interleaved = null;
var firstInterleavedUpdate = lastInterleavedUpdate.next;
var lastPendingUpdate = queue.pending;
if (lastPendingUpdate !== null) {
var firstPendingUpdate = lastPendingUpdate.next;
lastPendingUpdate.next = firstInterleavedUpdate;
lastInterleavedUpdate.next = firstPendingUpdate;
}
queue.pending = lastInterleavedUpdate;
}
}
concurrentQueues = null;
}
}
|
Warns if there is a duplicate or missing key
|
finishQueueingConcurrentUpdates
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function enqueueConcurrentHookUpdate(fiber, queue, update, lane) {
var interleaved = queue.interleaved;
if (interleaved === null) {
// This is the first update. Create a circular list.
update.next = update; // At the end of the current render, this queue's interleaved updates will
// be transferred to the pending queue.
pushConcurrentUpdateQueue(queue);
} else {
update.next = interleaved.next;
interleaved.next = update;
}
queue.interleaved = update;
return markUpdateLaneFromFiberToRoot(fiber, lane);
}
|
Warns if there is a duplicate or missing key
|
enqueueConcurrentHookUpdate
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function enqueueConcurrentHookUpdateAndEagerlyBailout(fiber, queue, update, lane) {
var interleaved = queue.interleaved;
if (interleaved === null) {
// This is the first update. Create a circular list.
update.next = update; // At the end of the current render, this queue's interleaved updates will
// be transferred to the pending queue.
pushConcurrentUpdateQueue(queue);
} else {
update.next = interleaved.next;
interleaved.next = update;
}
queue.interleaved = update;
}
|
Warns if there is a duplicate or missing key
|
enqueueConcurrentHookUpdateAndEagerlyBailout
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function enqueueConcurrentClassUpdate(fiber, queue, update, lane) {
var interleaved = queue.interleaved;
if (interleaved === null) {
// This is the first update. Create a circular list.
update.next = update; // At the end of the current render, this queue's interleaved updates will
// be transferred to the pending queue.
pushConcurrentUpdateQueue(queue);
} else {
update.next = interleaved.next;
interleaved.next = update;
}
queue.interleaved = update;
return markUpdateLaneFromFiberToRoot(fiber, lane);
}
|
Warns if there is a duplicate or missing key
|
enqueueConcurrentClassUpdate
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function enqueueConcurrentRenderForLane(fiber, lane) {
return markUpdateLaneFromFiberToRoot(fiber, lane);
} // Calling this function outside this module should only be done for backwards
|
Warns if there is a duplicate or missing key
|
enqueueConcurrentRenderForLane
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function markUpdateLaneFromFiberToRoot(sourceFiber, lane) {
// Update the source fiber's lanes
sourceFiber.lanes = mergeLanes(sourceFiber.lanes, lane);
var alternate = sourceFiber.alternate;
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, lane);
}
{
if (alternate === null && (sourceFiber.flags & (Placement | Hydrating)) !== NoFlags) {
warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
}
} // Walk the parent path to the root and update the child lanes.
var node = sourceFiber;
var parent = sourceFiber.return;
while (parent !== null) {
parent.childLanes = mergeLanes(parent.childLanes, lane);
alternate = parent.alternate;
if (alternate !== null) {
alternate.childLanes = mergeLanes(alternate.childLanes, lane);
} else {
{
if ((parent.flags & (Placement | Hydrating)) !== NoFlags) {
warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
}
}
}
node = parent;
parent = parent.return;
}
if (node.tag === HostRoot) {
var root = node.stateNode;
return root;
} else {
return null;
}
}
|
Warns if there is a duplicate or missing key
|
markUpdateLaneFromFiberToRoot
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function initializeUpdateQueue(fiber) {
var queue = {
baseState: fiber.memoizedState,
firstBaseUpdate: null,
lastBaseUpdate: null,
shared: {
pending: null,
interleaved: null,
lanes: NoLanes
},
effects: null
};
fiber.updateQueue = queue;
}
|
Warns if there is a duplicate or missing key
|
initializeUpdateQueue
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function cloneUpdateQueue(current, workInProgress) {
// Clone the update queue from current. Unless it's already a clone.
var queue = workInProgress.updateQueue;
var currentQueue = current.updateQueue;
if (queue === currentQueue) {
var clone = {
baseState: currentQueue.baseState,
firstBaseUpdate: currentQueue.firstBaseUpdate,
lastBaseUpdate: currentQueue.lastBaseUpdate,
shared: currentQueue.shared,
effects: currentQueue.effects
};
workInProgress.updateQueue = clone;
}
}
|
Warns if there is a duplicate or missing key
|
cloneUpdateQueue
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function createUpdate(eventTime, lane) {
var update = {
eventTime: eventTime,
lane: lane,
tag: UpdateState,
payload: null,
callback: null,
next: null
};
return update;
}
|
Warns if there is a duplicate or missing key
|
createUpdate
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function enqueueUpdate(fiber, update, lane) {
var updateQueue = fiber.updateQueue;
if (updateQueue === null) {
// Only occurs if the fiber has been unmounted.
return null;
}
var sharedQueue = updateQueue.shared;
{
if (currentlyProcessingQueue === sharedQueue && !didWarnUpdateInsideUpdate) {
error('An update (setState, replaceState, or forceUpdate) was scheduled ' + 'from inside an update function. Update functions should be pure, ' + 'with zero side-effects. Consider using componentDidUpdate or a ' + 'callback.');
didWarnUpdateInsideUpdate = true;
}
}
if (isUnsafeClassRenderPhaseUpdate()) {
// This is an unsafe render phase update. Add directly to the update
// queue so we can process it immediately during the current render.
var pending = sharedQueue.pending;
if (pending === null) {
// This is the first update. Create a circular list.
update.next = update;
} else {
update.next = pending.next;
pending.next = update;
}
sharedQueue.pending = update; // Update the childLanes even though we're most likely already rendering
// this fiber. This is for backwards compatibility in the case where you
// update a different component during render phase than the one that is
// currently renderings (a pattern that is accompanied by a warning).
return unsafe_markUpdateLaneFromFiberToRoot(fiber, lane);
} else {
return enqueueConcurrentClassUpdate(fiber, sharedQueue, update, lane);
}
}
|
Warns if there is a duplicate or missing key
|
enqueueUpdate
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function entangleTransitions(root, fiber, lane) {
var updateQueue = fiber.updateQueue;
if (updateQueue === null) {
// Only occurs if the fiber has been unmounted.
return;
}
var sharedQueue = updateQueue.shared;
if (isTransitionLane(lane)) {
var queueLanes = sharedQueue.lanes; // If any entangled lanes are no longer pending on the root, then they must
// have finished. We can remove them from the shared queue, which represents
// a superset of the actually pending lanes. In some cases we may entangle
// more than we need to, but that's OK. In fact it's worse if we *don't*
// entangle when we should.
queueLanes = intersectLanes(queueLanes, root.pendingLanes); // Entangle the new transition lane with the other transition lanes.
var newQueueLanes = mergeLanes(queueLanes, lane);
sharedQueue.lanes = newQueueLanes; // Even if queue.lanes already include lane, we don't know for certain if
// the lane finished since the last time we entangled it. So we need to
// entangle it again, just to be sure.
markRootEntangled(root, newQueueLanes);
}
}
|
Warns if there is a duplicate or missing key
|
entangleTransitions
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function enqueueCapturedUpdate(workInProgress, capturedUpdate) {
// Captured updates are updates that are thrown by a child during the render
// phase. They should be discarded if the render is aborted. Therefore,
// we should only put them on the work-in-progress queue, not the current one.
var queue = workInProgress.updateQueue; // Check if the work-in-progress queue is a clone.
var current = workInProgress.alternate;
if (current !== null) {
var currentQueue = current.updateQueue;
if (queue === currentQueue) {
// The work-in-progress queue is the same as current. This happens when
// we bail out on a parent fiber that then captures an error thrown by
// a child. Since we want to append the update only to the work-in
// -progress queue, we need to clone the updates. We usually clone during
// processUpdateQueue, but that didn't happen in this case because we
// skipped over the parent when we bailed out.
var newFirst = null;
var newLast = null;
var firstBaseUpdate = queue.firstBaseUpdate;
if (firstBaseUpdate !== null) {
// Loop through the updates and clone them.
var update = firstBaseUpdate;
do {
var clone = {
eventTime: update.eventTime,
lane: update.lane,
tag: update.tag,
payload: update.payload,
callback: update.callback,
next: null
};
if (newLast === null) {
newFirst = newLast = clone;
} else {
newLast.next = clone;
newLast = clone;
}
update = update.next;
} while (update !== null); // Append the captured update the end of the cloned list.
if (newLast === null) {
newFirst = newLast = capturedUpdate;
} else {
newLast.next = capturedUpdate;
newLast = capturedUpdate;
}
} else {
// There are no base updates.
newFirst = newLast = capturedUpdate;
}
queue = {
baseState: currentQueue.baseState,
firstBaseUpdate: newFirst,
lastBaseUpdate: newLast,
shared: currentQueue.shared,
effects: currentQueue.effects
};
workInProgress.updateQueue = queue;
return;
}
} // Append the update to the end of the list.
var lastBaseUpdate = queue.lastBaseUpdate;
if (lastBaseUpdate === null) {
queue.firstBaseUpdate = capturedUpdate;
} else {
lastBaseUpdate.next = capturedUpdate;
}
queue.lastBaseUpdate = capturedUpdate;
}
|
Warns if there is a duplicate or missing key
|
enqueueCapturedUpdate
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
switch (update.tag) {
case ReplaceState:
{
var payload = update.payload;
if (typeof payload === 'function') {
// Updater function
{
enterDisallowedContextReadInDEV();
}
var nextState = payload.call(instance, prevState, nextProps);
{
if ( workInProgress.mode & StrictLegacyMode) {
setIsStrictModeForDevtools(true);
try {
payload.call(instance, prevState, nextProps);
} finally {
setIsStrictModeForDevtools(false);
}
}
exitDisallowedContextReadInDEV();
}
return nextState;
} // State object
return payload;
}
case CaptureUpdate:
{
workInProgress.flags = workInProgress.flags & ~ShouldCapture | DidCapture;
}
// Intentional fallthrough
case UpdateState:
{
var _payload = update.payload;
var partialState;
if (typeof _payload === 'function') {
// Updater function
{
enterDisallowedContextReadInDEV();
}
partialState = _payload.call(instance, prevState, nextProps);
{
if ( workInProgress.mode & StrictLegacyMode) {
setIsStrictModeForDevtools(true);
try {
_payload.call(instance, prevState, nextProps);
} finally {
setIsStrictModeForDevtools(false);
}
}
exitDisallowedContextReadInDEV();
}
} else {
// Partial state object
partialState = _payload;
}
if (partialState === null || partialState === undefined) {
// Null and undefined are treated as no-ops.
return prevState;
} // Merge the partial state and the previous state.
return assign({}, prevState, partialState);
}
case ForceUpdate:
{
hasForceUpdate = true;
return prevState;
}
}
return prevState;
}
|
Warns if there is a duplicate or missing key
|
getStateFromUpdate
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function processUpdateQueue(workInProgress, props, instance, renderLanes) {
// This is always non-null on a ClassComponent or HostRoot
var queue = workInProgress.updateQueue;
hasForceUpdate = false;
{
currentlyProcessingQueue = queue.shared;
}
var firstBaseUpdate = queue.firstBaseUpdate;
var lastBaseUpdate = queue.lastBaseUpdate; // Check if there are pending updates. If so, transfer them to the base queue.
var pendingQueue = queue.shared.pending;
if (pendingQueue !== null) {
queue.shared.pending = null; // The pending queue is circular. Disconnect the pointer between first
// and last so that it's non-circular.
var lastPendingUpdate = pendingQueue;
var firstPendingUpdate = lastPendingUpdate.next;
lastPendingUpdate.next = null; // Append pending updates to base queue
if (lastBaseUpdate === null) {
firstBaseUpdate = firstPendingUpdate;
} else {
lastBaseUpdate.next = firstPendingUpdate;
}
lastBaseUpdate = lastPendingUpdate; // If there's a current queue, and it's different from the base queue, then
// we need to transfer the updates to that queue, too. Because the base
// queue is a singly-linked list with no cycles, we can append to both
// lists and take advantage of structural sharing.
// TODO: Pass `current` as argument
var current = workInProgress.alternate;
if (current !== null) {
// This is always non-null on a ClassComponent or HostRoot
var currentQueue = current.updateQueue;
var currentLastBaseUpdate = currentQueue.lastBaseUpdate;
if (currentLastBaseUpdate !== lastBaseUpdate) {
if (currentLastBaseUpdate === null) {
currentQueue.firstBaseUpdate = firstPendingUpdate;
} else {
currentLastBaseUpdate.next = firstPendingUpdate;
}
currentQueue.lastBaseUpdate = lastPendingUpdate;
}
}
} // These values may change as we process the queue.
if (firstBaseUpdate !== null) {
// Iterate through the list of updates to compute the result.
var newState = queue.baseState; // TODO: Don't need to accumulate this. Instead, we can remove renderLanes
// from the original lanes.
var newLanes = NoLanes;
var newBaseState = null;
var newFirstBaseUpdate = null;
var newLastBaseUpdate = null;
var update = firstBaseUpdate;
do {
var updateLane = update.lane;
var updateEventTime = update.eventTime;
if (!isSubsetOfLanes(renderLanes, updateLane)) {
// Priority is insufficient. Skip this update. If this is the first
// skipped update, the previous update/state is the new base
// update/state.
var clone = {
eventTime: updateEventTime,
lane: updateLane,
tag: update.tag,
payload: update.payload,
callback: update.callback,
next: null
};
if (newLastBaseUpdate === null) {
newFirstBaseUpdate = newLastBaseUpdate = clone;
newBaseState = newState;
} else {
newLastBaseUpdate = newLastBaseUpdate.next = clone;
} // Update the remaining priority in the queue.
newLanes = mergeLanes(newLanes, updateLane);
} else {
// This update does have sufficient priority.
if (newLastBaseUpdate !== null) {
var _clone = {
eventTime: updateEventTime,
// This update is going to be committed so we never want uncommit
// it. Using NoLane works because 0 is a subset of all bitmasks, so
// this will never be skipped by the check above.
lane: NoLane,
tag: update.tag,
payload: update.payload,
callback: update.callback,
next: null
};
newLastBaseUpdate = newLastBaseUpdate.next = _clone;
} // Process this update.
newState = getStateFromUpdate(workInProgress, queue, update, newState, props, instance);
var callback = update.callback;
if (callback !== null && // If the update was already committed, we should not queue its
// callback again.
update.lane !== NoLane) {
workInProgress.flags |= Callback;
var effects = queue.effects;
if (effects === null) {
queue.effects = [update];
} else {
effects.push(update);
}
}
}
update = update.next;
if (update === null) {
pendingQueue = queue.shared.pending;
if (pendingQueue === null) {
break;
} else {
// An update was scheduled from inside a reducer. Add the new
// pending updates to the end of the list and keep processing.
var _lastPendingUpdate = pendingQueue; // Intentionally unsound. Pending updates form a circular list, but we
// unravel them when transferring them to the base queue.
var _firstPendingUpdate = _lastPendingUpdate.next;
_lastPendingUpdate.next = null;
update = _firstPendingUpdate;
queue.lastBaseUpdate = _lastPendingUpdate;
queue.shared.pending = null;
}
}
} while (true);
if (newLastBaseUpdate === null) {
newBaseState = newState;
}
queue.baseState = newBaseState;
queue.firstBaseUpdate = newFirstBaseUpdate;
queue.lastBaseUpdate = newLastBaseUpdate; // Interleaved updates are stored on a separate queue. We aren't going to
// process them during this render, but we do need to track which lanes
// are remaining.
var lastInterleaved = queue.shared.interleaved;
if (lastInterleaved !== null) {
var interleaved = lastInterleaved;
do {
newLanes = mergeLanes(newLanes, interleaved.lane);
interleaved = interleaved.next;
} while (interleaved !== lastInterleaved);
} else if (firstBaseUpdate === null) {
// `queue.lanes` is used for entangling transitions. We can set it back to
// zero once the queue is empty.
queue.shared.lanes = NoLanes;
} // Set the remaining expiration time to be whatever is remaining in the queue.
// This should be fine because the only two other things that contribute to
// expiration time are props and context. We're already in the middle of the
// begin phase by the time we start processing the queue, so we've already
// dealt with the props. Context in components that specify
// shouldComponentUpdate is tricky; but we'll have to account for
// that regardless.
markSkippedUpdateLanes(newLanes);
workInProgress.lanes = newLanes;
workInProgress.memoizedState = newState;
}
{
currentlyProcessingQueue = null;
}
}
|
Warns if there is a duplicate or missing key
|
processUpdateQueue
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function callCallback(callback, context) {
if (typeof callback !== 'function') {
throw new Error('Invalid argument passed as callback. Expected a function. Instead ' + ("received: " + callback));
}
callback.call(context);
}
|
Warns if there is a duplicate or missing key
|
callCallback
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function resetHasForceUpdateBeforeProcessing() {
hasForceUpdate = false;
}
|
Warns if there is a duplicate or missing key
|
resetHasForceUpdateBeforeProcessing
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function checkHasForceUpdateAfterProcessing() {
return hasForceUpdate;
}
|
Warns if there is a duplicate or missing key
|
checkHasForceUpdateAfterProcessing
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function commitUpdateQueue(finishedWork, finishedQueue, instance) {
// Commit the effects
var effects = finishedQueue.effects;
finishedQueue.effects = null;
if (effects !== null) {
for (var i = 0; i < effects.length; i++) {
var effect = effects[i];
var callback = effect.callback;
if (callback !== null) {
effect.callback = null;
callCallback(callback, instance);
}
}
}
}
|
Warns if there is a duplicate or missing key
|
commitUpdateQueue
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function requiredContext(c) {
if (c === NO_CONTEXT) {
throw new Error('Expected host context to exist. This error is likely caused by a bug ' + 'in React. Please file an issue.');
}
return c;
}
|
Warns if there is a duplicate or missing key
|
requiredContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function getRootHostContainer() {
var rootInstance = requiredContext(rootInstanceStackCursor.current);
return rootInstance;
}
|
Warns if there is a duplicate or missing key
|
getRootHostContainer
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function pushHostContainer(fiber, nextRootInstance) {
// Push current root instance onto the stack;
// This allows us to reset root when portals are popped.
push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
// This enables us to pop only Fibers that provide unique contexts.
push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
// However, we can't just call getRootHostContext() and push it because
// we'd have a different number of entries on the stack depending on
// whether getRootHostContext() throws somewhere in renderer code or not.
// So we push an empty value first. This lets us safely unwind on errors.
push(contextStackCursor$1, NO_CONTEXT, fiber);
var nextRootContext = getRootHostContext(nextRootInstance); // Now that we know this function doesn't throw, replace it.
pop(contextStackCursor$1, fiber);
push(contextStackCursor$1, nextRootContext, fiber);
}
|
Warns if there is a duplicate or missing key
|
pushHostContainer
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function popHostContainer(fiber) {
pop(contextStackCursor$1, fiber);
pop(contextFiberStackCursor, fiber);
pop(rootInstanceStackCursor, fiber);
}
|
Warns if there is a duplicate or missing key
|
popHostContainer
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function getHostContext() {
var context = requiredContext(contextStackCursor$1.current);
return context;
}
|
Warns if there is a duplicate or missing key
|
getHostContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function pushHostContext(fiber) {
var rootInstance = requiredContext(rootInstanceStackCursor.current);
var context = requiredContext(contextStackCursor$1.current);
var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
if (context === nextContext) {
return;
} // Track the context and the Fiber that provided it.
// This enables us to pop only Fibers that provide unique contexts.
push(contextFiberStackCursor, fiber, fiber);
push(contextStackCursor$1, nextContext, fiber);
}
|
Warns if there is a duplicate or missing key
|
pushHostContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function popHostContext(fiber) {
// Do not pop unless this Fiber provided the current context.
// pushHostContext() only pushes Fibers that provide unique contexts.
if (contextFiberStackCursor.current !== fiber) {
return;
}
pop(contextStackCursor$1, fiber);
pop(contextFiberStackCursor, fiber);
}
|
Warns if there is a duplicate or missing key
|
popHostContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function hasSuspenseContext(parentContext, flag) {
return (parentContext & flag) !== 0;
}
|
Warns if there is a duplicate or missing key
|
hasSuspenseContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function setDefaultShallowSuspenseContext(parentContext) {
return parentContext & SubtreeSuspenseContextMask;
}
|
Warns if there is a duplicate or missing key
|
setDefaultShallowSuspenseContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function setShallowSuspenseContext(parentContext, shallowContext) {
return parentContext & SubtreeSuspenseContextMask | shallowContext;
}
|
Warns if there is a duplicate or missing key
|
setShallowSuspenseContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function addSubtreeSuspenseContext(parentContext, subtreeContext) {
return parentContext | subtreeContext;
}
|
Warns if there is a duplicate or missing key
|
addSubtreeSuspenseContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function pushSuspenseContext(fiber, newContext) {
push(suspenseStackCursor, newContext, fiber);
}
|
Warns if there is a duplicate or missing key
|
pushSuspenseContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function popSuspenseContext(fiber) {
pop(suspenseStackCursor, fiber);
}
|
Warns if there is a duplicate or missing key
|
popSuspenseContext
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
// If it was the primary children that just suspended, capture and render the
// fallback. Otherwise, don't capture and bubble to the next boundary.
var nextState = workInProgress.memoizedState;
if (nextState !== null) {
if (nextState.dehydrated !== null) {
// A dehydrated boundary always captures.
return true;
}
return false;
}
var props = workInProgress.memoizedProps; // Regular boundaries always capture.
{
return true;
} // If it's a boundary we should avoid, then we prefer to bubble up to the
}
|
Warns if there is a duplicate or missing key
|
shouldCaptureSuspense
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function findFirstSuspended(row) {
var node = row;
while (node !== null) {
if (node.tag === SuspenseComponent) {
var state = node.memoizedState;
if (state !== null) {
var dehydrated = state.dehydrated;
if (dehydrated === null || isSuspenseInstancePending(dehydrated) || isSuspenseInstanceFallback(dehydrated)) {
return node;
}
}
} else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
// keep track of whether it suspended or not.
node.memoizedProps.revealOrder !== undefined) {
var didSuspend = (node.flags & DidCapture) !== NoFlags;
if (didSuspend) {
return node;
}
} else if (node.child !== null) {
node.child.return = node;
node = node.child;
continue;
}
if (node === row) {
return null;
}
while (node.sibling === null) {
if (node.return === null || node.return === row) {
return null;
}
node = node.return;
}
node.sibling.return = node.return;
node = node.sibling;
}
return null;
}
|
Warns if there is a duplicate or missing key
|
findFirstSuspended
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function resetWorkInProgressVersions() {
for (var i = 0; i < workInProgressSources.length; i++) {
var mutableSource = workInProgressSources[i];
{
mutableSource._workInProgressVersionPrimary = null;
}
}
workInProgressSources.length = 0;
}
|
Warns if there is a duplicate or missing key
|
resetWorkInProgressVersions
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function registerMutableSourceForHydration(root, mutableSource) {
var getVersion = mutableSource._getVersion;
var version = getVersion(mutableSource._source); // TODO Clear this data once all pending hydration work is finished.
// Retaining it forever may interfere with GC.
if (root.mutableSourceEagerHydrationData == null) {
root.mutableSourceEagerHydrationData = [mutableSource, version];
} else {
root.mutableSourceEagerHydrationData.push(mutableSource, version);
}
}
|
Warns if there is a duplicate or missing key
|
registerMutableSourceForHydration
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function mountHookTypesDev() {
{
var hookName = currentHookNameInDev;
if (hookTypesDev === null) {
hookTypesDev = [hookName];
} else {
hookTypesDev.push(hookName);
}
}
}
|
Warns if there is a duplicate or missing key
|
mountHookTypesDev
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function updateHookTypesDev() {
{
var hookName = currentHookNameInDev;
if (hookTypesDev !== null) {
hookTypesUpdateIndexDev++;
if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
warnOnHookMismatchInDev(hookName);
}
}
}
}
|
Warns if there is a duplicate or missing key
|
updateHookTypesDev
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function checkDepsAreArrayDev(deps) {
{
if (deps !== undefined && deps !== null && !isArray(deps)) {
// Verify deps, but only on mount to avoid extra checks.
// It's unlikely their type would change as usually you define them inline.
error('%s received a final argument that is not an array (instead, received `%s`). When ' + 'specified, the final argument must be an array.', currentHookNameInDev, typeof deps);
}
}
}
|
Warns if there is a duplicate or missing key
|
checkDepsAreArrayDev
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function warnOnHookMismatchInDev(currentHookName) {
{
var componentName = getComponentNameFromFiber(currentlyRenderingFiber$1);
if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
didWarnAboutMismatchedHooksForComponent.add(componentName);
if (hookTypesDev !== null) {
var table = '';
var secondColumnStart = 30;
for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
var oldHookName = hookTypesDev[i];
var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
// lol @ IE not supporting String#repeat
while (row.length < secondColumnStart) {
row += ' ';
}
row += newHookName + '\n';
table += row;
}
error('React has detected a change in the order of Hooks called by %s. ' + 'This will lead to bugs and errors if not fixed. ' + 'For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks\n\n' + ' Previous render Next render\n' + ' ------------------------------------------------------\n' + '%s' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', componentName, table);
}
}
}
}
|
Warns if there is a duplicate or missing key
|
warnOnHookMismatchInDev
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function throwInvalidHookError() {
throw new Error('Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' + ' one of the following reasons:\n' + '1. You might have mismatching versions of React and the renderer (such as React DOM)\n' + '2. You might be breaking the Rules of Hooks\n' + '3. You might have more than one copy of React in the same app\n' + 'See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.');
}
|
Warns if there is a duplicate or missing key
|
throwInvalidHookError
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function areHookInputsEqual(nextDeps, prevDeps) {
{
if (ignorePreviousDependencies) {
// Only true when this component is being hot reloaded.
return false;
}
}
if (prevDeps === null) {
{
error('%s received a final argument during this render, but not during ' + 'the previous render. Even though the final argument is optional, ' + 'its type cannot change between renders.', currentHookNameInDev);
}
return false;
}
{
// Don't bother comparing lengths in prod because these arrays should be
// passed inline.
if (nextDeps.length !== prevDeps.length) {
error('The final argument passed to %s changed size between renders. The ' + 'order and size of this array must remain constant.\n\n' + 'Previous: %s\n' + 'Incoming: %s', currentHookNameInDev, "[" + prevDeps.join(', ') + "]", "[" + nextDeps.join(', ') + "]");
}
}
for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
if (objectIs(nextDeps[i], prevDeps[i])) {
continue;
}
return false;
}
return true;
}
|
Warns if there is a duplicate or missing key
|
areHookInputsEqual
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function renderWithHooks(current, workInProgress, Component, props, secondArg, nextRenderLanes) {
renderLanes = nextRenderLanes;
currentlyRenderingFiber$1 = workInProgress;
{
hookTypesDev = current !== null ? current._debugHookTypes : null;
hookTypesUpdateIndexDev = -1; // Used for hot reloading:
ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
}
workInProgress.memoizedState = null;
workInProgress.updateQueue = null;
workInProgress.lanes = NoLanes; // The following should have already been reset
// currentHook = null;
// workInProgressHook = null;
// didScheduleRenderPhaseUpdate = false;
// localIdCounter = 0;
// TODO Warn if no hooks are used at all during mount, then some are used during update.
// Currently we will identify the update render as a mount because memoizedState === null.
// This is tricky because it's valid for certain types of components (e.g. React.lazy)
// Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
// Non-stateful hooks (e.g. context) don't get added to memoizedState,
// so memoizedState would be null during updates and mounts.
{
if (current !== null && current.memoizedState !== null) {
ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
} else if (hookTypesDev !== null) {
// This dispatcher handles an edge case where a component is updating,
// but no stateful hooks have been used.
// We want to match the production code behavior (which will use HooksDispatcherOnMount),
// but with the extra DEV validation to ensure hooks ordering hasn't changed.
// This dispatcher does that.
ReactCurrentDispatcher$1.current = HooksDispatcherOnMountWithHookTypesInDEV;
} else {
ReactCurrentDispatcher$1.current = HooksDispatcherOnMountInDEV;
}
}
var children = Component(props, secondArg); // Check if there was a render phase update
if (didScheduleRenderPhaseUpdateDuringThisPass) {
// Keep rendering in a loop for as long as render phase updates continue to
// be scheduled. Use a counter to prevent infinite loops.
var numberOfReRenders = 0;
do {
didScheduleRenderPhaseUpdateDuringThisPass = false;
localIdCounter = 0;
if (numberOfReRenders >= RE_RENDER_LIMIT) {
throw new Error('Too many re-renders. React limits the number of renders to prevent ' + 'an infinite loop.');
}
numberOfReRenders += 1;
{
// Even when hot reloading, allow dependencies to stabilize
// after first render to prevent infinite render phase updates.
ignorePreviousDependencies = false;
} // Start over from the beginning of the list
currentHook = null;
workInProgressHook = null;
workInProgress.updateQueue = null;
{
// Also validate hook order for cascading updates.
hookTypesUpdateIndexDev = -1;
}
ReactCurrentDispatcher$1.current = HooksDispatcherOnRerenderInDEV ;
children = Component(props, secondArg);
} while (didScheduleRenderPhaseUpdateDuringThisPass);
} // We can assume the previous dispatcher is always this one, since we set it
// at the beginning of the render phase and there's no re-entrance.
ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
{
workInProgress._debugHookTypes = hookTypesDev;
} // This check uses currentHook so that it works the same in DEV and prod bundles.
// hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
renderLanes = NoLanes;
currentlyRenderingFiber$1 = null;
currentHook = null;
workInProgressHook = null;
{
currentHookNameInDev = null;
hookTypesDev = null;
hookTypesUpdateIndexDev = -1; // Confirm that a static flag was not added or removed since the last
// render. If this fires, it suggests that we incorrectly reset the static
// flags in some other part of the codebase. This has happened before, for
// example, in the SuspenseList implementation.
if (current !== null && (current.flags & StaticMask) !== (workInProgress.flags & StaticMask) && // Disable this warning in legacy mode, because legacy Suspense is weird
// and creates false positives. To make this work in legacy mode, we'd
// need to mark fibers that commit in an incomplete state, somehow. For
// now I'll disable the warning that most of the bugs that would trigger
// it are either exclusive to concurrent mode or exist in both.
(current.mode & ConcurrentMode) !== NoMode) {
error('Internal React error: Expected static flag was missing. Please ' + 'notify the React team.');
}
}
didScheduleRenderPhaseUpdate = false; // This is reset by checkDidRenderIdHook
// localIdCounter = 0;
if (didRenderTooFewHooks) {
throw new Error('Rendered fewer hooks than expected. This may be caused by an accidental ' + 'early return statement.');
}
return children;
}
|
Warns if there is a duplicate or missing key
|
renderWithHooks
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function checkDidRenderIdHook() {
// This should be called immediately after every renderWithHooks call.
// Conceptually, it's part of the return value of renderWithHooks; it's only a
// separate function to avoid using an array tuple.
var didRenderIdHook = localIdCounter !== 0;
localIdCounter = 0;
return didRenderIdHook;
}
|
Warns if there is a duplicate or missing key
|
checkDidRenderIdHook
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function bailoutHooks(current, workInProgress, lanes) {
workInProgress.updateQueue = current.updateQueue; // TODO: Don't need to reset the flags here, because they're reset in the
// complete phase (bubbleProperties).
if ( (workInProgress.mode & StrictEffectsMode) !== NoMode) {
workInProgress.flags &= ~(MountPassiveDev | MountLayoutDev | Passive | Update);
} else {
workInProgress.flags &= ~(Passive | Update);
}
current.lanes = removeLanes(current.lanes, lanes);
}
|
Warns if there is a duplicate or missing key
|
bailoutHooks
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function resetHooksAfterThrow() {
// We can assume the previous dispatcher is always this one, since we set it
// at the beginning of the render phase and there's no re-entrance.
ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
if (didScheduleRenderPhaseUpdate) {
// There were render phase updates. These are only valid for this render
// phase, which we are now aborting. Remove the updates from the queues so
// they do not persist to the next render. Do not remove updates from hooks
// that weren't processed.
//
// Only reset the updates from the queue if it has a clone. If it does
// not have a clone, that means it wasn't processed, and the updates were
// scheduled before we entered the render phase.
var hook = currentlyRenderingFiber$1.memoizedState;
while (hook !== null) {
var queue = hook.queue;
if (queue !== null) {
queue.pending = null;
}
hook = hook.next;
}
didScheduleRenderPhaseUpdate = false;
}
renderLanes = NoLanes;
currentlyRenderingFiber$1 = null;
currentHook = null;
workInProgressHook = null;
{
hookTypesDev = null;
hookTypesUpdateIndexDev = -1;
currentHookNameInDev = null;
isUpdatingOpaqueValueInRenderPhase = false;
}
didScheduleRenderPhaseUpdateDuringThisPass = false;
localIdCounter = 0;
}
|
Warns if there is a duplicate or missing key
|
resetHooksAfterThrow
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
function mountWorkInProgressHook() {
var hook = {
memoizedState: null,
baseState: null,
baseQueue: null,
queue: null,
next: null
};
if (workInProgressHook === null) {
// This is the first hook in the list
currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
} else {
// Append to the end of the list
workInProgressHook = workInProgressHook.next = hook;
}
return workInProgressHook;
}
|
Warns if there is a duplicate or missing key
|
mountWorkInProgressHook
|
javascript
|
facebook/memlab
|
packages/lens/src/tests/lib/react-dom-v18.dev.js
|
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.