From b1bddd79523f13ff576738307e15e0aa77e593c8 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Thu, 5 Apr 2018 23:45:58 +0200 Subject: [PATCH] Revert "React sync for revisions 9d484ed...1c2876d" This reverts commit 54f23f4b3c487cf516dc92262d0d87efaf2131dc. --- Libraries/Renderer/REVISION | 2 +- Libraries/Renderer/ReactFabric-dev.js | 3298 +++++++--------- Libraries/Renderer/ReactFabric-prod.js | 1025 ++--- Libraries/Renderer/ReactNativeRenderer-dev.js | 3305 +++++++---------- .../Renderer/ReactNativeRenderer-prod.js | 1089 +++--- Libraries/Renderer/shims/ReactTypes.js | 4 +- package.json | 32 +- 7 files changed, 3566 insertions(+), 5189 deletions(-) diff --git a/Libraries/Renderer/REVISION b/Libraries/Renderer/REVISION index fc81a7c7f28..824ff8c33a4 100644 --- a/Libraries/Renderer/REVISION +++ b/Libraries/Renderer/REVISION @@ -1 +1 @@ -1c2876d5b558b8591feb335d8d7204bc46f7da8a \ No newline at end of file +ad9544f48e58f2599a8ea0de1e9f4dd104db30bb \ No newline at end of file diff --git a/Libraries/Renderer/ReactFabric-dev.js b/Libraries/Renderer/ReactFabric-dev.js index 0b7a78516c1..867873cd41d 100644 --- a/Libraries/Renderer/ReactFabric-dev.js +++ b/Libraries/Renderer/ReactFabric-dev.js @@ -25,8 +25,8 @@ var deepDiffer = require("deepDiffer"); var flattenStyle = require("flattenStyle"); var React = require("react"); var emptyObject = require("fbjs/lib/emptyObject"); -var shallowEqual = require("fbjs/lib/shallowEqual"); var checkPropTypes = require("prop-types/checkPropTypes"); +var shallowEqual = require("fbjs/lib/shallowEqual"); var deepFreezeAndThrowOnMutationInDev = require("deepFreezeAndThrowOnMutationInDev"); var FabricUIManager = require("FabricUIManager"); @@ -509,13 +509,11 @@ var injection$1 = { getNodeFromInstance = Injected.getNodeFromInstance; { - !(getNodeFromInstance && getInstanceFromNode) - ? warning( - false, - "EventPluginUtils.injection.injectComponentTree(...): Injected " + - "module is missing getNodeFromInstance or getInstanceFromNode." - ) - : void 0; + warning( + getNodeFromInstance && getInstanceFromNode, + "EventPluginUtils.injection.injectComponentTree(...): Injected " + + "module is missing getNodeFromInstance or getInstanceFromNode." + ); } } }; @@ -551,9 +549,10 @@ var validateEventDispatches = void 0; ? dispatchInstances.length : dispatchInstances ? 1 : 0; - !(instancesIsArr === listenersIsArr && instancesLen === listenersLen) - ? warning(false, "EventPluginUtils: Invalid `event`.") - : void 0; + warning( + instancesIsArr === listenersIsArr && instancesLen === listenersLen, + "EventPluginUtils: Invalid `event`." + ); }; } @@ -811,7 +810,6 @@ var Fragment = 10; var Mode = 11; var ContextConsumer = 12; var ContextProvider = 13; -var ForwardRef = 14; function getParent(inst) { do { @@ -940,7 +938,7 @@ function listenerAtPhase(inst, event, propagationPhase) { */ function accumulateDirectionalDispatches(inst, phase, event) { { - !inst ? warning(false, "Dispatching inst must not be null") : void 0; + warning(inst, "Dispatching inst must not be null"); } var listener = listenerAtPhase(inst, event, phase); if (listener) { @@ -1259,15 +1257,13 @@ SyntheticEvent.extend = function(Interface) { !target.constructor.Interface.hasOwnProperty(prop) && shouldBeReleasedProperties.indexOf(prop) === -1 ) { - !(didWarnForAddedNewProperty || target.isPersistent()) - ? warning( - false, - "This synthetic event is reused for performance reasons. If you're " + - "seeing this, you're adding a new property in the synthetic event object. " + - "The property is never released. See " + - "https://fb.me/react-event-pooling for more information." - ) - : void 0; + warning( + didWarnForAddedNewProperty || target.isPersistent(), + "This synthetic event is reused for performance reasons. If you're " + + "seeing this, you're adding a new property in the synthetic event object. " + + "The property is never released. See " + + "https://fb.me/react-event-pooling for more information." + ); didWarnForAddedNewProperty = true; } target[prop] = value; @@ -1314,18 +1310,16 @@ function getPooledWarningPropertyDefinition(propName, getVal) { function warn(action, result) { var warningCondition = false; - !warningCondition - ? warning( - false, - "This synthetic event is reused for performance reasons. If you're seeing this, " + - "you're %s `%s` on a released/nullified synthetic event. %s. " + - "If you must keep the original synthetic event around, use event.persist(). " + - "See https://fb.me/react-event-pooling for more information.", - action, - propName, - result - ) - : void 0; + warning( + warningCondition, + "This synthetic event is reused for performance reasons. If you're seeing this, " + + "you're %s `%s` on a released/nullified synthetic event. %s. " + + "If you must keep the original synthetic event around, use event.persist(). " + + "See https://fb.me/react-event-pooling for more information.", + action, + propName, + result + ); } } @@ -1443,15 +1437,13 @@ function getTouchIdentifier(_ref) { invariant(identifier != null, "Touch object is missing identifier."); { - !(identifier <= MAX_TOUCH_BANK) - ? warning( - false, - "Touch identifier %s is greater than maximum supported %s which causes " + - "performance issues backfilling array locations for all of the indices.", - identifier, - MAX_TOUCH_BANK - ) - : void 0; + warning( + identifier <= MAX_TOUCH_BANK, + "Touch identifier %s is greater than maximum supported %s which causes " + + "performance issues backfilling array locations for all of the indices.", + identifier, + MAX_TOUCH_BANK + ); } return identifier; } @@ -1550,9 +1542,10 @@ var ResponderTouchHistoryStore = { } { var activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch]; - !(activeRecord != null && activeRecord.touchActive) - ? warning(false, "Cannot find single active touch.") - : void 0; + warning( + activeRecord != null && activeRecord.touchActive, + "Cannot find single active touch." + ); } } } @@ -2363,9 +2356,6 @@ var REACT_CONTEXT_TYPE = hasSymbol ? Symbol["for"]("react.context") : 0xeace; var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol["for"]("react.async_mode") : 0xeacf; -var REACT_FORWARD_REF_TYPE = hasSymbol - ? Symbol["for"]("react.forward_ref") - : 0xead0; var MAYBE_ITERATOR_SYMBOL = typeof Symbol === "function" && Symbol.iterator; var FAUX_ITERATOR_SYMBOL = "@@iterator"; @@ -2647,7 +2637,7 @@ var TouchHistoryMath = { // TODO: this is special because it gets imported during build. -var ReactVersion = "16.3.1"; +var ReactVersion = "16.3.0-alpha.1"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { @@ -3317,17 +3307,15 @@ function findNodeHandle(componentOrHandle) { { var owner = ReactCurrentOwner.current; if (owner !== null && owner.stateNode !== null) { - !owner.stateNode._warnedAboutRefsInRender - ? warning( - false, - "%s is accessing findNodeHandle inside its render(). " + - "render() should be a pure function of props and state. It should " + - "never access something that requires stale data from the previous " + - "render, such as refs. Move this logic to componentDidMount and " + - "componentDidUpdate instead.", - getComponentName(owner) || "A component" - ) - : void 0; + warning( + owner.stateNode._warnedAboutRefsInRender, + "%s is accessing findNodeHandle inside its render(). " + + "render() should be a pure function of props and state. It should " + + "never access something that requires stale data from the previous " + + "render, such as refs. Move this logic to componentDidMount and " + + "componentDidUpdate instead.", + getComponentName(owner) || "A component" + ); owner.stateNode._warnedAboutRefsInRender = true; } @@ -3785,8 +3773,7 @@ var frameDeadline = 0; var frameDeadlineObject = { timeRemaining: function() { return frameDeadline - now(); - }, - didTimeout: false + } }; function setTimeoutCallback() { @@ -3874,10 +3861,9 @@ var Callback = /* */ 32; var DidCapture = /* */ 64; var Ref = /* */ 128; var ErrLog = /* */ 256; -var Snapshot = /* */ 2048; // Union of all host effects -var HostEffectMask = /* */ 2559; +var HostEffectMask = /* */ 511; var Incomplete = /* */ 512; var ShouldCapture = /* */ 1024; @@ -3925,17 +3911,15 @@ function isMounted(component) { if (owner !== null && owner.tag === ClassComponent) { var ownerFiber = owner; var instance = ownerFiber.stateNode; - !instance._warnedAboutRefsInRender - ? warning( - false, - "%s is accessing isMounted inside its render() function. " + - "render() should be a pure function of props and state. It should " + - "never access something that requires stale data from the previous " + - "render, such as refs. Move this logic to componentDidMount and " + - "componentDidUpdate instead.", - getComponentName(ownerFiber) || "A component" - ) - : void 0; + warning( + instance._warnedAboutRefsInRender, + "%s is accessing isMounted inside its render() function. " + + "render() should be a pure function of props and state. It should " + + "never access something that requires stale data from the previous " + + "render, such as refs. Move this logic to componentDidMount and " + + "componentDidUpdate instead.", + getComponentName(ownerFiber) || "A component" + ); instance._warnedAboutRefsInRender = true; } } @@ -4146,6 +4130,876 @@ function findCurrentHostFiberWithNoPortals(parent) { return null; } +var valueStack = []; + +var fiberStack = void 0; + +{ + fiberStack = []; +} + +var index = -1; + +function createCursor(defaultValue) { + return { + current: defaultValue + }; +} + +function pop(cursor, fiber) { + if (index < 0) { + { + warning(false, "Unexpected pop."); + } + return; + } + + { + if (fiber !== fiberStack[index]) { + warning(false, "Unexpected Fiber popped."); + } + } + + cursor.current = valueStack[index]; + + valueStack[index] = null; + + { + fiberStack[index] = null; + } + + index--; +} + +function push(cursor, value, fiber) { + index++; + + valueStack[index] = cursor.current; + + { + fiberStack[index] = fiber; + } + + cursor.current = value; +} + +function reset() { + while (index > -1) { + valueStack[index] = null; + + { + fiberStack[index] = null; + } + + index--; + } +} + +var describeComponentFrame = function(name, source, ownerName) { + return ( + "\n in " + + (name || "Unknown") + + (source + ? " (at " + + source.fileName.replace(/^.*[\\\/]/, "") + + ":" + + source.lineNumber + + ")" + : ownerName ? " (created by " + ownerName + ")" : "") + ); +}; + +function describeFiber(fiber) { + switch (fiber.tag) { + case IndeterminateComponent: + case FunctionalComponent: + case ClassComponent: + case HostComponent: + var owner = fiber._debugOwner; + var source = fiber._debugSource; + var name = getComponentName(fiber); + var ownerName = null; + if (owner) { + ownerName = getComponentName(owner); + } + return describeComponentFrame(name, source, ownerName); + default: + return ""; + } +} + +// This function can only be called with a work-in-progress fiber and +// only during begin or complete phase. Do not call it under any other +// circumstances. +function getStackAddendumByWorkInProgressFiber(workInProgress) { + var info = ""; + var node = workInProgress; + do { + info += describeFiber(node); + // Otherwise this return pointer might point to the wrong tree: + node = node["return"]; + } while (node); + return info; +} + +function getCurrentFiberOwnerName() { + { + var fiber = ReactDebugCurrentFiber.current; + if (fiber === null) { + return null; + } + var owner = fiber._debugOwner; + if (owner !== null && typeof owner !== "undefined") { + return getComponentName(owner); + } + } + return null; +} + +function getCurrentFiberStackAddendum() { + { + var fiber = ReactDebugCurrentFiber.current; + if (fiber === null) { + return null; + } + // Safe because if current fiber exists, we are reconciling, + // and it is guaranteed to be the work-in-progress version. + return getStackAddendumByWorkInProgressFiber(fiber); + } + return null; +} + +function resetCurrentFiber() { + ReactDebugCurrentFrame.getCurrentStack = null; + ReactDebugCurrentFiber.current = null; + ReactDebugCurrentFiber.phase = null; +} + +function setCurrentFiber(fiber) { + ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackAddendum; + ReactDebugCurrentFiber.current = fiber; + ReactDebugCurrentFiber.phase = null; +} + +function setCurrentPhase(phase) { + ReactDebugCurrentFiber.phase = phase; +} + +var ReactDebugCurrentFiber = { + current: null, + phase: null, + resetCurrentFiber: resetCurrentFiber, + setCurrentFiber: setCurrentFiber, + setCurrentPhase: setCurrentPhase, + getCurrentFiberOwnerName: getCurrentFiberOwnerName, + getCurrentFiberStackAddendum: getCurrentFiberStackAddendum +}; + +var debugRenderPhaseSideEffects = false; +var debugRenderPhaseSideEffectsForStrictMode = false; + +var enableUserTimingAPI = true; +var enableGetDerivedStateFromCatch = false; +var warnAboutDeprecatedLifecycles = false; +var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; + +// React Fabric uses persistent reconciler. +var enableMutatingReconciler = false; +var enableNoopReconciler = false; +var enablePersistentReconciler = true; + +// Only used in www builds. + +// Prefix measurements so that it's possible to filter them. +// Longer prefixes are hard to read in DevTools. +var reactEmoji = "\u269B"; +var warningEmoji = "\u26D4"; +var supportsUserTiming = + typeof performance !== "undefined" && + typeof performance.mark === "function" && + typeof performance.clearMarks === "function" && + typeof performance.measure === "function" && + typeof performance.clearMeasures === "function"; + +// Keep track of current fiber so that we know the path to unwind on pause. +// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them? +var currentFiber = null; +// If we're in the middle of user code, which fiber and method is it? +// Reusing `currentFiber` would be confusing for this because user code fiber +// can change during commit phase too, but we don't need to unwind it (since +// lifecycles in the commit phase don't resemble a tree). +var currentPhase = null; +var currentPhaseFiber = null; +// Did lifecycle hook schedule an update? This is often a performance problem, +// so we will keep track of it, and include it in the report. +// Track commits caused by cascading updates. +var isCommitting = false; +var hasScheduledUpdateInCurrentCommit = false; +var hasScheduledUpdateInCurrentPhase = false; +var commitCountInCurrentWorkLoop = 0; +var effectCountInCurrentCommit = 0; +var isWaitingForCallback = false; +// During commits, we only show a measurement once per method name +// to avoid stretch the commit phase with measurement overhead. +var labelsInCurrentCommit = new Set(); + +var formatMarkName = function(markName) { + return reactEmoji + " " + markName; +}; + +var formatLabel = function(label, warning$$1) { + var prefix = warning$$1 ? warningEmoji + " " : reactEmoji + " "; + var suffix = warning$$1 ? " Warning: " + warning$$1 : ""; + return "" + prefix + label + suffix; +}; + +var beginMark = function(markName) { + performance.mark(formatMarkName(markName)); +}; + +var clearMark = function(markName) { + performance.clearMarks(formatMarkName(markName)); +}; + +var endMark = function(label, markName, warning$$1) { + var formattedMarkName = formatMarkName(markName); + var formattedLabel = formatLabel(label, warning$$1); + try { + performance.measure(formattedLabel, formattedMarkName); + } catch (err) {} + // If previous mark was missing for some reason, this will throw. + // This could only happen if React crashed in an unexpected place earlier. + // Don't pile on with more errors. + + // Clear marks immediately to avoid growing buffer. + performance.clearMarks(formattedMarkName); + performance.clearMeasures(formattedLabel); +}; + +var getFiberMarkName = function(label, debugID) { + return label + " (#" + debugID + ")"; +}; + +var getFiberLabel = function(componentName, isMounted, phase) { + if (phase === null) { + // These are composite component total time measurements. + return componentName + " [" + (isMounted ? "update" : "mount") + "]"; + } else { + // Composite component methods. + return componentName + "." + phase; + } +}; + +var beginFiberMark = function(fiber, phase) { + var componentName = getComponentName(fiber) || "Unknown"; + var debugID = fiber._debugID; + var isMounted = fiber.alternate !== null; + var label = getFiberLabel(componentName, isMounted, phase); + + if (isCommitting && labelsInCurrentCommit.has(label)) { + // During the commit phase, we don't show duplicate labels because + // there is a fixed overhead for every measurement, and we don't + // want to stretch the commit phase beyond necessary. + return false; + } + labelsInCurrentCommit.add(label); + + var markName = getFiberMarkName(label, debugID); + beginMark(markName); + return true; +}; + +var clearFiberMark = function(fiber, phase) { + var componentName = getComponentName(fiber) || "Unknown"; + var debugID = fiber._debugID; + var isMounted = fiber.alternate !== null; + var label = getFiberLabel(componentName, isMounted, phase); + var markName = getFiberMarkName(label, debugID); + clearMark(markName); +}; + +var endFiberMark = function(fiber, phase, warning$$1) { + var componentName = getComponentName(fiber) || "Unknown"; + var debugID = fiber._debugID; + var isMounted = fiber.alternate !== null; + var label = getFiberLabel(componentName, isMounted, phase); + var markName = getFiberMarkName(label, debugID); + endMark(label, markName, warning$$1); +}; + +var shouldIgnoreFiber = function(fiber) { + // Host components should be skipped in the timeline. + // We could check typeof fiber.type, but does this work with RN? + switch (fiber.tag) { + case HostRoot: + case HostComponent: + case HostText: + case HostPortal: + case CallComponent: + case ReturnComponent: + case Fragment: + case ContextProvider: + case ContextConsumer: + return true; + default: + return false; + } +}; + +var clearPendingPhaseMeasurement = function() { + if (currentPhase !== null && currentPhaseFiber !== null) { + clearFiberMark(currentPhaseFiber, currentPhase); + } + currentPhaseFiber = null; + currentPhase = null; + hasScheduledUpdateInCurrentPhase = false; +}; + +var pauseTimers = function() { + // Stops all currently active measurements so that they can be resumed + // if we continue in a later deferred loop from the same unit of work. + var fiber = currentFiber; + while (fiber) { + if (fiber._debugIsCurrentlyTiming) { + endFiberMark(fiber, null, null); + } + fiber = fiber["return"]; + } +}; + +var resumeTimersRecursively = function(fiber) { + if (fiber["return"] !== null) { + resumeTimersRecursively(fiber["return"]); + } + if (fiber._debugIsCurrentlyTiming) { + beginFiberMark(fiber, null); + } +}; + +var resumeTimers = function() { + // Resumes all measurements that were active during the last deferred loop. + if (currentFiber !== null) { + resumeTimersRecursively(currentFiber); + } +}; + +function recordEffect() { + if (enableUserTimingAPI) { + effectCountInCurrentCommit++; + } +} + +function recordScheduleUpdate() { + if (enableUserTimingAPI) { + if (isCommitting) { + hasScheduledUpdateInCurrentCommit = true; + } + if ( + currentPhase !== null && + currentPhase !== "componentWillMount" && + currentPhase !== "componentWillReceiveProps" + ) { + hasScheduledUpdateInCurrentPhase = true; + } + } +} + +function startRequestCallbackTimer() { + if (enableUserTimingAPI) { + if (supportsUserTiming && !isWaitingForCallback) { + isWaitingForCallback = true; + beginMark("(Waiting for async callback...)"); + } + } +} + +function stopRequestCallbackTimer(didExpire) { + if (enableUserTimingAPI) { + if (supportsUserTiming) { + isWaitingForCallback = false; + var warning$$1 = didExpire ? "React was blocked by main thread" : null; + endMark( + "(Waiting for async callback...)", + "(Waiting for async callback...)", + warning$$1 + ); + } + } +} + +function startWorkTimer(fiber) { + if (enableUserTimingAPI) { + if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { + return; + } + // If we pause, this is the fiber to unwind from. + currentFiber = fiber; + if (!beginFiberMark(fiber, null)) { + return; + } + fiber._debugIsCurrentlyTiming = true; + } +} + +function cancelWorkTimer(fiber) { + if (enableUserTimingAPI) { + if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { + return; + } + // Remember we shouldn't complete measurement for this fiber. + // Otherwise flamechart will be deep even for small updates. + fiber._debugIsCurrentlyTiming = false; + clearFiberMark(fiber, null); + } +} + +function stopWorkTimer(fiber) { + if (enableUserTimingAPI) { + if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { + return; + } + // If we pause, its parent is the fiber to unwind from. + currentFiber = fiber["return"]; + if (!fiber._debugIsCurrentlyTiming) { + return; + } + fiber._debugIsCurrentlyTiming = false; + endFiberMark(fiber, null, null); + } +} + +function stopFailedWorkTimer(fiber) { + if (enableUserTimingAPI) { + if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { + return; + } + // If we pause, its parent is the fiber to unwind from. + currentFiber = fiber["return"]; + if (!fiber._debugIsCurrentlyTiming) { + return; + } + fiber._debugIsCurrentlyTiming = false; + var warning$$1 = "An error was thrown inside this error boundary"; + endFiberMark(fiber, null, warning$$1); + } +} + +function startPhaseTimer(fiber, phase) { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + clearPendingPhaseMeasurement(); + if (!beginFiberMark(fiber, phase)) { + return; + } + currentPhaseFiber = fiber; + currentPhase = phase; + } +} + +function stopPhaseTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + if (currentPhase !== null && currentPhaseFiber !== null) { + var warning$$1 = hasScheduledUpdateInCurrentPhase + ? "Scheduled a cascading update" + : null; + endFiberMark(currentPhaseFiber, currentPhase, warning$$1); + } + currentPhase = null; + currentPhaseFiber = null; + } +} + +function startWorkLoopTimer(nextUnitOfWork) { + if (enableUserTimingAPI) { + currentFiber = nextUnitOfWork; + if (!supportsUserTiming) { + return; + } + commitCountInCurrentWorkLoop = 0; + // This is top level call. + // Any other measurements are performed within. + beginMark("(React Tree Reconciliation)"); + // Resume any measurements that were in progress during the last loop. + resumeTimers(); + } +} + +function stopWorkLoopTimer(interruptedBy) { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + var warning$$1 = null; + if (interruptedBy !== null) { + if (interruptedBy.tag === HostRoot) { + warning$$1 = "A top-level update interrupted the previous render"; + } else { + var componentName = getComponentName(interruptedBy) || "Unknown"; + warning$$1 = + "An update to " + componentName + " interrupted the previous render"; + } + } else if (commitCountInCurrentWorkLoop > 1) { + warning$$1 = "There were cascading updates"; + } + commitCountInCurrentWorkLoop = 0; + // Pause any measurements until the next loop. + pauseTimers(); + endMark( + "(React Tree Reconciliation)", + "(React Tree Reconciliation)", + warning$$1 + ); + } +} + +function startCommitTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + isCommitting = true; + hasScheduledUpdateInCurrentCommit = false; + labelsInCurrentCommit.clear(); + beginMark("(Committing Changes)"); + } +} + +function stopCommitTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + + var warning$$1 = null; + if (hasScheduledUpdateInCurrentCommit) { + warning$$1 = "Lifecycle hook scheduled a cascading update"; + } else if (commitCountInCurrentWorkLoop > 0) { + warning$$1 = "Caused by a cascading update in earlier commit"; + } + hasScheduledUpdateInCurrentCommit = false; + commitCountInCurrentWorkLoop++; + isCommitting = false; + labelsInCurrentCommit.clear(); + + endMark("(Committing Changes)", "(Committing Changes)", warning$$1); + } +} + +function startCommitHostEffectsTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + effectCountInCurrentCommit = 0; + beginMark("(Committing Host Effects)"); + } +} + +function stopCommitHostEffectsTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + var count = effectCountInCurrentCommit; + effectCountInCurrentCommit = 0; + endMark( + "(Committing Host Effects: " + count + " Total)", + "(Committing Host Effects)", + null + ); + } +} + +function startCommitLifeCyclesTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + effectCountInCurrentCommit = 0; + beginMark("(Calling Lifecycle Methods)"); + } +} + +function stopCommitLifeCyclesTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + var count = effectCountInCurrentCommit; + effectCountInCurrentCommit = 0; + endMark( + "(Calling Lifecycle Methods: " + count + " Total)", + "(Calling Lifecycle Methods)", + null + ); + } +} + +var warnedAboutMissingGetChildContext = void 0; + +{ + warnedAboutMissingGetChildContext = {}; +} + +// A cursor to the current merged context object on the stack. +var contextStackCursor = createCursor(emptyObject); +// A cursor to a boolean indicating whether the context has changed. +var didPerformWorkStackCursor = createCursor(false); +// Keep track of the previous context object that was on the stack. +// We use this to get access to the parent context after we have already +// pushed the next context provider, and now need to merge their contexts. +var previousContext = emptyObject; + +function getUnmaskedContext(workInProgress) { + var hasOwnContext = isContextProvider(workInProgress); + if (hasOwnContext) { + // If the fiber is a context provider itself, when we read its context + // we have already pushed its own child context on the stack. A context + // provider should not "see" its own child context. Therefore we read the + // previous (parent) context instead for a context provider. + return previousContext; + } + return contextStackCursor.current; +} + +function cacheContext(workInProgress, unmaskedContext, maskedContext) { + var instance = workInProgress.stateNode; + instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; + instance.__reactInternalMemoizedMaskedChildContext = maskedContext; +} + +function getMaskedContext(workInProgress, unmaskedContext) { + var type = workInProgress.type; + var contextTypes = type.contextTypes; + if (!contextTypes) { + return emptyObject; + } + + // Avoid recreating masked context unless unmasked context has changed. + // Failing to do this will result in unnecessary calls to componentWillReceiveProps. + // This may trigger infinite loops if componentWillReceiveProps calls setState. + var instance = workInProgress.stateNode; + if ( + instance && + instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext + ) { + return instance.__reactInternalMemoizedMaskedChildContext; + } + + var context = {}; + for (var key in contextTypes) { + context[key] = unmaskedContext[key]; + } + + { + var name = getComponentName(workInProgress) || "Unknown"; + checkPropTypes( + contextTypes, + context, + "context", + name, + ReactDebugCurrentFiber.getCurrentFiberStackAddendum + ); + } + + // Cache unmasked context so we can avoid recreating masked context unless necessary. + // Context is created before the class component is instantiated so check for instance. + if (instance) { + cacheContext(workInProgress, unmaskedContext, context); + } + + return context; +} + +function hasContextChanged() { + return didPerformWorkStackCursor.current; +} + +function isContextConsumer(fiber) { + return fiber.tag === ClassComponent && fiber.type.contextTypes != null; +} + +function isContextProvider(fiber) { + return fiber.tag === ClassComponent && fiber.type.childContextTypes != null; +} + +function popContextProvider(fiber) { + if (!isContextProvider(fiber)) { + return; + } + + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} + +function popTopLevelContextObject(fiber) { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} + +function pushTopLevelContextObject(fiber, context, didChange) { + invariant( + contextStackCursor.cursor == null, + "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; + var childContextTypes = fiber.type.childContextTypes; + + // TODO (bvaughn) Replace this behavior with an invariant() in the future. + // It has only been added in Fiber to match the (unintentional) behavior in Stack. + if (typeof instance.getChildContext !== "function") { + { + var componentName = getComponentName(fiber) || "Unknown"; + + if (!warnedAboutMissingGetChildContext[componentName]) { + warnedAboutMissingGetChildContext[componentName] = true; + warning( + false, + "%s.childContextTypes is specified but there is no getChildContext() method " + + "on the instance. You can either define getChildContext() on %s or remove " + + "childContextTypes from it.", + componentName, + componentName + ); + } + } + return parentContext; + } + + var childContext = void 0; + { + ReactDebugCurrentFiber.setCurrentPhase("getChildContext"); + } + startPhaseTimer(fiber, "getChildContext"); + childContext = instance.getChildContext(); + stopPhaseTimer(); + { + ReactDebugCurrentFiber.setCurrentPhase(null); + } + for (var contextKey in childContext) { + invariant( + contextKey in childContextTypes, + '%s.getChildContext(): key "%s" is not defined in childContextTypes.', + getComponentName(fiber) || "Unknown", + contextKey + ); + } + { + var name = getComponentName(fiber) || "Unknown"; + checkPropTypes( + childContextTypes, + childContext, + "child context", + name, + // In practice, there is one case in which we won't get a stack. It's when + // somebody calls unstable_renderSubtreeIntoContainer() and we process + // context from the parent component instance. The stack will be missing + // because it's outside of the reconciliation, and so the pointer has not + // been set. This is rare and doesn't matter. We'll also remove that API. + ReactDebugCurrentFiber.getCurrentFiberStackAddendum + ); + } + + return Object.assign({}, parentContext, childContext); +} + +function pushContextProvider(workInProgress) { + if (!isContextProvider(workInProgress)) { + return false; + } + + var instance = workInProgress.stateNode; + // We push the context as early as possible to ensure stack integrity. + // If the instance does not exist yet, we will push null at first, + // and replace it on the stack later when invalidating the context. + var memoizedMergedChildContext = + (instance && instance.__reactInternalMemoizedMergedChildContext) || + emptyObject; + + // Remember the parent context so we can merge with it later. + // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. + previousContext = contextStackCursor.current; + push(contextStackCursor, memoizedMergedChildContext, workInProgress); + push( + didPerformWorkStackCursor, + didPerformWorkStackCursor.current, + workInProgress + ); + + return true; +} + +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) { + // Merge parent and own context. + // Skip this if we're not updating due to sCU. + // This avoids unnecessarily recomputing memoized values. + var mergedContext = processChildContext(workInProgress, previousContext); + instance.__reactInternalMemoizedMergedChildContext = mergedContext; + + // Replace the old (or empty) context with the new one. + // It is important to unwind the context in the reverse order. + pop(didPerformWorkStackCursor, workInProgress); + pop(contextStackCursor, workInProgress); + // Now push the new context and mark that it has changed. + push(contextStackCursor, mergedContext, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); + } else { + pop(didPerformWorkStackCursor, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); + } +} + +function resetContext() { + previousContext = emptyObject; + contextStackCursor.current = emptyObject; + didPerformWorkStackCursor.current = false; +} + +function findCurrentUnmaskedContext(fiber) { + // Currently this is only used with renderSubtreeIntoContainer; not sure if it + // makes sense elsewhere + invariant( + isFiberMounted(fiber) && fiber.tag === ClassComponent, + "Expected subtree parent to be a mounted class component. " + + "This error is likely caused by a bug in React. Please file an issue." + ); + + var node = fiber; + while (node.tag !== HostRoot) { + if (isContextProvider(node)) { + return node.stateNode.__reactInternalMemoizedMergedChildContext; + } + var parent = node["return"]; + invariant( + parent, + "Found unexpected detached subtree parent. " + + "This error is likely caused by a bug in React. Please file an issue." + ); + node = parent; + } + return node.stateNode.context; +} + // Max 31 bit integer. The max integer size in V8 for 32-bit systems. // Math.pow(2, 30) - 1 // 0b111111111111111111111111111111 @@ -4388,9 +5242,6 @@ function createFiberFromElement(element, mode, expirationTime) { // This is a consumer fiberTag = ContextConsumer; break; - case REACT_FORWARD_REF_TYPE: - fiberTag = ForwardRef; - break; default: if (typeof type.tag === "number") { // Currently assumed to be a continuation and therefore is a @@ -4488,47 +5339,6 @@ function createFiberFromPortal(portal, mode, expirationTime) { return fiber; } -// Used for stashing WIP properties to replay failed work in DEV. -function assignFiberPropertiesInDEV(target, source) { - if (target === null) { - // This Fiber's initial properties will always be overwritten. - // We only use a Fiber to ensure the same hidden class so DEV isn't slow. - target = createFiber(IndeterminateComponent, null, null, NoContext); - } - - // This is intentionally written as a list of all properties. - // We tried to use Object.assign() instead but this is called in - // the hottest path, and Object.assign() was too slow: - // https://github.com/facebook/react/issues/12502 - // This code is DEV-only so size is not a concern. - - target.tag = source.tag; - target.key = source.key; - target.type = source.type; - target.stateNode = source.stateNode; - target["return"] = source["return"]; - target.child = source.child; - target.sibling = source.sibling; - target.index = source.index; - target.ref = source.ref; - target.pendingProps = source.pendingProps; - target.memoizedProps = source.memoizedProps; - target.updateQueue = source.updateQueue; - target.memoizedState = source.memoizedState; - target.mode = source.mode; - target.effectTag = source.effectTag; - target.nextEffect = source.nextEffect; - target.firstEffect = source.firstEffect; - target.lastEffect = source.lastEffect; - target.expirationTime = source.expirationTime; - target.alternate = source.alternate; - target._debugID = source._debugID; - target._debugSource = source._debugSource; - target._debugOwner = source._debugOwner; - target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming; - return target; -} - // TODO: This should be lifted into the renderer. function createFiberRoot(containerInfo, isAsync, hydrate) { @@ -4624,53 +5434,6 @@ function onCommitUnmount(fiber) { } } -var describeComponentFrame = function(name, source, ownerName) { - return ( - "\n in " + - (name || "Unknown") + - (source - ? " (at " + - source.fileName.replace(/^.*[\\\/]/, "") + - ":" + - source.lineNumber + - ")" - : ownerName ? " (created by " + ownerName + ")" : "") - ); -}; - -function describeFiber(fiber) { - switch (fiber.tag) { - case IndeterminateComponent: - case FunctionalComponent: - case ClassComponent: - case HostComponent: - var owner = fiber._debugOwner; - var source = fiber._debugSource; - var name = getComponentName(fiber); - var ownerName = null; - if (owner) { - ownerName = getComponentName(owner); - } - return describeComponentFrame(name, source, ownerName); - default: - return ""; - } -} - -// This function can only be called with a work-in-progress fiber and -// only during begin or complete phase. Do not call it under any other -// circumstances. -function getStackAddendumByWorkInProgressFiber(workInProgress) { - var info = ""; - var node = workInProgress; - do { - info += describeFiber(node); - // Otherwise this return pointer might point to the wrong tree: - node = node["return"]; - } while (node); - return info; -} - /** * Forked from fbjs/warning: * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js @@ -4934,10 +5697,7 @@ var ReactStrictModeWarnings = { ) { pendingComponentWillReceivePropsWarnings.push(fiber); } - if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true - ) { + if (typeof instance.componentWillUpdate === "function") { pendingComponentWillUpdateWarnings.push(fiber); } }; @@ -5008,529 +5768,6 @@ var ReactStrictModeWarnings = { }; } -var debugRenderPhaseSideEffects = false; -var debugRenderPhaseSideEffectsForStrictMode = false; -var enableUserTimingAPI = true; -var enableGetDerivedStateFromCatch = false; -var warnAboutDeprecatedLifecycles = false; -var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; - -// React Fabric uses persistent reconciler. -var enableMutatingReconciler = false; -var enableNoopReconciler = false; -var enablePersistentReconciler = true; - -// Only used in www builds. - -function getCurrentFiberOwnerName() { - { - var fiber = ReactDebugCurrentFiber.current; - if (fiber === null) { - return null; - } - var owner = fiber._debugOwner; - if (owner !== null && typeof owner !== "undefined") { - return getComponentName(owner); - } - } - return null; -} - -function getCurrentFiberStackAddendum() { - { - var fiber = ReactDebugCurrentFiber.current; - if (fiber === null) { - return null; - } - // Safe because if current fiber exists, we are reconciling, - // and it is guaranteed to be the work-in-progress version. - return getStackAddendumByWorkInProgressFiber(fiber); - } - return null; -} - -function resetCurrentFiber() { - ReactDebugCurrentFrame.getCurrentStack = null; - ReactDebugCurrentFiber.current = null; - ReactDebugCurrentFiber.phase = null; -} - -function setCurrentFiber(fiber) { - ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackAddendum; - ReactDebugCurrentFiber.current = fiber; - ReactDebugCurrentFiber.phase = null; -} - -function setCurrentPhase(phase) { - ReactDebugCurrentFiber.phase = phase; -} - -var ReactDebugCurrentFiber = { - current: null, - phase: null, - resetCurrentFiber: resetCurrentFiber, - setCurrentFiber: setCurrentFiber, - setCurrentPhase: setCurrentPhase, - getCurrentFiberOwnerName: getCurrentFiberOwnerName, - getCurrentFiberStackAddendum: getCurrentFiberStackAddendum -}; - -// Prefix measurements so that it's possible to filter them. -// Longer prefixes are hard to read in DevTools. -var reactEmoji = "\u269B"; -var warningEmoji = "\u26D4"; -var supportsUserTiming = - typeof performance !== "undefined" && - typeof performance.mark === "function" && - typeof performance.clearMarks === "function" && - typeof performance.measure === "function" && - typeof performance.clearMeasures === "function"; - -// Keep track of current fiber so that we know the path to unwind on pause. -// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them? -var currentFiber = null; -// If we're in the middle of user code, which fiber and method is it? -// Reusing `currentFiber` would be confusing for this because user code fiber -// can change during commit phase too, but we don't need to unwind it (since -// lifecycles in the commit phase don't resemble a tree). -var currentPhase = null; -var currentPhaseFiber = null; -// Did lifecycle hook schedule an update? This is often a performance problem, -// so we will keep track of it, and include it in the report. -// Track commits caused by cascading updates. -var isCommitting = false; -var hasScheduledUpdateInCurrentCommit = false; -var hasScheduledUpdateInCurrentPhase = false; -var commitCountInCurrentWorkLoop = 0; -var effectCountInCurrentCommit = 0; -var isWaitingForCallback = false; -// During commits, we only show a measurement once per method name -// to avoid stretch the commit phase with measurement overhead. -var labelsInCurrentCommit = new Set(); - -var formatMarkName = function(markName) { - return reactEmoji + " " + markName; -}; - -var formatLabel = function(label, warning$$1) { - var prefix = warning$$1 ? warningEmoji + " " : reactEmoji + " "; - var suffix = warning$$1 ? " Warning: " + warning$$1 : ""; - return "" + prefix + label + suffix; -}; - -var beginMark = function(markName) { - performance.mark(formatMarkName(markName)); -}; - -var clearMark = function(markName) { - performance.clearMarks(formatMarkName(markName)); -}; - -var endMark = function(label, markName, warning$$1) { - var formattedMarkName = formatMarkName(markName); - var formattedLabel = formatLabel(label, warning$$1); - try { - performance.measure(formattedLabel, formattedMarkName); - } catch (err) {} - // If previous mark was missing for some reason, this will throw. - // This could only happen if React crashed in an unexpected place earlier. - // Don't pile on with more errors. - - // Clear marks immediately to avoid growing buffer. - performance.clearMarks(formattedMarkName); - performance.clearMeasures(formattedLabel); -}; - -var getFiberMarkName = function(label, debugID) { - return label + " (#" + debugID + ")"; -}; - -var getFiberLabel = function(componentName, isMounted, phase) { - if (phase === null) { - // These are composite component total time measurements. - return componentName + " [" + (isMounted ? "update" : "mount") + "]"; - } else { - // Composite component methods. - return componentName + "." + phase; - } -}; - -var beginFiberMark = function(fiber, phase) { - var componentName = getComponentName(fiber) || "Unknown"; - var debugID = fiber._debugID; - var isMounted = fiber.alternate !== null; - var label = getFiberLabel(componentName, isMounted, phase); - - if (isCommitting && labelsInCurrentCommit.has(label)) { - // During the commit phase, we don't show duplicate labels because - // there is a fixed overhead for every measurement, and we don't - // want to stretch the commit phase beyond necessary. - return false; - } - labelsInCurrentCommit.add(label); - - var markName = getFiberMarkName(label, debugID); - beginMark(markName); - return true; -}; - -var clearFiberMark = function(fiber, phase) { - var componentName = getComponentName(fiber) || "Unknown"; - var debugID = fiber._debugID; - var isMounted = fiber.alternate !== null; - var label = getFiberLabel(componentName, isMounted, phase); - var markName = getFiberMarkName(label, debugID); - clearMark(markName); -}; - -var endFiberMark = function(fiber, phase, warning$$1) { - var componentName = getComponentName(fiber) || "Unknown"; - var debugID = fiber._debugID; - var isMounted = fiber.alternate !== null; - var label = getFiberLabel(componentName, isMounted, phase); - var markName = getFiberMarkName(label, debugID); - endMark(label, markName, warning$$1); -}; - -var shouldIgnoreFiber = function(fiber) { - // Host components should be skipped in the timeline. - // We could check typeof fiber.type, but does this work with RN? - switch (fiber.tag) { - case HostRoot: - case HostComponent: - case HostText: - case HostPortal: - case CallComponent: - case ReturnComponent: - case Fragment: - case ContextProvider: - case ContextConsumer: - return true; - default: - return false; - } -}; - -var clearPendingPhaseMeasurement = function() { - if (currentPhase !== null && currentPhaseFiber !== null) { - clearFiberMark(currentPhaseFiber, currentPhase); - } - currentPhaseFiber = null; - currentPhase = null; - hasScheduledUpdateInCurrentPhase = false; -}; - -var pauseTimers = function() { - // Stops all currently active measurements so that they can be resumed - // if we continue in a later deferred loop from the same unit of work. - var fiber = currentFiber; - while (fiber) { - if (fiber._debugIsCurrentlyTiming) { - endFiberMark(fiber, null, null); - } - fiber = fiber["return"]; - } -}; - -var resumeTimersRecursively = function(fiber) { - if (fiber["return"] !== null) { - resumeTimersRecursively(fiber["return"]); - } - if (fiber._debugIsCurrentlyTiming) { - beginFiberMark(fiber, null); - } -}; - -var resumeTimers = function() { - // Resumes all measurements that were active during the last deferred loop. - if (currentFiber !== null) { - resumeTimersRecursively(currentFiber); - } -}; - -function recordEffect() { - if (enableUserTimingAPI) { - effectCountInCurrentCommit++; - } -} - -function recordScheduleUpdate() { - if (enableUserTimingAPI) { - if (isCommitting) { - hasScheduledUpdateInCurrentCommit = true; - } - if ( - currentPhase !== null && - currentPhase !== "componentWillMount" && - currentPhase !== "componentWillReceiveProps" - ) { - hasScheduledUpdateInCurrentPhase = true; - } - } -} - -function startRequestCallbackTimer() { - if (enableUserTimingAPI) { - if (supportsUserTiming && !isWaitingForCallback) { - isWaitingForCallback = true; - beginMark("(Waiting for async callback...)"); - } - } -} - -function stopRequestCallbackTimer(didExpire, expirationTime) { - if (enableUserTimingAPI) { - if (supportsUserTiming) { - isWaitingForCallback = false; - var warning$$1 = didExpire ? "React was blocked by main thread" : null; - endMark( - "(Waiting for async callback... will force flush in " + - expirationTime + - " ms)", - "(Waiting for async callback...)", - warning$$1 - ); - } - } -} - -function startWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; - } - // If we pause, this is the fiber to unwind from. - currentFiber = fiber; - if (!beginFiberMark(fiber, null)) { - return; - } - fiber._debugIsCurrentlyTiming = true; - } -} - -function cancelWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; - } - // Remember we shouldn't complete measurement for this fiber. - // Otherwise flamechart will be deep even for small updates. - fiber._debugIsCurrentlyTiming = false; - clearFiberMark(fiber, null); - } -} - -function stopWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; - } - // If we pause, its parent is the fiber to unwind from. - currentFiber = fiber["return"]; - if (!fiber._debugIsCurrentlyTiming) { - return; - } - fiber._debugIsCurrentlyTiming = false; - endFiberMark(fiber, null, null); - } -} - -function stopFailedWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; - } - // If we pause, its parent is the fiber to unwind from. - currentFiber = fiber["return"]; - if (!fiber._debugIsCurrentlyTiming) { - return; - } - fiber._debugIsCurrentlyTiming = false; - var warning$$1 = "An error was thrown inside this error boundary"; - endFiberMark(fiber, null, warning$$1); - } -} - -function startPhaseTimer(fiber, phase) { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - clearPendingPhaseMeasurement(); - if (!beginFiberMark(fiber, phase)) { - return; - } - currentPhaseFiber = fiber; - currentPhase = phase; - } -} - -function stopPhaseTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - if (currentPhase !== null && currentPhaseFiber !== null) { - var warning$$1 = hasScheduledUpdateInCurrentPhase - ? "Scheduled a cascading update" - : null; - endFiberMark(currentPhaseFiber, currentPhase, warning$$1); - } - currentPhase = null; - currentPhaseFiber = null; - } -} - -function startWorkLoopTimer(nextUnitOfWork) { - if (enableUserTimingAPI) { - currentFiber = nextUnitOfWork; - if (!supportsUserTiming) { - return; - } - commitCountInCurrentWorkLoop = 0; - // This is top level call. - // Any other measurements are performed within. - beginMark("(React Tree Reconciliation)"); - // Resume any measurements that were in progress during the last loop. - resumeTimers(); - } -} - -function stopWorkLoopTimer(interruptedBy, didCompleteRoot) { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var warning$$1 = null; - if (interruptedBy !== null) { - if (interruptedBy.tag === HostRoot) { - warning$$1 = "A top-level update interrupted the previous render"; - } else { - var componentName = getComponentName(interruptedBy) || "Unknown"; - warning$$1 = - "An update to " + componentName + " interrupted the previous render"; - } - } else if (commitCountInCurrentWorkLoop > 1) { - warning$$1 = "There were cascading updates"; - } - commitCountInCurrentWorkLoop = 0; - var label = didCompleteRoot - ? "(React Tree Reconciliation: Completed Root)" - : "(React Tree Reconciliation: Yielded)"; - // Pause any measurements until the next loop. - pauseTimers(); - endMark(label, "(React Tree Reconciliation)", warning$$1); - } -} - -function startCommitTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - isCommitting = true; - hasScheduledUpdateInCurrentCommit = false; - labelsInCurrentCommit.clear(); - beginMark("(Committing Changes)"); - } -} - -function stopCommitTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - - var warning$$1 = null; - if (hasScheduledUpdateInCurrentCommit) { - warning$$1 = "Lifecycle hook scheduled a cascading update"; - } else if (commitCountInCurrentWorkLoop > 0) { - warning$$1 = "Caused by a cascading update in earlier commit"; - } - hasScheduledUpdateInCurrentCommit = false; - commitCountInCurrentWorkLoop++; - isCommitting = false; - labelsInCurrentCommit.clear(); - - endMark("(Committing Changes)", "(Committing Changes)", warning$$1); - } -} - -function startCommitSnapshotEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - effectCountInCurrentCommit = 0; - beginMark("(Committing Snapshot Effects)"); - } -} - -function stopCommitSnapshotEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Committing Snapshot Effects: " + count + " Total)", - "(Committing Snapshot Effects)", - null - ); - } -} - -function startCommitHostEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - effectCountInCurrentCommit = 0; - beginMark("(Committing Host Effects)"); - } -} - -function stopCommitHostEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Committing Host Effects: " + count + " Total)", - "(Committing Host Effects)", - null - ); - } -} - -function startCommitLifeCyclesTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - effectCountInCurrentCommit = 0; - beginMark("(Calling Lifecycle Methods)"); - } -} - -function stopCommitLifeCyclesTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Calling Lifecycle Methods: " + count + " Total)", - "(Calling Lifecycle Methods)", - null - ); - } -} - var didWarnUpdateInsideUpdate = void 0; { @@ -5865,26 +6102,23 @@ var isArray = Array.isArray; var didWarnAboutStateAssignmentForComponent = void 0; var didWarnAboutUndefinedDerivedState = void 0; var didWarnAboutUninitializedState = void 0; -var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0; -var didWarnAboutLegacyLifecyclesAndDerivedState = void 0; +var didWarnAboutWillReceivePropsAndDerivedState = void 0; var warnOnInvalidCallback = void 0; { - didWarnAboutStateAssignmentForComponent = new Set(); - didWarnAboutUndefinedDerivedState = new Set(); - didWarnAboutUninitializedState = new Set(); - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); - didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); + didWarnAboutStateAssignmentForComponent = {}; + didWarnAboutUndefinedDerivedState = {}; + didWarnAboutUninitializedState = {}; + didWarnAboutWillReceivePropsAndDerivedState = {}; - var didWarnOnInvalidCallback = new Set(); + var didWarnOnInvalidCallback = {}; warnOnInvalidCallback = function(callback, callerName) { if (callback === null || typeof callback === "function") { return; } var key = callerName + "_" + callback; - if (!didWarnOnInvalidCallback.has(key)) { - didWarnOnInvalidCallback.add(key); + if (!didWarnOnInvalidCallback[key]) { warning( false, "%s(...): Expected the last optional `callback` argument to be a " + @@ -5892,6 +6126,7 @@ var warnOnInvalidCallback = void 0; callerName, callback ); + didWarnOnInvalidCallback[key] = true; } }; @@ -5930,20 +6165,12 @@ function callGetDerivedStateFromCatch(ctor, capturedValues) { } var ReactFiberClassComponent = function( - legacyContext, scheduleWork, computeExpirationForFiber, memoizeProps, memoizeState ) { - var cacheContext = legacyContext.cacheContext, - getMaskedContext = legacyContext.getMaskedContext, - getUnmaskedContext = legacyContext.getUnmaskedContext, - isContextConsumer = legacyContext.isContextConsumer, - hasContextChanged = legacyContext.hasContextChanged; - // Class component state updater - var updater = { isMounted: isMounted, enqueueSetState: function(instance, partialState, callback) { @@ -6034,14 +6261,12 @@ var ReactFiberClassComponent = function( stopPhaseTimer(); { - !(shouldUpdate !== undefined) - ? warning( - false, - "%s.shouldComponentUpdate(): Returned undefined instead of a " + - "boolean value. Make sure to return true or false.", - getComponentName(workInProgress) || "Component" - ) - : void 0; + warning( + shouldUpdate !== undefined, + "%s.shouldComponentUpdate(): Returned undefined instead of a " + + "boolean value. Make sure to return true or false.", + getComponentName(workInProgress) || "Unknown" + ); } return shouldUpdate; @@ -6060,7 +6285,7 @@ var ReactFiberClassComponent = function( var instance = workInProgress.stateNode; var type = workInProgress.type; { - var name = getComponentName(workInProgress) || "Component"; + var name = getComponentName(workInProgress); var renderPresent = instance.render; if (!renderPresent) { @@ -6085,57 +6310,47 @@ var ReactFiberClassComponent = function( !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state; - !noGetInitialStateOnES6 - ? warning( - false, - "getInitialState was defined on %s, a plain JavaScript class. " + - "This is only supported for classes created using React.createClass. " + - "Did you mean to define a state property instead?", - name - ) - : void 0; + warning( + noGetInitialStateOnES6, + "getInitialState was defined on %s, a plain JavaScript class. " + + "This is only supported for classes created using React.createClass. " + + "Did you mean to define a state property instead?", + name + ); var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved; - !noGetDefaultPropsOnES6 - ? warning( - false, - "getDefaultProps was defined on %s, a plain JavaScript class. " + - "This is only supported for classes created using React.createClass. " + - "Use a static property to define defaultProps instead.", - name - ) - : void 0; + warning( + noGetDefaultPropsOnES6, + "getDefaultProps was defined on %s, a plain JavaScript class. " + + "This is only supported for classes created using React.createClass. " + + "Use a static property to define defaultProps instead.", + name + ); var noInstancePropTypes = !instance.propTypes; - !noInstancePropTypes - ? warning( - false, - "propTypes was defined as an instance property on %s. Use a static " + - "property to define propTypes instead.", - name - ) - : void 0; + warning( + noInstancePropTypes, + "propTypes was defined as an instance property on %s. Use a static " + + "property to define propTypes instead.", + name + ); var noInstanceContextTypes = !instance.contextTypes; - !noInstanceContextTypes - ? warning( - false, - "contextTypes was defined as an instance property on %s. Use a static " + - "property to define contextTypes instead.", - name - ) - : void 0; + warning( + noInstanceContextTypes, + "contextTypes was defined as an instance property on %s. Use a static " + + "property to define contextTypes instead.", + name + ); var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== "function"; - !noComponentShouldUpdate - ? warning( - false, - "%s has a method called " + - "componentShouldUpdate(). Did you mean shouldComponentUpdate()? " + - "The name is phrased as a question because the function is " + - "expected to return a value.", - name - ) - : void 0; + warning( + noComponentShouldUpdate, + "%s has a method called " + + "componentShouldUpdate(). Did you mean shouldComponentUpdate()? " + + "The name is phrased as a question because the function is " + + "expected to return a value.", + name + ); if ( type.prototype && type.prototype.isPureReactComponent && @@ -6151,128 +6366,73 @@ var ReactFiberClassComponent = function( } var noComponentDidUnmount = typeof instance.componentDidUnmount !== "function"; - !noComponentDidUnmount - ? warning( - false, - "%s has a method called " + - "componentDidUnmount(). But there is no such lifecycle method. " + - "Did you mean componentWillUnmount()?", - name - ) - : void 0; + warning( + noComponentDidUnmount, + "%s has a method called " + + "componentDidUnmount(). But there is no such lifecycle method. " + + "Did you mean componentWillUnmount()?", + name + ); var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== "function"; - !noComponentDidReceiveProps - ? warning( - false, - "%s has a method called " + - "componentDidReceiveProps(). But there is no such lifecycle method. " + - "If you meant to update the state in response to changing props, " + - "use componentWillReceiveProps(). If you meant to fetch data or " + - "run side-effects or mutations after React has updated the UI, use componentDidUpdate().", - name - ) - : void 0; + warning( + noComponentDidReceiveProps, + "%s has a method called " + + "componentDidReceiveProps(). But there is no such lifecycle method. " + + "If you meant to update the state in response to changing props, " + + "use componentWillReceiveProps(). If you meant to fetch data or " + + "run side-effects or mutations after React has updated the UI, use componentDidUpdate().", + name + ); var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== "function"; - !noComponentWillRecieveProps - ? warning( - false, - "%s has a method called " + - "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", - name - ) - : void 0; + warning( + noComponentWillRecieveProps, + "%s has a method called " + + "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", + name + ); var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== "function"; - !noUnsafeComponentWillRecieveProps - ? warning( - false, - "%s has a method called " + - "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?", - name - ) - : void 0; + warning( + noUnsafeComponentWillRecieveProps, + "%s has a method called " + + "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?", + name + ); var hasMutatedProps = instance.props !== workInProgress.pendingProps; - !(instance.props === undefined || !hasMutatedProps) - ? warning( - false, - "%s(...): When calling super() in `%s`, make sure to pass " + - "up the same props that your component's constructor was passed.", - name, - name - ) - : void 0; + warning( + instance.props === undefined || !hasMutatedProps, + "%s(...): When calling super() in `%s`, make sure to pass " + + "up the same props that your component's constructor was passed.", + name, + name + ); var noInstanceDefaultProps = !instance.defaultProps; - !noInstanceDefaultProps - ? warning( - false, - "Setting defaultProps as an instance property on %s is not supported and will be ignored." + - " Instead, define defaultProps as a static property on %s.", - name, - name - ) - : void 0; + warning( + noInstanceDefaultProps, + "Setting defaultProps as an instance property on %s is not supported and will be ignored." + + " Instead, define defaultProps as a static property on %s.", + name, + name + ); + } - if ( - typeof instance.getSnapshotBeforeUpdate === "function" && - typeof instance.componentDidUpdate !== "function" && - typeof instance.componentDidUpdate !== "function" && - !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(type) - ) { - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(type); - warning( - false, - "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " + - "This component defines getSnapshotBeforeUpdate() only.", - getComponentName(workInProgress) - ); - } - - var noInstanceGetDerivedStateFromProps = - typeof instance.getDerivedStateFromProps !== "function"; - !noInstanceGetDerivedStateFromProps - ? warning( - false, - "%s: getDerivedStateFromProps() is defined as an instance method " + - "and will be ignored. Instead, declare it as a static method.", - name - ) - : void 0; - var noInstanceGetDerivedStateFromCatch = - typeof instance.getDerivedStateFromCatch !== "function"; - !noInstanceGetDerivedStateFromCatch - ? warning( - false, - "%s: getDerivedStateFromCatch() is defined as an instance method " + - "and will be ignored. Instead, declare it as a static method.", - name - ) - : void 0; - var noStaticGetSnapshotBeforeUpdate = - typeof type.getSnapshotBeforeUpdate !== "function"; - !noStaticGetSnapshotBeforeUpdate - ? warning( - false, - "%s: getSnapshotBeforeUpdate() is defined as a static method " + - "and will be ignored. Instead, declare it as an instance method.", - name - ) - : void 0; - var _state = instance.state; - if (_state && (typeof _state !== "object" || isArray(_state))) { - warning(false, "%s.state: must be set to an object or null", name); - } - if (typeof instance.getChildContext === "function") { - !(typeof type.childContextTypes === "object") - ? warning( - false, - "%s.getChildContext(): childContextTypes must be defined in order to " + - "use getChildContext().", - name - ) - : void 0; - } + var state = instance.state; + if (state && (typeof state !== "object" || isArray(state))) { + warning( + false, + "%s.state: must be set to an object or null", + getComponentName(workInProgress) + ); + } + if (typeof instance.getChildContext === "function") { + warning( + typeof type.childContextTypes === "object", + "%s.getChildContext(): childContextTypes must be defined in order to " + + "use getChildContext().", + getComponentName(workInProgress) + ); } } @@ -6320,9 +6480,8 @@ var ReactFiberClassComponent = function( typeof ctor.getDerivedStateFromProps === "function" && state === null ) { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutUninitializedState.has(componentName)) { - didWarnAboutUninitializedState.add(componentName); + var componentName = getComponentName(workInProgress) || "Unknown"; + if (!didWarnAboutUninitializedState[componentName]) { warning( false, "%s: Did not properly initialize state during construction. " + @@ -6330,75 +6489,7 @@ var ReactFiberClassComponent = function( componentName, instance.state === null ? "null" : "undefined" ); - } - } - - // If new component APIs are defined, "unsafe" lifecycles won't be called. - // Warn about these lifecycles if they are present. - // Don't warn about react-lifecycles-compat polyfilled methods though. - if ( - typeof ctor.getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function" - ) { - var foundWillMountName = null; - var foundWillReceivePropsName = null; - var foundWillUpdateName = null; - if ( - typeof instance.componentWillMount === "function" && - instance.componentWillMount.__suppressDeprecationWarning !== true - ) { - foundWillMountName = "componentWillMount"; - } else if (typeof instance.UNSAFE_componentWillMount === "function") { - foundWillMountName = "UNSAFE_componentWillMount"; - } - if ( - typeof instance.componentWillReceiveProps === "function" && - instance.componentWillReceiveProps.__suppressDeprecationWarning !== - true - ) { - foundWillReceivePropsName = "componentWillReceiveProps"; - } else if ( - typeof instance.UNSAFE_componentWillReceiveProps === "function" - ) { - foundWillReceivePropsName = "UNSAFE_componentWillReceiveProps"; - } - if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true - ) { - foundWillUpdateName = "componentWillUpdate"; - } else if (typeof instance.UNSAFE_componentWillUpdate === "function") { - foundWillUpdateName = "UNSAFE_componentWillUpdate"; - } - if ( - foundWillMountName !== null || - foundWillReceivePropsName !== null || - foundWillUpdateName !== null - ) { - var _componentName = getComponentName(workInProgress) || "Component"; - var newApiName = - typeof ctor.getDerivedStateFromProps === "function" - ? "getDerivedStateFromProps()" - : "getSnapshotBeforeUpdate()"; - if ( - !didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName) - ) { - didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName); - warning( - false, - "Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n" + - "%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n" + - "The above lifecycles should be removed. Learn more about this warning here:\n" + - "https://fb.me/react-async-component-lifecycle-hooks", - _componentName, - newApiName, - foundWillMountName !== null ? "\n " + foundWillMountName : "", - foundWillReceivePropsName !== null - ? "\n " + foundWillReceivePropsName - : "", - foundWillUpdateName !== null ? "\n " + foundWillUpdateName : "" - ); - } + didWarnAboutUninitializedState[componentName] = true; } } } @@ -6408,8 +6499,7 @@ var ReactFiberClassComponent = function( var partialState = callGetDerivedStateFromProps( workInProgress, instance, - props, - state + props ); if (partialState !== null && partialState !== undefined) { @@ -6452,7 +6542,7 @@ var ReactFiberClassComponent = function( "%s.componentWillMount(): Assigning directly to this.state is " + "deprecated (except inside a component's " + "constructor). Use setState instead.", - getComponentName(workInProgress) || "Component" + getComponentName(workInProgress) ); } updater.enqueueReplaceState(instance, instance.state, null); @@ -6478,8 +6568,7 @@ var ReactFiberClassComponent = function( if (instance.state !== oldState) { { var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { - didWarnAboutStateAssignmentForComponent.add(componentName); + if (!didWarnAboutStateAssignmentForComponent[componentName]) { warning( false, "%s.componentWillReceiveProps(): Assigning directly to " + @@ -6487,47 +6576,69 @@ var ReactFiberClassComponent = function( "constructor). Use setState instead.", componentName ); + didWarnAboutStateAssignmentForComponent[componentName] = true; } } updater.enqueueReplaceState(instance, instance.state, null); } } - function callGetDerivedStateFromProps( - workInProgress, - instance, - nextProps, - prevState - ) { + function callGetDerivedStateFromProps(workInProgress, instance, props) { var type = workInProgress.type; if (typeof type.getDerivedStateFromProps === "function") { + { + // Don't warn about react-lifecycles-compat polyfilled components + if ( + (typeof instance.componentWillReceiveProps === "function" && + instance.componentWillReceiveProps.__suppressDeprecationWarning !== + true) || + typeof instance.UNSAFE_componentWillReceiveProps === "function" + ) { + var componentName = getComponentName(workInProgress) || "Unknown"; + if (!didWarnAboutWillReceivePropsAndDerivedState[componentName]) { + warning( + false, + "%s: Defines both componentWillReceiveProps() and static " + + "getDerivedStateFromProps() methods. We recommend using " + + "only getDerivedStateFromProps().", + componentName + ); + didWarnAboutWillReceivePropsAndDerivedState[componentName] = true; + } + } + } + if ( debugRenderPhaseSideEffects || (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) ) { // Invoke method an extra time to help detect side-effects. - type.getDerivedStateFromProps.call(null, nextProps, prevState); + type.getDerivedStateFromProps.call( + null, + props, + workInProgress.memoizedState + ); } var partialState = type.getDerivedStateFromProps.call( null, - nextProps, - prevState + props, + workInProgress.memoizedState ); { if (partialState === undefined) { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutUndefinedDerivedState.has(componentName)) { - didWarnAboutUndefinedDerivedState.add(componentName); + var _componentName = getComponentName(workInProgress) || "Unknown"; + if (!didWarnAboutUndefinedDerivedState[_componentName]) { warning( false, "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + "You have returned undefined.", - componentName + _componentName ); + didWarnAboutUndefinedDerivedState[_componentName] = _componentName; } } } @@ -6571,12 +6682,11 @@ var ReactFiberClassComponent = function( } // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - typeof ctor.getDerivedStateFromProps !== "function" && - typeof instance.getSnapshotBeforeUpdate !== "function" && (typeof instance.UNSAFE_componentWillMount === "function" || - typeof instance.componentWillMount === "function") + typeof instance.componentWillMount === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's @@ -6609,20 +6719,16 @@ var ReactFiberClassComponent = function( var newUnmaskedContext = getUnmaskedContext(workInProgress); var newContext = getMaskedContext(workInProgress, newUnmaskedContext); - var hasNewLifecycles = - typeof ctor.getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; - // Note: During these life-cycles, instance.props/instance.state are what // ever the previously attempted to render - not the "current". However, // during componentDidUpdate we pass the "current" props. // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - !hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === "function" || - typeof instance.componentWillReceiveProps === "function") + typeof instance.componentWillReceiveProps === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { if (oldProps !== newProps || oldContext !== newContext) { callComponentWillReceiveProps( @@ -6634,6 +6740,15 @@ var ReactFiberClassComponent = function( } } + var derivedStateFromProps = void 0; + if (oldProps !== newProps) { + derivedStateFromProps = callGetDerivedStateFromProps( + workInProgress, + instance, + newProps + ); + } + // Compute the next state using the memoized state and the update queue. var oldState = workInProgress.memoizedState; // TODO: Previous state can be null. @@ -6670,18 +6785,6 @@ var ReactFiberClassComponent = function( newState = oldState; } - var derivedStateFromProps = void 0; - if (oldProps !== newProps) { - // The prevState parameter should be the partially updated state. - // Otherwise, spreading state in return values could override updates. - derivedStateFromProps = callGetDerivedStateFromProps( - workInProgress, - instance, - newProps, - newState - ); - } - if (derivedStateFromProps !== null && derivedStateFromProps !== undefined) { // Render-phase updates (like this) should not be added to the update queue, // So that multiple render passes do not enqueue multiple updates. @@ -6690,17 +6793,6 @@ var ReactFiberClassComponent = function( newState === null || newState === undefined ? derivedStateFromProps : Object.assign({}, newState, derivedStateFromProps); - - // Update the base state of the update queue. - // FIXME: This is getting ridiculous. Refactor plz! - var _updateQueue = workInProgress.updateQueue; - if (_updateQueue !== null) { - _updateQueue.baseState = Object.assign( - {}, - _updateQueue.baseState, - derivedStateFromProps - ); - } } if (derivedStateFromCatch !== null && derivedStateFromCatch !== undefined) { // Render-phase updates (like this) should not be added to the update queue, @@ -6710,17 +6802,6 @@ var ReactFiberClassComponent = function( newState === null || newState === undefined ? derivedStateFromCatch : Object.assign({}, newState, derivedStateFromCatch); - - // Update the base state of the update queue. - // FIXME: This is getting ridiculous. Refactor plz! - var _updateQueue2 = workInProgress.updateQueue; - if (_updateQueue2 !== null) { - _updateQueue2.baseState = Object.assign( - {}, - _updateQueue2.baseState, - derivedStateFromCatch - ); - } } if ( @@ -6751,22 +6832,22 @@ var ReactFiberClassComponent = function( if (shouldUpdate) { // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillMount === "function" || - typeof instance.componentWillMount === "function") + (typeof instance.UNSAFE_componentWillUpdate === "function" || + typeof instance.componentWillUpdate === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { - startPhaseTimer(workInProgress, "componentWillMount"); - if (typeof instance.componentWillMount === "function") { - instance.componentWillMount(); + startPhaseTimer(workInProgress, "componentWillUpdate"); + if (typeof instance.componentWillUpdate === "function") { + instance.componentWillUpdate(newProps, newState, newContext); } - if (typeof instance.UNSAFE_componentWillMount === "function") { - instance.UNSAFE_componentWillMount(); + if (typeof instance.UNSAFE_componentWillUpdate === "function") { + instance.UNSAFE_componentWillUpdate(newProps, newState, newContext); } stopPhaseTimer(); } - if (typeof instance.componentDidMount === "function") { + if (typeof instance.componentDidUpdate === "function") { workInProgress.effectTag |= Update; } } else { @@ -6803,20 +6884,16 @@ var ReactFiberClassComponent = function( var newUnmaskedContext = getUnmaskedContext(workInProgress); var newContext = getMaskedContext(workInProgress, newUnmaskedContext); - var hasNewLifecycles = - typeof ctor.getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; - // Note: During these life-cycles, instance.props/instance.state are what // ever the previously attempted to render - not the "current". However, // during componentDidUpdate we pass the "current" props. // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - !hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === "function" || - typeof instance.componentWillReceiveProps === "function") + typeof instance.componentWillReceiveProps === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { if (oldProps !== newProps || oldContext !== newContext) { callComponentWillReceiveProps( @@ -6828,12 +6905,20 @@ var ReactFiberClassComponent = function( } } + var derivedStateFromProps = void 0; + if (oldProps !== newProps) { + derivedStateFromProps = callGetDerivedStateFromProps( + workInProgress, + instance, + newProps + ); + } + // Compute the next state using the memoized state and the update queue. var oldState = workInProgress.memoizedState; // TODO: Previous state can be null. var newState = void 0; var derivedStateFromCatch = void 0; - if (workInProgress.updateQueue !== null) { newState = processUpdateQueue( current, @@ -6865,18 +6950,6 @@ var ReactFiberClassComponent = function( newState = oldState; } - var derivedStateFromProps = void 0; - if (oldProps !== newProps) { - // The prevState parameter should be the partially updated state. - // Otherwise, spreading state in return values could override updates. - derivedStateFromProps = callGetDerivedStateFromProps( - workInProgress, - instance, - newProps, - newState - ); - } - if (derivedStateFromProps !== null && derivedStateFromProps !== undefined) { // Render-phase updates (like this) should not be added to the update queue, // So that multiple render passes do not enqueue multiple updates. @@ -6885,17 +6958,6 @@ var ReactFiberClassComponent = function( newState === null || newState === undefined ? derivedStateFromProps : Object.assign({}, newState, derivedStateFromProps); - - // Update the base state of the update queue. - // FIXME: This is getting ridiculous. Refactor plz! - var _updateQueue3 = workInProgress.updateQueue; - if (_updateQueue3 !== null) { - _updateQueue3.baseState = Object.assign( - {}, - _updateQueue3.baseState, - derivedStateFromProps - ); - } } if (derivedStateFromCatch !== null && derivedStateFromCatch !== undefined) { // Render-phase updates (like this) should not be added to the update queue, @@ -6905,17 +6967,6 @@ var ReactFiberClassComponent = function( newState === null || newState === undefined ? derivedStateFromCatch : Object.assign({}, newState, derivedStateFromCatch); - - // Update the base state of the update queue. - // FIXME: This is getting ridiculous. Refactor plz! - var _updateQueue4 = workInProgress.updateQueue; - if (_updateQueue4 !== null) { - _updateQueue4.baseState = Object.assign( - {}, - _updateQueue4.baseState, - derivedStateFromCatch - ); - } } if ( @@ -6937,14 +6988,6 @@ var ReactFiberClassComponent = function( workInProgress.effectTag |= Update; } } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Snapshot; - } - } return false; } @@ -6959,11 +7002,11 @@ var ReactFiberClassComponent = function( if (shouldUpdate) { // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - !hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === "function" || - typeof instance.componentWillUpdate === "function") + typeof instance.componentWillUpdate === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { startPhaseTimer(workInProgress, "componentWillUpdate"); if (typeof instance.componentWillUpdate === "function") { @@ -6977,9 +7020,6 @@ var ReactFiberClassComponent = function( if (typeof instance.componentDidUpdate === "function") { workInProgress.effectTag |= Update; } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - workInProgress.effectTag |= Snapshot; - } } else { // If an update was already in progress, we should schedule an Update // effect even though we're bailing out, so that cWU/cDU are called. @@ -6991,14 +7031,6 @@ var ReactFiberClassComponent = function( workInProgress.effectTag |= Update; } } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Snapshot; - } - } // If shouldComponentUpdate returned false, we should still update the // memoized props/state to indicate that this work can be reused. @@ -7838,15 +7870,13 @@ function ChildReconciler(shouldTrackSideEffects) { if (typeof newChildrenIterable.entries === "function") { var possibleMap = newChildrenIterable; if (possibleMap.entries === iteratorFn) { - !didWarnAboutMaps - ? warning( - false, - "Using Maps as children is unsupported and will likely yield " + - "unexpected results. Convert it to a sequence/iterable of keyed " + - "ReactElements instead.%s", - getCurrentFiberStackAddendum$1() - ) - : void 0; + warning( + didWarnAboutMaps, + "Using Maps as children is unsupported and will likely yield " + + "unexpected results. Convert it to a sequence/iterable of keyed " + + "ReactElements instead.%s", + getCurrentFiberStackAddendum$1() + ); didWarnAboutMaps = true; } } @@ -8288,6 +8318,71 @@ function cloneChildFibers(current, workInProgress) { newChild.sibling = null; } +var changedBitsStack = []; +var currentValueStack = []; +var stack = []; +var index$1 = -1; + +var rendererSigil = void 0; +{ + // Use this to detect multiple renderers using the same context + rendererSigil = {}; +} + +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; + + { + warning( + context._currentRenderer === null || + context._currentRenderer === rendererSigil, + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." + ); + context._currentRenderer = rendererSigil; + } +} + +function popProvider(providerFiber) { + { + warning( + index$1 > -1 && providerFiber === stack[index$1], + "Unexpected pop." + ); + } + var changedBits = changedBitsStack[index$1]; + var currentValue = currentValueStack[index$1]; + changedBitsStack[index$1] = null; + currentValueStack[index$1] = null; + stack[index$1] = null; + index$1 -= 1; + var context = providerFiber.type.context; + context._currentValue = currentValue; + context._changedBits = changedBits; +} + +function resetProviderStack() { + for (var i = index$1; i > -1; i--) { + var providerFiber = stack[i]; + var context = providerFiber.type.context; + context._currentValue = context._defaultValue; + context._changedBits = 0; + changedBitsStack[i] = null; + currentValueStack[i] = null; + stack[i] = null; + { + context._currentRenderer = null; + } + } + index$1 = -1; +} + var didWarnAboutBadClass = void 0; var didWarnAboutGetDerivedStateOnFunctionalComponent = void 0; var didWarnAboutStatelessRefs = void 0; @@ -8301,8 +8396,6 @@ var didWarnAboutStatelessRefs = void 0; var ReactFiberBeginWork = function( config, hostContext, - legacyContext, - newContext, hydrationContext, scheduleWork, computeExpirationForFiber @@ -8311,20 +8404,12 @@ var ReactFiberBeginWork = function( shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree; var pushHostContext = hostContext.pushHostContext, pushHostContainer = hostContext.pushHostContainer; - var pushProvider = newContext.pushProvider; - var getMaskedContext = legacyContext.getMaskedContext, - getUnmaskedContext = legacyContext.getUnmaskedContext, - hasLegacyContextChanged = legacyContext.hasContextChanged, - pushLegacyContextProvider = legacyContext.pushContextProvider, - pushTopLevelContextObject = legacyContext.pushTopLevelContextObject, - invalidateContextProvider = legacyContext.invalidateContextProvider; var enterHydrationState = hydrationContext.enterHydrationState, resetHydrationState = hydrationContext.resetHydrationState, tryToClaimNextHydratableInstance = hydrationContext.tryToClaimNextHydratableInstance; var _ReactFiberClassCompo = ReactFiberClassComponent( - legacyContext, scheduleWork, computeExpirationForFiber, memoizeProps, @@ -8382,17 +8467,9 @@ var ReactFiberBeginWork = function( } } - function updateForwardRef(current, workInProgress) { - var render = workInProgress.type.render; - var nextChildren = render(workInProgress.pendingProps, workInProgress.ref); - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextChildren); - return workInProgress.child; - } - function updateFragment(current, workInProgress) { var nextChildren = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (workInProgress.memoizedProps === nextChildren) { @@ -8405,7 +8482,7 @@ var ReactFiberBeginWork = function( function updateMode(current, workInProgress) { var nextChildren = workInProgress.pendingProps.children; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if ( @@ -8434,7 +8511,7 @@ var ReactFiberBeginWork = function( var fn = workInProgress.type; var nextProps = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else { @@ -8467,7 +8544,7 @@ var ReactFiberBeginWork = function( // Push context providers early to prevent context stack mismatches. // During mounting we don't know the child context yet as the instance doesn't exist. // We will invalidate the child context in finishClassComponent() right after rendering. - var hasContext = pushLegacyContextProvider(workInProgress); + var hasContext = pushContextProvider(workInProgress); var shouldUpdate = void 0; if (current === null) { if (workInProgress.stateNode === null) { @@ -8692,7 +8769,7 @@ var ReactFiberBeginWork = function( var nextProps = workInProgress.pendingProps; var prevProps = current !== null ? current.memoizedProps : null; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (memoizedProps === nextProps) { @@ -8812,8 +8889,7 @@ var ReactFiberBeginWork = function( var partialState = callGetDerivedStateFromProps( workInProgress, value, - props, - workInProgress.memoizedState + props ); if (partialState !== null && partialState !== undefined) { @@ -8828,7 +8904,7 @@ var ReactFiberBeginWork = function( // Push context providers early to prevent context stack mismatches. // During mounting we don't know the child context yet as the instance doesn't exist. // We will invalidate the child context in finishClassComponent() right after rendering. - var hasContext = pushLegacyContextProvider(workInProgress); + var hasContext = pushContextProvider(workInProgress); adoptClassInstance(workInProgress, value); mountClassInstance(workInProgress, renderExpirationTime); return finishClassComponent( @@ -8846,13 +8922,11 @@ var ReactFiberBeginWork = function( var _Component = workInProgress.type; if (_Component) { - !!_Component.childContextTypes - ? warning( - false, - "%s(...): childContextTypes cannot be defined on a functional component.", - _Component.displayName || _Component.name || "Component" - ) - : void 0; + warning( + !_Component.childContextTypes, + "%s(...): childContextTypes cannot be defined on a functional component.", + _Component.displayName || _Component.name || "Component" + ); } if (workInProgress.ref !== null) { var info = ""; @@ -8903,7 +8977,7 @@ var ReactFiberBeginWork = function( function updateCallComponent(current, workInProgress, renderExpirationTime) { var nextProps = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (workInProgress.memoizedProps === nextProps) { @@ -8946,7 +9020,7 @@ var ReactFiberBeginWork = function( ) { pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo); var nextChildren = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (workInProgress.memoizedProps === nextChildren) { @@ -8980,10 +9054,6 @@ var ReactFiberBeginWork = function( renderExpirationTime ) { 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. @@ -9071,12 +9141,12 @@ var ReactFiberBeginWork = function( renderExpirationTime ) { var providerType = workInProgress.type; - var context = providerType._context; + var context = providerType.context; var newProps = workInProgress.pendingProps; var oldProps = workInProgress.memoizedProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (oldProps === newProps) { @@ -9124,14 +9194,12 @@ var ReactFiberBeginWork = function( ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT; { - !((changedBits & MAX_SIGNED_31_BIT_INT) === changedBits) - ? warning( - false, - "calculateChangedBits: Expected the return value to be a " + - "31-bit integer. Instead received: %s", - changedBits - ) - : void 0; + warning( + (changedBits & MAX_SIGNED_31_BIT_INT) === changedBits, + "calculateChangedBits: Expected the return value to be a " + + "31-bit integer. Instead received: %s", + changedBits + ); } changedBits |= 0; @@ -9174,7 +9242,7 @@ var ReactFiberBeginWork = function( var newValue = context._currentValue; var changedBits = context._changedBits; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (changedBits === 0 && oldProps === newProps) { @@ -9199,23 +9267,21 @@ var ReactFiberBeginWork = function( changedBits, renderExpirationTime ); + } else if (oldProps !== null && oldProps.children === newProps.children) { + // No change. Bailout early if children are the same. + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - // There is no bailout on `children` equality because we expect people - // to often pass a bound method as a child, but it may reference - // `this.state` or `this.props` (and thus needs to re-render on `setState`). var render = newProps.children; { - !(typeof render === "function") - ? warning( - false, - "A context consumer was rendered with multiple children, or a child " + - "that isn't a function. A context consumer expects a single child " + - "that is a function. If you did pass a function, make sure there " + - "is no trailing or leading whitespace around it." - ) - : void 0; + warning( + typeof render === "function", + "A context consumer was rendered with multiple children, or a child " + + "that isn't a function. A context consumer expects a single child " + + "that is a function. If you did pass a function, make sure there " + + "is no trailing or leading whitespace around it." + ); } var newChildren = render(newValue); @@ -9273,7 +9339,7 @@ var ReactFiberBeginWork = function( pushHostRootContext(workInProgress); break; case ClassComponent: - pushLegacyContextProvider(workInProgress); + pushContextProvider(workInProgress); break; case HostPortal: pushHostContainer( @@ -9354,8 +9420,6 @@ var ReactFiberBeginWork = function( workInProgress, renderExpirationTime ); - case ForwardRef: - return updateForwardRef(current, workInProgress); case Fragment: return updateFragment(current, workInProgress); case Mode: @@ -9386,13 +9450,7 @@ var ReactFiberBeginWork = function( }; }; -var ReactFiberCompleteWork = function( - config, - hostContext, - legacyContext, - newContext, - hydrationContext -) { +var ReactFiberCompleteWork = function(config, hostContext, hydrationContext) { var createInstance = config.createInstance, createTextInstance = config.createTextInstance, appendInitialChild = config.appendInitialChild, @@ -9404,9 +9462,6 @@ var ReactFiberCompleteWork = function( popHostContext = hostContext.popHostContext, getHostContext = hostContext.getHostContext, popHostContainer = hostContext.popHostContainer; - var popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject; - var popProvider = newContext.popProvider; var prepareToHydrateHostInstance = hydrationContext.prepareToHydrateHostInstance, prepareToHydrateHostTextInstance = @@ -9722,7 +9777,7 @@ var ReactFiberCompleteWork = function( return null; case ClassComponent: { // We are leaving this subtree, so pop context if any. - popLegacyContextProvider(workInProgress); + popContextProvider(workInProgress); // If this component caught an error, schedule an error log effect. var instance = workInProgress.stateNode; @@ -9741,7 +9796,7 @@ var ReactFiberCompleteWork = function( } case HostRoot: { popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); + popTopLevelContextObject(workInProgress); var fiberRoot = workInProgress.stateNode; if (fiberRoot.pendingContext) { fiberRoot.context = fiberRoot.pendingContext; @@ -9917,8 +9972,6 @@ var ReactFiberCompleteWork = function( case ReturnComponent: // Does nothing. return null; - case ForwardRef: - return null; case Fragment: return null; case Mode: @@ -9968,16 +10021,11 @@ function createCapturedValue(value, source) { var ReactFiberUnwindWork = function( hostContext, - legacyContext, - newContext, scheduleWork, isAlreadyFailedLegacyErrorBoundary ) { var popHostContainer = hostContext.popHostContainer, popHostContext = hostContext.popHostContext; - var popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject; - var popProvider = newContext.popProvider; function throwException(returnFiber, sourceFiber, rawValue) { // The source fiber did not complete. @@ -10033,7 +10081,7 @@ var ReactFiberUnwindWork = function( function unwindWork(workInProgress) { switch (workInProgress.tag) { case ClassComponent: { - popLegacyContextProvider(workInProgress); + popContextProvider(workInProgress); var effectTag = workInProgress.effectTag; if (effectTag & ShouldCapture) { workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture; @@ -10043,7 +10091,7 @@ var ReactFiberUnwindWork = function( } case HostRoot: { popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); + popTopLevelContextObject(workInProgress); var _effectTag = workInProgress.effectTag; if (_effectTag & ShouldCapture) { workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture; @@ -10065,37 +10113,9 @@ var ReactFiberUnwindWork = function( return null; } } - - function unwindInterruptedWork(interruptedWork) { - switch (interruptedWork.tag) { - case ClassComponent: { - popLegacyContextProvider(interruptedWork); - break; - } - case HostRoot: { - popHostContainer(interruptedWork); - popTopLevelLegacyContextObject(interruptedWork); - break; - } - case HostComponent: { - popHostContext(interruptedWork); - break; - } - case HostPortal: - popHostContainer(interruptedWork); - break; - case ContextProvider: - popProvider(interruptedWork); - break; - default: - break; - } - } - return { throwException: throwException, - unwindWork: unwindWork, - unwindInterruptedWork: unwindInterruptedWork + unwindWork: unwindWork }; }; @@ -10170,11 +10190,6 @@ var invokeGuardedCallback$3 = ReactErrorUtils.invokeGuardedCallback; var hasCaughtError$1 = ReactErrorUtils.hasCaughtError; var clearCaughtError$1 = ReactErrorUtils.clearCaughtError; -var didWarnAboutUndefinedSnapshotBeforeUpdate = null; -{ - didWarnAboutUndefinedSnapshotBeforeUpdate = new Set(); -} - function logError(boundary, errorInfo) { var source = errorInfo.source; var stack = errorInfo.stack; @@ -10184,19 +10199,21 @@ function logError(boundary, errorInfo) { var capturedError = { componentName: source !== null ? getComponentName(source) : null, - componentStack: stack !== null ? stack : "", error: errorInfo.value, - errorBoundary: null, + errorBoundary: boundary, + componentStack: stack !== null ? stack : "", errorBoundaryName: null, errorBoundaryFound: false, willRetry: false }; - if (boundary !== null && boundary.tag === ClassComponent) { - capturedError.errorBoundary = boundary.stateNode; + if (boundary !== null) { capturedError.errorBoundaryName = getComponentName(boundary); - capturedError.errorBoundaryFound = true; - capturedError.willRetry = true; + capturedError.errorBoundaryFound = capturedError.willRetry = + boundary.tag === ClassComponent; + } else { + capturedError.errorBoundaryName = null; + capturedError.errorBoundaryFound = capturedError.willRetry = false; } try { @@ -10260,59 +10277,7 @@ var ReactFiberCommitWork = function( } } } else { - ref.current = null; - } - } - } - - function commitBeforeMutationLifeCycles(current, finishedWork) { - switch (finishedWork.tag) { - case ClassComponent: { - if (finishedWork.effectTag & Snapshot) { - if (current !== null) { - var prevProps = current.memoizedProps; - var prevState = current.memoizedState; - startPhaseTimer(finishedWork, "getSnapshotBeforeUpdate"); - var _instance = finishedWork.stateNode; - _instance.props = finishedWork.memoizedProps; - _instance.state = finishedWork.memoizedState; - var snapshot = _instance.getSnapshotBeforeUpdate( - prevProps, - prevState - ); - { - var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate; - if ( - snapshot === undefined && - !didWarnSet.has(finishedWork.type) - ) { - didWarnSet.add(finishedWork.type); - warning( - false, - "%s.getSnapshotBeforeUpdate(): A snapshot value (or null) " + - "must be returned. You have returned undefined.", - getComponentName(finishedWork) - ); - } - } - _instance.__reactInternalSnapshotBeforeUpdate = snapshot; - stopPhaseTimer(); - } - } - return; - } - case HostRoot: - case HostComponent: - case HostText: - case HostPortal: - // Nothing to do for these component types - return; - default: { - invariant( - false, - "This unit of work tag should not have side-effects. This error is " + - "likely caused by a bug in React. Please file an issue." - ); + ref.value = null; } } } @@ -10326,54 +10291,50 @@ var ReactFiberCommitWork = function( ) { switch (finishedWork.tag) { case ClassComponent: { - var _instance2 = finishedWork.stateNode; + var _instance = finishedWork.stateNode; if (finishedWork.effectTag & Update) { if (current === null) { startPhaseTimer(finishedWork, "componentDidMount"); - _instance2.props = finishedWork.memoizedProps; - _instance2.state = finishedWork.memoizedState; - _instance2.componentDidMount(); + _instance.props = finishedWork.memoizedProps; + _instance.state = finishedWork.memoizedState; + _instance.componentDidMount(); stopPhaseTimer(); } else { var prevProps = current.memoizedProps; var prevState = current.memoizedState; startPhaseTimer(finishedWork, "componentDidUpdate"); - _instance2.props = finishedWork.memoizedProps; - _instance2.state = finishedWork.memoizedState; - _instance2.componentDidUpdate( - prevProps, - prevState, - _instance2.__reactInternalSnapshotBeforeUpdate - ); + _instance.props = finishedWork.memoizedProps; + _instance.state = finishedWork.memoizedState; + _instance.componentDidUpdate(prevProps, prevState); stopPhaseTimer(); } } var updateQueue = finishedWork.updateQueue; if (updateQueue !== null) { - commitCallbacks(updateQueue, _instance2); + commitCallbacks(updateQueue, _instance); } return; } case HostRoot: { var _updateQueue = finishedWork.updateQueue; if (_updateQueue !== null) { - var _instance3 = null; + var _instance2 = null; if (finishedWork.child !== null) { switch (finishedWork.child.tag) { case HostComponent: - _instance3 = getPublicInstance(finishedWork.child.stateNode); + _instance2 = getPublicInstance(finishedWork.child.stateNode); break; case ClassComponent: - _instance3 = finishedWork.child.stateNode; + _instance2 = finishedWork.child.stateNode; break; } } - commitCallbacks(_updateQueue, _instance3); + commitCallbacks(_updateQueue, _instance2); } return; } case HostComponent: { - var _instance4 = finishedWork.stateNode; + var _instance3 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted // (eg DOM renderer may schedule auto-focus for inputs and form controls). @@ -10382,7 +10343,7 @@ var ReactFiberCommitWork = function( if (current === null && finishedWork.effectTag & Update) { var type = finishedWork.type; var props = finishedWork.memoizedProps; - commitMount(_instance4, type, props, finishedWork); + commitMount(_instance3, type, props, finishedWork); } return; @@ -10410,7 +10371,7 @@ var ReactFiberCommitWork = function( case ClassComponent: { var ctor = finishedWork.type; - var _instance5 = finishedWork.stateNode; + var _instance4 = finishedWork.stateNode; var updateQueue = finishedWork.updateQueue; invariant( updateQueue !== null && updateQueue.capturedValues !== null, @@ -10427,19 +10388,16 @@ var ReactFiberCommitWork = function( // This gets reset before we yield back to the browser. // TODO: Warn in strict mode if getDerivedStateFromCatch is // not defined. - markLegacyErrorBoundaryAsFailed(_instance5); + markLegacyErrorBoundaryAsFailed(_instance4); } - _instance5.props = finishedWork.memoizedProps; - _instance5.state = finishedWork.memoizedState; + _instance4.props = finishedWork.memoizedProps; + _instance4.state = finishedWork.memoizedState; for (var i = 0; i < capturedErrors.length; i++) { var errorInfo = capturedErrors[i]; var _error = errorInfo.value; - var stack = errorInfo.stack; logError(finishedWork, errorInfo); - _instance5.componentDidCatch(_error, { - componentStack: stack !== null ? stack : "" - }); + _instance4.componentDidCatch(_error); } } break; @@ -10472,31 +10430,19 @@ var ReactFiberCommitWork = function( function commitAttachRef(finishedWork) { var ref = finishedWork.ref; if (ref !== null) { - var _instance6 = finishedWork.stateNode; + var _instance5 = finishedWork.stateNode; var instanceToUse = void 0; switch (finishedWork.tag) { case HostComponent: - instanceToUse = getPublicInstance(_instance6); + instanceToUse = getPublicInstance(_instance5); break; default: - instanceToUse = _instance6; + instanceToUse = _instance5; } if (typeof ref === "function") { ref(instanceToUse); } else { - { - if (!ref.hasOwnProperty("current")) { - warning( - false, - "Unexpected ref object provided for %s. " + - "Use either a ref-setter function or React.createRef().%s", - getComponentName(finishedWork), - getStackAddendumByWorkInProgressFiber(finishedWork) - ); - } - } - - ref.current = instanceToUse; + ref.value = instanceToUse; } } } @@ -10507,7 +10453,7 @@ var ReactFiberCommitWork = function( if (typeof currentRef === "function") { currentRef(null); } else { - currentRef.current = null; + currentRef.value = null; } } } @@ -10523,9 +10469,9 @@ var ReactFiberCommitWork = function( switch (current.tag) { case ClassComponent: { safelyDetachRef(current); - var _instance7 = current.stateNode; - if (typeof _instance7.componentWillUnmount === "function") { - safelyCallComponentWillUnmount(current, _instance7); + var _instance6 = current.stateNode; + if (typeof _instance6.componentWillUnmount === "function") { + safelyCallComponentWillUnmount(current, _instance6); } return; } @@ -10662,7 +10608,6 @@ var ReactFiberCommitWork = function( }, commitLifeCycles: commitLifeCycles, - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, commitErrorLogging: commitErrorLogging, commitAttachRef: commitAttachRef, commitDetachRef: commitDetachRef @@ -10921,8 +10866,8 @@ var ReactFiberCommitWork = function( return; } case HostComponent: { - var _instance8 = finishedWork.stateNode; - if (_instance8 != null) { + var _instance7 = finishedWork.stateNode; + if (_instance7 != null) { // Commit the work prepared earlier. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps @@ -10935,7 +10880,7 @@ var ReactFiberCommitWork = function( finishedWork.updateQueue = null; if (updatePayload !== null) { commitUpdate( - _instance8, + _instance7, updatePayload, type, oldProps, @@ -10980,7 +10925,6 @@ var ReactFiberCommitWork = function( if (enableMutatingReconciler) { return { - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, commitResetTextContent: commitResetTextContent, commitPlacement: commitPlacement, commitDeletion: commitDeletion, @@ -10997,12 +10941,9 @@ var ReactFiberCommitWork = function( var NO_CONTEXT = {}; -var ReactFiberHostContext = function(config, stack) { +var ReactFiberHostContext = function(config) { var getChildHostContext = config.getChildHostContext, getRootHostContext = config.getRootHostContext; - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; var contextStackCursor = createCursor(NO_CONTEXT); var contextFiberStackCursor = createCursor(NO_CONTEXT); @@ -11026,19 +10967,12 @@ var ReactFiberHostContext = function(config, stack) { // Push current root instance onto the stack; // This allows us to reset root when portals are popped. push(rootInstanceStackCursor, nextRootInstance, fiber); + + var nextRootContext = getRootHostContext(nextRootInstance); + // 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, NO_CONTEXT, fiber); - var nextRootContext = getRootHostContext(nextRootInstance); - // Now that we know this function doesn't throw, replace it. - pop(contextStackCursor, fiber); push(contextStackCursor, nextRootContext, fiber); } @@ -11080,13 +11014,19 @@ var ReactFiberHostContext = function(config, stack) { pop(contextFiberStackCursor, fiber); } + function resetHostContainer() { + contextStackCursor.current = NO_CONTEXT; + rootInstanceStackCursor.current = NO_CONTEXT; + } + return { getHostContext: getHostContext, getRootHostContainer: getRootHostContainer, popHostContainer: popHostContainer, popHostContext: popHostContext, pushHostContainer: pushHostContainer, - pushHostContext: pushHostContext + pushHostContext: pushHostContext, + resetHostContainer: resetHostContainer }; }; @@ -11456,429 +11396,6 @@ var ReactFiberInstrumentation = { var ReactFiberInstrumentation_1 = ReactFiberInstrumentation; -var warnedAboutMissingGetChildContext = void 0; - -{ - warnedAboutMissingGetChildContext = {}; -} - -var ReactFiberLegacyContext = function(stack) { - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; - - // A cursor to the current merged context object on the stack. - - var contextStackCursor = createCursor(emptyObject); - // A cursor to a boolean indicating whether the context has changed. - var didPerformWorkStackCursor = createCursor(false); - // Keep track of the previous context object that was on the stack. - // We use this to get access to the parent context after we have already - // pushed the next context provider, and now need to merge their contexts. - var previousContext = emptyObject; - - function getUnmaskedContext(workInProgress) { - var hasOwnContext = isContextProvider(workInProgress); - if (hasOwnContext) { - // If the fiber is a context provider itself, when we read its context - // we have already pushed its own child context on the stack. A context - // provider should not "see" its own child context. Therefore we read the - // previous (parent) context instead for a context provider. - return previousContext; - } - return contextStackCursor.current; - } - - function cacheContext(workInProgress, unmaskedContext, maskedContext) { - var instance = workInProgress.stateNode; - instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; - instance.__reactInternalMemoizedMaskedChildContext = maskedContext; - } - - function getMaskedContext(workInProgress, unmaskedContext) { - var type = workInProgress.type; - var contextTypes = type.contextTypes; - if (!contextTypes) { - return emptyObject; - } - - // Avoid recreating masked context unless unmasked context has changed. - // Failing to do this will result in unnecessary calls to componentWillReceiveProps. - // This may trigger infinite loops if componentWillReceiveProps calls setState. - var instance = workInProgress.stateNode; - if ( - instance && - instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext - ) { - return instance.__reactInternalMemoizedMaskedChildContext; - } - - var context = {}; - for (var key in contextTypes) { - context[key] = unmaskedContext[key]; - } - - { - var name = getComponentName(workInProgress) || "Unknown"; - checkPropTypes( - contextTypes, - context, - "context", - name, - ReactDebugCurrentFiber.getCurrentFiberStackAddendum - ); - } - - // Cache unmasked context so we can avoid recreating masked context unless necessary. - // Context is created before the class component is instantiated so check for instance. - if (instance) { - cacheContext(workInProgress, unmaskedContext, context); - } - - return context; - } - - function hasContextChanged() { - return didPerformWorkStackCursor.current; - } - - function isContextConsumer(fiber) { - return fiber.tag === ClassComponent && fiber.type.contextTypes != null; - } - - function isContextProvider(fiber) { - return fiber.tag === ClassComponent && fiber.type.childContextTypes != null; - } - - function popContextProvider(fiber) { - if (!isContextProvider(fiber)) { - return; - } - - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); - } - - function popTopLevelContextObject(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); - } - - function pushTopLevelContextObject(fiber, context, didChange) { - invariant( - contextStackCursor.cursor == null, - "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; - var childContextTypes = fiber.type.childContextTypes; - - // TODO (bvaughn) Replace this behavior with an invariant() in the future. - // It has only been added in Fiber to match the (unintentional) behavior in Stack. - if (typeof instance.getChildContext !== "function") { - { - var componentName = getComponentName(fiber) || "Unknown"; - - if (!warnedAboutMissingGetChildContext[componentName]) { - warnedAboutMissingGetChildContext[componentName] = true; - warning( - false, - "%s.childContextTypes is specified but there is no getChildContext() method " + - "on the instance. You can either define getChildContext() on %s or remove " + - "childContextTypes from it.", - componentName, - componentName - ); - } - } - return parentContext; - } - - var childContext = void 0; - { - ReactDebugCurrentFiber.setCurrentPhase("getChildContext"); - } - startPhaseTimer(fiber, "getChildContext"); - childContext = instance.getChildContext(); - stopPhaseTimer(); - { - ReactDebugCurrentFiber.setCurrentPhase(null); - } - for (var contextKey in childContext) { - invariant( - contextKey in childContextTypes, - '%s.getChildContext(): key "%s" is not defined in childContextTypes.', - getComponentName(fiber) || "Unknown", - contextKey - ); - } - { - var name = getComponentName(fiber) || "Unknown"; - checkPropTypes( - childContextTypes, - childContext, - "child context", - name, - // In practice, there is one case in which we won't get a stack. It's when - // somebody calls unstable_renderSubtreeIntoContainer() and we process - // context from the parent component instance. The stack will be missing - // because it's outside of the reconciliation, and so the pointer has not - // been set. This is rare and doesn't matter. We'll also remove that API. - ReactDebugCurrentFiber.getCurrentFiberStackAddendum - ); - } - - return Object.assign({}, parentContext, childContext); - } - - function pushContextProvider(workInProgress) { - if (!isContextProvider(workInProgress)) { - return false; - } - - var instance = workInProgress.stateNode; - // We push the context as early as possible to ensure stack integrity. - // If the instance does not exist yet, we will push null at first, - // and replace it on the stack later when invalidating the context. - var memoizedMergedChildContext = - (instance && instance.__reactInternalMemoizedMergedChildContext) || - emptyObject; - - // Remember the parent context so we can merge with it later. - // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. - previousContext = contextStackCursor.current; - push(contextStackCursor, memoizedMergedChildContext, workInProgress); - push( - didPerformWorkStackCursor, - didPerformWorkStackCursor.current, - workInProgress - ); - - return true; - } - - 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) { - // Merge parent and own context. - // Skip this if we're not updating due to sCU. - // This avoids unnecessarily recomputing memoized values. - var mergedContext = processChildContext(workInProgress, previousContext); - instance.__reactInternalMemoizedMergedChildContext = mergedContext; - - // Replace the old (or empty) context with the new one. - // It is important to unwind the context in the reverse order. - pop(didPerformWorkStackCursor, workInProgress); - pop(contextStackCursor, workInProgress); - // Now push the new context and mark that it has changed. - push(contextStackCursor, mergedContext, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); - } else { - pop(didPerformWorkStackCursor, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); - } - } - - function findCurrentUnmaskedContext(fiber) { - // Currently this is only used with renderSubtreeIntoContainer; not sure if it - // makes sense elsewhere - invariant( - isFiberMounted(fiber) && fiber.tag === ClassComponent, - "Expected subtree parent to be a mounted class component. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - - var node = fiber; - while (node.tag !== HostRoot) { - if (isContextProvider(node)) { - return node.stateNode.__reactInternalMemoizedMergedChildContext; - } - var parent = node["return"]; - invariant( - parent, - "Found unexpected detached subtree parent. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - node = parent; - } - return node.stateNode.context; - } - - return { - getUnmaskedContext: getUnmaskedContext, - cacheContext: cacheContext, - getMaskedContext: getMaskedContext, - hasContextChanged: hasContextChanged, - isContextConsumer: isContextConsumer, - isContextProvider: isContextProvider, - popContextProvider: popContextProvider, - popTopLevelContextObject: popTopLevelContextObject, - pushTopLevelContextObject: pushTopLevelContextObject, - processChildContext: processChildContext, - pushContextProvider: pushContextProvider, - invalidateContextProvider: invalidateContextProvider, - findCurrentUnmaskedContext: findCurrentUnmaskedContext - }; -}; - -var ReactFiberNewContext = function(stack) { - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; - - var providerCursor = createCursor(null); - var valueCursor = createCursor(null); - var changedBitsCursor = createCursor(0); - - var rendererSigil = void 0; - { - // Use this to detect multiple renderers using the same context - rendererSigil = {}; - } - - function pushProvider(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; - - { - !( - context._currentRenderer === null || - context._currentRenderer === rendererSigil - ) - ? warning( - false, - "Detected multiple renderers concurrently rendering the " + - "same context provider. This is currently unsupported." - ) - : void 0; - context._currentRenderer = rendererSigil; - } - } - - function popProvider(providerFiber) { - var changedBits = changedBitsCursor.current; - var currentValue = valueCursor.current; - - pop(providerCursor, providerFiber); - pop(valueCursor, providerFiber); - pop(changedBitsCursor, providerFiber); - - var context = providerFiber.type._context; - context._currentValue = currentValue; - context._changedBits = changedBits; - } - - return { - pushProvider: pushProvider, - popProvider: popProvider - }; -}; - -var ReactFiberStack = function() { - var valueStack = []; - - var fiberStack = void 0; - - { - fiberStack = []; - } - - var index = -1; - - function createCursor(defaultValue) { - return { - current: defaultValue - }; - } - - function isEmpty() { - return index === -1; - } - - function pop(cursor, fiber) { - if (index < 0) { - { - warning(false, "Unexpected pop."); - } - return; - } - - { - if (fiber !== fiberStack[index]) { - warning(false, "Unexpected Fiber popped."); - } - } - - cursor.current = valueStack[index]; - - valueStack[index] = null; - - { - fiberStack[index] = null; - } - - index--; - } - - function push(cursor, value, fiber) { - index++; - - valueStack[index] = cursor.current; - - { - fiberStack[index] = fiber; - } - - cursor.current = value; - } - - function checkThatStackIsEmpty() { - { - if (index !== -1) { - warning( - false, - "Expected an empty stack. Something was not reset properly." - ); - } - } - } - - function resetStackAfterFatalErrorInDev() { - { - index = -1; - valueStack.length = 0; - fiberStack.length = 0; - } - } - - return { - createCursor: createCursor, - isEmpty: isEmpty, - pop: pop, - push: push, - checkThatStackIsEmpty: checkThatStackIsEmpty, - resetStackAfterFatalErrorInDev: resetStackAfterFatalErrorInDev - }; -}; - var invokeGuardedCallback$2 = ReactErrorUtils.invokeGuardedCallback; var hasCaughtError = ReactErrorUtils.hasCaughtError; var clearCaughtError = ReactErrorUtils.clearCaughtError; @@ -11894,19 +11411,17 @@ var warnAboutInvalidUpdates = void 0; var didWarnStateUpdateForUnmountedComponent = {}; warnAboutUpdateOnUnmounted = function(fiber) { - // We show the whole stack but dedupe on the top component's name because - // the problematic code almost always lies inside that component. var componentName = getComponentName(fiber) || "ReactClass"; if (didWarnStateUpdateForUnmountedComponent[componentName]) { return; } warning( false, - "Can't call setState (or forceUpdate) on an unmounted component. This " + - "is a no-op, but it indicates a memory leak in your application. To " + - "fix, cancel all subscriptions and asynchronous tasks in the " + - "componentWillUnmount method.%s", - getStackAddendumByWorkInProgressFiber(fiber) + "Can only update a mounted or mounting " + + "component. This usually means you called setState, replaceState, " + + "or forceUpdate on an unmounted component. This is a no-op.\n\nPlease " + + "check the code for the %s component.", + componentName ); didWarnStateUpdateForUnmountedComponent[componentName] = true; }; @@ -11941,23 +11456,16 @@ var warnAboutInvalidUpdates = void 0; } var ReactFiberScheduler = function(config) { - var stack = ReactFiberStack(); - var hostContext = ReactFiberHostContext(config, stack); - var legacyContext = ReactFiberLegacyContext(stack); - var newContext = ReactFiberNewContext(stack); + var hostContext = ReactFiberHostContext(config); var popHostContext = hostContext.popHostContext, popHostContainer = hostContext.popHostContainer; - var popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popLegacyContextProvider = legacyContext.popContextProvider; - var popProvider = newContext.popProvider; var hydrationContext = ReactFiberHydrationContext(config); + var resetHostContainer = hostContext.resetHostContainer; var _ReactFiberBeginWork = ReactFiberBeginWork( config, hostContext, - legacyContext, - newContext, hydrationContext, scheduleWork, computeExpirationForFiber @@ -11967,22 +11475,17 @@ var ReactFiberScheduler = function(config) { var _ReactFiberCompleteWo = ReactFiberCompleteWork( config, hostContext, - legacyContext, - newContext, hydrationContext ), completeWork = _ReactFiberCompleteWo.completeWork; var _ReactFiberUnwindWork = ReactFiberUnwindWork( hostContext, - legacyContext, - newContext, scheduleWork, isAlreadyFailedLegacyErrorBoundary ), throwException = _ReactFiberUnwindWork.throwException, - unwindWork = _ReactFiberUnwindWork.unwindWork, - unwindInterruptedWork = _ReactFiberUnwindWork.unwindInterruptedWork; + unwindWork = _ReactFiberUnwindWork.unwindWork; var _ReactFiberCommitWork = ReactFiberCommitWork( config, @@ -11992,8 +11495,6 @@ var ReactFiberScheduler = function(config) { markLegacyErrorBoundaryAsFailed, recalculateCurrentTime ), - commitBeforeMutationLifeCycles = - _ReactFiberCommitWork.commitBeforeMutationLifeCycles, commitResetTextContent = _ReactFiberCommitWork.commitResetTextContent, commitPlacement = _ReactFiberCommitWork.commitPlacement, commitDeletion = _ReactFiberCommitWork.commitDeletion, @@ -12045,29 +11546,21 @@ var ReactFiberScheduler = function(config) { var stashedWorkInProgressProperties = void 0; var replayUnitOfWork = void 0; - var isReplayingFailedUnitOfWork = void 0; - var originalReplayError = void 0; - var rethrowOriginalError = void 0; if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { stashedWorkInProgressProperties = null; - isReplayingFailedUnitOfWork = false; - originalReplayError = null; - replayUnitOfWork = function(failedUnitOfWork, error, isAsync) { - // Restore the original state of the work-in-progress - assignFiberPropertiesInDEV( - failedUnitOfWork, - stashedWorkInProgressProperties - ); + replayUnitOfWork = function(failedUnitOfWork, isAsync) { + // Retore the original state of the work-in-progress + Object.assign(failedUnitOfWork, stashedWorkInProgressProperties); switch (failedUnitOfWork.tag) { case HostRoot: popHostContainer(failedUnitOfWork); - popTopLevelLegacyContextObject(failedUnitOfWork); + popTopLevelContextObject(failedUnitOfWork); break; case HostComponent: popHostContext(failedUnitOfWork); break; case ClassComponent: - popLegacyContextProvider(failedUnitOfWork); + popContextProvider(failedUnitOfWork); break; case HostPortal: popHostContainer(failedUnitOfWork); @@ -12077,36 +11570,28 @@ var ReactFiberScheduler = function(config) { break; } // Replay the begin phase. - isReplayingFailedUnitOfWork = true; - originalReplayError = error; invokeGuardedCallback$2(null, workLoop, null, isAsync); - isReplayingFailedUnitOfWork = false; - originalReplayError = null; if (hasCaughtError()) { clearCaughtError(); } else { - // If the begin phase did not fail the second time, set this pointer - // back to the original value. - nextUnitOfWork = failedUnitOfWork; + // This should be unreachable because the render phase is + // idempotent } }; - rethrowOriginalError = function() { - throw originalReplayError; - }; } - function resetStack() { - if (nextUnitOfWork !== null) { - var interruptedWork = nextUnitOfWork["return"]; - while (interruptedWork !== null) { - unwindInterruptedWork(interruptedWork); - interruptedWork = interruptedWork["return"]; - } - } + function resetContextStack() { + // Reset the stack + reset(); + // Reset the cursors + resetContext(); + resetHostContainer(); + + // TODO: Unify new context implementation with other stacks + resetProviderStack(); { ReactStrictModeWarnings.discardPendingWarnings(); - stack.checkThatStackIsEmpty(); } nextRoot = null; @@ -12124,7 +11609,6 @@ var ReactFiberScheduler = function(config) { recordEffect(); var effectTag = nextEffect.effectTag; - if (effectTag & ContentReset) { commitResetTextContent(nextEffect); } @@ -12182,22 +11666,6 @@ var ReactFiberScheduler = function(config) { } } - function commitBeforeMutationLifecycles() { - while (nextEffect !== null) { - var effectTag = nextEffect.effectTag; - - if (effectTag & Snapshot) { - recordEffect(); - var current = nextEffect.alternate; - commitBeforeMutationLifeCycles(current, nextEffect); - } - - // Don't cleanup effects yet; - // This will be done by commitAllLifeCycles() - nextEffect = nextEffect.nextEffect; - } - } - function commitAllLifeCycles( finishedRoot, currentTime, @@ -12305,14 +11773,16 @@ var ReactFiberScheduler = function(config) { prepareForCommit(root.containerInfo); - // Invoke instances of getSnapshotBeforeUpdate before mutation. + // Commit all the side-effects within a tree. We'll do this in two passes. + // The first pass performs all the host insertions, updates, deletions and + // ref unmounts. nextEffect = firstEffect; - startCommitSnapshotEffectsTimer(); + startCommitHostEffectsTimer(); while (nextEffect !== null) { var didError = false; var error = void 0; { - invokeGuardedCallback$2(null, commitBeforeMutationLifecycles, null); + invokeGuardedCallback$2(null, commitAllHostEffects, null); if (hasCaughtError()) { didError = true; error = clearCaughtError(); @@ -12331,36 +11801,6 @@ var ReactFiberScheduler = function(config) { } } } - stopCommitSnapshotEffectsTimer(); - - // Commit all the side-effects within a tree. We'll do this in two passes. - // The first pass performs all the host insertions, updates, deletions and - // ref unmounts. - nextEffect = firstEffect; - startCommitHostEffectsTimer(); - while (nextEffect !== null) { - var _didError = false; - var _error = void 0; - { - invokeGuardedCallback$2(null, commitAllHostEffects, null); - if (hasCaughtError()) { - _didError = true; - _error = clearCaughtError(); - } - } - if (_didError) { - invariant( - nextEffect !== null, - "Should have next effect. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - onCommitPhaseError(nextEffect, _error); - // Clean-up - if (nextEffect !== null) { - nextEffect = nextEffect.nextEffect; - } - } - } stopCommitHostEffectsTimer(); resetAfterCommit(root.containerInfo); @@ -12378,8 +11818,8 @@ var ReactFiberScheduler = function(config) { nextEffect = firstEffect; startCommitLifeCyclesTimer(); while (nextEffect !== null) { - var _didError2 = false; - var _error2 = void 0; + var _didError = false; + var _error = void 0; { invokeGuardedCallback$2( null, @@ -12390,17 +11830,17 @@ var ReactFiberScheduler = function(config) { committedExpirationTime ); if (hasCaughtError()) { - _didError2 = true; - _error2 = clearCaughtError(); + _didError = true; + _error = clearCaughtError(); } } - if (_didError2) { + if (_didError) { invariant( nextEffect !== null, "Should have next effect. This error is likely caused by a bug " + "in React. Please file an issue." ); - onCommitPhaseError(nextEffect, _error2); + onCommitPhaseError(nextEffect, _error); if (nextEffect !== null) { nextEffect = nextEffect.nextEffect; } @@ -12624,21 +12064,12 @@ var ReactFiberScheduler = function(config) { } if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { - stashedWorkInProgressProperties = assignFiberPropertiesInDEV( - stashedWorkInProgressProperties, - workInProgress - ); + stashedWorkInProgressProperties = Object.assign({}, workInProgress); } var next = beginWork(current, workInProgress, nextRenderExpirationTime); + { ReactDebugCurrentFiber.resetCurrentFiber(); - if (isReplayingFailedUnitOfWork) { - // Currently replaying a failed unit of work. This should be unreachable, - // because the render phase is meant to be idempotent, and it should - // have thrown again. Since it didn't, rethrow the original error, so - // React's internal stack is not misaligned. - rethrowOriginalError(); - } } if (true && ReactFiberInstrumentation_1.debugTool) { ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress); @@ -12684,7 +12115,7 @@ var ReactFiberScheduler = function(config) { nextUnitOfWork === null ) { // Reset the stack and start working from the root. - resetStack(); + resetContextStack(); nextRoot = root; nextRenderExpirationTime = expirationTime; nextUnitOfWork = createWorkInProgress( @@ -12712,18 +12143,13 @@ var ReactFiberScheduler = function(config) { if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { var failedUnitOfWork = nextUnitOfWork; - replayUnitOfWork(failedUnitOfWork, thrownValue, isAsync); + replayUnitOfWork(failedUnitOfWork, isAsync); } var sourceFiber = nextUnitOfWork; var returnFiber = sourceFiber["return"]; if (returnFiber === null) { - // This is the root. The root could capture its own errors. However, - // we don't know if it errors before or after we pushed the host - // context. This information is needed to avoid a stack mismatch. - // Because we're not sure, treat this as a fatal error. We could track - // which phase it fails in, but doesn't seem worth it. At least - // for now. + // This is a fatal error. didFatal = true; onUncaughtError(thrownValue); break; @@ -12735,32 +12161,23 @@ var ReactFiberScheduler = function(config) { } while (true); // We're done performing work. Time to clean up. - var didCompleteRoot = false; + stopWorkLoopTimer(interruptedBy); + interruptedBy = null; isWorking = false; // Yield back to main thread. if (didFatal) { - stopWorkLoopTimer(interruptedBy, didCompleteRoot); - interruptedBy = null; // There was a fatal error. - { - stack.resetStackAfterFatalErrorInDev(); - } return null; } else if (nextUnitOfWork === null) { // We reached the root. if (isRootReadyForCommit) { - didCompleteRoot = true; - stopWorkLoopTimer(interruptedBy, didCompleteRoot); - interruptedBy = null; // The root successfully completed. It's ready for commit. root.pendingCommitExpirationTime = expirationTime; var finishedWork = root.current.alternate; return finishedWork; } else { // The root did not complete. - stopWorkLoopTimer(interruptedBy, didCompleteRoot); - interruptedBy = null; invariant( false, "Expired work should have completed. This error is likely caused " + @@ -12768,8 +12185,6 @@ var ReactFiberScheduler = function(config) { ); } } else { - stopWorkLoopTimer(interruptedBy, didCompleteRoot); - interruptedBy = null; // There's more work to do, but we ran out of time. Yield back to // the renderer. return null; @@ -12953,17 +12368,9 @@ var ReactFiberScheduler = function(config) { ) { // This is an interruption. (Used for performance tracking.) interruptedBy = fiber; - resetStack(); + resetContextStack(); } - if ( - // If we're in the render phase, we don't need to schedule this root - // for an update, because we'll do it before we exit... - !isWorking || - isCommitting || - // ...unless this is a different root than the one we're rendering. - nextRoot !== root - ) { - // Add this root to the root schedule. + if (nextRoot !== root || !isWorking) { requestWork(root, expirationTime); } if (nestedUpdateCount > NESTED_UPDATE_LIMIT) { @@ -13223,8 +12630,7 @@ var ReactFiberScheduler = function(config) { if (enableUserTimingAPI && deadline !== null) { var didExpire = nextFlushedExpirationTime < recalculateCurrentTime(); - var timeout = expirationTimeToMs(nextFlushedExpirationTime); - stopRequestCallbackTimer(didExpire, timeout); + stopRequestCallbackTimer(didExpire); } if (isAsync) { @@ -13284,11 +12690,7 @@ var ReactFiberScheduler = function(config) { // Perform work on root as if the given expiration time is the current time. // This has the effect of synchronously flushing all work up to and // including the given time. - nextFlushedRoot = root; - nextFlushedExpirationTime = expirationTime; performWorkOnRoot(root, expirationTime, false); - // Flush any sync work that was scheduled by lifecycles - performSyncWork(); finishRendering(); } @@ -13537,8 +12939,7 @@ var ReactFiberScheduler = function(config) { syncUpdates: syncUpdates, interactiveUpdates: interactiveUpdates, flushInteractiveUpdates: flushInteractiveUpdates, - computeUniqueAsyncExpiration: computeUniqueAsyncExpiration, - legacyContext: legacyContext + computeUniqueAsyncExpiration: computeUniqueAsyncExpiration }; }; @@ -13551,6 +12952,18 @@ var didWarnAboutNestedUpdates = void 0; // 0 is PROD, 1 is DEV. // Might add PROFILE later. +function getContextForSubtree(parentComponent) { + if (!parentComponent) { + return emptyObject; + } + + var fiber = get(parentComponent); + var parentContext = findCurrentUnmaskedContext(fiber); + return isContextProvider(fiber) + ? processChildContext(fiber, parentContext) + : parentContext; +} + var ReactFiberReconciler$1 = function(config) { var getPublicInstance = config.getPublicInstance; @@ -13569,24 +12982,7 @@ var ReactFiberReconciler$1 = function(config) { deferredUpdates = _ReactFiberScheduler.deferredUpdates, syncUpdates = _ReactFiberScheduler.syncUpdates, interactiveUpdates = _ReactFiberScheduler.interactiveUpdates, - flushInteractiveUpdates = _ReactFiberScheduler.flushInteractiveUpdates, - legacyContext = _ReactFiberScheduler.legacyContext; - - var findCurrentUnmaskedContext = legacyContext.findCurrentUnmaskedContext, - isContextProvider = legacyContext.isContextProvider, - processChildContext = legacyContext.processChildContext; - - function getContextForSubtree(parentComponent) { - if (!parentComponent) { - return emptyObject; - } - - var fiber = get(parentComponent); - var parentContext = findCurrentUnmaskedContext(fiber); - return isContextProvider(fiber) - ? processChildContext(fiber, parentContext) - : parentContext; - } + flushInteractiveUpdates = _ReactFiberScheduler.flushInteractiveUpdates; function scheduleRootUpdate( current, @@ -13615,14 +13011,12 @@ var ReactFiberReconciler$1 = function(config) { callback = callback === undefined ? null : callback; { - !(callback === null || typeof callback === "function") - ? warning( - false, - "render(...): Expected the last optional `callback` argument to be a " + - "function. Instead received: %s.", - callback - ) - : void 0; + warning( + callback === null || typeof callback === "function", + "render(...): Expected the last optional `callback` argument to be a " + + "function. Instead received: %s.", + callback + ); } var update = { diff --git a/Libraries/Renderer/ReactFabric-prod.js b/Libraries/Renderer/ReactFabric-prod.js index c12ebd601c8..950e09890f8 100644 --- a/Libraries/Renderer/ReactFabric-prod.js +++ b/Libraries/Renderer/ReactFabric-prod.js @@ -945,9 +945,6 @@ var hasSymbol = "function" === typeof Symbol && Symbol["for"], REACT_PROVIDER_TYPE = hasSymbol ? Symbol["for"]("react.provider") : 60109, REACT_CONTEXT_TYPE = hasSymbol ? Symbol["for"]("react.context") : 60110, REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol["for"]("react.async_mode") : 60111, - REACT_FORWARD_REF_TYPE = hasSymbol - ? Symbol["for"]("react.forward_ref") - : 60112, MAYBE_ITERATOR_SYMBOL = "function" === typeof Symbol && Symbol.iterator; function getIteratorFn(maybeIterable) { if (null === maybeIterable || "undefined" === typeof maybeIterable) @@ -1494,8 +1491,7 @@ var ReactNativeComponent = (function(_React$Component) { frameDeadlineObject = { timeRemaining: function() { return frameDeadline - now(); - }, - didTimeout: !1 + } }; function setTimeoutCallback() { frameDeadline = now() + 5; @@ -1634,6 +1630,136 @@ 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; @@ -1717,9 +1843,6 @@ function createFiberFromElement(element, mode, expirationTime) { case REACT_CONTEXT_TYPE: fiberTag = 12; break; - case REACT_FORWARD_REF_TYPE: - fiberTag = 14; - break; default: if ("number" === typeof type.tag) return ( @@ -1800,40 +1923,6 @@ 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, @@ -1989,7 +2078,6 @@ function commitCallbacks(queue, context) { } } function ReactFiberClassComponent( - legacyContext, scheduleWork, computeExpirationForFiber, memoizeProps, @@ -2037,80 +2125,71 @@ function ReactFiberClassComponent( instance.state !== workInProgress && updater.enqueueReplaceState(instance, instance.state, null); } - function callGetDerivedStateFromProps( - workInProgress, - instance, - nextProps, - prevState - ) { - workInProgress = workInProgress.type; - if ("function" === typeof workInProgress.getDerivedStateFromProps) - return workInProgress.getDerivedStateFromProps.call( + function callGetDerivedStateFromProps(workInProgress, instance, props) { + instance = workInProgress.type; + if ("function" === typeof instance.getDerivedStateFromProps) + return instance.getDerivedStateFromProps.call( null, - nextProps, - prevState + props, + workInProgress.memoizedState ); } - 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); - } - }; + 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); + } + }; return { adoptClassInstance: adoptClassInstance, callGetDerivedStateFromProps: callGetDerivedStateFromProps, constructClassInstance: function(workInProgress, props) { var ctor = workInProgress.type, unmaskedContext = getUnmaskedContext(workInProgress), - needsContext = isContextConsumer(workInProgress), + needsContext = + 2 === workInProgress.tag && null != workInProgress.type.contextTypes, context = needsContext ? getMaskedContext(workInProgress, unmaskedContext) : emptyObject; @@ -2119,7 +2198,7 @@ function ReactFiberClassComponent( null !== ctor.state && void 0 !== ctor.state ? ctor.state : null; adoptClassInstance(workInProgress, ctor); workInProgress.memoizedState = state; - props = callGetDerivedStateFromProps(workInProgress, ctor, props, state); + props = callGetDerivedStateFromProps(workInProgress, ctor, props); null !== props && void 0 !== props && (workInProgress.memoizedState = Object.assign( @@ -2127,7 +2206,10 @@ function ReactFiberClassComponent( workInProgress.memoizedState, props )); - needsContext && cacheContext(workInProgress, unmaskedContext, context); + needsContext && + ((workInProgress = workInProgress.stateNode), + (workInProgress.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext), + (workInProgress.__reactInternalMemoizedMaskedChildContext = context)); return ctor; }, mountClassInstance: function(workInProgress, renderExpirationTime) { @@ -2140,10 +2222,9 @@ function ReactFiberClassComponent( instance.state = workInProgress.memoizedState; instance.refs = emptyObject; instance.context = getMaskedContext(workInProgress, unmaskedContext); - "function" === typeof ctor.getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate || - ("function" !== typeof instance.UNSAFE_componentWillMount && - "function" !== typeof instance.componentWillMount) || + ("function" !== typeof instance.UNSAFE_componentWillMount && + "function" !== typeof instance.componentWillMount) || + "function" === typeof ctor.getDerivedStateFromProps || ((ctor = instance.state), "function" === typeof instance.componentWillMount && instance.componentWillMount(), @@ -2174,11 +2255,9 @@ function ReactFiberClassComponent( oldContext = instance.context, newUnmaskedContext = getUnmaskedContext(workInProgress); newUnmaskedContext = getMaskedContext(workInProgress, newUnmaskedContext); - (ctor = + ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && + "function" !== typeof instance.componentWillReceiveProps) || "function" === typeof ctor.getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate) || - ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && - "function" !== typeof instance.componentWillReceiveProps) || ((oldProps !== newProps || oldContext !== newUnmaskedContext) && callComponentWillReceiveProps( workInProgress, @@ -2186,7 +2265,14 @@ function ReactFiberClassComponent( newProps, newUnmaskedContext )); - oldContext = workInProgress.memoizedState; + oldContext = void 0; + oldProps !== newProps && + (oldContext = callGetDerivedStateFromProps( + workInProgress, + instance, + newProps + )); + var oldState = workInProgress.memoizedState; renderExpirationTime = null !== workInProgress.updateQueue ? processUpdateQueue( @@ -2197,33 +2283,18 @@ function ReactFiberClassComponent( newProps, renderExpirationTime ) - : oldContext; - var derivedStateFromProps = void 0; - oldProps !== newProps && - (derivedStateFromProps = callGetDerivedStateFromProps( - workInProgress, - instance, - newProps, - renderExpirationTime - )); - if (null !== derivedStateFromProps && void 0 !== derivedStateFromProps) { - renderExpirationTime = + : oldState; + null !== oldContext && + void 0 !== oldContext && + (renderExpirationTime = null === renderExpirationTime || void 0 === renderExpirationTime - ? derivedStateFromProps - : Object.assign({}, renderExpirationTime, derivedStateFromProps); - var _updateQueue = workInProgress.updateQueue; - null !== _updateQueue && - (_updateQueue.baseState = Object.assign( - {}, - _updateQueue.baseState, - derivedStateFromProps - )); - } + ? oldContext + : Object.assign({}, renderExpirationTime, oldContext)); if ( !( oldProps !== newProps || - oldContext !== renderExpirationTime || - hasContextChanged() || + oldState !== renderExpirationTime || + didPerformWorkStackCursor.current || (null !== workInProgress.updateQueue && workInProgress.updateQueue.hasForceUpdate) ) @@ -2237,18 +2308,26 @@ function ReactFiberClassComponent( workInProgress, oldProps, newProps, - oldContext, + oldState, renderExpirationTime, newUnmaskedContext )) - ? (ctor || - ("function" !== typeof instance.UNSAFE_componentWillMount && - "function" !== typeof instance.componentWillMount) || - ("function" === typeof instance.componentWillMount && - instance.componentWillMount(), - "function" === typeof instance.UNSAFE_componentWillMount && - instance.UNSAFE_componentWillMount()), - "function" === typeof instance.componentDidMount && + ? (("function" !== typeof instance.UNSAFE_componentWillUpdate && + "function" !== typeof instance.componentWillUpdate) || + "function" === typeof ctor.getDerivedStateFromProps || + ("function" === typeof instance.componentWillUpdate && + instance.componentWillUpdate( + newProps, + renderExpirationTime, + newUnmaskedContext + ), + "function" === typeof instance.UNSAFE_componentWillUpdate && + instance.UNSAFE_componentWillUpdate( + newProps, + renderExpirationTime, + newUnmaskedContext + )), + "function" === typeof instance.componentDidUpdate && (workInProgress.effectTag |= 4)) : ("function" === typeof instance.componentDidMount && (workInProgress.effectTag |= 4), @@ -2273,11 +2352,9 @@ function ReactFiberClassComponent( oldContext = instance.context, newUnmaskedContext = getUnmaskedContext(workInProgress); newUnmaskedContext = getMaskedContext(workInProgress, newUnmaskedContext); - (ctor = + ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && + "function" !== typeof instance.componentWillReceiveProps) || "function" === typeof ctor.getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate) || - ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && - "function" !== typeof instance.componentWillReceiveProps) || ((oldProps !== newProps || oldContext !== newUnmaskedContext) && callComponentWillReceiveProps( workInProgress, @@ -2285,6 +2362,13 @@ function ReactFiberClassComponent( newProps, newUnmaskedContext )); + var derivedStateFromProps = void 0; + oldProps !== newProps && + (derivedStateFromProps = callGetDerivedStateFromProps( + workInProgress, + instance, + newProps + )); oldContext = workInProgress.memoizedState; renderExpirationTime = null !== workInProgress.updateQueue @@ -2297,32 +2381,17 @@ function ReactFiberClassComponent( renderExpirationTime ) : oldContext; - var derivedStateFromProps = void 0; - oldProps !== newProps && - (derivedStateFromProps = callGetDerivedStateFromProps( - workInProgress, - instance, - newProps, - renderExpirationTime - )); - if (null !== derivedStateFromProps && void 0 !== derivedStateFromProps) { - renderExpirationTime = + null !== derivedStateFromProps && + void 0 !== derivedStateFromProps && + (renderExpirationTime = null === renderExpirationTime || void 0 === renderExpirationTime ? derivedStateFromProps - : Object.assign({}, renderExpirationTime, derivedStateFromProps); - var _updateQueue3 = workInProgress.updateQueue; - null !== _updateQueue3 && - (_updateQueue3.baseState = Object.assign( - {}, - _updateQueue3.baseState, - derivedStateFromProps - )); - } + : Object.assign({}, renderExpirationTime, derivedStateFromProps)); if ( !( oldProps !== newProps || oldContext !== renderExpirationTime || - hasContextChanged() || + didPerformWorkStackCursor.current || (null !== workInProgress.updateQueue && workInProgress.updateQueue.hasForceUpdate) ) @@ -2332,10 +2401,6 @@ function ReactFiberClassComponent( (oldProps === current.memoizedProps && oldContext === current.memoizedState) || (workInProgress.effectTag |= 4), - "function" !== typeof instance.getSnapshotBeforeUpdate || - (oldProps === current.memoizedProps && - oldContext === current.memoizedState) || - (workInProgress.effectTag |= 2048), !1 ); (derivedStateFromProps = checkShouldComponentUpdate( @@ -2346,9 +2411,9 @@ function ReactFiberClassComponent( renderExpirationTime, newUnmaskedContext )) - ? (ctor || - ("function" !== typeof instance.UNSAFE_componentWillUpdate && - "function" !== typeof instance.componentWillUpdate) || + ? (("function" !== typeof instance.UNSAFE_componentWillUpdate && + "function" !== typeof instance.componentWillUpdate) || + "function" === typeof ctor.getDerivedStateFromProps || ("function" === typeof instance.componentWillUpdate && instance.componentWillUpdate( newProps, @@ -2362,17 +2427,11 @@ function ReactFiberClassComponent( newUnmaskedContext )), "function" === typeof instance.componentDidUpdate && - (workInProgress.effectTag |= 4), - "function" === typeof instance.getSnapshotBeforeUpdate && - (workInProgress.effectTag |= 2048)) + (workInProgress.effectTag |= 4)) : ("function" !== typeof instance.componentDidUpdate || (oldProps === current.memoizedProps && oldContext === current.memoizedState) || (workInProgress.effectTag |= 4), - "function" !== typeof instance.getSnapshotBeforeUpdate || - (oldProps === current.memoizedProps && - oldContext === current.memoizedState) || - (workInProgress.effectTag |= 2048), memoizeProps(workInProgress, newProps), memoizeState(workInProgress, renderExpirationTime)); instance.props = newProps; @@ -3055,12 +3114,34 @@ function ChildReconciler(shouldTrackSideEffects) { }; } var reconcileChildFibers = ChildReconciler(!0), - mountChildFibers = ChildReconciler(!1); + 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; +} function ReactFiberBeginWork( config, hostContext, - legacyContext, - newContext, hydrationContext, scheduleWork, computeExpirationForFiber @@ -3157,12 +3238,7 @@ function ReactFiberBeginWork( changedBits, renderExpirationTime ) { - var fiber = workInProgress.child; - for ( - null !== fiber && (fiber["return"] = workInProgress); - null !== fiber; - - ) { + for (var fiber = workInProgress.child; null !== fiber; ) { switch (fiber.tag) { case 12: var nextFiber = fiber.stateNode | 0; @@ -3218,10 +3294,10 @@ function ReactFiberBeginWork( workInProgress, renderExpirationTime ) { - var context = workInProgress.type._context, + var context = workInProgress.type.context, newProps = workInProgress.pendingProps, oldProps = workInProgress.memoizedProps; - if (!hasLegacyContextChanged() && oldProps === newProps) + if (!didPerformWorkStackCursor.current && oldProps === newProps) return ( (workInProgress.stateNode = 0), pushProvider(workInProgress), @@ -3308,19 +3384,11 @@ 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) { @@ -3347,7 +3415,7 @@ function ReactFiberBeginWork( pushHostRootContext(workInProgress); break; case 2: - pushLegacyContextProvider(workInProgress); + pushContextProvider(workInProgress); break; case 4: pushHostContainer( @@ -3384,8 +3452,7 @@ function ReactFiberBeginWork( ((props = callGetDerivedStateFromProps( workInProgress, fn, - props, - workInProgress.memoizedState + props )), null !== props && void 0 !== props && @@ -3394,7 +3461,7 @@ function ReactFiberBeginWork( workInProgress.memoizedState, props ))), - (props = pushLegacyContextProvider(workInProgress)), + (props = pushContextProvider(workInProgress)), adoptClassInstance(workInProgress, fn), mountClassInstance(workInProgress, renderExpirationTime), (current = finishClassComponent( @@ -3414,7 +3481,7 @@ function ReactFiberBeginWork( return ( (props = workInProgress.type), (renderExpirationTime = workInProgress.pendingProps), - hasLegacyContextChanged() || + didPerformWorkStackCursor.current || workInProgress.memoizedProps !== renderExpirationTime ? ((fn = getUnmaskedContext(workInProgress)), (fn = getMaskedContext(workInProgress, fn)), @@ -3430,7 +3497,7 @@ function ReactFiberBeginWork( current ); case 2: - props = pushLegacyContextProvider(workInProgress); + props = pushContextProvider(workInProgress); null === current ? null === workInProgress.stateNode ? (constructClassInstance( @@ -3512,7 +3579,7 @@ function ReactFiberBeginWork( updateQueue = workInProgress.memoizedProps; fn = workInProgress.pendingProps; unmaskedContext = null !== current ? current.memoizedProps : null; - if (!hasLegacyContextChanged() && updateQueue === fn) { + if (!didPerformWorkStackCursor.current && updateQueue === fn) { if ( (updateQueue = workInProgress.mode & 1 && @@ -3554,7 +3621,7 @@ function ReactFiberBeginWork( case 7: return ( (props = workInProgress.pendingProps), - hasLegacyContextChanged() || + didPerformWorkStackCursor.current || workInProgress.memoizedProps !== props || (props = workInProgress.memoizedProps), (fn = props.children), @@ -3584,7 +3651,8 @@ function ReactFiberBeginWork( workInProgress.stateNode.containerInfo ), (props = workInProgress.pendingProps), - hasLegacyContextChanged() || workInProgress.memoizedProps !== props + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== props ? (null === current ? (workInProgress.child = reconcileChildFibers( workInProgress, @@ -3601,21 +3669,10 @@ function ReactFiberBeginWork( )), current ); - case 14: - return ( - (renderExpirationTime = workInProgress.type.render), - (renderExpirationTime = renderExpirationTime( - workInProgress.pendingProps, - workInProgress.ref - )), - reconcileChildren(current, workInProgress, renderExpirationTime), - (workInProgress.memoizedProps = renderExpirationTime), - workInProgress.child - ); case 10: return ( (renderExpirationTime = workInProgress.pendingProps), - hasLegacyContextChanged() || + didPerformWorkStackCursor.current || workInProgress.memoizedProps !== renderExpirationTime ? (reconcileChildren( current, @@ -3633,7 +3690,7 @@ function ReactFiberBeginWork( case 11: return ( (renderExpirationTime = workInProgress.pendingProps.children), - hasLegacyContextChanged() || + didPerformWorkStackCursor.current || (null !== renderExpirationTime && workInProgress.memoizedProps !== renderExpirationTime) ? (reconcileChildren( @@ -3656,33 +3713,43 @@ function ReactFiberBeginWork( renderExpirationTime ); case 12: - fn = workInProgress.type; - unmaskedContext = workInProgress.pendingProps; - var oldProps = workInProgress.memoizedProps; - props = fn._currentValue; - updateQueue = fn._changedBits; - if ( - hasLegacyContextChanged() || - 0 !== updateQueue || - oldProps !== unmaskedContext - ) { - workInProgress.memoizedProps = unmaskedContext; - oldProps = unmaskedContext.unstable_observedBits; - if (void 0 === oldProps || null === oldProps) oldProps = 1073741823; - workInProgress.stateNode = oldProps; - 0 !== (updateQueue & oldProps) && - propagateContextChange( - workInProgress, - fn, - updateQueue, - renderExpirationTime - ); - renderExpirationTime = unmaskedContext.children; - renderExpirationTime = renderExpirationTime(props); - reconcileChildren(current, workInProgress, renderExpirationTime); - current = workInProgress.child; - } else - current = bailoutOnAlreadyFinishedWork(current, workInProgress); + a: { + fn = workInProgress.type; + unmaskedContext = workInProgress.pendingProps; + updateQueue = workInProgress.memoizedProps; + props = fn._currentValue; + var changedBits = fn._changedBits; + if ( + didPerformWorkStackCursor.current || + 0 !== changedBits || + updateQueue !== unmaskedContext + ) { + workInProgress.memoizedProps = unmaskedContext; + var observedBits = unmaskedContext.unstable_observedBits; + if (void 0 === observedBits || null === observedBits) + observedBits = 1073741823; + workInProgress.stateNode = observedBits; + if (0 !== (changedBits & observedBits)) + propagateContextChange( + workInProgress, + fn, + changedBits, + renderExpirationTime + ); + else if ( + null !== updateQueue && + updateQueue.children === unmaskedContext.children + ) { + current = bailoutOnAlreadyFinishedWork(current, workInProgress); + break a; + } + renderExpirationTime = unmaskedContext.children; + renderExpirationTime = renderExpirationTime(props); + reconcileChildren(current, workInProgress, renderExpirationTime); + current = workInProgress.child; + } else + current = bailoutOnAlreadyFinishedWork(current, workInProgress); + } return current; default: invariant( @@ -3693,13 +3760,7 @@ function ReactFiberBeginWork( } }; } -function ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext -) { +function ReactFiberCompleteWork(config, hostContext, hydrationContext) { function markUpdate(workInProgress) { workInProgress.effectTag |= 4; } @@ -3732,9 +3793,6 @@ function ReactFiberCompleteWork( popHostContext = hostContext.popHostContext, getHostContext = hostContext.getHostContext, popHostContainer = hostContext.popHostContainer, - popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popProvider = newContext.popProvider, prepareToHydrateHostInstance = hydrationContext.prepareToHydrateHostInstance, prepareToHydrateHostTextInstance = @@ -3834,7 +3892,7 @@ function ReactFiberCompleteWork( return null; case 2: return ( - popLegacyContextProvider(workInProgress), + popContextProvider(workInProgress), (current = workInProgress.stateNode), (newProps = workInProgress.updateQueue), null !== newProps && @@ -3847,7 +3905,8 @@ function ReactFiberCompleteWork( ); case 3: popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); + pop(didPerformWorkStackCursor, workInProgress); + pop(contextStackCursor, workInProgress); newProps = workInProgress.stateNode; newProps.pendingContext && ((newProps.context = newProps.pendingContext), @@ -3999,8 +4058,6 @@ function ReactFiberCompleteWork( return (workInProgress.tag = 7), null; case 9: return null; - case 14: - return null; case 10: return null; case 11: @@ -4031,16 +4088,11 @@ function ReactFiberCompleteWork( } function ReactFiberUnwindWork( hostContext, - legacyContext, - newContext, scheduleWork, isAlreadyFailedLegacyErrorBoundary ) { var popHostContainer = hostContext.popHostContainer, - popHostContext = hostContext.popHostContext, - popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popProvider = newContext.popProvider; + popHostContext = hostContext.popHostContext; return { throwException: function(returnFiber, sourceFiber, rawValue) { sourceFiber.effectTag |= 512; @@ -4081,7 +4133,7 @@ function ReactFiberUnwindWork( unwindWork: function(workInProgress) { switch (workInProgress.tag) { case 2: - popLegacyContextProvider(workInProgress); + popContextProvider(workInProgress); var effectTag = workInProgress.effectTag; return effectTag & 1024 ? ((workInProgress.effectTag = (effectTag & -1025) | 64), @@ -4090,7 +4142,8 @@ function ReactFiberUnwindWork( case 3: return ( popHostContainer(workInProgress), - popTopLevelLegacyContextObject(workInProgress), + pop(didPerformWorkStackCursor, workInProgress), + pop(contextStackCursor, workInProgress), (effectTag = workInProgress.effectTag), effectTag & 1024 ? ((workInProgress.effectTag = (effectTag & -1025) | 64), @@ -4106,25 +4159,6 @@ 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); - } } }; } @@ -4133,7 +4167,7 @@ function logError(boundary, errorInfo) { null === errorInfo.stack && getStackAddendumByWorkInProgressFiber(source); null !== source && getComponentName(source); errorInfo = errorInfo.value; - null !== boundary && 2 === boundary.tag && getComponentName(boundary); + null !== boundary && getComponentName(boundary); try { (errorInfo && errorInfo.suppressReactErrorLogging) || console.error(errorInfo); @@ -4157,32 +4191,7 @@ function ReactFiberCommitWork( } catch (refError) { captureError(current, refError); } - else ref.current = null; - } - function commitBeforeMutationLifeCycles(current, finishedWork) { - switch (finishedWork.tag) { - case 2: - if (finishedWork.effectTag & 2048 && null !== current) { - var prevProps = current.memoizedProps, - prevState = current.memoizedState; - current = finishedWork.stateNode; - current.props = finishedWork.memoizedProps; - current.state = finishedWork.memoizedState; - finishedWork = current.getSnapshotBeforeUpdate(prevProps, prevState); - current.__reactInternalSnapshotBeforeUpdate = finishedWork; - } - break; - case 3: - case 5: - case 6: - case 4: - break; - default: - invariant( - !1, - "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue." - ); - } + else ref.value = null; } function commitLifeCycles(finishedRoot, current, finishedWork) { switch (finishedWork.tag) { @@ -4198,11 +4207,7 @@ function ReactFiberCommitWork( current = current.memoizedState; finishedRoot.props = finishedWork.memoizedProps; finishedRoot.state = finishedWork.memoizedState; - finishedRoot.componentDidUpdate( - prevProps, - current, - finishedRoot.__reactInternalSnapshotBeforeUpdate - ); + finishedRoot.componentDidUpdate(prevProps, current); } finishedWork = finishedWork.updateQueue; null !== finishedWork && commitCallbacks(finishedWork, finishedRoot); @@ -4262,12 +4267,9 @@ function ReactFiberCommitWork( onUncaughtError.state = finishedWork.memoizedState; for (ctor = 0; ctor < capturedErrors.length; ctor++) { updateQueue = capturedErrors[ctor]; - var _error = updateQueue.value, - stack = updateQueue.stack; + var _error = updateQueue.value; logError(finishedWork, updateQueue); - onUncaughtError.componentDidCatch(_error, { - componentStack: null !== stack ? stack : "" - }); + onUncaughtError.componentDidCatch(_error); } break; case 3: @@ -4293,25 +4295,23 @@ function ReactFiberCommitWork( function commitAttachRef(finishedWork) { var ref = finishedWork.ref; if (null !== ref) { - var _instance6 = finishedWork.stateNode; + var _instance5 = finishedWork.stateNode; switch (finishedWork.tag) { case 5: - finishedWork = getPublicInstance(_instance6); + finishedWork = getPublicInstance(_instance5); break; default: - finishedWork = _instance6; + finishedWork = _instance5; } "function" === typeof ref ? ref(finishedWork) - : (ref.current = finishedWork); + : (ref.value = finishedWork); } } function commitDetachRef(current) { current = current.ref; null !== current && - ("function" === typeof current - ? current(null) - : (current.current = null)); + ("function" === typeof current ? current(null) : (current.value = null)); } function commitNestedUnmounts(root) { for (var node = root; ; ) { @@ -4320,12 +4320,12 @@ function ReactFiberCommitWork( switch (current.tag) { case 2: safelyDetachRef(current); - var _instance7 = current.stateNode; - if ("function" === typeof _instance7.componentWillUnmount) + var _instance6 = current.stateNode; + if ("function" === typeof _instance6.componentWillUnmount) try { - (_instance7.props = current.memoizedProps), - (_instance7.state = current.memoizedState), - _instance7.componentWillUnmount(); + (_instance6.props = current.memoizedProps), + (_instance6.state = current.memoizedState), + _instance6.componentWillUnmount(); } catch (unmountError) { captureError(current, unmountError); } @@ -4403,7 +4403,6 @@ function ReactFiberCommitWork( commitContainer(finishedWork); }, commitLifeCycles: commitLifeCycles, - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, commitErrorLogging: commitErrorLogging, commitAttachRef: commitAttachRef, commitDetachRef: commitDetachRef @@ -4413,7 +4412,7 @@ function ReactFiberCommitWork( invariant(!1, "Mutating reconciler is disabled."); } var NO_CONTEXT = {}; -function ReactFiberHostContext(config, stack) { +function ReactFiberHostContext(config) { function requiredContext(c) { invariant( c !== NO_CONTEXT, @@ -4422,13 +4421,10 @@ function ReactFiberHostContext(config, stack) { return c; } var getChildHostContext = config.getChildHostContext, - 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); + getRootHostContext = config.getRootHostContext, + contextStackCursor = { current: NO_CONTEXT }, + contextFiberStackCursor = { current: NO_CONTEXT }, + rootInstanceStackCursor = { current: NO_CONTEXT }; return { getHostContext: function() { return requiredContext(contextStackCursor.current); @@ -4447,10 +4443,8 @@ function ReactFiberHostContext(config, stack) { }, pushHostContainer: function(fiber, nextRootInstance) { push(rootInstanceStackCursor, nextRootInstance, fiber); - push(contextFiberStackCursor, fiber, fiber); - push(contextStackCursor, NO_CONTEXT, fiber); nextRootInstance = getRootHostContext(nextRootInstance); - pop(contextStackCursor, fiber); + push(contextFiberStackCursor, fiber, fiber); push(contextStackCursor, nextRootInstance, fiber); }, pushHostContext: function(fiber) { @@ -4460,6 +4454,10 @@ function ReactFiberHostContext(config, stack) { context !== rootInstance && (push(contextFiberStackCursor, fiber, fiber), push(contextStackCursor, rootInstance, fiber)); + }, + resetHostContainer: function() { + contextStackCursor.current = NO_CONTEXT; + rootInstanceStackCursor.current = NO_CONTEXT; } }; } @@ -4619,198 +4617,22 @@ function ReactFiberHydrationContext(config) { } }; } -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; - 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; - } - }; -} -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"]); + function resetContextStack() { + for (; -1 < index; ) (valueStack[index] = null), index--; + 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; + } + index$1 = -1; nextRoot = null; nextRenderExpirationTime = 0; nextUnitOfWork = null; @@ -4883,7 +4705,7 @@ function ReactFiberScheduler(config) { workInProgress$jscomp$0 = unwindWork(workInProgress$jscomp$0); if (null !== workInProgress$jscomp$0) return ( - (workInProgress$jscomp$0.effectTag &= 2559), workInProgress$jscomp$0 + (workInProgress$jscomp$0.effectTag &= 511), workInProgress$jscomp$0 ); null !== returnFiber && ((returnFiber.firstEffect = returnFiber.lastEffect = null), @@ -4916,7 +4738,7 @@ function ReactFiberScheduler(config) { root !== nextRoot || null === nextUnitOfWork ) - resetStack(), + resetContextStack(), (nextRoot = root), (nextRenderExpirationTime = expirationTime), (nextUnitOfWork = createWorkInProgress( @@ -5046,8 +4868,8 @@ function ReactFiberScheduler(config) { !isWorking && 0 !== nextRenderExpirationTime && expirationTime < nextRenderExpirationTime && - resetStack(); - (isWorking && !isCommitting && nextRoot === root) || + resetContextStack(); + (nextRoot === root && isWorking) || requestWork(root, expirationTime); nestedUpdateCount > NESTED_UPDATE_LIMIT && invariant( @@ -5111,7 +4933,7 @@ function ReactFiberScheduler(config) { (nextFlushedExpirationTime = 1), performWorkOnRoot(root, 1, !1)) : 1 === expirationTime - ? performSyncWork() + ? performWork(1, !1, null) : scheduleCallbackWithExpiration(expirationTime)); } function findHighestPriorityRoot() { @@ -5171,9 +4993,6 @@ function ReactFiberScheduler(config) { function performAsyncWork(dl) { performWork(0, !0, dl); } - function performSyncWork() { - performWork(1, !1, null); - } function performWork(minExpirationTime, isAsync, dl) { deadline = dl; findHighestPriorityRoot(); @@ -5296,25 +5115,6 @@ function ReactFiberScheduler(config) { for (nextEffect = firstEffect; null !== nextEffect; ) { var didError = !1, error = void 0; - try { - for (; null !== nextEffect; ) - nextEffect.effectTag & 2048 && - commitBeforeMutationLifeCycles(nextEffect.alternate, nextEffect), - (nextEffect = nextEffect.nextEffect); - } catch (e) { - (didError = !0), (error = e); - } - didError && - (invariant( - null !== nextEffect, - "Should have next effect. This error is likely caused by a bug in React. Please file an issue." - ), - onCommitPhaseError(nextEffect, error), - null !== nextEffect && (nextEffect = nextEffect.nextEffect)); - } - for (nextEffect = firstEffect; null !== nextEffect; ) { - didError = !1; - error = void 0; try { for (; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; @@ -5412,37 +5212,25 @@ function ReactFiberScheduler(config) { nextFlushedRoot.remainingExpirationTime = 0; hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error)); } - var stack = ReactFiberStack(), - hostContext = ReactFiberHostContext(config, stack), - legacyContext = ReactFiberLegacyContext(stack); - stack = ReactFiberNewContext(stack); - var hydrationContext = ReactFiberHydrationContext(config), + var hostContext = ReactFiberHostContext(config), + hydrationContext = ReactFiberHydrationContext(config), + resetHostContainer = hostContext.resetHostContainer, beginWork = ReactFiberBeginWork( config, hostContext, - legacyContext, - stack, hydrationContext, scheduleWork, computeExpirationForFiber ).beginWork, - completeWork = ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - stack, - hydrationContext - ).completeWork; + completeWork = ReactFiberCompleteWork(config, hostContext, hydrationContext) + .completeWork; hostContext = ReactFiberUnwindWork( hostContext, - legacyContext, - stack, scheduleWork, isAlreadyFailedLegacyErrorBoundary ); var throwException = hostContext.throwException, - unwindWork = hostContext.unwindWork, - unwindInterruptedWork = hostContext.unwindInterruptedWork; + unwindWork = hostContext.unwindWork; hostContext = ReactFiberCommitWork( config, onCommitPhaseError, @@ -5455,9 +5243,7 @@ function ReactFiberScheduler(config) { }, recalculateCurrentTime ); - var commitBeforeMutationLifeCycles = - hostContext.commitBeforeMutationLifeCycles, - commitResetTextContent = hostContext.commitResetTextContent, + var commitResetTextContent = hostContext.commitResetTextContent, commitPlacement = hostContext.commitPlacement, commitDeletion = hostContext.commitDeletion, commitWork = hostContext.commitWork, @@ -5512,10 +5298,7 @@ function ReactFiberScheduler(config) { !isRendering, "work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method." ); - nextFlushedRoot = root; - nextFlushedExpirationTime = expirationTime; performWorkOnRoot(root, expirationTime, !1); - performSyncWork(); finishRendering(); }, batchedUpdates: function(fn, a) { @@ -5526,7 +5309,7 @@ function ReactFiberScheduler(config) { } finally { (isBatchingUpdates = previousIsBatchingUpdates) || isRendering || - performSyncWork(); + performWork(1, !1, null); } }, unbatchedUpdates: function(fn, a) { @@ -5550,7 +5333,8 @@ function ReactFiberScheduler(config) { try { return syncUpdates(fn, a); } finally { - (isBatchingUpdates = previousIsBatchingUpdates), performSyncWork(); + (isBatchingUpdates = previousIsBatchingUpdates), + performWork(1, !1, null); } }, flushControlled: function(fn) { @@ -5591,7 +5375,7 @@ function ReactFiberScheduler(config) { (isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates), (isBatchingUpdates = previousIsBatchingUpdates) || isRendering || - performSyncWork(); + performWork(1, !1, null); } }, flushInteractiveUpdates: function() { @@ -5605,8 +5389,7 @@ function ReactFiberScheduler(config) { result <= lastUniqueAsyncExpiration && (result = lastUniqueAsyncExpiration + 1); return (lastUniqueAsyncExpiration = result); - }, - legacyContext: legacyContext + } }; } function ReactFiberReconciler$1(config) { @@ -5621,7 +5404,27 @@ function ReactFiberReconciler$1(config) { currentTime = container.current; if (parentComponent) { parentComponent = parentComponent._reactInternalFiber; - var parentContext = findCurrentUnmaskedContext(parentComponent); + 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; + } parentComponent = isContextProvider(parentComponent) ? processChildContext(parentComponent, parentContext) : parentContext; @@ -5650,11 +5453,7 @@ function ReactFiberReconciler$1(config) { config = ReactFiberScheduler(config); var recalculateCurrentTime = config.recalculateCurrentTime, computeExpirationForFiber = config.computeExpirationForFiber, - scheduleWork = config.scheduleWork, - legacyContext = config.legacyContext, - findCurrentUnmaskedContext = legacyContext.findCurrentUnmaskedContext, - isContextProvider = legacyContext.isContextProvider, - processChildContext = legacyContext.processChildContext; + scheduleWork = config.scheduleWork; return { createContainer: function(containerInfo, isAsync, hydrate) { isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0); @@ -6092,7 +5891,7 @@ ReactFabricRenderer.injectIntoDevTools({ findFiberByHostInstance: getInstanceFromTag, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 0, - version: "16.3.1", + version: "16.3.0-alpha.1", rendererPackageName: "react-native-renderer" }); var ReactFabric$2 = Object.freeze({ default: ReactFabric }), diff --git a/Libraries/Renderer/ReactNativeRenderer-dev.js b/Libraries/Renderer/ReactNativeRenderer-dev.js index 7fd62f11ca6..400472d29a3 100644 --- a/Libraries/Renderer/ReactNativeRenderer-dev.js +++ b/Libraries/Renderer/ReactNativeRenderer-dev.js @@ -26,9 +26,9 @@ var deepDiffer = require("deepDiffer"); var flattenStyle = require("flattenStyle"); var React = require("react"); var emptyObject = require("fbjs/lib/emptyObject"); +var checkPropTypes = require("prop-types/checkPropTypes"); var shallowEqual = require("fbjs/lib/shallowEqual"); var ExceptionsManager = require("ExceptionsManager"); -var checkPropTypes = require("prop-types/checkPropTypes"); var deepFreezeAndThrowOnMutationInDev = require("deepFreezeAndThrowOnMutationInDev"); var invokeGuardedCallback = function(name, func, context, a, b, c, d, e, f) { @@ -510,13 +510,11 @@ var injection$1 = { getNodeFromInstance = Injected.getNodeFromInstance; { - !(getNodeFromInstance && getInstanceFromNode) - ? warning( - false, - "EventPluginUtils.injection.injectComponentTree(...): Injected " + - "module is missing getNodeFromInstance or getInstanceFromNode." - ) - : void 0; + warning( + getNodeFromInstance && getInstanceFromNode, + "EventPluginUtils.injection.injectComponentTree(...): Injected " + + "module is missing getNodeFromInstance or getInstanceFromNode." + ); } } }; @@ -552,9 +550,10 @@ var validateEventDispatches = void 0; ? dispatchInstances.length : dispatchInstances ? 1 : 0; - !(instancesIsArr === listenersIsArr && instancesLen === listenersLen) - ? warning(false, "EventPluginUtils: Invalid `event`.") - : void 0; + warning( + instancesIsArr === listenersIsArr && instancesLen === listenersLen, + "EventPluginUtils: Invalid `event`." + ); }; } @@ -966,7 +965,6 @@ var Fragment = 10; var Mode = 11; var ContextConsumer = 12; var ContextProvider = 13; -var ForwardRef = 14; function getParent(inst) { do { @@ -1095,7 +1093,7 @@ function listenerAtPhase(inst, event, propagationPhase) { */ function accumulateDirectionalDispatches(inst, phase, event) { { - !inst ? warning(false, "Dispatching inst must not be null") : void 0; + warning(inst, "Dispatching inst must not be null"); } var listener = listenerAtPhase(inst, event, phase); if (listener) { @@ -1414,15 +1412,13 @@ SyntheticEvent.extend = function(Interface) { !target.constructor.Interface.hasOwnProperty(prop) && shouldBeReleasedProperties.indexOf(prop) === -1 ) { - !(didWarnForAddedNewProperty || target.isPersistent()) - ? warning( - false, - "This synthetic event is reused for performance reasons. If you're " + - "seeing this, you're adding a new property in the synthetic event object. " + - "The property is never released. See " + - "https://fb.me/react-event-pooling for more information." - ) - : void 0; + warning( + didWarnForAddedNewProperty || target.isPersistent(), + "This synthetic event is reused for performance reasons. If you're " + + "seeing this, you're adding a new property in the synthetic event object. " + + "The property is never released. See " + + "https://fb.me/react-event-pooling for more information." + ); didWarnForAddedNewProperty = true; } target[prop] = value; @@ -1469,18 +1465,16 @@ function getPooledWarningPropertyDefinition(propName, getVal) { function warn(action, result) { var warningCondition = false; - !warningCondition - ? warning( - false, - "This synthetic event is reused for performance reasons. If you're seeing this, " + - "you're %s `%s` on a released/nullified synthetic event. %s. " + - "If you must keep the original synthetic event around, use event.persist(). " + - "See https://fb.me/react-event-pooling for more information.", - action, - propName, - result - ) - : void 0; + warning( + warningCondition, + "This synthetic event is reused for performance reasons. If you're seeing this, " + + "you're %s `%s` on a released/nullified synthetic event. %s. " + + "If you must keep the original synthetic event around, use event.persist(). " + + "See https://fb.me/react-event-pooling for more information.", + action, + propName, + result + ); } } @@ -1598,15 +1592,13 @@ function getTouchIdentifier(_ref) { invariant(identifier != null, "Touch object is missing identifier."); { - !(identifier <= MAX_TOUCH_BANK) - ? warning( - false, - "Touch identifier %s is greater than maximum supported %s which causes " + - "performance issues backfilling array locations for all of the indices.", - identifier, - MAX_TOUCH_BANK - ) - : void 0; + warning( + identifier <= MAX_TOUCH_BANK, + "Touch identifier %s is greater than maximum supported %s which causes " + + "performance issues backfilling array locations for all of the indices.", + identifier, + MAX_TOUCH_BANK + ); } return identifier; } @@ -1705,9 +1697,10 @@ var ResponderTouchHistoryStore = { } { var activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch]; - !(activeRecord != null && activeRecord.touchActive) - ? warning(false, "Cannot find single active touch.") - : void 0; + warning( + activeRecord != null && activeRecord.touchActive, + "Cannot find single active touch." + ); } } } @@ -2809,9 +2802,6 @@ var REACT_CONTEXT_TYPE = hasSymbol ? Symbol["for"]("react.context") : 0xeace; var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol["for"]("react.async_mode") : 0xeacf; -var REACT_FORWARD_REF_TYPE = hasSymbol - ? Symbol["for"]("react.forward_ref") - : 0xead0; var MAYBE_ITERATOR_SYMBOL = typeof Symbol === "function" && Symbol.iterator; var FAUX_ITERATOR_SYMBOL = "@@iterator"; @@ -2993,7 +2983,7 @@ var TouchHistoryMath = { // TODO: this is special because it gets imported during build. -var ReactVersion = "16.3.1"; +var ReactVersion = "16.3.0-alpha.1"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { @@ -3663,17 +3653,15 @@ function findNodeHandle(componentOrHandle) { { var owner = ReactCurrentOwner.current; if (owner !== null && owner.stateNode !== null) { - !owner.stateNode._warnedAboutRefsInRender - ? warning( - false, - "%s is accessing findNodeHandle inside its render(). " + - "render() should be a pure function of props and state. It should " + - "never access something that requires stale data from the previous " + - "render, such as refs. Move this logic to componentDidMount and " + - "componentDidUpdate instead.", - getComponentName(owner) || "A component" - ) - : void 0; + warning( + owner.stateNode._warnedAboutRefsInRender, + "%s is accessing findNodeHandle inside its render(). " + + "render() should be a pure function of props and state. It should " + + "never access something that requires stale data from the previous " + + "render, such as refs. Move this logic to componentDidMount and " + + "componentDidUpdate instead.", + getComponentName(owner) || "A component" + ); owner.stateNode._warnedAboutRefsInRender = true; } @@ -4128,10 +4116,9 @@ var Callback = /* */ 32; var DidCapture = /* */ 64; var Ref = /* */ 128; var ErrLog = /* */ 256; -var Snapshot = /* */ 2048; // Union of all host effects -var HostEffectMask = /* */ 2559; +var HostEffectMask = /* */ 511; var Incomplete = /* */ 512; var ShouldCapture = /* */ 1024; @@ -4179,17 +4166,15 @@ function isMounted(component) { if (owner !== null && owner.tag === ClassComponent) { var ownerFiber = owner; var instance = ownerFiber.stateNode; - !instance._warnedAboutRefsInRender - ? warning( - false, - "%s is accessing isMounted inside its render() function. " + - "render() should be a pure function of props and state. It should " + - "never access something that requires stale data from the previous " + - "render, such as refs. Move this logic to componentDidMount and " + - "componentDidUpdate instead.", - getComponentName(ownerFiber) || "A component" - ) - : void 0; + warning( + instance._warnedAboutRefsInRender, + "%s is accessing isMounted inside its render() function. " + + "render() should be a pure function of props and state. It should " + + "never access something that requires stale data from the previous " + + "render, such as refs. Move this logic to componentDidMount and " + + "componentDidUpdate instead.", + getComponentName(ownerFiber) || "A component" + ); instance._warnedAboutRefsInRender = true; } } @@ -4400,6 +4385,879 @@ function findCurrentHostFiberWithNoPortals(parent) { return null; } +var valueStack = []; + +var fiberStack = void 0; + +{ + fiberStack = []; +} + +var index = -1; + +function createCursor(defaultValue) { + return { + current: defaultValue + }; +} + +function pop(cursor, fiber) { + if (index < 0) { + { + warning(false, "Unexpected pop."); + } + return; + } + + { + if (fiber !== fiberStack[index]) { + warning(false, "Unexpected Fiber popped."); + } + } + + cursor.current = valueStack[index]; + + valueStack[index] = null; + + { + fiberStack[index] = null; + } + + index--; +} + +function push(cursor, value, fiber) { + index++; + + valueStack[index] = cursor.current; + + { + fiberStack[index] = fiber; + } + + cursor.current = value; +} + +function reset() { + while (index > -1) { + valueStack[index] = null; + + { + fiberStack[index] = null; + } + + index--; + } +} + +var describeComponentFrame = function(name, source, ownerName) { + return ( + "\n in " + + (name || "Unknown") + + (source + ? " (at " + + source.fileName.replace(/^.*[\\\/]/, "") + + ":" + + source.lineNumber + + ")" + : ownerName ? " (created by " + ownerName + ")" : "") + ); +}; + +function describeFiber(fiber) { + switch (fiber.tag) { + case IndeterminateComponent: + case FunctionalComponent: + case ClassComponent: + case HostComponent: + var owner = fiber._debugOwner; + var source = fiber._debugSource; + var name = getComponentName(fiber); + var ownerName = null; + if (owner) { + ownerName = getComponentName(owner); + } + return describeComponentFrame(name, source, ownerName); + default: + return ""; + } +} + +// This function can only be called with a work-in-progress fiber and +// only during begin or complete phase. Do not call it under any other +// circumstances. +function getStackAddendumByWorkInProgressFiber(workInProgress) { + var info = ""; + var node = workInProgress; + do { + info += describeFiber(node); + // Otherwise this return pointer might point to the wrong tree: + node = node["return"]; + } while (node); + return info; +} + +function getCurrentFiberOwnerName() { + { + var fiber = ReactDebugCurrentFiber.current; + if (fiber === null) { + return null; + } + var owner = fiber._debugOwner; + if (owner !== null && typeof owner !== "undefined") { + return getComponentName(owner); + } + } + return null; +} + +function getCurrentFiberStackAddendum() { + { + var fiber = ReactDebugCurrentFiber.current; + if (fiber === null) { + return null; + } + // Safe because if current fiber exists, we are reconciling, + // and it is guaranteed to be the work-in-progress version. + return getStackAddendumByWorkInProgressFiber(fiber); + } + return null; +} + +function resetCurrentFiber() { + ReactDebugCurrentFrame.getCurrentStack = null; + ReactDebugCurrentFiber.current = null; + ReactDebugCurrentFiber.phase = null; +} + +function setCurrentFiber(fiber) { + ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackAddendum; + ReactDebugCurrentFiber.current = fiber; + ReactDebugCurrentFiber.phase = null; +} + +function setCurrentPhase(phase) { + ReactDebugCurrentFiber.phase = phase; +} + +var ReactDebugCurrentFiber = { + current: null, + phase: null, + resetCurrentFiber: resetCurrentFiber, + setCurrentFiber: setCurrentFiber, + setCurrentPhase: setCurrentPhase, + getCurrentFiberOwnerName: getCurrentFiberOwnerName, + getCurrentFiberStackAddendum: getCurrentFiberStackAddendum +}; + +// Re-export dynamic flags from the fbsource version. +var _require = require("ReactFeatureFlags"); + +var enableGetDerivedStateFromCatch = _require.enableGetDerivedStateFromCatch; +var debugRenderPhaseSideEffects = _require.debugRenderPhaseSideEffects; +var debugRenderPhaseSideEffectsForStrictMode = + _require.debugRenderPhaseSideEffectsForStrictMode; +var warnAboutDeprecatedLifecycles = _require.warnAboutDeprecatedLifecycles; +var replayFailedUnitOfWorkWithInvokeGuardedCallback = + _require.replayFailedUnitOfWorkWithInvokeGuardedCallback; + +var enableUserTimingAPI = true; +var enableMutatingReconciler = true; +var enableNoopReconciler = false; +var enablePersistentReconciler = false; + +// Only used in www builds. + +// Prefix measurements so that it's possible to filter them. +// Longer prefixes are hard to read in DevTools. +var reactEmoji = "\u269B"; +var warningEmoji = "\u26D4"; +var supportsUserTiming = + typeof performance !== "undefined" && + typeof performance.mark === "function" && + typeof performance.clearMarks === "function" && + typeof performance.measure === "function" && + typeof performance.clearMeasures === "function"; + +// Keep track of current fiber so that we know the path to unwind on pause. +// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them? +var currentFiber = null; +// If we're in the middle of user code, which fiber and method is it? +// Reusing `currentFiber` would be confusing for this because user code fiber +// can change during commit phase too, but we don't need to unwind it (since +// lifecycles in the commit phase don't resemble a tree). +var currentPhase = null; +var currentPhaseFiber = null; +// Did lifecycle hook schedule an update? This is often a performance problem, +// so we will keep track of it, and include it in the report. +// Track commits caused by cascading updates. +var isCommitting = false; +var hasScheduledUpdateInCurrentCommit = false; +var hasScheduledUpdateInCurrentPhase = false; +var commitCountInCurrentWorkLoop = 0; +var effectCountInCurrentCommit = 0; +var isWaitingForCallback = false; +// During commits, we only show a measurement once per method name +// to avoid stretch the commit phase with measurement overhead. +var labelsInCurrentCommit = new Set(); + +var formatMarkName = function(markName) { + return reactEmoji + " " + markName; +}; + +var formatLabel = function(label, warning$$1) { + var prefix = warning$$1 ? warningEmoji + " " : reactEmoji + " "; + var suffix = warning$$1 ? " Warning: " + warning$$1 : ""; + return "" + prefix + label + suffix; +}; + +var beginMark = function(markName) { + performance.mark(formatMarkName(markName)); +}; + +var clearMark = function(markName) { + performance.clearMarks(formatMarkName(markName)); +}; + +var endMark = function(label, markName, warning$$1) { + var formattedMarkName = formatMarkName(markName); + var formattedLabel = formatLabel(label, warning$$1); + try { + performance.measure(formattedLabel, formattedMarkName); + } catch (err) {} + // If previous mark was missing for some reason, this will throw. + // This could only happen if React crashed in an unexpected place earlier. + // Don't pile on with more errors. + + // Clear marks immediately to avoid growing buffer. + performance.clearMarks(formattedMarkName); + performance.clearMeasures(formattedLabel); +}; + +var getFiberMarkName = function(label, debugID) { + return label + " (#" + debugID + ")"; +}; + +var getFiberLabel = function(componentName, isMounted, phase) { + if (phase === null) { + // These are composite component total time measurements. + return componentName + " [" + (isMounted ? "update" : "mount") + "]"; + } else { + // Composite component methods. + return componentName + "." + phase; + } +}; + +var beginFiberMark = function(fiber, phase) { + var componentName = getComponentName(fiber) || "Unknown"; + var debugID = fiber._debugID; + var isMounted = fiber.alternate !== null; + var label = getFiberLabel(componentName, isMounted, phase); + + if (isCommitting && labelsInCurrentCommit.has(label)) { + // During the commit phase, we don't show duplicate labels because + // there is a fixed overhead for every measurement, and we don't + // want to stretch the commit phase beyond necessary. + return false; + } + labelsInCurrentCommit.add(label); + + var markName = getFiberMarkName(label, debugID); + beginMark(markName); + return true; +}; + +var clearFiberMark = function(fiber, phase) { + var componentName = getComponentName(fiber) || "Unknown"; + var debugID = fiber._debugID; + var isMounted = fiber.alternate !== null; + var label = getFiberLabel(componentName, isMounted, phase); + var markName = getFiberMarkName(label, debugID); + clearMark(markName); +}; + +var endFiberMark = function(fiber, phase, warning$$1) { + var componentName = getComponentName(fiber) || "Unknown"; + var debugID = fiber._debugID; + var isMounted = fiber.alternate !== null; + var label = getFiberLabel(componentName, isMounted, phase); + var markName = getFiberMarkName(label, debugID); + endMark(label, markName, warning$$1); +}; + +var shouldIgnoreFiber = function(fiber) { + // Host components should be skipped in the timeline. + // We could check typeof fiber.type, but does this work with RN? + switch (fiber.tag) { + case HostRoot: + case HostComponent: + case HostText: + case HostPortal: + case CallComponent: + case ReturnComponent: + case Fragment: + case ContextProvider: + case ContextConsumer: + return true; + default: + return false; + } +}; + +var clearPendingPhaseMeasurement = function() { + if (currentPhase !== null && currentPhaseFiber !== null) { + clearFiberMark(currentPhaseFiber, currentPhase); + } + currentPhaseFiber = null; + currentPhase = null; + hasScheduledUpdateInCurrentPhase = false; +}; + +var pauseTimers = function() { + // Stops all currently active measurements so that they can be resumed + // if we continue in a later deferred loop from the same unit of work. + var fiber = currentFiber; + while (fiber) { + if (fiber._debugIsCurrentlyTiming) { + endFiberMark(fiber, null, null); + } + fiber = fiber["return"]; + } +}; + +var resumeTimersRecursively = function(fiber) { + if (fiber["return"] !== null) { + resumeTimersRecursively(fiber["return"]); + } + if (fiber._debugIsCurrentlyTiming) { + beginFiberMark(fiber, null); + } +}; + +var resumeTimers = function() { + // Resumes all measurements that were active during the last deferred loop. + if (currentFiber !== null) { + resumeTimersRecursively(currentFiber); + } +}; + +function recordEffect() { + if (enableUserTimingAPI) { + effectCountInCurrentCommit++; + } +} + +function recordScheduleUpdate() { + if (enableUserTimingAPI) { + if (isCommitting) { + hasScheduledUpdateInCurrentCommit = true; + } + if ( + currentPhase !== null && + currentPhase !== "componentWillMount" && + currentPhase !== "componentWillReceiveProps" + ) { + hasScheduledUpdateInCurrentPhase = true; + } + } +} + +function startRequestCallbackTimer() { + if (enableUserTimingAPI) { + if (supportsUserTiming && !isWaitingForCallback) { + isWaitingForCallback = true; + beginMark("(Waiting for async callback...)"); + } + } +} + +function stopRequestCallbackTimer(didExpire) { + if (enableUserTimingAPI) { + if (supportsUserTiming) { + isWaitingForCallback = false; + var warning$$1 = didExpire ? "React was blocked by main thread" : null; + endMark( + "(Waiting for async callback...)", + "(Waiting for async callback...)", + warning$$1 + ); + } + } +} + +function startWorkTimer(fiber) { + if (enableUserTimingAPI) { + if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { + return; + } + // If we pause, this is the fiber to unwind from. + currentFiber = fiber; + if (!beginFiberMark(fiber, null)) { + return; + } + fiber._debugIsCurrentlyTiming = true; + } +} + +function cancelWorkTimer(fiber) { + if (enableUserTimingAPI) { + if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { + return; + } + // Remember we shouldn't complete measurement for this fiber. + // Otherwise flamechart will be deep even for small updates. + fiber._debugIsCurrentlyTiming = false; + clearFiberMark(fiber, null); + } +} + +function stopWorkTimer(fiber) { + if (enableUserTimingAPI) { + if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { + return; + } + // If we pause, its parent is the fiber to unwind from. + currentFiber = fiber["return"]; + if (!fiber._debugIsCurrentlyTiming) { + return; + } + fiber._debugIsCurrentlyTiming = false; + endFiberMark(fiber, null, null); + } +} + +function stopFailedWorkTimer(fiber) { + if (enableUserTimingAPI) { + if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { + return; + } + // If we pause, its parent is the fiber to unwind from. + currentFiber = fiber["return"]; + if (!fiber._debugIsCurrentlyTiming) { + return; + } + fiber._debugIsCurrentlyTiming = false; + var warning$$1 = "An error was thrown inside this error boundary"; + endFiberMark(fiber, null, warning$$1); + } +} + +function startPhaseTimer(fiber, phase) { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + clearPendingPhaseMeasurement(); + if (!beginFiberMark(fiber, phase)) { + return; + } + currentPhaseFiber = fiber; + currentPhase = phase; + } +} + +function stopPhaseTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + if (currentPhase !== null && currentPhaseFiber !== null) { + var warning$$1 = hasScheduledUpdateInCurrentPhase + ? "Scheduled a cascading update" + : null; + endFiberMark(currentPhaseFiber, currentPhase, warning$$1); + } + currentPhase = null; + currentPhaseFiber = null; + } +} + +function startWorkLoopTimer(nextUnitOfWork) { + if (enableUserTimingAPI) { + currentFiber = nextUnitOfWork; + if (!supportsUserTiming) { + return; + } + commitCountInCurrentWorkLoop = 0; + // This is top level call. + // Any other measurements are performed within. + beginMark("(React Tree Reconciliation)"); + // Resume any measurements that were in progress during the last loop. + resumeTimers(); + } +} + +function stopWorkLoopTimer(interruptedBy) { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + var warning$$1 = null; + if (interruptedBy !== null) { + if (interruptedBy.tag === HostRoot) { + warning$$1 = "A top-level update interrupted the previous render"; + } else { + var componentName = getComponentName(interruptedBy) || "Unknown"; + warning$$1 = + "An update to " + componentName + " interrupted the previous render"; + } + } else if (commitCountInCurrentWorkLoop > 1) { + warning$$1 = "There were cascading updates"; + } + commitCountInCurrentWorkLoop = 0; + // Pause any measurements until the next loop. + pauseTimers(); + endMark( + "(React Tree Reconciliation)", + "(React Tree Reconciliation)", + warning$$1 + ); + } +} + +function startCommitTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + isCommitting = true; + hasScheduledUpdateInCurrentCommit = false; + labelsInCurrentCommit.clear(); + beginMark("(Committing Changes)"); + } +} + +function stopCommitTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + + var warning$$1 = null; + if (hasScheduledUpdateInCurrentCommit) { + warning$$1 = "Lifecycle hook scheduled a cascading update"; + } else if (commitCountInCurrentWorkLoop > 0) { + warning$$1 = "Caused by a cascading update in earlier commit"; + } + hasScheduledUpdateInCurrentCommit = false; + commitCountInCurrentWorkLoop++; + isCommitting = false; + labelsInCurrentCommit.clear(); + + endMark("(Committing Changes)", "(Committing Changes)", warning$$1); + } +} + +function startCommitHostEffectsTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + effectCountInCurrentCommit = 0; + beginMark("(Committing Host Effects)"); + } +} + +function stopCommitHostEffectsTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + var count = effectCountInCurrentCommit; + effectCountInCurrentCommit = 0; + endMark( + "(Committing Host Effects: " + count + " Total)", + "(Committing Host Effects)", + null + ); + } +} + +function startCommitLifeCyclesTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + effectCountInCurrentCommit = 0; + beginMark("(Calling Lifecycle Methods)"); + } +} + +function stopCommitLifeCyclesTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + var count = effectCountInCurrentCommit; + effectCountInCurrentCommit = 0; + endMark( + "(Calling Lifecycle Methods: " + count + " Total)", + "(Calling Lifecycle Methods)", + null + ); + } +} + +var warnedAboutMissingGetChildContext = void 0; + +{ + warnedAboutMissingGetChildContext = {}; +} + +// A cursor to the current merged context object on the stack. +var contextStackCursor = createCursor(emptyObject); +// A cursor to a boolean indicating whether the context has changed. +var didPerformWorkStackCursor = createCursor(false); +// Keep track of the previous context object that was on the stack. +// We use this to get access to the parent context after we have already +// pushed the next context provider, and now need to merge their contexts. +var previousContext = emptyObject; + +function getUnmaskedContext(workInProgress) { + var hasOwnContext = isContextProvider(workInProgress); + if (hasOwnContext) { + // If the fiber is a context provider itself, when we read its context + // we have already pushed its own child context on the stack. A context + // provider should not "see" its own child context. Therefore we read the + // previous (parent) context instead for a context provider. + return previousContext; + } + return contextStackCursor.current; +} + +function cacheContext(workInProgress, unmaskedContext, maskedContext) { + var instance = workInProgress.stateNode; + instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; + instance.__reactInternalMemoizedMaskedChildContext = maskedContext; +} + +function getMaskedContext(workInProgress, unmaskedContext) { + var type = workInProgress.type; + var contextTypes = type.contextTypes; + if (!contextTypes) { + return emptyObject; + } + + // Avoid recreating masked context unless unmasked context has changed. + // Failing to do this will result in unnecessary calls to componentWillReceiveProps. + // This may trigger infinite loops if componentWillReceiveProps calls setState. + var instance = workInProgress.stateNode; + if ( + instance && + instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext + ) { + return instance.__reactInternalMemoizedMaskedChildContext; + } + + var context = {}; + for (var key in contextTypes) { + context[key] = unmaskedContext[key]; + } + + { + var name = getComponentName(workInProgress) || "Unknown"; + checkPropTypes( + contextTypes, + context, + "context", + name, + ReactDebugCurrentFiber.getCurrentFiberStackAddendum + ); + } + + // Cache unmasked context so we can avoid recreating masked context unless necessary. + // Context is created before the class component is instantiated so check for instance. + if (instance) { + cacheContext(workInProgress, unmaskedContext, context); + } + + return context; +} + +function hasContextChanged() { + return didPerformWorkStackCursor.current; +} + +function isContextConsumer(fiber) { + return fiber.tag === ClassComponent && fiber.type.contextTypes != null; +} + +function isContextProvider(fiber) { + return fiber.tag === ClassComponent && fiber.type.childContextTypes != null; +} + +function popContextProvider(fiber) { + if (!isContextProvider(fiber)) { + return; + } + + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} + +function popTopLevelContextObject(fiber) { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} + +function pushTopLevelContextObject(fiber, context, didChange) { + invariant( + contextStackCursor.cursor == null, + "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; + var childContextTypes = fiber.type.childContextTypes; + + // TODO (bvaughn) Replace this behavior with an invariant() in the future. + // It has only been added in Fiber to match the (unintentional) behavior in Stack. + if (typeof instance.getChildContext !== "function") { + { + var componentName = getComponentName(fiber) || "Unknown"; + + if (!warnedAboutMissingGetChildContext[componentName]) { + warnedAboutMissingGetChildContext[componentName] = true; + warning( + false, + "%s.childContextTypes is specified but there is no getChildContext() method " + + "on the instance. You can either define getChildContext() on %s or remove " + + "childContextTypes from it.", + componentName, + componentName + ); + } + } + return parentContext; + } + + var childContext = void 0; + { + ReactDebugCurrentFiber.setCurrentPhase("getChildContext"); + } + startPhaseTimer(fiber, "getChildContext"); + childContext = instance.getChildContext(); + stopPhaseTimer(); + { + ReactDebugCurrentFiber.setCurrentPhase(null); + } + for (var contextKey in childContext) { + invariant( + contextKey in childContextTypes, + '%s.getChildContext(): key "%s" is not defined in childContextTypes.', + getComponentName(fiber) || "Unknown", + contextKey + ); + } + { + var name = getComponentName(fiber) || "Unknown"; + checkPropTypes( + childContextTypes, + childContext, + "child context", + name, + // In practice, there is one case in which we won't get a stack. It's when + // somebody calls unstable_renderSubtreeIntoContainer() and we process + // context from the parent component instance. The stack will be missing + // because it's outside of the reconciliation, and so the pointer has not + // been set. This is rare and doesn't matter. We'll also remove that API. + ReactDebugCurrentFiber.getCurrentFiberStackAddendum + ); + } + + return Object.assign({}, parentContext, childContext); +} + +function pushContextProvider(workInProgress) { + if (!isContextProvider(workInProgress)) { + return false; + } + + var instance = workInProgress.stateNode; + // We push the context as early as possible to ensure stack integrity. + // If the instance does not exist yet, we will push null at first, + // and replace it on the stack later when invalidating the context. + var memoizedMergedChildContext = + (instance && instance.__reactInternalMemoizedMergedChildContext) || + emptyObject; + + // Remember the parent context so we can merge with it later. + // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. + previousContext = contextStackCursor.current; + push(contextStackCursor, memoizedMergedChildContext, workInProgress); + push( + didPerformWorkStackCursor, + didPerformWorkStackCursor.current, + workInProgress + ); + + return true; +} + +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) { + // Merge parent and own context. + // Skip this if we're not updating due to sCU. + // This avoids unnecessarily recomputing memoized values. + var mergedContext = processChildContext(workInProgress, previousContext); + instance.__reactInternalMemoizedMergedChildContext = mergedContext; + + // Replace the old (or empty) context with the new one. + // It is important to unwind the context in the reverse order. + pop(didPerformWorkStackCursor, workInProgress); + pop(contextStackCursor, workInProgress); + // Now push the new context and mark that it has changed. + push(contextStackCursor, mergedContext, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); + } else { + pop(didPerformWorkStackCursor, workInProgress); + push(didPerformWorkStackCursor, didChange, workInProgress); + } +} + +function resetContext() { + previousContext = emptyObject; + contextStackCursor.current = emptyObject; + didPerformWorkStackCursor.current = false; +} + +function findCurrentUnmaskedContext(fiber) { + // Currently this is only used with renderSubtreeIntoContainer; not sure if it + // makes sense elsewhere + invariant( + isFiberMounted(fiber) && fiber.tag === ClassComponent, + "Expected subtree parent to be a mounted class component. " + + "This error is likely caused by a bug in React. Please file an issue." + ); + + var node = fiber; + while (node.tag !== HostRoot) { + if (isContextProvider(node)) { + return node.stateNode.__reactInternalMemoizedMergedChildContext; + } + var parent = node["return"]; + invariant( + parent, + "Found unexpected detached subtree parent. " + + "This error is likely caused by a bug in React. Please file an issue." + ); + node = parent; + } + return node.stateNode.context; +} + // Max 31 bit integer. The max integer size in V8 for 32-bit systems. // Math.pow(2, 30) - 1 // 0b111111111111111111111111111111 @@ -4642,9 +5500,6 @@ function createFiberFromElement(element, mode, expirationTime) { // This is a consumer fiberTag = ContextConsumer; break; - case REACT_FORWARD_REF_TYPE: - fiberTag = ForwardRef; - break; default: if (typeof type.tag === "number") { // Currently assumed to be a continuation and therefore is a @@ -4742,47 +5597,6 @@ function createFiberFromPortal(portal, mode, expirationTime) { return fiber; } -// Used for stashing WIP properties to replay failed work in DEV. -function assignFiberPropertiesInDEV(target, source) { - if (target === null) { - // This Fiber's initial properties will always be overwritten. - // We only use a Fiber to ensure the same hidden class so DEV isn't slow. - target = createFiber(IndeterminateComponent, null, null, NoContext); - } - - // This is intentionally written as a list of all properties. - // We tried to use Object.assign() instead but this is called in - // the hottest path, and Object.assign() was too slow: - // https://github.com/facebook/react/issues/12502 - // This code is DEV-only so size is not a concern. - - target.tag = source.tag; - target.key = source.key; - target.type = source.type; - target.stateNode = source.stateNode; - target["return"] = source["return"]; - target.child = source.child; - target.sibling = source.sibling; - target.index = source.index; - target.ref = source.ref; - target.pendingProps = source.pendingProps; - target.memoizedProps = source.memoizedProps; - target.updateQueue = source.updateQueue; - target.memoizedState = source.memoizedState; - target.mode = source.mode; - target.effectTag = source.effectTag; - target.nextEffect = source.nextEffect; - target.firstEffect = source.firstEffect; - target.lastEffect = source.lastEffect; - target.expirationTime = source.expirationTime; - target.alternate = source.alternate; - target._debugID = source._debugID; - target._debugSource = source._debugSource; - target._debugOwner = source._debugOwner; - target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming; - return target; -} - // TODO: This should be lifted into the renderer. function createFiberRoot(containerInfo, isAsync, hydrate) { @@ -4878,53 +5692,6 @@ function onCommitUnmount(fiber) { } } -var describeComponentFrame = function(name, source, ownerName) { - return ( - "\n in " + - (name || "Unknown") + - (source - ? " (at " + - source.fileName.replace(/^.*[\\\/]/, "") + - ":" + - source.lineNumber + - ")" - : ownerName ? " (created by " + ownerName + ")" : "") - ); -}; - -function describeFiber(fiber) { - switch (fiber.tag) { - case IndeterminateComponent: - case FunctionalComponent: - case ClassComponent: - case HostComponent: - var owner = fiber._debugOwner; - var source = fiber._debugSource; - var name = getComponentName(fiber); - var ownerName = null; - if (owner) { - ownerName = getComponentName(owner); - } - return describeComponentFrame(name, source, ownerName); - default: - return ""; - } -} - -// This function can only be called with a work-in-progress fiber and -// only during begin or complete phase. Do not call it under any other -// circumstances. -function getStackAddendumByWorkInProgressFiber(workInProgress) { - var info = ""; - var node = workInProgress; - do { - info += describeFiber(node); - // Otherwise this return pointer might point to the wrong tree: - node = node["return"]; - } while (node); - return info; -} - /** * Forked from fbjs/warning: * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js @@ -5188,10 +5955,7 @@ var ReactStrictModeWarnings = { ) { pendingComponentWillReceivePropsWarnings.push(fiber); } - if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true - ) { + if (typeof instance.componentWillUpdate === "function") { pendingComponentWillUpdateWarnings.push(fiber); } }; @@ -5262,533 +6026,6 @@ var ReactStrictModeWarnings = { }; } -// Re-export dynamic flags from the fbsource version. -var _require = require("ReactFeatureFlags"); - -var enableGetDerivedStateFromCatch = _require.enableGetDerivedStateFromCatch; -var debugRenderPhaseSideEffects = _require.debugRenderPhaseSideEffects; -var debugRenderPhaseSideEffectsForStrictMode = - _require.debugRenderPhaseSideEffectsForStrictMode; -var warnAboutDeprecatedLifecycles = _require.warnAboutDeprecatedLifecycles; -var replayFailedUnitOfWorkWithInvokeGuardedCallback = - _require.replayFailedUnitOfWorkWithInvokeGuardedCallback; - -var enableUserTimingAPI = true; -var enableMutatingReconciler = true; -var enableNoopReconciler = false; -var enablePersistentReconciler = false; - -// Only used in www builds. - -function getCurrentFiberOwnerName() { - { - var fiber = ReactDebugCurrentFiber.current; - if (fiber === null) { - return null; - } - var owner = fiber._debugOwner; - if (owner !== null && typeof owner !== "undefined") { - return getComponentName(owner); - } - } - return null; -} - -function getCurrentFiberStackAddendum() { - { - var fiber = ReactDebugCurrentFiber.current; - if (fiber === null) { - return null; - } - // Safe because if current fiber exists, we are reconciling, - // and it is guaranteed to be the work-in-progress version. - return getStackAddendumByWorkInProgressFiber(fiber); - } - return null; -} - -function resetCurrentFiber() { - ReactDebugCurrentFrame.getCurrentStack = null; - ReactDebugCurrentFiber.current = null; - ReactDebugCurrentFiber.phase = null; -} - -function setCurrentFiber(fiber) { - ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackAddendum; - ReactDebugCurrentFiber.current = fiber; - ReactDebugCurrentFiber.phase = null; -} - -function setCurrentPhase(phase) { - ReactDebugCurrentFiber.phase = phase; -} - -var ReactDebugCurrentFiber = { - current: null, - phase: null, - resetCurrentFiber: resetCurrentFiber, - setCurrentFiber: setCurrentFiber, - setCurrentPhase: setCurrentPhase, - getCurrentFiberOwnerName: getCurrentFiberOwnerName, - getCurrentFiberStackAddendum: getCurrentFiberStackAddendum -}; - -// Prefix measurements so that it's possible to filter them. -// Longer prefixes are hard to read in DevTools. -var reactEmoji = "\u269B"; -var warningEmoji = "\u26D4"; -var supportsUserTiming = - typeof performance !== "undefined" && - typeof performance.mark === "function" && - typeof performance.clearMarks === "function" && - typeof performance.measure === "function" && - typeof performance.clearMeasures === "function"; - -// Keep track of current fiber so that we know the path to unwind on pause. -// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them? -var currentFiber = null; -// If we're in the middle of user code, which fiber and method is it? -// Reusing `currentFiber` would be confusing for this because user code fiber -// can change during commit phase too, but we don't need to unwind it (since -// lifecycles in the commit phase don't resemble a tree). -var currentPhase = null; -var currentPhaseFiber = null; -// Did lifecycle hook schedule an update? This is often a performance problem, -// so we will keep track of it, and include it in the report. -// Track commits caused by cascading updates. -var isCommitting = false; -var hasScheduledUpdateInCurrentCommit = false; -var hasScheduledUpdateInCurrentPhase = false; -var commitCountInCurrentWorkLoop = 0; -var effectCountInCurrentCommit = 0; -var isWaitingForCallback = false; -// During commits, we only show a measurement once per method name -// to avoid stretch the commit phase with measurement overhead. -var labelsInCurrentCommit = new Set(); - -var formatMarkName = function(markName) { - return reactEmoji + " " + markName; -}; - -var formatLabel = function(label, warning$$1) { - var prefix = warning$$1 ? warningEmoji + " " : reactEmoji + " "; - var suffix = warning$$1 ? " Warning: " + warning$$1 : ""; - return "" + prefix + label + suffix; -}; - -var beginMark = function(markName) { - performance.mark(formatMarkName(markName)); -}; - -var clearMark = function(markName) { - performance.clearMarks(formatMarkName(markName)); -}; - -var endMark = function(label, markName, warning$$1) { - var formattedMarkName = formatMarkName(markName); - var formattedLabel = formatLabel(label, warning$$1); - try { - performance.measure(formattedLabel, formattedMarkName); - } catch (err) {} - // If previous mark was missing for some reason, this will throw. - // This could only happen if React crashed in an unexpected place earlier. - // Don't pile on with more errors. - - // Clear marks immediately to avoid growing buffer. - performance.clearMarks(formattedMarkName); - performance.clearMeasures(formattedLabel); -}; - -var getFiberMarkName = function(label, debugID) { - return label + " (#" + debugID + ")"; -}; - -var getFiberLabel = function(componentName, isMounted, phase) { - if (phase === null) { - // These are composite component total time measurements. - return componentName + " [" + (isMounted ? "update" : "mount") + "]"; - } else { - // Composite component methods. - return componentName + "." + phase; - } -}; - -var beginFiberMark = function(fiber, phase) { - var componentName = getComponentName(fiber) || "Unknown"; - var debugID = fiber._debugID; - var isMounted = fiber.alternate !== null; - var label = getFiberLabel(componentName, isMounted, phase); - - if (isCommitting && labelsInCurrentCommit.has(label)) { - // During the commit phase, we don't show duplicate labels because - // there is a fixed overhead for every measurement, and we don't - // want to stretch the commit phase beyond necessary. - return false; - } - labelsInCurrentCommit.add(label); - - var markName = getFiberMarkName(label, debugID); - beginMark(markName); - return true; -}; - -var clearFiberMark = function(fiber, phase) { - var componentName = getComponentName(fiber) || "Unknown"; - var debugID = fiber._debugID; - var isMounted = fiber.alternate !== null; - var label = getFiberLabel(componentName, isMounted, phase); - var markName = getFiberMarkName(label, debugID); - clearMark(markName); -}; - -var endFiberMark = function(fiber, phase, warning$$1) { - var componentName = getComponentName(fiber) || "Unknown"; - var debugID = fiber._debugID; - var isMounted = fiber.alternate !== null; - var label = getFiberLabel(componentName, isMounted, phase); - var markName = getFiberMarkName(label, debugID); - endMark(label, markName, warning$$1); -}; - -var shouldIgnoreFiber = function(fiber) { - // Host components should be skipped in the timeline. - // We could check typeof fiber.type, but does this work with RN? - switch (fiber.tag) { - case HostRoot: - case HostComponent: - case HostText: - case HostPortal: - case CallComponent: - case ReturnComponent: - case Fragment: - case ContextProvider: - case ContextConsumer: - return true; - default: - return false; - } -}; - -var clearPendingPhaseMeasurement = function() { - if (currentPhase !== null && currentPhaseFiber !== null) { - clearFiberMark(currentPhaseFiber, currentPhase); - } - currentPhaseFiber = null; - currentPhase = null; - hasScheduledUpdateInCurrentPhase = false; -}; - -var pauseTimers = function() { - // Stops all currently active measurements so that they can be resumed - // if we continue in a later deferred loop from the same unit of work. - var fiber = currentFiber; - while (fiber) { - if (fiber._debugIsCurrentlyTiming) { - endFiberMark(fiber, null, null); - } - fiber = fiber["return"]; - } -}; - -var resumeTimersRecursively = function(fiber) { - if (fiber["return"] !== null) { - resumeTimersRecursively(fiber["return"]); - } - if (fiber._debugIsCurrentlyTiming) { - beginFiberMark(fiber, null); - } -}; - -var resumeTimers = function() { - // Resumes all measurements that were active during the last deferred loop. - if (currentFiber !== null) { - resumeTimersRecursively(currentFiber); - } -}; - -function recordEffect() { - if (enableUserTimingAPI) { - effectCountInCurrentCommit++; - } -} - -function recordScheduleUpdate() { - if (enableUserTimingAPI) { - if (isCommitting) { - hasScheduledUpdateInCurrentCommit = true; - } - if ( - currentPhase !== null && - currentPhase !== "componentWillMount" && - currentPhase !== "componentWillReceiveProps" - ) { - hasScheduledUpdateInCurrentPhase = true; - } - } -} - -function startRequestCallbackTimer() { - if (enableUserTimingAPI) { - if (supportsUserTiming && !isWaitingForCallback) { - isWaitingForCallback = true; - beginMark("(Waiting for async callback...)"); - } - } -} - -function stopRequestCallbackTimer(didExpire, expirationTime) { - if (enableUserTimingAPI) { - if (supportsUserTiming) { - isWaitingForCallback = false; - var warning$$1 = didExpire ? "React was blocked by main thread" : null; - endMark( - "(Waiting for async callback... will force flush in " + - expirationTime + - " ms)", - "(Waiting for async callback...)", - warning$$1 - ); - } - } -} - -function startWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; - } - // If we pause, this is the fiber to unwind from. - currentFiber = fiber; - if (!beginFiberMark(fiber, null)) { - return; - } - fiber._debugIsCurrentlyTiming = true; - } -} - -function cancelWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; - } - // Remember we shouldn't complete measurement for this fiber. - // Otherwise flamechart will be deep even for small updates. - fiber._debugIsCurrentlyTiming = false; - clearFiberMark(fiber, null); - } -} - -function stopWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; - } - // If we pause, its parent is the fiber to unwind from. - currentFiber = fiber["return"]; - if (!fiber._debugIsCurrentlyTiming) { - return; - } - fiber._debugIsCurrentlyTiming = false; - endFiberMark(fiber, null, null); - } -} - -function stopFailedWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; - } - // If we pause, its parent is the fiber to unwind from. - currentFiber = fiber["return"]; - if (!fiber._debugIsCurrentlyTiming) { - return; - } - fiber._debugIsCurrentlyTiming = false; - var warning$$1 = "An error was thrown inside this error boundary"; - endFiberMark(fiber, null, warning$$1); - } -} - -function startPhaseTimer(fiber, phase) { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - clearPendingPhaseMeasurement(); - if (!beginFiberMark(fiber, phase)) { - return; - } - currentPhaseFiber = fiber; - currentPhase = phase; - } -} - -function stopPhaseTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - if (currentPhase !== null && currentPhaseFiber !== null) { - var warning$$1 = hasScheduledUpdateInCurrentPhase - ? "Scheduled a cascading update" - : null; - endFiberMark(currentPhaseFiber, currentPhase, warning$$1); - } - currentPhase = null; - currentPhaseFiber = null; - } -} - -function startWorkLoopTimer(nextUnitOfWork) { - if (enableUserTimingAPI) { - currentFiber = nextUnitOfWork; - if (!supportsUserTiming) { - return; - } - commitCountInCurrentWorkLoop = 0; - // This is top level call. - // Any other measurements are performed within. - beginMark("(React Tree Reconciliation)"); - // Resume any measurements that were in progress during the last loop. - resumeTimers(); - } -} - -function stopWorkLoopTimer(interruptedBy, didCompleteRoot) { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var warning$$1 = null; - if (interruptedBy !== null) { - if (interruptedBy.tag === HostRoot) { - warning$$1 = "A top-level update interrupted the previous render"; - } else { - var componentName = getComponentName(interruptedBy) || "Unknown"; - warning$$1 = - "An update to " + componentName + " interrupted the previous render"; - } - } else if (commitCountInCurrentWorkLoop > 1) { - warning$$1 = "There were cascading updates"; - } - commitCountInCurrentWorkLoop = 0; - var label = didCompleteRoot - ? "(React Tree Reconciliation: Completed Root)" - : "(React Tree Reconciliation: Yielded)"; - // Pause any measurements until the next loop. - pauseTimers(); - endMark(label, "(React Tree Reconciliation)", warning$$1); - } -} - -function startCommitTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - isCommitting = true; - hasScheduledUpdateInCurrentCommit = false; - labelsInCurrentCommit.clear(); - beginMark("(Committing Changes)"); - } -} - -function stopCommitTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - - var warning$$1 = null; - if (hasScheduledUpdateInCurrentCommit) { - warning$$1 = "Lifecycle hook scheduled a cascading update"; - } else if (commitCountInCurrentWorkLoop > 0) { - warning$$1 = "Caused by a cascading update in earlier commit"; - } - hasScheduledUpdateInCurrentCommit = false; - commitCountInCurrentWorkLoop++; - isCommitting = false; - labelsInCurrentCommit.clear(); - - endMark("(Committing Changes)", "(Committing Changes)", warning$$1); - } -} - -function startCommitSnapshotEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - effectCountInCurrentCommit = 0; - beginMark("(Committing Snapshot Effects)"); - } -} - -function stopCommitSnapshotEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Committing Snapshot Effects: " + count + " Total)", - "(Committing Snapshot Effects)", - null - ); - } -} - -function startCommitHostEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - effectCountInCurrentCommit = 0; - beginMark("(Committing Host Effects)"); - } -} - -function stopCommitHostEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Committing Host Effects: " + count + " Total)", - "(Committing Host Effects)", - null - ); - } -} - -function startCommitLifeCyclesTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - effectCountInCurrentCommit = 0; - beginMark("(Calling Lifecycle Methods)"); - } -} - -function stopCommitLifeCyclesTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Calling Lifecycle Methods: " + count + " Total)", - "(Calling Lifecycle Methods)", - null - ); - } -} - var didWarnUpdateInsideUpdate = void 0; { @@ -6123,26 +6360,23 @@ var isArray = Array.isArray; var didWarnAboutStateAssignmentForComponent = void 0; var didWarnAboutUndefinedDerivedState = void 0; var didWarnAboutUninitializedState = void 0; -var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0; -var didWarnAboutLegacyLifecyclesAndDerivedState = void 0; +var didWarnAboutWillReceivePropsAndDerivedState = void 0; var warnOnInvalidCallback = void 0; { - didWarnAboutStateAssignmentForComponent = new Set(); - didWarnAboutUndefinedDerivedState = new Set(); - didWarnAboutUninitializedState = new Set(); - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); - didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); + didWarnAboutStateAssignmentForComponent = {}; + didWarnAboutUndefinedDerivedState = {}; + didWarnAboutUninitializedState = {}; + didWarnAboutWillReceivePropsAndDerivedState = {}; - var didWarnOnInvalidCallback = new Set(); + var didWarnOnInvalidCallback = {}; warnOnInvalidCallback = function(callback, callerName) { if (callback === null || typeof callback === "function") { return; } var key = callerName + "_" + callback; - if (!didWarnOnInvalidCallback.has(key)) { - didWarnOnInvalidCallback.add(key); + if (!didWarnOnInvalidCallback[key]) { warning( false, "%s(...): Expected the last optional `callback` argument to be a " + @@ -6150,6 +6384,7 @@ var warnOnInvalidCallback = void 0; callerName, callback ); + didWarnOnInvalidCallback[key] = true; } }; @@ -6188,20 +6423,12 @@ function callGetDerivedStateFromCatch(ctor, capturedValues) { } var ReactFiberClassComponent = function( - legacyContext, scheduleWork, computeExpirationForFiber, memoizeProps, memoizeState ) { - var cacheContext = legacyContext.cacheContext, - getMaskedContext = legacyContext.getMaskedContext, - getUnmaskedContext = legacyContext.getUnmaskedContext, - isContextConsumer = legacyContext.isContextConsumer, - hasContextChanged = legacyContext.hasContextChanged; - // Class component state updater - var updater = { isMounted: isMounted, enqueueSetState: function(instance, partialState, callback) { @@ -6292,14 +6519,12 @@ var ReactFiberClassComponent = function( stopPhaseTimer(); { - !(shouldUpdate !== undefined) - ? warning( - false, - "%s.shouldComponentUpdate(): Returned undefined instead of a " + - "boolean value. Make sure to return true or false.", - getComponentName(workInProgress) || "Component" - ) - : void 0; + warning( + shouldUpdate !== undefined, + "%s.shouldComponentUpdate(): Returned undefined instead of a " + + "boolean value. Make sure to return true or false.", + getComponentName(workInProgress) || "Unknown" + ); } return shouldUpdate; @@ -6318,7 +6543,7 @@ var ReactFiberClassComponent = function( var instance = workInProgress.stateNode; var type = workInProgress.type; { - var name = getComponentName(workInProgress) || "Component"; + var name = getComponentName(workInProgress); var renderPresent = instance.render; if (!renderPresent) { @@ -6343,57 +6568,47 @@ var ReactFiberClassComponent = function( !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state; - !noGetInitialStateOnES6 - ? warning( - false, - "getInitialState was defined on %s, a plain JavaScript class. " + - "This is only supported for classes created using React.createClass. " + - "Did you mean to define a state property instead?", - name - ) - : void 0; + warning( + noGetInitialStateOnES6, + "getInitialState was defined on %s, a plain JavaScript class. " + + "This is only supported for classes created using React.createClass. " + + "Did you mean to define a state property instead?", + name + ); var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved; - !noGetDefaultPropsOnES6 - ? warning( - false, - "getDefaultProps was defined on %s, a plain JavaScript class. " + - "This is only supported for classes created using React.createClass. " + - "Use a static property to define defaultProps instead.", - name - ) - : void 0; + warning( + noGetDefaultPropsOnES6, + "getDefaultProps was defined on %s, a plain JavaScript class. " + + "This is only supported for classes created using React.createClass. " + + "Use a static property to define defaultProps instead.", + name + ); var noInstancePropTypes = !instance.propTypes; - !noInstancePropTypes - ? warning( - false, - "propTypes was defined as an instance property on %s. Use a static " + - "property to define propTypes instead.", - name - ) - : void 0; + warning( + noInstancePropTypes, + "propTypes was defined as an instance property on %s. Use a static " + + "property to define propTypes instead.", + name + ); var noInstanceContextTypes = !instance.contextTypes; - !noInstanceContextTypes - ? warning( - false, - "contextTypes was defined as an instance property on %s. Use a static " + - "property to define contextTypes instead.", - name - ) - : void 0; + warning( + noInstanceContextTypes, + "contextTypes was defined as an instance property on %s. Use a static " + + "property to define contextTypes instead.", + name + ); var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== "function"; - !noComponentShouldUpdate - ? warning( - false, - "%s has a method called " + - "componentShouldUpdate(). Did you mean shouldComponentUpdate()? " + - "The name is phrased as a question because the function is " + - "expected to return a value.", - name - ) - : void 0; + warning( + noComponentShouldUpdate, + "%s has a method called " + + "componentShouldUpdate(). Did you mean shouldComponentUpdate()? " + + "The name is phrased as a question because the function is " + + "expected to return a value.", + name + ); if ( type.prototype && type.prototype.isPureReactComponent && @@ -6409,128 +6624,73 @@ var ReactFiberClassComponent = function( } var noComponentDidUnmount = typeof instance.componentDidUnmount !== "function"; - !noComponentDidUnmount - ? warning( - false, - "%s has a method called " + - "componentDidUnmount(). But there is no such lifecycle method. " + - "Did you mean componentWillUnmount()?", - name - ) - : void 0; + warning( + noComponentDidUnmount, + "%s has a method called " + + "componentDidUnmount(). But there is no such lifecycle method. " + + "Did you mean componentWillUnmount()?", + name + ); var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== "function"; - !noComponentDidReceiveProps - ? warning( - false, - "%s has a method called " + - "componentDidReceiveProps(). But there is no such lifecycle method. " + - "If you meant to update the state in response to changing props, " + - "use componentWillReceiveProps(). If you meant to fetch data or " + - "run side-effects or mutations after React has updated the UI, use componentDidUpdate().", - name - ) - : void 0; + warning( + noComponentDidReceiveProps, + "%s has a method called " + + "componentDidReceiveProps(). But there is no such lifecycle method. " + + "If you meant to update the state in response to changing props, " + + "use componentWillReceiveProps(). If you meant to fetch data or " + + "run side-effects or mutations after React has updated the UI, use componentDidUpdate().", + name + ); var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== "function"; - !noComponentWillRecieveProps - ? warning( - false, - "%s has a method called " + - "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", - name - ) - : void 0; + warning( + noComponentWillRecieveProps, + "%s has a method called " + + "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", + name + ); var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== "function"; - !noUnsafeComponentWillRecieveProps - ? warning( - false, - "%s has a method called " + - "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?", - name - ) - : void 0; + warning( + noUnsafeComponentWillRecieveProps, + "%s has a method called " + + "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?", + name + ); var hasMutatedProps = instance.props !== workInProgress.pendingProps; - !(instance.props === undefined || !hasMutatedProps) - ? warning( - false, - "%s(...): When calling super() in `%s`, make sure to pass " + - "up the same props that your component's constructor was passed.", - name, - name - ) - : void 0; + warning( + instance.props === undefined || !hasMutatedProps, + "%s(...): When calling super() in `%s`, make sure to pass " + + "up the same props that your component's constructor was passed.", + name, + name + ); var noInstanceDefaultProps = !instance.defaultProps; - !noInstanceDefaultProps - ? warning( - false, - "Setting defaultProps as an instance property on %s is not supported and will be ignored." + - " Instead, define defaultProps as a static property on %s.", - name, - name - ) - : void 0; + warning( + noInstanceDefaultProps, + "Setting defaultProps as an instance property on %s is not supported and will be ignored." + + " Instead, define defaultProps as a static property on %s.", + name, + name + ); + } - if ( - typeof instance.getSnapshotBeforeUpdate === "function" && - typeof instance.componentDidUpdate !== "function" && - typeof instance.componentDidUpdate !== "function" && - !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(type) - ) { - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(type); - warning( - false, - "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " + - "This component defines getSnapshotBeforeUpdate() only.", - getComponentName(workInProgress) - ); - } - - var noInstanceGetDerivedStateFromProps = - typeof instance.getDerivedStateFromProps !== "function"; - !noInstanceGetDerivedStateFromProps - ? warning( - false, - "%s: getDerivedStateFromProps() is defined as an instance method " + - "and will be ignored. Instead, declare it as a static method.", - name - ) - : void 0; - var noInstanceGetDerivedStateFromCatch = - typeof instance.getDerivedStateFromCatch !== "function"; - !noInstanceGetDerivedStateFromCatch - ? warning( - false, - "%s: getDerivedStateFromCatch() is defined as an instance method " + - "and will be ignored. Instead, declare it as a static method.", - name - ) - : void 0; - var noStaticGetSnapshotBeforeUpdate = - typeof type.getSnapshotBeforeUpdate !== "function"; - !noStaticGetSnapshotBeforeUpdate - ? warning( - false, - "%s: getSnapshotBeforeUpdate() is defined as a static method " + - "and will be ignored. Instead, declare it as an instance method.", - name - ) - : void 0; - var _state = instance.state; - if (_state && (typeof _state !== "object" || isArray(_state))) { - warning(false, "%s.state: must be set to an object or null", name); - } - if (typeof instance.getChildContext === "function") { - !(typeof type.childContextTypes === "object") - ? warning( - false, - "%s.getChildContext(): childContextTypes must be defined in order to " + - "use getChildContext().", - name - ) - : void 0; - } + var state = instance.state; + if (state && (typeof state !== "object" || isArray(state))) { + warning( + false, + "%s.state: must be set to an object or null", + getComponentName(workInProgress) + ); + } + if (typeof instance.getChildContext === "function") { + warning( + typeof type.childContextTypes === "object", + "%s.getChildContext(): childContextTypes must be defined in order to " + + "use getChildContext().", + getComponentName(workInProgress) + ); } } @@ -6578,9 +6738,8 @@ var ReactFiberClassComponent = function( typeof ctor.getDerivedStateFromProps === "function" && state === null ) { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutUninitializedState.has(componentName)) { - didWarnAboutUninitializedState.add(componentName); + var componentName = getComponentName(workInProgress) || "Unknown"; + if (!didWarnAboutUninitializedState[componentName]) { warning( false, "%s: Did not properly initialize state during construction. " + @@ -6588,75 +6747,7 @@ var ReactFiberClassComponent = function( componentName, instance.state === null ? "null" : "undefined" ); - } - } - - // If new component APIs are defined, "unsafe" lifecycles won't be called. - // Warn about these lifecycles if they are present. - // Don't warn about react-lifecycles-compat polyfilled methods though. - if ( - typeof ctor.getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function" - ) { - var foundWillMountName = null; - var foundWillReceivePropsName = null; - var foundWillUpdateName = null; - if ( - typeof instance.componentWillMount === "function" && - instance.componentWillMount.__suppressDeprecationWarning !== true - ) { - foundWillMountName = "componentWillMount"; - } else if (typeof instance.UNSAFE_componentWillMount === "function") { - foundWillMountName = "UNSAFE_componentWillMount"; - } - if ( - typeof instance.componentWillReceiveProps === "function" && - instance.componentWillReceiveProps.__suppressDeprecationWarning !== - true - ) { - foundWillReceivePropsName = "componentWillReceiveProps"; - } else if ( - typeof instance.UNSAFE_componentWillReceiveProps === "function" - ) { - foundWillReceivePropsName = "UNSAFE_componentWillReceiveProps"; - } - if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true - ) { - foundWillUpdateName = "componentWillUpdate"; - } else if (typeof instance.UNSAFE_componentWillUpdate === "function") { - foundWillUpdateName = "UNSAFE_componentWillUpdate"; - } - if ( - foundWillMountName !== null || - foundWillReceivePropsName !== null || - foundWillUpdateName !== null - ) { - var _componentName = getComponentName(workInProgress) || "Component"; - var newApiName = - typeof ctor.getDerivedStateFromProps === "function" - ? "getDerivedStateFromProps()" - : "getSnapshotBeforeUpdate()"; - if ( - !didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName) - ) { - didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName); - warning( - false, - "Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n" + - "%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n" + - "The above lifecycles should be removed. Learn more about this warning here:\n" + - "https://fb.me/react-async-component-lifecycle-hooks", - _componentName, - newApiName, - foundWillMountName !== null ? "\n " + foundWillMountName : "", - foundWillReceivePropsName !== null - ? "\n " + foundWillReceivePropsName - : "", - foundWillUpdateName !== null ? "\n " + foundWillUpdateName : "" - ); - } + didWarnAboutUninitializedState[componentName] = true; } } } @@ -6666,8 +6757,7 @@ var ReactFiberClassComponent = function( var partialState = callGetDerivedStateFromProps( workInProgress, instance, - props, - state + props ); if (partialState !== null && partialState !== undefined) { @@ -6710,7 +6800,7 @@ var ReactFiberClassComponent = function( "%s.componentWillMount(): Assigning directly to this.state is " + "deprecated (except inside a component's " + "constructor). Use setState instead.", - getComponentName(workInProgress) || "Component" + getComponentName(workInProgress) ); } updater.enqueueReplaceState(instance, instance.state, null); @@ -6736,8 +6826,7 @@ var ReactFiberClassComponent = function( if (instance.state !== oldState) { { var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { - didWarnAboutStateAssignmentForComponent.add(componentName); + if (!didWarnAboutStateAssignmentForComponent[componentName]) { warning( false, "%s.componentWillReceiveProps(): Assigning directly to " + @@ -6745,47 +6834,69 @@ var ReactFiberClassComponent = function( "constructor). Use setState instead.", componentName ); + didWarnAboutStateAssignmentForComponent[componentName] = true; } } updater.enqueueReplaceState(instance, instance.state, null); } } - function callGetDerivedStateFromProps( - workInProgress, - instance, - nextProps, - prevState - ) { + function callGetDerivedStateFromProps(workInProgress, instance, props) { var type = workInProgress.type; if (typeof type.getDerivedStateFromProps === "function") { + { + // Don't warn about react-lifecycles-compat polyfilled components + if ( + (typeof instance.componentWillReceiveProps === "function" && + instance.componentWillReceiveProps.__suppressDeprecationWarning !== + true) || + typeof instance.UNSAFE_componentWillReceiveProps === "function" + ) { + var componentName = getComponentName(workInProgress) || "Unknown"; + if (!didWarnAboutWillReceivePropsAndDerivedState[componentName]) { + warning( + false, + "%s: Defines both componentWillReceiveProps() and static " + + "getDerivedStateFromProps() methods. We recommend using " + + "only getDerivedStateFromProps().", + componentName + ); + didWarnAboutWillReceivePropsAndDerivedState[componentName] = true; + } + } + } + if ( debugRenderPhaseSideEffects || (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) ) { // Invoke method an extra time to help detect side-effects. - type.getDerivedStateFromProps.call(null, nextProps, prevState); + type.getDerivedStateFromProps.call( + null, + props, + workInProgress.memoizedState + ); } var partialState = type.getDerivedStateFromProps.call( null, - nextProps, - prevState + props, + workInProgress.memoizedState ); { if (partialState === undefined) { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutUndefinedDerivedState.has(componentName)) { - didWarnAboutUndefinedDerivedState.add(componentName); + var _componentName = getComponentName(workInProgress) || "Unknown"; + if (!didWarnAboutUndefinedDerivedState[_componentName]) { warning( false, "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + "You have returned undefined.", - componentName + _componentName ); + didWarnAboutUndefinedDerivedState[_componentName] = _componentName; } } } @@ -6829,12 +6940,11 @@ var ReactFiberClassComponent = function( } // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - typeof ctor.getDerivedStateFromProps !== "function" && - typeof instance.getSnapshotBeforeUpdate !== "function" && (typeof instance.UNSAFE_componentWillMount === "function" || - typeof instance.componentWillMount === "function") + typeof instance.componentWillMount === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's @@ -6867,20 +6977,16 @@ var ReactFiberClassComponent = function( var newUnmaskedContext = getUnmaskedContext(workInProgress); var newContext = getMaskedContext(workInProgress, newUnmaskedContext); - var hasNewLifecycles = - typeof ctor.getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; - // Note: During these life-cycles, instance.props/instance.state are what // ever the previously attempted to render - not the "current". However, // during componentDidUpdate we pass the "current" props. // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - !hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === "function" || - typeof instance.componentWillReceiveProps === "function") + typeof instance.componentWillReceiveProps === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { if (oldProps !== newProps || oldContext !== newContext) { callComponentWillReceiveProps( @@ -6892,6 +6998,15 @@ var ReactFiberClassComponent = function( } } + var derivedStateFromProps = void 0; + if (oldProps !== newProps) { + derivedStateFromProps = callGetDerivedStateFromProps( + workInProgress, + instance, + newProps + ); + } + // Compute the next state using the memoized state and the update queue. var oldState = workInProgress.memoizedState; // TODO: Previous state can be null. @@ -6928,18 +7043,6 @@ var ReactFiberClassComponent = function( newState = oldState; } - var derivedStateFromProps = void 0; - if (oldProps !== newProps) { - // The prevState parameter should be the partially updated state. - // Otherwise, spreading state in return values could override updates. - derivedStateFromProps = callGetDerivedStateFromProps( - workInProgress, - instance, - newProps, - newState - ); - } - if (derivedStateFromProps !== null && derivedStateFromProps !== undefined) { // Render-phase updates (like this) should not be added to the update queue, // So that multiple render passes do not enqueue multiple updates. @@ -6948,17 +7051,6 @@ var ReactFiberClassComponent = function( newState === null || newState === undefined ? derivedStateFromProps : Object.assign({}, newState, derivedStateFromProps); - - // Update the base state of the update queue. - // FIXME: This is getting ridiculous. Refactor plz! - var _updateQueue = workInProgress.updateQueue; - if (_updateQueue !== null) { - _updateQueue.baseState = Object.assign( - {}, - _updateQueue.baseState, - derivedStateFromProps - ); - } } if (derivedStateFromCatch !== null && derivedStateFromCatch !== undefined) { // Render-phase updates (like this) should not be added to the update queue, @@ -6968,17 +7060,6 @@ var ReactFiberClassComponent = function( newState === null || newState === undefined ? derivedStateFromCatch : Object.assign({}, newState, derivedStateFromCatch); - - // Update the base state of the update queue. - // FIXME: This is getting ridiculous. Refactor plz! - var _updateQueue2 = workInProgress.updateQueue; - if (_updateQueue2 !== null) { - _updateQueue2.baseState = Object.assign( - {}, - _updateQueue2.baseState, - derivedStateFromCatch - ); - } } if ( @@ -7009,22 +7090,22 @@ var ReactFiberClassComponent = function( if (shouldUpdate) { // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillMount === "function" || - typeof instance.componentWillMount === "function") + (typeof instance.UNSAFE_componentWillUpdate === "function" || + typeof instance.componentWillUpdate === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { - startPhaseTimer(workInProgress, "componentWillMount"); - if (typeof instance.componentWillMount === "function") { - instance.componentWillMount(); + startPhaseTimer(workInProgress, "componentWillUpdate"); + if (typeof instance.componentWillUpdate === "function") { + instance.componentWillUpdate(newProps, newState, newContext); } - if (typeof instance.UNSAFE_componentWillMount === "function") { - instance.UNSAFE_componentWillMount(); + if (typeof instance.UNSAFE_componentWillUpdate === "function") { + instance.UNSAFE_componentWillUpdate(newProps, newState, newContext); } stopPhaseTimer(); } - if (typeof instance.componentDidMount === "function") { + if (typeof instance.componentDidUpdate === "function") { workInProgress.effectTag |= Update; } } else { @@ -7061,20 +7142,16 @@ var ReactFiberClassComponent = function( var newUnmaskedContext = getUnmaskedContext(workInProgress); var newContext = getMaskedContext(workInProgress, newUnmaskedContext); - var hasNewLifecycles = - typeof ctor.getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; - // Note: During these life-cycles, instance.props/instance.state are what // ever the previously attempted to render - not the "current". However, // during componentDidUpdate we pass the "current" props. // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - !hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === "function" || - typeof instance.componentWillReceiveProps === "function") + typeof instance.componentWillReceiveProps === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { if (oldProps !== newProps || oldContext !== newContext) { callComponentWillReceiveProps( @@ -7086,12 +7163,20 @@ var ReactFiberClassComponent = function( } } + var derivedStateFromProps = void 0; + if (oldProps !== newProps) { + derivedStateFromProps = callGetDerivedStateFromProps( + workInProgress, + instance, + newProps + ); + } + // Compute the next state using the memoized state and the update queue. var oldState = workInProgress.memoizedState; // TODO: Previous state can be null. var newState = void 0; var derivedStateFromCatch = void 0; - if (workInProgress.updateQueue !== null) { newState = processUpdateQueue( current, @@ -7123,18 +7208,6 @@ var ReactFiberClassComponent = function( newState = oldState; } - var derivedStateFromProps = void 0; - if (oldProps !== newProps) { - // The prevState parameter should be the partially updated state. - // Otherwise, spreading state in return values could override updates. - derivedStateFromProps = callGetDerivedStateFromProps( - workInProgress, - instance, - newProps, - newState - ); - } - if (derivedStateFromProps !== null && derivedStateFromProps !== undefined) { // Render-phase updates (like this) should not be added to the update queue, // So that multiple render passes do not enqueue multiple updates. @@ -7143,17 +7216,6 @@ var ReactFiberClassComponent = function( newState === null || newState === undefined ? derivedStateFromProps : Object.assign({}, newState, derivedStateFromProps); - - // Update the base state of the update queue. - // FIXME: This is getting ridiculous. Refactor plz! - var _updateQueue3 = workInProgress.updateQueue; - if (_updateQueue3 !== null) { - _updateQueue3.baseState = Object.assign( - {}, - _updateQueue3.baseState, - derivedStateFromProps - ); - } } if (derivedStateFromCatch !== null && derivedStateFromCatch !== undefined) { // Render-phase updates (like this) should not be added to the update queue, @@ -7163,17 +7225,6 @@ var ReactFiberClassComponent = function( newState === null || newState === undefined ? derivedStateFromCatch : Object.assign({}, newState, derivedStateFromCatch); - - // Update the base state of the update queue. - // FIXME: This is getting ridiculous. Refactor plz! - var _updateQueue4 = workInProgress.updateQueue; - if (_updateQueue4 !== null) { - _updateQueue4.baseState = Object.assign( - {}, - _updateQueue4.baseState, - derivedStateFromCatch - ); - } } if ( @@ -7195,14 +7246,6 @@ var ReactFiberClassComponent = function( workInProgress.effectTag |= Update; } } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Snapshot; - } - } return false; } @@ -7217,11 +7260,11 @@ var ReactFiberClassComponent = function( if (shouldUpdate) { // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Unsafe lifecycles should not be invoked for any component with the new gDSFP. if ( - !hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === "function" || - typeof instance.componentWillUpdate === "function") + typeof instance.componentWillUpdate === "function") && + typeof ctor.getDerivedStateFromProps !== "function" ) { startPhaseTimer(workInProgress, "componentWillUpdate"); if (typeof instance.componentWillUpdate === "function") { @@ -7235,9 +7278,6 @@ var ReactFiberClassComponent = function( if (typeof instance.componentDidUpdate === "function") { workInProgress.effectTag |= Update; } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - workInProgress.effectTag |= Snapshot; - } } else { // If an update was already in progress, we should schedule an Update // effect even though we're bailing out, so that cWU/cDU are called. @@ -7249,14 +7289,6 @@ var ReactFiberClassComponent = function( workInProgress.effectTag |= Update; } } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Snapshot; - } - } // If shouldComponentUpdate returned false, we should still update the // memoized props/state to indicate that this work can be reused. @@ -8096,15 +8128,13 @@ function ChildReconciler(shouldTrackSideEffects) { if (typeof newChildrenIterable.entries === "function") { var possibleMap = newChildrenIterable; if (possibleMap.entries === iteratorFn) { - !didWarnAboutMaps - ? warning( - false, - "Using Maps as children is unsupported and will likely yield " + - "unexpected results. Convert it to a sequence/iterable of keyed " + - "ReactElements instead.%s", - getCurrentFiberStackAddendum$1() - ) - : void 0; + warning( + didWarnAboutMaps, + "Using Maps as children is unsupported and will likely yield " + + "unexpected results. Convert it to a sequence/iterable of keyed " + + "ReactElements instead.%s", + getCurrentFiberStackAddendum$1() + ); didWarnAboutMaps = true; } } @@ -8546,6 +8576,71 @@ function cloneChildFibers(current, workInProgress) { newChild.sibling = null; } +var changedBitsStack = []; +var currentValueStack = []; +var stack = []; +var index$1 = -1; + +var rendererSigil = void 0; +{ + // Use this to detect multiple renderers using the same context + rendererSigil = {}; +} + +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; + + { + warning( + context._currentRenderer === null || + context._currentRenderer === rendererSigil, + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." + ); + context._currentRenderer = rendererSigil; + } +} + +function popProvider(providerFiber) { + { + warning( + index$1 > -1 && providerFiber === stack[index$1], + "Unexpected pop." + ); + } + var changedBits = changedBitsStack[index$1]; + var currentValue = currentValueStack[index$1]; + changedBitsStack[index$1] = null; + currentValueStack[index$1] = null; + stack[index$1] = null; + index$1 -= 1; + var context = providerFiber.type.context; + context._currentValue = currentValue; + context._changedBits = changedBits; +} + +function resetProviderStack() { + for (var i = index$1; i > -1; i--) { + var providerFiber = stack[i]; + var context = providerFiber.type.context; + context._currentValue = context._defaultValue; + context._changedBits = 0; + changedBitsStack[i] = null; + currentValueStack[i] = null; + stack[i] = null; + { + context._currentRenderer = null; + } + } + index$1 = -1; +} + var didWarnAboutBadClass = void 0; var didWarnAboutGetDerivedStateOnFunctionalComponent = void 0; var didWarnAboutStatelessRefs = void 0; @@ -8559,8 +8654,6 @@ var didWarnAboutStatelessRefs = void 0; var ReactFiberBeginWork = function( config, hostContext, - legacyContext, - newContext, hydrationContext, scheduleWork, computeExpirationForFiber @@ -8569,20 +8662,12 @@ var ReactFiberBeginWork = function( shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree; var pushHostContext = hostContext.pushHostContext, pushHostContainer = hostContext.pushHostContainer; - var pushProvider = newContext.pushProvider; - var getMaskedContext = legacyContext.getMaskedContext, - getUnmaskedContext = legacyContext.getUnmaskedContext, - hasLegacyContextChanged = legacyContext.hasContextChanged, - pushLegacyContextProvider = legacyContext.pushContextProvider, - pushTopLevelContextObject = legacyContext.pushTopLevelContextObject, - invalidateContextProvider = legacyContext.invalidateContextProvider; var enterHydrationState = hydrationContext.enterHydrationState, resetHydrationState = hydrationContext.resetHydrationState, tryToClaimNextHydratableInstance = hydrationContext.tryToClaimNextHydratableInstance; var _ReactFiberClassCompo = ReactFiberClassComponent( - legacyContext, scheduleWork, computeExpirationForFiber, memoizeProps, @@ -8640,17 +8725,9 @@ var ReactFiberBeginWork = function( } } - function updateForwardRef(current, workInProgress) { - var render = workInProgress.type.render; - var nextChildren = render(workInProgress.pendingProps, workInProgress.ref); - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextChildren); - return workInProgress.child; - } - function updateFragment(current, workInProgress) { var nextChildren = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (workInProgress.memoizedProps === nextChildren) { @@ -8663,7 +8740,7 @@ var ReactFiberBeginWork = function( function updateMode(current, workInProgress) { var nextChildren = workInProgress.pendingProps.children; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if ( @@ -8692,7 +8769,7 @@ var ReactFiberBeginWork = function( var fn = workInProgress.type; var nextProps = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else { @@ -8725,7 +8802,7 @@ var ReactFiberBeginWork = function( // Push context providers early to prevent context stack mismatches. // During mounting we don't know the child context yet as the instance doesn't exist. // We will invalidate the child context in finishClassComponent() right after rendering. - var hasContext = pushLegacyContextProvider(workInProgress); + var hasContext = pushContextProvider(workInProgress); var shouldUpdate = void 0; if (current === null) { if (workInProgress.stateNode === null) { @@ -8950,7 +9027,7 @@ var ReactFiberBeginWork = function( var nextProps = workInProgress.pendingProps; var prevProps = current !== null ? current.memoizedProps : null; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (memoizedProps === nextProps) { @@ -9070,8 +9147,7 @@ var ReactFiberBeginWork = function( var partialState = callGetDerivedStateFromProps( workInProgress, value, - props, - workInProgress.memoizedState + props ); if (partialState !== null && partialState !== undefined) { @@ -9086,7 +9162,7 @@ var ReactFiberBeginWork = function( // Push context providers early to prevent context stack mismatches. // During mounting we don't know the child context yet as the instance doesn't exist. // We will invalidate the child context in finishClassComponent() right after rendering. - var hasContext = pushLegacyContextProvider(workInProgress); + var hasContext = pushContextProvider(workInProgress); adoptClassInstance(workInProgress, value); mountClassInstance(workInProgress, renderExpirationTime); return finishClassComponent( @@ -9104,13 +9180,11 @@ var ReactFiberBeginWork = function( var _Component = workInProgress.type; if (_Component) { - !!_Component.childContextTypes - ? warning( - false, - "%s(...): childContextTypes cannot be defined on a functional component.", - _Component.displayName || _Component.name || "Component" - ) - : void 0; + warning( + !_Component.childContextTypes, + "%s(...): childContextTypes cannot be defined on a functional component.", + _Component.displayName || _Component.name || "Component" + ); } if (workInProgress.ref !== null) { var info = ""; @@ -9161,7 +9235,7 @@ var ReactFiberBeginWork = function( function updateCallComponent(current, workInProgress, renderExpirationTime) { var nextProps = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (workInProgress.memoizedProps === nextProps) { @@ -9204,7 +9278,7 @@ var ReactFiberBeginWork = function( ) { pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo); var nextChildren = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (workInProgress.memoizedProps === nextChildren) { @@ -9238,10 +9312,6 @@ var ReactFiberBeginWork = function( renderExpirationTime ) { 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. @@ -9329,12 +9399,12 @@ var ReactFiberBeginWork = function( renderExpirationTime ) { var providerType = workInProgress.type; - var context = providerType._context; + var context = providerType.context; var newProps = workInProgress.pendingProps; var oldProps = workInProgress.memoizedProps; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (oldProps === newProps) { @@ -9382,14 +9452,12 @@ var ReactFiberBeginWork = function( ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT; { - !((changedBits & MAX_SIGNED_31_BIT_INT) === changedBits) - ? warning( - false, - "calculateChangedBits: Expected the return value to be a " + - "31-bit integer. Instead received: %s", - changedBits - ) - : void 0; + warning( + (changedBits & MAX_SIGNED_31_BIT_INT) === changedBits, + "calculateChangedBits: Expected the return value to be a " + + "31-bit integer. Instead received: %s", + changedBits + ); } changedBits |= 0; @@ -9432,7 +9500,7 @@ var ReactFiberBeginWork = function( var newValue = context._currentValue; var changedBits = context._changedBits; - if (hasLegacyContextChanged()) { + if (hasContextChanged()) { // Normally we can bail out on props equality but if context has changed // we don't do the bailout and we have to reuse existing props instead. } else if (changedBits === 0 && oldProps === newProps) { @@ -9457,23 +9525,21 @@ var ReactFiberBeginWork = function( changedBits, renderExpirationTime ); + } else if (oldProps !== null && oldProps.children === newProps.children) { + // No change. Bailout early if children are the same. + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - // There is no bailout on `children` equality because we expect people - // to often pass a bound method as a child, but it may reference - // `this.state` or `this.props` (and thus needs to re-render on `setState`). var render = newProps.children; { - !(typeof render === "function") - ? warning( - false, - "A context consumer was rendered with multiple children, or a child " + - "that isn't a function. A context consumer expects a single child " + - "that is a function. If you did pass a function, make sure there " + - "is no trailing or leading whitespace around it." - ) - : void 0; + warning( + typeof render === "function", + "A context consumer was rendered with multiple children, or a child " + + "that isn't a function. A context consumer expects a single child " + + "that is a function. If you did pass a function, make sure there " + + "is no trailing or leading whitespace around it." + ); } var newChildren = render(newValue); @@ -9531,7 +9597,7 @@ var ReactFiberBeginWork = function( pushHostRootContext(workInProgress); break; case ClassComponent: - pushLegacyContextProvider(workInProgress); + pushContextProvider(workInProgress); break; case HostPortal: pushHostContainer( @@ -9612,8 +9678,6 @@ var ReactFiberBeginWork = function( workInProgress, renderExpirationTime ); - case ForwardRef: - return updateForwardRef(current, workInProgress); case Fragment: return updateFragment(current, workInProgress); case Mode: @@ -9644,13 +9708,7 @@ var ReactFiberBeginWork = function( }; }; -var ReactFiberCompleteWork = function( - config, - hostContext, - legacyContext, - newContext, - hydrationContext -) { +var ReactFiberCompleteWork = function(config, hostContext, hydrationContext) { var createInstance = config.createInstance, createTextInstance = config.createTextInstance, appendInitialChild = config.appendInitialChild, @@ -9662,9 +9720,6 @@ var ReactFiberCompleteWork = function( popHostContext = hostContext.popHostContext, getHostContext = hostContext.getHostContext, popHostContainer = hostContext.popHostContainer; - var popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject; - var popProvider = newContext.popProvider; var prepareToHydrateHostInstance = hydrationContext.prepareToHydrateHostInstance, prepareToHydrateHostTextInstance = @@ -9980,7 +10035,7 @@ var ReactFiberCompleteWork = function( return null; case ClassComponent: { // We are leaving this subtree, so pop context if any. - popLegacyContextProvider(workInProgress); + popContextProvider(workInProgress); // If this component caught an error, schedule an error log effect. var instance = workInProgress.stateNode; @@ -9999,7 +10054,7 @@ var ReactFiberCompleteWork = function( } case HostRoot: { popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); + popTopLevelContextObject(workInProgress); var fiberRoot = workInProgress.stateNode; if (fiberRoot.pendingContext) { fiberRoot.context = fiberRoot.pendingContext; @@ -10175,8 +10230,6 @@ var ReactFiberCompleteWork = function( case ReturnComponent: // Does nothing. return null; - case ForwardRef: - return null; case Fragment: return null; case Mode: @@ -10226,16 +10279,11 @@ function createCapturedValue(value, source) { var ReactFiberUnwindWork = function( hostContext, - legacyContext, - newContext, scheduleWork, isAlreadyFailedLegacyErrorBoundary ) { var popHostContainer = hostContext.popHostContainer, popHostContext = hostContext.popHostContext; - var popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject; - var popProvider = newContext.popProvider; function throwException(returnFiber, sourceFiber, rawValue) { // The source fiber did not complete. @@ -10291,7 +10339,7 @@ var ReactFiberUnwindWork = function( function unwindWork(workInProgress) { switch (workInProgress.tag) { case ClassComponent: { - popLegacyContextProvider(workInProgress); + popContextProvider(workInProgress); var effectTag = workInProgress.effectTag; if (effectTag & ShouldCapture) { workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture; @@ -10301,7 +10349,7 @@ var ReactFiberUnwindWork = function( } case HostRoot: { popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); + popTopLevelContextObject(workInProgress); var _effectTag = workInProgress.effectTag; if (_effectTag & ShouldCapture) { workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture; @@ -10323,37 +10371,9 @@ var ReactFiberUnwindWork = function( return null; } } - - function unwindInterruptedWork(interruptedWork) { - switch (interruptedWork.tag) { - case ClassComponent: { - popLegacyContextProvider(interruptedWork); - break; - } - case HostRoot: { - popHostContainer(interruptedWork); - popTopLevelLegacyContextObject(interruptedWork); - break; - } - case HostComponent: { - popHostContext(interruptedWork); - break; - } - case HostPortal: - popHostContainer(interruptedWork); - break; - case ContextProvider: - popProvider(interruptedWork); - break; - default: - break; - } - } - return { throwException: throwException, - unwindWork: unwindWork, - unwindInterruptedWork: unwindInterruptedWork + unwindWork: unwindWork }; }; @@ -10462,11 +10482,6 @@ var invokeGuardedCallback$3 = ReactErrorUtils.invokeGuardedCallback; var hasCaughtError$1 = ReactErrorUtils.hasCaughtError; var clearCaughtError$1 = ReactErrorUtils.clearCaughtError; -var didWarnAboutUndefinedSnapshotBeforeUpdate = null; -{ - didWarnAboutUndefinedSnapshotBeforeUpdate = new Set(); -} - function logError(boundary, errorInfo) { var source = errorInfo.source; var stack = errorInfo.stack; @@ -10476,19 +10491,21 @@ function logError(boundary, errorInfo) { var capturedError = { componentName: source !== null ? getComponentName(source) : null, - componentStack: stack !== null ? stack : "", error: errorInfo.value, - errorBoundary: null, + errorBoundary: boundary, + componentStack: stack !== null ? stack : "", errorBoundaryName: null, errorBoundaryFound: false, willRetry: false }; - if (boundary !== null && boundary.tag === ClassComponent) { - capturedError.errorBoundary = boundary.stateNode; + if (boundary !== null) { capturedError.errorBoundaryName = getComponentName(boundary); - capturedError.errorBoundaryFound = true; - capturedError.willRetry = true; + capturedError.errorBoundaryFound = capturedError.willRetry = + boundary.tag === ClassComponent; + } else { + capturedError.errorBoundaryName = null; + capturedError.errorBoundaryFound = capturedError.willRetry = false; } try { @@ -10552,59 +10569,7 @@ var ReactFiberCommitWork = function( } } } else { - ref.current = null; - } - } - } - - function commitBeforeMutationLifeCycles(current, finishedWork) { - switch (finishedWork.tag) { - case ClassComponent: { - if (finishedWork.effectTag & Snapshot) { - if (current !== null) { - var prevProps = current.memoizedProps; - var prevState = current.memoizedState; - startPhaseTimer(finishedWork, "getSnapshotBeforeUpdate"); - var _instance = finishedWork.stateNode; - _instance.props = finishedWork.memoizedProps; - _instance.state = finishedWork.memoizedState; - var snapshot = _instance.getSnapshotBeforeUpdate( - prevProps, - prevState - ); - { - var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate; - if ( - snapshot === undefined && - !didWarnSet.has(finishedWork.type) - ) { - didWarnSet.add(finishedWork.type); - warning( - false, - "%s.getSnapshotBeforeUpdate(): A snapshot value (or null) " + - "must be returned. You have returned undefined.", - getComponentName(finishedWork) - ); - } - } - _instance.__reactInternalSnapshotBeforeUpdate = snapshot; - stopPhaseTimer(); - } - } - return; - } - case HostRoot: - case HostComponent: - case HostText: - case HostPortal: - // Nothing to do for these component types - return; - default: { - invariant( - false, - "This unit of work tag should not have side-effects. This error is " + - "likely caused by a bug in React. Please file an issue." - ); + ref.value = null; } } } @@ -10618,54 +10583,50 @@ var ReactFiberCommitWork = function( ) { switch (finishedWork.tag) { case ClassComponent: { - var _instance2 = finishedWork.stateNode; + var _instance = finishedWork.stateNode; if (finishedWork.effectTag & Update) { if (current === null) { startPhaseTimer(finishedWork, "componentDidMount"); - _instance2.props = finishedWork.memoizedProps; - _instance2.state = finishedWork.memoizedState; - _instance2.componentDidMount(); + _instance.props = finishedWork.memoizedProps; + _instance.state = finishedWork.memoizedState; + _instance.componentDidMount(); stopPhaseTimer(); } else { var prevProps = current.memoizedProps; var prevState = current.memoizedState; startPhaseTimer(finishedWork, "componentDidUpdate"); - _instance2.props = finishedWork.memoizedProps; - _instance2.state = finishedWork.memoizedState; - _instance2.componentDidUpdate( - prevProps, - prevState, - _instance2.__reactInternalSnapshotBeforeUpdate - ); + _instance.props = finishedWork.memoizedProps; + _instance.state = finishedWork.memoizedState; + _instance.componentDidUpdate(prevProps, prevState); stopPhaseTimer(); } } var updateQueue = finishedWork.updateQueue; if (updateQueue !== null) { - commitCallbacks(updateQueue, _instance2); + commitCallbacks(updateQueue, _instance); } return; } case HostRoot: { var _updateQueue = finishedWork.updateQueue; if (_updateQueue !== null) { - var _instance3 = null; + var _instance2 = null; if (finishedWork.child !== null) { switch (finishedWork.child.tag) { case HostComponent: - _instance3 = getPublicInstance(finishedWork.child.stateNode); + _instance2 = getPublicInstance(finishedWork.child.stateNode); break; case ClassComponent: - _instance3 = finishedWork.child.stateNode; + _instance2 = finishedWork.child.stateNode; break; } } - commitCallbacks(_updateQueue, _instance3); + commitCallbacks(_updateQueue, _instance2); } return; } case HostComponent: { - var _instance4 = finishedWork.stateNode; + var _instance3 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted // (eg DOM renderer may schedule auto-focus for inputs and form controls). @@ -10674,7 +10635,7 @@ var ReactFiberCommitWork = function( if (current === null && finishedWork.effectTag & Update) { var type = finishedWork.type; var props = finishedWork.memoizedProps; - commitMount(_instance4, type, props, finishedWork); + commitMount(_instance3, type, props, finishedWork); } return; @@ -10702,7 +10663,7 @@ var ReactFiberCommitWork = function( case ClassComponent: { var ctor = finishedWork.type; - var _instance5 = finishedWork.stateNode; + var _instance4 = finishedWork.stateNode; var updateQueue = finishedWork.updateQueue; invariant( updateQueue !== null && updateQueue.capturedValues !== null, @@ -10719,19 +10680,16 @@ var ReactFiberCommitWork = function( // This gets reset before we yield back to the browser. // TODO: Warn in strict mode if getDerivedStateFromCatch is // not defined. - markLegacyErrorBoundaryAsFailed(_instance5); + markLegacyErrorBoundaryAsFailed(_instance4); } - _instance5.props = finishedWork.memoizedProps; - _instance5.state = finishedWork.memoizedState; + _instance4.props = finishedWork.memoizedProps; + _instance4.state = finishedWork.memoizedState; for (var i = 0; i < capturedErrors.length; i++) { var errorInfo = capturedErrors[i]; var _error = errorInfo.value; - var stack = errorInfo.stack; logError(finishedWork, errorInfo); - _instance5.componentDidCatch(_error, { - componentStack: stack !== null ? stack : "" - }); + _instance4.componentDidCatch(_error); } } break; @@ -10764,31 +10722,19 @@ var ReactFiberCommitWork = function( function commitAttachRef(finishedWork) { var ref = finishedWork.ref; if (ref !== null) { - var _instance6 = finishedWork.stateNode; + var _instance5 = finishedWork.stateNode; var instanceToUse = void 0; switch (finishedWork.tag) { case HostComponent: - instanceToUse = getPublicInstance(_instance6); + instanceToUse = getPublicInstance(_instance5); break; default: - instanceToUse = _instance6; + instanceToUse = _instance5; } if (typeof ref === "function") { ref(instanceToUse); } else { - { - if (!ref.hasOwnProperty("current")) { - warning( - false, - "Unexpected ref object provided for %s. " + - "Use either a ref-setter function or React.createRef().%s", - getComponentName(finishedWork), - getStackAddendumByWorkInProgressFiber(finishedWork) - ); - } - } - - ref.current = instanceToUse; + ref.value = instanceToUse; } } } @@ -10799,7 +10745,7 @@ var ReactFiberCommitWork = function( if (typeof currentRef === "function") { currentRef(null); } else { - currentRef.current = null; + currentRef.value = null; } } } @@ -10815,9 +10761,9 @@ var ReactFiberCommitWork = function( switch (current.tag) { case ClassComponent: { safelyDetachRef(current); - var _instance7 = current.stateNode; - if (typeof _instance7.componentWillUnmount === "function") { - safelyCallComponentWillUnmount(current, _instance7); + var _instance6 = current.stateNode; + if (typeof _instance6.componentWillUnmount === "function") { + safelyCallComponentWillUnmount(current, _instance6); } return; } @@ -10954,7 +10900,6 @@ var ReactFiberCommitWork = function( }, commitLifeCycles: commitLifeCycles, - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, commitErrorLogging: commitErrorLogging, commitAttachRef: commitAttachRef, commitDetachRef: commitDetachRef @@ -11213,8 +11158,8 @@ var ReactFiberCommitWork = function( return; } case HostComponent: { - var _instance8 = finishedWork.stateNode; - if (_instance8 != null) { + var _instance7 = finishedWork.stateNode; + if (_instance7 != null) { // Commit the work prepared earlier. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps @@ -11227,7 +11172,7 @@ var ReactFiberCommitWork = function( finishedWork.updateQueue = null; if (updatePayload !== null) { commitUpdate( - _instance8, + _instance7, updatePayload, type, oldProps, @@ -11272,7 +11217,6 @@ var ReactFiberCommitWork = function( if (enableMutatingReconciler) { return { - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, commitResetTextContent: commitResetTextContent, commitPlacement: commitPlacement, commitDeletion: commitDeletion, @@ -11289,12 +11233,9 @@ var ReactFiberCommitWork = function( var NO_CONTEXT = {}; -var ReactFiberHostContext = function(config, stack) { +var ReactFiberHostContext = function(config) { var getChildHostContext = config.getChildHostContext, getRootHostContext = config.getRootHostContext; - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; var contextStackCursor = createCursor(NO_CONTEXT); var contextFiberStackCursor = createCursor(NO_CONTEXT); @@ -11318,19 +11259,12 @@ var ReactFiberHostContext = function(config, stack) { // Push current root instance onto the stack; // This allows us to reset root when portals are popped. push(rootInstanceStackCursor, nextRootInstance, fiber); + + var nextRootContext = getRootHostContext(nextRootInstance); + // 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, NO_CONTEXT, fiber); - var nextRootContext = getRootHostContext(nextRootInstance); - // Now that we know this function doesn't throw, replace it. - pop(contextStackCursor, fiber); push(contextStackCursor, nextRootContext, fiber); } @@ -11372,13 +11306,19 @@ var ReactFiberHostContext = function(config, stack) { pop(contextFiberStackCursor, fiber); } + function resetHostContainer() { + contextStackCursor.current = NO_CONTEXT; + rootInstanceStackCursor.current = NO_CONTEXT; + } + return { getHostContext: getHostContext, getRootHostContainer: getRootHostContainer, popHostContainer: popHostContainer, popHostContext: popHostContext, pushHostContainer: pushHostContainer, - pushHostContext: pushHostContext + pushHostContext: pushHostContext, + resetHostContainer: resetHostContainer }; }; @@ -11748,429 +11688,6 @@ var ReactFiberInstrumentation = { var ReactFiberInstrumentation_1 = ReactFiberInstrumentation; -var warnedAboutMissingGetChildContext = void 0; - -{ - warnedAboutMissingGetChildContext = {}; -} - -var ReactFiberLegacyContext = function(stack) { - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; - - // A cursor to the current merged context object on the stack. - - var contextStackCursor = createCursor(emptyObject); - // A cursor to a boolean indicating whether the context has changed. - var didPerformWorkStackCursor = createCursor(false); - // Keep track of the previous context object that was on the stack. - // We use this to get access to the parent context after we have already - // pushed the next context provider, and now need to merge their contexts. - var previousContext = emptyObject; - - function getUnmaskedContext(workInProgress) { - var hasOwnContext = isContextProvider(workInProgress); - if (hasOwnContext) { - // If the fiber is a context provider itself, when we read its context - // we have already pushed its own child context on the stack. A context - // provider should not "see" its own child context. Therefore we read the - // previous (parent) context instead for a context provider. - return previousContext; - } - return contextStackCursor.current; - } - - function cacheContext(workInProgress, unmaskedContext, maskedContext) { - var instance = workInProgress.stateNode; - instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; - instance.__reactInternalMemoizedMaskedChildContext = maskedContext; - } - - function getMaskedContext(workInProgress, unmaskedContext) { - var type = workInProgress.type; - var contextTypes = type.contextTypes; - if (!contextTypes) { - return emptyObject; - } - - // Avoid recreating masked context unless unmasked context has changed. - // Failing to do this will result in unnecessary calls to componentWillReceiveProps. - // This may trigger infinite loops if componentWillReceiveProps calls setState. - var instance = workInProgress.stateNode; - if ( - instance && - instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext - ) { - return instance.__reactInternalMemoizedMaskedChildContext; - } - - var context = {}; - for (var key in contextTypes) { - context[key] = unmaskedContext[key]; - } - - { - var name = getComponentName(workInProgress) || "Unknown"; - checkPropTypes( - contextTypes, - context, - "context", - name, - ReactDebugCurrentFiber.getCurrentFiberStackAddendum - ); - } - - // Cache unmasked context so we can avoid recreating masked context unless necessary. - // Context is created before the class component is instantiated so check for instance. - if (instance) { - cacheContext(workInProgress, unmaskedContext, context); - } - - return context; - } - - function hasContextChanged() { - return didPerformWorkStackCursor.current; - } - - function isContextConsumer(fiber) { - return fiber.tag === ClassComponent && fiber.type.contextTypes != null; - } - - function isContextProvider(fiber) { - return fiber.tag === ClassComponent && fiber.type.childContextTypes != null; - } - - function popContextProvider(fiber) { - if (!isContextProvider(fiber)) { - return; - } - - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); - } - - function popTopLevelContextObject(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); - } - - function pushTopLevelContextObject(fiber, context, didChange) { - invariant( - contextStackCursor.cursor == null, - "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; - var childContextTypes = fiber.type.childContextTypes; - - // TODO (bvaughn) Replace this behavior with an invariant() in the future. - // It has only been added in Fiber to match the (unintentional) behavior in Stack. - if (typeof instance.getChildContext !== "function") { - { - var componentName = getComponentName(fiber) || "Unknown"; - - if (!warnedAboutMissingGetChildContext[componentName]) { - warnedAboutMissingGetChildContext[componentName] = true; - warning( - false, - "%s.childContextTypes is specified but there is no getChildContext() method " + - "on the instance. You can either define getChildContext() on %s or remove " + - "childContextTypes from it.", - componentName, - componentName - ); - } - } - return parentContext; - } - - var childContext = void 0; - { - ReactDebugCurrentFiber.setCurrentPhase("getChildContext"); - } - startPhaseTimer(fiber, "getChildContext"); - childContext = instance.getChildContext(); - stopPhaseTimer(); - { - ReactDebugCurrentFiber.setCurrentPhase(null); - } - for (var contextKey in childContext) { - invariant( - contextKey in childContextTypes, - '%s.getChildContext(): key "%s" is not defined in childContextTypes.', - getComponentName(fiber) || "Unknown", - contextKey - ); - } - { - var name = getComponentName(fiber) || "Unknown"; - checkPropTypes( - childContextTypes, - childContext, - "child context", - name, - // In practice, there is one case in which we won't get a stack. It's when - // somebody calls unstable_renderSubtreeIntoContainer() and we process - // context from the parent component instance. The stack will be missing - // because it's outside of the reconciliation, and so the pointer has not - // been set. This is rare and doesn't matter. We'll also remove that API. - ReactDebugCurrentFiber.getCurrentFiberStackAddendum - ); - } - - return Object.assign({}, parentContext, childContext); - } - - function pushContextProvider(workInProgress) { - if (!isContextProvider(workInProgress)) { - return false; - } - - var instance = workInProgress.stateNode; - // We push the context as early as possible to ensure stack integrity. - // If the instance does not exist yet, we will push null at first, - // and replace it on the stack later when invalidating the context. - var memoizedMergedChildContext = - (instance && instance.__reactInternalMemoizedMergedChildContext) || - emptyObject; - - // Remember the parent context so we can merge with it later. - // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates. - previousContext = contextStackCursor.current; - push(contextStackCursor, memoizedMergedChildContext, workInProgress); - push( - didPerformWorkStackCursor, - didPerformWorkStackCursor.current, - workInProgress - ); - - return true; - } - - 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) { - // Merge parent and own context. - // Skip this if we're not updating due to sCU. - // This avoids unnecessarily recomputing memoized values. - var mergedContext = processChildContext(workInProgress, previousContext); - instance.__reactInternalMemoizedMergedChildContext = mergedContext; - - // Replace the old (or empty) context with the new one. - // It is important to unwind the context in the reverse order. - pop(didPerformWorkStackCursor, workInProgress); - pop(contextStackCursor, workInProgress); - // Now push the new context and mark that it has changed. - push(contextStackCursor, mergedContext, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); - } else { - pop(didPerformWorkStackCursor, workInProgress); - push(didPerformWorkStackCursor, didChange, workInProgress); - } - } - - function findCurrentUnmaskedContext(fiber) { - // Currently this is only used with renderSubtreeIntoContainer; not sure if it - // makes sense elsewhere - invariant( - isFiberMounted(fiber) && fiber.tag === ClassComponent, - "Expected subtree parent to be a mounted class component. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - - var node = fiber; - while (node.tag !== HostRoot) { - if (isContextProvider(node)) { - return node.stateNode.__reactInternalMemoizedMergedChildContext; - } - var parent = node["return"]; - invariant( - parent, - "Found unexpected detached subtree parent. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - node = parent; - } - return node.stateNode.context; - } - - return { - getUnmaskedContext: getUnmaskedContext, - cacheContext: cacheContext, - getMaskedContext: getMaskedContext, - hasContextChanged: hasContextChanged, - isContextConsumer: isContextConsumer, - isContextProvider: isContextProvider, - popContextProvider: popContextProvider, - popTopLevelContextObject: popTopLevelContextObject, - pushTopLevelContextObject: pushTopLevelContextObject, - processChildContext: processChildContext, - pushContextProvider: pushContextProvider, - invalidateContextProvider: invalidateContextProvider, - findCurrentUnmaskedContext: findCurrentUnmaskedContext - }; -}; - -var ReactFiberNewContext = function(stack) { - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; - - var providerCursor = createCursor(null); - var valueCursor = createCursor(null); - var changedBitsCursor = createCursor(0); - - var rendererSigil = void 0; - { - // Use this to detect multiple renderers using the same context - rendererSigil = {}; - } - - function pushProvider(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; - - { - !( - context._currentRenderer === null || - context._currentRenderer === rendererSigil - ) - ? warning( - false, - "Detected multiple renderers concurrently rendering the " + - "same context provider. This is currently unsupported." - ) - : void 0; - context._currentRenderer = rendererSigil; - } - } - - function popProvider(providerFiber) { - var changedBits = changedBitsCursor.current; - var currentValue = valueCursor.current; - - pop(providerCursor, providerFiber); - pop(valueCursor, providerFiber); - pop(changedBitsCursor, providerFiber); - - var context = providerFiber.type._context; - context._currentValue = currentValue; - context._changedBits = changedBits; - } - - return { - pushProvider: pushProvider, - popProvider: popProvider - }; -}; - -var ReactFiberStack = function() { - var valueStack = []; - - var fiberStack = void 0; - - { - fiberStack = []; - } - - var index = -1; - - function createCursor(defaultValue) { - return { - current: defaultValue - }; - } - - function isEmpty() { - return index === -1; - } - - function pop(cursor, fiber) { - if (index < 0) { - { - warning(false, "Unexpected pop."); - } - return; - } - - { - if (fiber !== fiberStack[index]) { - warning(false, "Unexpected Fiber popped."); - } - } - - cursor.current = valueStack[index]; - - valueStack[index] = null; - - { - fiberStack[index] = null; - } - - index--; - } - - function push(cursor, value, fiber) { - index++; - - valueStack[index] = cursor.current; - - { - fiberStack[index] = fiber; - } - - cursor.current = value; - } - - function checkThatStackIsEmpty() { - { - if (index !== -1) { - warning( - false, - "Expected an empty stack. Something was not reset properly." - ); - } - } - } - - function resetStackAfterFatalErrorInDev() { - { - index = -1; - valueStack.length = 0; - fiberStack.length = 0; - } - } - - return { - createCursor: createCursor, - isEmpty: isEmpty, - pop: pop, - push: push, - checkThatStackIsEmpty: checkThatStackIsEmpty, - resetStackAfterFatalErrorInDev: resetStackAfterFatalErrorInDev - }; -}; - var invokeGuardedCallback$2 = ReactErrorUtils.invokeGuardedCallback; var hasCaughtError = ReactErrorUtils.hasCaughtError; var clearCaughtError = ReactErrorUtils.clearCaughtError; @@ -12186,19 +11703,17 @@ var warnAboutInvalidUpdates = void 0; var didWarnStateUpdateForUnmountedComponent = {}; warnAboutUpdateOnUnmounted = function(fiber) { - // We show the whole stack but dedupe on the top component's name because - // the problematic code almost always lies inside that component. var componentName = getComponentName(fiber) || "ReactClass"; if (didWarnStateUpdateForUnmountedComponent[componentName]) { return; } warning( false, - "Can't call setState (or forceUpdate) on an unmounted component. This " + - "is a no-op, but it indicates a memory leak in your application. To " + - "fix, cancel all subscriptions and asynchronous tasks in the " + - "componentWillUnmount method.%s", - getStackAddendumByWorkInProgressFiber(fiber) + "Can only update a mounted or mounting " + + "component. This usually means you called setState, replaceState, " + + "or forceUpdate on an unmounted component. This is a no-op.\n\nPlease " + + "check the code for the %s component.", + componentName ); didWarnStateUpdateForUnmountedComponent[componentName] = true; }; @@ -12233,23 +11748,16 @@ var warnAboutInvalidUpdates = void 0; } var ReactFiberScheduler = function(config) { - var stack = ReactFiberStack(); - var hostContext = ReactFiberHostContext(config, stack); - var legacyContext = ReactFiberLegacyContext(stack); - var newContext = ReactFiberNewContext(stack); + var hostContext = ReactFiberHostContext(config); var popHostContext = hostContext.popHostContext, popHostContainer = hostContext.popHostContainer; - var popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popLegacyContextProvider = legacyContext.popContextProvider; - var popProvider = newContext.popProvider; var hydrationContext = ReactFiberHydrationContext(config); + var resetHostContainer = hostContext.resetHostContainer; var _ReactFiberBeginWork = ReactFiberBeginWork( config, hostContext, - legacyContext, - newContext, hydrationContext, scheduleWork, computeExpirationForFiber @@ -12259,22 +11767,17 @@ var ReactFiberScheduler = function(config) { var _ReactFiberCompleteWo = ReactFiberCompleteWork( config, hostContext, - legacyContext, - newContext, hydrationContext ), completeWork = _ReactFiberCompleteWo.completeWork; var _ReactFiberUnwindWork = ReactFiberUnwindWork( hostContext, - legacyContext, - newContext, scheduleWork, isAlreadyFailedLegacyErrorBoundary ), throwException = _ReactFiberUnwindWork.throwException, - unwindWork = _ReactFiberUnwindWork.unwindWork, - unwindInterruptedWork = _ReactFiberUnwindWork.unwindInterruptedWork; + unwindWork = _ReactFiberUnwindWork.unwindWork; var _ReactFiberCommitWork = ReactFiberCommitWork( config, @@ -12284,8 +11787,6 @@ var ReactFiberScheduler = function(config) { markLegacyErrorBoundaryAsFailed, recalculateCurrentTime ), - commitBeforeMutationLifeCycles = - _ReactFiberCommitWork.commitBeforeMutationLifeCycles, commitResetTextContent = _ReactFiberCommitWork.commitResetTextContent, commitPlacement = _ReactFiberCommitWork.commitPlacement, commitDeletion = _ReactFiberCommitWork.commitDeletion, @@ -12337,29 +11838,21 @@ var ReactFiberScheduler = function(config) { var stashedWorkInProgressProperties = void 0; var replayUnitOfWork = void 0; - var isReplayingFailedUnitOfWork = void 0; - var originalReplayError = void 0; - var rethrowOriginalError = void 0; if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { stashedWorkInProgressProperties = null; - isReplayingFailedUnitOfWork = false; - originalReplayError = null; - replayUnitOfWork = function(failedUnitOfWork, error, isAsync) { - // Restore the original state of the work-in-progress - assignFiberPropertiesInDEV( - failedUnitOfWork, - stashedWorkInProgressProperties - ); + replayUnitOfWork = function(failedUnitOfWork, isAsync) { + // Retore the original state of the work-in-progress + Object.assign(failedUnitOfWork, stashedWorkInProgressProperties); switch (failedUnitOfWork.tag) { case HostRoot: popHostContainer(failedUnitOfWork); - popTopLevelLegacyContextObject(failedUnitOfWork); + popTopLevelContextObject(failedUnitOfWork); break; case HostComponent: popHostContext(failedUnitOfWork); break; case ClassComponent: - popLegacyContextProvider(failedUnitOfWork); + popContextProvider(failedUnitOfWork); break; case HostPortal: popHostContainer(failedUnitOfWork); @@ -12369,36 +11862,28 @@ var ReactFiberScheduler = function(config) { break; } // Replay the begin phase. - isReplayingFailedUnitOfWork = true; - originalReplayError = error; invokeGuardedCallback$2(null, workLoop, null, isAsync); - isReplayingFailedUnitOfWork = false; - originalReplayError = null; if (hasCaughtError()) { clearCaughtError(); } else { - // If the begin phase did not fail the second time, set this pointer - // back to the original value. - nextUnitOfWork = failedUnitOfWork; + // This should be unreachable because the render phase is + // idempotent } }; - rethrowOriginalError = function() { - throw originalReplayError; - }; } - function resetStack() { - if (nextUnitOfWork !== null) { - var interruptedWork = nextUnitOfWork["return"]; - while (interruptedWork !== null) { - unwindInterruptedWork(interruptedWork); - interruptedWork = interruptedWork["return"]; - } - } + function resetContextStack() { + // Reset the stack + reset(); + // Reset the cursors + resetContext(); + resetHostContainer(); + + // TODO: Unify new context implementation with other stacks + resetProviderStack(); { ReactStrictModeWarnings.discardPendingWarnings(); - stack.checkThatStackIsEmpty(); } nextRoot = null; @@ -12416,7 +11901,6 @@ var ReactFiberScheduler = function(config) { recordEffect(); var effectTag = nextEffect.effectTag; - if (effectTag & ContentReset) { commitResetTextContent(nextEffect); } @@ -12474,22 +11958,6 @@ var ReactFiberScheduler = function(config) { } } - function commitBeforeMutationLifecycles() { - while (nextEffect !== null) { - var effectTag = nextEffect.effectTag; - - if (effectTag & Snapshot) { - recordEffect(); - var current = nextEffect.alternate; - commitBeforeMutationLifeCycles(current, nextEffect); - } - - // Don't cleanup effects yet; - // This will be done by commitAllLifeCycles() - nextEffect = nextEffect.nextEffect; - } - } - function commitAllLifeCycles( finishedRoot, currentTime, @@ -12597,14 +12065,16 @@ var ReactFiberScheduler = function(config) { prepareForCommit(root.containerInfo); - // Invoke instances of getSnapshotBeforeUpdate before mutation. + // Commit all the side-effects within a tree. We'll do this in two passes. + // The first pass performs all the host insertions, updates, deletions and + // ref unmounts. nextEffect = firstEffect; - startCommitSnapshotEffectsTimer(); + startCommitHostEffectsTimer(); while (nextEffect !== null) { var didError = false; var error = void 0; { - invokeGuardedCallback$2(null, commitBeforeMutationLifecycles, null); + invokeGuardedCallback$2(null, commitAllHostEffects, null); if (hasCaughtError()) { didError = true; error = clearCaughtError(); @@ -12623,36 +12093,6 @@ var ReactFiberScheduler = function(config) { } } } - stopCommitSnapshotEffectsTimer(); - - // Commit all the side-effects within a tree. We'll do this in two passes. - // The first pass performs all the host insertions, updates, deletions and - // ref unmounts. - nextEffect = firstEffect; - startCommitHostEffectsTimer(); - while (nextEffect !== null) { - var _didError = false; - var _error = void 0; - { - invokeGuardedCallback$2(null, commitAllHostEffects, null); - if (hasCaughtError()) { - _didError = true; - _error = clearCaughtError(); - } - } - if (_didError) { - invariant( - nextEffect !== null, - "Should have next effect. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - onCommitPhaseError(nextEffect, _error); - // Clean-up - if (nextEffect !== null) { - nextEffect = nextEffect.nextEffect; - } - } - } stopCommitHostEffectsTimer(); resetAfterCommit(root.containerInfo); @@ -12670,8 +12110,8 @@ var ReactFiberScheduler = function(config) { nextEffect = firstEffect; startCommitLifeCyclesTimer(); while (nextEffect !== null) { - var _didError2 = false; - var _error2 = void 0; + var _didError = false; + var _error = void 0; { invokeGuardedCallback$2( null, @@ -12682,17 +12122,17 @@ var ReactFiberScheduler = function(config) { committedExpirationTime ); if (hasCaughtError()) { - _didError2 = true; - _error2 = clearCaughtError(); + _didError = true; + _error = clearCaughtError(); } } - if (_didError2) { + if (_didError) { invariant( nextEffect !== null, "Should have next effect. This error is likely caused by a bug " + "in React. Please file an issue." ); - onCommitPhaseError(nextEffect, _error2); + onCommitPhaseError(nextEffect, _error); if (nextEffect !== null) { nextEffect = nextEffect.nextEffect; } @@ -12916,21 +12356,12 @@ var ReactFiberScheduler = function(config) { } if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { - stashedWorkInProgressProperties = assignFiberPropertiesInDEV( - stashedWorkInProgressProperties, - workInProgress - ); + stashedWorkInProgressProperties = Object.assign({}, workInProgress); } var next = beginWork(current, workInProgress, nextRenderExpirationTime); + { ReactDebugCurrentFiber.resetCurrentFiber(); - if (isReplayingFailedUnitOfWork) { - // Currently replaying a failed unit of work. This should be unreachable, - // because the render phase is meant to be idempotent, and it should - // have thrown again. Since it didn't, rethrow the original error, so - // React's internal stack is not misaligned. - rethrowOriginalError(); - } } if (true && ReactFiberInstrumentation_1.debugTool) { ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress); @@ -12976,7 +12407,7 @@ var ReactFiberScheduler = function(config) { nextUnitOfWork === null ) { // Reset the stack and start working from the root. - resetStack(); + resetContextStack(); nextRoot = root; nextRenderExpirationTime = expirationTime; nextUnitOfWork = createWorkInProgress( @@ -13004,18 +12435,13 @@ var ReactFiberScheduler = function(config) { if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { var failedUnitOfWork = nextUnitOfWork; - replayUnitOfWork(failedUnitOfWork, thrownValue, isAsync); + replayUnitOfWork(failedUnitOfWork, isAsync); } var sourceFiber = nextUnitOfWork; var returnFiber = sourceFiber["return"]; if (returnFiber === null) { - // This is the root. The root could capture its own errors. However, - // we don't know if it errors before or after we pushed the host - // context. This information is needed to avoid a stack mismatch. - // Because we're not sure, treat this as a fatal error. We could track - // which phase it fails in, but doesn't seem worth it. At least - // for now. + // This is a fatal error. didFatal = true; onUncaughtError(thrownValue); break; @@ -13027,32 +12453,23 @@ var ReactFiberScheduler = function(config) { } while (true); // We're done performing work. Time to clean up. - var didCompleteRoot = false; + stopWorkLoopTimer(interruptedBy); + interruptedBy = null; isWorking = false; // Yield back to main thread. if (didFatal) { - stopWorkLoopTimer(interruptedBy, didCompleteRoot); - interruptedBy = null; // There was a fatal error. - { - stack.resetStackAfterFatalErrorInDev(); - } return null; } else if (nextUnitOfWork === null) { // We reached the root. if (isRootReadyForCommit) { - didCompleteRoot = true; - stopWorkLoopTimer(interruptedBy, didCompleteRoot); - interruptedBy = null; // The root successfully completed. It's ready for commit. root.pendingCommitExpirationTime = expirationTime; var finishedWork = root.current.alternate; return finishedWork; } else { // The root did not complete. - stopWorkLoopTimer(interruptedBy, didCompleteRoot); - interruptedBy = null; invariant( false, "Expired work should have completed. This error is likely caused " + @@ -13060,8 +12477,6 @@ var ReactFiberScheduler = function(config) { ); } } else { - stopWorkLoopTimer(interruptedBy, didCompleteRoot); - interruptedBy = null; // There's more work to do, but we ran out of time. Yield back to // the renderer. return null; @@ -13245,17 +12660,9 @@ var ReactFiberScheduler = function(config) { ) { // This is an interruption. (Used for performance tracking.) interruptedBy = fiber; - resetStack(); + resetContextStack(); } - if ( - // If we're in the render phase, we don't need to schedule this root - // for an update, because we'll do it before we exit... - !isWorking || - isCommitting || - // ...unless this is a different root than the one we're rendering. - nextRoot !== root - ) { - // Add this root to the root schedule. + if (nextRoot !== root || !isWorking) { requestWork(root, expirationTime); } if (nestedUpdateCount > NESTED_UPDATE_LIMIT) { @@ -13515,8 +12922,7 @@ var ReactFiberScheduler = function(config) { if (enableUserTimingAPI && deadline !== null) { var didExpire = nextFlushedExpirationTime < recalculateCurrentTime(); - var timeout = expirationTimeToMs(nextFlushedExpirationTime); - stopRequestCallbackTimer(didExpire, timeout); + stopRequestCallbackTimer(didExpire); } if (isAsync) { @@ -13576,11 +12982,7 @@ var ReactFiberScheduler = function(config) { // Perform work on root as if the given expiration time is the current time. // This has the effect of synchronously flushing all work up to and // including the given time. - nextFlushedRoot = root; - nextFlushedExpirationTime = expirationTime; performWorkOnRoot(root, expirationTime, false); - // Flush any sync work that was scheduled by lifecycles - performSyncWork(); finishRendering(); } @@ -13829,8 +13231,7 @@ var ReactFiberScheduler = function(config) { syncUpdates: syncUpdates, interactiveUpdates: interactiveUpdates, flushInteractiveUpdates: flushInteractiveUpdates, - computeUniqueAsyncExpiration: computeUniqueAsyncExpiration, - legacyContext: legacyContext + computeUniqueAsyncExpiration: computeUniqueAsyncExpiration }; }; @@ -13843,6 +13244,18 @@ var didWarnAboutNestedUpdates = void 0; // 0 is PROD, 1 is DEV. // Might add PROFILE later. +function getContextForSubtree(parentComponent) { + if (!parentComponent) { + return emptyObject; + } + + var fiber = get(parentComponent); + var parentContext = findCurrentUnmaskedContext(fiber); + return isContextProvider(fiber) + ? processChildContext(fiber, parentContext) + : parentContext; +} + var ReactFiberReconciler$1 = function(config) { var getPublicInstance = config.getPublicInstance; @@ -13861,24 +13274,7 @@ var ReactFiberReconciler$1 = function(config) { deferredUpdates = _ReactFiberScheduler.deferredUpdates, syncUpdates = _ReactFiberScheduler.syncUpdates, interactiveUpdates = _ReactFiberScheduler.interactiveUpdates, - flushInteractiveUpdates = _ReactFiberScheduler.flushInteractiveUpdates, - legacyContext = _ReactFiberScheduler.legacyContext; - - var findCurrentUnmaskedContext = legacyContext.findCurrentUnmaskedContext, - isContextProvider = legacyContext.isContextProvider, - processChildContext = legacyContext.processChildContext; - - function getContextForSubtree(parentComponent) { - if (!parentComponent) { - return emptyObject; - } - - var fiber = get(parentComponent); - var parentContext = findCurrentUnmaskedContext(fiber); - return isContextProvider(fiber) - ? processChildContext(fiber, parentContext) - : parentContext; - } + flushInteractiveUpdates = _ReactFiberScheduler.flushInteractiveUpdates; function scheduleRootUpdate( current, @@ -13907,14 +13303,12 @@ var ReactFiberReconciler$1 = function(config) { callback = callback === undefined ? null : callback; { - !(callback === null || typeof callback === "function") - ? warning( - false, - "render(...): Expected the last optional `callback` argument to be a " + - "function. Instead received: %s.", - callback - ) - : void 0; + warning( + callback === null || typeof callback === "function", + "render(...): Expected the last optional `callback` argument to be a " + + "function. Instead received: %s.", + callback + ); } var update = { @@ -14236,8 +13630,7 @@ var frameDeadline = 0; var frameDeadlineObject = { timeRemaining: function() { return frameDeadline - now(); - }, - didTimeout: false + } }; function setTimeoutCallback() { diff --git a/Libraries/Renderer/ReactNativeRenderer-prod.js b/Libraries/Renderer/ReactNativeRenderer-prod.js index 055ddd7bb0c..ca27b720b33 100644 --- a/Libraries/Renderer/ReactNativeRenderer-prod.js +++ b/Libraries/Renderer/ReactNativeRenderer-prod.js @@ -1174,9 +1174,6 @@ var hasSymbol = "function" === typeof Symbol && Symbol["for"], REACT_PROVIDER_TYPE = hasSymbol ? Symbol["for"]("react.provider") : 60109, REACT_CONTEXT_TYPE = hasSymbol ? Symbol["for"]("react.context") : 60110, REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol["for"]("react.async_mode") : 60111, - REACT_FORWARD_REF_TYPE = hasSymbol - ? Symbol["for"]("react.forward_ref") - : 60112, MAYBE_ITERATOR_SYMBOL = "function" === typeof Symbol && Symbol.iterator; function getIteratorFn(maybeIterable) { if (null === maybeIterable || "undefined" === typeof maybeIterable) @@ -1822,6 +1819,141 @@ 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; @@ -1905,9 +2037,6 @@ function createFiberFromElement(element, mode, expirationTime) { case REACT_CONTEXT_TYPE: fiberTag = 12; break; - case REACT_FORWARD_REF_TYPE: - fiberTag = 14; - break; default: if ("number" === typeof type.tag) return ( @@ -1988,45 +2117,6 @@ 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, @@ -2198,7 +2288,6 @@ function callGetDerivedStateFromCatch(ctor, capturedValues) { return resultState; } function ReactFiberClassComponent( - legacyContext, scheduleWork, computeExpirationForFiber, memoizeProps, @@ -2246,82 +2335,81 @@ function ReactFiberClassComponent( instance.state !== workInProgress && updater.enqueueReplaceState(instance, instance.state, null); } - function callGetDerivedStateFromProps( - workInProgress, - instance, - nextProps, - prevState - ) { + function callGetDerivedStateFromProps(workInProgress, instance, props) { instance = workInProgress.type; if ("function" === typeof instance.getDerivedStateFromProps) return ( (debugRenderPhaseSideEffects || (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & 2)) && - instance.getDerivedStateFromProps.call(null, nextProps, prevState), - instance.getDerivedStateFromProps.call(null, nextProps, prevState) + instance.getDerivedStateFromProps.call( + null, + props, + workInProgress.memoizedState + ), + instance.getDerivedStateFromProps.call( + null, + props, + workInProgress.memoizedState + ) ); } - 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); - } - }; + 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); + } + }; return { adoptClassInstance: adoptClassInstance, callGetDerivedStateFromProps: callGetDerivedStateFromProps, constructClassInstance: function(workInProgress, props) { var ctor = workInProgress.type, unmaskedContext = getUnmaskedContext(workInProgress), - needsContext = isContextConsumer(workInProgress), + needsContext = + 2 === workInProgress.tag && null != workInProgress.type.contextTypes, context = needsContext ? getMaskedContext(workInProgress, unmaskedContext) : emptyObject; @@ -2334,7 +2422,7 @@ function ReactFiberClassComponent( null !== ctor.state && void 0 !== ctor.state ? ctor.state : null; adoptClassInstance(workInProgress, ctor); workInProgress.memoizedState = state; - props = callGetDerivedStateFromProps(workInProgress, ctor, props, state); + props = callGetDerivedStateFromProps(workInProgress, ctor, props); null !== props && void 0 !== props && (workInProgress.memoizedState = Object.assign( @@ -2342,7 +2430,10 @@ function ReactFiberClassComponent( workInProgress.memoizedState, props )); - needsContext && cacheContext(workInProgress, unmaskedContext, context); + needsContext && + ((workInProgress = workInProgress.stateNode), + (workInProgress.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext), + (workInProgress.__reactInternalMemoizedMaskedChildContext = context)); return ctor; }, mountClassInstance: function(workInProgress, renderExpirationTime) { @@ -2355,10 +2446,9 @@ function ReactFiberClassComponent( instance.state = workInProgress.memoizedState; instance.refs = emptyObject; instance.context = getMaskedContext(workInProgress, unmaskedContext); - "function" === typeof ctor.getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate || - ("function" !== typeof instance.UNSAFE_componentWillMount && - "function" !== typeof instance.componentWillMount) || + ("function" !== typeof instance.UNSAFE_componentWillMount && + "function" !== typeof instance.componentWillMount) || + "function" === typeof ctor.getDerivedStateFromProps || ((ctor = instance.state), "function" === typeof instance.componentWillMount && instance.componentWillMount(), @@ -2389,12 +2479,9 @@ function ReactFiberClassComponent( oldContext = instance.context, newUnmaskedContext = getUnmaskedContext(workInProgress); newUnmaskedContext = getMaskedContext(workInProgress, newUnmaskedContext); - var hasNewLifecycles = + ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && + "function" !== typeof instance.componentWillReceiveProps) || "function" === typeof ctor.getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate; - hasNewLifecycles || - ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && - "function" !== typeof instance.componentWillReceiveProps) || ((oldProps !== newProps || oldContext !== newUnmaskedContext) && callComponentWillReceiveProps( workInProgress, @@ -2402,8 +2489,15 @@ function ReactFiberClassComponent( newProps, newUnmaskedContext )); - oldContext = workInProgress.memoizedState; - var derivedStateFromCatch = void 0; + oldContext = void 0; + oldProps !== newProps && + (oldContext = callGetDerivedStateFromProps( + workInProgress, + instance, + newProps + )); + var oldState = workInProgress.memoizedState, + derivedStateFromCatch = void 0; if (null !== workInProgress.updateQueue) { renderExpirationTime = processUpdateQueue( null, @@ -2422,46 +2516,24 @@ function ReactFiberClassComponent( ctor, updateQueue.capturedValues )); - } else renderExpirationTime = oldContext; - ctor = void 0; - oldProps !== newProps && - (ctor = callGetDerivedStateFromProps( - workInProgress, - instance, - newProps, - renderExpirationTime - )); - null !== ctor && - void 0 !== ctor && - ((renderExpirationTime = + } else renderExpirationTime = oldState; + null !== oldContext && + void 0 !== oldContext && + (renderExpirationTime = null === renderExpirationTime || void 0 === renderExpirationTime - ? ctor - : Object.assign({}, renderExpirationTime, ctor)), - (updateQueue = workInProgress.updateQueue), - null !== updateQueue && - (updateQueue.baseState = Object.assign( - {}, - updateQueue.baseState, - ctor - ))); + ? oldContext + : Object.assign({}, renderExpirationTime, oldContext)); null !== derivedStateFromCatch && void 0 !== derivedStateFromCatch && - ((renderExpirationTime = + (renderExpirationTime = null === renderExpirationTime || void 0 === renderExpirationTime ? derivedStateFromCatch - : Object.assign({}, renderExpirationTime, derivedStateFromCatch)), - (ctor = workInProgress.updateQueue), - null !== ctor && - (ctor.baseState = Object.assign( - {}, - ctor.baseState, - derivedStateFromCatch - ))); + : Object.assign({}, renderExpirationTime, derivedStateFromCatch)); if ( !( oldProps !== newProps || - oldContext !== renderExpirationTime || - hasContextChanged() || + oldState !== renderExpirationTime || + didPerformWorkStackCursor.current || (null !== workInProgress.updateQueue && workInProgress.updateQueue.hasForceUpdate) ) @@ -2475,18 +2547,26 @@ function ReactFiberClassComponent( workInProgress, oldProps, newProps, - oldContext, + oldState, renderExpirationTime, newUnmaskedContext )) - ? (hasNewLifecycles || - ("function" !== typeof instance.UNSAFE_componentWillMount && - "function" !== typeof instance.componentWillMount) || - ("function" === typeof instance.componentWillMount && - instance.componentWillMount(), - "function" === typeof instance.UNSAFE_componentWillMount && - instance.UNSAFE_componentWillMount()), - "function" === typeof instance.componentDidMount && + ? (("function" !== typeof instance.UNSAFE_componentWillUpdate && + "function" !== typeof instance.componentWillUpdate) || + "function" === typeof ctor.getDerivedStateFromProps || + ("function" === typeof instance.componentWillUpdate && + instance.componentWillUpdate( + newProps, + renderExpirationTime, + newUnmaskedContext + ), + "function" === typeof instance.UNSAFE_componentWillUpdate && + instance.UNSAFE_componentWillUpdate( + newProps, + renderExpirationTime, + newUnmaskedContext + )), + "function" === typeof instance.componentDidUpdate && (workInProgress.effectTag |= 4)) : ("function" === typeof instance.componentDidMount && (workInProgress.effectTag |= 4), @@ -2511,12 +2591,9 @@ function ReactFiberClassComponent( oldContext = instance.context, newUnmaskedContext = getUnmaskedContext(workInProgress); newUnmaskedContext = getMaskedContext(workInProgress, newUnmaskedContext); - var hasNewLifecycles = + ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && + "function" !== typeof instance.componentWillReceiveProps) || "function" === typeof ctor.getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate; - hasNewLifecycles || - ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && - "function" !== typeof instance.componentWillReceiveProps) || ((oldProps !== newProps || oldContext !== newUnmaskedContext) && callComponentWillReceiveProps( workInProgress, @@ -2524,6 +2601,13 @@ function ReactFiberClassComponent( newProps, newUnmaskedContext )); + var derivedStateFromProps = void 0; + oldProps !== newProps && + (derivedStateFromProps = callGetDerivedStateFromProps( + workInProgress, + instance, + newProps + )); oldContext = workInProgress.memoizedState; var derivedStateFromCatch = void 0; if (null !== workInProgress.updateQueue) { @@ -2545,45 +2629,23 @@ function ReactFiberClassComponent( updateQueue.capturedValues )); } else renderExpirationTime = oldContext; - ctor = void 0; - oldProps !== newProps && - (ctor = callGetDerivedStateFromProps( - workInProgress, - instance, - newProps, - renderExpirationTime - )); - null !== ctor && - void 0 !== ctor && - ((renderExpirationTime = + null !== derivedStateFromProps && + void 0 !== derivedStateFromProps && + (renderExpirationTime = null === renderExpirationTime || void 0 === renderExpirationTime - ? ctor - : Object.assign({}, renderExpirationTime, ctor)), - (updateQueue = workInProgress.updateQueue), - null !== updateQueue && - (updateQueue.baseState = Object.assign( - {}, - updateQueue.baseState, - ctor - ))); + ? derivedStateFromProps + : Object.assign({}, renderExpirationTime, derivedStateFromProps)); null !== derivedStateFromCatch && void 0 !== derivedStateFromCatch && - ((renderExpirationTime = + (renderExpirationTime = null === renderExpirationTime || void 0 === renderExpirationTime ? derivedStateFromCatch - : Object.assign({}, renderExpirationTime, derivedStateFromCatch)), - (ctor = workInProgress.updateQueue), - null !== ctor && - (ctor.baseState = Object.assign( - {}, - ctor.baseState, - derivedStateFromCatch - ))); + : Object.assign({}, renderExpirationTime, derivedStateFromCatch)); if ( !( oldProps !== newProps || oldContext !== renderExpirationTime || - hasContextChanged() || + didPerformWorkStackCursor.current || (null !== workInProgress.updateQueue && workInProgress.updateQueue.hasForceUpdate) ) @@ -2593,13 +2655,9 @@ function ReactFiberClassComponent( (oldProps === current.memoizedProps && oldContext === current.memoizedState) || (workInProgress.effectTag |= 4), - "function" !== typeof instance.getSnapshotBeforeUpdate || - (oldProps === current.memoizedProps && - oldContext === current.memoizedState) || - (workInProgress.effectTag |= 2048), !1 ); - (derivedStateFromCatch = checkShouldComponentUpdate( + (derivedStateFromProps = checkShouldComponentUpdate( workInProgress, oldProps, newProps, @@ -2607,9 +2665,9 @@ function ReactFiberClassComponent( renderExpirationTime, newUnmaskedContext )) - ? (hasNewLifecycles || - ("function" !== typeof instance.UNSAFE_componentWillUpdate && - "function" !== typeof instance.componentWillUpdate) || + ? (("function" !== typeof instance.UNSAFE_componentWillUpdate && + "function" !== typeof instance.componentWillUpdate) || + "function" === typeof ctor.getDerivedStateFromProps || ("function" === typeof instance.componentWillUpdate && instance.componentWillUpdate( newProps, @@ -2623,23 +2681,17 @@ function ReactFiberClassComponent( newUnmaskedContext )), "function" === typeof instance.componentDidUpdate && - (workInProgress.effectTag |= 4), - "function" === typeof instance.getSnapshotBeforeUpdate && - (workInProgress.effectTag |= 2048)) + (workInProgress.effectTag |= 4)) : ("function" !== typeof instance.componentDidUpdate || (oldProps === current.memoizedProps && oldContext === current.memoizedState) || (workInProgress.effectTag |= 4), - "function" !== typeof instance.getSnapshotBeforeUpdate || - (oldProps === current.memoizedProps && - oldContext === current.memoizedState) || - (workInProgress.effectTag |= 2048), memoizeProps(workInProgress, newProps), memoizeState(workInProgress, renderExpirationTime)); instance.props = newProps; instance.state = renderExpirationTime; instance.context = newUnmaskedContext; - return derivedStateFromCatch; + return derivedStateFromProps; } }; } @@ -3316,12 +3368,34 @@ function ChildReconciler(shouldTrackSideEffects) { }; } var reconcileChildFibers = ChildReconciler(!0), - mountChildFibers = ChildReconciler(!1); + 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; +} function ReactFiberBeginWork( config, hostContext, - legacyContext, - newContext, hydrationContext, scheduleWork, computeExpirationForFiber @@ -3427,12 +3501,7 @@ function ReactFiberBeginWork( changedBits, renderExpirationTime ) { - var fiber = workInProgress.child; - for ( - null !== fiber && (fiber["return"] = workInProgress); - null !== fiber; - - ) { + for (var fiber = workInProgress.child; null !== fiber; ) { switch (fiber.tag) { case 12: var nextFiber = fiber.stateNode | 0; @@ -3488,10 +3557,10 @@ function ReactFiberBeginWork( workInProgress, renderExpirationTime ) { - var context = workInProgress.type._context, + var context = workInProgress.type.context, newProps = workInProgress.pendingProps, oldProps = workInProgress.memoizedProps; - if (!hasLegacyContextChanged() && oldProps === newProps) + if (!didPerformWorkStackCursor.current && oldProps === newProps) return ( (workInProgress.stateNode = 0), pushProvider(workInProgress), @@ -3578,19 +3647,11 @@ 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) { @@ -3617,7 +3678,7 @@ function ReactFiberBeginWork( pushHostRootContext(workInProgress); break; case 2: - pushLegacyContextProvider(workInProgress); + pushContextProvider(workInProgress); break; case 4: pushHostContainer( @@ -3654,8 +3715,7 @@ function ReactFiberBeginWork( ((props = callGetDerivedStateFromProps( workInProgress, fn, - props, - workInProgress.memoizedState + props )), null !== props && void 0 !== props && @@ -3664,7 +3724,7 @@ function ReactFiberBeginWork( workInProgress.memoizedState, props ))), - (props = pushLegacyContextProvider(workInProgress)), + (props = pushContextProvider(workInProgress)), adoptClassInstance(workInProgress, fn), mountClassInstance(workInProgress, renderExpirationTime), (current = finishClassComponent( @@ -3684,7 +3744,7 @@ function ReactFiberBeginWork( return ( (props = workInProgress.type), (renderExpirationTime = workInProgress.pendingProps), - hasLegacyContextChanged() || + didPerformWorkStackCursor.current || workInProgress.memoizedProps !== renderExpirationTime ? ((fn = getUnmaskedContext(workInProgress)), (fn = getMaskedContext(workInProgress, fn)), @@ -3700,7 +3760,7 @@ function ReactFiberBeginWork( current ); case 2: - props = pushLegacyContextProvider(workInProgress); + props = pushContextProvider(workInProgress); null === current ? null === workInProgress.stateNode ? (constructClassInstance( @@ -3782,7 +3842,7 @@ function ReactFiberBeginWork( updateQueue = workInProgress.memoizedProps; fn = workInProgress.pendingProps; unmaskedContext = null !== current ? current.memoizedProps : null; - if (!hasLegacyContextChanged() && updateQueue === fn) { + if (!didPerformWorkStackCursor.current && updateQueue === fn) { if ( (updateQueue = workInProgress.mode & 1 && @@ -3824,7 +3884,7 @@ function ReactFiberBeginWork( case 7: return ( (props = workInProgress.pendingProps), - hasLegacyContextChanged() || + didPerformWorkStackCursor.current || workInProgress.memoizedProps !== props || (props = workInProgress.memoizedProps), (fn = props.children), @@ -3854,7 +3914,8 @@ function ReactFiberBeginWork( workInProgress.stateNode.containerInfo ), (props = workInProgress.pendingProps), - hasLegacyContextChanged() || workInProgress.memoizedProps !== props + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== props ? (null === current ? (workInProgress.child = reconcileChildFibers( workInProgress, @@ -3871,21 +3932,10 @@ function ReactFiberBeginWork( )), current ); - case 14: - return ( - (renderExpirationTime = workInProgress.type.render), - (renderExpirationTime = renderExpirationTime( - workInProgress.pendingProps, - workInProgress.ref - )), - reconcileChildren(current, workInProgress, renderExpirationTime), - (workInProgress.memoizedProps = renderExpirationTime), - workInProgress.child - ); case 10: return ( (renderExpirationTime = workInProgress.pendingProps), - hasLegacyContextChanged() || + didPerformWorkStackCursor.current || workInProgress.memoizedProps !== renderExpirationTime ? (reconcileChildren( current, @@ -3903,7 +3953,7 @@ function ReactFiberBeginWork( case 11: return ( (renderExpirationTime = workInProgress.pendingProps.children), - hasLegacyContextChanged() || + didPerformWorkStackCursor.current || (null !== renderExpirationTime && workInProgress.memoizedProps !== renderExpirationTime) ? (reconcileChildren( @@ -3926,33 +3976,43 @@ function ReactFiberBeginWork( renderExpirationTime ); case 12: - fn = workInProgress.type; - unmaskedContext = workInProgress.pendingProps; - var oldProps = workInProgress.memoizedProps; - props = fn._currentValue; - updateQueue = fn._changedBits; - if ( - hasLegacyContextChanged() || - 0 !== updateQueue || - oldProps !== unmaskedContext - ) { - workInProgress.memoizedProps = unmaskedContext; - oldProps = unmaskedContext.unstable_observedBits; - if (void 0 === oldProps || null === oldProps) oldProps = 1073741823; - workInProgress.stateNode = oldProps; - 0 !== (updateQueue & oldProps) && - propagateContextChange( - workInProgress, - fn, - updateQueue, - renderExpirationTime - ); - renderExpirationTime = unmaskedContext.children; - renderExpirationTime = renderExpirationTime(props); - reconcileChildren(current, workInProgress, renderExpirationTime); - current = workInProgress.child; - } else - current = bailoutOnAlreadyFinishedWork(current, workInProgress); + a: { + fn = workInProgress.type; + unmaskedContext = workInProgress.pendingProps; + updateQueue = workInProgress.memoizedProps; + props = fn._currentValue; + var changedBits = fn._changedBits; + if ( + didPerformWorkStackCursor.current || + 0 !== changedBits || + updateQueue !== unmaskedContext + ) { + workInProgress.memoizedProps = unmaskedContext; + var observedBits = unmaskedContext.unstable_observedBits; + if (void 0 === observedBits || null === observedBits) + observedBits = 1073741823; + workInProgress.stateNode = observedBits; + if (0 !== (changedBits & observedBits)) + propagateContextChange( + workInProgress, + fn, + changedBits, + renderExpirationTime + ); + else if ( + null !== updateQueue && + updateQueue.children === unmaskedContext.children + ) { + current = bailoutOnAlreadyFinishedWork(current, workInProgress); + break a; + } + renderExpirationTime = unmaskedContext.children; + renderExpirationTime = renderExpirationTime(props); + reconcileChildren(current, workInProgress, renderExpirationTime); + current = workInProgress.child; + } else + current = bailoutOnAlreadyFinishedWork(current, workInProgress); + } return current; default: invariant( @@ -3963,13 +4023,7 @@ function ReactFiberBeginWork( } }; } -function ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext -) { +function ReactFiberCompleteWork(config, hostContext, hydrationContext) { function markUpdate(workInProgress) { workInProgress.effectTag |= 4; } @@ -3983,9 +4037,6 @@ function ReactFiberCompleteWork( popHostContext = hostContext.popHostContext, getHostContext = hostContext.getHostContext, popHostContainer = hostContext.popHostContainer, - popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popProvider = newContext.popProvider, prepareToHydrateHostInstance = hydrationContext.prepareToHydrateHostInstance, prepareToHydrateHostTextInstance = @@ -4014,7 +4065,7 @@ function ReactFiberCompleteWork( return null; case 2: return ( - popLegacyContextProvider(workInProgress), + popContextProvider(workInProgress), (current = workInProgress.stateNode), (newProps = workInProgress.updateQueue), null !== newProps && @@ -4027,7 +4078,8 @@ function ReactFiberCompleteWork( ); case 3: popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); + pop(didPerformWorkStackCursor, workInProgress); + pop(contextStackCursor, workInProgress); newProps = workInProgress.stateNode; newProps.pendingContext && ((newProps.context = newProps.pendingContext), @@ -4211,8 +4263,6 @@ function ReactFiberCompleteWork( return (workInProgress.tag = 7), null; case 9: return null; - case 14: - return null; case 10: return null; case 11: @@ -4243,16 +4293,11 @@ function ReactFiberCompleteWork( } function ReactFiberUnwindWork( hostContext, - legacyContext, - newContext, scheduleWork, isAlreadyFailedLegacyErrorBoundary ) { var popHostContainer = hostContext.popHostContainer, - popHostContext = hostContext.popHostContext, - popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popProvider = newContext.popProvider; + popHostContext = hostContext.popHostContext; return { throwException: function(returnFiber, sourceFiber, rawValue) { sourceFiber.effectTag |= 512; @@ -4296,7 +4341,7 @@ function ReactFiberUnwindWork( unwindWork: function(workInProgress) { switch (workInProgress.tag) { case 2: - popLegacyContextProvider(workInProgress); + popContextProvider(workInProgress); var effectTag = workInProgress.effectTag; return effectTag & 1024 ? ((workInProgress.effectTag = (effectTag & -1025) | 64), @@ -4305,7 +4350,8 @@ function ReactFiberUnwindWork( case 3: return ( popHostContainer(workInProgress), - popTopLevelLegacyContextObject(workInProgress), + pop(didPerformWorkStackCursor, workInProgress), + pop(contextStackCursor, workInProgress), (effectTag = workInProgress.effectTag), effectTag & 1024 ? ((workInProgress.effectTag = (effectTag & -1025) | 64), @@ -4321,25 +4367,6 @@ 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); - } } }; } @@ -4348,9 +4375,9 @@ function logError(boundary, errorInfo) { stack = errorInfo.stack; null === stack && (stack = getStackAddendumByWorkInProgressFiber(source)); null !== source && getComponentName(source); - source = null !== stack ? stack : ""; errorInfo = errorInfo.value; - null !== boundary && 2 === boundary.tag && getComponentName(boundary); + stack = null !== stack ? stack : ""; + null !== boundary && getComponentName(boundary); try { if (errorInfo instanceof Error) { var message = errorInfo.message, @@ -4360,13 +4387,13 @@ function logError(boundary, errorInfo) { errorToHandle.message = (message ? name + ": " + message : name) + "\n\nThis error is located at:" + - source; + stack; } catch (e) {} } else errorToHandle = "string" === typeof errorInfo - ? Error(errorInfo + "\n\nThis error is located at:" + source) - : Error("Unspecified error at:" + source); + ? Error(errorInfo + "\n\nThis error is located at:" + stack) + : Error("Unspecified error at:" + stack); ExceptionsManager.handleException(errorToHandle, !1); } catch (e) { (e && e.suppressReactErrorLogging) || console.error(e); @@ -4388,19 +4415,19 @@ function ReactFiberCommitWork( } catch (refError) { captureError(current, refError); } - else ref.current = null; + else ref.value = null; } function commitUnmount(current) { "function" === typeof onCommitUnmount && onCommitUnmount(current); switch (current.tag) { case 2: safelyDetachRef(current); - var _instance7 = current.stateNode; - if ("function" === typeof _instance7.componentWillUnmount) + var _instance6 = current.stateNode; + if ("function" === typeof _instance6.componentWillUnmount) try { - (_instance7.props = current.memoizedProps), - (_instance7.state = current.memoizedState), - _instance7.componentWillUnmount(); + (_instance6.props = current.memoizedProps), + (_instance6.state = current.memoizedState), + _instance6.componentWillUnmount(); } catch (unmountError) { captureError(current, unmountError); } @@ -4510,34 +4537,6 @@ function ReactFiberCommitWork( removeChild = mutation.removeChild, removeChildFromContainer = mutation.removeChildFromContainer; return { - commitBeforeMutationLifeCycles: function(current, finishedWork) { - switch (finishedWork.tag) { - case 2: - if (finishedWork.effectTag & 2048 && null !== current) { - var prevProps = current.memoizedProps, - prevState = current.memoizedState; - current = finishedWork.stateNode; - current.props = finishedWork.memoizedProps; - current.state = finishedWork.memoizedState; - finishedWork = current.getSnapshotBeforeUpdate( - prevProps, - prevState - ); - current.__reactInternalSnapshotBeforeUpdate = finishedWork; - } - break; - case 3: - case 5: - case 6: - case 4: - break; - default: - invariant( - !1, - "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue." - ); - } - }, commitResetTextContent: function(current) { resetTextContent(current.stateNode); }, @@ -4643,8 +4642,8 @@ function ReactFiberCommitWork( case 2: break; case 5: - var _instance8 = finishedWork.stateNode; - if (null != _instance8) { + var _instance7 = finishedWork.stateNode; + if (null != _instance7) { var newProps = finishedWork.memoizedProps; current = null !== current ? current.memoizedProps : newProps; var type = finishedWork.type, @@ -4652,7 +4651,7 @@ function ReactFiberCommitWork( finishedWork.updateQueue = null; null !== updatePayload && commitUpdate( - _instance8, + _instance7, updatePayload, type, current, @@ -4666,11 +4665,11 @@ function ReactFiberCommitWork( null !== finishedWork.stateNode, "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue." ); - _instance8 = finishedWork.memoizedProps; + _instance7 = finishedWork.memoizedProps; commitTextUpdate( finishedWork.stateNode, - null !== current ? current.memoizedProps : _instance8, - _instance8 + null !== current ? current.memoizedProps : _instance7, + _instance7 ); break; case 3: @@ -4696,11 +4695,7 @@ function ReactFiberCommitWork( current = current.memoizedState; finishedRoot.props = finishedWork.memoizedProps; finishedRoot.state = finishedWork.memoizedState; - finishedRoot.componentDidUpdate( - prevProps, - current, - finishedRoot.__reactInternalSnapshotBeforeUpdate - ); + finishedRoot.componentDidUpdate(prevProps, current); } finishedWork = finishedWork.updateQueue; null !== finishedWork && commitCallbacks(finishedWork, finishedRoot); @@ -4762,12 +4757,9 @@ function ReactFiberCommitWork( onUncaughtError.state = finishedWork.memoizedState; for (ctor = 0; ctor < capturedErrors.length; ctor++) { updateQueue = capturedErrors[ctor]; - var _error = updateQueue.value, - stack = updateQueue.stack; + var _error = updateQueue.value; logError(finishedWork, updateQueue); - onUncaughtError.componentDidCatch(_error, { - componentStack: null !== stack ? stack : "" - }); + onUncaughtError.componentDidCatch(_error); } break; case 3: @@ -4793,17 +4785,17 @@ function ReactFiberCommitWork( commitAttachRef: function(finishedWork) { var ref = finishedWork.ref; if (null !== ref) { - var _instance6 = finishedWork.stateNode; + var _instance5 = finishedWork.stateNode; switch (finishedWork.tag) { case 5: - finishedWork = getPublicInstance(_instance6); + finishedWork = getPublicInstance(_instance5); break; default: - finishedWork = _instance6; + finishedWork = _instance5; } "function" === typeof ref ? ref(finishedWork) - : (ref.current = finishedWork); + : (ref.value = finishedWork); } }, commitDetachRef: function(current) { @@ -4811,12 +4803,12 @@ function ReactFiberCommitWork( null !== current && ("function" === typeof current ? current(null) - : (current.current = null)); + : (current.value = null)); } }; } var NO_CONTEXT = {}; -function ReactFiberHostContext(config, stack) { +function ReactFiberHostContext(config) { function requiredContext(c) { invariant( c !== NO_CONTEXT, @@ -4825,13 +4817,10 @@ function ReactFiberHostContext(config, stack) { return c; } var getChildHostContext = config.getChildHostContext, - 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); + getRootHostContext = config.getRootHostContext, + contextStackCursor = { current: NO_CONTEXT }, + contextFiberStackCursor = { current: NO_CONTEXT }, + rootInstanceStackCursor = { current: NO_CONTEXT }; return { getHostContext: function() { return requiredContext(contextStackCursor.current); @@ -4850,10 +4839,8 @@ function ReactFiberHostContext(config, stack) { }, pushHostContainer: function(fiber, nextRootInstance) { push(rootInstanceStackCursor, nextRootInstance, fiber); - push(contextFiberStackCursor, fiber, fiber); - push(contextStackCursor, NO_CONTEXT, fiber); nextRootInstance = getRootHostContext(nextRootInstance); - pop(contextStackCursor, fiber); + push(contextFiberStackCursor, fiber, fiber); push(contextStackCursor, nextRootInstance, fiber); }, pushHostContext: function(fiber) { @@ -4863,6 +4850,10 @@ function ReactFiberHostContext(config, stack) { context !== rootInstance && (push(contextFiberStackCursor, fiber, fiber), push(contextStackCursor, rootInstance, fiber)); + }, + resetHostContainer: function() { + contextStackCursor.current = NO_CONTEXT; + rootInstanceStackCursor.current = NO_CONTEXT; } }; } @@ -5022,198 +5013,22 @@ function ReactFiberHydrationContext(config) { } }; } -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; - 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; - } - }; -} -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"]); + function resetContextStack() { + for (; -1 < index; ) (valueStack[index] = null), index--; + 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; + } + index$1 = -1; nextRoot = null; nextRenderExpirationTime = 0; nextUnitOfWork = null; @@ -5286,7 +5101,7 @@ function ReactFiberScheduler(config) { workInProgress$jscomp$0 = unwindWork(workInProgress$jscomp$0); if (null !== workInProgress$jscomp$0) return ( - (workInProgress$jscomp$0.effectTag &= 2559), workInProgress$jscomp$0 + (workInProgress$jscomp$0.effectTag &= 511), workInProgress$jscomp$0 ); null !== returnFiber && ((returnFiber.firstEffect = returnFiber.lastEffect = null), @@ -5319,7 +5134,7 @@ function ReactFiberScheduler(config) { root !== nextRoot || null === nextUnitOfWork ) - resetStack(), + resetContextStack(), (nextRoot = root), (nextRenderExpirationTime = expirationTime), (nextUnitOfWork = createWorkInProgress( @@ -5449,8 +5264,8 @@ function ReactFiberScheduler(config) { !isWorking && 0 !== nextRenderExpirationTime && expirationTime < nextRenderExpirationTime && - resetStack(); - (isWorking && !isCommitting && nextRoot === root) || + resetContextStack(); + (nextRoot === root && isWorking) || requestWork(root, expirationTime); nestedUpdateCount > NESTED_UPDATE_LIMIT && invariant( @@ -5514,7 +5329,7 @@ function ReactFiberScheduler(config) { (nextFlushedExpirationTime = 1), performWorkOnRoot(root, 1, !1)) : 1 === expirationTime - ? performSyncWork() + ? performWork(1, !1, null) : scheduleCallbackWithExpiration(expirationTime)); } function findHighestPriorityRoot() { @@ -5574,9 +5389,6 @@ function ReactFiberScheduler(config) { function performAsyncWork(dl) { performWork(0, !0, dl); } - function performSyncWork() { - performWork(1, !1, null); - } function performWork(minExpirationTime, isAsync, dl) { deadline = dl; findHighestPriorityRoot(); @@ -5699,25 +5511,6 @@ function ReactFiberScheduler(config) { for (nextEffect = firstEffect; null !== nextEffect; ) { var didError = !1, error = void 0; - try { - for (; null !== nextEffect; ) - nextEffect.effectTag & 2048 && - commitBeforeMutationLifeCycles(nextEffect.alternate, nextEffect), - (nextEffect = nextEffect.nextEffect); - } catch (e) { - (didError = !0), (error = e); - } - didError && - (invariant( - null !== nextEffect, - "Should have next effect. This error is likely caused by a bug in React. Please file an issue." - ), - onCommitPhaseError(nextEffect, error), - null !== nextEffect && (nextEffect = nextEffect.nextEffect)); - } - for (nextEffect = firstEffect; null !== nextEffect; ) { - didError = !1; - error = void 0; try { for (; null !== nextEffect; ) { var effectTag = nextEffect.effectTag; @@ -5815,37 +5608,25 @@ function ReactFiberScheduler(config) { nextFlushedRoot.remainingExpirationTime = 0; hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error)); } - var stack = ReactFiberStack(), - hostContext = ReactFiberHostContext(config, stack), - legacyContext = ReactFiberLegacyContext(stack); - stack = ReactFiberNewContext(stack); - var hydrationContext = ReactFiberHydrationContext(config), + var hostContext = ReactFiberHostContext(config), + hydrationContext = ReactFiberHydrationContext(config), + resetHostContainer = hostContext.resetHostContainer, beginWork = ReactFiberBeginWork( config, hostContext, - legacyContext, - stack, hydrationContext, scheduleWork, computeExpirationForFiber ).beginWork, - completeWork = ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - stack, - hydrationContext - ).completeWork; + completeWork = ReactFiberCompleteWork(config, hostContext, hydrationContext) + .completeWork; hostContext = ReactFiberUnwindWork( hostContext, - legacyContext, - stack, scheduleWork, isAlreadyFailedLegacyErrorBoundary ); var throwException = hostContext.throwException, - unwindWork = hostContext.unwindWork, - unwindInterruptedWork = hostContext.unwindInterruptedWork; + unwindWork = hostContext.unwindWork; hostContext = ReactFiberCommitWork( config, onCommitPhaseError, @@ -5858,9 +5639,7 @@ function ReactFiberScheduler(config) { }, recalculateCurrentTime ); - var commitBeforeMutationLifeCycles = - hostContext.commitBeforeMutationLifeCycles, - commitResetTextContent = hostContext.commitResetTextContent, + var commitResetTextContent = hostContext.commitResetTextContent, commitPlacement = hostContext.commitPlacement, commitDeletion = hostContext.commitDeletion, commitWork = hostContext.commitWork, @@ -5915,10 +5694,7 @@ function ReactFiberScheduler(config) { !isRendering, "work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method." ); - nextFlushedRoot = root; - nextFlushedExpirationTime = expirationTime; performWorkOnRoot(root, expirationTime, !1); - performSyncWork(); finishRendering(); }, batchedUpdates: function(fn, a) { @@ -5929,7 +5705,7 @@ function ReactFiberScheduler(config) { } finally { (isBatchingUpdates = previousIsBatchingUpdates) || isRendering || - performSyncWork(); + performWork(1, !1, null); } }, unbatchedUpdates: function(fn, a) { @@ -5953,7 +5729,8 @@ function ReactFiberScheduler(config) { try { return syncUpdates(fn, a); } finally { - (isBatchingUpdates = previousIsBatchingUpdates), performSyncWork(); + (isBatchingUpdates = previousIsBatchingUpdates), + performWork(1, !1, null); } }, flushControlled: function(fn) { @@ -5994,7 +5771,7 @@ function ReactFiberScheduler(config) { (isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates), (isBatchingUpdates = previousIsBatchingUpdates) || isRendering || - performSyncWork(); + performWork(1, !1, null); } }, flushInteractiveUpdates: function() { @@ -6008,8 +5785,7 @@ function ReactFiberScheduler(config) { result <= lastUniqueAsyncExpiration && (result = lastUniqueAsyncExpiration + 1); return (lastUniqueAsyncExpiration = result); - }, - legacyContext: legacyContext + } }; } function ReactFiberReconciler$1(config) { @@ -6024,7 +5800,27 @@ function ReactFiberReconciler$1(config) { currentTime = container.current; if (parentComponent) { parentComponent = parentComponent._reactInternalFiber; - var parentContext = findCurrentUnmaskedContext(parentComponent); + 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; + } parentComponent = isContextProvider(parentComponent) ? processChildContext(parentComponent, parentContext) : parentContext; @@ -6053,11 +5849,7 @@ function ReactFiberReconciler$1(config) { config = ReactFiberScheduler(config); var recalculateCurrentTime = config.recalculateCurrentTime, computeExpirationForFiber = config.computeExpirationForFiber, - scheduleWork = config.scheduleWork, - legacyContext = config.legacyContext, - findCurrentUnmaskedContext = legacyContext.findCurrentUnmaskedContext, - isContextProvider = legacyContext.isContextProvider, - processChildContext = legacyContext.processChildContext; + scheduleWork = config.scheduleWork; return { createContainer: function(containerInfo, isAsync, hydrate) { isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0); @@ -6226,8 +6018,7 @@ var ReactFiberReconciler$2 = Object.freeze({ default: ReactFiberReconciler$1 }), frameDeadlineObject = { timeRemaining: function() { return frameDeadline - now(); - }, - didTimeout: !1 + } }; function setTimeoutCallback() { frameDeadline = now() + 5; @@ -6561,7 +6352,7 @@ NativeRenderer.injectIntoDevTools({ findFiberByHostInstance: getInstanceFromTag, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 0, - version: "16.3.1", + version: "16.3.0-alpha.1", rendererPackageName: "react-native-renderer" }); var ReactNativeRenderer$2 = Object.freeze({ default: ReactNativeRenderer }), diff --git a/Libraries/Renderer/shims/ReactTypes.js b/Libraries/Renderer/shims/ReactTypes.js index 87a769a148c..bede9f00e30 100644 --- a/Libraries/Renderer/shims/ReactTypes.js +++ b/Libraries/Renderer/shims/ReactTypes.js @@ -62,7 +62,7 @@ export type ReactProvider = { export type ReactProviderType = { $$typeof: Symbol | number, - _context: ReactContext, + context: ReactContext, }; export type ReactConsumer = { @@ -72,7 +72,7 @@ export type ReactConsumer = { ref: null, props: { children: (value: T) => ReactNodeList, - unstable_observedBits?: number, + bits?: number, }, }; diff --git a/package.json b/package.json index 4f4f5584511..8dda61d84ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native", - "version": "1000.0.0", + "version": "0.55.0", "description": "A framework for building native apps using React", "license": "MIT", "repository": { @@ -127,22 +127,22 @@ "lint": "eslint .", "prettier": "find . -name node_modules -prune -or -name '*.js' -print | xargs prettier --write", "start": "/usr/bin/env bash -c './scripts/packager.sh \"$@\" || true' --", - "docker-setup-android": "docker pull hramos/android-base:latest", - "docker-build-android-base": "docker build -t hramos/android-base -f ContainerShip/Dockerfile.android-base .", - "docker-build-android": "docker build -t react/android -f ContainerShip/Dockerfile.android .", + "test-android-setup": "docker pull hramos/android-base:latest", + "test-android-build-base": "docker build -t hramos/android-base -f ContainerShip/Dockerfile.android-base .", + "test-android-build": "docker build -t react/android -f ContainerShip/Dockerfile.android .", "test-android-run-instrumentation": "docker run --cap-add=SYS_ADMIN -it react/android bash ContainerShip/scripts/run-android-docker-instrumentation-tests.sh", "test-android-run-unit": "docker run --cap-add=SYS_ADMIN -it react/android bash ContainerShip/scripts/run-android-docker-unit-tests.sh", "test-android-run-e2e": "docker run --privileged -it react/android bash ContainerShip/scripts/run-ci-e2e-tests.sh --android --js", - "test-android-all": "yarn run docker-build-android && yarn run test-android-run-unit && yarn run test-android-run-instrumentation && yarn run test-android-run-e2e", - "test-android-instrumentation": "yarn run docker-build-android && yarn run test-android-run-instrumentation", - "test-android-unit": "yarn run docker-build-android && yarn run test-android-run-unit", - "test-android-e2e": "yarn run docker-build-android && yarn run test-android-run-e2e" + "test-android-all": "npm run test-android-build && npm run test-android-run-unit && npm run test-android-run-instrumentation && npm run test-android-run-e2e", + "test-android-instrumentation": "npm run test-android-build && npm run test-android-run-instrumentation", + "test-android-unit": "npm run test-android-build && npm run test-android-run-unit", + "test-android-e2e": "npm run test-android-build && npm run test-android-run-e2e" }, "bin": { "react-native": "local-cli/wrong-react-native.js" }, "peerDependencies": { - "react": "16.3.1" + "react": "^16.3.0-alpha.0" }, "dependencies": { "absolute-path": "^0.0.0", @@ -175,8 +175,8 @@ "graceful-fs": "^4.1.3", "inquirer": "^3.0.6", "lodash": "^4.17.5", - "metro": "^0.31.0", - "metro-core": "^0.31.0", + "metro": "^0.30.0", + "metro-core": "^0.30.0", "mime": "^1.3.4", "minimist": "^1.2.0", "mkdirp": "^0.5.1", @@ -215,13 +215,13 @@ "eslint-plugin-jest": "21.8.0", "eslint-plugin-prettier": "2.6.0", "eslint-plugin-react": "7.6.1", - "flow-bin": "^0.69.0", - "jest": "23.0.0-alpha.4", + "flow-bin": "^0.67.1", + "jest": "22.4.2", "jest-junit": "3.6.0", "prettier": "1.9.1", - "react": "16.3.1", - "react-test-renderer": "16.3.1", + "react": "^16.3.0-alpha.1", + "react-test-renderer": "^16.3.0-alpha.1", "shelljs": "^0.7.8", "sinon": "^2.2.0" } -} +} \ No newline at end of file