React sync for revisions ced176e...9d484ed

Reviewed By: bvaughn

Differential Revision: D7338640

fbshipit-source-id: e2d75d2f1795fb3c37f193d15216951c707711d9
This commit is contained in:
Héctor Ramos 2018-03-20 17:03:06 -07:00 committed by Mike Grabowski
parent 73ffa6003a
commit 69c77d6492
6 changed files with 2990 additions and 2565 deletions

View File

@ -1 +1 @@
ced176edb7605a25e916895fd060f3943c647fee
9d484edc4b64160cb335a23a2cb21667fb2cdf4c

File diff suppressed because it is too large Load Diff

View File

@ -1633,136 +1633,6 @@ function findCurrentHostFiberWithNoPortals(parent) {
}
return null;
}
var valueStack = [],
index = -1;
function pop(cursor) {
0 > index ||
((cursor.current = valueStack[index]), (valueStack[index] = null), index--);
}
function push(cursor, value) {
index++;
valueStack[index] = cursor.current;
cursor.current = value;
}
function getStackAddendumByWorkInProgressFiber(workInProgress) {
var info = "";
do {
a: switch (workInProgress.tag) {
case 0:
case 1:
case 2:
case 5:
var owner = workInProgress._debugOwner,
source = workInProgress._debugSource;
var JSCompiler_inline_result = getComponentName(workInProgress);
var ownerName = null;
owner && (ownerName = getComponentName(owner));
owner = source;
JSCompiler_inline_result =
"\n in " +
(JSCompiler_inline_result || "Unknown") +
(owner
? " (at " +
owner.fileName.replace(/^.*[\\\/]/, "") +
":" +
owner.lineNumber +
")"
: ownerName ? " (created by " + ownerName + ")" : "");
break a;
default:
JSCompiler_inline_result = "";
}
info += JSCompiler_inline_result;
workInProgress = workInProgress["return"];
} while (workInProgress);
return info;
}
new Set();
var contextStackCursor = { current: emptyObject },
didPerformWorkStackCursor = { current: !1 },
previousContext = emptyObject;
function getUnmaskedContext(workInProgress) {
return isContextProvider(workInProgress)
? previousContext
: contextStackCursor.current;
}
function getMaskedContext(workInProgress, unmaskedContext) {
var contextTypes = workInProgress.type.contextTypes;
if (!contextTypes) return emptyObject;
var instance = workInProgress.stateNode;
if (
instance &&
instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
)
return instance.__reactInternalMemoizedMaskedChildContext;
var context = {},
key;
for (key in contextTypes) context[key] = unmaskedContext[key];
instance &&
((workInProgress = workInProgress.stateNode),
(workInProgress.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext),
(workInProgress.__reactInternalMemoizedMaskedChildContext = context));
return context;
}
function isContextProvider(fiber) {
return 2 === fiber.tag && null != fiber.type.childContextTypes;
}
function popContextProvider(fiber) {
isContextProvider(fiber) &&
(pop(didPerformWorkStackCursor, fiber), pop(contextStackCursor, fiber));
}
function pushTopLevelContextObject(fiber, context, didChange) {
invariant(
null == contextStackCursor.cursor,
"Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."
);
push(contextStackCursor, context, fiber);
push(didPerformWorkStackCursor, didChange, fiber);
}
function processChildContext(fiber, parentContext) {
var instance = fiber.stateNode,
childContextTypes = fiber.type.childContextTypes;
if ("function" !== typeof instance.getChildContext) return parentContext;
instance = instance.getChildContext();
for (var contextKey in instance)
invariant(
contextKey in childContextTypes,
'%s.getChildContext(): key "%s" is not defined in childContextTypes.',
getComponentName(fiber) || "Unknown",
contextKey
);
return Object.assign({}, parentContext, instance);
}
function pushContextProvider(workInProgress) {
if (!isContextProvider(workInProgress)) return !1;
var instance = workInProgress.stateNode;
instance =
(instance && instance.__reactInternalMemoizedMergedChildContext) ||
emptyObject;
previousContext = contextStackCursor.current;
push(contextStackCursor, instance, workInProgress);
push(
didPerformWorkStackCursor,
didPerformWorkStackCursor.current,
workInProgress
);
return !0;
}
function invalidateContextProvider(workInProgress, didChange) {
var instance = workInProgress.stateNode;
invariant(
instance,
"Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."
);
if (didChange) {
var mergedContext = processChildContext(workInProgress, previousContext);
instance.__reactInternalMemoizedMergedChildContext = mergedContext;
pop(didPerformWorkStackCursor, workInProgress);
pop(contextStackCursor, workInProgress);
push(contextStackCursor, mergedContext, workInProgress);
} else pop(didPerformWorkStackCursor, workInProgress);
push(didPerformWorkStackCursor, didChange, workInProgress);
}
function FiberNode(tag, pendingProps, key, mode) {
this.tag = tag;
this.key = key;
@ -1929,6 +1799,40 @@ function onCommitRoot(root) {
function onCommitUnmount(fiber) {
"function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(fiber);
}
function getStackAddendumByWorkInProgressFiber(workInProgress) {
var info = "";
do {
a: switch (workInProgress.tag) {
case 0:
case 1:
case 2:
case 5:
var owner = workInProgress._debugOwner,
source = workInProgress._debugSource;
var JSCompiler_inline_result = getComponentName(workInProgress);
var ownerName = null;
owner && (ownerName = getComponentName(owner));
owner = source;
JSCompiler_inline_result =
"\n in " +
(JSCompiler_inline_result || "Unknown") +
(owner
? " (at " +
owner.fileName.replace(/^.*[\\\/]/, "") +
":" +
owner.lineNumber +
")"
: ownerName ? " (created by " + ownerName + ")" : "");
break a;
default:
JSCompiler_inline_result = "";
}
info += JSCompiler_inline_result;
workInProgress = workInProgress["return"];
} while (workInProgress);
return info;
}
new Set();
function createUpdateQueue(baseState) {
return {
baseState: baseState,
@ -2084,6 +1988,7 @@ function commitCallbacks(queue, context) {
}
}
function ReactFiberClassComponent(
legacyContext,
scheduleWork,
computeExpirationForFiber,
memoizeProps,
@ -2140,62 +2045,66 @@ function ReactFiberClassComponent(
workInProgress.memoizedState
);
}
var updater = {
isMounted: isMounted,
enqueueSetState: function(instance, partialState, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: partialState,
callback: callback,
isReplace: !1,
isForced: !1,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
},
enqueueReplaceState: function(instance, state, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: state,
callback: callback,
isReplace: !0,
isForced: !1,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
},
enqueueForceUpdate: function(instance, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: null,
callback: callback,
isReplace: !1,
isForced: !0,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
}
};
var cacheContext = legacyContext.cacheContext,
getMaskedContext = legacyContext.getMaskedContext,
getUnmaskedContext = legacyContext.getUnmaskedContext,
isContextConsumer = legacyContext.isContextConsumer,
hasContextChanged = legacyContext.hasContextChanged,
updater = {
isMounted: isMounted,
enqueueSetState: function(instance, partialState, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: partialState,
callback: callback,
isReplace: !1,
isForced: !1,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
},
enqueueReplaceState: function(instance, state, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: state,
callback: callback,
isReplace: !0,
isForced: !1,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
},
enqueueForceUpdate: function(instance, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: null,
callback: callback,
isReplace: !1,
isForced: !0,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
}
};
return {
adoptClassInstance: adoptClassInstance,
callGetDerivedStateFromProps: callGetDerivedStateFromProps,
constructClassInstance: function(workInProgress, props) {
var ctor = workInProgress.type,
unmaskedContext = getUnmaskedContext(workInProgress),
needsContext =
2 === workInProgress.tag && null != workInProgress.type.contextTypes,
needsContext = isContextConsumer(workInProgress),
context = needsContext
? getMaskedContext(workInProgress, unmaskedContext)
: emptyObject;
@ -2212,10 +2121,7 @@ function ReactFiberClassComponent(
workInProgress.memoizedState,
props
));
needsContext &&
((workInProgress = workInProgress.stateNode),
(workInProgress.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext),
(workInProgress.__reactInternalMemoizedMaskedChildContext = context));
needsContext && cacheContext(workInProgress, unmaskedContext, context);
return ctor;
},
mountClassInstance: function(workInProgress, renderExpirationTime) {
@ -2300,7 +2206,7 @@ function ReactFiberClassComponent(
!(
oldProps !== newProps ||
oldState !== renderExpirationTime ||
didPerformWorkStackCursor.current ||
hasContextChanged() ||
(null !== workInProgress.updateQueue &&
workInProgress.updateQueue.hasForceUpdate)
)
@ -2389,7 +2295,7 @@ function ReactFiberClassComponent(
!(
oldProps !== newProps ||
oldContext !== renderExpirationTime ||
didPerformWorkStackCursor.current ||
hasContextChanged() ||
(null !== workInProgress.updateQueue &&
workInProgress.updateQueue.hasForceUpdate)
)
@ -3112,34 +3018,12 @@ function ChildReconciler(shouldTrackSideEffects) {
};
}
var reconcileChildFibers = ChildReconciler(!0),
mountChildFibers = ChildReconciler(!1),
changedBitsStack = [],
currentValueStack = [],
stack = [],
index$1 = -1;
function pushProvider(providerFiber) {
var context = providerFiber.type.context;
index$1 += 1;
changedBitsStack[index$1] = context._changedBits;
currentValueStack[index$1] = context._currentValue;
stack[index$1] = providerFiber;
context._currentValue = providerFiber.pendingProps.value;
context._changedBits = providerFiber.stateNode;
}
function popProvider(providerFiber) {
var changedBits = changedBitsStack[index$1],
currentValue = currentValueStack[index$1];
changedBitsStack[index$1] = null;
currentValueStack[index$1] = null;
stack[index$1] = null;
--index$1;
providerFiber = providerFiber.type.context;
providerFiber._currentValue = currentValue;
providerFiber._changedBits = changedBits;
}
mountChildFibers = ChildReconciler(!1);
function ReactFiberBeginWork(
config,
hostContext,
legacyContext,
newContext,
hydrationContext,
scheduleWork,
computeExpirationForFiber
@ -3236,7 +3120,12 @@ function ReactFiberBeginWork(
changedBits,
renderExpirationTime
) {
for (var fiber = workInProgress.child; null !== fiber; ) {
var fiber = workInProgress.child;
for (
null !== fiber && (fiber["return"] = workInProgress);
null !== fiber;
) {
switch (fiber.tag) {
case 12:
var nextFiber = fiber.stateNode | 0;
@ -3295,7 +3184,7 @@ function ReactFiberBeginWork(
var context = workInProgress.type.context,
newProps = workInProgress.pendingProps,
oldProps = workInProgress.memoizedProps;
if (!didPerformWorkStackCursor.current && oldProps === newProps)
if (!hasLegacyContextChanged() && oldProps === newProps)
return (
(workInProgress.stateNode = 0),
pushProvider(workInProgress),
@ -3382,11 +3271,19 @@ function ReactFiberBeginWork(
shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree,
pushHostContext = hostContext.pushHostContext,
pushHostContainer = hostContext.pushHostContainer,
pushProvider = newContext.pushProvider,
getMaskedContext = legacyContext.getMaskedContext,
getUnmaskedContext = legacyContext.getUnmaskedContext,
hasLegacyContextChanged = legacyContext.hasContextChanged,
pushLegacyContextProvider = legacyContext.pushContextProvider,
pushTopLevelContextObject = legacyContext.pushTopLevelContextObject,
invalidateContextProvider = legacyContext.invalidateContextProvider,
enterHydrationState = hydrationContext.enterHydrationState,
resetHydrationState = hydrationContext.resetHydrationState,
tryToClaimNextHydratableInstance =
hydrationContext.tryToClaimNextHydratableInstance;
config = ReactFiberClassComponent(
legacyContext,
scheduleWork,
computeExpirationForFiber,
function(workInProgress, nextProps) {
@ -3413,7 +3310,7 @@ function ReactFiberBeginWork(
pushHostRootContext(workInProgress);
break;
case 2:
pushContextProvider(workInProgress);
pushLegacyContextProvider(workInProgress);
break;
case 4:
pushHostContainer(
@ -3459,7 +3356,7 @@ function ReactFiberBeginWork(
workInProgress.memoizedState,
props
))),
(props = pushContextProvider(workInProgress)),
(props = pushLegacyContextProvider(workInProgress)),
adoptClassInstance(workInProgress, fn),
mountClassInstance(workInProgress, renderExpirationTime),
(current = finishClassComponent(
@ -3479,7 +3376,7 @@ function ReactFiberBeginWork(
return (
(props = workInProgress.type),
(renderExpirationTime = workInProgress.pendingProps),
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
workInProgress.memoizedProps !== renderExpirationTime
? ((fn = getUnmaskedContext(workInProgress)),
(fn = getMaskedContext(workInProgress, fn)),
@ -3495,7 +3392,7 @@ function ReactFiberBeginWork(
current
);
case 2:
props = pushContextProvider(workInProgress);
props = pushLegacyContextProvider(workInProgress);
null === current
? null === workInProgress.stateNode
? (constructClassInstance(
@ -3577,7 +3474,7 @@ function ReactFiberBeginWork(
updateQueue = workInProgress.memoizedProps;
fn = workInProgress.pendingProps;
unmaskedContext = null !== current ? current.memoizedProps : null;
if (!didPerformWorkStackCursor.current && updateQueue === fn) {
if (!hasLegacyContextChanged() && updateQueue === fn) {
if (
(updateQueue =
workInProgress.mode & 1 &&
@ -3619,7 +3516,7 @@ function ReactFiberBeginWork(
case 7:
return (
(props = workInProgress.pendingProps),
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
workInProgress.memoizedProps !== props ||
(props = workInProgress.memoizedProps),
(fn = props.children),
@ -3649,8 +3546,7 @@ function ReactFiberBeginWork(
workInProgress.stateNode.containerInfo
),
(props = workInProgress.pendingProps),
didPerformWorkStackCursor.current ||
workInProgress.memoizedProps !== props
hasLegacyContextChanged() || workInProgress.memoizedProps !== props
? (null === current
? (workInProgress.child = reconcileChildFibers(
workInProgress,
@ -3681,7 +3577,7 @@ function ReactFiberBeginWork(
case 10:
return (
(renderExpirationTime = workInProgress.pendingProps),
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
workInProgress.memoizedProps !== renderExpirationTime
? (reconcileChildren(
current,
@ -3699,7 +3595,7 @@ function ReactFiberBeginWork(
case 11:
return (
(renderExpirationTime = workInProgress.pendingProps.children),
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
(null !== renderExpirationTime &&
workInProgress.memoizedProps !== renderExpirationTime)
? (reconcileChildren(
@ -3729,7 +3625,7 @@ function ReactFiberBeginWork(
props = fn._currentValue;
var changedBits = fn._changedBits;
if (
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
0 !== changedBits ||
updateQueue !== unmaskedContext
) {
@ -3769,7 +3665,13 @@ function ReactFiberBeginWork(
}
};
}
function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
function ReactFiberCompleteWork(
config,
hostContext,
legacyContext,
newContext,
hydrationContext
) {
function markUpdate(workInProgress) {
workInProgress.effectTag |= 4;
}
@ -3802,6 +3704,9 @@ function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
popHostContext = hostContext.popHostContext,
getHostContext = hostContext.getHostContext,
popHostContainer = hostContext.popHostContainer,
popLegacyContextProvider = legacyContext.popContextProvider,
popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject,
popProvider = newContext.popProvider,
prepareToHydrateHostInstance =
hydrationContext.prepareToHydrateHostInstance,
prepareToHydrateHostTextInstance =
@ -3901,7 +3806,7 @@ function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
return null;
case 2:
return (
popContextProvider(workInProgress),
popLegacyContextProvider(workInProgress),
(current = workInProgress.stateNode),
(newProps = workInProgress.updateQueue),
null !== newProps &&
@ -3914,8 +3819,7 @@ function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
);
case 3:
popHostContainer(workInProgress);
pop(didPerformWorkStackCursor, workInProgress);
pop(contextStackCursor, workInProgress);
popTopLevelLegacyContextObject(workInProgress);
newProps = workInProgress.stateNode;
newProps.pendingContext &&
((newProps.context = newProps.pendingContext),
@ -4099,11 +4003,16 @@ function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
}
function ReactFiberUnwindWork(
hostContext,
legacyContext,
newContext,
scheduleWork,
isAlreadyFailedLegacyErrorBoundary
) {
var popHostContainer = hostContext.popHostContainer,
popHostContext = hostContext.popHostContext;
popHostContext = hostContext.popHostContext,
popLegacyContextProvider = legacyContext.popContextProvider,
popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject,
popProvider = newContext.popProvider;
return {
throwException: function(returnFiber, sourceFiber, rawValue) {
sourceFiber.effectTag |= 512;
@ -4144,7 +4053,7 @@ function ReactFiberUnwindWork(
unwindWork: function(workInProgress) {
switch (workInProgress.tag) {
case 2:
popContextProvider(workInProgress);
popLegacyContextProvider(workInProgress);
var effectTag = workInProgress.effectTag;
return effectTag & 1024
? ((workInProgress.effectTag = (effectTag & -1025) | 64),
@ -4153,8 +4062,7 @@ function ReactFiberUnwindWork(
case 3:
return (
popHostContainer(workInProgress),
pop(didPerformWorkStackCursor, workInProgress),
pop(contextStackCursor, workInProgress),
popTopLevelLegacyContextObject(workInProgress),
(effectTag = workInProgress.effectTag),
effectTag & 1024
? ((workInProgress.effectTag = (effectTag & -1025) | 64),
@ -4170,6 +4078,25 @@ function ReactFiberUnwindWork(
default:
return null;
}
},
unwindInterruptedWork: function(interruptedWork) {
switch (interruptedWork.tag) {
case 2:
popLegacyContextProvider(interruptedWork);
break;
case 3:
popHostContainer(interruptedWork);
popTopLevelLegacyContextObject(interruptedWork);
break;
case 5:
popHostContext(interruptedWork);
break;
case 4:
popHostContainer(interruptedWork);
break;
case 13:
popProvider(interruptedWork);
}
}
};
}
@ -4425,7 +4352,7 @@ function ReactFiberCommitWork(
invariant(!1, "Mutating reconciler is disabled.");
}
var NO_CONTEXT = {};
function ReactFiberHostContext(config) {
function ReactFiberHostContext(config, stack) {
function requiredContext(c) {
invariant(
c !== NO_CONTEXT,
@ -4434,10 +4361,13 @@ function ReactFiberHostContext(config) {
return c;
}
var getChildHostContext = config.getChildHostContext,
getRootHostContext = config.getRootHostContext,
contextStackCursor = { current: NO_CONTEXT },
contextFiberStackCursor = { current: NO_CONTEXT },
rootInstanceStackCursor = { current: NO_CONTEXT };
getRootHostContext = config.getRootHostContext;
config = stack.createCursor;
var push = stack.push,
pop = stack.pop,
contextStackCursor = config(NO_CONTEXT),
contextFiberStackCursor = config(NO_CONTEXT),
rootInstanceStackCursor = config(NO_CONTEXT);
return {
getHostContext: function() {
return requiredContext(contextStackCursor.current);
@ -4467,10 +4397,6 @@ function ReactFiberHostContext(config) {
context !== rootInstance &&
(push(contextFiberStackCursor, fiber, fiber),
push(contextStackCursor, rootInstance, fiber));
},
resetHostContainer: function() {
contextStackCursor.current = NO_CONTEXT;
rootInstanceStackCursor.current = NO_CONTEXT;
}
};
}
@ -4630,22 +4556,198 @@ function ReactFiberHydrationContext(config) {
}
};
}
function ReactFiberScheduler(config) {
function resetContextStack() {
for (; -1 < index; ) (valueStack[index] = null), index--;
function ReactFiberLegacyContext(stack) {
function cacheContext(workInProgress, unmaskedContext, maskedContext) {
workInProgress = workInProgress.stateNode;
workInProgress.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
workInProgress.__reactInternalMemoizedMaskedChildContext = maskedContext;
}
function isContextProvider(fiber) {
return 2 === fiber.tag && null != fiber.type.childContextTypes;
}
function processChildContext(fiber, parentContext) {
var instance = fiber.stateNode,
childContextTypes = fiber.type.childContextTypes;
if ("function" !== typeof instance.getChildContext) return parentContext;
instance = instance.getChildContext();
for (var contextKey in instance)
invariant(
contextKey in childContextTypes,
'%s.getChildContext(): key "%s" is not defined in childContextTypes.',
getComponentName(fiber) || "Unknown",
contextKey
);
return Object.assign({}, parentContext, instance);
}
var createCursor = stack.createCursor,
push = stack.push,
pop = stack.pop,
contextStackCursor = createCursor(emptyObject),
didPerformWorkStackCursor = createCursor(!1),
previousContext = emptyObject;
contextStackCursor.current = emptyObject;
didPerformWorkStackCursor.current = !1;
resetHostContainer();
for (var i = index$1; -1 < i; i--) {
var context = stack[i].type.context;
context._currentValue = context._defaultValue;
context._changedBits = 0;
changedBitsStack[i] = null;
currentValueStack[i] = null;
stack[i] = null;
return {
getUnmaskedContext: function(workInProgress) {
return isContextProvider(workInProgress)
? previousContext
: contextStackCursor.current;
},
cacheContext: cacheContext,
getMaskedContext: function(workInProgress, unmaskedContext) {
var contextTypes = workInProgress.type.contextTypes;
if (!contextTypes) return emptyObject;
var instance = workInProgress.stateNode;
if (
instance &&
instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
)
return instance.__reactInternalMemoizedMaskedChildContext;
var context = {},
key;
for (key in contextTypes) context[key] = unmaskedContext[key];
instance && cacheContext(workInProgress, unmaskedContext, context);
return context;
},
hasContextChanged: function() {
return didPerformWorkStackCursor.current;
},
isContextConsumer: function(fiber) {
return 2 === fiber.tag && null != fiber.type.contextTypes;
},
isContextProvider: isContextProvider,
popContextProvider: function(fiber) {
isContextProvider(fiber) &&
(pop(didPerformWorkStackCursor, fiber), pop(contextStackCursor, fiber));
},
popTopLevelContextObject: function(fiber) {
pop(didPerformWorkStackCursor, fiber);
pop(contextStackCursor, fiber);
},
pushTopLevelContextObject: function(fiber, context, didChange) {
invariant(
null == contextStackCursor.cursor,
"Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."
);
push(contextStackCursor, context, fiber);
push(didPerformWorkStackCursor, didChange, fiber);
},
processChildContext: processChildContext,
pushContextProvider: function(workInProgress) {
if (!isContextProvider(workInProgress)) return !1;
var instance = workInProgress.stateNode;
instance =
(instance && instance.__reactInternalMemoizedMergedChildContext) ||
emptyObject;
previousContext = contextStackCursor.current;
push(contextStackCursor, instance, workInProgress);
push(
didPerformWorkStackCursor,
didPerformWorkStackCursor.current,
workInProgress
);
return !0;
},
invalidateContextProvider: function(workInProgress, didChange) {
var instance = workInProgress.stateNode;
invariant(
instance,
"Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."
);
if (didChange) {
var mergedContext = processChildContext(
workInProgress,
previousContext
);
instance.__reactInternalMemoizedMergedChildContext = mergedContext;
pop(didPerformWorkStackCursor, workInProgress);
pop(contextStackCursor, workInProgress);
push(contextStackCursor, mergedContext, workInProgress);
} else pop(didPerformWorkStackCursor, workInProgress);
push(didPerformWorkStackCursor, didChange, workInProgress);
},
findCurrentUnmaskedContext: function(fiber) {
for (
invariant(
2 === isFiberMountedImpl(fiber) && 2 === fiber.tag,
"Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."
);
3 !== fiber.tag;
) {
if (isContextProvider(fiber))
return fiber.stateNode.__reactInternalMemoizedMergedChildContext;
fiber = fiber["return"];
invariant(
fiber,
"Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."
);
}
return fiber.stateNode.context;
}
index$1 = -1;
};
}
function ReactFiberNewContext(stack) {
var createCursor = stack.createCursor,
push = stack.push,
pop = stack.pop,
providerCursor = createCursor(null),
valueCursor = createCursor(null),
changedBitsCursor = createCursor(0);
return {
pushProvider: function(providerFiber) {
var context = providerFiber.type.context;
push(changedBitsCursor, context._changedBits, providerFiber);
push(valueCursor, context._currentValue, providerFiber);
push(providerCursor, providerFiber, providerFiber);
context._currentValue = providerFiber.pendingProps.value;
context._changedBits = providerFiber.stateNode;
},
popProvider: function(providerFiber) {
var changedBits = changedBitsCursor.current,
currentValue = valueCursor.current;
pop(providerCursor, providerFiber);
pop(valueCursor, providerFiber);
pop(changedBitsCursor, providerFiber);
providerFiber = providerFiber.type.context;
providerFiber._currentValue = currentValue;
providerFiber._changedBits = changedBits;
}
};
}
function ReactFiberStack() {
var valueStack = [],
index = -1;
return {
createCursor: function(defaultValue) {
return { current: defaultValue };
},
isEmpty: function() {
return -1 === index;
},
pop: function(cursor) {
0 > index ||
((cursor.current = valueStack[index]),
(valueStack[index] = null),
index--);
},
push: function(cursor, value) {
index++;
valueStack[index] = cursor.current;
cursor.current = value;
},
checkThatStackIsEmpty: function() {},
resetStackAfterFatalErrorInDev: function() {}
};
}
function ReactFiberScheduler(config) {
function resetStack() {
if (null !== nextUnitOfWork)
for (
var interruptedWork = nextUnitOfWork["return"];
null !== interruptedWork;
)
unwindInterruptedWork(interruptedWork),
(interruptedWork = interruptedWork["return"]);
nextRoot = null;
nextRenderExpirationTime = 0;
nextUnitOfWork = null;
@ -4751,7 +4853,7 @@ function ReactFiberScheduler(config) {
root !== nextRoot ||
null === nextUnitOfWork
)
resetContextStack(),
resetStack(),
(nextRoot = root),
(nextRenderExpirationTime = expirationTime),
(nextUnitOfWork = createWorkInProgress(
@ -4881,7 +4983,7 @@ function ReactFiberScheduler(config) {
!isWorking &&
0 !== nextRenderExpirationTime &&
expirationTime < nextRenderExpirationTime &&
resetContextStack();
resetStack();
(nextRoot === root && isWorking) ||
requestWork(root, expirationTime);
nestedUpdateCount > NESTED_UPDATE_LIMIT &&
@ -5225,25 +5327,37 @@ function ReactFiberScheduler(config) {
nextFlushedRoot.remainingExpirationTime = 0;
hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error));
}
var hostContext = ReactFiberHostContext(config),
hydrationContext = ReactFiberHydrationContext(config),
resetHostContainer = hostContext.resetHostContainer,
var stack = ReactFiberStack(),
hostContext = ReactFiberHostContext(config, stack),
legacyContext = ReactFiberLegacyContext(stack);
stack = ReactFiberNewContext(stack);
var hydrationContext = ReactFiberHydrationContext(config),
beginWork = ReactFiberBeginWork(
config,
hostContext,
legacyContext,
stack,
hydrationContext,
scheduleWork,
computeExpirationForFiber
).beginWork,
completeWork = ReactFiberCompleteWork(config, hostContext, hydrationContext)
.completeWork;
completeWork = ReactFiberCompleteWork(
config,
hostContext,
legacyContext,
stack,
hydrationContext
).completeWork;
hostContext = ReactFiberUnwindWork(
hostContext,
legacyContext,
stack,
scheduleWork,
isAlreadyFailedLegacyErrorBoundary
);
var throwException = hostContext.throwException,
unwindWork = hostContext.unwindWork;
unwindWork = hostContext.unwindWork,
unwindInterruptedWork = hostContext.unwindInterruptedWork;
hostContext = ReactFiberCommitWork(
config,
onCommitPhaseError,
@ -5402,7 +5516,8 @@ function ReactFiberScheduler(config) {
result <= lastUniqueAsyncExpiration &&
(result = lastUniqueAsyncExpiration + 1);
return (lastUniqueAsyncExpiration = result);
}
},
legacyContext: legacyContext
};
}
function ReactFiberReconciler$1(config) {
@ -5417,27 +5532,7 @@ function ReactFiberReconciler$1(config) {
currentTime = container.current;
if (parentComponent) {
parentComponent = parentComponent._reactInternalFiber;
var parentContext;
b: {
invariant(
2 === isFiberMountedImpl(parentComponent) &&
2 === parentComponent.tag,
"Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."
);
for (parentContext = parentComponent; 3 !== parentContext.tag; ) {
if (isContextProvider(parentContext)) {
parentContext =
parentContext.stateNode.__reactInternalMemoizedMergedChildContext;
break b;
}
parentContext = parentContext["return"];
invariant(
parentContext,
"Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."
);
}
parentContext = parentContext.stateNode.context;
}
var parentContext = findCurrentUnmaskedContext(parentComponent);
parentComponent = isContextProvider(parentComponent)
? processChildContext(parentComponent, parentContext)
: parentContext;
@ -5466,7 +5561,11 @@ function ReactFiberReconciler$1(config) {
config = ReactFiberScheduler(config);
var recalculateCurrentTime = config.recalculateCurrentTime,
computeExpirationForFiber = config.computeExpirationForFiber,
scheduleWork = config.scheduleWork;
scheduleWork = config.scheduleWork,
legacyContext = config.legacyContext,
findCurrentUnmaskedContext = legacyContext.findCurrentUnmaskedContext,
isContextProvider = legacyContext.isContextProvider,
processChildContext = legacyContext.processChildContext;
return {
createContainer: function(containerInfo, isAsync, hydrate) {
isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0);

File diff suppressed because it is too large Load Diff

View File

@ -1822,141 +1822,6 @@ function findCurrentHostFiberWithNoPortals(parent) {
}
return null;
}
var valueStack = [],
index = -1;
function pop(cursor) {
0 > index ||
((cursor.current = valueStack[index]), (valueStack[index] = null), index--);
}
function push(cursor, value) {
index++;
valueStack[index] = cursor.current;
cursor.current = value;
}
function getStackAddendumByWorkInProgressFiber(workInProgress) {
var info = "";
do {
a: switch (workInProgress.tag) {
case 0:
case 1:
case 2:
case 5:
var owner = workInProgress._debugOwner,
source = workInProgress._debugSource;
var JSCompiler_inline_result = getComponentName(workInProgress);
var ownerName = null;
owner && (ownerName = getComponentName(owner));
owner = source;
JSCompiler_inline_result =
"\n in " +
(JSCompiler_inline_result || "Unknown") +
(owner
? " (at " +
owner.fileName.replace(/^.*[\\\/]/, "") +
":" +
owner.lineNumber +
")"
: ownerName ? " (created by " + ownerName + ")" : "");
break a;
default:
JSCompiler_inline_result = "";
}
info += JSCompiler_inline_result;
workInProgress = workInProgress["return"];
} while (workInProgress);
return info;
}
var _require = require("ReactFeatureFlags"),
enableGetDerivedStateFromCatch = _require.enableGetDerivedStateFromCatch,
debugRenderPhaseSideEffects = _require.debugRenderPhaseSideEffects,
debugRenderPhaseSideEffectsForStrictMode =
_require.debugRenderPhaseSideEffectsForStrictMode;
new Set();
var contextStackCursor = { current: emptyObject },
didPerformWorkStackCursor = { current: !1 },
previousContext = emptyObject;
function getUnmaskedContext(workInProgress) {
return isContextProvider(workInProgress)
? previousContext
: contextStackCursor.current;
}
function getMaskedContext(workInProgress, unmaskedContext) {
var contextTypes = workInProgress.type.contextTypes;
if (!contextTypes) return emptyObject;
var instance = workInProgress.stateNode;
if (
instance &&
instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
)
return instance.__reactInternalMemoizedMaskedChildContext;
var context = {},
key;
for (key in contextTypes) context[key] = unmaskedContext[key];
instance &&
((workInProgress = workInProgress.stateNode),
(workInProgress.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext),
(workInProgress.__reactInternalMemoizedMaskedChildContext = context));
return context;
}
function isContextProvider(fiber) {
return 2 === fiber.tag && null != fiber.type.childContextTypes;
}
function popContextProvider(fiber) {
isContextProvider(fiber) &&
(pop(didPerformWorkStackCursor, fiber), pop(contextStackCursor, fiber));
}
function pushTopLevelContextObject(fiber, context, didChange) {
invariant(
null == contextStackCursor.cursor,
"Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."
);
push(contextStackCursor, context, fiber);
push(didPerformWorkStackCursor, didChange, fiber);
}
function processChildContext(fiber, parentContext) {
var instance = fiber.stateNode,
childContextTypes = fiber.type.childContextTypes;
if ("function" !== typeof instance.getChildContext) return parentContext;
instance = instance.getChildContext();
for (var contextKey in instance)
invariant(
contextKey in childContextTypes,
'%s.getChildContext(): key "%s" is not defined in childContextTypes.',
getComponentName(fiber) || "Unknown",
contextKey
);
return Object.assign({}, parentContext, instance);
}
function pushContextProvider(workInProgress) {
if (!isContextProvider(workInProgress)) return !1;
var instance = workInProgress.stateNode;
instance =
(instance && instance.__reactInternalMemoizedMergedChildContext) ||
emptyObject;
previousContext = contextStackCursor.current;
push(contextStackCursor, instance, workInProgress);
push(
didPerformWorkStackCursor,
didPerformWorkStackCursor.current,
workInProgress
);
return !0;
}
function invalidateContextProvider(workInProgress, didChange) {
var instance = workInProgress.stateNode;
invariant(
instance,
"Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."
);
if (didChange) {
var mergedContext = processChildContext(workInProgress, previousContext);
instance.__reactInternalMemoizedMergedChildContext = mergedContext;
pop(didPerformWorkStackCursor, workInProgress);
pop(contextStackCursor, workInProgress);
push(contextStackCursor, mergedContext, workInProgress);
} else pop(didPerformWorkStackCursor, workInProgress);
push(didPerformWorkStackCursor, didChange, workInProgress);
}
function FiberNode(tag, pendingProps, key, mode) {
this.tag = tag;
this.key = key;
@ -2123,6 +1988,45 @@ function onCommitRoot(root) {
function onCommitUnmount(fiber) {
"function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(fiber);
}
function getStackAddendumByWorkInProgressFiber(workInProgress) {
var info = "";
do {
a: switch (workInProgress.tag) {
case 0:
case 1:
case 2:
case 5:
var owner = workInProgress._debugOwner,
source = workInProgress._debugSource;
var JSCompiler_inline_result = getComponentName(workInProgress);
var ownerName = null;
owner && (ownerName = getComponentName(owner));
owner = source;
JSCompiler_inline_result =
"\n in " +
(JSCompiler_inline_result || "Unknown") +
(owner
? " (at " +
owner.fileName.replace(/^.*[\\\/]/, "") +
":" +
owner.lineNumber +
")"
: ownerName ? " (created by " + ownerName + ")" : "");
break a;
default:
JSCompiler_inline_result = "";
}
info += JSCompiler_inline_result;
workInProgress = workInProgress["return"];
} while (workInProgress);
return info;
}
var _require = require("ReactFeatureFlags"),
enableGetDerivedStateFromCatch = _require.enableGetDerivedStateFromCatch,
debugRenderPhaseSideEffects = _require.debugRenderPhaseSideEffects,
debugRenderPhaseSideEffectsForStrictMode =
_require.debugRenderPhaseSideEffectsForStrictMode;
new Set();
function createUpdateQueue(baseState) {
return {
baseState: baseState,
@ -2294,6 +2198,7 @@ function callGetDerivedStateFromCatch(ctor, capturedValues) {
return resultState;
}
function ReactFiberClassComponent(
legacyContext,
scheduleWork,
computeExpirationForFiber,
memoizeProps,
@ -2360,62 +2265,66 @@ function ReactFiberClassComponent(
)
);
}
var updater = {
isMounted: isMounted,
enqueueSetState: function(instance, partialState, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: partialState,
callback: callback,
isReplace: !1,
isForced: !1,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
},
enqueueReplaceState: function(instance, state, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: state,
callback: callback,
isReplace: !0,
isForced: !1,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
},
enqueueForceUpdate: function(instance, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: null,
callback: callback,
isReplace: !1,
isForced: !0,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
}
};
var cacheContext = legacyContext.cacheContext,
getMaskedContext = legacyContext.getMaskedContext,
getUnmaskedContext = legacyContext.getUnmaskedContext,
isContextConsumer = legacyContext.isContextConsumer,
hasContextChanged = legacyContext.hasContextChanged,
updater = {
isMounted: isMounted,
enqueueSetState: function(instance, partialState, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: partialState,
callback: callback,
isReplace: !1,
isForced: !1,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
},
enqueueReplaceState: function(instance, state, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: state,
callback: callback,
isReplace: !0,
isForced: !1,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
},
enqueueForceUpdate: function(instance, callback) {
instance = instance._reactInternalFiber;
callback = void 0 === callback ? null : callback;
var expirationTime = computeExpirationForFiber(instance);
insertUpdateIntoFiber(instance, {
expirationTime: expirationTime,
partialState: null,
callback: callback,
isReplace: !1,
isForced: !0,
capturedValue: null,
next: null
});
scheduleWork(instance, expirationTime);
}
};
return {
adoptClassInstance: adoptClassInstance,
callGetDerivedStateFromProps: callGetDerivedStateFromProps,
constructClassInstance: function(workInProgress, props) {
var ctor = workInProgress.type,
unmaskedContext = getUnmaskedContext(workInProgress),
needsContext =
2 === workInProgress.tag && null != workInProgress.type.contextTypes,
needsContext = isContextConsumer(workInProgress),
context = needsContext
? getMaskedContext(workInProgress, unmaskedContext)
: emptyObject;
@ -2436,10 +2345,7 @@ function ReactFiberClassComponent(
workInProgress.memoizedState,
props
));
needsContext &&
((workInProgress = workInProgress.stateNode),
(workInProgress.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext),
(workInProgress.__reactInternalMemoizedMaskedChildContext = context));
needsContext && cacheContext(workInProgress, unmaskedContext, context);
return ctor;
},
mountClassInstance: function(workInProgress, renderExpirationTime) {
@ -2539,7 +2445,7 @@ function ReactFiberClassComponent(
!(
oldProps !== newProps ||
oldState !== renderExpirationTime ||
didPerformWorkStackCursor.current ||
hasContextChanged() ||
(null !== workInProgress.updateQueue &&
workInProgress.updateQueue.hasForceUpdate)
)
@ -2643,7 +2549,7 @@ function ReactFiberClassComponent(
!(
oldProps !== newProps ||
oldContext !== renderExpirationTime ||
didPerformWorkStackCursor.current ||
hasContextChanged() ||
(null !== workInProgress.updateQueue &&
workInProgress.updateQueue.hasForceUpdate)
)
@ -3366,34 +3272,12 @@ function ChildReconciler(shouldTrackSideEffects) {
};
}
var reconcileChildFibers = ChildReconciler(!0),
mountChildFibers = ChildReconciler(!1),
changedBitsStack = [],
currentValueStack = [],
stack = [],
index$1 = -1;
function pushProvider(providerFiber) {
var context = providerFiber.type.context;
index$1 += 1;
changedBitsStack[index$1] = context._changedBits;
currentValueStack[index$1] = context._currentValue;
stack[index$1] = providerFiber;
context._currentValue = providerFiber.pendingProps.value;
context._changedBits = providerFiber.stateNode;
}
function popProvider(providerFiber) {
var changedBits = changedBitsStack[index$1],
currentValue = currentValueStack[index$1];
changedBitsStack[index$1] = null;
currentValueStack[index$1] = null;
stack[index$1] = null;
--index$1;
providerFiber = providerFiber.type.context;
providerFiber._currentValue = currentValue;
providerFiber._changedBits = changedBits;
}
mountChildFibers = ChildReconciler(!1);
function ReactFiberBeginWork(
config,
hostContext,
legacyContext,
newContext,
hydrationContext,
scheduleWork,
computeExpirationForFiber
@ -3499,7 +3383,12 @@ function ReactFiberBeginWork(
changedBits,
renderExpirationTime
) {
for (var fiber = workInProgress.child; null !== fiber; ) {
var fiber = workInProgress.child;
for (
null !== fiber && (fiber["return"] = workInProgress);
null !== fiber;
) {
switch (fiber.tag) {
case 12:
var nextFiber = fiber.stateNode | 0;
@ -3558,7 +3447,7 @@ function ReactFiberBeginWork(
var context = workInProgress.type.context,
newProps = workInProgress.pendingProps,
oldProps = workInProgress.memoizedProps;
if (!didPerformWorkStackCursor.current && oldProps === newProps)
if (!hasLegacyContextChanged() && oldProps === newProps)
return (
(workInProgress.stateNode = 0),
pushProvider(workInProgress),
@ -3645,11 +3534,19 @@ function ReactFiberBeginWork(
shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree,
pushHostContext = hostContext.pushHostContext,
pushHostContainer = hostContext.pushHostContainer,
pushProvider = newContext.pushProvider,
getMaskedContext = legacyContext.getMaskedContext,
getUnmaskedContext = legacyContext.getUnmaskedContext,
hasLegacyContextChanged = legacyContext.hasContextChanged,
pushLegacyContextProvider = legacyContext.pushContextProvider,
pushTopLevelContextObject = legacyContext.pushTopLevelContextObject,
invalidateContextProvider = legacyContext.invalidateContextProvider,
enterHydrationState = hydrationContext.enterHydrationState,
resetHydrationState = hydrationContext.resetHydrationState,
tryToClaimNextHydratableInstance =
hydrationContext.tryToClaimNextHydratableInstance;
config = ReactFiberClassComponent(
legacyContext,
scheduleWork,
computeExpirationForFiber,
function(workInProgress, nextProps) {
@ -3676,7 +3573,7 @@ function ReactFiberBeginWork(
pushHostRootContext(workInProgress);
break;
case 2:
pushContextProvider(workInProgress);
pushLegacyContextProvider(workInProgress);
break;
case 4:
pushHostContainer(
@ -3722,7 +3619,7 @@ function ReactFiberBeginWork(
workInProgress.memoizedState,
props
))),
(props = pushContextProvider(workInProgress)),
(props = pushLegacyContextProvider(workInProgress)),
adoptClassInstance(workInProgress, fn),
mountClassInstance(workInProgress, renderExpirationTime),
(current = finishClassComponent(
@ -3742,7 +3639,7 @@ function ReactFiberBeginWork(
return (
(props = workInProgress.type),
(renderExpirationTime = workInProgress.pendingProps),
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
workInProgress.memoizedProps !== renderExpirationTime
? ((fn = getUnmaskedContext(workInProgress)),
(fn = getMaskedContext(workInProgress, fn)),
@ -3758,7 +3655,7 @@ function ReactFiberBeginWork(
current
);
case 2:
props = pushContextProvider(workInProgress);
props = pushLegacyContextProvider(workInProgress);
null === current
? null === workInProgress.stateNode
? (constructClassInstance(
@ -3840,7 +3737,7 @@ function ReactFiberBeginWork(
updateQueue = workInProgress.memoizedProps;
fn = workInProgress.pendingProps;
unmaskedContext = null !== current ? current.memoizedProps : null;
if (!didPerformWorkStackCursor.current && updateQueue === fn) {
if (!hasLegacyContextChanged() && updateQueue === fn) {
if (
(updateQueue =
workInProgress.mode & 1 &&
@ -3882,7 +3779,7 @@ function ReactFiberBeginWork(
case 7:
return (
(props = workInProgress.pendingProps),
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
workInProgress.memoizedProps !== props ||
(props = workInProgress.memoizedProps),
(fn = props.children),
@ -3912,8 +3809,7 @@ function ReactFiberBeginWork(
workInProgress.stateNode.containerInfo
),
(props = workInProgress.pendingProps),
didPerformWorkStackCursor.current ||
workInProgress.memoizedProps !== props
hasLegacyContextChanged() || workInProgress.memoizedProps !== props
? (null === current
? (workInProgress.child = reconcileChildFibers(
workInProgress,
@ -3944,7 +3840,7 @@ function ReactFiberBeginWork(
case 10:
return (
(renderExpirationTime = workInProgress.pendingProps),
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
workInProgress.memoizedProps !== renderExpirationTime
? (reconcileChildren(
current,
@ -3962,7 +3858,7 @@ function ReactFiberBeginWork(
case 11:
return (
(renderExpirationTime = workInProgress.pendingProps.children),
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
(null !== renderExpirationTime &&
workInProgress.memoizedProps !== renderExpirationTime)
? (reconcileChildren(
@ -3992,7 +3888,7 @@ function ReactFiberBeginWork(
props = fn._currentValue;
var changedBits = fn._changedBits;
if (
didPerformWorkStackCursor.current ||
hasLegacyContextChanged() ||
0 !== changedBits ||
updateQueue !== unmaskedContext
) {
@ -4032,7 +3928,13 @@ function ReactFiberBeginWork(
}
};
}
function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
function ReactFiberCompleteWork(
config,
hostContext,
legacyContext,
newContext,
hydrationContext
) {
function markUpdate(workInProgress) {
workInProgress.effectTag |= 4;
}
@ -4046,6 +3948,9 @@ function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
popHostContext = hostContext.popHostContext,
getHostContext = hostContext.getHostContext,
popHostContainer = hostContext.popHostContainer,
popLegacyContextProvider = legacyContext.popContextProvider,
popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject,
popProvider = newContext.popProvider,
prepareToHydrateHostInstance =
hydrationContext.prepareToHydrateHostInstance,
prepareToHydrateHostTextInstance =
@ -4074,7 +3979,7 @@ function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
return null;
case 2:
return (
popContextProvider(workInProgress),
popLegacyContextProvider(workInProgress),
(current = workInProgress.stateNode),
(newProps = workInProgress.updateQueue),
null !== newProps &&
@ -4087,8 +3992,7 @@ function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
);
case 3:
popHostContainer(workInProgress);
pop(didPerformWorkStackCursor, workInProgress);
pop(contextStackCursor, workInProgress);
popTopLevelLegacyContextObject(workInProgress);
newProps = workInProgress.stateNode;
newProps.pendingContext &&
((newProps.context = newProps.pendingContext),
@ -4304,11 +4208,16 @@ function ReactFiberCompleteWork(config, hostContext, hydrationContext) {
}
function ReactFiberUnwindWork(
hostContext,
legacyContext,
newContext,
scheduleWork,
isAlreadyFailedLegacyErrorBoundary
) {
var popHostContainer = hostContext.popHostContainer,
popHostContext = hostContext.popHostContext;
popHostContext = hostContext.popHostContext,
popLegacyContextProvider = legacyContext.popContextProvider,
popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject,
popProvider = newContext.popProvider;
return {
throwException: function(returnFiber, sourceFiber, rawValue) {
sourceFiber.effectTag |= 512;
@ -4352,7 +4261,7 @@ function ReactFiberUnwindWork(
unwindWork: function(workInProgress) {
switch (workInProgress.tag) {
case 2:
popContextProvider(workInProgress);
popLegacyContextProvider(workInProgress);
var effectTag = workInProgress.effectTag;
return effectTag & 1024
? ((workInProgress.effectTag = (effectTag & -1025) | 64),
@ -4361,8 +4270,7 @@ function ReactFiberUnwindWork(
case 3:
return (
popHostContainer(workInProgress),
pop(didPerformWorkStackCursor, workInProgress),
pop(contextStackCursor, workInProgress),
popTopLevelLegacyContextObject(workInProgress),
(effectTag = workInProgress.effectTag),
effectTag & 1024
? ((workInProgress.effectTag = (effectTag & -1025) | 64),
@ -4378,6 +4286,25 @@ function ReactFiberUnwindWork(
default:
return null;
}
},
unwindInterruptedWork: function(interruptedWork) {
switch (interruptedWork.tag) {
case 2:
popLegacyContextProvider(interruptedWork);
break;
case 3:
popHostContainer(interruptedWork);
popTopLevelLegacyContextObject(interruptedWork);
break;
case 5:
popHostContext(interruptedWork);
break;
case 4:
popHostContainer(interruptedWork);
break;
case 13:
popProvider(interruptedWork);
}
}
};
}
@ -4819,7 +4746,7 @@ function ReactFiberCommitWork(
};
}
var NO_CONTEXT = {};
function ReactFiberHostContext(config) {
function ReactFiberHostContext(config, stack) {
function requiredContext(c) {
invariant(
c !== NO_CONTEXT,
@ -4828,10 +4755,13 @@ function ReactFiberHostContext(config) {
return c;
}
var getChildHostContext = config.getChildHostContext,
getRootHostContext = config.getRootHostContext,
contextStackCursor = { current: NO_CONTEXT },
contextFiberStackCursor = { current: NO_CONTEXT },
rootInstanceStackCursor = { current: NO_CONTEXT };
getRootHostContext = config.getRootHostContext;
config = stack.createCursor;
var push = stack.push,
pop = stack.pop,
contextStackCursor = config(NO_CONTEXT),
contextFiberStackCursor = config(NO_CONTEXT),
rootInstanceStackCursor = config(NO_CONTEXT);
return {
getHostContext: function() {
return requiredContext(contextStackCursor.current);
@ -4861,10 +4791,6 @@ function ReactFiberHostContext(config) {
context !== rootInstance &&
(push(contextFiberStackCursor, fiber, fiber),
push(contextStackCursor, rootInstance, fiber));
},
resetHostContainer: function() {
contextStackCursor.current = NO_CONTEXT;
rootInstanceStackCursor.current = NO_CONTEXT;
}
};
}
@ -5024,22 +4950,198 @@ function ReactFiberHydrationContext(config) {
}
};
}
function ReactFiberScheduler(config) {
function resetContextStack() {
for (; -1 < index; ) (valueStack[index] = null), index--;
function ReactFiberLegacyContext(stack) {
function cacheContext(workInProgress, unmaskedContext, maskedContext) {
workInProgress = workInProgress.stateNode;
workInProgress.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
workInProgress.__reactInternalMemoizedMaskedChildContext = maskedContext;
}
function isContextProvider(fiber) {
return 2 === fiber.tag && null != fiber.type.childContextTypes;
}
function processChildContext(fiber, parentContext) {
var instance = fiber.stateNode,
childContextTypes = fiber.type.childContextTypes;
if ("function" !== typeof instance.getChildContext) return parentContext;
instance = instance.getChildContext();
for (var contextKey in instance)
invariant(
contextKey in childContextTypes,
'%s.getChildContext(): key "%s" is not defined in childContextTypes.',
getComponentName(fiber) || "Unknown",
contextKey
);
return Object.assign({}, parentContext, instance);
}
var createCursor = stack.createCursor,
push = stack.push,
pop = stack.pop,
contextStackCursor = createCursor(emptyObject),
didPerformWorkStackCursor = createCursor(!1),
previousContext = emptyObject;
contextStackCursor.current = emptyObject;
didPerformWorkStackCursor.current = !1;
resetHostContainer();
for (var i = index$1; -1 < i; i--) {
var context = stack[i].type.context;
context._currentValue = context._defaultValue;
context._changedBits = 0;
changedBitsStack[i] = null;
currentValueStack[i] = null;
stack[i] = null;
return {
getUnmaskedContext: function(workInProgress) {
return isContextProvider(workInProgress)
? previousContext
: contextStackCursor.current;
},
cacheContext: cacheContext,
getMaskedContext: function(workInProgress, unmaskedContext) {
var contextTypes = workInProgress.type.contextTypes;
if (!contextTypes) return emptyObject;
var instance = workInProgress.stateNode;
if (
instance &&
instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
)
return instance.__reactInternalMemoizedMaskedChildContext;
var context = {},
key;
for (key in contextTypes) context[key] = unmaskedContext[key];
instance && cacheContext(workInProgress, unmaskedContext, context);
return context;
},
hasContextChanged: function() {
return didPerformWorkStackCursor.current;
},
isContextConsumer: function(fiber) {
return 2 === fiber.tag && null != fiber.type.contextTypes;
},
isContextProvider: isContextProvider,
popContextProvider: function(fiber) {
isContextProvider(fiber) &&
(pop(didPerformWorkStackCursor, fiber), pop(contextStackCursor, fiber));
},
popTopLevelContextObject: function(fiber) {
pop(didPerformWorkStackCursor, fiber);
pop(contextStackCursor, fiber);
},
pushTopLevelContextObject: function(fiber, context, didChange) {
invariant(
null == contextStackCursor.cursor,
"Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."
);
push(contextStackCursor, context, fiber);
push(didPerformWorkStackCursor, didChange, fiber);
},
processChildContext: processChildContext,
pushContextProvider: function(workInProgress) {
if (!isContextProvider(workInProgress)) return !1;
var instance = workInProgress.stateNode;
instance =
(instance && instance.__reactInternalMemoizedMergedChildContext) ||
emptyObject;
previousContext = contextStackCursor.current;
push(contextStackCursor, instance, workInProgress);
push(
didPerformWorkStackCursor,
didPerformWorkStackCursor.current,
workInProgress
);
return !0;
},
invalidateContextProvider: function(workInProgress, didChange) {
var instance = workInProgress.stateNode;
invariant(
instance,
"Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."
);
if (didChange) {
var mergedContext = processChildContext(
workInProgress,
previousContext
);
instance.__reactInternalMemoizedMergedChildContext = mergedContext;
pop(didPerformWorkStackCursor, workInProgress);
pop(contextStackCursor, workInProgress);
push(contextStackCursor, mergedContext, workInProgress);
} else pop(didPerformWorkStackCursor, workInProgress);
push(didPerformWorkStackCursor, didChange, workInProgress);
},
findCurrentUnmaskedContext: function(fiber) {
for (
invariant(
2 === isFiberMountedImpl(fiber) && 2 === fiber.tag,
"Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."
);
3 !== fiber.tag;
) {
if (isContextProvider(fiber))
return fiber.stateNode.__reactInternalMemoizedMergedChildContext;
fiber = fiber["return"];
invariant(
fiber,
"Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."
);
}
return fiber.stateNode.context;
}
index$1 = -1;
};
}
function ReactFiberNewContext(stack) {
var createCursor = stack.createCursor,
push = stack.push,
pop = stack.pop,
providerCursor = createCursor(null),
valueCursor = createCursor(null),
changedBitsCursor = createCursor(0);
return {
pushProvider: function(providerFiber) {
var context = providerFiber.type.context;
push(changedBitsCursor, context._changedBits, providerFiber);
push(valueCursor, context._currentValue, providerFiber);
push(providerCursor, providerFiber, providerFiber);
context._currentValue = providerFiber.pendingProps.value;
context._changedBits = providerFiber.stateNode;
},
popProvider: function(providerFiber) {
var changedBits = changedBitsCursor.current,
currentValue = valueCursor.current;
pop(providerCursor, providerFiber);
pop(valueCursor, providerFiber);
pop(changedBitsCursor, providerFiber);
providerFiber = providerFiber.type.context;
providerFiber._currentValue = currentValue;
providerFiber._changedBits = changedBits;
}
};
}
function ReactFiberStack() {
var valueStack = [],
index = -1;
return {
createCursor: function(defaultValue) {
return { current: defaultValue };
},
isEmpty: function() {
return -1 === index;
},
pop: function(cursor) {
0 > index ||
((cursor.current = valueStack[index]),
(valueStack[index] = null),
index--);
},
push: function(cursor, value) {
index++;
valueStack[index] = cursor.current;
cursor.current = value;
},
checkThatStackIsEmpty: function() {},
resetStackAfterFatalErrorInDev: function() {}
};
}
function ReactFiberScheduler(config) {
function resetStack() {
if (null !== nextUnitOfWork)
for (
var interruptedWork = nextUnitOfWork["return"];
null !== interruptedWork;
)
unwindInterruptedWork(interruptedWork),
(interruptedWork = interruptedWork["return"]);
nextRoot = null;
nextRenderExpirationTime = 0;
nextUnitOfWork = null;
@ -5145,7 +5247,7 @@ function ReactFiberScheduler(config) {
root !== nextRoot ||
null === nextUnitOfWork
)
resetContextStack(),
resetStack(),
(nextRoot = root),
(nextRenderExpirationTime = expirationTime),
(nextUnitOfWork = createWorkInProgress(
@ -5275,7 +5377,7 @@ function ReactFiberScheduler(config) {
!isWorking &&
0 !== nextRenderExpirationTime &&
expirationTime < nextRenderExpirationTime &&
resetContextStack();
resetStack();
(nextRoot === root && isWorking) ||
requestWork(root, expirationTime);
nestedUpdateCount > NESTED_UPDATE_LIMIT &&
@ -5619,25 +5721,37 @@ function ReactFiberScheduler(config) {
nextFlushedRoot.remainingExpirationTime = 0;
hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error));
}
var hostContext = ReactFiberHostContext(config),
hydrationContext = ReactFiberHydrationContext(config),
resetHostContainer = hostContext.resetHostContainer,
var stack = ReactFiberStack(),
hostContext = ReactFiberHostContext(config, stack),
legacyContext = ReactFiberLegacyContext(stack);
stack = ReactFiberNewContext(stack);
var hydrationContext = ReactFiberHydrationContext(config),
beginWork = ReactFiberBeginWork(
config,
hostContext,
legacyContext,
stack,
hydrationContext,
scheduleWork,
computeExpirationForFiber
).beginWork,
completeWork = ReactFiberCompleteWork(config, hostContext, hydrationContext)
.completeWork;
completeWork = ReactFiberCompleteWork(
config,
hostContext,
legacyContext,
stack,
hydrationContext
).completeWork;
hostContext = ReactFiberUnwindWork(
hostContext,
legacyContext,
stack,
scheduleWork,
isAlreadyFailedLegacyErrorBoundary
);
var throwException = hostContext.throwException,
unwindWork = hostContext.unwindWork;
unwindWork = hostContext.unwindWork,
unwindInterruptedWork = hostContext.unwindInterruptedWork;
hostContext = ReactFiberCommitWork(
config,
onCommitPhaseError,
@ -5796,7 +5910,8 @@ function ReactFiberScheduler(config) {
result <= lastUniqueAsyncExpiration &&
(result = lastUniqueAsyncExpiration + 1);
return (lastUniqueAsyncExpiration = result);
}
},
legacyContext: legacyContext
};
}
function ReactFiberReconciler$1(config) {
@ -5811,27 +5926,7 @@ function ReactFiberReconciler$1(config) {
currentTime = container.current;
if (parentComponent) {
parentComponent = parentComponent._reactInternalFiber;
var parentContext;
b: {
invariant(
2 === isFiberMountedImpl(parentComponent) &&
2 === parentComponent.tag,
"Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."
);
for (parentContext = parentComponent; 3 !== parentContext.tag; ) {
if (isContextProvider(parentContext)) {
parentContext =
parentContext.stateNode.__reactInternalMemoizedMergedChildContext;
break b;
}
parentContext = parentContext["return"];
invariant(
parentContext,
"Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."
);
}
parentContext = parentContext.stateNode.context;
}
var parentContext = findCurrentUnmaskedContext(parentComponent);
parentComponent = isContextProvider(parentComponent)
? processChildContext(parentComponent, parentContext)
: parentContext;
@ -5860,7 +5955,11 @@ function ReactFiberReconciler$1(config) {
config = ReactFiberScheduler(config);
var recalculateCurrentTime = config.recalculateCurrentTime,
computeExpirationForFiber = config.computeExpirationForFiber,
scheduleWork = config.scheduleWork;
scheduleWork = config.scheduleWork,
legacyContext = config.legacyContext,
findCurrentUnmaskedContext = legacyContext.findCurrentUnmaskedContext,
isContextProvider = legacyContext.isContextProvider,
processChildContext = legacyContext.processChildContext;
return {
createContainer: function(containerInfo, isAsync, hydrate) {
isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0);

View File

@ -9,6 +9,8 @@
*/
'use strict';
const BatchedBridge = require('BatchedBridge');
// TODO @sema: Adjust types
import type {ReactNativeType} from 'ReactNativeTypes';
@ -20,4 +22,7 @@ if (__DEV__) {
ReactFabric = require('ReactFabric-prod');
}
BatchedBridge.registerCallableModule('ReactFabric', ReactFabric);
module.exports = (ReactFabric: ReactNativeType);