diff --git a/Libraries/Renderer/REVISION b/Libraries/Renderer/REVISION index 06ec4e875f81bd..7e020bc8087be8 100644 --- a/Libraries/Renderer/REVISION +++ b/Libraries/Renderer/REVISION @@ -1 +1 @@ -c0fe8d6f6942f5cbc93c09825e803ba8cf950522 \ No newline at end of file +ae14317d6810d5b07d01308a2116a707e5e09983 \ No newline at end of file diff --git a/Libraries/Renderer/oss/ReactFabric-dev.js b/Libraries/Renderer/oss/ReactFabric-dev.js index 3597c91b11f898..c81fac1813cc06 100644 --- a/Libraries/Renderer/oss/ReactFabric-dev.js +++ b/Libraries/Renderer/oss/ReactFabric-dev.js @@ -19,19 +19,17 @@ if (__DEV__) { require("InitializeCore"); var invariant = require("fbjs/lib/invariant"); var warning = require("fbjs/lib/warning"); -var emptyFunction = require("fbjs/lib/emptyFunction"); var ReactNativeViewConfigRegistry = require("ReactNativeViewConfigRegistry"); var UIManager = require("UIManager"); -var TextInputState = require("TextInputState"); -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 deepDiffer = require("deepDiffer"); +var flattenStyle = require("flattenStyle"); var deepFreezeAndThrowOnMutationInDev = require("deepFreezeAndThrowOnMutationInDev"); +var TextInputState = require("TextInputState"); var FabricUIManager = require("FabricUIManager"); +var checkPropTypes = require("prop-types/checkPropTypes"); +var ExceptionsManager = require("ExceptionsManager"); var invokeGuardedCallback = function(name, func, context, a, b, c, d, e, f) { this._hasCaughtError = false; @@ -1183,7 +1181,9 @@ var EventInterface = { type: null, target: null, // currentTarget is set when dispatching; no use in copying it here - currentTarget: emptyFunction.thatReturnsNull, + currentTarget: function() { + return null; + }, eventPhase: null, bubbles: null, cancelable: null, @@ -1194,6 +1194,14 @@ var EventInterface = { isTrusted: null }; +function functionThatReturnsTrue() { + return true; +} + +function functionThatReturnsFalse() { + return false; +} + /** * Synthetic events are dispatched by event plugins, typically in response to a * top-level event delegation handler. @@ -1254,11 +1262,11 @@ function SyntheticEvent( ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false; if (defaultPrevented) { - this.isDefaultPrevented = emptyFunction.thatReturnsTrue; + this.isDefaultPrevented = functionThatReturnsTrue; } else { - this.isDefaultPrevented = emptyFunction.thatReturnsFalse; + this.isDefaultPrevented = functionThatReturnsFalse; } - this.isPropagationStopped = emptyFunction.thatReturnsFalse; + this.isPropagationStopped = functionThatReturnsFalse; return this; } @@ -1275,7 +1283,7 @@ Object.assign(SyntheticEvent.prototype, { } else if (typeof event.returnValue !== "unknown") { event.returnValue = false; } - this.isDefaultPrevented = emptyFunction.thatReturnsTrue; + this.isDefaultPrevented = functionThatReturnsTrue; }, stopPropagation: function() { @@ -1295,7 +1303,7 @@ Object.assign(SyntheticEvent.prototype, { event.cancelBubble = true; } - this.isPropagationStopped = emptyFunction.thatReturnsTrue; + this.isPropagationStopped = functionThatReturnsTrue; }, /** @@ -1304,7 +1312,7 @@ Object.assign(SyntheticEvent.prototype, { * won't be added back into the pool. */ persist: function() { - this.isPersistent = emptyFunction.thatReturnsTrue; + this.isPersistent = functionThatReturnsTrue; }, /** @@ -1312,7 +1320,7 @@ Object.assign(SyntheticEvent.prototype, { * * @return {boolean} True if this should not be released, false otherwise. */ - isPersistent: emptyFunction.thatReturnsFalse, + isPersistent: functionThatReturnsFalse, /** * `PooledClass` looks for `destructor` on each instance it releases. @@ -1340,12 +1348,12 @@ Object.assign(SyntheticEvent.prototype, { Object.defineProperty( this, "preventDefault", - getPooledWarningPropertyDefinition("preventDefault", emptyFunction) + getPooledWarningPropertyDefinition("preventDefault", function() {}) ); Object.defineProperty( this, "stopPropagation", - getPooledWarningPropertyDefinition("stopPropagation", emptyFunction) + getPooledWarningPropertyDefinition("stopPropagation", function() {}) ); } } @@ -2371,64 +2379,58 @@ var ReactNativeBridgeEventPlugin = { } }; -var instanceCache = {}; -var instanceProps = {}; +var ReactNativeEventPluginOrder = [ + "ResponderEventPlugin", + "ReactNativeBridgeEventPlugin" +]; -function precacheFiberNode(hostInst, tag) { - instanceCache[tag] = hostInst; -} +/** + * Make sure essential globals are available and are patched correctly. Please don't remove this + * line. Bundles created by react-packager `require` it before executing any application code. This + * ensures it exists in the dependency graph and can be `require`d. + * TODO: require this in packager, not in React #10932517 + */ +// Module provided by RN: +/** + * Inject module for resolving DOM hierarchy and plugin ordering. + */ +injection.injectEventPluginOrder(ReactNativeEventPluginOrder); -function uncacheFiberNode(tag) { - delete instanceCache[tag]; - delete instanceProps[tag]; -} +/** + * Some important event plugins included by default (without having to require + * them). + */ +injection.injectEventPluginsByName({ + ResponderEventPlugin: ResponderEventPlugin, + ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin +}); -function getInstanceFromTag(tag) { - if (typeof tag === "number") { - return instanceCache[tag] || null; - } else { - // Fabric will invoke event emitters on a direct fiber reference - return tag; - } +function getInstanceFromInstance(instanceHandle) { + return instanceHandle; } function getTagFromInstance(inst) { - var tag = inst.stateNode._nativeTag; - if (tag === undefined) { - tag = inst.stateNode.canonical._nativeTag; - } + var tag = inst.stateNode.canonical._nativeTag; invariant(tag, "All native instances should have a tag."); return tag; } -function getFiberCurrentPropsFromNode$1(stateNode) { - return instanceProps[stateNode._nativeTag] || null; +function getFiberCurrentPropsFromNode$1(inst) { + return inst.canonical.currentProps; } -function updateFiberProps(tag, props) { - instanceProps[tag] = props; -} - -var ReactNativeComponentTree = Object.freeze({ - precacheFiberNode: precacheFiberNode, - uncacheFiberNode: uncacheFiberNode, - getClosestInstanceFromNode: getInstanceFromTag, - getInstanceFromNode: getInstanceFromTag, +var ReactFabricComponentTree = Object.freeze({ + getClosestInstanceFromNode: getInstanceFromInstance, + getInstanceFromNode: getInstanceFromInstance, getNodeFromInstance: getTagFromInstance, - getFiberCurrentPropsFromNode: getFiberCurrentPropsFromNode$1, - updateFiberProps: updateFiberProps + getFiberCurrentPropsFromNode: getFiberCurrentPropsFromNode$1 }); -var ReactNativeEventPluginOrder = [ - "ResponderEventPlugin", - "ReactNativeBridgeEventPlugin" -]; - // Module provided by RN: -var ReactNativeGlobalResponderHandler = { +var ReactFabricGlobalResponderHandler = { onChange: function(from, to, blockNativeResponder) { if (to !== null) { - var tag = to.stateNode._nativeTag; + var tag = to.stateNode.canonical._nativeTag; UIManager.setJSResponder(tag, blockNativeResponder); } else { UIManager.clearJSResponder(); @@ -2436,44 +2438,40 @@ var ReactNativeGlobalResponderHandler = { } }; -/** - * Make sure essential globals are available and are patched correctly. Please don't remove this - * line. Bundles created by react-packager `require` it before executing any application code. This - * ensures it exists in the dependency graph and can be `require`d. - * TODO: require this in packager, not in React #10932517 - */ -// Module provided by RN: -/** - * Inject module for resolving DOM hierarchy and plugin ordering. - */ -injection.injectEventPluginOrder(ReactNativeEventPluginOrder); -injection$1.injectComponentTree(ReactNativeComponentTree); +injection$1.injectComponentTree(ReactFabricComponentTree); ResponderEventPlugin.injection.injectGlobalResponderHandler( - ReactNativeGlobalResponderHandler + ReactFabricGlobalResponderHandler ); /** - * Some important event plugins included by default (without having to require - * them). + * `ReactInstanceMap` maintains a mapping from a public facing stateful + * instance (key) and the internal representation (value). This allows public + * methods to accept the user facing instance as an argument and map them back + * to internal methods. + * + * Note that this module is currently shared and assumed to be stateless. + * If this becomes an actual Map, that will break. + */ + +/** + * This API should be called `delete` but we'd have to make sure to always + * transform these to strings for IE support. When this transform is fully + * supported we can rename it. */ -injection.injectEventPluginsByName({ - ResponderEventPlugin: ResponderEventPlugin, - ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin -}); -// TODO: The event emitter registration is interfering with the existing -// ReactNative renderer. So disable it for Fabric for now. +function get$1(key) { + return key._reactInternalFiber; +} -// import * as ReactNativeEventEmitter from './ReactNativeEventEmitter'; +function set(key, value) { + key._reactInternalFiber = value; +} -// Module provided by RN: -// import RCTEventEmitter from 'RCTEventEmitter'; +var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; -/** - * Register the event emitter with the native bridge - */ -// RCTEventEmitter.register(ReactNativeEventEmitter); +var ReactCurrentOwner = ReactInternals.ReactCurrentOwner; +var ReactDebugCurrentFrame = ReactInternals.ReactDebugCurrentFrame; // The Symbol used to tag the ReactElement-like types. If there is no native Symbol // nor polyfill, then a plain number is used for performance. @@ -2510,238 +2508,503 @@ function getIteratorFn(maybeIterable) { return null; } -function createPortal( - children, - containerInfo, - // TODO: figure out the API for cross-renderer implementation. - implementation -) { - var key = - arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; +function getComponentName(fiber) { + var type = fiber.type; - return { - // This tag allow us to uniquely identify this as a React Portal - $$typeof: REACT_PORTAL_TYPE, - key: key == null ? null : "" + key, - children: children, - containerInfo: containerInfo, - implementation: implementation - }; + if (typeof type === "function") { + return type.displayName || type.name; + } + if (typeof type === "string") { + return type; + } + switch (type) { + case REACT_ASYNC_MODE_TYPE: + return "AsyncMode"; + case REACT_CONTEXT_TYPE: + return "Context.Consumer"; + case REACT_FRAGMENT_TYPE: + return "ReactFragment"; + case REACT_PORTAL_TYPE: + return "ReactPortal"; + case REACT_PROFILER_TYPE: + return "Profiler(" + fiber.pendingProps.id + ")"; + case REACT_PROVIDER_TYPE: + return "Context.Provider"; + case REACT_STRICT_MODE_TYPE: + return "StrictMode"; + case REACT_TIMEOUT_TYPE: + return "Timeout"; + } + if (typeof type === "object" && type !== null) { + switch (type.$$typeof) { + case REACT_FORWARD_REF_TYPE: + var functionName = type.render.displayName || type.render.name || ""; + return functionName !== "" + ? "ForwardRef(" + functionName + ")" + : "ForwardRef"; + } + } + return null; } -// Use to restore controlled state after a change event has fired. +// Don't change these two values. They're used by React Dev Tools. +var NoEffect = /* */ 0; +var PerformedWork = /* */ 1; -var fiberHostComponent = null; +// You can change the rest (and add more). +var Placement = /* */ 2; +var Update = /* */ 4; +var PlacementAndUpdate = /* */ 6; +var Deletion = /* */ 8; +var ContentReset = /* */ 16; +var Callback = /* */ 32; +var DidCapture = /* */ 64; +var Ref = /* */ 128; +var Snapshot = /* */ 256; -var restoreTarget = null; -var restoreQueue = null; +// Union of all host effects +var HostEffectMask = /* */ 511; -function restoreStateOfTarget(target) { - // We perform this translation at the end of the event loop so that we - // always receive the correct fiber here - var internalInstance = getInstanceFromNode(target); - if (!internalInstance) { - // Unmounted - return; +var Incomplete = /* */ 512; +var ShouldCapture = /* */ 1024; + +var MOUNTING = 1; +var MOUNTED = 2; +var UNMOUNTED = 3; + +function isFiberMountedImpl(fiber) { + var node = fiber; + if (!fiber.alternate) { + // If there is no alternate, this might be a new tree that isn't inserted + // yet. If it is, then it will have a pending insertion effect on it. + if ((node.effectTag & Placement) !== NoEffect) { + return MOUNTING; + } + while (node.return) { + node = node.return; + if ((node.effectTag & Placement) !== NoEffect) { + return MOUNTING; + } + } + } else { + while (node.return) { + node = node.return; + } } - invariant( - fiberHostComponent && - typeof fiberHostComponent.restoreControlledState === "function", - "Fiber needs to be injected to handle a fiber target for controlled " + - "events. This error is likely caused by a bug in React. Please file an issue." - ); - var props = getFiberCurrentPropsFromNode(internalInstance.stateNode); - fiberHostComponent.restoreControlledState( - internalInstance.stateNode, - internalInstance.type, - props - ); + if (node.tag === HostRoot) { + // TODO: Check if this was a nested HostRoot when used with + // renderContainerIntoSubtree. + return MOUNTED; + } + // If we didn't hit the root, that means that we're in an disconnected tree + // that has been unmounted. + return UNMOUNTED; } -function needsStateRestore() { - return restoreTarget !== null || restoreQueue !== null; +function isFiberMounted(fiber) { + return isFiberMountedImpl(fiber) === MOUNTED; } -function restoreStateIfNeeded() { - if (!restoreTarget) { - return; - } - var target = restoreTarget; - var queuedTargets = restoreQueue; - restoreTarget = null; - restoreQueue = null; - - restoreStateOfTarget(target); - if (queuedTargets) { - for (var i = 0; i < queuedTargets.length; i++) { - restoreStateOfTarget(queuedTargets[i]); +function isMounted(component) { + { + var owner = ReactCurrentOwner.current; + 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; + instance._warnedAboutRefsInRender = true; } } -} -// Used as a way to call batchedUpdates when we don't have a reference to -// the renderer. Such as when we're dispatching events or if third party -// libraries need to call batchedUpdates. Eventually, this API will go away when -// everything is batched by default. We'll then have a similar API to opt-out of -// scheduled work and instead do synchronous work. - -// Defaults -var _batchedUpdates = function(fn, bookkeeping) { - return fn(bookkeeping); -}; -var _interactiveUpdates = function(fn, a, b) { - return fn(a, b); -}; -var _flushInteractiveUpdates = function() {}; - -var isBatching = false; -function batchedUpdates(fn, bookkeeping) { - if (isBatching) { - // If we are currently inside another batch, we need to wait until it - // fully completes before restoring state. - return fn(bookkeeping); - } - isBatching = true; - try { - return _batchedUpdates(fn, bookkeeping); - } finally { - // Here we wait until all updates have propagated, which is important - // when using controlled components within layers: - // https://github.com/facebook/react/issues/1698 - // Then we restore state of any controlled component. - isBatching = false; - var controlledComponentsHavePendingUpdates = needsStateRestore(); - if (controlledComponentsHavePendingUpdates) { - // If a controlled event was fired, we may need to restore the state of - // the DOM node back to the controlled value. This is necessary when React - // bails out of the update without touching the DOM. - _flushInteractiveUpdates(); - restoreStateIfNeeded(); - } + var fiber = get$1(component); + if (!fiber) { + return false; } + return isFiberMountedImpl(fiber) === MOUNTED; } -var injection$2 = { - injectRenderer: function(renderer) { - _batchedUpdates = renderer.batchedUpdates; - _interactiveUpdates = renderer.interactiveUpdates; - _flushInteractiveUpdates = renderer.flushInteractiveUpdates; - } -}; - -// TODO: this is special because it gets imported during build. - -var ReactVersion = "16.3.2"; - -// Modules provided by RN: -var emptyObject$1 = {}; - -/** - * Create a payload that contains all the updates between two sets of props. - * - * These helpers are all encapsulated into a single module, because they use - * mutation as a performance optimization which leads to subtle shared - * dependencies between the code paths. To avoid this mutable state leaking - * across modules, I've kept them isolated to this module. - */ - -// Tracks removed keys -var removedKeys = null; -var removedKeyCount = 0; - -function defaultDiffer(prevProp, nextProp) { - if (typeof nextProp !== "object" || nextProp === null) { - // Scalars have already been checked for equality - return true; - } else { - // For objects and arrays, the default diffing algorithm is a deep compare - return deepDiffer(prevProp, nextProp); - } +function assertIsMounted(fiber) { + invariant( + isFiberMountedImpl(fiber) === MOUNTED, + "Unable to find node on an unmounted component." + ); } -function restoreDeletedValuesInNestedArray( - updatePayload, - node, - validAttributes -) { - if (Array.isArray(node)) { - var i = node.length; - while (i-- && removedKeyCount > 0) { - restoreDeletedValuesInNestedArray( - updatePayload, - node[i], - validAttributes - ); +function findCurrentFiberUsingSlowPath(fiber) { + var alternate = fiber.alternate; + if (!alternate) { + // If there is no alternate, then we only need to check if it is mounted. + var state = isFiberMountedImpl(fiber); + invariant( + state !== UNMOUNTED, + "Unable to find node on an unmounted component." + ); + if (state === MOUNTING) { + return null; + } + return fiber; + } + // If we have two possible branches, we'll walk backwards up to the root + // to see what path the root points to. On the way we may hit one of the + // special cases and we'll deal with them. + var a = fiber; + var b = alternate; + while (true) { + var parentA = a.return; + var parentB = parentA ? parentA.alternate : null; + if (!parentA || !parentB) { + // We're at the root. + break; } - } else if (node && removedKeyCount > 0) { - var obj = node; - for (var propKey in removedKeys) { - if (!removedKeys[propKey]) { - continue; - } - var _nextProp = obj[propKey]; - if (_nextProp === undefined) { - continue; - } - var attributeConfig = validAttributes[propKey]; - if (!attributeConfig) { - continue; // not a valid native prop + // If both copies of the parent fiber point to the same child, we can + // assume that the child is current. This happens when we bailout on low + // priority: the bailed out fiber's child reuses the current child. + if (parentA.child === parentB.child) { + var child = parentA.child; + while (child) { + if (child === a) { + // We've determined that A is the current branch. + assertIsMounted(parentA); + return fiber; + } + if (child === b) { + // We've determined that B is the current branch. + assertIsMounted(parentA); + return alternate; + } + child = child.sibling; } + // We should never have an alternate for any mounting node. So the only + // way this could possibly happen is if this was unmounted, if at all. + invariant(false, "Unable to find node on an unmounted component."); + } - if (typeof _nextProp === "function") { - _nextProp = true; - } - if (typeof _nextProp === "undefined") { - _nextProp = null; + if (a.return !== b.return) { + // The return pointer of A and the return pointer of B point to different + // fibers. We assume that return pointers never criss-cross, so A must + // belong to the child set of A.return, and B must belong to the child + // set of B.return. + a = parentA; + b = parentB; + } else { + // The return pointers point to the same fiber. We'll have to use the + // default, slow path: scan the child sets of each parent alternate to see + // which child belongs to which set. + // + // Search parent A's child set + var didFindChild = false; + var _child = parentA.child; + while (_child) { + if (_child === a) { + didFindChild = true; + a = parentA; + b = parentB; + break; + } + if (_child === b) { + didFindChild = true; + b = parentA; + a = parentB; + break; + } + _child = _child.sibling; } - - if (typeof attributeConfig !== "object") { - // case: !Object is the default case - updatePayload[propKey] = _nextProp; - } else if ( - typeof attributeConfig.diff === "function" || - typeof attributeConfig.process === "function" - ) { - // case: CustomAttributeConfiguration - var nextValue = - typeof attributeConfig.process === "function" - ? attributeConfig.process(_nextProp) - : _nextProp; - updatePayload[propKey] = nextValue; + if (!didFindChild) { + // Search parent B's child set + _child = parentB.child; + while (_child) { + if (_child === a) { + didFindChild = true; + a = parentB; + b = parentA; + break; + } + if (_child === b) { + didFindChild = true; + b = parentB; + a = parentA; + break; + } + _child = _child.sibling; + } + invariant( + didFindChild, + "Child was not found in either parent set. This indicates a bug " + + "in React related to the return pointer. Please file an issue." + ); } - removedKeys[propKey] = false; - removedKeyCount--; } - } -} -function diffNestedArrayProperty( - updatePayload, - prevArray, - nextArray, - validAttributes -) { - var minLength = - prevArray.length < nextArray.length ? prevArray.length : nextArray.length; - var i = void 0; - for (i = 0; i < minLength; i++) { - // Diff any items in the array in the forward direction. Repeated keys - // will be overwritten by later values. - updatePayload = diffNestedProperty( - updatePayload, - prevArray[i], - nextArray[i], - validAttributes + invariant( + a.alternate === b, + "Return fibers should always be each others' alternates. " + + "This error is likely caused by a bug in React. Please file an issue." ); } - for (; i < prevArray.length; i++) { - // Clear out all remaining properties. - updatePayload = clearNestedProperty( - updatePayload, - prevArray[i], - validAttributes - ); + // If the root is not a host container, we're in a disconnected tree. I.e. + // unmounted. + invariant( + a.tag === HostRoot, + "Unable to find node on an unmounted component." + ); + if (a.stateNode.current === a) { + // We've determined that A is the current branch. + return fiber; + } + // Otherwise B has to be current branch. + return alternate; +} + +function findCurrentHostFiber(parent) { + var currentParent = findCurrentFiberUsingSlowPath(parent); + if (!currentParent) { + return null; + } + + // Next we'll drill down this component to find the first HostComponent/Text. + var node = currentParent; + while (true) { + if (node.tag === HostComponent || node.tag === HostText) { + return node; + } else if (node.child) { + node.child.return = node; + node = node.child; + continue; + } + if (node === currentParent) { + return null; + } + while (!node.sibling) { + if (!node.return || node.return === currentParent) { + return null; + } + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + // Flow needs the return null here, but ESLint complains about it. + // eslint-disable-next-line no-unreachable + return null; +} + +function findCurrentHostFiberWithNoPortals(parent) { + var currentParent = findCurrentFiberUsingSlowPath(parent); + if (!currentParent) { + return null; + } + + // Next we'll drill down this component to find the first HostComponent/Text. + var node = currentParent; + while (true) { + if (node.tag === HostComponent || node.tag === HostText) { + return node; + } else if (node.child && node.tag !== HostPortal) { + node.child.return = node; + node = node.child; + continue; + } + if (node === currentParent) { + return null; + } + while (!node.sibling) { + if (!node.return || node.return === currentParent) { + return null; + } + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + // Flow needs the return null here, but ESLint complains about it. + // eslint-disable-next-line no-unreachable + return null; +} + +/** + * In the future, we should cleanup callbacks by cancelling them instead of + * using this. + */ +function mountSafeCallback(context, callback) { + return function() { + if (!callback) { + return undefined; + } + if (typeof context.__isMounted === "boolean") { + // TODO(gaearon): this is gross and should be removed. + // It is currently necessary because View uses createClass, + // and so any measure() calls on View (which are done by React + // DevTools) trigger the isMounted() deprecation warning. + if (!context.__isMounted) { + return undefined; + } + // The else branch is important so that we don't + // trigger the deprecation warning by calling isMounted. + } else if (typeof context.isMounted === "function") { + if (!context.isMounted()) { + return undefined; + } + } + return callback.apply(context, arguments); + }; +} + +function throwOnStylesProp(component, props) { + if (props.styles !== undefined) { + var owner = component._owner || null; + var name = component.constructor.displayName; + var msg = + "`styles` is not a supported property of `" + + name + + "`, did " + + "you mean `style` (singular)?"; + if (owner && owner.constructor && owner.constructor.displayName) { + msg += + "\n\nCheck the `" + + owner.constructor.displayName + + "` parent " + + " component."; + } + throw new Error(msg); + } +} + +function warnForStyleProps(props, validAttributes) { + for (var key in validAttributes.style) { + if (!(validAttributes[key] || props[key] === undefined)) { + console.error( + "You are setting the style `{ " + + key + + ": ... }` as a prop. You " + + "should nest it in a style object. " + + "E.g. `{ style: { " + + key + + ": ... } }`" + ); + } + } +} + +// Modules provided by RN: +var emptyObject$1 = {}; + +/** + * Create a payload that contains all the updates between two sets of props. + * + * These helpers are all encapsulated into a single module, because they use + * mutation as a performance optimization which leads to subtle shared + * dependencies between the code paths. To avoid this mutable state leaking + * across modules, I've kept them isolated to this module. + */ + +// Tracks removed keys +var removedKeys = null; +var removedKeyCount = 0; + +function defaultDiffer(prevProp, nextProp) { + if (typeof nextProp !== "object" || nextProp === null) { + // Scalars have already been checked for equality + return true; + } else { + // For objects and arrays, the default diffing algorithm is a deep compare + return deepDiffer(prevProp, nextProp); + } +} + +function restoreDeletedValuesInNestedArray( + updatePayload, + node, + validAttributes +) { + if (Array.isArray(node)) { + var i = node.length; + while (i-- && removedKeyCount > 0) { + restoreDeletedValuesInNestedArray( + updatePayload, + node[i], + validAttributes + ); + } + } else if (node && removedKeyCount > 0) { + var obj = node; + for (var propKey in removedKeys) { + if (!removedKeys[propKey]) { + continue; + } + var _nextProp = obj[propKey]; + if (_nextProp === undefined) { + continue; + } + + var attributeConfig = validAttributes[propKey]; + if (!attributeConfig) { + continue; // not a valid native prop + } + + if (typeof _nextProp === "function") { + _nextProp = true; + } + if (typeof _nextProp === "undefined") { + _nextProp = null; + } + + if (typeof attributeConfig !== "object") { + // case: !Object is the default case + updatePayload[propKey] = _nextProp; + } else if ( + typeof attributeConfig.diff === "function" || + typeof attributeConfig.process === "function" + ) { + // case: CustomAttributeConfiguration + var nextValue = + typeof attributeConfig.process === "function" + ? attributeConfig.process(_nextProp) + : _nextProp; + updatePayload[propKey] = nextValue; + } + removedKeys[propKey] = false; + removedKeyCount--; + } + } +} + +function diffNestedArrayProperty( + updatePayload, + prevArray, + nextArray, + validAttributes +) { + var minLength = + prevArray.length < nextArray.length ? prevArray.length : nextArray.length; + var i = void 0; + for (i = 0; i < minLength; i++) { + // Diff any items in the array in the forward direction. Repeated keys + // will be overwritten by later values. + updatePayload = diffNestedProperty( + updatePayload, + prevArray[i], + nextArray[i], + validAttributes + ); + } + for (; i < prevArray.length; i++) { + // Clear out all remaining properties. + updatePayload = clearNestedProperty( + updatePayload, + prevArray[i], + validAttributes + ); } for (; i < nextArray.length; i++) { // Add all remaining properties. @@ -3072,2355 +3335,2552 @@ function diff(prevProps, nextProps, validAttributes) { ); } -/** - * In the future, we should cleanup callbacks by cancelling them instead of - * using this. - */ -function mountSafeCallback(context, callback) { - return function() { - if (!callback) { - return undefined; - } - if (typeof context.__isMounted === "boolean") { - // TODO(gaearon): this is gross and should be removed. - // It is currently necessary because View uses createClass, - // and so any measure() calls on View (which are done by React - // DevTools) trigger the isMounted() deprecation warning. - if (!context.__isMounted) { - return undefined; - } - // The else branch is important so that we don't - // trigger the deprecation warning by calling isMounted. - } else if (typeof context.isMounted === "function") { - if (!context.isMounted()) { - return undefined; - } - } - return callback.apply(context, arguments); - }; -} +var hasNativePerformanceNow = + typeof performance === "object" && typeof performance.now === "function"; -function throwOnStylesProp(component, props) { - if (props.styles !== undefined) { - var owner = component._owner || null; - var name = component.constructor.displayName; - var msg = - "`styles` is not a supported property of `" + - name + - "`, did " + - "you mean `style` (singular)?"; - if (owner && owner.constructor && owner.constructor.displayName) { - msg += - "\n\nCheck the `" + - owner.constructor.displayName + - "` parent " + - " component."; +var now$1 = hasNativePerformanceNow + ? function() { + return performance.now(); } - throw new Error(msg); + : function() { + return Date.now(); + }; + +var scheduledCallback = null; +var frameDeadline = 0; + +var frameDeadlineObject = { + timeRemaining: function() { + return frameDeadline - now$1(); + }, + didTimeout: false +}; + +function setTimeoutCallback() { + // TODO (bvaughn) Hard-coded 5ms unblocks initial async testing. + // React API probably changing to boolean rather than time remaining. + // Longer-term plan is to rewrite this using shared memory, + // And just return the value of the bit as the boolean. + frameDeadline = now$1() + 5; + + var callback = scheduledCallback; + scheduledCallback = null; + if (callback !== null) { + callback(frameDeadlineObject); } } -function warnForStyleProps(props, validAttributes) { - for (var key in validAttributes.style) { - if (!(validAttributes[key] || props[key] === undefined)) { - console.error( - "You are setting the style `{ " + - key + - ": ... }` as a prop. You " + - "should nest it in a style object. " + - "E.g. `{ style: { " + - key + - ": ... } }`" - ); - } - } +// RN has a poor polyfill for requestIdleCallback so we aren't using it. +// This implementation is only intended for short-term use anyway. +// We also don't implement cancel functionality b'c Fiber doesn't currently need it. +function scheduleDeferredCallback$1(callback, options) { + // We assume only one callback is scheduled at a time b'c that's how Fiber works. + scheduledCallback = callback; + var timeoutId = setTimeout(setTimeoutCallback, 1); + return timeoutId; // Timeouts are always numbers on RN } -// Modules provided by RN: -var NativeMethodsMixin = function(findNodeHandle, findHostInstance) { - /** - * `NativeMethodsMixin` provides methods to access the underlying native - * component directly. This can be useful in cases when you want to focus - * a view or measure its on-screen dimensions, for example. - * - * The methods described here are available on most of the default components - * provided by React Native. Note, however, that they are *not* available on - * composite components that aren't directly backed by a native view. This will - * generally include most components that you define in your own app. For more - * information, see [Direct - * Manipulation](docs/direct-manipulation.html). - * - * Note the Flow $Exact<> syntax is required to support mixins. - * React createClass mixins can only be used with exact types. - */ - var NativeMethodsMixin = { - /** - * Determines the location on screen, width, and height of the given view and - * returns the values via an async callback. If successful, the callback will - * be called with the following arguments: - * - * - x - * - y - * - width - * - height - * - pageX - * - pageY - * - * Note that these measurements are not available until after the rendering - * has been completed in native. If you need the measurements as soon as - * possible, consider using the [`onLayout` - * prop](docs/view.html#onlayout) instead. - */ - measure: function(callback) { - UIManager.measure( - findNodeHandle(this), - mountSafeCallback(this, callback) - ); - }, +function cancelDeferredCallback$1(callbackID) { + scheduledCallback = null; + clearTimeout(callbackID); // Timeouts are always numbers on RN +} - /** - * Determines the location of the given view in the window and returns the - * values via an async callback. If the React root view is embedded in - * another native view, this will give you the absolute coordinates. If - * successful, the callback will be called with the following - * arguments: - * - * - x - * - y - * - width - * - height - * - * Note that these measurements are not available until after the rendering - * has been completed in native. - */ - measureInWindow: function(callback) { - UIManager.measureInWindow( - findNodeHandle(this), - mountSafeCallback(this, callback) - ); - }, +// Use to restore controlled state after a change event has fired. - /** - * Like [`measure()`](#measure), but measures the view relative an ancestor, - * specified as `relativeToNativeNode`. This means that the returned x, y - * are relative to the origin x, y of the ancestor view. - * - * As always, to obtain a native node handle for a component, you can use - * `findNodeHandle(component)`. - */ - measureLayout: function( - relativeToNativeNode, - onSuccess, - onFail /* currently unused */ - ) { - UIManager.measureLayout( - findNodeHandle(this), - relativeToNativeNode, - mountSafeCallback(this, onFail), - mountSafeCallback(this, onSuccess) - ); - }, +var fiberHostComponent = null; - /** - * This function sends props straight to native. They will not participate in - * future diff process - this means that if you do not include them in the - * next render, they will remain active (see [Direct - * Manipulation](docs/direct-manipulation.html)). - */ - setNativeProps: function(nativeProps) { - // Class components don't have viewConfig -> validateAttributes. - // Nor does it make sense to set native props on a non-native component. - // Instead, find the nearest host component and set props on it. - // Use findNodeHandle() rather than findNodeHandle() because - // We want the instance/wrapper (not the native tag). - var maybeInstance = void 0; +var restoreTarget = null; +var restoreQueue = null; - // Fiber errors if findNodeHandle is called for an umounted component. - // Tests using ReactTestRenderer will trigger this case indirectly. - // Mimicking stack behavior, we should silently ignore this case. - // TODO Fix ReactTestRenderer so we can remove this try/catch. - try { - maybeInstance = findHostInstance(this); - } catch (error) {} +function restoreStateOfTarget(target) { + // We perform this translation at the end of the event loop so that we + // always receive the correct fiber here + var internalInstance = getInstanceFromNode(target); + if (!internalInstance) { + // Unmounted + return; + } + invariant( + fiberHostComponent && + typeof fiberHostComponent.restoreControlledState === "function", + "Fiber needs to be injected to handle a fiber target for controlled " + + "events. This error is likely caused by a bug in React. Please file an issue." + ); + var props = getFiberCurrentPropsFromNode(internalInstance.stateNode); + fiberHostComponent.restoreControlledState( + internalInstance.stateNode, + internalInstance.type, + props + ); +} - // If there is no host component beneath this we should fail silently. - // This is not an error; it could mean a class component rendered null. - if (maybeInstance == null) { - return; - } +function needsStateRestore() { + return restoreTarget !== null || restoreQueue !== null; +} - var viewConfig = maybeInstance.viewConfig; +function restoreStateIfNeeded() { + if (!restoreTarget) { + return; + } + var target = restoreTarget; + var queuedTargets = restoreQueue; + restoreTarget = null; + restoreQueue = null; - { - warnForStyleProps(nativeProps, viewConfig.validAttributes); - } + restoreStateOfTarget(target); + if (queuedTargets) { + for (var i = 0; i < queuedTargets.length; i++) { + restoreStateOfTarget(queuedTargets[i]); + } + } +} - var updatePayload = create(nativeProps, viewConfig.validAttributes); +// Used as a way to call batchedUpdates when we don't have a reference to +// the renderer. Such as when we're dispatching events or if third party +// libraries need to call batchedUpdates. Eventually, this API will go away when +// everything is batched by default. We'll then have a similar API to opt-out of +// scheduled work and instead do synchronous work. - // Avoid the overhead of bridge calls if there's no update. - // This is an expensive no-op for Android, and causes an unnecessary - // view invalidation for certain components (eg RCTTextInput) on iOS. - if (updatePayload != null) { - UIManager.updateView( - maybeInstance._nativeTag, - viewConfig.uiViewClassName, - updatePayload - ); - } - }, - - /** - * Requests focus for the given input or view. The exact behavior triggered - * will depend on the platform and type of view. - */ - focus: function() { - TextInputState.focusTextInput(findNodeHandle(this)); - }, +// Defaults +var _batchedUpdates = function(fn, bookkeeping) { + return fn(bookkeeping); +}; +var _interactiveUpdates = function(fn, a, b) { + return fn(a, b); +}; +var _flushInteractiveUpdates = function() {}; - /** - * Removes focus from an input or view. This is the opposite of `focus()`. - */ - blur: function() { - TextInputState.blurTextInput(findNodeHandle(this)); +var isBatching = false; +function batchedUpdates(fn, bookkeeping) { + if (isBatching) { + // If we are currently inside another batch, we need to wait until it + // fully completes before restoring state. + return fn(bookkeeping); + } + isBatching = true; + try { + return _batchedUpdates(fn, bookkeeping); + } finally { + // Here we wait until all updates have propagated, which is important + // when using controlled components within layers: + // https://github.com/facebook/react/issues/1698 + // Then we restore state of any controlled component. + isBatching = false; + var controlledComponentsHavePendingUpdates = needsStateRestore(); + if (controlledComponentsHavePendingUpdates) { + // If a controlled event was fired, we may need to restore the state of + // the DOM node back to the controlled value. This is necessary when React + // bails out of the update without touching the DOM. + _flushInteractiveUpdates(); + restoreStateIfNeeded(); } - }; - - { - // hide this from Flow since we can't define these properties outside of - // true without actually implementing them (setting them to undefined - // isn't allowed by ReactClass) - var NativeMethodsMixin_DEV = NativeMethodsMixin; - invariant( - !NativeMethodsMixin_DEV.componentWillMount && - !NativeMethodsMixin_DEV.componentWillReceiveProps && - !NativeMethodsMixin_DEV.UNSAFE_componentWillMount && - !NativeMethodsMixin_DEV.UNSAFE_componentWillReceiveProps, - "Do not override existing functions." - ); - // TODO (bvaughn) Remove cWM and cWRP in a future version of React Native, - // Once these lifecycles have been remove from the reconciler. - NativeMethodsMixin_DEV.componentWillMount = function() { - throwOnStylesProp(this, this.props); - }; - NativeMethodsMixin_DEV.componentWillReceiveProps = function(newProps) { - throwOnStylesProp(this, newProps); - }; - NativeMethodsMixin_DEV.UNSAFE_componentWillMount = function() { - throwOnStylesProp(this, this.props); - }; - NativeMethodsMixin_DEV.UNSAFE_componentWillReceiveProps = function( - newProps - ) { - throwOnStylesProp(this, newProps); - }; - - // React may warn about cWM/cWRP/cWU methods being deprecated. - // Add a flag to suppress these warnings for this special case. - // TODO (bvaughn) Remove this flag once the above methods have been removed. - NativeMethodsMixin_DEV.componentWillMount.__suppressDeprecationWarning = true; - NativeMethodsMixin_DEV.componentWillReceiveProps.__suppressDeprecationWarning = true; } +} - return NativeMethodsMixin; +var injection$2 = { + injectRenderer: function(renderer) { + _batchedUpdates = renderer.batchedUpdates; + _interactiveUpdates = renderer.interactiveUpdates; + _flushInteractiveUpdates = renderer.flushInteractiveUpdates; + } }; -function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } +function dispatchEvent(target, topLevelType, nativeEvent) { + var targetFiber = target; + batchedUpdates(function() { + runExtractedEventsInBatch( + topLevelType, + targetFiber, + nativeEvent, + nativeEvent.target + ); + }); + // React Native doesn't use ReactControlledComponent but if it did, here's + // where it would do it. } -function _possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError( - "this hasn't been initialised - super() hasn't been called" - ); - } - return call && (typeof call === "object" || typeof call === "function") - ? call - : self; +// Renderers that don't support mutation +// can re-export everything from this module. + +function shim() { + invariant( + false, + "The current renderer does not support mutation. " + + "This error is likely caused by a bug in React. " + + "Please file an issue." + ); } -function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError( - "Super expression must either be null or a function, not " + - typeof superClass - ); +// Mutation (when unsupported) +var supportsMutation = false; +var appendChild$1 = shim; +var appendChildToContainer = shim; +var commitTextUpdate = shim; +var commitMount = shim; +var commitUpdate = shim; +var insertBefore = shim; +var insertInContainerBefore = shim; +var removeChild = shim; +var removeChildFromContainer = shim; +var resetTextContent = shim; + +// Renderers that don't support hydration +// can re-export everything from this module. + +function shim$1() { + invariant( + false, + "The current renderer does not support hyration. " + + "This error is likely caused by a bug in React. " + + "Please file an issue." + ); +} + +// Hydration (when unsupported) +var supportsHydration = false; +var canHydrateInstance = shim$1; +var canHydrateTextInstance = shim$1; +var getNextHydratableSibling = shim$1; +var getFirstHydratableChild = shim$1; +var hydrateInstance = shim$1; +var hydrateTextInstance = shim$1; +var didNotMatchHydratedContainerTextInstance = shim$1; +var didNotMatchHydratedTextInstance = shim$1; +var didNotHydrateContainerInstance = shim$1; +var didNotHydrateInstance = shim$1; +var didNotFindHydratableContainerInstance = shim$1; +var didNotFindHydratableContainerTextInstance = shim$1; +var didNotFindHydratableInstance = shim$1; +var didNotFindHydratableTextInstance = shim$1; + +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); } - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) - Object.setPrototypeOf - ? Object.setPrototypeOf(subClass, superClass) - : (subClass.__proto__ = superClass); } // Modules provided by RN: -var ReactNativeComponent = function(findNodeHandle, findHostInstance) { +// Counter for uniquely identifying views. +// % 10 === 1 means it is a rootTag. +// % 2 === 0 means it is a Fabric tag. +// This means that they never overlap. +var nextReactTag = 2; + +// TODO: Remove this conditional once all changes have propagated. +if (FabricUIManager.registerEventHandler) { /** - * Superclass that provides methods to access the underlying native component. - * This can be useful when you want to focus a view or measure its dimensions. - * - * Methods implemented by this class are available on most default components - * provided by React Native. However, they are *not* available on composite - * components that are not directly backed by a native view. For more - * information, see [Direct Manipulation](docs/direct-manipulation.html). - * - * @abstract + * Register the event emitter with the native bridge */ - var ReactNativeComponent = (function(_React$Component) { - _inherits(ReactNativeComponent, _React$Component); + FabricUIManager.registerEventHandler(dispatchEvent); +} - function ReactNativeComponent() { - _classCallCheck(this, ReactNativeComponent); +/** + * This is used for refs on host components. + */ - return _possibleConstructorReturn( - this, - _React$Component.apply(this, arguments) - ); - } +var ReactFabricHostComponent = (function() { + function ReactFabricHostComponent(tag, viewConfig, props) { + _classCallCheck(this, ReactFabricHostComponent); - /** - * Removes focus. This is the opposite of `focus()`. - */ + this._nativeTag = tag; + this.viewConfig = viewConfig; + this.currentProps = props; + } - /** - * Due to bugs in Flow's handling of React.createClass, some fields already - * declared in the base class need to be redeclared below. - */ - ReactNativeComponent.prototype.blur = function blur() { - TextInputState.blurTextInput(findNodeHandle(this)); - }; + ReactFabricHostComponent.prototype.blur = function blur() { + TextInputState.blurTextInput(this._nativeTag); + }; - /** - * Requests focus. The exact behavior depends on the platform and view. - */ + ReactFabricHostComponent.prototype.focus = function focus() { + TextInputState.focusTextInput(this._nativeTag); + }; - ReactNativeComponent.prototype.focus = function focus() { - TextInputState.focusTextInput(findNodeHandle(this)); - }; + ReactFabricHostComponent.prototype.measure = function measure(callback) { + UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); + }; - /** - * Measures the on-screen location and dimensions. If successful, the callback - * will be called asynchronously with the following arguments: - * - * - x - * - y - * - width - * - height - * - pageX - * - pageY - * - * These values are not available until after natives rendering completes. If - * you need the measurements as soon as possible, consider using the - * [`onLayout` prop](docs/view.html#onlayout) instead. - */ + ReactFabricHostComponent.prototype.measureInWindow = function measureInWindow( + callback + ) { + UIManager.measureInWindow( + this._nativeTag, + mountSafeCallback(this, callback) + ); + }; - ReactNativeComponent.prototype.measure = function measure(callback) { - UIManager.measure( - findNodeHandle(this), - mountSafeCallback(this, callback) - ); - }; + ReactFabricHostComponent.prototype.measureLayout = function measureLayout( + relativeToNativeNode, + onSuccess, + onFail /* currently unused */ + ) { + UIManager.measureLayout( + this._nativeTag, + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }; - /** - * Measures the on-screen location and dimensions. Even if the React Native - * root view is embedded within another native view, this method will give you - * the absolute coordinates measured from the window. If successful, the - * callback will be called asynchronously with the following arguments: - * - * - x - * - y - * - width - * - height - * - * These values are not available until after natives rendering completes. - */ - - ReactNativeComponent.prototype.measureInWindow = function measureInWindow( - callback - ) { - UIManager.measureInWindow( - findNodeHandle(this), - mountSafeCallback(this, callback) - ); - }; + ReactFabricHostComponent.prototype.setNativeProps = function setNativeProps( + nativeProps + ) { + { + warnForStyleProps(nativeProps, this.viewConfig.validAttributes); + } - /** - * Similar to [`measure()`](#measure), but the resulting location will be - * relative to the supplied ancestor's location. - * - * Obtain a native node handle with `ReactNative.findNodeHandle(component)`. - */ + var updatePayload = create(nativeProps, this.viewConfig.validAttributes); - ReactNativeComponent.prototype.measureLayout = function measureLayout( - relativeToNativeNode, - onSuccess, - onFail /* currently unused */ - ) { - UIManager.measureLayout( - findNodeHandle(this), - relativeToNativeNode, - mountSafeCallback(this, onFail), - mountSafeCallback(this, onSuccess) + // Avoid the overhead of bridge calls if there's no update. + // This is an expensive no-op for Android, and causes an unnecessary + // view invalidation for certain components (eg RCTTextInput) on iOS. + if (updatePayload != null) { + UIManager.updateView( + this._nativeTag, + this.viewConfig.uiViewClassName, + updatePayload ); - }; + } + }; - /** - * This function sends props straight to native. They will not participate in - * future diff process - this means that if you do not include them in the - * next render, they will remain active (see [Direct - * Manipulation](docs/direct-manipulation.html)). - */ + return ReactFabricHostComponent; +})(); - ReactNativeComponent.prototype.setNativeProps = function setNativeProps( - nativeProps - ) { - // Class components don't have viewConfig -> validateAttributes. - // Nor does it make sense to set native props on a non-native component. - // Instead, find the nearest host component and set props on it. - // Use findNodeHandle() rather than ReactNative.findNodeHandle() because - // We want the instance/wrapper (not the native tag). - var maybeInstance = void 0; +function appendInitialChild(parentInstance, child) { + FabricUIManager.appendChild(parentInstance.node, child.node); +} - // Fiber errors if findNodeHandle is called for an umounted component. - // Tests using ReactTestRenderer will trigger this case indirectly. - // Mimicking stack behavior, we should silently ignore this case. - // TODO Fix ReactTestRenderer so we can remove this try/catch. - try { - maybeInstance = findHostInstance(this); - } catch (error) {} +function createInstance( + type, + props, + rootContainerInstance, + hostContext, + internalInstanceHandle +) { + var tag = nextReactTag; + nextReactTag += 2; - // If there is no host component beneath this we should fail silently. - // This is not an error; it could mean a class component rendered null. - if (maybeInstance == null) { - return; + var viewConfig = ReactNativeViewConfigRegistry.get(type); + + { + for (var key in viewConfig.validAttributes) { + if (props.hasOwnProperty(key)) { + deepFreezeAndThrowOnMutationInDev(props[key]); } + } + } - var viewConfig = - maybeInstance.viewConfig || maybeInstance.canonical.viewConfig; + invariant( + type !== "RCTView" || !hostContext.isInAParentText, + "Nesting of within is not currently supported." + ); - var updatePayload = create(nativeProps, viewConfig.validAttributes); + var updatePayload = create(props, viewConfig.validAttributes); - // Avoid the overhead of bridge calls if there's no update. - // This is an expensive no-op for Android, and causes an unnecessary - // view invalidation for certain components (eg RCTTextInput) on iOS. - if (updatePayload != null) { - UIManager.updateView( - maybeInstance._nativeTag, - viewConfig.uiViewClassName, - updatePayload - ); - } - }; + var node = FabricUIManager.createNode( + tag, // reactTag + viewConfig.uiViewClassName, // viewName + rootContainerInstance, // rootTag + updatePayload, // props + internalInstanceHandle // internalInstanceHandle + ); - return ReactNativeComponent; - })(React.Component); + var component = new ReactFabricHostComponent(tag, viewConfig, props); - // eslint-disable-next-line no-unused-expressions + return { + node: node, + canonical: component + }; +} - return ReactNativeComponent; -}; +function createTextInstance( + text, + rootContainerInstance, + hostContext, + internalInstanceHandle +) { + invariant( + hostContext.isInAParentText, + "Text strings must be rendered within a component." + ); -/** - * `ReactInstanceMap` maintains a mapping from a public facing stateful - * instance (key) and the internal representation (value). This allows public - * methods to accept the user facing instance as an argument and map them back - * to internal methods. - * - * Note that this module is currently shared and assumed to be stateless. - * If this becomes an actual Map, that will break. - */ + var tag = nextReactTag; + nextReactTag += 2; -/** - * This API should be called `delete` but we'd have to make sure to always - * transform these to strings for IE support. When this transform is fully - * supported we can rename it. - */ + var node = FabricUIManager.createNode( + tag, // reactTag + "RCTRawText", // viewName + rootContainerInstance, // rootTag + { text: text }, // props + internalInstanceHandle // instance handle + ); -function get$1(key) { - return key._reactInternalFiber; + return { + node: node + }; } -function set(key, value) { - key._reactInternalFiber = value; +function finalizeInitialChildren( + parentInstance, + type, + props, + rootContainerInstance, + hostContext +) { + return false; } -var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; - -var ReactCurrentOwner = ReactInternals.ReactCurrentOwner; -var ReactDebugCurrentFrame = ReactInternals.ReactDebugCurrentFrame; +function getRootHostContext(rootContainerInstance) { + return { isInAParentText: false }; +} -function getComponentName(fiber) { - var type = fiber.type; +function getChildHostContext(parentHostContext, type, rootContainerInstance) { + var prevIsInAParentText = parentHostContext.isInAParentText; + var isInAParentText = + type === "AndroidTextInput" || // Android + type === "RCTMultilineTextInputView" || // iOS + type === "RCTSinglelineTextInputView" || // iOS + type === "RCTText" || + type === "RCTVirtualText"; - if (typeof type === "function") { - return type.displayName || type.name; - } - if (typeof type === "string") { - return type; - } - switch (type) { - case REACT_ASYNC_MODE_TYPE: - return "AsyncMode"; - case REACT_CONTEXT_TYPE: - return "Context.Consumer"; - case REACT_FRAGMENT_TYPE: - return "ReactFragment"; - case REACT_PORTAL_TYPE: - return "ReactPortal"; - case REACT_PROFILER_TYPE: - return "Profiler(" + fiber.pendingProps.id + ")"; - case REACT_PROVIDER_TYPE: - return "Context.Provider"; - case REACT_STRICT_MODE_TYPE: - return "StrictMode"; - } - if (typeof type === "object" && type !== null) { - switch (type.$$typeof) { - case REACT_FORWARD_REF_TYPE: - var functionName = type.render.displayName || type.render.name || ""; - return functionName !== "" - ? "ForwardRef(" + functionName + ")" - : "ForwardRef"; - } + if (prevIsInAParentText !== isInAParentText) { + return { isInAParentText: isInAParentText }; + } else { + return parentHostContext; } - return null; } -// Don't change these two values. They're used by React Dev Tools. -var NoEffect = /* */ 0; -var PerformedWork = /* */ 1; +function getPublicInstance(instance) { + return instance.canonical; +} -// You can change the rest (and add more). -var Placement = /* */ 2; -var Update = /* */ 4; -var PlacementAndUpdate = /* */ 6; -var Deletion = /* */ 8; -var ContentReset = /* */ 16; -var Callback = /* */ 32; -var DidCapture = /* */ 64; -var Ref = /* */ 128; -var Snapshot = /* */ 256; +function prepareForCommit(containerInfo) { + // Noop +} -// Union of all host effects -var HostEffectMask = /* */ 511; +function prepareUpdate( + instance, + type, + oldProps, + newProps, + rootContainerInstance, + hostContext +) { + var viewConfig = instance.canonical.viewConfig; + var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); + // TODO: If the event handlers have changed, we need to update the current props + // in the commit phase but there is no host config hook to do it yet. + // So instead we hack it by updating it in the render phase. + instance.canonical.currentProps = newProps; + return updatePayload; +} -var Incomplete = /* */ 512; -var ShouldCapture = /* */ 1024; +function resetAfterCommit(containerInfo) { + // Noop +} -var MOUNTING = 1; -var MOUNTED = 2; -var UNMOUNTED = 3; +function shouldDeprioritizeSubtree(type, props) { + return false; +} -function isFiberMountedImpl(fiber) { - var node = fiber; - if (!fiber.alternate) { - // If there is no alternate, this might be a new tree that isn't inserted - // yet. If it is, then it will have a pending insertion effect on it. - if ((node.effectTag & Placement) !== NoEffect) { - return MOUNTING; - } - while (node.return) { - node = node.return; - if ((node.effectTag & Placement) !== NoEffect) { - return MOUNTING; - } +function shouldSetTextContent(type, props) { + // TODO (bvaughn) Revisit this decision. + // Always returning false simplifies the createInstance() implementation, + // But creates an additional child Fiber for raw text children. + // No additional native views are created though. + // It's not clear to me which is better so I'm deferring for now. + // More context @ github.com/facebook/react/pull/8560#discussion_r92111303 + return false; +} + +// The Fabric renderer is secondary to the existing React Native renderer. +var isPrimaryRenderer = false; +var now = now$1; +var scheduleDeferredCallback = scheduleDeferredCallback$1; +var cancelDeferredCallback = cancelDeferredCallback$1; + +// ------------------- +// Persistence +// ------------------- + +var supportsPersistence = true; + +function cloneInstance( + instance, + updatePayload, + type, + oldProps, + newProps, + internalInstanceHandle, + keepChildren, + recyclableInstance +) { + var node = instance.node; + var clone = void 0; + if (keepChildren) { + if (updatePayload !== null) { + clone = FabricUIManager.cloneNodeWithNewProps( + node, + updatePayload, + internalInstanceHandle + ); + } else { + clone = FabricUIManager.cloneNode(node, internalInstanceHandle); } } else { - while (node.return) { - node = node.return; + if (updatePayload !== null) { + clone = FabricUIManager.cloneNodeWithNewChildrenAndProps( + node, + updatePayload, + internalInstanceHandle + ); + } else { + clone = FabricUIManager.cloneNodeWithNewChildren( + node, + internalInstanceHandle + ); } } - if (node.tag === HostRoot) { - // TODO: Check if this was a nested HostRoot when used with - // renderContainerIntoSubtree. - return MOUNTED; - } - // If we didn't hit the root, that means that we're in an disconnected tree - // that has been unmounted. - return UNMOUNTED; + return { + node: clone, + canonical: instance.canonical + }; } -function isFiberMounted(fiber) { - return isFiberMountedImpl(fiber) === MOUNTED; +function createContainerChildSet(container) { + return FabricUIManager.createChildSet(container); } -function isMounted(component) { - { - var owner = ReactCurrentOwner.current; - 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; - instance._warnedAboutRefsInRender = true; - } - } +function appendChildToContainerChildSet(childSet, child) { + FabricUIManager.appendChildToSet(childSet, child.node); +} - var fiber = get$1(component); - if (!fiber) { - return false; - } - return isFiberMountedImpl(fiber) === MOUNTED; +function finalizeContainerChildren(container, newChildren) { + FabricUIManager.completeRoot(container, newChildren); } -function assertIsMounted(fiber) { - invariant( - isFiberMountedImpl(fiber) === MOUNTED, - "Unable to find node on an unmounted component." +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 ""; + } } -function findCurrentFiberUsingSlowPath(fiber) { - var alternate = fiber.alternate; - if (!alternate) { - // If there is no alternate, then we only need to check if it is mounted. - var state = isFiberMountedImpl(fiber); - invariant( - state !== UNMOUNTED, - "Unable to find node on an unmounted component." - ); - if (state === MOUNTING) { +// 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; } - return fiber; - } - // If we have two possible branches, we'll walk backwards up to the root - // to see what path the root points to. On the way we may hit one of the - // special cases and we'll deal with them. - var a = fiber; - var b = alternate; - while (true) { - var parentA = a.return; - var parentB = parentA ? parentA.alternate : null; - if (!parentA || !parentB) { - // We're at the root. - break; + var owner = fiber._debugOwner; + if (owner !== null && typeof owner !== "undefined") { + return getComponentName(owner); } + } + return null; +} - // If both copies of the parent fiber point to the same child, we can - // assume that the child is current. This happens when we bailout on low - // priority: the bailed out fiber's child reuses the current child. - if (parentA.child === parentB.child) { - var child = parentA.child; - while (child) { - if (child === a) { - // We've determined that A is the current branch. - assertIsMounted(parentA); - return fiber; - } - if (child === b) { - // We've determined that B is the current branch. - assertIsMounted(parentA); - return alternate; - } - child = child.sibling; - } - // We should never have an alternate for any mounting node. So the only - // way this could possibly happen is if this was unmounted, if at all. - invariant(false, "Unable to find node on an unmounted component."); +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; +} - if (a.return !== b.return) { - // The return pointer of A and the return pointer of B point to different - // fibers. We assume that return pointers never criss-cross, so A must - // belong to the child set of A.return, and B must belong to the child - // set of B.return. - a = parentA; - b = parentB; - } else { - // The return pointers point to the same fiber. We'll have to use the - // default, slow path: scan the child sets of each parent alternate to see - // which child belongs to which set. - // - // Search parent A's child set - var didFindChild = false; - var _child = parentA.child; - while (_child) { - if (_child === a) { - didFindChild = true; - a = parentA; - b = parentB; - break; - } - if (_child === b) { - didFindChild = true; - b = parentA; - a = parentB; - break; - } - _child = _child.sibling; - } - if (!didFindChild) { - // Search parent B's child set - _child = parentB.child; - while (_child) { - if (_child === a) { - didFindChild = true; - a = parentB; - b = parentA; - break; - } - if (_child === b) { - didFindChild = true; - b = parentB; - a = parentA; - break; - } - _child = _child.sibling; - } - invariant( - didFindChild, - "Child was not found in either parent set. This indicates a bug " + - "in React related to the return pointer. Please file an issue." - ); - } - } +function resetCurrentFiber() { + ReactDebugCurrentFrame.getCurrentStack = null; + ReactDebugCurrentFiber.current = null; + ReactDebugCurrentFiber.phase = null; +} - invariant( - a.alternate === b, - "Return fibers should always be each others' alternates. " + - "This error is likely caused by a bug in React. Please file an issue." - ); +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 enableSuspense = false; +var warnAboutDeprecatedLifecycles = false; +var warnAboutLegacyContextAPI = false; +var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; +var enableProfilerTimer = 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; } - // If the root is not a host container, we're in a disconnected tree. I.e. - // unmounted. - invariant( - a.tag === HostRoot, - "Unable to find node on an unmounted component." - ); - if (a.stateNode.current === a) { - // We've determined that A is the current branch. - return fiber; +}; + +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; } - // Otherwise B has to be current branch. - return alternate; -} + labelsInCurrentCommit.add(label); -function findCurrentHostFiber(parent) { - var currentParent = findCurrentFiberUsingSlowPath(parent); - if (!currentParent) { - return null; + 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 Fragment: + case ContextProvider: + case ContextConsumer: + case Mode: + 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); } +}; - // Next we'll drill down this component to find the first HostComponent/Text. - var node = currentParent; - while (true) { - if (node.tag === HostComponent || node.tag === HostText) { - return node; - } else if (node.child) { - node.child.return = node; - node = node.child; - continue; - } - if (node === currentParent) { - return null; - } - while (!node.sibling) { - if (!node.return || node.return === currentParent) { - return null; - } - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; +var resumeTimers = function() { + // Resumes all measurements that were active during the last deferred loop. + if (currentFiber !== null) { + resumeTimersRecursively(currentFiber); } - // Flow needs the return null here, but ESLint complains about it. - // eslint-disable-next-line no-unreachable - return null; -} +}; -function findCurrentHostFiberWithNoPortals(parent) { - var currentParent = findCurrentFiberUsingSlowPath(parent); - if (!currentParent) { - return null; +function recordEffect() { + if (enableUserTimingAPI) { + effectCountInCurrentCommit++; } +} - // Next we'll drill down this component to find the first HostComponent/Text. - var node = currentParent; - while (true) { - if (node.tag === HostComponent || node.tag === HostText) { - return node; - } else if (node.child && node.tag !== HostPortal) { - node.child.return = node; - node = node.child; - continue; - } - if (node === currentParent) { - return null; +function recordScheduleUpdate() { + if (enableUserTimingAPI) { + if (isCommitting) { + hasScheduledUpdateInCurrentCommit = true; } - while (!node.sibling) { - if (!node.return || node.return === currentParent) { - return null; - } - node = node.return; + if ( + currentPhase !== null && + currentPhase !== "componentWillMount" && + currentPhase !== "componentWillReceiveProps" + ) { + hasScheduledUpdateInCurrentPhase = true; } - node.sibling.return = node.return; - node = node.sibling; } - // Flow needs the return null here, but ESLint complains about it. - // eslint-disable-next-line no-unreachable - return null; } -var debugRenderPhaseSideEffects = false; -var debugRenderPhaseSideEffectsForStrictMode = false; -var enableUserTimingAPI = true; -var enableGetDerivedStateFromCatch = false; -var enableSuspense = false; -var warnAboutDeprecatedLifecycles = false; -var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; -var enableProfilerTimer = false; - -// React Fabric uses persistent reconciler. -var enableMutatingReconciler = false; -var enableNoopReconciler = false; -var enablePersistentReconciler = true; -var fireGetDerivedStateFromPropsOnStateUpdates = true; - -// Only used in www builds. - -// Max 31 bit integer. The max integer size in V8 for 32-bit systems. -// Math.pow(2, 30) - 1 -// 0b111111111111111111111111111111 -var MAX_SIGNED_31_BIT_INT = 1073741823; - -// TODO: Use an opaque type once ESLint et al support the syntax - -var NoWork = 0; -var Sync = 1; -var Never = MAX_SIGNED_31_BIT_INT; - -var UNIT_SIZE = 10; -var MAGIC_NUMBER_OFFSET = 2; - -// 1 unit of expiration time represents 10ms. -function msToExpirationTime(ms) { - // Always add an offset so that we don't clash with the magic number for NoWork. - return ((ms / UNIT_SIZE) | 0) + MAGIC_NUMBER_OFFSET; +function startRequestCallbackTimer() { + if (enableUserTimingAPI) { + if (supportsUserTiming && !isWaitingForCallback) { + isWaitingForCallback = true; + beginMark("(Waiting for async callback...)"); + } + } } -function expirationTimeToMs(expirationTime) { - return (expirationTime - MAGIC_NUMBER_OFFSET) * UNIT_SIZE; +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 ceiling(num, precision) { - return (((num / precision) | 0) + 1) * precision; +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 computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) { - return ( - MAGIC_NUMBER_OFFSET + - ceiling( - currentTime - MAGIC_NUMBER_OFFSET + expirationInMs / UNIT_SIZE, - bucketSizeMs / UNIT_SIZE - ) - ); +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); + } } -var NoContext = 0; -var AsyncMode = 1; -var StrictMode = 2; -var ProfileMode = 4; - -var hasBadMapPolyfill = void 0; - -{ - hasBadMapPolyfill = false; - try { - var nonExtensibleObject = Object.preventExtensions({}); - var testMap = new Map([[nonExtensibleObject, null]]); - var testSet = new Set([nonExtensibleObject]); - // This is necessary for Rollup to not consider these unused. - // https://github.com/rollup/rollup/issues/1771 - // TODO: we can remove these if Rollup fixes the bug. - testMap.set(0, 0); - testSet.add(0); - } catch (e) { - // TODO: Consider warning about bad polyfills - hasBadMapPolyfill = true; +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); } } -// A Fiber is work on a Component that needs to be done or was done. There can -// be more than one per component. - -var debugCounter = void 0; - -{ - debugCounter = 1; +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 FiberNode(tag, pendingProps, key, mode) { - // Instance - this.tag = tag; - this.key = key; - this.type = null; - this.stateNode = null; - - // Fiber - this.return = null; - this.child = null; - this.sibling = null; - this.index = 0; - - this.ref = null; - - this.pendingProps = pendingProps; - this.memoizedProps = null; - this.updateQueue = null; - this.memoizedState = null; - - this.mode = mode; - - // Effects - this.effectTag = NoEffect; - this.nextEffect = null; - - this.firstEffect = null; - this.lastEffect = null; - - this.expirationTime = NoWork; - - this.alternate = null; - - if (enableProfilerTimer) { - this.selfBaseTime = 0; - this.treeBaseTime = 0; +function startPhaseTimer(fiber, phase) { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + clearPendingPhaseMeasurement(); + if (!beginFiberMark(fiber, phase)) { + return; + } + currentPhaseFiber = fiber; + currentPhase = phase; } +} - { - this._debugID = debugCounter++; - this._debugSource = null; - this._debugOwner = null; - this._debugIsCurrentlyTiming = false; - if (!hasBadMapPolyfill && typeof Object.preventExtensions === "function") { - Object.preventExtensions(this); +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; } } -// This is a constructor function, rather than a POJO constructor, still -// please ensure we do the following: -// 1) Nobody should add any instance methods on this. Instance methods can be -// more difficult to predict when they get optimized and they are almost -// never inlined properly in static compilers. -// 2) Nobody should rely on `instanceof Fiber` for type testing. We should -// always know when it is a fiber. -// 3) We might want to experiment with using numeric keys since they are easier -// to optimize in a non-JIT environment. -// 4) We can easily go from a constructor to a createFiber object literal if that -// is faster. -// 5) It should be easy to port this to a C struct and keep a C implementation -// compatible. -var createFiber = function(tag, pendingProps, key, mode) { - // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors - return new FiberNode(tag, pendingProps, key, mode); -}; - -function shouldConstruct(Component) { - return !!(Component.prototype && Component.prototype.isReactComponent); +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(); + } } -// This is used to create an alternate fiber to do work on. -function createWorkInProgress(current, pendingProps, expirationTime) { - var workInProgress = current.alternate; - if (workInProgress === null) { - // We use a double buffering pooling technique because we know that we'll - // only ever need at most two versions of a tree. We pool the "other" unused - // node that we're free to reuse. This is lazily created to avoid allocating - // extra objects for things that are never updated. It also allow us to - // reclaim the extra memory if needed. - workInProgress = createFiber( - current.tag, - pendingProps, - current.key, - current.mode - ); - workInProgress.type = current.type; - workInProgress.stateNode = current.stateNode; - - { - // DEV-only fields - workInProgress._debugID = current._debugID; - workInProgress._debugSource = current._debugSource; - workInProgress._debugOwner = current._debugOwner; +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); + } +} - workInProgress.alternate = current; - current.alternate = workInProgress; - } else { - workInProgress.pendingProps = pendingProps; - - // We already have an alternate. - // Reset the effect tag. - workInProgress.effectTag = NoEffect; - - // The effect list is no longer valid. - workInProgress.nextEffect = null; - workInProgress.firstEffect = null; - workInProgress.lastEffect = null; +function startCommitTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + isCommitting = true; + hasScheduledUpdateInCurrentCommit = false; + labelsInCurrentCommit.clear(); + beginMark("(Committing Changes)"); } +} - workInProgress.expirationTime = expirationTime; +function stopCommitTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } - workInProgress.child = current.child; - workInProgress.memoizedProps = current.memoizedProps; - workInProgress.memoizedState = current.memoizedState; - workInProgress.updateQueue = current.updateQueue; + 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(); - // These will be overridden during the parent's reconciliation - workInProgress.sibling = current.sibling; - workInProgress.index = current.index; - workInProgress.ref = current.ref; + endMark("(Committing Changes)", "(Committing Changes)", warning$$1); + } +} - if (enableProfilerTimer) { - workInProgress.selfBaseTime = current.selfBaseTime; - workInProgress.treeBaseTime = current.treeBaseTime; +function startCommitSnapshotEffectsTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + effectCountInCurrentCommit = 0; + beginMark("(Committing Snapshot Effects)"); } +} - return workInProgress; +function stopCommitSnapshotEffectsTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + var count = effectCountInCurrentCommit; + effectCountInCurrentCommit = 0; + endMark( + "(Committing Snapshot Effects: " + count + " Total)", + "(Committing Snapshot Effects)", + null + ); + } } -function createHostRootFiber(isAsync) { - var mode = isAsync ? AsyncMode | StrictMode : NoContext; - return createFiber(HostRoot, null, null, mode); +function startCommitHostEffectsTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + effectCountInCurrentCommit = 0; + beginMark("(Committing Host Effects)"); + } } -function createFiberFromElement(element, mode, expirationTime) { - var owner = null; - { - owner = element._owner; +function stopCommitHostEffectsTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + var count = effectCountInCurrentCommit; + effectCountInCurrentCommit = 0; + endMark( + "(Committing Host Effects: " + count + " Total)", + "(Committing Host Effects)", + null + ); } +} - var fiber = void 0; - var type = element.type; - var key = element.key; - var pendingProps = element.props; +function startCommitLifeCyclesTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; + } + effectCountInCurrentCommit = 0; + beginMark("(Calling Lifecycle Methods)"); + } +} - var fiberTag = void 0; - if (typeof type === "function") { - fiberTag = shouldConstruct(type) ? ClassComponent : IndeterminateComponent; - } else if (typeof type === "string") { - fiberTag = HostComponent; - } else { - switch (type) { - case REACT_FRAGMENT_TYPE: - return createFiberFromFragment( - pendingProps.children, - mode, - expirationTime, - key - ); - case REACT_ASYNC_MODE_TYPE: - fiberTag = Mode; - mode |= AsyncMode | StrictMode; - break; - case REACT_STRICT_MODE_TYPE: - fiberTag = Mode; - mode |= StrictMode; - break; - case REACT_PROFILER_TYPE: - return createFiberFromProfiler(pendingProps, mode, expirationTime, key); - case REACT_TIMEOUT_TYPE: - fiberTag = TimeoutComponent; - // Suspense does not require async, but its children should be strict - // mode compatible. - mode |= StrictMode; - break; - default: - fiberTag = getFiberTagFromObjectType(type, owner); - break; +function stopCommitLifeCyclesTimer() { + if (enableUserTimingAPI) { + if (!supportsUserTiming) { + return; } + var count = effectCountInCurrentCommit; + effectCountInCurrentCommit = 0; + endMark( + "(Calling Lifecycle Methods: " + count + " Total)", + "(Calling Lifecycle Methods)", + null + ); } +} - fiber = createFiber(fiberTag, pendingProps, key, mode); - fiber.type = type; - fiber.expirationTime = expirationTime; +var valueStack = []; - { - fiber._debugSource = element._source; - fiber._debugOwner = element._owner; - } +var fiberStack = void 0; - return fiber; +{ + fiberStack = []; } -function getFiberTagFromObjectType(type, owner) { - var $$typeof = - typeof type === "object" && type !== null ? type.$$typeof : null; +var index = -1; - switch ($$typeof) { - case REACT_PROVIDER_TYPE: - return ContextProvider; - case REACT_CONTEXT_TYPE: - // This is a consumer - return ContextConsumer; - case REACT_FORWARD_REF_TYPE: - return ForwardRef; - default: { - var info = ""; - { - if ( - type === undefined || - (typeof type === "object" && - type !== null && - Object.keys(type).length === 0) - ) { - info += - " You likely forgot to export your component from the file " + - "it's defined in, or you might have mixed up default and " + - "named imports."; - } - var ownerName = owner ? getComponentName(owner) : null; - if (ownerName) { - info += "\n\nCheck the render method of `" + ownerName + "`."; - } - } - invariant( - false, - "Element type is invalid: expected a string (for built-in " + - "components) or a class/function (for composite components) " + - "but got: %s.%s", - type == null ? type : typeof type, - info - ); +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 createFiberFromFragment(elements, mode, expirationTime, key) { - var fiber = createFiber(Fragment, elements, key, mode); - fiber.expirationTime = expirationTime; - return fiber; +function push(cursor, value, fiber) { + index++; + + valueStack[index] = cursor.current; + + { + fiberStack[index] = fiber; + } + + cursor.current = value; } -function createFiberFromProfiler(pendingProps, mode, expirationTime, key) { +function checkThatStackIsEmpty() { { - if ( - typeof pendingProps.id !== "string" || - typeof pendingProps.onRender !== "function" - ) { - invariant( + if (index !== -1) { + warning( false, - 'Profiler must specify an "id" string and "onRender" function as props' + "Expected an empty stack. Something was not reset properly." ); } } +} - var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); - fiber.type = REACT_PROFILER_TYPE; - fiber.expirationTime = expirationTime; - fiber.stateNode = { - duration: 0, - startTime: 0 - }; - - return fiber; +function resetStackAfterFatalErrorInDev() { + { + index = -1; + valueStack.length = 0; + fiberStack.length = 0; + } } -function createFiberFromText(content, mode, expirationTime) { - var fiber = createFiber(HostText, content, null, mode); - fiber.expirationTime = expirationTime; - return fiber; +var warnedAboutMissingGetChildContext = void 0; + +{ + warnedAboutMissingGetChildContext = {}; } -function createFiberFromHostInstanceForDeletion() { - var fiber = createFiber(HostComponent, null, null, NoContext); - fiber.type = "DELETED"; - return fiber; +// 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 createFiberFromPortal(portal, mode, expirationTime) { - var pendingProps = portal.children !== null ? portal.children : []; - var fiber = createFiber(HostPortal, pendingProps, portal.key, mode); - fiber.expirationTime = expirationTime; - fiber.stateNode = { - containerInfo: portal.containerInfo, - pendingChildren: null, // Used by persistent updates - implementation: portal.implementation - }; - return fiber; +function cacheContext(workInProgress, unmaskedContext, maskedContext) { + var instance = workInProgress.stateNode; + instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; + instance.__reactInternalMemoizedMaskedChildContext = maskedContext; } -// 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); +function getMaskedContext(workInProgress, unmaskedContext) { + var type = workInProgress.type; + var contextTypes = type.contextTypes; + if (!contextTypes) { + return emptyObject; } - // 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. + // 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; + } - 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; - if (enableProfilerTimer) { - target.selfBaseTime = source.selfBaseTime; - target.treeBaseTime = source.treeBaseTime; + var context = {}; + for (var key in contextTypes) { + context[key] = unmaskedContext[key]; } - 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. + { + var name = getComponentName(workInProgress) || "Unknown"; + checkPropTypes( + contextTypes, + context, + "context", + name, + ReactDebugCurrentFiber.getCurrentFiberStackAddendum + ); + } -function createFiberRoot(containerInfo, isAsync, hydrate) { - // Cyclic construction. This cheats the type system right now because - // stateNode is any. - var uninitializedFiber = createHostRootFiber(isAsync); - var root = { - current: uninitializedFiber, - containerInfo: containerInfo, - pendingChildren: null, + // 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); + } - earliestPendingTime: NoWork, - latestPendingTime: NoWork, - earliestSuspendedTime: NoWork, - latestSuspendedTime: NoWork, - latestPingedTime: NoWork, + return context; +} - pendingCommitExpirationTime: NoWork, - finishedWork: null, - context: null, - pendingContext: null, - hydrate: hydrate, - remainingExpirationTime: NoWork, - firstBatch: null, - nextScheduledRoot: null - }; - uninitializedFiber.stateNode = root; - return root; +function hasContextChanged() { + return didPerformWorkStackCursor.current; } -var onCommitFiberRoot = null; -var onCommitFiberUnmount = null; -var hasLoggedError = false; +function isContextConsumer(fiber) { + return fiber.tag === ClassComponent && fiber.type.contextTypes != null; +} -function catchErrors(fn) { - return function(arg) { - try { - return fn(arg); - } catch (err) { - if (true && !hasLoggedError) { - hasLoggedError = true; - warning(false, "React DevTools encountered an error: %s", err); - } - } - }; +function isContextProvider(fiber) { + return fiber.tag === ClassComponent && fiber.type.childContextTypes != null; } -function injectInternals(internals) { - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined") { - // No DevTools - return false; - } - var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__; - if (hook.isDisabled) { - // This isn't a real property on the hook, but it can be set to opt out - // of DevTools integration and associated warnings and logs. - // https://github.com/facebook/react/issues/3877 - return true; - } - if (!hook.supportsFiber) { - { - warning( - false, - "The installed version of React DevTools is too old and will not work " + - "with the current version of React. Please update React DevTools. " + - "https://fb.me/react-devtools" - ); - } - // DevTools exists, even though it doesn't support Fiber. - return true; +function popContextProvider(fiber) { + if (!isContextProvider(fiber)) { + return; } - try { - var rendererID = hook.inject(internals); - // We have successfully injected, so now it is safe to set up hooks. - onCommitFiberRoot = catchErrors(function(root) { - return hook.onCommitFiberRoot(rendererID, root); - }); - onCommitFiberUnmount = catchErrors(function(fiber) { - return hook.onCommitFiberUnmount(rendererID, fiber); - }); - } catch (err) { - // Catch all errors because it is unsafe to throw during initialization. + + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} + +function popTopLevelContextObject(fiber) { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} + +function pushTopLevelContextObject(fiber, context, didChange) { + invariant( + contextStackCursor.current === emptyObject, + "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") { { - warning(false, "React DevTools encountered an error: %s.", err); + 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; } - // DevTools exists + + 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 onCommitRoot(root) { - if (typeof onCommitFiberRoot === "function") { - onCommitFiberRoot(root); +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 onCommitUnmount(fiber) { - if (typeof onCommitFiberUnmount === "function") { - onCommitFiberUnmount(fiber); +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; } -var describeComponentFrame = function(name, source, ownerName) { +// Max 31 bit integer. The max integer size in V8 for 32-bit systems. +// Math.pow(2, 30) - 1 +// 0b111111111111111111111111111111 +var MAX_SIGNED_31_BIT_INT = 1073741823; + +var NoWork = 0; +var Sync = 1; +var Never = MAX_SIGNED_31_BIT_INT; + +var UNIT_SIZE = 10; +var MAGIC_NUMBER_OFFSET = 2; + +// 1 unit of expiration time represents 10ms. +function msToExpirationTime(ms) { + // Always add an offset so that we don't clash with the magic number for NoWork. + return ((ms / UNIT_SIZE) | 0) + MAGIC_NUMBER_OFFSET; +} + +function expirationTimeToMs(expirationTime) { + return (expirationTime - MAGIC_NUMBER_OFFSET) * UNIT_SIZE; +} + +function ceiling(num, precision) { + return (((num / precision) | 0) + 1) * precision; +} + +function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) { return ( - "\n in " + - (name || "Unknown") + - (source - ? " (at " + - source.fileName.replace(/^.*[\\\/]/, "") + - ":" + - source.lineNumber + - ")" - : ownerName ? " (created by " + ownerName + ")" : "") + MAGIC_NUMBER_OFFSET + + ceiling( + currentTime - MAGIC_NUMBER_OFFSET + expirationInMs / UNIT_SIZE, + bucketSizeMs / UNIT_SIZE + ) ); -}; +} -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 ""; +var NoContext = 0; +var AsyncMode = 1; +var StrictMode = 2; +var ProfileMode = 4; + +var hasBadMapPolyfill = void 0; + +{ + hasBadMapPolyfill = false; + try { + var nonExtensibleObject = Object.preventExtensions({}); + var testMap = new Map([[nonExtensibleObject, null]]); + var testSet = new Set([nonExtensibleObject]); + // This is necessary for Rollup to not consider these unused. + // https://github.com/rollup/rollup/issues/1771 + // TODO: we can remove these if Rollup fixes the bug. + testMap.set(0, 0); + testSet.add(0); + } catch (e) { + // TODO: Consider warning about bad polyfills + hasBadMapPolyfill = true; } } -// 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; +// A Fiber is work on a Component that needs to be done or was done. There can +// be more than one per component. + +var debugCounter = void 0; + +{ + debugCounter = 1; } -/** - * Forked from fbjs/warning: - * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js - * - * Only change is we use console.warn instead of console.error, - * and do nothing when 'console' is not supported. - * This really simplifies the code. - * --- - * Similar to invariant but only logs a warning if the condition is not met. - * This can be used to log issues in development environments in critical - * paths. Removing the logging code for production environments will keep the - * same logic and follow the same code paths. - */ +function FiberNode(tag, pendingProps, key, mode) { + // Instance + this.tag = tag; + this.key = key; + this.type = null; + this.stateNode = null; -var lowPriorityWarning = function() {}; + // Fiber + this.return = null; + this.child = null; + this.sibling = null; + this.index = 0; -{ - var printWarning = function(format) { - for ( - var _len = arguments.length, - args = Array(_len > 1 ? _len - 1 : 0), - _key = 1; - _key < _len; - _key++ - ) { - args[_key - 1] = arguments[_key]; - } + this.ref = null; - var argIndex = 0; - var message = - "Warning: " + - format.replace(/%s/g, function() { - return args[argIndex++]; - }); - if (typeof console !== "undefined") { - console.warn(message); - } - try { - // --- Welcome to debugging React --- - // This error was thrown as a convenience so that you can use this stack - // to find the callsite that caused this warning to fire. - throw new Error(message); - } catch (x) {} - }; + this.pendingProps = pendingProps; + this.memoizedProps = null; + this.updateQueue = null; + this.memoizedState = null; - lowPriorityWarning = function(condition, format) { - if (format === undefined) { - throw new Error( - "`warning(condition, format, ...args)` requires a warning " + - "message argument" - ); + this.mode = mode; + + // Effects + this.effectTag = NoEffect; + this.nextEffect = null; + + this.firstEffect = null; + this.lastEffect = null; + + this.expirationTime = NoWork; + + this.alternate = null; + + if (enableProfilerTimer) { + this.actualDuration = 0; + this.actualStartTime = 0; + this.selfBaseTime = 0; + this.treeBaseTime = 0; + } + + { + this._debugID = debugCounter++; + this._debugSource = null; + this._debugOwner = null; + this._debugIsCurrentlyTiming = false; + if (!hasBadMapPolyfill && typeof Object.preventExtensions === "function") { + Object.preventExtensions(this); } - if (!condition) { - for ( - var _len2 = arguments.length, - args = Array(_len2 > 2 ? _len2 - 2 : 0), - _key2 = 2; - _key2 < _len2; - _key2++ - ) { - args[_key2 - 2] = arguments[_key2]; - } + } +} + +// This is a constructor function, rather than a POJO constructor, still +// please ensure we do the following: +// 1) Nobody should add any instance methods on this. Instance methods can be +// more difficult to predict when they get optimized and they are almost +// never inlined properly in static compilers. +// 2) Nobody should rely on `instanceof Fiber` for type testing. We should +// always know when it is a fiber. +// 3) We might want to experiment with using numeric keys since they are easier +// to optimize in a non-JIT environment. +// 4) We can easily go from a constructor to a createFiber object literal if that +// is faster. +// 5) It should be easy to port this to a C struct and keep a C implementation +// compatible. +var createFiber = function(tag, pendingProps, key, mode) { + // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors + return new FiberNode(tag, pendingProps, key, mode); +}; - printWarning.apply(undefined, [format].concat(args)); - } - }; +function shouldConstruct(Component) { + return !!(Component.prototype && Component.prototype.isReactComponent); } -var lowPriorityWarning$1 = lowPriorityWarning; - -var ReactStrictModeWarnings = { - discardPendingWarnings: function() {}, - flushPendingDeprecationWarnings: function() {}, - flushPendingUnsafeLifecycleWarnings: function() {}, - recordDeprecationWarnings: function(fiber, instance) {}, - recordUnsafeLifecycleWarnings: function(fiber, instance) {} -}; +// This is used to create an alternate fiber to do work on. +function createWorkInProgress(current, pendingProps, expirationTime) { + var workInProgress = current.alternate; + if (workInProgress === null) { + // We use a double buffering pooling technique because we know that we'll + // only ever need at most two versions of a tree. We pool the "other" unused + // node that we're free to reuse. This is lazily created to avoid allocating + // extra objects for things that are never updated. It also allow us to + // reclaim the extra memory if needed. + workInProgress = createFiber( + current.tag, + pendingProps, + current.key, + current.mode + ); + workInProgress.type = current.type; + workInProgress.stateNode = current.stateNode; -{ - var LIFECYCLE_SUGGESTIONS = { - UNSAFE_componentWillMount: "componentDidMount", - UNSAFE_componentWillReceiveProps: "static getDerivedStateFromProps", - UNSAFE_componentWillUpdate: "componentDidUpdate" - }; + { + // DEV-only fields + workInProgress._debugID = current._debugID; + workInProgress._debugSource = current._debugSource; + workInProgress._debugOwner = current._debugOwner; + } - var pendingComponentWillMountWarnings = []; - var pendingComponentWillReceivePropsWarnings = []; - var pendingComponentWillUpdateWarnings = []; - var pendingUnsafeLifecycleWarnings = new Map(); + workInProgress.alternate = current; + current.alternate = workInProgress; + } else { + workInProgress.pendingProps = pendingProps; - // Tracks components we have already warned about. - var didWarnAboutDeprecatedLifecycles = new Set(); - var didWarnAboutUnsafeLifecycles = new Set(); + // We already have an alternate. + // Reset the effect tag. + workInProgress.effectTag = NoEffect; - var setToSortedString = function(set) { - var array = []; - set.forEach(function(value) { - array.push(value); - }); - return array.sort().join(", "); - }; + // The effect list is no longer valid. + workInProgress.nextEffect = null; + workInProgress.firstEffect = null; + workInProgress.lastEffect = null; - ReactStrictModeWarnings.discardPendingWarnings = function() { - pendingComponentWillMountWarnings = []; - pendingComponentWillReceivePropsWarnings = []; - pendingComponentWillUpdateWarnings = []; - pendingUnsafeLifecycleWarnings = new Map(); - }; + if (enableProfilerTimer) { + // We intentionally reset, rather than copy, actualDuration & actualStartTime. + // This prevents time from endlessly accumulating in new commits. + // This has the downside of resetting values for different priority renders, + // But works for yielding (the common case) and should support resuming. + workInProgress.actualDuration = 0; + workInProgress.actualStartTime = 0; + } + } - ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function() { - pendingUnsafeLifecycleWarnings.forEach(function( - lifecycleWarningsMap, - strictRoot - ) { - var lifecyclesWarningMesages = []; + workInProgress.expirationTime = expirationTime; - Object.keys(lifecycleWarningsMap).forEach(function(lifecycle) { - var lifecycleWarnings = lifecycleWarningsMap[lifecycle]; - if (lifecycleWarnings.length > 0) { - var componentNames = new Set(); - lifecycleWarnings.forEach(function(fiber) { - componentNames.add(getComponentName(fiber) || "Component"); - didWarnAboutUnsafeLifecycles.add(fiber.type); - }); + workInProgress.child = current.child; + workInProgress.memoizedProps = current.memoizedProps; + workInProgress.memoizedState = current.memoizedState; + workInProgress.updateQueue = current.updateQueue; - var formatted = lifecycle.replace("UNSAFE_", ""); - var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle]; - var sortedComponentNames = setToSortedString(componentNames); + // These will be overridden during the parent's reconciliation + workInProgress.sibling = current.sibling; + workInProgress.index = current.index; + workInProgress.ref = current.ref; - lifecyclesWarningMesages.push( - formatted + - ": Please update the following components to use " + - (suggestion + " instead: " + sortedComponentNames) - ); - } - }); + if (enableProfilerTimer) { + workInProgress.selfBaseTime = current.selfBaseTime; + workInProgress.treeBaseTime = current.treeBaseTime; + } - if (lifecyclesWarningMesages.length > 0) { - var strictRootComponentStack = getStackAddendumByWorkInProgressFiber( - strictRoot - ); + return workInProgress; +} - warning( - false, - "Unsafe lifecycle methods were found within a strict-mode tree:%s" + - "\n\n%s" + - "\n\nLearn more about this warning here:" + - "\nhttps://fb.me/react-strict-mode-warnings", - strictRootComponentStack, - lifecyclesWarningMesages.join("\n\n") - ); - } - }); +function createHostRootFiber(isAsync) { + var mode = isAsync ? AsyncMode | StrictMode : NoContext; + return createFiber(HostRoot, null, null, mode); +} - pendingUnsafeLifecycleWarnings = new Map(); - }; +function createFiberFromElement(element, mode, expirationTime) { + var owner = null; + { + owner = element._owner; + } - var findStrictRoot = function(fiber) { - var maybeStrictRoot = null; + var fiber = void 0; + var type = element.type; + var key = element.key; + var pendingProps = element.props; - var node = fiber; - while (node !== null) { - if (node.mode & StrictMode) { - maybeStrictRoot = node; - } - node = node.return; + var fiberTag = void 0; + if (typeof type === "function") { + fiberTag = shouldConstruct(type) ? ClassComponent : IndeterminateComponent; + } else if (typeof type === "string") { + fiberTag = HostComponent; + } else { + switch (type) { + case REACT_FRAGMENT_TYPE: + return createFiberFromFragment( + pendingProps.children, + mode, + expirationTime, + key + ); + case REACT_ASYNC_MODE_TYPE: + fiberTag = Mode; + mode |= AsyncMode | StrictMode; + break; + case REACT_STRICT_MODE_TYPE: + fiberTag = Mode; + mode |= StrictMode; + break; + case REACT_PROFILER_TYPE: + return createFiberFromProfiler(pendingProps, mode, expirationTime, key); + case REACT_TIMEOUT_TYPE: + fiberTag = TimeoutComponent; + // Suspense does not require async, but its children should be strict + // mode compatible. + mode |= StrictMode; + break; + default: + fiberTag = getFiberTagFromObjectType(type, owner); + break; } + } - return maybeStrictRoot; - }; + fiber = createFiber(fiberTag, pendingProps, key, mode); + fiber.type = type; + fiber.expirationTime = expirationTime; - ReactStrictModeWarnings.flushPendingDeprecationWarnings = function() { - if (pendingComponentWillMountWarnings.length > 0) { - var uniqueNames = new Set(); - pendingComponentWillMountWarnings.forEach(function(fiber) { - uniqueNames.add(getComponentName(fiber) || "Component"); - didWarnAboutDeprecatedLifecycles.add(fiber.type); - }); + { + fiber._debugSource = element._source; + fiber._debugOwner = element._owner; + } - var sortedNames = setToSortedString(uniqueNames); + return fiber; +} - lowPriorityWarning$1( - false, - "componentWillMount is deprecated and will be removed in the next major version. " + - "Use componentDidMount instead. As a temporary workaround, " + - "you can rename to UNSAFE_componentWillMount." + - "\n\nPlease update the following components: %s" + - "\n\nLearn more about this warning here:" + - "\nhttps://fb.me/react-async-component-lifecycle-hooks", - sortedNames +function getFiberTagFromObjectType(type, owner) { + var $$typeof = + typeof type === "object" && type !== null ? type.$$typeof : null; + + switch ($$typeof) { + case REACT_PROVIDER_TYPE: + return ContextProvider; + case REACT_CONTEXT_TYPE: + // This is a consumer + return ContextConsumer; + case REACT_FORWARD_REF_TYPE: + return ForwardRef; + default: { + var info = ""; + { + if ( + type === undefined || + (typeof type === "object" && + type !== null && + Object.keys(type).length === 0) + ) { + info += + " You likely forgot to export your component from the file " + + "it's defined in, or you might have mixed up default and " + + "named imports."; + } + var ownerName = owner ? getComponentName(owner) : null; + if (ownerName) { + info += "\n\nCheck the render method of `" + ownerName + "`."; + } + } + invariant( + false, + "Element type is invalid: expected a string (for built-in " + + "components) or a class/function (for composite components) " + + "but got: %s.%s", + type == null ? type : typeof type, + info ); - - pendingComponentWillMountWarnings = []; } + } +} - if (pendingComponentWillReceivePropsWarnings.length > 0) { - var _uniqueNames = new Set(); - pendingComponentWillReceivePropsWarnings.forEach(function(fiber) { - _uniqueNames.add(getComponentName(fiber) || "Component"); - didWarnAboutDeprecatedLifecycles.add(fiber.type); - }); - - var _sortedNames = setToSortedString(_uniqueNames); +function createFiberFromFragment(elements, mode, expirationTime, key) { + var fiber = createFiber(Fragment, elements, key, mode); + fiber.expirationTime = expirationTime; + return fiber; +} - lowPriorityWarning$1( +function createFiberFromProfiler(pendingProps, mode, expirationTime, key) { + { + if ( + typeof pendingProps.id !== "string" || + typeof pendingProps.onRender !== "function" + ) { + invariant( false, - "componentWillReceiveProps is deprecated and will be removed in the next major version. " + - "Use static getDerivedStateFromProps instead." + - "\n\nPlease update the following components: %s" + - "\n\nLearn more about this warning here:" + - "\nhttps://fb.me/react-async-component-lifecycle-hooks", - _sortedNames + 'Profiler must specify an "id" string and "onRender" function as props' ); - - pendingComponentWillReceivePropsWarnings = []; } + } - if (pendingComponentWillUpdateWarnings.length > 0) { - var _uniqueNames2 = new Set(); - pendingComponentWillUpdateWarnings.forEach(function(fiber) { - _uniqueNames2.add(getComponentName(fiber) || "Component"); - didWarnAboutDeprecatedLifecycles.add(fiber.type); - }); + var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); + fiber.type = REACT_PROFILER_TYPE; + fiber.expirationTime = expirationTime; - var _sortedNames2 = setToSortedString(_uniqueNames2); + return fiber; +} - lowPriorityWarning$1( - false, - "componentWillUpdate is deprecated and will be removed in the next major version. " + - "Use componentDidUpdate instead. As a temporary workaround, " + - "you can rename to UNSAFE_componentWillUpdate." + - "\n\nPlease update the following components: %s" + - "\n\nLearn more about this warning here:" + - "\nhttps://fb.me/react-async-component-lifecycle-hooks", - _sortedNames2 - ); +function createFiberFromText(content, mode, expirationTime) { + var fiber = createFiber(HostText, content, null, mode); + fiber.expirationTime = expirationTime; + return fiber; +} - pendingComponentWillUpdateWarnings = []; - } +function createFiberFromHostInstanceForDeletion() { + var fiber = createFiber(HostComponent, null, null, NoContext); + fiber.type = "DELETED"; + return fiber; +} + +function createFiberFromPortal(portal, mode, expirationTime) { + var pendingProps = portal.children !== null ? portal.children : []; + var fiber = createFiber(HostPortal, pendingProps, portal.key, mode); + fiber.expirationTime = expirationTime; + fiber.stateNode = { + containerInfo: portal.containerInfo, + pendingChildren: null, // Used by persistent updates + implementation: portal.implementation }; + return fiber; +} - ReactStrictModeWarnings.recordDeprecationWarnings = function( - fiber, - instance - ) { - // Dedup strategy: Warn once per component. - if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) { - return; - } +// 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); + } - // Don't warn about react-lifecycles-compat polyfilled components. - if ( - typeof instance.componentWillMount === "function" && - instance.componentWillMount.__suppressDeprecationWarning !== true - ) { - pendingComponentWillMountWarnings.push(fiber); - } - if ( - typeof instance.componentWillReceiveProps === "function" && - instance.componentWillReceiveProps.__suppressDeprecationWarning !== true - ) { - pendingComponentWillReceivePropsWarnings.push(fiber); - } - if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true - ) { - pendingComponentWillUpdateWarnings.push(fiber); - } - }; + // 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. - ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function( - fiber, - instance - ) { - var strictRoot = findStrictRoot(fiber); - if (strictRoot === null) { - warning( - false, - "Expected to find a StrictMode component in a strict mode tree. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - return; - } + 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; + if (enableProfilerTimer) { + target.actualDuration = source.actualDuration; + target.actualStartTime = source.actualStartTime; + target.selfBaseTime = source.selfBaseTime; + target.treeBaseTime = source.treeBaseTime; + } + target._debugID = source._debugID; + target._debugSource = source._debugSource; + target._debugOwner = source._debugOwner; + target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming; + return target; +} - // Dedup strategy: Warn once per component. - // This is difficult to track any other way since component names - // are often vague and are likely to collide between 3rd party libraries. - // An expand property is probably okay to use here since it's DEV-only, - // and will only be set in the event of serious warnings. - if (didWarnAboutUnsafeLifecycles.has(fiber.type)) { - return; - } +// TODO: This should be lifted into the renderer. - var warningsForRoot = void 0; - if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) { - warningsForRoot = { - UNSAFE_componentWillMount: [], - UNSAFE_componentWillReceiveProps: [], - UNSAFE_componentWillUpdate: [] - }; +function createFiberRoot(containerInfo, isAsync, hydrate) { + // Cyclic construction. This cheats the type system right now because + // stateNode is any. + var uninitializedFiber = createHostRootFiber(isAsync); + var root = { + current: uninitializedFiber, + containerInfo: containerInfo, + pendingChildren: null, - pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot); - } else { - warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot); - } + earliestPendingTime: NoWork, + latestPendingTime: NoWork, + earliestSuspendedTime: NoWork, + latestSuspendedTime: NoWork, + latestPingedTime: NoWork, - var unsafeLifecycles = []; - if ( - (typeof instance.componentWillMount === "function" && - instance.componentWillMount.__suppressDeprecationWarning !== true) || - typeof instance.UNSAFE_componentWillMount === "function" - ) { - unsafeLifecycles.push("UNSAFE_componentWillMount"); - } - if ( - (typeof instance.componentWillReceiveProps === "function" && - instance.componentWillReceiveProps.__suppressDeprecationWarning !== - true) || - typeof instance.UNSAFE_componentWillReceiveProps === "function" - ) { - unsafeLifecycles.push("UNSAFE_componentWillReceiveProps"); - } - if ( - (typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true) || - typeof instance.UNSAFE_componentWillUpdate === "function" - ) { - unsafeLifecycles.push("UNSAFE_componentWillUpdate"); - } + didError: false, - if (unsafeLifecycles.length > 0) { - unsafeLifecycles.forEach(function(lifecycle) { - warningsForRoot[lifecycle].push(fiber); - }); + pendingCommitExpirationTime: NoWork, + finishedWork: null, + context: null, + pendingContext: null, + hydrate: hydrate, + nextExpirationTimeToWorkOn: NoWork, + expirationTime: NoWork, + firstBatch: null, + nextScheduledRoot: null + }; + uninitializedFiber.stateNode = root; + return root; +} + +var onCommitFiberRoot = null; +var onCommitFiberUnmount = null; +var hasLoggedError = false; + +function catchErrors(fn) { + return function(arg) { + try { + return fn(arg); + } catch (err) { + if (true && !hasLoggedError) { + hasLoggedError = true; + warning(false, "React DevTools encountered an error: %s", err); + } } }; } -/** - * The "actual" render time is total time required to render the descendants of a Profiler component. - * This time is stored as a stack, since Profilers can be nested. - * This time is started during the "begin" phase and stopped during the "complete" phase. - * It is paused (and accumulated) in the event of an interruption or an aborted render. - */ - -function createProfilerTimer(now) { - var fiberStack = void 0; - - { - fiberStack = []; +function injectInternals(internals) { + if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined") { + // No DevTools + return false; } - - var timerPausedAt = 0; - var totalElapsedPauseTime = 0; - - function checkActualRenderTimeStackEmpty() { - { - !(fiberStack.length === 0) - ? warning( - false, - "Expected an empty stack. Something was not reset properly." - ) - : void 0; - } + var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__; + if (hook.isDisabled) { + // This isn't a real property on the hook, but it can be set to opt out + // of DevTools integration and associated warnings and logs. + // https://github.com/facebook/react/issues/3877 + return true; } - - function markActualRenderTimeStarted(fiber) { + if (!hook.supportsFiber) { { - fiberStack.push(fiber); - } - fiber.stateNode.startTime = now() - totalElapsedPauseTime; - } - - function pauseActualRenderTimerIfRunning() { - if (timerPausedAt === 0) { - timerPausedAt = now(); + warning( + false, + "The installed version of React DevTools is too old and will not work " + + "with the current version of React. Please update React DevTools. " + + "https://fb.me/react-devtools" + ); } + // DevTools exists, even though it doesn't support Fiber. + return true; } - - function recordElapsedActualRenderTime(fiber) { + try { + var rendererID = hook.inject(internals); + // We have successfully injected, so now it is safe to set up hooks. + onCommitFiberRoot = catchErrors(function(root) { + return hook.onCommitFiberRoot(rendererID, root); + }); + onCommitFiberUnmount = catchErrors(function(fiber) { + return hook.onCommitFiberUnmount(rendererID, fiber); + }); + } catch (err) { + // Catch all errors because it is unsafe to throw during initialization. { - !(fiber === fiberStack.pop()) - ? warning(false, "Unexpected Fiber popped.") - : void 0; + warning(false, "React DevTools encountered an error: %s.", err); } - fiber.stateNode.duration += - now() - totalElapsedPauseTime - fiber.stateNode.startTime; } + // DevTools exists + return true; +} - function resetActualRenderTimer() { - totalElapsedPauseTime = 0; +function onCommitRoot(root) { + if (typeof onCommitFiberRoot === "function") { + onCommitFiberRoot(root); } +} - function resumeActualRenderTimerIfPaused() { - if (timerPausedAt > 0) { - totalElapsedPauseTime += now() - timerPausedAt; - timerPausedAt = 0; - } +function onCommitUnmount(fiber) { + if (typeof onCommitFiberUnmount === "function") { + onCommitFiberUnmount(fiber); } +} - /** - * The "base" render time is the duration of the “begin” phase of work for a particular fiber. - * This time is measured and stored on each fiber. - * The time for all sibling fibers are accumulated and stored on their parent during the "complete" phase. - * If a fiber bails out (sCU false) then its "base" timer is cancelled and the fiber is not updated. - */ +/** + * Forked from fbjs/warning: + * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js + * + * Only change is we use console.warn instead of console.error, + * and do nothing when 'console' is not supported. + * This really simplifies the code. + * --- + * Similar to invariant but only logs a warning if the condition is not met. + * This can be used to log issues in development environments in critical + * paths. Removing the logging code for production environments will keep the + * same logic and follow the same code paths. + */ - var baseStartTime = -1; +var lowPriorityWarning = function() {}; - function recordElapsedBaseRenderTimeIfRunning(fiber) { - if (baseStartTime !== -1) { - fiber.selfBaseTime = now() - baseStartTime; +{ + var printWarning = function(format) { + for ( + var _len = arguments.length, + args = Array(_len > 1 ? _len - 1 : 0), + _key = 1; + _key < _len; + _key++ + ) { + args[_key - 1] = arguments[_key]; } - } - function startBaseRenderTimer() { - { - if (baseStartTime !== -1) { - warning( - false, - "Cannot start base timer that is already running. " + - "This error is likely caused by a bug in React. " + - "Please file an issue." - ); - } + var argIndex = 0; + var message = + "Warning: " + + format.replace(/%s/g, function() { + return args[argIndex++]; + }); + if (typeof console !== "undefined") { + console.warn(message); } - baseStartTime = now(); - } - - function stopBaseRenderTimerIfRunning() { - baseStartTime = -1; - } - - if (enableProfilerTimer) { - return { - checkActualRenderTimeStackEmpty: checkActualRenderTimeStackEmpty, - markActualRenderTimeStarted: markActualRenderTimeStarted, - pauseActualRenderTimerIfRunning: pauseActualRenderTimerIfRunning, - recordElapsedActualRenderTime: recordElapsedActualRenderTime, - resetActualRenderTimer: resetActualRenderTimer, - resumeActualRenderTimerIfPaused: resumeActualRenderTimerIfPaused, - recordElapsedBaseRenderTimeIfRunning: recordElapsedBaseRenderTimeIfRunning, - startBaseRenderTimer: startBaseRenderTimer, - stopBaseRenderTimerIfRunning: stopBaseRenderTimerIfRunning - }; - } else { - return { - checkActualRenderTimeStackEmpty: function() {}, - markActualRenderTimeStarted: function(fiber) {}, - pauseActualRenderTimerIfRunning: function() {}, - recordElapsedActualRenderTime: function(fiber) {}, - resetActualRenderTimer: function() {}, - resumeActualRenderTimerIfPaused: function() {}, - recordElapsedBaseRenderTimeIfRunning: function(fiber) {}, - startBaseRenderTimer: function() {}, - stopBaseRenderTimerIfRunning: function() {} - }; - } -} + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) {} + }; -function getCurrentFiberOwnerName() { - { - var fiber = ReactDebugCurrentFiber.current; - if (fiber === null) { - return null; - } - var owner = fiber._debugOwner; - if (owner !== null && typeof owner !== "undefined") { - return getComponentName(owner); + lowPriorityWarning = function(condition, format) { + if (format === undefined) { + throw new Error( + "`warning(condition, format, ...args)` requires a warning " + + "message argument" + ); } - } - return null; -} + if (!condition) { + for ( + var _len2 = arguments.length, + args = Array(_len2 > 2 ? _len2 - 2 : 0), + _key2 = 2; + _key2 < _len2; + _key2++ + ) { + args[_key2 - 2] = arguments[_key2]; + } -function getCurrentFiberStackAddendum$1() { - { - var fiber = ReactDebugCurrentFiber.current; - if (fiber === null) { - return null; + printWarning.apply(undefined, [format].concat(args)); } - // 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; -} +var lowPriorityWarning$1 = lowPriorityWarning; -function setCurrentFiber(fiber) { - ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackAddendum$1; - ReactDebugCurrentFiber.current = fiber; - ReactDebugCurrentFiber.phase = null; -} +var ReactStrictModeWarnings = { + discardPendingWarnings: function() {}, + flushPendingDeprecationWarnings: function() {}, + flushPendingUnsafeLifecycleWarnings: function() {}, + recordDeprecationWarnings: function(fiber, instance) {}, + recordUnsafeLifecycleWarnings: function(fiber, instance) {}, + recordLegacyContextWarning: function(fiber, instance) {}, + flushLegacyContextWarning: function() {} +}; -function setCurrentPhase(phase) { - ReactDebugCurrentFiber.phase = phase; -} +{ + var LIFECYCLE_SUGGESTIONS = { + UNSAFE_componentWillMount: "componentDidMount", + UNSAFE_componentWillReceiveProps: "static getDerivedStateFromProps", + UNSAFE_componentWillUpdate: "componentDidUpdate" + }; -var ReactDebugCurrentFiber = { - current: null, - phase: null, - resetCurrentFiber: resetCurrentFiber, - setCurrentFiber: setCurrentFiber, - setCurrentPhase: setCurrentPhase, - getCurrentFiberOwnerName: getCurrentFiberOwnerName, - getCurrentFiberStackAddendum: getCurrentFiberStackAddendum$1 -}; + var pendingComponentWillMountWarnings = []; + var pendingComponentWillReceivePropsWarnings = []; + var pendingComponentWillUpdateWarnings = []; + var pendingUnsafeLifecycleWarnings = new Map(); + var pendingLegacyContextWarning = new Map(); -// 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"; + // Tracks components we have already warned about. + var didWarnAboutDeprecatedLifecycles = new Set(); + var didWarnAboutUnsafeLifecycles = new Set(); + var didWarnAboutLegacyContext = new Set(); -// 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 setToSortedString = function(set) { + var array = []; + set.forEach(function(value) { + array.push(value); + }); + return array.sort().join(", "); + }; + + ReactStrictModeWarnings.discardPendingWarnings = function() { + pendingComponentWillMountWarnings = []; + pendingComponentWillReceivePropsWarnings = []; + pendingComponentWillUpdateWarnings = []; + pendingUnsafeLifecycleWarnings = new Map(); + pendingLegacyContextWarning = new Map(); + }; + + ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function() { + pendingUnsafeLifecycleWarnings.forEach(function( + lifecycleWarningsMap, + strictRoot + ) { + var lifecyclesWarningMesages = []; -var formatMarkName = function(markName) { - return reactEmoji + " " + markName; -}; + Object.keys(lifecycleWarningsMap).forEach(function(lifecycle) { + var lifecycleWarnings = lifecycleWarningsMap[lifecycle]; + if (lifecycleWarnings.length > 0) { + var componentNames = new Set(); + lifecycleWarnings.forEach(function(fiber) { + componentNames.add(getComponentName(fiber) || "Component"); + didWarnAboutUnsafeLifecycles.add(fiber.type); + }); -var formatLabel = function(label, warning$$1) { - var prefix = warning$$1 ? warningEmoji + " " : reactEmoji + " "; - var suffix = warning$$1 ? " Warning: " + warning$$1 : ""; - return "" + prefix + label + suffix; -}; + var formatted = lifecycle.replace("UNSAFE_", ""); + var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle]; + var sortedComponentNames = setToSortedString(componentNames); -var beginMark = function(markName) { - performance.mark(formatMarkName(markName)); -}; + lifecyclesWarningMesages.push( + formatted + + ": Please update the following components to use " + + (suggestion + " instead: " + sortedComponentNames) + ); + } + }); -var clearMark = function(markName) { - performance.clearMarks(formatMarkName(markName)); -}; + if (lifecyclesWarningMesages.length > 0) { + var strictRootComponentStack = getStackAddendumByWorkInProgressFiber( + strictRoot + ); -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. + warning( + false, + "Unsafe lifecycle methods were found within a strict-mode tree:%s" + + "\n\n%s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-strict-mode-warnings", + strictRootComponentStack, + lifecyclesWarningMesages.join("\n\n") + ); + } + }); - // Clear marks immediately to avoid growing buffer. - performance.clearMarks(formattedMarkName); - performance.clearMeasures(formattedLabel); -}; + pendingUnsafeLifecycleWarnings = new Map(); + }; -var getFiberMarkName = function(label, debugID) { - return label + " (#" + debugID + ")"; -}; + var findStrictRoot = function(fiber) { + var maybeStrictRoot = null; -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 node = fiber; + while (node !== null) { + if (node.mode & StrictMode) { + maybeStrictRoot = node; + } + node = node.return; + } -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); + return maybeStrictRoot; + }; - 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); + ReactStrictModeWarnings.flushPendingDeprecationWarnings = function() { + if (pendingComponentWillMountWarnings.length > 0) { + var uniqueNames = new Set(); + pendingComponentWillMountWarnings.forEach(function(fiber) { + uniqueNames.add(getComponentName(fiber) || "Component"); + didWarnAboutDeprecatedLifecycles.add(fiber.type); + }); - var markName = getFiberMarkName(label, debugID); - beginMark(markName); - return true; -}; + var sortedNames = setToSortedString(uniqueNames); -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); -}; + lowPriorityWarning$1( + false, + "componentWillMount is deprecated and will be removed in the next major version. " + + "Use componentDidMount instead. As a temporary workaround, " + + "you can rename to UNSAFE_componentWillMount." + + "\n\nPlease update the following components: %s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-async-component-lifecycle-hooks", + sortedNames + ); -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); -}; + pendingComponentWillMountWarnings = []; + } -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 Fragment: - case ContextProvider: - case ContextConsumer: - case Mode: - return true; - default: - return false; - } -}; + if (pendingComponentWillReceivePropsWarnings.length > 0) { + var _uniqueNames = new Set(); + pendingComponentWillReceivePropsWarnings.forEach(function(fiber) { + _uniqueNames.add(getComponentName(fiber) || "Component"); + didWarnAboutDeprecatedLifecycles.add(fiber.type); + }); -var clearPendingPhaseMeasurement = function() { - if (currentPhase !== null && currentPhaseFiber !== null) { - clearFiberMark(currentPhaseFiber, currentPhase); - } - currentPhaseFiber = null; - currentPhase = null; - hasScheduledUpdateInCurrentPhase = false; -}; + var _sortedNames = setToSortedString(_uniqueNames); -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); + lowPriorityWarning$1( + false, + "componentWillReceiveProps is deprecated and will be removed in the next major version. " + + "Use static getDerivedStateFromProps instead." + + "\n\nPlease update the following components: %s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-async-component-lifecycle-hooks", + _sortedNames + ); + + pendingComponentWillReceivePropsWarnings = []; } - fiber = fiber.return; - } -}; -var resumeTimersRecursively = function(fiber) { - if (fiber.return !== null) { - resumeTimersRecursively(fiber.return); - } - if (fiber._debugIsCurrentlyTiming) { - beginFiberMark(fiber, null); - } -}; + if (pendingComponentWillUpdateWarnings.length > 0) { + var _uniqueNames2 = new Set(); + pendingComponentWillUpdateWarnings.forEach(function(fiber) { + _uniqueNames2.add(getComponentName(fiber) || "Component"); + didWarnAboutDeprecatedLifecycles.add(fiber.type); + }); -var resumeTimers = function() { - // Resumes all measurements that were active during the last deferred loop. - if (currentFiber !== null) { - resumeTimersRecursively(currentFiber); - } -}; + var _sortedNames2 = setToSortedString(_uniqueNames2); -function recordEffect() { - if (enableUserTimingAPI) { - effectCountInCurrentCommit++; - } -} + lowPriorityWarning$1( + false, + "componentWillUpdate is deprecated and will be removed in the next major version. " + + "Use componentDidUpdate instead. As a temporary workaround, " + + "you can rename to UNSAFE_componentWillUpdate." + + "\n\nPlease update the following components: %s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-async-component-lifecycle-hooks", + _sortedNames2 + ); -function recordScheduleUpdate() { - if (enableUserTimingAPI) { - if (isCommitting) { - hasScheduledUpdateInCurrentCommit = true; + pendingComponentWillUpdateWarnings = []; + } + }; + + ReactStrictModeWarnings.recordDeprecationWarnings = function( + fiber, + instance + ) { + // Dedup strategy: Warn once per component. + if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) { + return; + } + + // Don't warn about react-lifecycles-compat polyfilled components. + if ( + typeof instance.componentWillMount === "function" && + instance.componentWillMount.__suppressDeprecationWarning !== true + ) { + pendingComponentWillMountWarnings.push(fiber); + } + if ( + typeof instance.componentWillReceiveProps === "function" && + instance.componentWillReceiveProps.__suppressDeprecationWarning !== true + ) { + pendingComponentWillReceivePropsWarnings.push(fiber); } if ( - currentPhase !== null && - currentPhase !== "componentWillMount" && - currentPhase !== "componentWillReceiveProps" + typeof instance.componentWillUpdate === "function" && + instance.componentWillUpdate.__suppressDeprecationWarning !== true ) { - hasScheduledUpdateInCurrentPhase = true; - } - } -} - -function startRequestCallbackTimer() { - if (enableUserTimingAPI) { - if (supportsUserTiming && !isWaitingForCallback) { - isWaitingForCallback = true; - beginMark("(Waiting for async callback...)"); + pendingComponentWillUpdateWarnings.push(fiber); } - } -} + }; -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 + ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function( + fiber, + instance + ) { + var strictRoot = findStrictRoot(fiber); + if (strictRoot === null) { + warning( + false, + "Expected to find a StrictMode component in a strict mode tree. " + + "This error is likely caused by a bug in React. Please file an issue." ); - } - } -} - -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)) { + + // Dedup strategy: Warn once per component. + // This is difficult to track any other way since component names + // are often vague and are likely to collide between 3rd party libraries. + // An expand property is probably okay to use here since it's DEV-only, + // and will only be set in the event of serious warnings. + if (didWarnAboutUnsafeLifecycles.has(fiber.type)) { return; } - fiber._debugIsCurrentlyTiming = true; - } -} -function cancelWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; + var warningsForRoot = void 0; + if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) { + warningsForRoot = { + UNSAFE_componentWillMount: [], + UNSAFE_componentWillReceiveProps: [], + UNSAFE_componentWillUpdate: [] + }; + + pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot); + } else { + warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot); } - // 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; + var unsafeLifecycles = []; + if ( + (typeof instance.componentWillMount === "function" && + instance.componentWillMount.__suppressDeprecationWarning !== true) || + typeof instance.UNSAFE_componentWillMount === "function" + ) { + unsafeLifecycles.push("UNSAFE_componentWillMount"); } - // If we pause, its parent is the fiber to unwind from. - currentFiber = fiber.return; - if (!fiber._debugIsCurrentlyTiming) { - return; + if ( + (typeof instance.componentWillReceiveProps === "function" && + instance.componentWillReceiveProps.__suppressDeprecationWarning !== + true) || + typeof instance.UNSAFE_componentWillReceiveProps === "function" + ) { + unsafeLifecycles.push("UNSAFE_componentWillReceiveProps"); + } + if ( + (typeof instance.componentWillUpdate === "function" && + instance.componentWillUpdate.__suppressDeprecationWarning !== true) || + typeof instance.UNSAFE_componentWillUpdate === "function" + ) { + unsafeLifecycles.push("UNSAFE_componentWillUpdate"); } - fiber._debugIsCurrentlyTiming = false; - endFiberMark(fiber, null, null); - } -} -function stopFailedWorkTimer(fiber) { - if (enableUserTimingAPI) { - if (!supportsUserTiming || shouldIgnoreFiber(fiber)) { - return; + if (unsafeLifecycles.length > 0) { + unsafeLifecycles.forEach(function(lifecycle) { + warningsForRoot[lifecycle].push(fiber); + }); } - // If we pause, its parent is the fiber to unwind from. - currentFiber = fiber.return; - if (!fiber._debugIsCurrentlyTiming) { + }; + + ReactStrictModeWarnings.recordLegacyContextWarning = function( + fiber, + instance + ) { + var strictRoot = findStrictRoot(fiber); + if (strictRoot === null) { + warning( + false, + "Expected to find a StrictMode component in a strict mode tree. " + + "This error is likely caused by a bug in React. Please file an issue." + ); 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) { + // Dedup strategy: Warn once per component. + if (didWarnAboutLegacyContext.has(fiber.type)) { return; } - clearPendingPhaseMeasurement(); - if (!beginFiberMark(fiber, phase)) { - return; + + var warningsForRoot = pendingLegacyContextWarning.get(strictRoot); + + if ( + fiber.type.contextTypes != null || + fiber.type.childContextTypes != null || + (instance !== null && typeof instance.getChildContext === "function") + ) { + if (warningsForRoot === undefined) { + warningsForRoot = []; + pendingLegacyContextWarning.set(strictRoot, warningsForRoot); + } + warningsForRoot.push(fiber); } - currentPhaseFiber = fiber; - currentPhase = phase; - } + }; + + ReactStrictModeWarnings.flushLegacyContextWarning = function() { + pendingLegacyContextWarning.forEach(function(fiberArray, strictRoot) { + var uniqueNames = new Set(); + fiberArray.forEach(function(fiber) { + uniqueNames.add(getComponentName(fiber) || "Component"); + didWarnAboutLegacyContext.add(fiber.type); + }); + + var sortedNames = setToSortedString(uniqueNames); + var strictRootComponentStack = getStackAddendumByWorkInProgressFiber( + strictRoot + ); + + warning( + false, + "Legacy context API has been detected within a strict-mode tree: %s" + + "\n\nPlease update the following components: %s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-strict-mode-warnings", + strictRootComponentStack, + sortedNames + ); + }); + }; } -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); +// This lets us hook into Fiber to debug what it's doing. +// See https://github.com/facebook/react/pull/8033. +// This is not part of the public API, not even for React DevTools. +// You may only inject a debugTool if you work on React Fiber itself. +var ReactFiberInstrumentation = { + debugTool: null +}; + +var ReactFiberInstrumentation_1 = ReactFiberInstrumentation; + +// TODO: Offscreen updates + +function markPendingPriorityLevel(root, expirationTime) { + // If there's a gap between completing a failed root and retrying it, + // additional updates may be scheduled. Clear `didError`, in case the update + // is sufficient to fix the error. + root.didError = false; + + // Update the latest and earliest pending times + var earliestPendingTime = root.earliestPendingTime; + if (earliestPendingTime === NoWork) { + // No other pending updates. + root.earliestPendingTime = root.latestPendingTime = expirationTime; + } else { + if (earliestPendingTime > expirationTime) { + // This is the earliest pending update. + root.earliestPendingTime = expirationTime; + } else { + var latestPendingTime = root.latestPendingTime; + if (latestPendingTime < expirationTime) { + // This is the latest pending update + root.latestPendingTime = expirationTime; + } } - currentPhase = null; - currentPhaseFiber = null; } + findNextPendingPriorityLevel(root); } -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 markCommittedPriorityLevels(root, currentTime, earliestRemainingTime) { + root.didError = false; + + if (earliestRemainingTime === NoWork) { + // Fast path. There's no remaining work. Clear everything. + root.earliestPendingTime = NoWork; + root.latestPendingTime = NoWork; + root.earliestSuspendedTime = NoWork; + root.latestSuspendedTime = NoWork; + root.latestPingedTime = NoWork; + findNextPendingPriorityLevel(root); + return; } -} -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"; + // Let's see if the previous latest known pending level was just flushed. + var latestPendingTime = root.latestPendingTime; + if (latestPendingTime !== NoWork) { + if (latestPendingTime < earliestRemainingTime) { + // We've flushed all the known pending levels. + root.earliestPendingTime = root.latestPendingTime = NoWork; + } else { + var earliestPendingTime = root.earliestPendingTime; + if (earliestPendingTime < earliestRemainingTime) { + // We've flushed the earliest known pending level. Set this to the + // latest pending time. + root.earliestPendingTime = root.latestPendingTime; } - } 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)"); + // Now let's handle the earliest remaining level in the whole tree. We need to + // decide whether to treat it as a pending level or as suspended. Check + // it falls within the range of known suspended levels. + + var earliestSuspendedTime = root.earliestSuspendedTime; + if (earliestSuspendedTime === NoWork) { + // There's no suspended work. Treat the earliest remaining level as a + // pending level. + markPendingPriorityLevel(root, earliestRemainingTime); + findNextPendingPriorityLevel(root); + return; } -} -function stopCommitTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } + var latestSuspendedTime = root.latestSuspendedTime; + if (earliestRemainingTime > latestSuspendedTime) { + // The earliest remaining level is later than all the suspended work. That + // means we've flushed all the suspended work. + root.earliestSuspendedTime = NoWork; + root.latestSuspendedTime = NoWork; + root.latestPingedTime = NoWork; - 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(); + // There's no suspended work. Treat the earliest remaining level as a + // pending level. + markPendingPriorityLevel(root, earliestRemainingTime); + findNextPendingPriorityLevel(root); + return; + } - endMark("(Committing Changes)", "(Committing Changes)", warning$$1); + if (earliestRemainingTime < earliestSuspendedTime) { + // The earliest remaining time is earlier than all the suspended work. + // Treat it as a pending update. + markPendingPriorityLevel(root, earliestRemainingTime); + findNextPendingPriorityLevel(root); + return; } + + // The earliest remaining time falls within the range of known suspended + // levels. We should treat this as suspended work. + findNextPendingPriorityLevel(root); } -function startCommitSnapshotEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - effectCountInCurrentCommit = 0; - beginMark("(Committing Snapshot Effects)"); - } +function hasLowerPriorityWork(root, renderExpirationTime) { + return ( + renderExpirationTime !== root.latestPendingTime && + renderExpirationTime !== root.latestSuspendedTime + ); } -function stopCommitSnapshotEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Committing Snapshot Effects: " + count + " Total)", - "(Committing Snapshot Effects)", - null - ); +function markSuspendedPriorityLevel(root, suspendedTime, didError) { + if (didError && !hasLowerPriorityWork(root, suspendedTime)) { + // TODO: When we add back resuming, we need to ensure the progressed work + // is thrown out and not reused during the restarted render. One way to + // invalidate the progressed work is to restart at expirationTime + 1. + root.didError = true; + findNextPendingPriorityLevel(root); + return; } -} -function startCommitHostEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; + // First, check the known pending levels and update them if needed. + var earliestPendingTime = root.earliestPendingTime; + var latestPendingTime = root.latestPendingTime; + if (earliestPendingTime === suspendedTime) { + if (latestPendingTime === suspendedTime) { + // Both known pending levels were suspended. Clear them. + root.earliestPendingTime = root.latestPendingTime = NoWork; + } else { + // The earliest pending level was suspended. Clear by setting it to the + // latest pending level. + root.earliestPendingTime = latestPendingTime; } - effectCountInCurrentCommit = 0; - beginMark("(Committing Host Effects)"); + } else if (latestPendingTime === suspendedTime) { + // The latest pending level was suspended. Clear by setting it to the + // latest pending level. + root.latestPendingTime = earliestPendingTime; } -} -function stopCommitHostEffectsTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; + // Next, if we're working on the lowest known suspended level, clear the ping. + // TODO: What if a promise suspends and pings before the root completes? + var latestSuspendedTime = root.latestSuspendedTime; + if (latestSuspendedTime === suspendedTime) { + root.latestPingedTime = NoWork; + } + + // Finally, update the known suspended levels. + var earliestSuspendedTime = root.earliestSuspendedTime; + if (earliestSuspendedTime === NoWork) { + // No other suspended levels. + root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime; + } else { + if (earliestSuspendedTime > suspendedTime) { + // This is the earliest suspended level. + root.earliestSuspendedTime = suspendedTime; + } else if (latestSuspendedTime < suspendedTime) { + // This is the latest suspended level + root.latestSuspendedTime = suspendedTime; } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Committing Host Effects: " + count + " Total)", - "(Committing Host Effects)", - null - ); } + findNextPendingPriorityLevel(root); } -function startCommitLifeCyclesTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; +function markPingedPriorityLevel(root, pingedTime) { + var latestSuspendedTime = root.latestSuspendedTime; + if (latestSuspendedTime !== NoWork && latestSuspendedTime <= pingedTime) { + var latestPingedTime = root.latestPingedTime; + if (latestPingedTime === NoWork || latestPingedTime < pingedTime) { + root.latestPingedTime = pingedTime; } - effectCountInCurrentCommit = 0; - beginMark("(Calling Lifecycle Methods)"); } + findNextPendingPriorityLevel(root); } -function stopCommitLifeCyclesTimer() { - if (enableUserTimingAPI) { - if (!supportsUserTiming) { - return; - } - var count = effectCountInCurrentCommit; - effectCountInCurrentCommit = 0; - endMark( - "(Calling Lifecycle Methods: " + count + " Total)", - "(Calling Lifecycle Methods)", - null - ); +function findNextPendingPriorityLevel(root) { + var earliestSuspendedTime = root.earliestSuspendedTime; + var earliestPendingTime = root.earliestPendingTime; + var nextExpirationTimeToWorkOn = void 0; + var expirationTime = void 0; + if (earliestSuspendedTime === NoWork) { + // Fast path. There's no suspended work. + nextExpirationTimeToWorkOn = expirationTime = earliestPendingTime; + } else if (earliestPendingTime !== NoWork) { + // Check if there's known pending work. + nextExpirationTimeToWorkOn = earliestPendingTime; + expirationTime = + earliestSuspendedTime < earliestPendingTime + ? earliestSuspendedTime + : earliestPendingTime; + } else { + // Finally, if a suspended level was pinged, work on that. Otherwise there's + // nothing to work on. + nextExpirationTimeToWorkOn = expirationTime = root.latestPingedTime; + } + + if (root.didError) { + // Revert to synchronous mode. + expirationTime = Sync; } + + root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn; + root.expirationTime = expirationTime; } // UpdateQueue is a linked list of prioritized updates. @@ -5998,4634 +6458,4124 @@ function commitUpdateQueue( } } -var fakeInternalInstance = {}; -var isArray = Array.isArray; - -var didWarnAboutStateAssignmentForComponent = void 0; -var didWarnAboutUninitializedState = void 0; -var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0; -var didWarnAboutLegacyLifecyclesAndDerivedState = void 0; -var didWarnAboutUndefinedDerivedState = void 0; -var warnOnUndefinedDerivedState = void 0; -var warnOnInvalidCallback = void 0; - -{ - didWarnAboutStateAssignmentForComponent = new Set(); - didWarnAboutUninitializedState = new Set(); - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); - didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); - didWarnAboutUndefinedDerivedState = new Set(); - - var didWarnOnInvalidCallback = new Set(); - - warnOnInvalidCallback = function(callback, callerName) { - if (callback === null || typeof callback === "function") { - return; - } - var key = callerName + "_" + callback; - if (!didWarnOnInvalidCallback.has(key)) { - didWarnOnInvalidCallback.add(key); - warning( - false, - "%s(...): Expected the last optional `callback` argument to be a " + - "function. Instead received: %s.", - callerName, - callback - ); - } - }; - - warnOnUndefinedDerivedState = function(workInProgress, partialState) { - if (partialState === undefined) { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutUndefinedDerivedState.has(componentName)) { - didWarnAboutUndefinedDerivedState.add(componentName); - warning( - false, - "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + - "You have returned undefined.", - componentName - ); - } - } - }; - - // This is so gross but it's at least non-critical and can be removed if - // it causes problems. This is meant to give a nicer error message for - // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component, - // ...)) which otherwise throws a "_processChildContext is not a function" - // exception. - Object.defineProperty(fakeInternalInstance, "_processChildContext", { - enumerable: false, - value: function() { - invariant( - false, - "_processChildContext is not available in React 16+. This likely " + - "means you have multiple copies of React and are attempting to nest " + - "a React 15 tree inside a React 16 tree using " + - "unstable_renderSubtreeIntoContainer, which isn't supported. Try " + - "to make sure you have only one copy of React (and ideally, switch " + - "to ReactDOM.createPortal)." - ); - } - }); - Object.freeze(fakeInternalInstance); -} - -function applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - nextProps -) { - var prevState = workInProgress.memoizedState; - - { - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - // Invoke the function an extra time to help detect side-effects. - getDerivedStateFromProps(nextProps, prevState); - } - } - - var partialState = getDerivedStateFromProps(nextProps, prevState); - - { - warnOnUndefinedDerivedState(workInProgress, partialState); - } - // Merge the partial state and the previous state. - var memoizedState = - partialState === null || partialState === undefined - ? prevState - : Object.assign({}, prevState, partialState); - workInProgress.memoizedState = memoizedState; - - // Once the update queue is empty, persist the derived state onto the - // base state. - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null && updateQueue.expirationTime === NoWork) { - updateQueue.baseState = memoizedState; - } -} - -var ReactFiberClassComponent = function( - legacyContext, - scheduleWork, - computeExpirationForFiber, - memoizeProps, - memoizeState, - recalculateCurrentTime -) { - var cacheContext = legacyContext.cacheContext, - getMaskedContext = legacyContext.getMaskedContext, - getUnmaskedContext = legacyContext.getUnmaskedContext, - isContextConsumer = legacyContext.isContextConsumer, - hasContextChanged = legacyContext.hasContextChanged; - - var classComponentUpdater = { - isMounted: isMounted, - enqueueSetState: function(inst, payload, callback) { - var fiber = get$1(inst); - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); - - var update = createUpdate(expirationTime); - update.payload = payload; - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "setState"); - } - update.callback = callback; - } - - enqueueUpdate(fiber, update, expirationTime); - scheduleWork(fiber, expirationTime); - }, - enqueueReplaceState: function(inst, payload, callback) { - var fiber = get$1(inst); - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); - - var update = createUpdate(expirationTime); - update.tag = ReplaceState; - update.payload = payload; - - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "replaceState"); - } - update.callback = callback; - } - - enqueueUpdate(fiber, update, expirationTime); - scheduleWork(fiber, expirationTime); - }, - enqueueForceUpdate: function(inst, callback) { - var fiber = get$1(inst); - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); - - var update = createUpdate(expirationTime); - update.tag = ForceUpdate; - - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "forceUpdate"); - } - update.callback = callback; - } - - enqueueUpdate(fiber, update, expirationTime); - scheduleWork(fiber, expirationTime); - } - }; - - function checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - newState, - newContext - ) { - var instance = workInProgress.stateNode; - var ctor = workInProgress.type; - if (typeof instance.shouldComponentUpdate === "function") { - startPhaseTimer(workInProgress, "shouldComponentUpdate"); - var shouldUpdate = instance.shouldComponentUpdate( - newProps, - newState, - newContext - ); - 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; - } - - return shouldUpdate; - } - - if (ctor.prototype && ctor.prototype.isPureReactComponent) { - return ( - !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) - ); - } - - return true; - } +function createCapturedValue(value, source) { + // If the value is an error, call this function immediately after it is thrown + // so the stack is accurate. + return { + value: value, + source: source, + stack: getStackAddendumByWorkInProgressFiber(source) + }; +} - function checkClassInstance(workInProgress) { - var instance = workInProgress.stateNode; - var type = workInProgress.type; - { - var name = getComponentName(workInProgress) || "Component"; - var renderPresent = instance.render; +var providerCursor = createCursor(null); +var valueCursor = createCursor(null); +var changedBitsCursor = createCursor(0); - if (!renderPresent) { - if (type.prototype && typeof type.prototype.render === "function") { - warning( - false, - "%s(...): No `render` method found on the returned component " + - "instance: did you accidentally return an object from the constructor?", - name - ); - } else { - warning( - false, - "%s(...): No `render` method found on the returned component " + - "instance: you may have forgotten to define `render`.", - name - ); - } - } +var rendererSigil = void 0; +{ + // Use this to detect multiple renderers using the same context + rendererSigil = {}; +} - var noGetInitialStateOnES6 = - !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; - 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; - 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; - 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; - 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; - if ( - type.prototype && - type.prototype.isPureReactComponent && - typeof instance.shouldComponentUpdate !== "undefined" - ) { - warning( - false, - "%s has a method called shouldComponentUpdate(). " + - "shouldComponentUpdate should not be used when extending React.PureComponent. " + - "Please extend React.Component if shouldComponentUpdate is used.", - getComponentName(workInProgress) || "A pure component" - ); - } - 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; - 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; - var noComponentWillRecieveProps = - typeof instance.componentWillRecieveProps !== "function"; - !noComponentWillRecieveProps - ? warning( - false, - "%s has a method called " + - "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", - name - ) - : void 0; - 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; - 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; - 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; +function pushProvider(providerFiber) { + var context = providerFiber.type._context; - if ( - typeof instance.getSnapshotBeforeUpdate === "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) - ); - } + if (isPrimaryRenderer) { + push(changedBitsCursor, context._changedBits, providerFiber); + push(valueCursor, context._currentValue, providerFiber); + push(providerCursor, providerFiber, providerFiber); - 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 + context._currentValue = providerFiber.pendingProps.value; + context._changedBits = providerFiber.stateNode; + { + !( + context._currentRenderer === undefined || + context._currentRenderer === null || + context._currentRenderer === rendererSigil + ) ? warning( false, - "%s: getDerivedStateFromCatch() is defined as an instance method " + - "and will be ignored. Instead, declare it as a static method.", - name + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." ) : void 0; - var noStaticGetSnapshotBeforeUpdate = - typeof type.getSnapshotBeforeUpdate !== "function"; - !noStaticGetSnapshotBeforeUpdate + context._currentRenderer = rendererSigil; + } + } else { + push(changedBitsCursor, context._changedBits2, providerFiber); + push(valueCursor, context._currentValue2, providerFiber); + push(providerCursor, providerFiber, providerFiber); + + context._currentValue2 = providerFiber.pendingProps.value; + context._changedBits2 = providerFiber.stateNode; + { + !( + context._currentRenderer2 === undefined || + context._currentRenderer2 === null || + context._currentRenderer2 === rendererSigil + ) ? warning( false, - "%s: getSnapshotBeforeUpdate() is defined as a static method " + - "and will be ignored. Instead, declare it as an instance method.", - name + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." ) : 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; - } + context._currentRenderer2 = rendererSigil; } } +} - function adoptClassInstance(workInProgress, instance) { - instance.updater = classComponentUpdater; - workInProgress.stateNode = instance; - // The instance needs access to the fiber so that it can schedule updates - set(instance, workInProgress); - { - instance._reactInternalInstance = fakeInternalInstance; - } +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; + if (isPrimaryRenderer) { + context._currentValue = currentValue; + context._changedBits = changedBits; + } else { + context._currentValue2 = currentValue; + context._changedBits2 = changedBits; } +} - function constructClassInstance(workInProgress, props, renderExpirationTime) { - var ctor = workInProgress.type; - var unmaskedContext = getUnmaskedContext(workInProgress); - var needsContext = isContextConsumer(workInProgress); - var context = needsContext - ? getMaskedContext(workInProgress, unmaskedContext) - : emptyObject; +function getContextCurrentValue(context) { + return isPrimaryRenderer ? context._currentValue : context._currentValue2; +} - // Instantiate twice to help detect side-effects. - { - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - new ctor(props, context); // eslint-disable-line no-new - } - } +function getContextChangedBits(context) { + return isPrimaryRenderer ? context._changedBits : context._changedBits2; +} - var instance = new ctor(props, context); - var state = (workInProgress.memoizedState = - instance.state !== null && instance.state !== undefined - ? instance.state - : null); - adoptClassInstance(workInProgress, instance); +var NO_CONTEXT = {}; - { - if ( - typeof ctor.getDerivedStateFromProps === "function" && - state === null - ) { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutUninitializedState.has(componentName)) { - didWarnAboutUninitializedState.add(componentName); - warning( - false, - "%s: Did not properly initialize state during construction. " + - "Expected state to be an object, but it was %s.", - componentName, - instance.state === null ? "null" : "undefined" - ); - } - } +var contextStackCursor$1 = createCursor(NO_CONTEXT); +var contextFiberStackCursor = createCursor(NO_CONTEXT); +var rootInstanceStackCursor = createCursor(NO_CONTEXT); - // 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 : "" - ); - } - } - } - } +function requiredContext(c) { + invariant( + c !== NO_CONTEXT, + "Expected host context to exist. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + return c; +} - // Cache unmasked context so we can avoid recreating masked context unless necessary. - // ReactFiberContext usually updates this cache but can't for newly-created instances. - if (needsContext) { - cacheContext(workInProgress, unmaskedContext, context); - } +function getRootHostContainer() { + var rootInstance = requiredContext(rootInstanceStackCursor.current); + return rootInstance; +} - return instance; +function pushHostContainer(fiber, nextRootInstance) { + // Push current root instance onto the stack; + // This allows us to reset root when portals are popped. + push(rootInstanceStackCursor, nextRootInstance, fiber); + // Track the context and the Fiber that provided it. + // This enables us to pop only Fibers that provide unique contexts. + push(contextFiberStackCursor, fiber, fiber); + + // Finally, we need to push the host context to the stack. + // However, we can't just call getRootHostContext() and push it because + // we'd have a different number of entries on the stack depending on + // whether getRootHostContext() throws somewhere in renderer code or not. + // So we push an empty value first. This lets us safely unwind on errors. + push(contextStackCursor$1, NO_CONTEXT, fiber); + var nextRootContext = getRootHostContext(nextRootInstance); + // Now that we know this function doesn't throw, replace it. + pop(contextStackCursor$1, fiber); + push(contextStackCursor$1, nextRootContext, fiber); +} + +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} + +function getHostContext() { + var context = requiredContext(contextStackCursor$1.current); + return context; +} + +function pushHostContext(fiber) { + var rootInstance = requiredContext(rootInstanceStackCursor.current); + var context = requiredContext(contextStackCursor$1.current); + var nextContext = getChildHostContext(context, fiber.type, rootInstance); + + // Don't push this Fiber's context unless it's unique. + if (context === nextContext) { + return; } - function callComponentWillMount(workInProgress, instance) { - startPhaseTimer(workInProgress, "componentWillMount"); - var oldState = instance.state; + // Track the context and the Fiber that provided it. + // This enables us to pop only Fibers that provide unique contexts. + push(contextFiberStackCursor, fiber, fiber); + push(contextStackCursor$1, nextContext, fiber); +} - if (typeof instance.componentWillMount === "function") { - instance.componentWillMount(); - } - if (typeof instance.UNSAFE_componentWillMount === "function") { - instance.UNSAFE_componentWillMount(); - } +function popHostContext(fiber) { + // Do not pop unless this Fiber provided the current context. + // pushHostContext() only pushes Fibers that provide unique contexts. + if (contextFiberStackCursor.current !== fiber) { + return; + } - stopPhaseTimer(); + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); +} - if (oldState !== instance.state) { - { - warning( +var commitTime = 0; + +function getCommitTime() { + return commitTime; +} + +function recordCommitTime() { + if (!enableProfilerTimer) { + return; + } + commitTime = now(); +} + +/** + * The "actual" render time is total time required to render the descendants of a Profiler component. + * This time is stored as a stack, since Profilers can be nested. + * This time is started during the "begin" phase and stopped during the "complete" phase. + * It is paused (and accumulated) in the event of an interruption or an aborted render. + */ + +var fiberStack$1 = void 0; + +{ + fiberStack$1 = []; +} + +var timerPausedAt = 0; +var totalElapsedPauseTime = 0; + +function checkActualRenderTimeStackEmpty() { + if (!enableProfilerTimer) { + return; + } + { + !(fiberStack$1.length === 0) + ? warning( false, - "%s.componentWillMount(): Assigning directly to this.state is " + - "deprecated (except inside a component's " + - "constructor). Use setState instead.", - getComponentName(workInProgress) || "Component" - ); - } - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); - } + "Expected an empty stack. Something was not reset properly." + ) + : void 0; } +} - function callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newContext - ) { - var oldState = instance.state; - startPhaseTimer(workInProgress, "componentWillReceiveProps"); - if (typeof instance.componentWillReceiveProps === "function") { - instance.componentWillReceiveProps(newProps, newContext); - } - if (typeof instance.UNSAFE_componentWillReceiveProps === "function") { - instance.UNSAFE_componentWillReceiveProps(newProps, newContext); - } - stopPhaseTimer(); +function markActualRenderTimeStarted(fiber) { + if (!enableProfilerTimer) { + return; + } + { + fiberStack$1.push(fiber); + } - if (instance.state !== oldState) { - { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { - didWarnAboutStateAssignmentForComponent.add(componentName); - warning( - false, - "%s.componentWillReceiveProps(): Assigning directly to " + - "this.state is deprecated (except inside a component's " + - "constructor). Use setState instead.", - componentName - ); - } - } - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); + fiber.actualDuration = now() - fiber.actualDuration - totalElapsedPauseTime; + fiber.actualStartTime = now(); +} + +function pauseActualRenderTimerIfRunning() { + if (!enableProfilerTimer) { + return; + } + if (timerPausedAt === 0) { + timerPausedAt = now(); + } +} + +function recordElapsedActualRenderTime(fiber) { + if (!enableProfilerTimer) { + return; + } + { + !(fiber === fiberStack$1.pop()) + ? warning(false, "Unexpected Fiber (%s) popped.", getComponentName(fiber)) + : void 0; + } + + fiber.actualDuration = now() - totalElapsedPauseTime - fiber.actualDuration; +} + +function resetActualRenderTimer() { + if (!enableProfilerTimer) { + return; + } + totalElapsedPauseTime = 0; +} + +function resumeActualRenderTimerIfPaused() { + if (!enableProfilerTimer) { + return; + } + if (timerPausedAt > 0) { + totalElapsedPauseTime += now() - timerPausedAt; + timerPausedAt = 0; + } +} + +/** + * The "base" render time is the duration of the “begin” phase of work for a particular fiber. + * This time is measured and stored on each fiber. + * The time for all sibling fibers are accumulated and stored on their parent during the "complete" phase. + * If a fiber bails out (sCU false) then its "base" timer is cancelled and the fiber is not updated. + */ + +var baseStartTime = -1; + +function recordElapsedBaseRenderTimeIfRunning(fiber) { + if (!enableProfilerTimer) { + return; + } + if (baseStartTime !== -1) { + fiber.selfBaseTime = now() - baseStartTime; + } +} + +function startBaseRenderTimer() { + if (!enableProfilerTimer) { + return; + } + { + if (baseStartTime !== -1) { + warning( + false, + "Cannot start base timer that is already running. " + + "This error is likely caused by a bug in React. " + + "Please file an issue." + ); } } + baseStartTime = now(); +} - // Invokes the mount life-cycles on a previously never rendered instance. - function mountClassInstance(workInProgress, renderExpirationTime) { - var ctor = workInProgress.type; +function stopBaseRenderTimerIfRunning() { + if (!enableProfilerTimer) { + return; + } + baseStartTime = -1; +} - { - checkClassInstance(workInProgress); - } +/*eslint-disable no-self-compare */ - var instance = workInProgress.stateNode; - var props = workInProgress.pendingProps; - var unmaskedContext = getUnmaskedContext(workInProgress); +var hasOwnProperty = Object.prototype.hasOwnProperty; - instance.props = props; - instance.state = workInProgress.memoizedState; - instance.refs = emptyObject; - instance.context = getMaskedContext(workInProgress, unmaskedContext); +/** + * inlined Object.is polyfill to avoid requiring consumers ship their own + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + */ +function is(x, y) { + // SameValue algorithm + if (x === y) { + // Steps 1-5, 7-10 + // Steps 6.b-6.e: +0 != -0 + // Added the nonzero y check to make Flow happy, but it is redundant + return x !== 0 || y !== 0 || 1 / x === 1 / y; + } else { + // Step 6.a: NaN == NaN + return x !== x && y !== y; + } +} - { - if (workInProgress.mode & StrictMode) { - ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( - workInProgress, - instance - ); - } +/** + * Performs equality by iterating through keys on an object and returning false + * when any key has values which are not strictly equal between the arguments. + * Returns true when the values of all keys are strictly equal. + */ +function shallowEqual(objA, objB) { + if (is(objA, objB)) { + return true; + } - if (warnAboutDeprecatedLifecycles) { - ReactStrictModeWarnings.recordDeprecationWarnings( - workInProgress, - instance - ); - } - } + if ( + typeof objA !== "object" || + objA === null || + typeof objB !== "object" || + objB === null + ) { + return false; + } - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - props, - instance, - renderExpirationTime - ); - instance.state = workInProgress.memoizedState; - } + var keysA = Object.keys(objA); + var keysB = Object.keys(objB); - var getDerivedStateFromProps = workInProgress.type.getDerivedStateFromProps; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - props - ); - instance.state = workInProgress.memoizedState; - } + if (keysA.length !== keysB.length) { + return false; + } - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. + // Test for A's keys different from B. + for (var i = 0; i < keysA.length; i++) { if ( - typeof ctor.getDerivedStateFromProps !== "function" && - typeof instance.getSnapshotBeforeUpdate !== "function" && - (typeof instance.UNSAFE_componentWillMount === "function" || - typeof instance.componentWillMount === "function") + !hasOwnProperty.call(objB, keysA[i]) || + !is(objA[keysA[i]], objB[keysA[i]]) ) { - callComponentWillMount(workInProgress, instance); - // If we had additional state updates during this life-cycle, let's - // process them now. - updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - props, - instance, - renderExpirationTime - ); - instance.state = workInProgress.memoizedState; - } - } - - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; + return false; } } - function resumeMountClassInstance(workInProgress, renderExpirationTime) { - var ctor = workInProgress.type; - var instance = workInProgress.stateNode; + return true; +} - var oldProps = workInProgress.memoizedProps; - var newProps = workInProgress.pendingProps; - instance.props = oldProps; +var fakeInternalInstance = {}; +var isArray = Array.isArray; - var oldContext = instance.context; - var newUnmaskedContext = getUnmaskedContext(workInProgress); - var newContext = getMaskedContext(workInProgress, newUnmaskedContext); +var didWarnAboutStateAssignmentForComponent = void 0; +var didWarnAboutUninitializedState = void 0; +var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0; +var didWarnAboutLegacyLifecyclesAndDerivedState = void 0; +var didWarnAboutUndefinedDerivedState = void 0; +var warnOnUndefinedDerivedState = void 0; +var warnOnInvalidCallback = void 0; - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - var hasNewLifecycles = - typeof getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; +{ + didWarnAboutStateAssignmentForComponent = new Set(); + didWarnAboutUninitializedState = new Set(); + didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); + didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); + didWarnAboutUndefinedDerivedState = new Set(); - // 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. + var didWarnOnInvalidCallback = new Set(); - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillReceiveProps === "function" || - typeof instance.componentWillReceiveProps === "function") - ) { - if (oldProps !== newProps || oldContext !== newContext) { - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newContext - ); - } + warnOnInvalidCallback = function(callback, callerName) { + if (callback === null || typeof callback === "function") { + return; } - - resetHasForceUpdateBeforeProcessing(); - - var oldState = workInProgress.memoizedState; - var newState = (instance.state = oldState); - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime + var key = callerName + "_" + callback; + if (!didWarnOnInvalidCallback.has(key)) { + didWarnOnInvalidCallback.add(key); + warning( + false, + "%s(...): Expected the last optional `callback` argument to be a " + + "function. Instead received: %s.", + callerName, + callback ); - newState = workInProgress.memoizedState; } - if ( - oldProps === newProps && - oldState === newState && - !hasContextChanged() && - !checkHasForceUpdateAfterProcessing() - ) { - // 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. - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; + }; + + warnOnUndefinedDerivedState = function(workInProgress, partialState) { + if (partialState === undefined) { + var componentName = getComponentName(workInProgress) || "Component"; + if (!didWarnAboutUndefinedDerivedState.has(componentName)) { + didWarnAboutUndefinedDerivedState.add(componentName); + warning( + false, + "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + + "You have returned undefined.", + componentName + ); } - return false; } + }; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - newProps + // This is so gross but it's at least non-critical and can be removed if + // it causes problems. This is meant to give a nicer error message for + // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component, + // ...)) which otherwise throws a "_processChildContext is not a function" + // exception. + Object.defineProperty(fakeInternalInstance, "_processChildContext", { + enumerable: false, + value: function() { + invariant( + false, + "_processChildContext is not available in React 16+. This likely " + + "means you have multiple copies of React and are attempting to nest " + + "a React 15 tree inside a React 16 tree using " + + "unstable_renderSubtreeIntoContainer, which isn't supported. Try " + + "to make sure you have only one copy of React (and ideally, switch " + + "to ReactDOM.createPortal)." ); - newState = workInProgress.memoizedState; } + }); + Object.freeze(fakeInternalInstance); +} - var shouldUpdate = - checkHasForceUpdateAfterProcessing() || - checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - newState, - newContext - ); - - if (shouldUpdate) { - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillMount === "function" || - typeof instance.componentWillMount === "function") - ) { - startPhaseTimer(workInProgress, "componentWillMount"); - if (typeof instance.componentWillMount === "function") { - instance.componentWillMount(); - } - if (typeof instance.UNSAFE_componentWillMount === "function") { - instance.UNSAFE_componentWillMount(); - } - stopPhaseTimer(); - } - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; - } - } 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. - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; - } +function applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + nextProps +) { + var prevState = workInProgress.memoizedState; - // If shouldComponentUpdate returned false, we should still update the - // memoized state to indicate that this work can be reused. - workInProgress.memoizedProps = newProps; - workInProgress.memoizedState = newState; + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + // Invoke the function an extra time to help detect side-effects. + getDerivedStateFromProps(nextProps, prevState); } - - // Update the existing instance's state, props, and context pointers even - // if shouldComponentUpdate returns false. - instance.props = newProps; - instance.state = newState; - instance.context = newContext; - - return shouldUpdate; } - // Invokes the update life-cycles and returns false if it shouldn't rerender. - function updateClassInstance(current, workInProgress, renderExpirationTime) { - var ctor = workInProgress.type; - var instance = workInProgress.stateNode; - - var oldProps = workInProgress.memoizedProps; - var newProps = workInProgress.pendingProps; - instance.props = oldProps; + var partialState = getDerivedStateFromProps(nextProps, prevState); - var oldContext = instance.context; - var newUnmaskedContext = getUnmaskedContext(workInProgress); - var newContext = getMaskedContext(workInProgress, newUnmaskedContext); + { + warnOnUndefinedDerivedState(workInProgress, partialState); + } + // Merge the partial state and the previous state. + var memoizedState = + partialState === null || partialState === undefined + ? prevState + : Object.assign({}, prevState, partialState); + workInProgress.memoizedState = memoizedState; - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - var hasNewLifecycles = - typeof getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; + // Once the update queue is empty, persist the derived state onto the + // base state. + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null && updateQueue.expirationTime === NoWork) { + updateQueue.baseState = memoizedState; + } +} - // 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. +var classComponentUpdater = { + isMounted: isMounted, + enqueueSetState: function(inst, payload, callback) { + var fiber = get$1(inst); + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillReceiveProps === "function" || - typeof instance.componentWillReceiveProps === "function") - ) { - if (oldProps !== newProps || oldContext !== newContext) { - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newContext - ); + var update = createUpdate(expirationTime); + update.payload = payload; + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "setState"); } + update.callback = callback; } - resetHasForceUpdateBeforeProcessing(); + enqueueUpdate(fiber, update, expirationTime); + scheduleWork(fiber, expirationTime); + }, + enqueueReplaceState: function(inst, payload, callback) { + var fiber = get$1(inst); + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); - var oldState = workInProgress.memoizedState; - var newState = (instance.state = oldState); - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime - ); - newState = workInProgress.memoizedState; - } + var update = createUpdate(expirationTime); + update.tag = ReplaceState; + update.payload = payload; - if ( - oldProps === newProps && - oldState === newState && - !hasContextChanged() && - !checkHasForceUpdateAfterProcessing() - ) { - // 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. - if (typeof instance.componentDidUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Update; - } - } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Snapshot; - } + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "replaceState"); } - return false; + update.callback = callback; } - if (typeof getDerivedStateFromProps === "function") { - if (fireGetDerivedStateFromPropsOnStateUpdates || oldProps !== newProps) { - applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - newProps - ); - newState = workInProgress.memoizedState; + enqueueUpdate(fiber, update, expirationTime); + scheduleWork(fiber, expirationTime); + }, + enqueueForceUpdate: function(inst, callback) { + var fiber = get$1(inst); + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); + + var update = createUpdate(expirationTime); + update.tag = ForceUpdate; + + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "forceUpdate"); } + update.callback = callback; } - var shouldUpdate = - checkHasForceUpdateAfterProcessing() || - checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - newState, - newContext - ); + enqueueUpdate(fiber, update, expirationTime); + scheduleWork(fiber, expirationTime); + } +}; - if (shouldUpdate) { - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillUpdate === "function" || - typeof instance.componentWillUpdate === "function") - ) { - startPhaseTimer(workInProgress, "componentWillUpdate"); - if (typeof instance.componentWillUpdate === "function") { - instance.componentWillUpdate(newProps, newState, newContext); - } - if (typeof instance.UNSAFE_componentWillUpdate === "function") { - instance.UNSAFE_componentWillUpdate(newProps, newState, newContext); - } - stopPhaseTimer(); - } - 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. - if (typeof instance.componentDidUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Update; - } - } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Snapshot; - } - } +function checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext +) { + var instance = workInProgress.stateNode; + var ctor = workInProgress.type; + if (typeof instance.shouldComponentUpdate === "function") { + startPhaseTimer(workInProgress, "shouldComponentUpdate"); + var shouldUpdate = instance.shouldComponentUpdate( + newProps, + newState, + newContext + ); + stopPhaseTimer(); - // If shouldComponentUpdate returned false, we should still update the - // memoized props/state to indicate that this work can be reused. - workInProgress.memoizedProps = newProps; - workInProgress.memoizedState = newState; + { + !(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; } - // Update the existing instance's state, props, and context pointers even - // if shouldComponentUpdate returns false. - instance.props = newProps; - instance.state = newState; - instance.context = newContext; - return shouldUpdate; } - return { - adoptClassInstance: adoptClassInstance, - constructClassInstance: constructClassInstance, - mountClassInstance: mountClassInstance, - resumeMountClassInstance: resumeMountClassInstance, - updateClassInstance: updateClassInstance - }; -}; - -var getCurrentFiberStackAddendum$2 = - ReactDebugCurrentFiber.getCurrentFiberStackAddendum; + if (ctor.prototype && ctor.prototype.isPureReactComponent) { + return ( + !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) + ); + } -var didWarnAboutMaps = void 0; -var didWarnAboutStringRefInStrictMode = void 0; -var ownerHasKeyUseWarning = void 0; -var ownerHasFunctionTypeWarning = void 0; -var warnForMissingKey = function(child) {}; + return true; +} -{ - didWarnAboutMaps = false; - didWarnAboutStringRefInStrictMode = {}; +function checkClassInstance(workInProgress) { + var instance = workInProgress.stateNode; + var type = workInProgress.type; + { + var name = getComponentName(workInProgress) || "Component"; + var renderPresent = instance.render; - /** - * Warn if there's no key explicitly set on dynamic arrays of children or - * object keys are not valid. This allows us to keep track of children between - * updates. - */ - ownerHasKeyUseWarning = {}; - ownerHasFunctionTypeWarning = {}; + if (!renderPresent) { + if (type.prototype && typeof type.prototype.render === "function") { + warning( + false, + "%s(...): No `render` method found on the returned component " + + "instance: did you accidentally return an object from the constructor?", + name + ); + } else { + warning( + false, + "%s(...): No `render` method found on the returned component " + + "instance: you may have forgotten to define `render`.", + name + ); + } + } - warnForMissingKey = function(child) { - if (child === null || typeof child !== "object") { - return; + var noGetInitialStateOnES6 = + !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; + 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; + 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; + 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; + 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; + if ( + type.prototype && + type.prototype.isPureReactComponent && + typeof instance.shouldComponentUpdate !== "undefined" + ) { + warning( + false, + "%s has a method called shouldComponentUpdate(). " + + "shouldComponentUpdate should not be used when extending React.PureComponent. " + + "Please extend React.Component if shouldComponentUpdate is used.", + getComponentName(workInProgress) || "A pure component" + ); } - if (!child._store || child._store.validated || child.key != null) { - return; + 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; + 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; + var noComponentWillRecieveProps = + typeof instance.componentWillRecieveProps !== "function"; + !noComponentWillRecieveProps + ? warning( + false, + "%s has a method called " + + "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", + name + ) + : void 0; + 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; + 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; + 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; + + if ( + typeof instance.getSnapshotBeforeUpdate === "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) + ); } - invariant( - typeof child._store === "object", - "React Component in warnForMissingKey should have a _store. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - child._store.validated = true; - var currentComponentErrorInfo = - "Each child in an array or iterator should have a unique " + - '"key" prop. See https://fb.me/react-warning-keys for ' + - "more information." + - (getCurrentFiberStackAddendum$2() || ""); - if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { - return; + 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); } - ownerHasKeyUseWarning[currentComponentErrorInfo] = true; + 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; + } + } +} - warning( - false, - "Each child in an array or iterator should have a unique " + - '"key" prop. See https://fb.me/react-warning-keys for ' + - "more information.%s", - getCurrentFiberStackAddendum$2() - ); - }; +function adoptClassInstance(workInProgress, instance) { + instance.updater = classComponentUpdater; + workInProgress.stateNode = instance; + // The instance needs access to the fiber so that it can schedule updates + set(instance, workInProgress); + { + instance._reactInternalInstance = fakeInternalInstance; + } } -var isArray$1 = Array.isArray; +function constructClassInstance(workInProgress, props, renderExpirationTime) { + var ctor = workInProgress.type; + var unmaskedContext = getUnmaskedContext(workInProgress); + var needsContext = isContextConsumer(workInProgress); + var context = needsContext + ? getMaskedContext(workInProgress, unmaskedContext) + : emptyObject; -function coerceRef(returnFiber, current, element) { - var mixedRef = element.ref; - if ( - mixedRef !== null && - typeof mixedRef !== "function" && - typeof mixedRef !== "object" - ) { - { - if (returnFiber.mode & StrictMode) { - var componentName = getComponentName(returnFiber) || "Component"; - if (!didWarnAboutStringRefInStrictMode[componentName]) { - warning( - false, - 'A string ref, "%s", has been found within a strict mode tree. ' + - "String refs are a source of potential bugs and should be avoided. " + - "We recommend using createRef() instead." + - "\n%s" + - "\n\nLearn more about using refs safely here:" + - "\nhttps://fb.me/react-strict-mode-string-ref", - mixedRef, - getStackAddendumByWorkInProgressFiber(returnFiber) - ); - didWarnAboutStringRefInStrictMode[componentName] = true; - } - } + // Instantiate twice to help detect side-effects. + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + new ctor(props, context); // eslint-disable-line no-new } + } - if (element._owner) { - var owner = element._owner; - var inst = void 0; - if (owner) { - var ownerFiber = owner; - invariant( - ownerFiber.tag === ClassComponent, - "Stateless function components cannot have refs." + var instance = new ctor(props, context); + var state = (workInProgress.memoizedState = + instance.state !== null && instance.state !== undefined + ? instance.state + : null); + adoptClassInstance(workInProgress, instance); + + { + if (typeof ctor.getDerivedStateFromProps === "function" && state === null) { + var componentName = getComponentName(workInProgress) || "Component"; + if (!didWarnAboutUninitializedState.has(componentName)) { + didWarnAboutUninitializedState.add(componentName); + warning( + false, + "%s: Did not properly initialize state during construction. " + + "Expected state to be an object, but it was %s.", + componentName, + instance.state === null ? "null" : "undefined" ); - inst = ownerFiber.stateNode; } - invariant( - inst, - "Missing owner for string ref %s. This error is likely caused by a " + - "bug in React. Please file an issue.", - mixedRef - ); - var stringRef = "" + mixedRef; - // Check if previous string ref matches new string ref + } + + // 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 ( - current !== null && - current.ref !== null && - current.ref._stringRef === stringRef + typeof instance.componentWillMount === "function" && + instance.componentWillMount.__suppressDeprecationWarning !== true ) { - return current.ref; + foundWillMountName = "componentWillMount"; + } else if (typeof instance.UNSAFE_componentWillMount === "function") { + foundWillMountName = "UNSAFE_componentWillMount"; } - var ref = function(value) { - var refs = inst.refs === emptyObject ? (inst.refs = {}) : inst.refs; - if (value === null) { - delete refs[stringRef]; - } else { - refs[stringRef] = value; + 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 : "" + ); } - }; - ref._stringRef = stringRef; - return ref; - } else { - invariant( - typeof mixedRef === "string", - "Expected ref to be a function or a string." - ); - invariant( - element._owner, - "Element ref was specified as a string (%s) but no owner was set. This could happen for one of" + - " the following reasons:\n" + - "1. You may be adding a ref to a functional component\n" + - "2. You may be adding a ref to a component that was not created inside a component's render method\n" + - "3. You have multiple copies of React loaded\n" + - "See https://fb.me/react-refs-must-have-owner for more information.", - mixedRef + } + } + } + + // Cache unmasked context so we can avoid recreating masked context unless necessary. + // ReactFiberContext usually updates this cache but can't for newly-created instances. + if (needsContext) { + cacheContext(workInProgress, unmaskedContext, context); + } + + return instance; +} + +function callComponentWillMount(workInProgress, instance) { + startPhaseTimer(workInProgress, "componentWillMount"); + var oldState = instance.state; + + if (typeof instance.componentWillMount === "function") { + instance.componentWillMount(); + } + if (typeof instance.UNSAFE_componentWillMount === "function") { + instance.UNSAFE_componentWillMount(); + } + + stopPhaseTimer(); + + if (oldState !== instance.state) { + { + warning( + false, + "%s.componentWillMount(): Assigning directly to this.state is " + + "deprecated (except inside a component's " + + "constructor). Use setState instead.", + getComponentName(workInProgress) || "Component" ); } + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); } - return mixedRef; } -function throwOnInvalidObjectType(returnFiber, newChild) { - if (returnFiber.type !== "textarea") { - var addendum = ""; +function callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext +) { + var oldState = instance.state; + startPhaseTimer(workInProgress, "componentWillReceiveProps"); + if (typeof instance.componentWillReceiveProps === "function") { + instance.componentWillReceiveProps(newProps, newContext); + } + if (typeof instance.UNSAFE_componentWillReceiveProps === "function") { + instance.UNSAFE_componentWillReceiveProps(newProps, newContext); + } + stopPhaseTimer(); + + if (instance.state !== oldState) { { - addendum = - " If you meant to render a collection of children, use an array " + - "instead." + - (getCurrentFiberStackAddendum$2() || ""); + var componentName = getComponentName(workInProgress) || "Component"; + if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { + didWarnAboutStateAssignmentForComponent.add(componentName); + warning( + false, + "%s.componentWillReceiveProps(): Assigning directly to " + + "this.state is deprecated (except inside a component's " + + "constructor). Use setState instead.", + componentName + ); + } } - invariant( - false, - "Objects are not valid as a React child (found: %s).%s", - Object.prototype.toString.call(newChild) === "[object Object]" - ? "object with keys {" + Object.keys(newChild).join(", ") + "}" - : newChild, - addendum - ); + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); } } -function warnOnFunctionType() { - var currentComponentErrorInfo = - "Functions are not valid as a React child. This may happen if " + - "you return a Component instead of from render. " + - "Or maybe you meant to call this function rather than return it." + - (getCurrentFiberStackAddendum$2() || ""); +// Invokes the mount life-cycles on a previously never rendered instance. +function mountClassInstance(workInProgress, renderExpirationTime) { + var ctor = workInProgress.type; - if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) { - return; + { + checkClassInstance(workInProgress); } - ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; - warning( - false, - "Functions are not valid as a React child. This may happen if " + - "you return a Component instead of from render. " + - "Or maybe you meant to call this function rather than return it.%s", - getCurrentFiberStackAddendum$2() || "" - ); -} + var instance = workInProgress.stateNode; + var props = workInProgress.pendingProps; + var unmaskedContext = getUnmaskedContext(workInProgress); -// This wrapper function exists because I expect to clone the code in each path -// to be able to optimize each path individually by branching early. This needs -// a compiler or we can do it manually. Helpers that don't need this branching -// live outside of this function. -function ChildReconciler(shouldTrackSideEffects) { - function deleteChild(returnFiber, childToDelete) { - if (!shouldTrackSideEffects) { - // Noop. - return; + instance.props = props; + instance.state = workInProgress.memoizedState; + instance.refs = emptyObject; + instance.context = getMaskedContext(workInProgress, unmaskedContext); + + { + if (workInProgress.mode & StrictMode) { + ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( + workInProgress, + instance + ); + + ReactStrictModeWarnings.recordLegacyContextWarning( + workInProgress, + instance + ); } - // Deletions are added in reversed order so we add it to the front. - // At this point, the return fiber's effect list is empty except for - // deletions, so we can just append the deletion to the list. The remaining - // effects aren't added until the complete phase. Once we implement - // resuming, this may not be true. - var last = returnFiber.lastEffect; - if (last !== null) { - last.nextEffect = childToDelete; - returnFiber.lastEffect = childToDelete; - } else { - returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; + + if (warnAboutDeprecatedLifecycles) { + ReactStrictModeWarnings.recordDeprecationWarnings( + workInProgress, + instance + ); } - childToDelete.nextEffect = null; - childToDelete.effectTag = Deletion; } - function deleteRemainingChildren(returnFiber, currentFirstChild) { - if (!shouldTrackSideEffects) { - // Noop. - return null; + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + props, + instance, + renderExpirationTime + ); + instance.state = workInProgress.memoizedState; + } + + var getDerivedStateFromProps = workInProgress.type.getDerivedStateFromProps; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps(workInProgress, getDerivedStateFromProps, props); + instance.state = workInProgress.memoizedState; + } + + // In order to support react-lifecycles-compat polyfilled components, + // Unsafe lifecycles should not be invoked for components using the new APIs. + if ( + typeof ctor.getDerivedStateFromProps !== "function" && + typeof instance.getSnapshotBeforeUpdate !== "function" && + (typeof instance.UNSAFE_componentWillMount === "function" || + typeof instance.componentWillMount === "function") + ) { + callComponentWillMount(workInProgress, instance); + // If we had additional state updates during this life-cycle, let's + // process them now. + updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + props, + instance, + renderExpirationTime + ); + instance.state = workInProgress.memoizedState; } + } - // TODO: For the shouldClone case, this could be micro-optimized a bit by - // assuming that after the first child we've already added everything. - var childToDelete = currentFirstChild; - while (childToDelete !== null) { - deleteChild(returnFiber, childToDelete); - childToDelete = childToDelete.sibling; + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; + } +} + +function resumeMountClassInstance(workInProgress, renderExpirationTime) { + var ctor = workInProgress.type; + var instance = workInProgress.stateNode; + + var oldProps = workInProgress.memoizedProps; + var newProps = workInProgress.pendingProps; + instance.props = oldProps; + + var oldContext = instance.context; + var newUnmaskedContext = getUnmaskedContext(workInProgress); + var newContext = getMaskedContext(workInProgress, newUnmaskedContext); + + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + var hasNewLifecycles = + typeof 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. + if ( + !hasNewLifecycles && + (typeof instance.UNSAFE_componentWillReceiveProps === "function" || + typeof instance.componentWillReceiveProps === "function") + ) { + if (oldProps !== newProps || oldContext !== newContext) { + callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext + ); } - return null; } - function mapRemainingChildren(returnFiber, currentFirstChild) { - // Add the remaining children to a temporary map so that we can find them by - // keys quickly. Implicit (null) keys get added to this set with their index - var existingChildren = new Map(); + resetHasForceUpdateBeforeProcessing(); - var existingChild = currentFirstChild; - while (existingChild !== null) { - if (existingChild.key !== null) { - existingChildren.set(existingChild.key, existingChild); - } else { - existingChildren.set(existingChild.index, existingChild); - } - existingChild = existingChild.sibling; + var oldState = workInProgress.memoizedState; + var newState = (instance.state = oldState); + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + newProps, + instance, + renderExpirationTime + ); + newState = workInProgress.memoizedState; + } + if ( + oldProps === newProps && + oldState === newState && + !hasContextChanged() && + !checkHasForceUpdateAfterProcessing() + ) { + // 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. + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; } - return existingChildren; + return false; } - function useFiber(fiber, pendingProps, expirationTime) { - // We currently set sibling to null and index to 0 here because it is easy - // to forget to do before returning it. E.g. for the single child case. - var clone = createWorkInProgress(fiber, pendingProps, expirationTime); - clone.index = 0; - clone.sibling = null; - return clone; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + newProps + ); + newState = workInProgress.memoizedState; } - function placeChild(newFiber, lastPlacedIndex, newIndex) { - newFiber.index = newIndex; - if (!shouldTrackSideEffects) { - // Noop. - return lastPlacedIndex; - } - var current = newFiber.alternate; - if (current !== null) { - var oldIndex = current.index; - if (oldIndex < lastPlacedIndex) { - // This is a move. - newFiber.effectTag = Placement; - return lastPlacedIndex; - } else { - // This item can stay in place. - return oldIndex; + var shouldUpdate = + checkHasForceUpdateAfterProcessing() || + checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext + ); + + if (shouldUpdate) { + // In order to support react-lifecycles-compat polyfilled components, + // Unsafe lifecycles should not be invoked for components using the new APIs. + if ( + !hasNewLifecycles && + (typeof instance.UNSAFE_componentWillMount === "function" || + typeof instance.componentWillMount === "function") + ) { + startPhaseTimer(workInProgress, "componentWillMount"); + if (typeof instance.componentWillMount === "function") { + instance.componentWillMount(); } - } else { - // This is an insertion. - newFiber.effectTag = Placement; - return lastPlacedIndex; + if (typeof instance.UNSAFE_componentWillMount === "function") { + instance.UNSAFE_componentWillMount(); + } + stopPhaseTimer(); } - } - - function placeSingleChild(newFiber) { - // This is simpler for the single child case. We only need to do a - // placement for inserting new children. - if (shouldTrackSideEffects && newFiber.alternate === null) { - newFiber.effectTag = Placement; + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; } - return newFiber; + } 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. + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; + } + + // If shouldComponentUpdate returned false, we should still update the + // memoized state to indicate that this work can be reused. + workInProgress.memoizedProps = newProps; + workInProgress.memoizedState = newState; } - function updateTextNode(returnFiber, current, textContent, expirationTime) { - if (current === null || current.tag !== HostText) { - // Insert - var created = createFiberFromText( - textContent, - returnFiber.mode, - expirationTime + // Update the existing instance's state, props, and context pointers even + // if shouldComponentUpdate returns false. + instance.props = newProps; + instance.state = newState; + instance.context = newContext; + + return shouldUpdate; +} + +// Invokes the update life-cycles and returns false if it shouldn't rerender. +function updateClassInstance(current, workInProgress, renderExpirationTime) { + var ctor = workInProgress.type; + var instance = workInProgress.stateNode; + + var oldProps = workInProgress.memoizedProps; + var newProps = workInProgress.pendingProps; + instance.props = oldProps; + + var oldContext = instance.context; + var newUnmaskedContext = getUnmaskedContext(workInProgress); + var newContext = getMaskedContext(workInProgress, newUnmaskedContext); + + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + var hasNewLifecycles = + typeof 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. + if ( + !hasNewLifecycles && + (typeof instance.UNSAFE_componentWillReceiveProps === "function" || + typeof instance.componentWillReceiveProps === "function") + ) { + if (oldProps !== newProps || oldContext !== newContext) { + callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current, textContent, expirationTime); - existing.return = returnFiber; - return existing; } } - function updateElement(returnFiber, current, element, expirationTime) { - if (current !== null && current.type === element.type) { - // Move based on index - var existing = useFiber(current, element.props, expirationTime); - existing.ref = coerceRef(returnFiber, current, element); - existing.return = returnFiber; - { - existing._debugSource = element._source; - existing._debugOwner = element._owner; + resetHasForceUpdateBeforeProcessing(); + + var oldState = workInProgress.memoizedState; + var newState = (instance.state = oldState); + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + newProps, + instance, + renderExpirationTime + ); + newState = workInProgress.memoizedState; + } + + if ( + oldProps === newProps && + oldState === newState && + !hasContextChanged() && + !checkHasForceUpdateAfterProcessing() + ) { + // 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. + if (typeof instance.componentDidUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + workInProgress.effectTag |= Update; } - return existing; - } else { - // Insert - var created = createFiberFromElement( - element, - returnFiber.mode, - expirationTime - ); - created.ref = coerceRef(returnFiber, current, element); - created.return = returnFiber; - return created; } + if (typeof instance.getSnapshotBeforeUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + workInProgress.effectTag |= Snapshot; + } + } + return false; } - function updatePortal(returnFiber, current, portal, expirationTime) { + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + newProps + ); + newState = workInProgress.memoizedState; + } + + var shouldUpdate = + checkHasForceUpdateAfterProcessing() || + checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext + ); + + if (shouldUpdate) { + // In order to support react-lifecycles-compat polyfilled components, + // Unsafe lifecycles should not be invoked for components using the new APIs. if ( - current === null || - current.tag !== HostPortal || - current.stateNode.containerInfo !== portal.containerInfo || - current.stateNode.implementation !== portal.implementation + !hasNewLifecycles && + (typeof instance.UNSAFE_componentWillUpdate === "function" || + typeof instance.componentWillUpdate === "function") ) { - // Insert - var created = createFiberFromPortal( - portal, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current, portal.children || [], expirationTime); - existing.return = returnFiber; - return existing; + startPhaseTimer(workInProgress, "componentWillUpdate"); + if (typeof instance.componentWillUpdate === "function") { + instance.componentWillUpdate(newProps, newState, newContext); + } + if (typeof instance.UNSAFE_componentWillUpdate === "function") { + instance.UNSAFE_componentWillUpdate(newProps, newState, newContext); + } + stopPhaseTimer(); } - } - - function updateFragment(returnFiber, current, fragment, expirationTime, key) { - if (current === null || current.tag !== Fragment) { - // Insert - var created = createFiberFromFragment( - fragment, - returnFiber.mode, - expirationTime, - key - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current, fragment, expirationTime); - existing.return = returnFiber; - return existing; + 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. + if (typeof instance.componentDidUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + 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. + workInProgress.memoizedProps = newProps; + workInProgress.memoizedState = newState; } - function createChild(returnFiber, newChild, expirationTime) { - if (typeof newChild === "string" || typeof newChild === "number") { - // Text nodes don't have keys. If the previous node is implicitly keyed - // we can continue to replace it without aborting even if it is not a text - // node. - var created = createFiberFromText( - "" + newChild, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } + // Update the existing instance's state, props, and context pointers even + // if shouldComponentUpdate returns false. + instance.props = newProps; + instance.state = newState; + instance.context = newContext; - if (typeof newChild === "object" && newChild !== null) { - switch (newChild.$$typeof) { - case REACT_ELEMENT_TYPE: { - var _created = createFiberFromElement( - newChild, - returnFiber.mode, - expirationTime - ); - _created.ref = coerceRef(returnFiber, null, newChild); - _created.return = returnFiber; - return _created; - } - case REACT_PORTAL_TYPE: { - var _created2 = createFiberFromPortal( - newChild, - returnFiber.mode, - expirationTime - ); - _created2.return = returnFiber; - return _created2; - } - } + return shouldUpdate; +} - if (isArray$1(newChild) || getIteratorFn(newChild)) { - var _created3 = createFiberFromFragment( - newChild, - returnFiber.mode, - expirationTime, - null - ); - _created3.return = returnFiber; - return _created3; - } +var getCurrentFiberStackAddendum$2 = + ReactDebugCurrentFiber.getCurrentFiberStackAddendum; - throwOnInvalidObjectType(returnFiber, newChild); +var didWarnAboutMaps = void 0; +var didWarnAboutStringRefInStrictMode = void 0; +var ownerHasKeyUseWarning = void 0; +var ownerHasFunctionTypeWarning = void 0; +var warnForMissingKey = function(child) {}; + +{ + didWarnAboutMaps = false; + didWarnAboutStringRefInStrictMode = {}; + + /** + * Warn if there's no key explicitly set on dynamic arrays of children or + * object keys are not valid. This allows us to keep track of children between + * updates. + */ + ownerHasKeyUseWarning = {}; + ownerHasFunctionTypeWarning = {}; + + warnForMissingKey = function(child) { + if (child === null || typeof child !== "object") { + return; + } + if (!child._store || child._store.validated || child.key != null) { + return; + } + invariant( + typeof child._store === "object", + "React Component in warnForMissingKey should have a _store. " + + "This error is likely caused by a bug in React. Please file an issue." + ); + child._store.validated = true; + + var currentComponentErrorInfo = + "Each child in an array or iterator should have a unique " + + '"key" prop. See https://fb.me/react-warning-keys for ' + + "more information." + + (getCurrentFiberStackAddendum$2() || ""); + if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { + return; } + ownerHasKeyUseWarning[currentComponentErrorInfo] = true; + + warning( + false, + "Each child in an array or iterator should have a unique " + + '"key" prop. See https://fb.me/react-warning-keys for ' + + "more information.%s", + getCurrentFiberStackAddendum$2() + ); + }; +} +var isArray$1 = Array.isArray; + +function coerceRef(returnFiber, current, element) { + var mixedRef = element.ref; + if ( + mixedRef !== null && + typeof mixedRef !== "function" && + typeof mixedRef !== "object" + ) { { - if (typeof newChild === "function") { - warnOnFunctionType(); + if (returnFiber.mode & StrictMode) { + var componentName = getComponentName(returnFiber) || "Component"; + if (!didWarnAboutStringRefInStrictMode[componentName]) { + warning( + false, + 'A string ref, "%s", has been found within a strict mode tree. ' + + "String refs are a source of potential bugs and should be avoided. " + + "We recommend using createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + mixedRef, + getStackAddendumByWorkInProgressFiber(returnFiber) + ); + didWarnAboutStringRefInStrictMode[componentName] = true; + } } } - return null; - } - - function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { - // Update the fiber if the keys match, otherwise return null. - - var key = oldFiber !== null ? oldFiber.key : null; - - if (typeof newChild === "string" || typeof newChild === "number") { - // Text nodes don't have keys. If the previous node is implicitly keyed - // we can continue to replace it without aborting even if it is not a text - // node. - if (key !== null) { - return null; + if (element._owner) { + var owner = element._owner; + var inst = void 0; + if (owner) { + var ownerFiber = owner; + invariant( + ownerFiber.tag === ClassComponent, + "Stateless function components cannot have refs." + ); + inst = ownerFiber.stateNode; } - return updateTextNode( - returnFiber, - oldFiber, - "" + newChild, - expirationTime + invariant( + inst, + "Missing owner for string ref %s. This error is likely caused by a " + + "bug in React. Please file an issue.", + mixedRef ); - } - - if (typeof newChild === "object" && newChild !== null) { - switch (newChild.$$typeof) { - case REACT_ELEMENT_TYPE: { - if (newChild.key === key) { - if (newChild.type === REACT_FRAGMENT_TYPE) { - return updateFragment( - returnFiber, - oldFiber, - newChild.props.children, - expirationTime, - key - ); - } - return updateElement( - returnFiber, - oldFiber, - newChild, - expirationTime - ); - } else { - return null; - } - } - case REACT_PORTAL_TYPE: { - if (newChild.key === key) { - return updatePortal( - returnFiber, - oldFiber, - newChild, - expirationTime - ); - } else { - return null; - } - } + var stringRef = "" + mixedRef; + // Check if previous string ref matches new string ref + if ( + current !== null && + current.ref !== null && + typeof current.ref === "function" && + current.ref._stringRef === stringRef + ) { + return current.ref; } - - if (isArray$1(newChild) || getIteratorFn(newChild)) { - if (key !== null) { - return null; + var ref = function(value) { + var refs = inst.refs === emptyObject ? (inst.refs = {}) : inst.refs; + if (value === null) { + delete refs[stringRef]; + } else { + refs[stringRef] = value; } - - return updateFragment( - returnFiber, - oldFiber, - newChild, - expirationTime, - null - ); - } - - throwOnInvalidObjectType(returnFiber, newChild); + }; + ref._stringRef = stringRef; + return ref; + } else { + invariant( + typeof mixedRef === "string", + "Expected ref to be a function or a string." + ); + invariant( + element._owner, + "Element ref was specified as a string (%s) but no owner was set. This could happen for one of" + + " the following reasons:\n" + + "1. You may be adding a ref to a functional component\n" + + "2. You may be adding a ref to a component that was not created inside a component's render method\n" + + "3. You have multiple copies of React loaded\n" + + "See https://fb.me/react-refs-must-have-owner for more information.", + mixedRef + ); } + } + return mixedRef; +} +function throwOnInvalidObjectType(returnFiber, newChild) { + if (returnFiber.type !== "textarea") { + var addendum = ""; { - if (typeof newChild === "function") { - warnOnFunctionType(); - } + addendum = + " If you meant to render a collection of children, use an array " + + "instead." + + (getCurrentFiberStackAddendum$2() || ""); } - - return null; + invariant( + false, + "Objects are not valid as a React child (found: %s).%s", + Object.prototype.toString.call(newChild) === "[object Object]" + ? "object with keys {" + Object.keys(newChild).join(", ") + "}" + : newChild, + addendum + ); } +} - function updateFromMap( - existingChildren, - returnFiber, - newIdx, - newChild, - expirationTime - ) { - if (typeof newChild === "string" || typeof newChild === "number") { - // Text nodes don't have keys, so we neither have to check the old nor - // new node for the key. If both are text nodes, they match. - var matchedFiber = existingChildren.get(newIdx) || null; - return updateTextNode( - returnFiber, - matchedFiber, - "" + newChild, - expirationTime - ); - } +function warnOnFunctionType() { + var currentComponentErrorInfo = + "Functions are not valid as a React child. This may happen if " + + "you return a Component instead of from render. " + + "Or maybe you meant to call this function rather than return it." + + (getCurrentFiberStackAddendum$2() || ""); - if (typeof newChild === "object" && newChild !== null) { - switch (newChild.$$typeof) { - case REACT_ELEMENT_TYPE: { - var _matchedFiber = - existingChildren.get( - newChild.key === null ? newIdx : newChild.key - ) || null; - if (newChild.type === REACT_FRAGMENT_TYPE) { - return updateFragment( - returnFiber, - _matchedFiber, - newChild.props.children, - expirationTime, - newChild.key - ); - } - return updateElement( - returnFiber, - _matchedFiber, - newChild, - expirationTime - ); - } - case REACT_PORTAL_TYPE: { - var _matchedFiber2 = - existingChildren.get( - newChild.key === null ? newIdx : newChild.key - ) || null; - return updatePortal( - returnFiber, - _matchedFiber2, - newChild, - expirationTime - ); - } - } + if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) { + return; + } + ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; - if (isArray$1(newChild) || getIteratorFn(newChild)) { - var _matchedFiber3 = existingChildren.get(newIdx) || null; - return updateFragment( - returnFiber, - _matchedFiber3, - newChild, - expirationTime, - null - ); - } + warning( + false, + "Functions are not valid as a React child. This may happen if " + + "you return a Component instead of from render. " + + "Or maybe you meant to call this function rather than return it.%s", + getCurrentFiberStackAddendum$2() || "" + ); +} + +// This wrapper function exists because I expect to clone the code in each path +// to be able to optimize each path individually by branching early. This needs +// a compiler or we can do it manually. Helpers that don't need this branching +// live outside of this function. +function ChildReconciler(shouldTrackSideEffects) { + function deleteChild(returnFiber, childToDelete) { + if (!shouldTrackSideEffects) { + // Noop. + return; + } + // Deletions are added in reversed order so we add it to the front. + // At this point, the return fiber's effect list is empty except for + // deletions, so we can just append the deletion to the list. The remaining + // effects aren't added until the complete phase. Once we implement + // resuming, this may not be true. + var last = returnFiber.lastEffect; + if (last !== null) { + last.nextEffect = childToDelete; + returnFiber.lastEffect = childToDelete; + } else { + returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; + } + childToDelete.nextEffect = null; + childToDelete.effectTag = Deletion; + } - throwOnInvalidObjectType(returnFiber, newChild); + function deleteRemainingChildren(returnFiber, currentFirstChild) { + if (!shouldTrackSideEffects) { + // Noop. + return null; } - { - if (typeof newChild === "function") { - warnOnFunctionType(); - } + // TODO: For the shouldClone case, this could be micro-optimized a bit by + // assuming that after the first child we've already added everything. + var childToDelete = currentFirstChild; + while (childToDelete !== null) { + deleteChild(returnFiber, childToDelete); + childToDelete = childToDelete.sibling; } - return null; } - /** - * Warns if there is a duplicate or missing key - */ - function warnOnInvalidKey(child, knownKeys) { - { - if (typeof child !== "object" || child === null) { - return knownKeys; - } - switch (child.$$typeof) { - case REACT_ELEMENT_TYPE: - case REACT_PORTAL_TYPE: - warnForMissingKey(child); - var key = child.key; - if (typeof key !== "string") { - break; - } - if (knownKeys === null) { - knownKeys = new Set(); - knownKeys.add(key); - break; - } - if (!knownKeys.has(key)) { - knownKeys.add(key); - break; - } - warning( - false, - "Encountered two children with the same key, `%s`. " + - "Keys should be unique so that components maintain their identity " + - "across updates. Non-unique keys may cause children to be " + - "duplicated and/or omitted — the behavior is unsupported and " + - "could change in a future version.%s", - key, - getCurrentFiberStackAddendum$2() - ); - break; - default: - break; + function mapRemainingChildren(returnFiber, currentFirstChild) { + // Add the remaining children to a temporary map so that we can find them by + // keys quickly. Implicit (null) keys get added to this set with their index + var existingChildren = new Map(); + + var existingChild = currentFirstChild; + while (existingChild !== null) { + if (existingChild.key !== null) { + existingChildren.set(existingChild.key, existingChild); + } else { + existingChildren.set(existingChild.index, existingChild); } + existingChild = existingChild.sibling; } - return knownKeys; + return existingChildren; } - function reconcileChildrenArray( - returnFiber, - currentFirstChild, - newChildren, - expirationTime - ) { - // This algorithm can't optimize by searching from boths ends since we - // don't have backpointers on fibers. I'm trying to see how far we can get - // with that model. If it ends up not being worth the tradeoffs, we can - // add it later. - - // Even with a two ended optimization, we'd want to optimize for the case - // where there are few changes and brute force the comparison instead of - // going for the Map. It'd like to explore hitting that path first in - // forward-only mode and only go for the Map once we notice that we need - // lots of look ahead. This doesn't handle reversal as well as two ended - // search but that's unusual. Besides, for the two ended optimization to - // work on Iterables, we'd need to copy the whole set. - - // In this first iteration, we'll just live with hitting the bad case - // (adding everything to a Map) in for every insert/move. - - // If you change this code, also update reconcileChildrenIterator() which - // uses the same algorithm. + function useFiber(fiber, pendingProps, expirationTime) { + // We currently set sibling to null and index to 0 here because it is easy + // to forget to do before returning it. E.g. for the single child case. + var clone = createWorkInProgress(fiber, pendingProps, expirationTime); + clone.index = 0; + clone.sibling = null; + return clone; + } - { - // First, validate keys. - var knownKeys = null; - for (var i = 0; i < newChildren.length; i++) { - var child = newChildren[i]; - knownKeys = warnOnInvalidKey(child, knownKeys); - } + function placeChild(newFiber, lastPlacedIndex, newIndex) { + newFiber.index = newIndex; + if (!shouldTrackSideEffects) { + // Noop. + return lastPlacedIndex; } - - var resultingFirstChild = null; - var previousNewFiber = null; - - var oldFiber = currentFirstChild; - var lastPlacedIndex = 0; - var newIdx = 0; - var nextOldFiber = null; - for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) { - if (oldFiber.index > newIdx) { - nextOldFiber = oldFiber; - oldFiber = null; - } else { - nextOldFiber = oldFiber.sibling; - } - var newFiber = updateSlot( - returnFiber, - oldFiber, - newChildren[newIdx], - expirationTime - ); - if (newFiber === null) { - // TODO: This breaks on empty slots like null children. That's - // unfortunate because it triggers the slow path all the time. We need - // a better way to communicate whether this was a miss or null, - // boolean, undefined, etc. - if (oldFiber === null) { - oldFiber = nextOldFiber; - } - break; - } - if (shouldTrackSideEffects) { - if (oldFiber && newFiber.alternate === null) { - // We matched the slot, but we didn't reuse the existing fiber, so we - // need to delete the existing child. - deleteChild(returnFiber, oldFiber); - } - } - lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - // TODO: Move out of the loop. This only happens for the first run. - resultingFirstChild = newFiber; + var current = newFiber.alternate; + if (current !== null) { + var oldIndex = current.index; + if (oldIndex < lastPlacedIndex) { + // This is a move. + newFiber.effectTag = Placement; + return lastPlacedIndex; } else { - // TODO: Defer siblings if we're not at the right index for this slot. - // I.e. if we had null values before, then we want to defer this - // for each null value. However, we also don't want to call updateSlot - // with the previous one. - previousNewFiber.sibling = newFiber; + // This item can stay in place. + return oldIndex; } - previousNewFiber = newFiber; - oldFiber = nextOldFiber; - } - - if (newIdx === newChildren.length) { - // We've reached the end of the new children. We can delete the rest. - deleteRemainingChildren(returnFiber, oldFiber); - return resultingFirstChild; + } else { + // This is an insertion. + newFiber.effectTag = Placement; + return lastPlacedIndex; } + } - if (oldFiber === null) { - // If we don't have any more existing children we can choose a fast path - // since the rest will all be insertions. - for (; newIdx < newChildren.length; newIdx++) { - var _newFiber = createChild( - returnFiber, - newChildren[newIdx], - expirationTime - ); - if (!_newFiber) { - continue; - } - lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - // TODO: Move out of the loop. This only happens for the first run. - resultingFirstChild = _newFiber; - } else { - previousNewFiber.sibling = _newFiber; - } - previousNewFiber = _newFiber; - } - return resultingFirstChild; + function placeSingleChild(newFiber) { + // This is simpler for the single child case. We only need to do a + // placement for inserting new children. + if (shouldTrackSideEffects && newFiber.alternate === null) { + newFiber.effectTag = Placement; } + return newFiber; + } - // Add all children to a key map for quick lookups. - var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - - // Keep scanning and use the map to restore deleted items as moves. - for (; newIdx < newChildren.length; newIdx++) { - var _newFiber2 = updateFromMap( - existingChildren, - returnFiber, - newIdx, - newChildren[newIdx], + function updateTextNode(returnFiber, current, textContent, expirationTime) { + if (current === null || current.tag !== HostText) { + // Insert + var created = createFiberFromText( + textContent, + returnFiber.mode, expirationTime ); - if (_newFiber2) { - if (shouldTrackSideEffects) { - if (_newFiber2.alternate !== null) { - // The new fiber is a work in progress, but if there exists a - // current, that means that we reused the fiber. We need to delete - // it from the child list so that we don't add it to the deletion - // list. - existingChildren.delete( - _newFiber2.key === null ? newIdx : _newFiber2.key - ); - } - } - lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - resultingFirstChild = _newFiber2; - } else { - previousNewFiber.sibling = _newFiber2; - } - previousNewFiber = _newFiber2; - } - } - - if (shouldTrackSideEffects) { - // Any existing children that weren't consumed above were deleted. We need - // to add them to the deletion list. - existingChildren.forEach(function(child) { - return deleteChild(returnFiber, child); - }); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber(current, textContent, expirationTime); + existing.return = returnFiber; + return existing; } - - return resultingFirstChild; } - function reconcileChildrenIterator( - returnFiber, - currentFirstChild, - newChildrenIterable, - expirationTime - ) { - // This is the same implementation as reconcileChildrenArray(), - // but using the iterator instead. - - var iteratorFn = getIteratorFn(newChildrenIterable); - invariant( - typeof iteratorFn === "function", - "An object is not an iterable. This error is likely caused by a bug in " + - "React. Please file an issue." - ); - - { - // Warn about using Maps as children - 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$2() - ) - : void 0; - didWarnAboutMaps = true; - } - } - - // First, validate keys. - // We'll get a different iterator later for the main pass. - var _newChildren = iteratorFn.call(newChildrenIterable); - if (_newChildren) { - var knownKeys = null; - var _step = _newChildren.next(); - for (; !_step.done; _step = _newChildren.next()) { - var child = _step.value; - knownKeys = warnOnInvalidKey(child, knownKeys); - } + function updateElement(returnFiber, current, element, expirationTime) { + if (current !== null && current.type === element.type) { + // Move based on index + var existing = useFiber(current, element.props, expirationTime); + existing.ref = coerceRef(returnFiber, current, element); + existing.return = returnFiber; + { + existing._debugSource = element._source; + existing._debugOwner = element._owner; } + return existing; + } else { + // Insert + var created = createFiberFromElement( + element, + returnFiber.mode, + expirationTime + ); + created.ref = coerceRef(returnFiber, current, element); + created.return = returnFiber; + return created; } + } - var newChildren = iteratorFn.call(newChildrenIterable); - invariant(newChildren != null, "An iterable object provided no iterator."); - - var resultingFirstChild = null; - var previousNewFiber = null; + function updatePortal(returnFiber, current, portal, expirationTime) { + if ( + current === null || + current.tag !== HostPortal || + current.stateNode.containerInfo !== portal.containerInfo || + current.stateNode.implementation !== portal.implementation + ) { + // Insert + var created = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber(current, portal.children || [], expirationTime); + existing.return = returnFiber; + return existing; + } + } - var oldFiber = currentFirstChild; - var lastPlacedIndex = 0; - var newIdx = 0; - var nextOldFiber = null; + function updateFragment(returnFiber, current, fragment, expirationTime, key) { + if (current === null || current.tag !== Fragment) { + // Insert + var created = createFiberFromFragment( + fragment, + returnFiber.mode, + expirationTime, + key + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber(current, fragment, expirationTime); + existing.return = returnFiber; + return existing; + } + } - var step = newChildren.next(); - for ( - ; - oldFiber !== null && !step.done; - newIdx++, step = newChildren.next() - ) { - if (oldFiber.index > newIdx) { - nextOldFiber = oldFiber; - oldFiber = null; - } else { - nextOldFiber = oldFiber.sibling; - } - var newFiber = updateSlot( - returnFiber, - oldFiber, - step.value, + function createChild(returnFiber, newChild, expirationTime) { + if (typeof newChild === "string" || typeof newChild === "number") { + // Text nodes don't have keys. If the previous node is implicitly keyed + // we can continue to replace it without aborting even if it is not a text + // node. + var created = createFiberFromText( + "" + newChild, + returnFiber.mode, expirationTime ); - if (newFiber === null) { - // TODO: This breaks on empty slots like null children. That's - // unfortunate because it triggers the slow path all the time. We need - // a better way to communicate whether this was a miss or null, - // boolean, undefined, etc. - if (!oldFiber) { - oldFiber = nextOldFiber; + created.return = returnFiber; + return created; + } + + if (typeof newChild === "object" && newChild !== null) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: { + var _created = createFiberFromElement( + newChild, + returnFiber.mode, + expirationTime + ); + _created.ref = coerceRef(returnFiber, null, newChild); + _created.return = returnFiber; + return _created; } - break; - } - if (shouldTrackSideEffects) { - if (oldFiber && newFiber.alternate === null) { - // We matched the slot, but we didn't reuse the existing fiber, so we - // need to delete the existing child. - deleteChild(returnFiber, oldFiber); + case REACT_PORTAL_TYPE: { + var _created2 = createFiberFromPortal( + newChild, + returnFiber.mode, + expirationTime + ); + _created2.return = returnFiber; + return _created2; } } - lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - // TODO: Move out of the loop. This only happens for the first run. - resultingFirstChild = newFiber; - } else { - // TODO: Defer siblings if we're not at the right index for this slot. - // I.e. if we had null values before, then we want to defer this - // for each null value. However, we also don't want to call updateSlot - // with the previous one. - previousNewFiber.sibling = newFiber; + + if (isArray$1(newChild) || getIteratorFn(newChild)) { + var _created3 = createFiberFromFragment( + newChild, + returnFiber.mode, + expirationTime, + null + ); + _created3.return = returnFiber; + return _created3; } - previousNewFiber = newFiber; - oldFiber = nextOldFiber; - } - if (step.done) { - // We've reached the end of the new children. We can delete the rest. - deleteRemainingChildren(returnFiber, oldFiber); - return resultingFirstChild; + throwOnInvalidObjectType(returnFiber, newChild); } - if (oldFiber === null) { - // If we don't have any more existing children we can choose a fast path - // since the rest will all be insertions. - for (; !step.done; newIdx++, step = newChildren.next()) { - var _newFiber3 = createChild(returnFiber, step.value, expirationTime); - if (_newFiber3 === null) { - continue; - } - lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - // TODO: Move out of the loop. This only happens for the first run. - resultingFirstChild = _newFiber3; - } else { - previousNewFiber.sibling = _newFiber3; - } - previousNewFiber = _newFiber3; + { + if (typeof newChild === "function") { + warnOnFunctionType(); } - return resultingFirstChild; } - // Add all children to a key map for quick lookups. - var existingChildren = mapRemainingChildren(returnFiber, oldFiber); + return null; + } - // Keep scanning and use the map to restore deleted items as moves. - for (; !step.done; newIdx++, step = newChildren.next()) { - var _newFiber4 = updateFromMap( - existingChildren, + function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { + // Update the fiber if the keys match, otherwise return null. + + var key = oldFiber !== null ? oldFiber.key : null; + + if (typeof newChild === "string" || typeof newChild === "number") { + // Text nodes don't have keys. If the previous node is implicitly keyed + // we can continue to replace it without aborting even if it is not a text + // node. + if (key !== null) { + return null; + } + return updateTextNode( returnFiber, - newIdx, - step.value, + oldFiber, + "" + newChild, expirationTime ); - if (_newFiber4 !== null) { - if (shouldTrackSideEffects) { - if (_newFiber4.alternate !== null) { - // The new fiber is a work in progress, but if there exists a - // current, that means that we reused the fiber. We need to delete - // it from the child list so that we don't add it to the deletion - // list. - existingChildren.delete( - _newFiber4.key === null ? newIdx : _newFiber4.key + } + + if (typeof newChild === "object" && newChild !== null) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: { + if (newChild.key === key) { + if (newChild.type === REACT_FRAGMENT_TYPE) { + return updateFragment( + returnFiber, + oldFiber, + newChild.props.children, + expirationTime, + key + ); + } + return updateElement( + returnFiber, + oldFiber, + newChild, + expirationTime ); + } else { + return null; } } - lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - resultingFirstChild = _newFiber4; - } else { - previousNewFiber.sibling = _newFiber4; + case REACT_PORTAL_TYPE: { + if (newChild.key === key) { + return updatePortal( + returnFiber, + oldFiber, + newChild, + expirationTime + ); + } else { + return null; + } } - previousNewFiber = _newFiber4; } + + if (isArray$1(newChild) || getIteratorFn(newChild)) { + if (key !== null) { + return null; + } + + return updateFragment( + returnFiber, + oldFiber, + newChild, + expirationTime, + null + ); + } + + throwOnInvalidObjectType(returnFiber, newChild); } - if (shouldTrackSideEffects) { - // Any existing children that weren't consumed above were deleted. We need - // to add them to the deletion list. - existingChildren.forEach(function(child) { - return deleteChild(returnFiber, child); - }); + { + if (typeof newChild === "function") { + warnOnFunctionType(); + } } - return resultingFirstChild; + return null; } - function reconcileSingleTextNode( + function updateFromMap( + existingChildren, returnFiber, - currentFirstChild, - textContent, + newIdx, + newChild, expirationTime ) { - // There's no need to check for keys on text nodes since we don't have a - // way to define them. - if (currentFirstChild !== null && currentFirstChild.tag === HostText) { - // We already have an existing node so let's just update it and delete - // the rest. - deleteRemainingChildren(returnFiber, currentFirstChild.sibling); - var existing = useFiber(currentFirstChild, textContent, expirationTime); - existing.return = returnFiber; - return existing; + if (typeof newChild === "string" || typeof newChild === "number") { + // Text nodes don't have keys, so we neither have to check the old nor + // new node for the key. If both are text nodes, they match. + var matchedFiber = existingChildren.get(newIdx) || null; + return updateTextNode( + returnFiber, + matchedFiber, + "" + newChild, + expirationTime + ); } - // The existing first child is not a text node so we need to create one - // and delete the existing ones. - deleteRemainingChildren(returnFiber, currentFirstChild); - var created = createFiberFromText( - textContent, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } - function reconcileSingleElement( - returnFiber, - currentFirstChild, - element, - expirationTime - ) { - var key = element.key; - var child = currentFirstChild; - while (child !== null) { - // TODO: If key === null and child.key === null, then this only applies to - // the first item in the list. - if (child.key === key) { - if ( - child.tag === Fragment - ? element.type === REACT_FRAGMENT_TYPE - : child.type === element.type - ) { - deleteRemainingChildren(returnFiber, child.sibling); - var existing = useFiber( - child, - element.type === REACT_FRAGMENT_TYPE - ? element.props.children - : element.props, + if (typeof newChild === "object" && newChild !== null) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: { + var _matchedFiber = + existingChildren.get( + newChild.key === null ? newIdx : newChild.key + ) || null; + if (newChild.type === REACT_FRAGMENT_TYPE) { + return updateFragment( + returnFiber, + _matchedFiber, + newChild.props.children, + expirationTime, + newChild.key + ); + } + return updateElement( + returnFiber, + _matchedFiber, + newChild, + expirationTime + ); + } + case REACT_PORTAL_TYPE: { + var _matchedFiber2 = + existingChildren.get( + newChild.key === null ? newIdx : newChild.key + ) || null; + return updatePortal( + returnFiber, + _matchedFiber2, + newChild, expirationTime ); - existing.ref = coerceRef(returnFiber, child, element); - existing.return = returnFiber; - { - existing._debugSource = element._source; - existing._debugOwner = element._owner; - } - return existing; - } else { - deleteRemainingChildren(returnFiber, child); - break; } - } else { - deleteChild(returnFiber, child); } - child = child.sibling; + + if (isArray$1(newChild) || getIteratorFn(newChild)) { + var _matchedFiber3 = existingChildren.get(newIdx) || null; + return updateFragment( + returnFiber, + _matchedFiber3, + newChild, + expirationTime, + null + ); + } + + throwOnInvalidObjectType(returnFiber, newChild); } - if (element.type === REACT_FRAGMENT_TYPE) { - var created = createFiberFromFragment( - element.props.children, - returnFiber.mode, - expirationTime, - element.key - ); - created.return = returnFiber; - return created; - } else { - var _created4 = createFiberFromElement( - element, - returnFiber.mode, - expirationTime - ); - _created4.ref = coerceRef(returnFiber, currentFirstChild, element); - _created4.return = returnFiber; - return _created4; + { + if (typeof newChild === "function") { + warnOnFunctionType(); + } } + + return null; } - function reconcileSinglePortal( - returnFiber, - currentFirstChild, - portal, - expirationTime - ) { - var key = portal.key; - var child = currentFirstChild; - while (child !== null) { - // TODO: If key === null and child.key === null, then this only applies to - // the first item in the list. - if (child.key === key) { - if ( - child.tag === HostPortal && - child.stateNode.containerInfo === portal.containerInfo && - child.stateNode.implementation === portal.implementation - ) { - deleteRemainingChildren(returnFiber, child.sibling); - var existing = useFiber(child, portal.children || [], expirationTime); - existing.return = returnFiber; - return existing; - } else { - deleteRemainingChildren(returnFiber, child); + /** + * Warns if there is a duplicate or missing key + */ + function warnOnInvalidKey(child, knownKeys) { + { + if (typeof child !== "object" || child === null) { + return knownKeys; + } + switch (child.$$typeof) { + case REACT_ELEMENT_TYPE: + case REACT_PORTAL_TYPE: + warnForMissingKey(child); + var key = child.key; + if (typeof key !== "string") { + break; + } + if (knownKeys === null) { + knownKeys = new Set(); + knownKeys.add(key); + break; + } + if (!knownKeys.has(key)) { + knownKeys.add(key); + break; + } + warning( + false, + "Encountered two children with the same key, `%s`. " + + "Keys should be unique so that components maintain their identity " + + "across updates. Non-unique keys may cause children to be " + + "duplicated and/or omitted — the behavior is unsupported and " + + "could change in a future version.%s", + key, + getCurrentFiberStackAddendum$2() + ); + break; + default: break; - } - } else { - deleteChild(returnFiber, child); } - child = child.sibling; } - - var created = createFiberFromPortal( - portal, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; + return knownKeys; } - // This API will tag the children with the side-effect of the reconciliation - // itself. They will be added to the side-effect list as we pass through the - // children and the parent. - function reconcileChildFibers( + function reconcileChildrenArray( returnFiber, currentFirstChild, - newChild, + newChildren, expirationTime ) { - // This function is not recursive. - // If the top level item is an array, we treat it as a set of children, - // not as a fragment. Nested arrays on the other hand will be treated as - // fragment nodes. Recursion happens at the normal flow. + // This algorithm can't optimize by searching from boths ends since we + // don't have backpointers on fibers. I'm trying to see how far we can get + // with that model. If it ends up not being worth the tradeoffs, we can + // add it later. - // Handle top level unkeyed fragments as if they were arrays. - // This leads to an ambiguity between <>{[...]} and <>.... - // We treat the ambiguous cases above the same. - if ( - typeof newChild === "object" && - newChild !== null && - newChild.type === REACT_FRAGMENT_TYPE && - newChild.key === null - ) { - newChild = newChild.props.children; - } + // Even with a two ended optimization, we'd want to optimize for the case + // where there are few changes and brute force the comparison instead of + // going for the Map. It'd like to explore hitting that path first in + // forward-only mode and only go for the Map once we notice that we need + // lots of look ahead. This doesn't handle reversal as well as two ended + // search but that's unusual. Besides, for the two ended optimization to + // work on Iterables, we'd need to copy the whole set. - // Handle object types - var isObject = typeof newChild === "object" && newChild !== null; + // In this first iteration, we'll just live with hitting the bad case + // (adding everything to a Map) in for every insert/move. - if (isObject) { - switch (newChild.$$typeof) { - case REACT_ELEMENT_TYPE: - return placeSingleChild( - reconcileSingleElement( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ) - ); - case REACT_PORTAL_TYPE: - return placeSingleChild( - reconcileSinglePortal( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ) - ); - } - } + // If you change this code, also update reconcileChildrenIterator() which + // uses the same algorithm. - if (typeof newChild === "string" || typeof newChild === "number") { - return placeSingleChild( - reconcileSingleTextNode( - returnFiber, - currentFirstChild, - "" + newChild, - expirationTime - ) - ); + { + // First, validate keys. + var knownKeys = null; + for (var i = 0; i < newChildren.length; i++) { + var child = newChildren[i]; + knownKeys = warnOnInvalidKey(child, knownKeys); + } } - if (isArray$1(newChild)) { - return reconcileChildrenArray( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ); - } + var resultingFirstChild = null; + var previousNewFiber = null; - if (getIteratorFn(newChild)) { - return reconcileChildrenIterator( + var oldFiber = currentFirstChild; + var lastPlacedIndex = 0; + var newIdx = 0; + var nextOldFiber = null; + for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) { + if (oldFiber.index > newIdx) { + nextOldFiber = oldFiber; + oldFiber = null; + } else { + nextOldFiber = oldFiber.sibling; + } + var newFiber = updateSlot( returnFiber, - currentFirstChild, - newChild, + oldFiber, + newChildren[newIdx], expirationTime ); + if (newFiber === null) { + // TODO: This breaks on empty slots like null children. That's + // unfortunate because it triggers the slow path all the time. We need + // a better way to communicate whether this was a miss or null, + // boolean, undefined, etc. + if (oldFiber === null) { + oldFiber = nextOldFiber; + } + break; + } + if (shouldTrackSideEffects) { + if (oldFiber && newFiber.alternate === null) { + // We matched the slot, but we didn't reuse the existing fiber, so we + // need to delete the existing child. + deleteChild(returnFiber, oldFiber); + } + } + lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + // TODO: Move out of the loop. This only happens for the first run. + resultingFirstChild = newFiber; + } else { + // TODO: Defer siblings if we're not at the right index for this slot. + // I.e. if we had null values before, then we want to defer this + // for each null value. However, we also don't want to call updateSlot + // with the previous one. + previousNewFiber.sibling = newFiber; + } + previousNewFiber = newFiber; + oldFiber = nextOldFiber; } - if (isObject) { - throwOnInvalidObjectType(returnFiber, newChild); + if (newIdx === newChildren.length) { + // We've reached the end of the new children. We can delete the rest. + deleteRemainingChildren(returnFiber, oldFiber); + return resultingFirstChild; } - { - if (typeof newChild === "function") { - warnOnFunctionType(); - } - } - if (typeof newChild === "undefined") { - // If the new child is undefined, and the return fiber is a composite - // component, throw an error. If Fiber return types are disabled, - // we already threw above. - switch (returnFiber.tag) { - case ClassComponent: { - { - var instance = returnFiber.stateNode; - if (instance.render._isMockFunction) { - // We allow auto-mocks to proceed as if they're returning null. - break; - } - } + if (oldFiber === null) { + // If we don't have any more existing children we can choose a fast path + // since the rest will all be insertions. + for (; newIdx < newChildren.length; newIdx++) { + var _newFiber = createChild( + returnFiber, + newChildren[newIdx], + expirationTime + ); + if (!_newFiber) { + continue; } - // Intentionally fall through to the next case, which handles both - // functions and classes - // eslint-disable-next-lined no-fallthrough - case FunctionalComponent: { - var Component = returnFiber.type; - invariant( - false, - "%s(...): Nothing was returned from render. This usually means a " + - "return statement is missing. Or, to render nothing, " + - "return null.", - Component.displayName || Component.name || "Component" - ); + lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + // TODO: Move out of the loop. This only happens for the first run. + resultingFirstChild = _newFiber; + } else { + previousNewFiber.sibling = _newFiber; } + previousNewFiber = _newFiber; } + return resultingFirstChild; } - // Remaining cases are all treated as empty. - return deleteRemainingChildren(returnFiber, currentFirstChild); - } - - return reconcileChildFibers; -} - -var reconcileChildFibers = ChildReconciler(true); -var mountChildFibers = ChildReconciler(false); - -function cloneChildFibers(current, workInProgress) { - invariant( - current === null || workInProgress.child === current.child, - "Resuming work not yet implemented." - ); - - if (workInProgress.child === null) { - return; - } - - var currentChild = workInProgress.child; - var newChild = createWorkInProgress( - currentChild, - currentChild.pendingProps, - currentChild.expirationTime - ); - workInProgress.child = newChild; - - newChild.return = workInProgress; - while (currentChild.sibling !== null) { - currentChild = currentChild.sibling; - newChild = newChild.sibling = createWorkInProgress( - currentChild, - currentChild.pendingProps, - currentChild.expirationTime - ); - newChild.return = workInProgress; - } - newChild.sibling = null; -} - -var getCurrentFiberStackAddendum = - ReactDebugCurrentFiber.getCurrentFiberStackAddendum; + // Add all children to a key map for quick lookups. + var existingChildren = mapRemainingChildren(returnFiber, oldFiber); -var didWarnAboutBadClass = void 0; -var didWarnAboutGetDerivedStateOnFunctionalComponent = void 0; -var didWarnAboutStatelessRefs = void 0; + // Keep scanning and use the map to restore deleted items as moves. + for (; newIdx < newChildren.length; newIdx++) { + var _newFiber2 = updateFromMap( + existingChildren, + returnFiber, + newIdx, + newChildren[newIdx], + expirationTime + ); + if (_newFiber2) { + if (shouldTrackSideEffects) { + if (_newFiber2.alternate !== null) { + // The new fiber is a work in progress, but if there exists a + // current, that means that we reused the fiber. We need to delete + // it from the child list so that we don't add it to the deletion + // list. + existingChildren.delete( + _newFiber2.key === null ? newIdx : _newFiber2.key + ); + } + } + lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + resultingFirstChild = _newFiber2; + } else { + previousNewFiber.sibling = _newFiber2; + } + previousNewFiber = _newFiber2; + } + } -{ - didWarnAboutBadClass = {}; - didWarnAboutGetDerivedStateOnFunctionalComponent = {}; - didWarnAboutStatelessRefs = {}; -} + if (shouldTrackSideEffects) { + // Any existing children that weren't consumed above were deleted. We need + // to add them to the deletion list. + existingChildren.forEach(function(child) { + return deleteChild(returnFiber, child); + }); + } -var ReactFiberBeginWork = function( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - scheduleWork, - computeExpirationForFiber, - profilerTimer, - recalculateCurrentTime -) { - var shouldSetTextContent = config.shouldSetTextContent, - shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree; - var pushHostContext = hostContext.pushHostContext, - pushHostContainer = hostContext.pushHostContainer; - var pushProvider = newContext.pushProvider, - getContextCurrentValue = newContext.getContextCurrentValue, - getContextChangedBits = newContext.getContextChangedBits; - var markActualRenderTimeStarted = profilerTimer.markActualRenderTimeStarted, - stopBaseRenderTimerIfRunning = profilerTimer.stopBaseRenderTimerIfRunning; - 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, - memoizeState, - recalculateCurrentTime - ), - adoptClassInstance = _ReactFiberClassCompo.adoptClassInstance, - constructClassInstance = _ReactFiberClassCompo.constructClassInstance, - mountClassInstance = _ReactFiberClassCompo.mountClassInstance, - resumeMountClassInstance = _ReactFiberClassCompo.resumeMountClassInstance, - updateClassInstance = _ReactFiberClassCompo.updateClassInstance; - - // TODO: Remove this and use reconcileChildrenAtExpirationTime directly. - - function reconcileChildren(current, workInProgress, nextChildren) { - reconcileChildrenAtExpirationTime( - current, - workInProgress, - nextChildren, - workInProgress.expirationTime - ); + return resultingFirstChild; } - function reconcileChildrenAtExpirationTime( - current, - workInProgress, - nextChildren, - renderExpirationTime + function reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChildrenIterable, + expirationTime ) { - if (current === null) { - // If this is a fresh new component that hasn't been rendered yet, we - // won't update its child set by applying minimal side-effects. Instead, - // we will add them all to the child before it gets rendered. That means - // we can optimize this reconciliation pass by not tracking side-effects. - workInProgress.child = mountChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime - ); - } else { - // If the current child is the same as the work in progress, it means that - // we haven't yet started any work on these children. Therefore, we use - // the clone algorithm to create a copy of all the current children. + // This is the same implementation as reconcileChildrenArray(), + // but using the iterator instead. - // If we had any progressed work already, that is invalid at this point so - // let's throw it out. - workInProgress.child = reconcileChildFibers( - workInProgress, - current.child, - nextChildren, - renderExpirationTime - ); - } - } + var iteratorFn = getIteratorFn(newChildrenIterable); + invariant( + typeof iteratorFn === "function", + "An object is not an iterable. This error is likely caused by a bug in " + + "React. Please file an issue." + ); - function updateForwardRef(current, workInProgress) { - var render = workInProgress.type.render; - var nextProps = workInProgress.pendingProps; - var ref = workInProgress.ref; - if (hasLegacyContextChanged()) { - // 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) { - var currentRef = current !== null ? current.ref : null; - if (ref === currentRef) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); + { + // Warn about using Maps as children + if (newChildrenIterable.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$2() + ) + : void 0; + didWarnAboutMaps = true; } - } - var nextChildren = void 0; - { - ReactCurrentOwner.current = workInProgress; - ReactDebugCurrentFiber.setCurrentPhase("render"); - nextChildren = render(nextProps, ref); - ReactDebugCurrentFiber.setCurrentPhase(null); + // First, validate keys. + // We'll get a different iterator later for the main pass. + var _newChildren = iteratorFn.call(newChildrenIterable); + if (_newChildren) { + var knownKeys = null; + var _step = _newChildren.next(); + for (; !_step.done; _step = _newChildren.next()) { + var child = _step.value; + knownKeys = warnOnInvalidKey(child, knownKeys); + } + } } - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextProps); - return workInProgress.child; - } + var newChildren = iteratorFn.call(newChildrenIterable); + invariant(newChildren != null, "An iterable object provided no iterator."); - function updateFragment(current, workInProgress) { - var nextChildren = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { - // 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) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextChildren); - return workInProgress.child; - } + var resultingFirstChild = null; + var previousNewFiber = null; - function updateMode(current, workInProgress) { - var nextChildren = workInProgress.pendingProps.children; - if (hasLegacyContextChanged()) { - // 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 ( - nextChildren === null || - workInProgress.memoizedProps === nextChildren + var oldFiber = currentFirstChild; + var lastPlacedIndex = 0; + var newIdx = 0; + var nextOldFiber = null; + + var step = newChildren.next(); + for ( + ; + oldFiber !== null && !step.done; + newIdx++, step = newChildren.next() ) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); + if (oldFiber.index > newIdx) { + nextOldFiber = oldFiber; + oldFiber = null; + } else { + nextOldFiber = oldFiber.sibling; + } + var newFiber = updateSlot( + returnFiber, + oldFiber, + step.value, + expirationTime + ); + if (newFiber === null) { + // TODO: This breaks on empty slots like null children. That's + // unfortunate because it triggers the slow path all the time. We need + // a better way to communicate whether this was a miss or null, + // boolean, undefined, etc. + if (!oldFiber) { + oldFiber = nextOldFiber; + } + break; + } + if (shouldTrackSideEffects) { + if (oldFiber && newFiber.alternate === null) { + // We matched the slot, but we didn't reuse the existing fiber, so we + // need to delete the existing child. + deleteChild(returnFiber, oldFiber); + } + } + lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + // TODO: Move out of the loop. This only happens for the first run. + resultingFirstChild = newFiber; + } else { + // TODO: Defer siblings if we're not at the right index for this slot. + // I.e. if we had null values before, then we want to defer this + // for each null value. However, we also don't want to call updateSlot + // with the previous one. + previousNewFiber.sibling = newFiber; + } + previousNewFiber = newFiber; + oldFiber = nextOldFiber; } - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextChildren); - return workInProgress.child; - } - - function updateProfiler(current, workInProgress) { - var nextProps = workInProgress.pendingProps; - if (enableProfilerTimer) { - // Start render timer here and push start time onto queue - markActualRenderTimeStarted(workInProgress); - // Let the "complete" phase know to stop the timer, - // And the scheduler to record the measured time. - workInProgress.effectTag |= Update; - } - if (workInProgress.memoizedProps === nextProps) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); + if (step.done) { + // We've reached the end of the new children. We can delete the rest. + deleteRemainingChildren(returnFiber, oldFiber); + return resultingFirstChild; } - var nextChildren = nextProps.children; - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextProps); - return workInProgress.child; - } - function markRef(current, workInProgress) { - var ref = workInProgress.ref; - if ( - (current === null && ref !== null) || - (current !== null && current.ref !== ref) - ) { - // Schedule a Ref effect - workInProgress.effectTag |= Ref; + if (oldFiber === null) { + // If we don't have any more existing children we can choose a fast path + // since the rest will all be insertions. + for (; !step.done; newIdx++, step = newChildren.next()) { + var _newFiber3 = createChild(returnFiber, step.value, expirationTime); + if (_newFiber3 === null) { + continue; + } + lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + // TODO: Move out of the loop. This only happens for the first run. + resultingFirstChild = _newFiber3; + } else { + previousNewFiber.sibling = _newFiber3; + } + previousNewFiber = _newFiber3; + } + return resultingFirstChild; } - } - function updateFunctionalComponent(current, workInProgress) { - var fn = workInProgress.type; - var nextProps = workInProgress.pendingProps; + // Add all children to a key map for quick lookups. + var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - if (hasLegacyContextChanged()) { - // 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) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); + // Keep scanning and use the map to restore deleted items as moves. + for (; !step.done; newIdx++, step = newChildren.next()) { + var _newFiber4 = updateFromMap( + existingChildren, + returnFiber, + newIdx, + step.value, + expirationTime + ); + if (_newFiber4 !== null) { + if (shouldTrackSideEffects) { + if (_newFiber4.alternate !== null) { + // The new fiber is a work in progress, but if there exists a + // current, that means that we reused the fiber. We need to delete + // it from the child list so that we don't add it to the deletion + // list. + existingChildren.delete( + _newFiber4.key === null ? newIdx : _newFiber4.key + ); + } + } + lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + resultingFirstChild = _newFiber4; + } else { + previousNewFiber.sibling = _newFiber4; + } + previousNewFiber = _newFiber4; } - // TODO: consider bringing fn.shouldComponentUpdate() back. - // It used to be here. } - var unmaskedContext = getUnmaskedContext(workInProgress); - var context = getMaskedContext(workInProgress, unmaskedContext); + if (shouldTrackSideEffects) { + // Any existing children that weren't consumed above were deleted. We need + // to add them to the deletion list. + existingChildren.forEach(function(child) { + return deleteChild(returnFiber, child); + }); + } - var nextChildren = void 0; + return resultingFirstChild; + } - { - ReactCurrentOwner.current = workInProgress; - ReactDebugCurrentFiber.setCurrentPhase("render"); - nextChildren = fn(nextProps, context); - ReactDebugCurrentFiber.setCurrentPhase(null); + function reconcileSingleTextNode( + returnFiber, + currentFirstChild, + textContent, + expirationTime + ) { + // There's no need to check for keys on text nodes since we don't have a + // way to define them. + if (currentFirstChild !== null && currentFirstChild.tag === HostText) { + // We already have an existing node so let's just update it and delete + // the rest. + deleteRemainingChildren(returnFiber, currentFirstChild.sibling); + var existing = useFiber(currentFirstChild, textContent, expirationTime); + existing.return = returnFiber; + return existing; } - // React DevTools reads this flag. - workInProgress.effectTag |= PerformedWork; - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextProps); - return workInProgress.child; + // The existing first child is not a text node so we need to create one + // and delete the existing ones. + deleteRemainingChildren(returnFiber, currentFirstChild); + var created = createFiberFromText( + textContent, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; } - function updateClassComponent(current, workInProgress, renderExpirationTime) { - // 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 shouldUpdate = void 0; - if (current === null) { - if (workInProgress.stateNode === null) { - // In the initial pass we might need to construct the instance. - constructClassInstance( - workInProgress, - workInProgress.pendingProps, - renderExpirationTime - ); - mountClassInstance(workInProgress, renderExpirationTime); - - shouldUpdate = true; + function reconcileSingleElement( + returnFiber, + currentFirstChild, + element, + expirationTime + ) { + var key = element.key; + var child = currentFirstChild; + while (child !== null) { + // TODO: If key === null and child.key === null, then this only applies to + // the first item in the list. + if (child.key === key) { + if ( + child.tag === Fragment + ? element.type === REACT_FRAGMENT_TYPE + : child.type === element.type + ) { + deleteRemainingChildren(returnFiber, child.sibling); + var existing = useFiber( + child, + element.type === REACT_FRAGMENT_TYPE + ? element.props.children + : element.props, + expirationTime + ); + existing.ref = coerceRef(returnFiber, child, element); + existing.return = returnFiber; + { + existing._debugSource = element._source; + existing._debugOwner = element._owner; + } + return existing; + } else { + deleteRemainingChildren(returnFiber, child); + break; + } } else { - // In a resume, we'll already have an instance we can reuse. - shouldUpdate = resumeMountClassInstance( - workInProgress, - renderExpirationTime - ); + deleteChild(returnFiber, child); } + child = child.sibling; + } + + if (element.type === REACT_FRAGMENT_TYPE) { + var created = createFiberFromFragment( + element.props.children, + returnFiber.mode, + expirationTime, + element.key + ); + created.return = returnFiber; + return created; } else { - shouldUpdate = updateClassInstance( - current, - workInProgress, - renderExpirationTime + var _created4 = createFiberFromElement( + element, + returnFiber.mode, + expirationTime ); + _created4.ref = coerceRef(returnFiber, currentFirstChild, element); + _created4.return = returnFiber; + return _created4; } - return finishClassComponent( - current, - workInProgress, - shouldUpdate, - hasContext, - renderExpirationTime - ); } - function finishClassComponent( - current, - workInProgress, - shouldUpdate, - hasContext, - renderExpirationTime + function reconcileSinglePortal( + returnFiber, + currentFirstChild, + portal, + expirationTime ) { - // Refs should update even if shouldComponentUpdate returns false - markRef(current, workInProgress); - - var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect; - - if (!shouldUpdate && !didCaptureError) { - // Context providers should defer to sCU for rendering - if (hasContext) { - invalidateContextProvider(workInProgress, false); - } - - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - - var ctor = workInProgress.type; - var instance = workInProgress.stateNode; - - // Rerender - ReactCurrentOwner.current = workInProgress; - var nextChildren = void 0; - if ( - didCaptureError && - (!enableGetDerivedStateFromCatch || - typeof ctor.getDerivedStateFromCatch !== "function") - ) { - // If we captured an error, but getDerivedStateFrom catch is not defined, - // unmount all the children. componentDidCatch will schedule an update to - // re-render a fallback. This is temporary until we migrate everyone to - // the new API. - // TODO: Warn in a future release. - nextChildren = null; - - if (enableProfilerTimer) { - stopBaseRenderTimerIfRunning(); - } - } else { - { - ReactDebugCurrentFiber.setCurrentPhase("render"); - nextChildren = instance.render(); + var key = portal.key; + var child = currentFirstChild; + while (child !== null) { + // TODO: If key === null and child.key === null, then this only applies to + // the first item in the list. + if (child.key === key) { if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) + child.tag === HostPortal && + child.stateNode.containerInfo === portal.containerInfo && + child.stateNode.implementation === portal.implementation ) { - instance.render(); + deleteRemainingChildren(returnFiber, child.sibling); + var existing = useFiber(child, portal.children || [], expirationTime); + existing.return = returnFiber; + return existing; + } else { + deleteRemainingChildren(returnFiber, child); + break; } - ReactDebugCurrentFiber.setCurrentPhase(null); + } else { + deleteChild(returnFiber, child); } + child = child.sibling; } - // React DevTools reads this flag. - workInProgress.effectTag |= PerformedWork; - if (didCaptureError) { - // If we're recovering from an error, reconcile twice: first to delete - // all the existing children. - reconcileChildrenAtExpirationTime( - current, - workInProgress, - null, - renderExpirationTime - ); - workInProgress.child = null; - // Now we can continue reconciling like normal. This has the effect of - // remounting all children regardless of whether their their - // identity matches. - } - reconcileChildrenAtExpirationTime( - current, - workInProgress, - nextChildren, - renderExpirationTime + var created = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime ); - // Memoize props and state using the values we just used to render. - // TODO: Restructure so we never read values from the instance. - memoizeState(workInProgress, instance.state); - memoizeProps(workInProgress, instance.props); + created.return = returnFiber; + return created; + } - // The context might have changed so we need to recalculate it. - if (hasContext) { - invalidateContextProvider(workInProgress, true); + // This API will tag the children with the side-effect of the reconciliation + // itself. They will be added to the side-effect list as we pass through the + // children and the parent. + function reconcileChildFibers( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ) { + // This function is not recursive. + // If the top level item is an array, we treat it as a set of children, + // not as a fragment. Nested arrays on the other hand will be treated as + // fragment nodes. Recursion happens at the normal flow. + + // Handle top level unkeyed fragments as if they were arrays. + // This leads to an ambiguity between <>{[...]} and <>.... + // We treat the ambiguous cases above the same. + var isUnkeyedTopLevelFragment = + typeof newChild === "object" && + newChild !== null && + newChild.type === REACT_FRAGMENT_TYPE && + newChild.key === null; + if (isUnkeyedTopLevelFragment) { + newChild = newChild.props.children; } - return workInProgress.child; - } + // Handle object types + var isObject = typeof newChild === "object" && newChild !== null; - function pushHostRootContext(workInProgress) { - var root = workInProgress.stateNode; - if (root.pendingContext) { - pushTopLevelContextObject( - workInProgress, - root.pendingContext, - root.pendingContext !== root.context - ); - } else if (root.context) { - // Should always be set - pushTopLevelContextObject(workInProgress, root.context, false); + if (isObject) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + return placeSingleChild( + reconcileSingleElement( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ) + ); + case REACT_PORTAL_TYPE: + return placeSingleChild( + reconcileSinglePortal( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ) + ); + } } - pushHostContainer(workInProgress, root.containerInfo); - } - function updateHostRoot(current, workInProgress, renderExpirationTime) { - pushHostRootContext(workInProgress); - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - var nextProps = workInProgress.pendingProps; - var prevState = workInProgress.memoizedState; - var prevChildren = prevState !== null ? prevState.element : null; - processUpdateQueue( - workInProgress, - updateQueue, - nextProps, - null, - renderExpirationTime + if (typeof newChild === "string" || typeof newChild === "number") { + return placeSingleChild( + reconcileSingleTextNode( + returnFiber, + currentFirstChild, + "" + newChild, + expirationTime + ) ); - var nextState = workInProgress.memoizedState; - // Caution: React DevTools currently depends on this property - // being called "element". - var nextChildren = nextState.element; - - if (nextChildren === prevChildren) { - // If the state is the same as before, that's a bailout because we had - // no work that expires at this time. - resetHydrationState(); - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - var root = workInProgress.stateNode; - if ( - (current === null || current.child === null) && - root.hydrate && - enterHydrationState(workInProgress) - ) { - // If we don't have any current children this might be the first pass. - // We always try to hydrate. If this isn't a hydration pass there won't - // be any children to hydrate which is effectively the same thing as - // not hydrating. - - // This is a bit of a hack. We track the host root as a placement to - // know that we're currently in a mounting state. That way isMounted - // works as expected. We must reset this before committing. - // TODO: Delete this when we delete isMounted and findDOMNode. - workInProgress.effectTag |= Placement; - - // Ensure that children mount into this root without tracking - // side-effects. This ensures that we don't store Placement effects on - // nodes that will be hydrated. - workInProgress.child = mountChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime - ); - } else { - // Otherwise reset hydration state in case we aborted and resumed another - // root. - resetHydrationState(); - reconcileChildren(current, workInProgress, nextChildren); - } - return workInProgress.child; } - resetHydrationState(); - // If there is no update queue, that's a bailout because the root has no props. - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - function updateHostComponent(current, workInProgress, renderExpirationTime) { - pushHostContext(workInProgress); + if (isArray$1(newChild)) { + return reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); + } - if (current === null) { - tryToClaimNextHydratableInstance(workInProgress); + if (getIteratorFn(newChild)) { + return reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); } - var type = workInProgress.type; - var memoizedProps = workInProgress.memoizedProps; - var nextProps = workInProgress.pendingProps; - var prevProps = current !== null ? current.memoizedProps : null; + if (isObject) { + throwOnInvalidObjectType(returnFiber, newChild); + } - if (hasLegacyContextChanged()) { - // 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) { - var isHidden = - workInProgress.mode & AsyncMode && - shouldDeprioritizeSubtree(type, nextProps); - if (isHidden) { - // Before bailing out, make sure we've deprioritized a hidden component. - workInProgress.expirationTime = Never; - } - if (!isHidden || renderExpirationTime !== Never) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); + { + if (typeof newChild === "function") { + warnOnFunctionType(); + } + } + if (typeof newChild === "undefined" && !isUnkeyedTopLevelFragment) { + // If the new child is undefined, and the return fiber is a composite + // component, throw an error. If Fiber return types are disabled, + // we already threw above. + switch (returnFiber.tag) { + case ClassComponent: { + { + var instance = returnFiber.stateNode; + if (instance.render._isMockFunction) { + // We allow auto-mocks to proceed as if they're returning null. + break; + } + } + } + // Intentionally fall through to the next case, which handles both + // functions and classes + // eslint-disable-next-lined no-fallthrough + case FunctionalComponent: { + var Component = returnFiber.type; + invariant( + false, + "%s(...): Nothing was returned from render. This usually means a " + + "return statement is missing. Or, to render nothing, " + + "return null.", + Component.displayName || Component.name || "Component" + ); + } } - // If we're rendering a hidden node at hidden priority, don't bailout. The - // parent is complete, but the children may not be. } - var nextChildren = nextProps.children; - var isDirectTextChild = shouldSetTextContent(type, nextProps); + // Remaining cases are all treated as empty. + return deleteRemainingChildren(returnFiber, currentFirstChild); + } - if (isDirectTextChild) { - // We special case a direct text child of a host node. This is a common - // case. We won't handle it as a reified child. We will instead handle - // this in the host environment that also have access to this prop. That - // avoids allocating another HostText fiber and traversing it. - nextChildren = null; - } else if (prevProps && shouldSetTextContent(type, prevProps)) { - // If we're switching from a direct text child to a normal child, or to - // empty, we need to schedule the text content to be reset. - workInProgress.effectTag |= ContentReset; - } + return reconcileChildFibers; +} - markRef(current, workInProgress); +var reconcileChildFibers = ChildReconciler(true); +var mountChildFibers = ChildReconciler(false); - // Check the host config to see if the children are offscreen/hidden. - if ( - renderExpirationTime !== Never && - workInProgress.mode & AsyncMode && - shouldDeprioritizeSubtree(type, nextProps) - ) { - // Down-prioritize the children. - workInProgress.expirationTime = Never; - // Bailout and come back to this fiber later. - workInProgress.memoizedProps = nextProps; - return null; - } +function cloneChildFibers(current, workInProgress) { + invariant( + current === null || workInProgress.child === current.child, + "Resuming work not yet implemented." + ); - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextProps); - return workInProgress.child; + if (workInProgress.child === null) { + return; } - function updateHostText(current, workInProgress) { - if (current === null) { - tryToClaimNextHydratableInstance(workInProgress); - } - var nextProps = workInProgress.pendingProps; - memoizeProps(workInProgress, nextProps); - // Nothing to do here. This is terminal. We'll do the completion step - // immediately after. - return null; - } + var currentChild = workInProgress.child; + var newChild = createWorkInProgress( + currentChild, + currentChild.pendingProps, + currentChild.expirationTime + ); + workInProgress.child = newChild; - function mountIndeterminateComponent( - current, - workInProgress, - renderExpirationTime - ) { - invariant( - current === null, - "An indeterminate component should never have mounted. This error is " + - "likely caused by a bug in React. Please file an issue." + newChild.return = workInProgress; + while (currentChild.sibling !== null) { + currentChild = currentChild.sibling; + newChild = newChild.sibling = createWorkInProgress( + currentChild, + currentChild.pendingProps, + currentChild.expirationTime ); - var fn = workInProgress.type; - var props = workInProgress.pendingProps; - var unmaskedContext = getUnmaskedContext(workInProgress); - var context = getMaskedContext(workInProgress, unmaskedContext); - - var value = void 0; - - { - if (fn.prototype && typeof fn.prototype.render === "function") { - var componentName = getComponentName(workInProgress) || "Unknown"; - - if (!didWarnAboutBadClass[componentName]) { - warning( - false, - "The <%s /> component appears to have a render method, but doesn't extend React.Component. " + - "This is likely to cause errors. Change %s to extend React.Component instead.", - componentName, - componentName - ); - didWarnAboutBadClass[componentName] = true; - } - } - ReactCurrentOwner.current = workInProgress; - value = fn(props, context); - } - // React DevTools reads this flag. - workInProgress.effectTag |= PerformedWork; + newChild.return = workInProgress; + } + newChild.sibling = null; +} - if ( - typeof value === "object" && - value !== null && - typeof value.render === "function" && - value.$$typeof === undefined - ) { - var Component = workInProgress.type; +// The deepest Fiber on the stack involved in a hydration context. +// This may have been an insertion or a hydration. +var hydrationParentFiber = null; +var nextHydratableInstance = null; +var isHydrating = false; - // Proceed under the assumption that this is a class instance - workInProgress.tag = ClassComponent; +function enterHydrationState(fiber) { + if (!supportsHydration) { + return false; + } - workInProgress.memoizedState = - value.state !== null && value.state !== undefined ? value.state : null; + var parentInstance = fiber.stateNode.containerInfo; + nextHydratableInstance = getFirstHydratableChild(parentInstance); + hydrationParentFiber = fiber; + isHydrating = true; + return true; +} - var getDerivedStateFromProps = Component.getDerivedStateFromProps; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - props +function deleteHydratableInstance(returnFiber, instance) { + { + switch (returnFiber.tag) { + case HostRoot: + didNotHydrateContainerInstance( + returnFiber.stateNode.containerInfo, + instance ); - } + break; + case HostComponent: + didNotHydrateInstance( + returnFiber.type, + returnFiber.memoizedProps, + returnFiber.stateNode, + instance + ); + break; + } + } - // 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); - adoptClassInstance(workInProgress, value); - mountClassInstance(workInProgress, renderExpirationTime); - return finishClassComponent( - current, - workInProgress, - true, - hasContext, - renderExpirationTime - ); - } else { - // Proceed under the assumption that this is a functional component - workInProgress.tag = FunctionalComponent; - { - var _Component = workInProgress.type; + var childToDelete = createFiberFromHostInstanceForDeletion(); + childToDelete.stateNode = instance; + childToDelete.return = returnFiber; + childToDelete.effectTag = Deletion; - if (_Component) { - !!_Component.childContextTypes - ? warning( - false, - "%s(...): childContextTypes cannot be defined on a functional component.", - _Component.displayName || _Component.name || "Component" - ) - : void 0; - } - if (workInProgress.ref !== null) { - var info = ""; - var ownerName = ReactDebugCurrentFiber.getCurrentFiberOwnerName(); - if (ownerName) { - info += "\n\nCheck the render method of `" + ownerName + "`."; - } + // This might seem like it belongs on progressedFirstDeletion. However, + // these children are not part of the reconciliation list of children. + // Even if we abort and rereconcile the children, that will try to hydrate + // again and the nodes are still in the host tree so these will be + // recreated. + if (returnFiber.lastEffect !== null) { + returnFiber.lastEffect.nextEffect = childToDelete; + returnFiber.lastEffect = childToDelete; + } else { + returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; + } +} - var warningKey = ownerName || workInProgress._debugID || ""; - var debugSource = workInProgress._debugSource; - if (debugSource) { - warningKey = debugSource.fileName + ":" + debugSource.lineNumber; - } - if (!didWarnAboutStatelessRefs[warningKey]) { - didWarnAboutStatelessRefs[warningKey] = true; - warning( - false, - "Stateless function components cannot be given refs. " + - "Attempts to access this ref will fail.%s%s", - info, - ReactDebugCurrentFiber.getCurrentFiberStackAddendum() - ); - } +function insertNonHydratedInstance(returnFiber, fiber) { + fiber.effectTag |= Placement; + { + switch (returnFiber.tag) { + case HostRoot: { + var parentContainer = returnFiber.stateNode.containerInfo; + switch (fiber.tag) { + case HostComponent: + var type = fiber.type; + var props = fiber.pendingProps; + didNotFindHydratableContainerInstance(parentContainer, type, props); + break; + case HostText: + var text = fiber.pendingProps; + didNotFindHydratableContainerTextInstance(parentContainer, text); + break; } - - if (typeof fn.getDerivedStateFromProps === "function") { - var _componentName = getComponentName(workInProgress) || "Unknown"; - - if ( - !didWarnAboutGetDerivedStateOnFunctionalComponent[_componentName] - ) { - warning( - false, - "%s: Stateless functional components do not support getDerivedStateFromProps.", - _componentName + break; + } + case HostComponent: { + var parentType = returnFiber.type; + var parentProps = returnFiber.memoizedProps; + var parentInstance = returnFiber.stateNode; + switch (fiber.tag) { + case HostComponent: + var _type = fiber.type; + var _props = fiber.pendingProps; + didNotFindHydratableInstance( + parentType, + parentProps, + parentInstance, + _type, + _props ); - didWarnAboutGetDerivedStateOnFunctionalComponent[ - _componentName - ] = true; - } + break; + case HostText: + var _text = fiber.pendingProps; + didNotFindHydratableTextInstance( + parentType, + parentProps, + parentInstance, + _text + ); + break; } + break; } - reconcileChildren(current, workInProgress, value); - memoizeProps(workInProgress, props); - return workInProgress.child; + default: + return; } } +} - function updateTimeoutComponent( - current, - workInProgress, - renderExpirationTime - ) { - if (enableSuspense) { - var nextProps = workInProgress.pendingProps; - var prevProps = workInProgress.memoizedProps; - - var prevDidTimeout = workInProgress.memoizedState; - - // Check if we already attempted to render the normal state. If we did, - // and we timed out, render the placeholder state. - var alreadyCaptured = - (workInProgress.effectTag & DidCapture) === NoEffect; - var nextDidTimeout = !alreadyCaptured; - - if (hasLegacyContextChanged()) { - // 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 (nextProps === prevProps && nextDidTimeout === prevDidTimeout) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); +function tryHydrate(fiber, nextInstance) { + switch (fiber.tag) { + case HostComponent: { + var type = fiber.type; + var props = fiber.pendingProps; + var instance = canHydrateInstance(nextInstance, type, props); + if (instance !== null) { + fiber.stateNode = instance; + return true; } - - var render = nextProps.children; - var nextChildren = render(nextDidTimeout); - workInProgress.memoizedProps = nextProps; - workInProgress.memoizedState = nextDidTimeout; - reconcileChildren(current, workInProgress, nextChildren); - return workInProgress.child; - } else { - return null; + return false; + } + case HostText: { + var text = fiber.pendingProps; + var textInstance = canHydrateTextInstance(nextInstance, text); + if (textInstance !== null) { + fiber.stateNode = textInstance; + return true; + } + return false; } + default: + return false; } +} - function updatePortalComponent( - current, - workInProgress, - renderExpirationTime - ) { - pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo); - var nextChildren = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { - // 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) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); +function tryToClaimNextHydratableInstance(fiber) { + if (!isHydrating) { + return; + } + var nextInstance = nextHydratableInstance; + if (!nextInstance) { + // Nothing to hydrate. Make it an insertion. + insertNonHydratedInstance(hydrationParentFiber, fiber); + isHydrating = false; + hydrationParentFiber = fiber; + return; + } + var firstAttemptedInstance = nextInstance; + if (!tryHydrate(fiber, nextInstance)) { + // If we can't hydrate this instance let's try the next one. + // We use this as a heuristic. It's based on intuition and not data so it + // might be flawed or unnecessary. + nextInstance = getNextHydratableSibling(firstAttemptedInstance); + if (!nextInstance || !tryHydrate(fiber, nextInstance)) { + // Nothing to hydrate. Make it an insertion. + insertNonHydratedInstance(hydrationParentFiber, fiber); + isHydrating = false; + hydrationParentFiber = fiber; + return; } + // We matched the next one, we'll now assume that the first one was + // superfluous and we'll delete it. Since we can't eagerly delete it + // we'll have to schedule a deletion. To do that, this node needs a dummy + // fiber associated with it. + deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance); + } + hydrationParentFiber = fiber; + nextHydratableInstance = getFirstHydratableChild(nextInstance); +} - if (current === null) { - // Portals are special because we don't append the children during mount - // but at commit. Therefore we need to track insertions which the normal - // flow doesn't do during mount. This doesn't happen at the root because - // the root always starts with a "current" with a null child. - // TODO: Consider unifying this with how the root works. - workInProgress.child = reconcileChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime - ); - memoizeProps(workInProgress, nextChildren); - } else { - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextChildren); - } - return workInProgress.child; +function prepareToHydrateHostInstance( + fiber, + rootContainerInstance, + hostContext +) { + if (!supportsHydration) { + invariant( + false, + "Expected prepareToHydrateHostInstance() to never be called. " + + "This error is likely caused by a bug in React. Please file an issue." + ); } - function propagateContextChange( - workInProgress, - context, - changedBits, - 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. - switch (fiber.tag) { - case ContextConsumer: - // Check if the context matches. - var observedBits = fiber.stateNode | 0; - if (fiber.type === context && (observedBits & changedBits) !== 0) { - // Update the expiration time of all the ancestors, including - // the alternates. - var node = fiber; - while (node !== null) { - var alternate = node.alternate; - if ( - node.expirationTime === NoWork || - node.expirationTime > renderExpirationTime - ) { - node.expirationTime = renderExpirationTime; - if ( - alternate !== null && - (alternate.expirationTime === NoWork || - alternate.expirationTime > renderExpirationTime) - ) { - alternate.expirationTime = renderExpirationTime; - } - } else if ( - alternate !== null && - (alternate.expirationTime === NoWork || - alternate.expirationTime > renderExpirationTime) - ) { - alternate.expirationTime = renderExpirationTime; - } else { - // Neither alternate was updated, which means the rest of the - // ancestor path already has sufficient priority. - break; - } - node = node.return; - } - // Don't scan deeper than a matching consumer. When we render the - // consumer, we'll continue scanning from that point. This way the - // scanning work is time-sliced. - nextFiber = null; - } else { - // Traverse down. - nextFiber = fiber.child; - } - break; - case ContextProvider: - // Don't scan deeper if this is a matching provider - nextFiber = fiber.type === workInProgress.type ? null : fiber.child; - break; - default: - // Traverse down. - nextFiber = fiber.child; - break; - } - if (nextFiber !== null) { - // Set the return pointer of the child to the work-in-progress fiber. - nextFiber.return = fiber; - } else { - // No child. Traverse to next sibling. - nextFiber = fiber; - while (nextFiber !== null) { - if (nextFiber === workInProgress) { - // We're back to the root of this subtree. Exit. - nextFiber = null; + var instance = fiber.stateNode; + var updatePayload = hydrateInstance( + instance, + fiber.type, + fiber.memoizedProps, + rootContainerInstance, + hostContext, + fiber + ); + // TODO: Type this specific to this type of component. + fiber.updateQueue = updatePayload; + // If the update payload indicates that there is a change or if there + // is a new ref we mark this as an update. + if (updatePayload !== null) { + return true; + } + return false; +} + +function prepareToHydrateHostTextInstance(fiber) { + if (!supportsHydration) { + invariant( + false, + "Expected prepareToHydrateHostTextInstance() to never be called. " + + "This error is likely caused by a bug in React. Please file an issue." + ); + } + + var textInstance = fiber.stateNode; + var textContent = fiber.memoizedProps; + var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber); + { + if (shouldUpdate) { + // We assume that prepareToHydrateHostTextInstance is called in a context where the + // hydration parent is the parent host component of this host text. + var returnFiber = hydrationParentFiber; + if (returnFiber !== null) { + switch (returnFiber.tag) { + case HostRoot: { + var parentContainer = returnFiber.stateNode.containerInfo; + didNotMatchHydratedContainerTextInstance( + parentContainer, + textInstance, + textContent + ); break; } - var sibling = nextFiber.sibling; - if (sibling !== null) { - // Set the return pointer of the sibling to the work-in-progress fiber. - sibling.return = nextFiber.return; - nextFiber = sibling; + case HostComponent: { + var parentType = returnFiber.type; + var parentProps = returnFiber.memoizedProps; + var parentInstance = returnFiber.stateNode; + didNotMatchHydratedTextInstance( + parentType, + parentProps, + parentInstance, + textInstance, + textContent + ); break; } - // No more siblings. Traverse up. - nextFiber = nextFiber.return; } } - fiber = nextFiber; } } + return shouldUpdate; +} - function updateContextProvider( - current, - workInProgress, - renderExpirationTime +function popToNextHostParent(fiber) { + var parent = fiber.return; + while ( + parent !== null && + parent.tag !== HostComponent && + parent.tag !== HostRoot ) { - var providerType = workInProgress.type; - var context = providerType._context; + parent = parent.return; + } + hydrationParentFiber = parent; +} + +function popHydrationState(fiber) { + if (!supportsHydration) { + return false; + } + if (fiber !== hydrationParentFiber) { + // We're deeper than the current hydration context, inside an inserted + // tree. + return false; + } + if (!isHydrating) { + // If we're not currently hydrating but we're in a hydration context, then + // we were an insertion and now need to pop up reenter hydration of our + // siblings. + popToNextHostParent(fiber); + isHydrating = true; + return false; + } - var newProps = workInProgress.pendingProps; - var oldProps = workInProgress.memoizedProps; - var canBailOnProps = true; + var type = fiber.type; - if (hasLegacyContextChanged()) { - canBailOnProps = false; - // 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) { - workInProgress.stateNode = 0; - pushProvider(workInProgress); - return bailoutOnAlreadyFinishedWork(current, workInProgress); + // If we have any remaining hydratable nodes, we need to delete them now. + // We only do this deeper than head and body since they tend to have random + // other nodes in them. We also ignore components with pure text content in + // side of them. + // TODO: Better heuristic. + if ( + fiber.tag !== HostComponent || + (type !== "head" && + type !== "body" && + !shouldSetTextContent(type, fiber.memoizedProps)) + ) { + var nextInstance = nextHydratableInstance; + while (nextInstance) { + deleteHydratableInstance(fiber, nextInstance); + nextInstance = getNextHydratableSibling(nextInstance); } + } - var newValue = newProps.value; - workInProgress.memoizedProps = newProps; + popToNextHostParent(fiber); + nextHydratableInstance = hydrationParentFiber + ? getNextHydratableSibling(fiber.stateNode) + : null; + return true; +} - { - var providerPropTypes = workInProgress.type.propTypes; +function resetHydrationState() { + if (!supportsHydration) { + return; + } - if (providerPropTypes) { - checkPropTypes( - providerPropTypes, - newProps, - "prop", - "Context.Provider", - getCurrentFiberStackAddendum - ); - } - } + hydrationParentFiber = null; + nextHydratableInstance = null; + isHydrating = false; +} - var changedBits = void 0; - if (oldProps === null) { - // Initial render - changedBits = MAX_SIGNED_31_BIT_INT; - } else { - if (oldProps.value === newProps.value) { - // No change. Bailout early if children are the same. - if (oldProps.children === newProps.children && canBailOnProps) { - workInProgress.stateNode = 0; - pushProvider(workInProgress); - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - changedBits = 0; - } else { - var oldValue = oldProps.value; - // Use Object.is to compare the new context value to the old value. - // Inlined Object.is polyfill. - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is - if ( - (oldValue === newValue && - (oldValue !== 0 || 1 / oldValue === 1 / newValue)) || - (oldValue !== oldValue && newValue !== newValue) // eslint-disable-line no-self-compare - ) { - // No change. Bailout early if children are the same. - if (oldProps.children === newProps.children && canBailOnProps) { - workInProgress.stateNode = 0; - pushProvider(workInProgress); - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - changedBits = 0; - } else { - changedBits = - typeof context._calculateChangedBits === "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; - } - changedBits |= 0; - - if (changedBits === 0) { - // No change. Bailout early if children are the same. - if (oldProps.children === newProps.children && canBailOnProps) { - workInProgress.stateNode = 0; - pushProvider(workInProgress); - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - } else { - propagateContextChange( - workInProgress, - context, - changedBits, - renderExpirationTime - ); - } - } - } - } +var getCurrentFiberStackAddendum$1 = + ReactDebugCurrentFiber.getCurrentFiberStackAddendum; - workInProgress.stateNode = changedBits; - pushProvider(workInProgress); +var didWarnAboutBadClass = void 0; +var didWarnAboutGetDerivedStateOnFunctionalComponent = void 0; +var didWarnAboutStatelessRefs = void 0; - var newChildren = newProps.children; - reconcileChildren(current, workInProgress, newChildren); - return workInProgress.child; - } +{ + didWarnAboutBadClass = {}; + didWarnAboutGetDerivedStateOnFunctionalComponent = {}; + didWarnAboutStatelessRefs = {}; +} - function updateContextConsumer( +// TODO: Remove this and use reconcileChildrenAtExpirationTime directly. +function reconcileChildren(current, workInProgress, nextChildren) { + reconcileChildrenAtExpirationTime( current, workInProgress, - renderExpirationTime - ) { - var context = workInProgress.type; - var newProps = workInProgress.pendingProps; - var oldProps = workInProgress.memoizedProps; - - var newValue = getContextCurrentValue(context); - var changedBits = getContextChangedBits(context); + nextChildren, + workInProgress.expirationTime + ); +} - if (hasLegacyContextChanged()) { - // 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) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - workInProgress.memoizedProps = newProps; +function reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime +) { + if (current === null) { + // If this is a fresh new component that hasn't been rendered yet, we + // won't update its child set by applying minimal side-effects. Instead, + // we will add them all to the child before it gets rendered. That means + // we can optimize this reconciliation pass by not tracking side-effects. + workInProgress.child = mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ); + } else { + // If the current child is the same as the work in progress, it means that + // we haven't yet started any work on these children. Therefore, we use + // the clone algorithm to create a copy of all the current children. - var observedBits = newProps.unstable_observedBits; - if (observedBits === undefined || observedBits === null) { - // Subscribe to all changes by default - observedBits = MAX_SIGNED_31_BIT_INT; - } - // Store the observedBits on the fiber's stateNode for quick access. - workInProgress.stateNode = observedBits; + // If we had any progressed work already, that is invalid at this point so + // let's throw it out. + workInProgress.child = reconcileChildFibers( + workInProgress, + current.child, + nextChildren, + renderExpirationTime + ); + } +} - if ((changedBits & observedBits) !== 0) { - // Context change propagation stops at matching consumers, for time- - // slicing. Continue the propagation here. - propagateContextChange( - workInProgress, - context, - changedBits, - renderExpirationTime - ); - } else if (oldProps === newProps) { - // Skip over a memoized parent with a bitmask bailout even - // if we began working on it because of a deeper matching child. +function updateForwardRef(current, workInProgress) { + var render = workInProgress.type.render; + var nextProps = workInProgress.pendingProps; + var ref = workInProgress.ref; + 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) { + var currentRef = current !== null ? current.ref : null; + if (ref === currentRef) { 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; - } + var nextChildren = void 0; + { + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase("render"); + nextChildren = render(nextProps, ref); + ReactDebugCurrentFiber.setCurrentPhase(null); + } - var newChildren = void 0; - { - ReactCurrentOwner.current = workInProgress; - ReactDebugCurrentFiber.setCurrentPhase("render"); - newChildren = render(newValue); - ReactDebugCurrentFiber.setCurrentPhase(null); - } + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextProps); + return workInProgress.child; +} - // React DevTools reads this flag. - workInProgress.effectTag |= PerformedWork; - reconcileChildren(current, workInProgress, newChildren); - return workInProgress.child; +function updateFragment(current, workInProgress) { + var nextChildren = workInProgress.pendingProps; + 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) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextChildren); + return workInProgress.child; +} - /* - function reuseChildrenEffects(returnFiber : Fiber, firstChild : Fiber) { - let child = firstChild; - do { - // Ensure that the first and last effect of the parent corresponds - // to the children's first and last effect. - if (!returnFiber.firstEffect) { - returnFiber.firstEffect = child.firstEffect; - } - if (child.lastEffect) { - if (returnFiber.lastEffect) { - returnFiber.lastEffect.nextEffect = child.firstEffect; - } - returnFiber.lastEffect = child.lastEffect; - } - } while (child = child.sibling); +function updateMode(current, workInProgress) { + var nextChildren = workInProgress.pendingProps.children; + 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 ( + nextChildren === null || + workInProgress.memoizedProps === nextChildren + ) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - */ - - function bailoutOnAlreadyFinishedWork(current, workInProgress) { - cancelWorkTimer(workInProgress); - - if (enableProfilerTimer) { - // Don't update "base" render times for bailouts. - stopBaseRenderTimerIfRunning(); - } + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextChildren); + return workInProgress.child; +} - // TODO: We should ideally be able to bail out early if the children have no - // more work to do. However, since we don't have a separation of this - // Fiber's priority and its children yet - we don't know without doing lots - // of the same work we do anyway. Once we have that separation we can just - // bail out here if the children has no more work at this priority level. - // if (workInProgress.priorityOfChildren <= priorityLevel) { - // // If there are side-effects in these children that have not yet been - // // committed we need to ensure that they get properly transferred up. - // if (current && current.child !== workInProgress.child) { - // reuseChildrenEffects(workInProgress, child); - // } - // return null; - // } - - cloneChildFibers(current, workInProgress); - return workInProgress.child; +function updateProfiler(current, workInProgress) { + var nextProps = workInProgress.pendingProps; + if (enableProfilerTimer) { + workInProgress.effectTag |= Update; + } + if (workInProgress.memoizedProps === nextProps) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } + var nextChildren = nextProps.children; + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextProps); + return workInProgress.child; +} - function bailoutOnLowPriority(current, workInProgress) { - cancelWorkTimer(workInProgress); +function markRef(current, workInProgress) { + var ref = workInProgress.ref; + if ( + (current === null && ref !== null) || + (current !== null && current.ref !== ref) + ) { + // Schedule a Ref effect + workInProgress.effectTag |= Ref; + } +} - if (enableProfilerTimer) { - // Don't update "base" render times for bailouts. - stopBaseRenderTimerIfRunning(); - } +function updateFunctionalComponent(current, workInProgress) { + var fn = workInProgress.type; + var nextProps = workInProgress.pendingProps; - // TODO: Handle HostComponent tags here as well and call pushHostContext()? - // See PR 8590 discussion for context - switch (workInProgress.tag) { - case HostRoot: - pushHostRootContext(workInProgress); - break; - case ClassComponent: - pushLegacyContextProvider(workInProgress); - break; - case HostPortal: - pushHostContainer( - workInProgress, - workInProgress.stateNode.containerInfo - ); - break; - case ContextProvider: - pushProvider(workInProgress); - break; - case Profiler: - if (enableProfilerTimer) { - markActualRenderTimeStarted(workInProgress); - } - break; + 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) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - // TODO: What if this is currently in progress? - // How can that happen? How is this not being cloned? - return null; + // TODO: consider bringing fn.shouldComponentUpdate() back. + // It used to be here. } - // TODO: Delete memoizeProps/State and move to reconcile/bailout instead - function memoizeProps(workInProgress, nextProps) { - workInProgress.memoizedProps = nextProps; - } + var unmaskedContext = getUnmaskedContext(workInProgress); + var context = getMaskedContext(workInProgress, unmaskedContext); - function memoizeState(workInProgress, nextState) { - workInProgress.memoizedState = nextState; - // Don't reset the updateQueue, in case there are pending updates. Resetting - // is handled by processUpdateQueue. - } + var nextChildren = void 0; - function beginWork(current, workInProgress, renderExpirationTime) { - if ( - workInProgress.expirationTime === NoWork || - workInProgress.expirationTime > renderExpirationTime - ) { - return bailoutOnLowPriority(current, workInProgress); - } + { + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase("render"); + nextChildren = fn(nextProps, context); + ReactDebugCurrentFiber.setCurrentPhase(null); + } + // React DevTools reads this flag. + workInProgress.effectTag |= PerformedWork; + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextProps); + return workInProgress.child; +} + +function updateClassComponent(current, workInProgress, renderExpirationTime) { + // 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 = pushContextProvider(workInProgress); + var shouldUpdate = void 0; + if (current === null) { + if (workInProgress.stateNode === null) { + // In the initial pass we might need to construct the instance. + constructClassInstance( + workInProgress, + workInProgress.pendingProps, + renderExpirationTime + ); + mountClassInstance(workInProgress, renderExpirationTime); - switch (workInProgress.tag) { - case IndeterminateComponent: - return mountIndeterminateComponent( - current, - workInProgress, - renderExpirationTime - ); - case FunctionalComponent: - return updateFunctionalComponent(current, workInProgress); - case ClassComponent: - return updateClassComponent( - current, - workInProgress, - renderExpirationTime - ); - case HostRoot: - return updateHostRoot(current, workInProgress, renderExpirationTime); - case HostComponent: - return updateHostComponent( - current, - workInProgress, - renderExpirationTime - ); - case HostText: - return updateHostText(current, workInProgress); - case TimeoutComponent: - return updateTimeoutComponent( - current, - workInProgress, - renderExpirationTime - ); - case HostPortal: - return updatePortalComponent( - current, - workInProgress, - renderExpirationTime - ); - case ForwardRef: - return updateForwardRef(current, workInProgress); - case Fragment: - return updateFragment(current, workInProgress); - case Mode: - return updateMode(current, workInProgress); - case Profiler: - return updateProfiler(current, workInProgress); - case ContextProvider: - return updateContextProvider( - current, - workInProgress, - renderExpirationTime - ); - case ContextConsumer: - return updateContextConsumer( - current, - workInProgress, - renderExpirationTime - ); - default: - invariant( - false, - "Unknown unit of work tag. This error is likely caused by a bug in " + - "React. Please file an issue." - ); + shouldUpdate = true; + } else { + // In a resume, we'll already have an instance we can reuse. + shouldUpdate = resumeMountClassInstance( + workInProgress, + renderExpirationTime + ); } + } else { + shouldUpdate = updateClassInstance( + current, + workInProgress, + renderExpirationTime + ); } + return finishClassComponent( + current, + workInProgress, + shouldUpdate, + hasContext, + renderExpirationTime + ); +} - return { - beginWork: beginWork - }; -}; - -var ReactFiberCompleteWork = function( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - profilerTimer +function finishClassComponent( + current, + workInProgress, + shouldUpdate, + hasContext, + renderExpirationTime ) { - var createInstance = config.createInstance, - createTextInstance = config.createTextInstance, - appendInitialChild = config.appendInitialChild, - finalizeInitialChildren = config.finalizeInitialChildren, - prepareUpdate = config.prepareUpdate, - mutation = config.mutation, - persistence = config.persistence; - var getRootHostContainer = hostContext.getRootHostContainer, - popHostContext = hostContext.popHostContext, - getHostContext = hostContext.getHostContext, - popHostContainer = hostContext.popHostContainer; - var recordElapsedActualRenderTime = - profilerTimer.recordElapsedActualRenderTime; - var popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject; - var popProvider = newContext.popProvider; - var prepareToHydrateHostInstance = - hydrationContext.prepareToHydrateHostInstance, - prepareToHydrateHostTextInstance = - hydrationContext.prepareToHydrateHostTextInstance, - popHydrationState = hydrationContext.popHydrationState; - - function markUpdate(workInProgress) { - // Tag the fiber with an update effect. This turns a Placement into - // a PlacementAndUpdate. - workInProgress.effectTag |= Update; - } + // Refs should update even if shouldComponentUpdate returns false + markRef(current, workInProgress); - function markRef(workInProgress) { - workInProgress.effectTag |= Ref; - } + var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect; - function appendAllChildren(parent, workInProgress) { - // We only have the top Fiber that was created but we need recurse down its - // children to find all the terminal nodes. - var node = workInProgress.child; - while (node !== null) { - if (node.tag === HostComponent || node.tag === HostText) { - appendInitialChild(parent, node.stateNode); - } else if (node.tag === HostPortal) { - // If we have a portal child, then we don't want to traverse - // down its children. Instead, we'll get insertions from each child in - // the portal directly. - } else if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; - } - if (node === workInProgress) { - return; - } - while (node.sibling === null) { - if (node.return === null || node.return === workInProgress) { - return; - } - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; + if (!shouldUpdate && !didCaptureError) { + // Context providers should defer to sCU for rendering + if (hasContext) { + invalidateContextProvider(workInProgress, false); } + + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - var updateHostContainer = void 0; - var updateHostComponent = void 0; - var updateHostText = void 0; - if (mutation) { - if (enableMutatingReconciler) { - // Mutation mode - updateHostContainer = function(workInProgress) { - // Noop - }; - updateHostComponent = function( - current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ) { - // TODO: Type this specific to this type of component. - workInProgress.updateQueue = updatePayload; - // If the update payload indicates that there is a change or if there - // is a new ref we mark this as an update. All the work is done in commitWork. - if (updatePayload) { - markUpdate(workInProgress); - } - }; - updateHostText = function(current, workInProgress, oldText, newText) { - // If the text differs, mark it as an update. All the work in done in commitWork. - if (oldText !== newText) { - markUpdate(workInProgress); - } - }; - } else { - invariant(false, "Mutating reconciler is disabled."); - } - } else if (persistence) { - if (enablePersistentReconciler) { - // Persistent host tree mode - var cloneInstance = persistence.cloneInstance, - createContainerChildSet = persistence.createContainerChildSet, - appendChildToContainerChildSet = - persistence.appendChildToContainerChildSet, - finalizeContainerChildren = persistence.finalizeContainerChildren; + var ctor = workInProgress.type; + var instance = workInProgress.stateNode; - // An unfortunate fork of appendAllChildren because we have two different parent types. + // Rerender + ReactCurrentOwner.current = workInProgress; + var nextChildren = void 0; + if ( + didCaptureError && + (!enableGetDerivedStateFromCatch || + typeof ctor.getDerivedStateFromCatch !== "function") + ) { + // If we captured an error, but getDerivedStateFrom catch is not defined, + // unmount all the children. componentDidCatch will schedule an update to + // re-render a fallback. This is temporary until we migrate everyone to + // the new API. + // TODO: Warn in a future release. + nextChildren = null; - var appendAllChildrenToContainer = function( - containerChildSet, - workInProgress - ) { - // We only have the top Fiber that was created but we need recurse down its - // children to find all the terminal nodes. - var node = workInProgress.child; - while (node !== null) { - if (node.tag === HostComponent || node.tag === HostText) { - appendChildToContainerChildSet(containerChildSet, node.stateNode); - } else if (node.tag === HostPortal) { - // If we have a portal child, then we don't want to traverse - // down its children. Instead, we'll get insertions from each child in - // the portal directly. - } else if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; - } - if (node === workInProgress) { - return; - } - while (node.sibling === null) { - if (node.return === null || node.return === workInProgress) { - return; - } - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } - }; - updateHostContainer = function(workInProgress) { - var portalOrRoot = workInProgress.stateNode; - var childrenUnchanged = workInProgress.firstEffect === null; - if (childrenUnchanged) { - // No changes, just reuse the existing instance. - } else { - var container = portalOrRoot.containerInfo; - var newChildSet = createContainerChildSet(container); - // If children might have changed, we have to add them all to the set. - appendAllChildrenToContainer(newChildSet, workInProgress); - portalOrRoot.pendingChildren = newChildSet; - // Schedule an update on the container to swap out the container. - markUpdate(workInProgress); - finalizeContainerChildren(container, newChildSet); - } - }; - updateHostComponent = function( - current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ) { - // If there are no effects associated with this node, then none of our children had any updates. - // This guarantees that we can reuse all of them. - var childrenUnchanged = workInProgress.firstEffect === null; - var currentInstance = current.stateNode; - if (childrenUnchanged && updatePayload === null) { - // No changes, just reuse the existing instance. - // Note that this might release a previous clone. - workInProgress.stateNode = currentInstance; - } else { - var recyclableInstance = workInProgress.stateNode; - var newInstance = cloneInstance( - currentInstance, - updatePayload, - type, - oldProps, - newProps, - workInProgress, - childrenUnchanged, - recyclableInstance - ); - if ( - finalizeInitialChildren( - newInstance, - type, - newProps, - rootContainerInstance, - currentHostContext - ) - ) { - markUpdate(workInProgress); - } - workInProgress.stateNode = newInstance; - if (childrenUnchanged) { - // If there are no other effects in this tree, we need to flag this node as having one. - // Even though we're not going to use it for anything. - // Otherwise parents won't know that there are new children to propagate upwards. - markUpdate(workInProgress); - } else { - // If children might have changed, we have to add them all to the set. - appendAllChildren(newInstance, workInProgress); - } - } - }; - updateHostText = function(current, workInProgress, oldText, newText) { - if (oldText !== newText) { - // If the text content differs, we'll create a new text instance for it. - var rootContainerInstance = getRootHostContainer(); - var currentHostContext = getHostContext(); - workInProgress.stateNode = createTextInstance( - newText, - rootContainerInstance, - currentHostContext, - workInProgress - ); - // We'll have to mark it as having an effect, even though we won't use the effect for anything. - // This lets the parents know that at least one of their children has changed. - markUpdate(workInProgress); - } - }; - } else { - invariant(false, "Persistent reconciler is disabled."); + if (enableProfilerTimer) { + stopBaseRenderTimerIfRunning(); } } else { - if (enableNoopReconciler) { - // No host operations - updateHostContainer = function(workInProgress) { - // Noop - }; - updateHostComponent = function( - current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext + { + ReactDebugCurrentFiber.setCurrentPhase("render"); + nextChildren = instance.render(); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) ) { - // Noop - }; - updateHostText = function(current, workInProgress, oldText, newText) { - // Noop - }; - } else { - invariant(false, "Noop reconciler is disabled."); + instance.render(); + } + ReactDebugCurrentFiber.setCurrentPhase(null); } } - function completeWork(current, workInProgress, renderExpirationTime) { - var newProps = workInProgress.pendingProps; - switch (workInProgress.tag) { - case FunctionalComponent: - return null; - case ClassComponent: { - // We are leaving this subtree, so pop context if any. - popLegacyContextProvider(workInProgress); - return null; - } - case HostRoot: { - popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); - var fiberRoot = workInProgress.stateNode; - if (fiberRoot.pendingContext) { - fiberRoot.context = fiberRoot.pendingContext; - fiberRoot.pendingContext = null; - } - if (current === null || current.child === null) { - // If we hydrated, pop so that we can delete any remaining children - // that weren't hydrated. - popHydrationState(workInProgress); - // This resets the hacky state to fix isMounted before committing. - // TODO: Delete this when we delete isMounted and findDOMNode. - workInProgress.effectTag &= ~Placement; - } - updateHostContainer(workInProgress); - return null; - } - case HostComponent: { - popHostContext(workInProgress); - var rootContainerInstance = getRootHostContainer(); - var type = workInProgress.type; - if (current !== null && workInProgress.stateNode != null) { - // If we have an alternate, that means this is an update and we need to - // schedule a side-effect to do the updates. - var oldProps = current.memoizedProps; - // If we get updated because one of our children updated, we don't - // have newProps so we'll have to reuse them. - // TODO: Split the update API as separate for the props vs. children. - // Even better would be if children weren't special cased at all tho. - var instance = workInProgress.stateNode; - var currentHostContext = getHostContext(); - // TODO: Experiencing an error where oldProps is null. Suggests a host - // component is hitting the resume path. Figure out why. Possibly - // related to `hidden`. - var updatePayload = prepareUpdate( - instance, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ); + // React DevTools reads this flag. + workInProgress.effectTag |= PerformedWork; + if (didCaptureError) { + // If we're recovering from an error, reconcile twice: first to delete + // all the existing children. + reconcileChildrenAtExpirationTime( + current, + workInProgress, + null, + renderExpirationTime + ); + workInProgress.child = null; + // Now we can continue reconciling like normal. This has the effect of + // remounting all children regardless of whether their their + // identity matches. + } + reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime + ); + // Memoize props and state using the values we just used to render. + // TODO: Restructure so we never read values from the instance. + memoizeState(workInProgress, instance.state); + memoizeProps(workInProgress, instance.props); - updateHostComponent( - current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ); + // The context might have changed so we need to recalculate it. + if (hasContext) { + invalidateContextProvider(workInProgress, true); + } - if (current.ref !== workInProgress.ref) { - markRef(workInProgress); - } - } else { - if (!newProps) { - invariant( - workInProgress.stateNode !== null, - "We must have new props for new mounts. This error is likely " + - "caused by a bug in React. Please file an issue." - ); - // This can happen when we abort work. - return null; - } + return workInProgress.child; +} - var _currentHostContext = getHostContext(); - // TODO: Move createInstance to beginWork and keep it on a context - // "stack" as the parent. Then append children as we go in beginWork - // or completeWork depending on we want to add then top->down or - // bottom->up. Top->down is faster in IE11. - var wasHydrated = popHydrationState(workInProgress); - if (wasHydrated) { - // TODO: Move this and createInstance step into the beginPhase - // to consolidate. - if ( - prepareToHydrateHostInstance( - workInProgress, - rootContainerInstance, - _currentHostContext - ) - ) { - // If changes to the hydrated node needs to be applied at the - // commit-phase we mark this as such. - markUpdate(workInProgress); - } - } else { - var _instance = createInstance( - type, - newProps, - rootContainerInstance, - _currentHostContext, - workInProgress - ); +function pushHostRootContext(workInProgress) { + var root = workInProgress.stateNode; + if (root.pendingContext) { + pushTopLevelContextObject( + workInProgress, + root.pendingContext, + root.pendingContext !== root.context + ); + } else if (root.context) { + // Should always be set + pushTopLevelContextObject(workInProgress, root.context, false); + } + pushHostContainer(workInProgress, root.containerInfo); +} - appendAllChildren(_instance, workInProgress); +function updateHostRoot(current, workInProgress, renderExpirationTime) { + pushHostRootContext(workInProgress); + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + var nextProps = workInProgress.pendingProps; + var prevState = workInProgress.memoizedState; + var prevChildren = prevState !== null ? prevState.element : null; + processUpdateQueue( + workInProgress, + updateQueue, + nextProps, + null, + renderExpirationTime + ); + var nextState = workInProgress.memoizedState; + // Caution: React DevTools currently depends on this property + // being called "element". + var nextChildren = nextState.element; - // Certain renderers require commit-time effects for initial mount. - // (eg DOM renderer supports auto-focus for certain elements). - // Make sure such renderers get scheduled for later work. - if ( - finalizeInitialChildren( - _instance, - type, - newProps, - rootContainerInstance, - _currentHostContext - ) - ) { - markUpdate(workInProgress); - } - workInProgress.stateNode = _instance; - } + if (nextChildren === prevChildren) { + // If the state is the same as before, that's a bailout because we had + // no work that expires at this time. + resetHydrationState(); + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + var root = workInProgress.stateNode; + if ( + (current === null || current.child === null) && + root.hydrate && + enterHydrationState(workInProgress) + ) { + // If we don't have any current children this might be the first pass. + // We always try to hydrate. If this isn't a hydration pass there won't + // be any children to hydrate which is effectively the same thing as + // not hydrating. + + // This is a bit of a hack. We track the host root as a placement to + // know that we're currently in a mounting state. That way isMounted + // works as expected. We must reset this before committing. + // TODO: Delete this when we delete isMounted and findDOMNode. + workInProgress.effectTag |= Placement; + + // Ensure that children mount into this root without tracking + // side-effects. This ensures that we don't store Placement effects on + // nodes that will be hydrated. + workInProgress.child = mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ); + } else { + // Otherwise reset hydration state in case we aborted and resumed another + // root. + resetHydrationState(); + reconcileChildren(current, workInProgress, nextChildren); + } + return workInProgress.child; + } + resetHydrationState(); + // If there is no update queue, that's a bailout because the root has no props. + return bailoutOnAlreadyFinishedWork(current, workInProgress); +} - if (workInProgress.ref !== null) { - // If there is a ref on a host node we need to schedule a callback - markRef(workInProgress); - } - } - return null; - } - case HostText: { - var newText = newProps; - if (current && workInProgress.stateNode != null) { - var oldText = current.memoizedProps; - // If we have an alternate, that means this is an update and we need - // to schedule a side-effect to do the updates. - updateHostText(current, workInProgress, oldText, newText); - } else { - if (typeof newText !== "string") { - invariant( - workInProgress.stateNode !== null, - "We must have new props for new mounts. This error is likely " + - "caused by a bug in React. Please file an issue." - ); - // This can happen when we abort work. - return null; - } - var _rootContainerInstance = getRootHostContainer(); - var _currentHostContext2 = getHostContext(); - var _wasHydrated = popHydrationState(workInProgress); - if (_wasHydrated) { - if (prepareToHydrateHostTextInstance(workInProgress)) { - markUpdate(workInProgress); - } - } else { - workInProgress.stateNode = createTextInstance( - newText, - _rootContainerInstance, - _currentHostContext2, - workInProgress - ); - } - } - return null; - } - case ForwardRef: - return null; - case TimeoutComponent: - return null; - case Fragment: - return null; - case Mode: - return null; - case Profiler: - if (enableProfilerTimer) { - recordElapsedActualRenderTime(workInProgress); - } - return null; - case HostPortal: - popHostContainer(workInProgress); - updateHostContainer(workInProgress); - return null; - case ContextProvider: - // Pop provider fiber - popProvider(workInProgress); - return null; - case ContextConsumer: - return null; - // Error cases - case IndeterminateComponent: - invariant( - false, - "An indeterminate component should have become determinate before " + - "completing. This error is likely caused by a bug in React. Please " + - "file an issue." - ); - // eslint-disable-next-line no-fallthrough - default: - invariant( - false, - "Unknown unit of work tag. This error is likely caused by a bug in " + - "React. Please file an issue." - ); +function updateHostComponent(current, workInProgress, renderExpirationTime) { + pushHostContext(workInProgress); + + if (current === null) { + tryToClaimNextHydratableInstance(workInProgress); + } + + var type = workInProgress.type; + var memoizedProps = workInProgress.memoizedProps; + var nextProps = workInProgress.pendingProps; + var prevProps = current !== null ? current.memoizedProps : null; + + 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) { + var isHidden = + workInProgress.mode & AsyncMode && + shouldDeprioritizeSubtree(type, nextProps); + if (isHidden) { + // Before bailing out, make sure we've deprioritized a hidden component. + workInProgress.expirationTime = Never; + } + if (!isHidden || renderExpirationTime !== Never) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } + // If we're rendering a hidden node at hidden priority, don't bailout. The + // parent is complete, but the children may not be. + } + + var nextChildren = nextProps.children; + var isDirectTextChild = shouldSetTextContent(type, nextProps); + + if (isDirectTextChild) { + // We special case a direct text child of a host node. This is a common + // case. We won't handle it as a reified child. We will instead handle + // this in the host environment that also have access to this prop. That + // avoids allocating another HostText fiber and traversing it. + nextChildren = null; + } else if (prevProps && shouldSetTextContent(type, prevProps)) { + // If we're switching from a direct text child to a normal child, or to + // empty, we need to schedule the text content to be reset. + workInProgress.effectTag |= ContentReset; } - return { - completeWork: completeWork - }; -}; + markRef(current, workInProgress); -function createCapturedValue(value, source) { - // If the value is an error, call this function immediately after it is thrown - // so the stack is accurate. - return { - value: value, - source: source, - stack: getStackAddendumByWorkInProgressFiber(source) - }; + // Check the host config to see if the children are offscreen/hidden. + if ( + renderExpirationTime !== Never && + workInProgress.mode & AsyncMode && + shouldDeprioritizeSubtree(type, nextProps) + ) { + // Down-prioritize the children. + workInProgress.expirationTime = Never; + // Bailout and come back to this fiber later. + workInProgress.memoizedProps = nextProps; + return null; + } + + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextProps); + return workInProgress.child; } -// Module provided by RN: -/** - * Intercept lifecycle errors and ensure they are shown with the correct stack - * trace within the native redbox component. - */ -function showErrorDialog(capturedError) { - var componentStack = capturedError.componentStack, - error = capturedError.error; +function updateHostText(current, workInProgress) { + if (current === null) { + tryToClaimNextHydratableInstance(workInProgress); + } + var nextProps = workInProgress.pendingProps; + memoizeProps(workInProgress, nextProps); + // Nothing to do here. This is terminal. We'll do the completion step + // immediately after. + return null; +} - var errorToHandle = void 0; +function mountIndeterminateComponent( + current, + workInProgress, + renderExpirationTime +) { + invariant( + current === null, + "An indeterminate component should never have mounted. This error is " + + "likely caused by a bug in React. Please file an issue." + ); + var fn = workInProgress.type; + var props = workInProgress.pendingProps; + var unmaskedContext = getUnmaskedContext(workInProgress); + var context = getMaskedContext(workInProgress, unmaskedContext); - // Typically Errors are thrown but eg strings or null can be thrown as well. - if (error instanceof Error) { - var message = error.message, - name = error.name; + var value = void 0; - var summary = message ? name + ": " + message : name; + { + if (fn.prototype && typeof fn.prototype.render === "function") { + var componentName = getComponentName(workInProgress) || "Unknown"; - errorToHandle = error; + if (!didWarnAboutBadClass[componentName]) { + warning( + false, + "The <%s /> component appears to have a render method, but doesn't extend React.Component. " + + "This is likely to cause errors. Change %s to extend React.Component instead.", + componentName, + componentName + ); + didWarnAboutBadClass[componentName] = true; + } + } - try { - errorToHandle.message = - summary + "\n\nThis error is located at:" + componentStack; - } catch (e) {} - } else if (typeof error === "string") { - errorToHandle = new Error( - error + "\n\nThis error is located at:" + componentStack - ); - } else { - errorToHandle = new Error("Unspecified error at:" + componentStack); + if (workInProgress.mode & StrictMode) { + ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null); + } + + ReactCurrentOwner.current = workInProgress; + value = fn(props, context); } + // React DevTools reads this flag. + workInProgress.effectTag |= PerformedWork; - ExceptionsManager.handleException(errorToHandle, false); + if ( + typeof value === "object" && + value !== null && + typeof value.render === "function" && + value.$$typeof === undefined + ) { + var Component = workInProgress.type; - // Return false here to prevent ReactFiberErrorLogger default behavior of - // logging error details to console.error. Calls to console.error are - // automatically routed to the native redbox controller, which we've already - // done above by calling ExceptionsManager. - return false; -} + // Proceed under the assumption that this is a class instance + workInProgress.tag = ClassComponent; -function logCapturedError(capturedError) { - var logError = showErrorDialog(capturedError); + workInProgress.memoizedState = + value.state !== null && value.state !== undefined ? value.state : null; - // Allow injected showErrorDialog() to prevent default console.error logging. - // This enables renderers like ReactNative to better manage redbox behavior. - if (logError === false) { - return; - } + var getDerivedStateFromProps = Component.getDerivedStateFromProps; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + props + ); + } - var error = capturedError.error; - var suppressLogging = error && error.suppressReactErrorLogging; - if (suppressLogging) { - return; - } + // 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 = pushContextProvider(workInProgress); + adoptClassInstance(workInProgress, value); + mountClassInstance(workInProgress, renderExpirationTime); + return finishClassComponent( + current, + workInProgress, + true, + hasContext, + renderExpirationTime + ); + } else { + // Proceed under the assumption that this is a functional component + workInProgress.tag = FunctionalComponent; + { + var _Component = workInProgress.type; - { - var componentName = capturedError.componentName, - componentStack = capturedError.componentStack, - errorBoundaryName = capturedError.errorBoundaryName, - errorBoundaryFound = capturedError.errorBoundaryFound, - willRetry = capturedError.willRetry; + if (_Component) { + !!_Component.childContextTypes + ? warning( + false, + "%s(...): childContextTypes cannot be defined on a functional component.", + _Component.displayName || _Component.name || "Component" + ) + : void 0; + } + if (workInProgress.ref !== null) { + var info = ""; + var ownerName = ReactDebugCurrentFiber.getCurrentFiberOwnerName(); + if (ownerName) { + info += "\n\nCheck the render method of `" + ownerName + "`."; + } - var componentNameMessage = componentName - ? "The above error occurred in the <" + componentName + "> component:" - : "The above error occurred in one of your React components:"; + var warningKey = ownerName || workInProgress._debugID || ""; + var debugSource = workInProgress._debugSource; + if (debugSource) { + warningKey = debugSource.fileName + ":" + debugSource.lineNumber; + } + if (!didWarnAboutStatelessRefs[warningKey]) { + didWarnAboutStatelessRefs[warningKey] = true; + warning( + false, + "Stateless function components cannot be given refs. " + + "Attempts to access this ref will fail.%s%s", + info, + ReactDebugCurrentFiber.getCurrentFiberStackAddendum() + ); + } + } - var errorBoundaryMessage = void 0; - // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow. - if (errorBoundaryFound && errorBoundaryName) { - if (willRetry) { - errorBoundaryMessage = - "React will try to recreate this component tree from scratch " + - ("using the error boundary you provided, " + errorBoundaryName + "."); - } else { - errorBoundaryMessage = - "This error was initially handled by the error boundary " + - errorBoundaryName + - ".\n" + - "Recreating the tree from scratch failed so React will unmount the tree."; + if (typeof fn.getDerivedStateFromProps === "function") { + var _componentName = getComponentName(workInProgress) || "Unknown"; + + if (!didWarnAboutGetDerivedStateOnFunctionalComponent[_componentName]) { + warning( + false, + "%s: Stateless functional components do not support getDerivedStateFromProps.", + _componentName + ); + didWarnAboutGetDerivedStateOnFunctionalComponent[ + _componentName + ] = true; + } } - } else { - errorBoundaryMessage = - "Consider adding an error boundary to your tree to customize error handling behavior.\n" + - "Visit https://fb.me/react-error-boundaries to learn more about error boundaries."; } - var combinedMessage = - "" + - componentNameMessage + - componentStack + - "\n\n" + - ("" + errorBoundaryMessage); - - // In development, we provide our own message with just the component stack. - // We don't include the original error message and JS stack because the browser - // has already printed it. Even if the application swallows the error, it is still - // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils. - console.error(combinedMessage); + reconcileChildren(current, workInProgress, value); + memoizeProps(workInProgress, props); + return workInProgress.child; } } -var invokeGuardedCallback$3 = ReactErrorUtils.invokeGuardedCallback; -var hasCaughtError$1 = ReactErrorUtils.hasCaughtError; -var clearCaughtError$1 = ReactErrorUtils.clearCaughtError; +function updateTimeoutComponent(current, workInProgress, renderExpirationTime) { + if (enableSuspense) { + var nextProps = workInProgress.pendingProps; + var prevProps = workInProgress.memoizedProps; -var didWarnAboutUndefinedSnapshotBeforeUpdate = null; -{ - didWarnAboutUndefinedSnapshotBeforeUpdate = new Set(); -} + var prevDidTimeout = workInProgress.memoizedState; -function logError(boundary, errorInfo) { - var source = errorInfo.source; - var stack = errorInfo.stack; - if (stack === null && source !== null) { - stack = getStackAddendumByWorkInProgressFiber(source); + // Check if we already attempted to render the normal state. If we did, + // and we timed out, render the placeholder state. + var alreadyCaptured = (workInProgress.effectTag & DidCapture) === NoEffect; + var nextDidTimeout = !alreadyCaptured; + + 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 (nextProps === prevProps && nextDidTimeout === prevDidTimeout) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + + var render = nextProps.children; + var nextChildren = render(nextDidTimeout); + workInProgress.memoizedProps = nextProps; + workInProgress.memoizedState = nextDidTimeout; + reconcileChildren(current, workInProgress, nextChildren); + return workInProgress.child; + } else { + return null; } +} - var capturedError = { - componentName: source !== null ? getComponentName(source) : null, - componentStack: stack !== null ? stack : "", - error: errorInfo.value, - errorBoundary: null, - errorBoundaryName: null, - errorBoundaryFound: false, - willRetry: false - }; +function updatePortalComponent(current, workInProgress, renderExpirationTime) { + pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo); + var nextChildren = workInProgress.pendingProps; + 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) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } - if (boundary !== null && boundary.tag === ClassComponent) { - capturedError.errorBoundary = boundary.stateNode; - capturedError.errorBoundaryName = getComponentName(boundary); - capturedError.errorBoundaryFound = true; - capturedError.willRetry = true; + if (current === null) { + // Portals are special because we don't append the children during mount + // but at commit. Therefore we need to track insertions which the normal + // flow doesn't do during mount. This doesn't happen at the root because + // the root always starts with a "current" with a null child. + // TODO: Consider unifying this with how the root works. + workInProgress.child = reconcileChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ); + memoizeProps(workInProgress, nextChildren); + } else { + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextChildren); } + return workInProgress.child; +} - try { - logCapturedError(capturedError); - } catch (e) { - // Prevent cycle if logCapturedError() throws. - // A cycle may still occur if logCapturedError renders a component that throws. - var suppressLogging = e && e.suppressReactErrorLogging; - if (!suppressLogging) { - console.error(e); +function propagateContextChange( + workInProgress, + context, + changedBits, + 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. + switch (fiber.tag) { + case ContextConsumer: + // Check if the context matches. + var observedBits = fiber.stateNode | 0; + if (fiber.type === context && (observedBits & changedBits) !== 0) { + // Update the expiration time of all the ancestors, including + // the alternates. + var node = fiber; + while (node !== null) { + var alternate = node.alternate; + if ( + node.expirationTime === NoWork || + node.expirationTime > renderExpirationTime + ) { + node.expirationTime = renderExpirationTime; + if ( + alternate !== null && + (alternate.expirationTime === NoWork || + alternate.expirationTime > renderExpirationTime) + ) { + alternate.expirationTime = renderExpirationTime; + } + } else if ( + alternate !== null && + (alternate.expirationTime === NoWork || + alternate.expirationTime > renderExpirationTime) + ) { + alternate.expirationTime = renderExpirationTime; + } else { + // Neither alternate was updated, which means the rest of the + // ancestor path already has sufficient priority. + break; + } + node = node.return; + } + // Don't scan deeper than a matching consumer. When we render the + // consumer, we'll continue scanning from that point. This way the + // scanning work is time-sliced. + nextFiber = null; + } else { + // Traverse down. + nextFiber = fiber.child; + } + break; + case ContextProvider: + // Don't scan deeper if this is a matching provider + nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + break; + default: + // Traverse down. + nextFiber = fiber.child; + break; + } + if (nextFiber !== null) { + // Set the return pointer of the child to the work-in-progress fiber. + nextFiber.return = fiber; + } else { + // No child. Traverse to next sibling. + nextFiber = fiber; + while (nextFiber !== null) { + if (nextFiber === workInProgress) { + // We're back to the root of this subtree. Exit. + nextFiber = null; + break; + } + var sibling = nextFiber.sibling; + if (sibling !== null) { + // Set the return pointer of the sibling to the work-in-progress fiber. + sibling.return = nextFiber.return; + nextFiber = sibling; + break; + } + // No more siblings. Traverse up. + nextFiber = nextFiber.return; + } } + fiber = nextFiber; } } -var ReactFiberCommitWork = function( - config, - captureError, - scheduleWork, - computeExpirationForFiber, - markLegacyErrorBoundaryAsFailed, - recalculateCurrentTime -) { - var getPublicInstance = config.getPublicInstance, - mutation = config.mutation, - persistence = config.persistence; - - var callComponentWillUnmountWithTimer = function(current, instance) { - startPhaseTimer(current, "componentWillUnmount"); - instance.props = current.memoizedProps; - instance.state = current.memoizedState; - instance.componentWillUnmount(); - stopPhaseTimer(); - }; +function updateContextProvider(current, workInProgress, renderExpirationTime) { + var providerType = workInProgress.type; + var context = providerType._context; - // Capture errors so they don't interrupt unmounting. - function safelyCallComponentWillUnmount(current, instance) { - { - invokeGuardedCallback$3( - null, - callComponentWillUnmountWithTimer, - null, - current, - instance - ); - if (hasCaughtError$1()) { - var unmountError = clearCaughtError$1(); - captureError(current, unmountError); - } - } - } + var newProps = workInProgress.pendingProps; + var oldProps = workInProgress.memoizedProps; + var canBailOnProps = true; - function safelyDetachRef(current) { - var ref = current.ref; - if (ref !== null) { - if (typeof ref === "function") { - { - invokeGuardedCallback$3(null, ref, null, null); - if (hasCaughtError$1()) { - var refError = clearCaughtError$1(); - captureError(current, refError); - } - } - } else { - ref.current = null; - } - } + if (hasContextChanged()) { + canBailOnProps = false; + // 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) { + workInProgress.stateNode = 0; + pushProvider(workInProgress); + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - 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." - ); - } + var newValue = newProps.value; + workInProgress.memoizedProps = newProps; + + { + var providerPropTypes = workInProgress.type.propTypes; + + if (providerPropTypes) { + checkPropTypes( + providerPropTypes, + newProps, + "prop", + "Context.Provider", + getCurrentFiberStackAddendum$1 + ); } } - function commitLifeCycles( - finishedRoot, - current, - finishedWork, - currentTime, - committedExpirationTime - ) { - switch (finishedWork.tag) { - case ClassComponent: { - var _instance2 = finishedWork.stateNode; - if (finishedWork.effectTag & Update) { - if (current === null) { - startPhaseTimer(finishedWork, "componentDidMount"); - _instance2.props = finishedWork.memoizedProps; - _instance2.state = finishedWork.memoizedState; - _instance2.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 - ); - stopPhaseTimer(); - } + var changedBits = void 0; + if (oldProps === null) { + // Initial render + changedBits = MAX_SIGNED_31_BIT_INT; + } else { + if (oldProps.value === newProps.value) { + // No change. Bailout early if children are the same. + if (oldProps.children === newProps.children && canBailOnProps) { + workInProgress.stateNode = 0; + pushProvider(workInProgress); + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + changedBits = 0; + } else { + var oldValue = oldProps.value; + // Use Object.is to compare the new context value to the old value. + // Inlined Object.is polyfill. + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + if ( + (oldValue === newValue && + (oldValue !== 0 || 1 / oldValue === 1 / newValue)) || + (oldValue !== oldValue && newValue !== newValue) // eslint-disable-line no-self-compare + ) { + // No change. Bailout early if children are the same. + if (oldProps.children === newProps.children && canBailOnProps) { + workInProgress.stateNode = 0; + pushProvider(workInProgress); + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - var updateQueue = finishedWork.updateQueue; - if (updateQueue !== null) { - _instance2.props = finishedWork.memoizedProps; - _instance2.state = finishedWork.memoizedState; - commitUpdateQueue( - finishedWork, - updateQueue, - _instance2, - committedExpirationTime - ); + changedBits = 0; + } else { + changedBits = + typeof context._calculateChangedBits === "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; } - return; - } - case HostRoot: { - var _updateQueue = finishedWork.updateQueue; - if (_updateQueue !== null) { - var _instance3 = null; - if (finishedWork.child !== null) { - switch (finishedWork.child.tag) { - case HostComponent: - _instance3 = getPublicInstance(finishedWork.child.stateNode); - break; - case ClassComponent: - _instance3 = finishedWork.child.stateNode; - break; - } + changedBits |= 0; + + if (changedBits === 0) { + // No change. Bailout early if children are the same. + if (oldProps.children === newProps.children && canBailOnProps) { + workInProgress.stateNode = 0; + pushProvider(workInProgress); + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - commitUpdateQueue( - finishedWork, - _updateQueue, - _instance3, - committedExpirationTime + } else { + propagateContextChange( + workInProgress, + context, + changedBits, + renderExpirationTime ); } - return; - } - case HostComponent: { - var _instance4 = 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). - // These effects should only be committed when components are first mounted, - // aka when there is no current/alternate. - if (current === null && finishedWork.effectTag & Update) { - var type = finishedWork.type; - var props = finishedWork.memoizedProps; - commitMount(_instance4, type, props, finishedWork); - } - - return; - } - case HostText: { - // We have no life-cycles associated with text. - return; - } - case HostPortal: { - // We have no life-cycles associated with portals. - return; - } - case Profiler: { - // We have no life-cycles associated with Profiler. - return; - } - case TimeoutComponent: { - // We have no life-cycles associated with Timeouts. - 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." - ); } } } - function commitAttachRef(finishedWork) { - var ref = finishedWork.ref; - if (ref !== null) { - var _instance5 = finishedWork.stateNode; - var instanceToUse = void 0; - switch (finishedWork.tag) { - case HostComponent: - instanceToUse = getPublicInstance(_instance5); - break; - default: - 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) - ); - } - } + workInProgress.stateNode = changedBits; + pushProvider(workInProgress); - ref.current = instanceToUse; - } - } + var newChildren = newProps.children; + reconcileChildren(current, workInProgress, newChildren); + return workInProgress.child; +} + +function updateContextConsumer(current, workInProgress, renderExpirationTime) { + var context = workInProgress.type; + var newProps = workInProgress.pendingProps; + var oldProps = workInProgress.memoizedProps; + + var newValue = getContextCurrentValue(context); + var changedBits = getContextChangedBits(context); + + 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) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } + workInProgress.memoizedProps = newProps; - function commitDetachRef(current) { - var currentRef = current.ref; - if (currentRef !== null) { - if (typeof currentRef === "function") { - currentRef(null); - } else { - currentRef.current = null; - } - } + var observedBits = newProps.unstable_observedBits; + if (observedBits === undefined || observedBits === null) { + // Subscribe to all changes by default + observedBits = MAX_SIGNED_31_BIT_INT; } + // Store the observedBits on the fiber's stateNode for quick access. + workInProgress.stateNode = observedBits; - // User-originating errors (lifecycles and refs) should not interrupt - // deletion, so don't let them throw. Host-originating errors should - // interrupt deletion, so it's okay - function commitUnmount(current) { - if (typeof onCommitUnmount === "function") { - onCommitUnmount(current); - } + if ((changedBits & observedBits) !== 0) { + // Context change propagation stops at matching consumers, for time- + // slicing. Continue the propagation here. + propagateContextChange( + workInProgress, + context, + changedBits, + renderExpirationTime + ); + } else if (oldProps === newProps) { + // Skip over a memoized parent with a bitmask bailout even + // if we began working on it because of a deeper matching child. + 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`). - switch (current.tag) { - case ClassComponent: { - safelyDetachRef(current); - var _instance6 = current.stateNode; - if (typeof _instance6.componentWillUnmount === "function") { - safelyCallComponentWillUnmount(current, _instance6); - } - return; - } - case HostComponent: { - safelyDetachRef(current); - return; - } - case HostPortal: { - // TODO: this is recursive. - // We are also not using this parent because - // the portal will get pushed immediately. - if (enableMutatingReconciler && mutation) { - unmountHostComponents(current); - } else if (enablePersistentReconciler && persistence) { - emptyPortalContainer(current); - } - return; - } - } + 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; } - function commitNestedUnmounts(root) { - // While we're inside a removed host node we don't want to call - // removeChild on the inner nodes because they're removed by the top - // call anyway. We also want to call componentWillUnmount on all - // composites before this host node is removed from the tree. Therefore - var node = root; - while (true) { - commitUnmount(node); - // Visit children because they may contain more composite or host nodes. - // Skip portals because commitUnmount() currently visits them recursively. - if ( - node.child !== null && - // If we use mutation we drill down into portals using commitUnmount above. - // If we don't use mutation we drill down into portals here instead. - (!mutation || node.tag !== HostPortal) - ) { - node.child.return = node; - node = node.child; - continue; - } - if (node === root) { - return; + var newChildren = void 0; + { + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase("render"); + newChildren = render(newValue); + ReactDebugCurrentFiber.setCurrentPhase(null); + } + + // React DevTools reads this flag. + workInProgress.effectTag |= PerformedWork; + reconcileChildren(current, workInProgress, newChildren); + return workInProgress.child; +} + +/* + function reuseChildrenEffects(returnFiber : Fiber, firstChild : Fiber) { + let child = firstChild; + do { + // Ensure that the first and last effect of the parent corresponds + // to the children's first and last effect. + if (!returnFiber.firstEffect) { + returnFiber.firstEffect = child.firstEffect; } - while (node.sibling === null) { - if (node.return === null || node.return === root) { - return; + if (child.lastEffect) { + if (returnFiber.lastEffect) { + returnFiber.lastEffect.nextEffect = child.firstEffect; } - node = node.return; + returnFiber.lastEffect = child.lastEffect; } - node.sibling.return = node.return; - node = node.sibling; - } + } while (child = child.sibling); } + */ - function detachFiber(current) { - // Cut off the return pointers to disconnect it from the tree. Ideally, we - // should clear the child pointer of the parent alternate to let this - // get GC:ed but we don't know which for sure which parent is the current - // one so we'll settle for GC:ing the subtree of this child. This child - // itself will be GC:ed when the parent updates the next time. - current.return = null; - current.child = null; - if (current.alternate) { - current.alternate.child = null; - current.alternate.return = null; - } +function bailoutOnAlreadyFinishedWork(current, workInProgress) { + cancelWorkTimer(workInProgress); + + if (enableProfilerTimer) { + // Don't update "base" render times for bailouts. + stopBaseRenderTimerIfRunning(); } - var emptyPortalContainer = void 0; + // TODO: We should ideally be able to bail out early if the children have no + // more work to do. However, since we don't have a separation of this + // Fiber's priority and its children yet - we don't know without doing lots + // of the same work we do anyway. Once we have that separation we can just + // bail out here if the children has no more work at this priority level. + // if (workInProgress.priorityOfChildren <= priorityLevel) { + // // If there are side-effects in these children that have not yet been + // // committed we need to ensure that they get properly transferred up. + // if (current && current.child !== workInProgress.child) { + // reuseChildrenEffects(workInProgress, child); + // } + // return null; + // } - if (!mutation) { - var commitContainer = void 0; - if (persistence) { - var replaceContainerChildren = persistence.replaceContainerChildren, - createContainerChildSet = persistence.createContainerChildSet; + cloneChildFibers(current, workInProgress); + return workInProgress.child; +} - emptyPortalContainer = function(current) { - var portal = current.stateNode; - var containerInfo = portal.containerInfo; +function bailoutOnLowPriority(current, workInProgress) { + cancelWorkTimer(workInProgress); - var emptyChildSet = createContainerChildSet(containerInfo); - replaceContainerChildren(containerInfo, emptyChildSet); - }; - commitContainer = function(finishedWork) { - switch (finishedWork.tag) { - case ClassComponent: { - return; - } - case HostComponent: { - return; - } - case HostText: { - return; - } - case HostRoot: - case HostPortal: { - var portalOrRoot = finishedWork.stateNode; - var containerInfo = portalOrRoot.containerInfo, - _pendingChildren = portalOrRoot.pendingChildren; + if (enableProfilerTimer) { + // Don't update "base" render times for bailouts. + stopBaseRenderTimerIfRunning(); + } - replaceContainerChildren(containerInfo, _pendingChildren); - 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." - ); - } - } - }; - } else { - commitContainer = function(finishedWork) { - // Noop - }; - } - if (enablePersistentReconciler || enableNoopReconciler) { - return { - commitResetTextContent: function(finishedWork) {}, - commitPlacement: function(finishedWork) {}, - commitDeletion: function(current) { - // Detach refs and call componentWillUnmount() on the whole subtree. - commitNestedUnmounts(current); - detachFiber(current); - }, - commitWork: function(current, finishedWork) { - commitContainer(finishedWork); - }, - - commitLifeCycles: commitLifeCycles, - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, - commitAttachRef: commitAttachRef, - commitDetachRef: commitDetachRef - }; - } else if (persistence) { - invariant(false, "Persistent reconciler is disabled."); - } else { - invariant(false, "Noop reconciler is disabled."); + // TODO: Handle HostComponent tags here as well and call pushHostContext()? + // See PR 8590 discussion for context + switch (workInProgress.tag) { + case HostRoot: + pushHostRootContext(workInProgress); + break; + case ClassComponent: + pushContextProvider(workInProgress); + break; + case HostPortal: + pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo); + break; + case ContextProvider: + pushProvider(workInProgress); + break; + } + // TODO: What if this is currently in progress? + // How can that happen? How is this not being cloned? + return null; +} + +// TODO: Delete memoizeProps/State and move to reconcile/bailout instead +function memoizeProps(workInProgress, nextProps) { + workInProgress.memoizedProps = nextProps; +} + +function memoizeState(workInProgress, nextState) { + workInProgress.memoizedState = nextState; + // Don't reset the updateQueue, in case there are pending updates. Resetting + // is handled by processUpdateQueue. +} + +function beginWork(current, workInProgress, renderExpirationTime) { + if (enableProfilerTimer) { + if (workInProgress.mode & ProfileMode) { + markActualRenderTimeStarted(workInProgress); } } - var commitMount = mutation.commitMount, - commitUpdate = mutation.commitUpdate, - resetTextContent = mutation.resetTextContent, - commitTextUpdate = mutation.commitTextUpdate, - appendChild$$1 = mutation.appendChild, - appendChildToContainer = mutation.appendChildToContainer, - insertBefore = mutation.insertBefore, - insertInContainerBefore = mutation.insertInContainerBefore, - removeChild = mutation.removeChild, - removeChildFromContainer = mutation.removeChildFromContainer; - function getHostParentFiber(fiber) { - var parent = fiber.return; - while (parent !== null) { - if (isHostParent(parent)) { - return parent; - } - parent = parent.return; - } - invariant( - false, - "Expected to find a host parent. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - } + if ( + workInProgress.expirationTime === NoWork || + workInProgress.expirationTime > renderExpirationTime + ) { + return bailoutOnLowPriority(current, workInProgress); + } + + switch (workInProgress.tag) { + case IndeterminateComponent: + return mountIndeterminateComponent( + current, + workInProgress, + renderExpirationTime + ); + case FunctionalComponent: + return updateFunctionalComponent(current, workInProgress); + case ClassComponent: + return updateClassComponent( + current, + workInProgress, + renderExpirationTime + ); + case HostRoot: + return updateHostRoot(current, workInProgress, renderExpirationTime); + case HostComponent: + return updateHostComponent(current, workInProgress, renderExpirationTime); + case HostText: + return updateHostText(current, workInProgress); + case TimeoutComponent: + return updateTimeoutComponent( + current, + workInProgress, + renderExpirationTime + ); + case HostPortal: + return updatePortalComponent( + current, + workInProgress, + renderExpirationTime + ); + case ForwardRef: + return updateForwardRef(current, workInProgress); + case Fragment: + return updateFragment(current, workInProgress); + case Mode: + return updateMode(current, workInProgress); + case Profiler: + return updateProfiler(current, workInProgress); + case ContextProvider: + return updateContextProvider( + current, + workInProgress, + renderExpirationTime + ); + case ContextConsumer: + return updateContextConsumer( + current, + workInProgress, + renderExpirationTime + ); + default: + invariant( + false, + "Unknown unit of work tag. This error is likely caused by a bug in " + + "React. Please file an issue." + ); + } +} + +function markUpdate(workInProgress) { + // Tag the fiber with an update effect. This turns a Placement into + // a PlacementAndUpdate. + workInProgress.effectTag |= Update; +} - function isHostParent(fiber) { - return ( - fiber.tag === HostComponent || - fiber.tag === HostRoot || - fiber.tag === HostPortal - ); - } +function markRef$1(workInProgress) { + workInProgress.effectTag |= Ref; +} - function getHostSibling(fiber) { - // We're going to search forward into the tree until we find a sibling host - // node. Unfortunately, if multiple insertions are done in a row we have to - // search past them. This leads to exponential search for the next sibling. - var node = fiber; - siblings: while (true) { - // If we didn't find anything, let's try the next sibling. - while (node.sibling === null) { - if (node.return === null || isHostParent(node.return)) { - // If we pop out of the root or hit the parent the fiber we are the - // last sibling. - return null; - } - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - while (node.tag !== HostComponent && node.tag !== HostText) { - // If it is not host node and, we might have a host node inside it. - // Try to search down until we find one. - if (node.effectTag & Placement) { - // If we don't have a child, try the siblings instead. - continue siblings; - } - // If we don't have a child, try the siblings instead. - // We also skip portals because they are not part of this host tree. - if (node.child === null || node.tag === HostPortal) { - continue siblings; - } else { - node.child.return = node; - node = node.child; - } - } - // Check if this host node is stable or about to be placed. - if (!(node.effectTag & Placement)) { - // Found it! - return node.stateNode; +function appendAllChildren(parent, workInProgress) { + // We only have the top Fiber that was created but we need recurse down its + // children to find all the terminal nodes. + var node = workInProgress.child; + while (node !== null) { + if (node.tag === HostComponent || node.tag === HostText) { + appendInitialChild(parent, node.stateNode); + } else if (node.tag === HostPortal) { + // If we have a portal child, then we don't want to traverse + // down its children. Instead, we'll get insertions from each child in + // the portal directly. + } else if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; + } + if (node === workInProgress) { + return; + } + while (node.sibling === null) { + if (node.return === null || node.return === workInProgress) { + return; } + node = node.return; } + node.sibling.return = node.return; + node = node.sibling; } +} - function commitPlacement(finishedWork) { - // Recursively insert all host nodes into the parent. - var parentFiber = getHostParentFiber(finishedWork); - var parent = void 0; - var isContainer = void 0; - switch (parentFiber.tag) { - case HostComponent: - parent = parentFiber.stateNode; - isContainer = false; - break; - case HostRoot: - parent = parentFiber.stateNode.containerInfo; - isContainer = true; - break; - case HostPortal: - parent = parentFiber.stateNode.containerInfo; - isContainer = true; - break; - default: - invariant( - false, - "Invalid host parent fiber. This error is likely caused by a bug " + - "in React. Please file an issue." - ); +var updateHostContainer = void 0; +var updateHostComponent$1 = void 0; +var updateHostText$1 = void 0; +if (supportsMutation) { + // Mutation mode + + updateHostContainer = function(workInProgress) { + // Noop + }; + updateHostComponent$1 = function( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ) { + // TODO: Type this specific to this type of component. + workInProgress.updateQueue = updatePayload; + // If the update payload indicates that there is a change or if there + // is a new ref we mark this as an update. All the work is done in commitWork. + if (updatePayload) { + markUpdate(workInProgress); } - if (parentFiber.effectTag & ContentReset) { - // Reset the text content of the parent before doing any insertions - resetTextContent(parent); - // Clear ContentReset from the effect tag - parentFiber.effectTag &= ~ContentReset; + }; + updateHostText$1 = function(current, workInProgress, oldText, newText) { + // If the text differs, mark it as an update. All the work in done in commitWork. + if (oldText !== newText) { + markUpdate(workInProgress); } + }; +} else if (supportsPersistence) { + // Persistent host tree mode - var before = getHostSibling(finishedWork); - // We only have the top Fiber that was inserted but we need recurse down its + // An unfortunate fork of appendAllChildren because we have two different parent types. + var appendAllChildrenToContainer = function( + containerChildSet, + workInProgress + ) { + // We only have the top Fiber that was created but we need recurse down its // children to find all the terminal nodes. - var node = finishedWork; - while (true) { + var node = workInProgress.child; + while (node !== null) { if (node.tag === HostComponent || node.tag === HostText) { - if (before) { - if (isContainer) { - insertInContainerBefore(parent, node.stateNode, before); - } else { - insertBefore(parent, node.stateNode, before); - } - } else { - if (isContainer) { - appendChildToContainer(parent, node.stateNode); - } else { - appendChild$$1(parent, node.stateNode); - } - } + appendChildToContainerChildSet(containerChildSet, node.stateNode); } else if (node.tag === HostPortal) { - // If the insertion itself is a portal, then we don't want to traverse + // If we have a portal child, then we don't want to traverse // down its children. Instead, we'll get insertions from each child in // the portal directly. } else if (node.child !== null) { @@ -10633,11 +10583,11 @@ var ReactFiberCommitWork = function( node = node.child; continue; } - if (node === finishedWork) { + if (node === workInProgress) { return; } while (node.sibling === null) { - if (node.return === null || node.return === finishedWork) { + if (node.return === null || node.return === workInProgress) { return; } node = node.return; @@ -10645,1629 +10595,1489 @@ var ReactFiberCommitWork = function( node.sibling.return = node.return; node = node.sibling; } - } - - function unmountHostComponents(current) { - // We only have the top Fiber that was inserted but we need recurse down its - var node = current; - - // Each iteration, currentParent is populated with node's host parent if not - // currentParentIsValid. - var currentParentIsValid = false; - var currentParent = void 0; - var currentParentIsContainer = void 0; - - while (true) { - if (!currentParentIsValid) { - var parent = node.return; - findParent: while (true) { - invariant( - parent !== null, - "Expected to find a host parent. This error is likely caused by " + - "a bug in React. Please file an issue." - ); - switch (parent.tag) { - case HostComponent: - currentParent = parent.stateNode; - currentParentIsContainer = false; - break findParent; - case HostRoot: - currentParent = parent.stateNode.containerInfo; - currentParentIsContainer = true; - break findParent; - case HostPortal: - currentParent = parent.stateNode.containerInfo; - currentParentIsContainer = true; - break findParent; - } - parent = parent.return; - } - currentParentIsValid = true; - } - - if (node.tag === HostComponent || node.tag === HostText) { - commitNestedUnmounts(node); - // After all the children have unmounted, it is now safe to remove the - // node from the tree. - if (currentParentIsContainer) { - removeChildFromContainer(currentParent, node.stateNode); - } else { - removeChild(currentParent, node.stateNode); - } - // Don't visit children because we already visited them. - } else if (node.tag === HostPortal) { - // When we go into a portal, it becomes the parent to remove from. - // We will reassign it back when we pop the portal on the way up. - currentParent = node.stateNode.containerInfo; - // Visit children because portals might contain host components. - if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; - } + }; + updateHostContainer = function(workInProgress) { + var portalOrRoot = workInProgress.stateNode; + var childrenUnchanged = workInProgress.firstEffect === null; + if (childrenUnchanged) { + // No changes, just reuse the existing instance. + } else { + var container = portalOrRoot.containerInfo; + var newChildSet = createContainerChildSet(container); + // If children might have changed, we have to add them all to the set. + appendAllChildrenToContainer(newChildSet, workInProgress); + portalOrRoot.pendingChildren = newChildSet; + // Schedule an update on the container to swap out the container. + markUpdate(workInProgress); + finalizeContainerChildren(container, newChildSet); + } + }; + updateHostComponent$1 = function( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ) { + // If there are no effects associated with this node, then none of our children had any updates. + // This guarantees that we can reuse all of them. + var childrenUnchanged = workInProgress.firstEffect === null; + var currentInstance = current.stateNode; + if (childrenUnchanged && updatePayload === null) { + // No changes, just reuse the existing instance. + // Note that this might release a previous clone. + workInProgress.stateNode = currentInstance; + } else { + var recyclableInstance = workInProgress.stateNode; + var newInstance = cloneInstance( + currentInstance, + updatePayload, + type, + oldProps, + newProps, + workInProgress, + childrenUnchanged, + recyclableInstance + ); + if ( + finalizeInitialChildren( + newInstance, + type, + newProps, + rootContainerInstance, + currentHostContext + ) + ) { + markUpdate(workInProgress); + } + workInProgress.stateNode = newInstance; + if (childrenUnchanged) { + // If there are no other effects in this tree, we need to flag this node as having one. + // Even though we're not going to use it for anything. + // Otherwise parents won't know that there are new children to propagate upwards. + markUpdate(workInProgress); } else { - commitUnmount(node); - // Visit children because we may find more host components below. - if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; - } - } - if (node === current) { - return; - } - while (node.sibling === null) { - if (node.return === null || node.return === current) { - return; - } - node = node.return; - if (node.tag === HostPortal) { - // When we go out of the portal, we need to restore the parent. - // Since we don't keep a stack of them, we will search for it. - currentParentIsValid = false; - } + // If children might have changed, we have to add them all to the set. + appendAllChildren(newInstance, workInProgress); } - node.sibling.return = node.return; - node = node.sibling; } - } - - function commitDeletion(current) { - // Recursively delete all host nodes from the parent. - // Detach refs and call componentWillUnmount() on the whole subtree. - unmountHostComponents(current); - detachFiber(current); - } - - function commitWork(current, finishedWork) { - switch (finishedWork.tag) { - case ClassComponent: { - return; - } - case HostComponent: { - 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 - // as the newProps. The updatePayload will contain the real change in - // this case. - var oldProps = current !== null ? current.memoizedProps : newProps; - var type = finishedWork.type; - // TODO: Type the updateQueue to be specific to host components. - var updatePayload = finishedWork.updateQueue; - finishedWork.updateQueue = null; - if (updatePayload !== null) { - commitUpdate( - _instance7, - updatePayload, - type, - oldProps, - newProps, - finishedWork - ); - } - } - return; - } - case HostText: { - invariant( - finishedWork.stateNode !== null, - "This should have a text node initialized. This error is likely " + - "caused by a bug in React. Please file an issue." - ); - var textInstance = finishedWork.stateNode; - var newText = finishedWork.memoizedProps; - // For hydration we reuse the update path but we treat the oldProps - // as the newProps. The updatePayload will contain the real change in - // this case. - var oldText = current !== null ? current.memoizedProps : newText; - commitTextUpdate(textInstance, oldText, newText); - return; - } - case HostRoot: { - return; - } - case Profiler: { - if (enableProfilerTimer) { - var onRender = finishedWork.memoizedProps.onRender; - onRender( - finishedWork.memoizedProps.id, - current === null ? "mount" : "update", - finishedWork.stateNode.duration, - finishedWork.treeBaseTime - ); - - // Reset actualTime after successful commit. - // By default, we append to this time to account for errors and pauses. - finishedWork.stateNode.duration = 0; - } - return; - } - case TimeoutComponent: { - 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." - ); - } + }; + updateHostText$1 = function(current, workInProgress, oldText, newText) { + if (oldText !== newText) { + // If the text content differs, we'll create a new text instance for it. + var rootContainerInstance = getRootHostContainer(); + var currentHostContext = getHostContext(); + workInProgress.stateNode = createTextInstance( + newText, + rootContainerInstance, + currentHostContext, + workInProgress + ); + // We'll have to mark it as having an effect, even though we won't use the effect for anything. + // This lets the parents know that at least one of their children has changed. + markUpdate(workInProgress); } - } - - function commitResetTextContent(current) { - resetTextContent(current.stateNode); - } - - if (enableMutatingReconciler) { - return { - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, - commitResetTextContent: commitResetTextContent, - commitPlacement: commitPlacement, - commitDeletion: commitDeletion, - commitWork: commitWork, - commitLifeCycles: commitLifeCycles, - commitAttachRef: commitAttachRef, - commitDetachRef: commitDetachRef - }; - } else { - invariant(false, "Mutating reconciler is disabled."); - } -}; - -var ReactFiberUnwindWork = function( - config, - hostContext, - legacyContext, - newContext, - scheduleWork, - computeExpirationForFiber, - recalculateCurrentTime, - markLegacyErrorBoundaryAsFailed, - isAlreadyFailedLegacyErrorBoundary, - onUncaughtError, - profilerTimer, - suspendRoot, - retrySuspendedRoot -) { - var popHostContainer = hostContext.popHostContainer, - popHostContext = hostContext.popHostContext; - var popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject; - var popProvider = newContext.popProvider; - var resumeActualRenderTimerIfPaused = - profilerTimer.resumeActualRenderTimerIfPaused, - recordElapsedActualRenderTime = profilerTimer.recordElapsedActualRenderTime; - - function createRootErrorUpdate(fiber, errorInfo, expirationTime) { - var update = createUpdate(expirationTime); - // Unmount the root by rendering null. - update.tag = CaptureUpdate; - // Caution: React DevTools currently depends on this property - // being called "element". - update.payload = { element: null }; - var error = errorInfo.value; - update.callback = function() { - onUncaughtError(error); - logError(fiber, errorInfo); - }; - return update; - } + }; +} else { + // No host operations + updateHostContainer = function(workInProgress) { + // Noop + }; + updateHostComponent$1 = function( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ) { + // Noop + }; + updateHostText$1 = function(current, workInProgress, oldText, newText) { + // Noop + }; +} - function createClassErrorUpdate(fiber, errorInfo, expirationTime) { - var update = createUpdate(expirationTime); - update.tag = CaptureUpdate; - var getDerivedStateFromCatch = fiber.type.getDerivedStateFromCatch; - if ( - enableGetDerivedStateFromCatch && - typeof getDerivedStateFromCatch === "function" - ) { - var _error = errorInfo.value; - update.payload = function() { - return getDerivedStateFromCatch(_error); - }; - } +function completeWork(current, workInProgress, renderExpirationTime) { + var newProps = workInProgress.pendingProps; - var inst = fiber.stateNode; - if (inst !== null && typeof inst.componentDidCatch === "function") { - update.callback = function callback() { - if ( - !enableGetDerivedStateFromCatch || - getDerivedStateFromCatch !== "function" - ) { - // To preserve the preexisting retry behavior of error boundaries, - // we keep track of which ones already failed during this batch. - // This gets reset before we yield back to the browser. - // TODO: Warn in strict mode if getDerivedStateFromCatch is - // not defined. - markLegacyErrorBoundaryAsFailed(this); - } - var error = errorInfo.value; - var stack = errorInfo.stack; - logError(fiber, errorInfo); - this.componentDidCatch(error, { - componentStack: stack !== null ? stack : "" - }); - }; + if (enableProfilerTimer) { + if (workInProgress.mode & ProfileMode) { + recordElapsedActualRenderTime(workInProgress); } - return update; - } - - function schedulePing(finishedWork) { - // Once the promise resolves, we should try rendering the non- - // placeholder state again. - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, finishedWork); - var recoveryUpdate = createUpdate(expirationTime); - enqueueUpdate(finishedWork, recoveryUpdate, expirationTime); - scheduleWork(finishedWork, expirationTime); } - function throwException( - root, - returnFiber, - sourceFiber, - value, - renderIsExpired, - renderExpirationTime, - currentTimeMs - ) { - // The source fiber did not complete. - sourceFiber.effectTag |= Incomplete; - // Its effect list is no longer valid. - sourceFiber.firstEffect = sourceFiber.lastEffect = null; - - if ( - enableSuspense && - value !== null && - typeof value === "object" && - typeof value.then === "function" - ) { - // This is a thenable. - var _thenable = value; - - var expirationTimeMs = expirationTimeToMs(renderExpirationTime); - var startTimeMs = expirationTimeMs - 5000; - var elapsedMs = currentTimeMs - startTimeMs; - if (elapsedMs < 0) { - elapsedMs = 0; - } - var remainingTimeMs = expirationTimeMs - currentTimeMs; - - // Find the earliest timeout of all the timeouts in the ancestor path. - // TODO: Alternatively, we could store the earliest timeout on the context - // stack, rather than searching on every suspend. - var _workInProgress = returnFiber; - var earliestTimeoutMs = -1; - searchForEarliestTimeout: do { - if (_workInProgress.tag === TimeoutComponent) { - var current = _workInProgress.alternate; - if (current !== null && current.memoizedState === true) { - // A parent Timeout already committed in a placeholder state. We - // need to handle this promise immediately. In other words, we - // should never suspend inside a tree that already expired. - earliestTimeoutMs = 0; - break searchForEarliestTimeout; - } - var timeoutPropMs = _workInProgress.pendingProps.ms; - if (typeof timeoutPropMs === "number") { - if (timeoutPropMs <= 0) { - earliestTimeoutMs = 0; - break searchForEarliestTimeout; - } else if ( - earliestTimeoutMs === -1 || - timeoutPropMs < earliestTimeoutMs - ) { - earliestTimeoutMs = timeoutPropMs; - } - } else if (earliestTimeoutMs === -1) { - earliestTimeoutMs = remainingTimeMs; - } - } - _workInProgress = _workInProgress.return; - } while (_workInProgress !== null); - - // Compute the remaining time until the timeout. - var msUntilTimeout = earliestTimeoutMs - elapsedMs; - - if (renderExpirationTime === Never || msUntilTimeout > 0) { - // There's still time remaining. - suspendRoot(root, _thenable, msUntilTimeout, renderExpirationTime); - var onResolveOrReject = function() { - retrySuspendedRoot(root, renderExpirationTime); - }; - _thenable.then(onResolveOrReject, onResolveOrReject); - return; - } else { - // No time remaining. Need to fallback to placeholder. - // Find the nearest timeout that can be retried. - _workInProgress = returnFiber; - do { - switch (_workInProgress.tag) { - case HostRoot: { - // The root expired, but no fallback was provided. Throw a - // helpful error. - var message = - renderExpirationTime === Sync - ? "A synchronous update was suspended, but no fallback UI " + - "was provided." - : "An update was suspended for longer than the timeout, " + - "but no fallback UI was provided."; - value = new Error(message); - break; - } - case TimeoutComponent: { - if ((_workInProgress.effectTag & DidCapture) === NoEffect) { - _workInProgress.effectTag |= ShouldCapture; - var _onResolveOrReject = schedulePing.bind( - null, - _workInProgress - ); - _thenable.then(_onResolveOrReject, _onResolveOrReject); - return; - } - // Already captured during this render. Continue to the next - // Timeout ancestor. - break; - } - } - _workInProgress = _workInProgress.return; - } while (_workInProgress !== null); + switch (workInProgress.tag) { + case FunctionalComponent: + return null; + case ClassComponent: { + // We are leaving this subtree, so pop context if any. + popContextProvider(workInProgress); + return null; + } + case HostRoot: { + popHostContainer(workInProgress); + popTopLevelContextObject(workInProgress); + var fiberRoot = workInProgress.stateNode; + if (fiberRoot.pendingContext) { + fiberRoot.context = fiberRoot.pendingContext; + fiberRoot.pendingContext = null; + } + if (current === null || current.child === null) { + // If we hydrated, pop so that we can delete any remaining children + // that weren't hydrated. + popHydrationState(workInProgress); + // This resets the hacky state to fix isMounted before committing. + // TODO: Delete this when we delete isMounted and findDOMNode. + workInProgress.effectTag &= ~Placement; } + updateHostContainer(workInProgress); + return null; } + case HostComponent: { + popHostContext(workInProgress); + var rootContainerInstance = getRootHostContainer(); + var type = workInProgress.type; + if (current !== null && workInProgress.stateNode != null) { + // If we have an alternate, that means this is an update and we need to + // schedule a side-effect to do the updates. + var oldProps = current.memoizedProps; + // If we get updated because one of our children updated, we don't + // have newProps so we'll have to reuse them. + // TODO: Split the update API as separate for the props vs. children. + // Even better would be if children weren't special cased at all tho. + var instance = workInProgress.stateNode; + var currentHostContext = getHostContext(); + // TODO: Experiencing an error where oldProps is null. Suggests a host + // component is hitting the resume path. Figure out why. Possibly + // related to `hidden`. + var updatePayload = prepareUpdate( + instance, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ); - // We didn't find a boundary that could handle this type of exception. Start - // over and traverse parent path again, this time treating the exception - // as an error. - value = createCapturedValue(value, sourceFiber); - var workInProgress = returnFiber; - do { - switch (workInProgress.tag) { - case HostRoot: { - var _errorInfo = value; - workInProgress.effectTag |= ShouldCapture; - var update = createRootErrorUpdate( - workInProgress, - _errorInfo, - renderExpirationTime + updateHostComponent$1( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ); + + if (current.ref !== workInProgress.ref) { + markRef$1(workInProgress); + } + } else { + if (!newProps) { + invariant( + workInProgress.stateNode !== null, + "We must have new props for new mounts. This error is likely " + + "caused by a bug in React. Please file an issue." ); - enqueueCapturedUpdate(workInProgress, update, renderExpirationTime); - return; + // This can happen when we abort work. + return null; } - case ClassComponent: - // Capture and retry - var errorInfo = value; - var ctor = workInProgress.type; - var _instance = workInProgress.stateNode; + + var _currentHostContext = getHostContext(); + // TODO: Move createInstance to beginWork and keep it on a context + // "stack" as the parent. Then append children as we go in beginWork + // or completeWork depending on we want to add then top->down or + // bottom->up. Top->down is faster in IE11. + var wasHydrated = popHydrationState(workInProgress); + if (wasHydrated) { + // TODO: Move this and createInstance step into the beginPhase + // to consolidate. if ( - (workInProgress.effectTag & DidCapture) === NoEffect && - ((typeof ctor.getDerivedStateFromCatch === "function" && - enableGetDerivedStateFromCatch) || - (_instance !== null && - typeof _instance.componentDidCatch === "function" && - !isAlreadyFailedLegacyErrorBoundary(_instance))) - ) { - workInProgress.effectTag |= ShouldCapture; - // Schedule the error boundary to re-render using updated state - var _update = createClassErrorUpdate( + prepareToHydrateHostInstance( workInProgress, - errorInfo, - renderExpirationTime - ); - enqueueCapturedUpdate( - workInProgress, - _update, - renderExpirationTime - ); - return; + rootContainerInstance, + _currentHostContext + ) + ) { + // If changes to the hydrated node needs to be applied at the + // commit-phase we mark this as such. + markUpdate(workInProgress); } - break; - default: - break; - } - workInProgress = workInProgress.return; - } while (workInProgress !== null); - } + } else { + var _instance = createInstance( + type, + newProps, + rootContainerInstance, + _currentHostContext, + workInProgress + ); - function unwindWork(workInProgress, renderIsExpired, renderExpirationTime) { - switch (workInProgress.tag) { - case ClassComponent: { - popLegacyContextProvider(workInProgress); - var effectTag = workInProgress.effectTag; - if (effectTag & ShouldCapture) { - workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture; - return workInProgress; + appendAllChildren(_instance, workInProgress); + + // Certain renderers require commit-time effects for initial mount. + // (eg DOM renderer supports auto-focus for certain elements). + // Make sure such renderers get scheduled for later work. + if ( + finalizeInitialChildren( + _instance, + type, + newProps, + rootContainerInstance, + _currentHostContext + ) + ) { + markUpdate(workInProgress); + } + workInProgress.stateNode = _instance; } - return null; - } - case HostRoot: { - popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); - var _effectTag = workInProgress.effectTag; - if (_effectTag & ShouldCapture) { - workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture; - return workInProgress; + + if (workInProgress.ref !== null) { + // If there is a ref on a host node we need to schedule a callback + markRef$1(workInProgress); } - return null; } - case HostComponent: { - popHostContext(workInProgress); - return null; - } - case TimeoutComponent: { - var _effectTag2 = workInProgress.effectTag; - if (_effectTag2 & ShouldCapture) { - workInProgress.effectTag = - (_effectTag2 & ~ShouldCapture) | DidCapture; - return workInProgress; + return null; + } + case HostText: { + var newText = newProps; + if (current && workInProgress.stateNode != null) { + var oldText = current.memoizedProps; + // If we have an alternate, that means this is an update and we need + // to schedule a side-effect to do the updates. + updateHostText$1(current, workInProgress, oldText, newText); + } else { + if (typeof newText !== "string") { + invariant( + workInProgress.stateNode !== null, + "We must have new props for new mounts. This error is likely " + + "caused by a bug in React. Please file an issue." + ); + // This can happen when we abort work. + return null; + } + var _rootContainerInstance = getRootHostContainer(); + var _currentHostContext2 = getHostContext(); + var _wasHydrated = popHydrationState(workInProgress); + if (_wasHydrated) { + if (prepareToHydrateHostTextInstance(workInProgress)) { + markUpdate(workInProgress); + } + } else { + workInProgress.stateNode = createTextInstance( + newText, + _rootContainerInstance, + _currentHostContext2, + workInProgress + ); } - return null; } - case HostPortal: - popHostContainer(workInProgress); - return null; - case ContextProvider: - popProvider(workInProgress); - return null; - default: - return null; + return null; } + case ForwardRef: + return null; + case TimeoutComponent: + return null; + case Fragment: + return null; + case Mode: + return null; + case Profiler: + return null; + case HostPortal: + popHostContainer(workInProgress); + updateHostContainer(workInProgress); + return null; + case ContextProvider: + // Pop provider fiber + popProvider(workInProgress); + return null; + case ContextConsumer: + return null; + // Error cases + case IndeterminateComponent: + invariant( + false, + "An indeterminate component should have become determinate before " + + "completing. This error is likely caused by a bug in React. Please " + + "file an issue." + ); + // eslint-disable-next-line no-fallthrough + default: + invariant( + false, + "Unknown unit of work tag. This error is likely caused by a bug in " + + "React. Please file an issue." + ); } +} - 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; - case Profiler: - if (enableProfilerTimer) { - // Resume in case we're picking up on work that was paused. - resumeActualRenderTimerIfPaused(); - recordElapsedActualRenderTime(interruptedWork); - } - break; - default: - break; - } - } +// Module provided by RN: +/** + * Intercept lifecycle errors and ensure they are shown with the correct stack + * trace within the native redbox component. + */ +function showErrorDialog(capturedError) { + var componentStack = capturedError.componentStack, + error = capturedError.error; - return { - throwException: throwException, - unwindWork: unwindWork, - unwindInterruptedWork: unwindInterruptedWork, - createRootErrorUpdate: createRootErrorUpdate, - createClassErrorUpdate: createClassErrorUpdate - }; -}; + var errorToHandle = void 0; -var NO_CONTEXT = {}; + // Typically Errors are thrown but eg strings or null can be thrown as well. + if (error instanceof Error) { + var message = error.message, + name = error.name; -var ReactFiberHostContext = function(config, stack) { - var getChildHostContext = config.getChildHostContext, - getRootHostContext = config.getRootHostContext; - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; + var summary = message ? name + ": " + message : name; - var contextStackCursor = createCursor(NO_CONTEXT); - var contextFiberStackCursor = createCursor(NO_CONTEXT); - var rootInstanceStackCursor = createCursor(NO_CONTEXT); + errorToHandle = error; - function requiredContext(c) { - invariant( - c !== NO_CONTEXT, - "Expected host context to exist. This error is likely caused by a bug " + - "in React. Please file an issue." + try { + errorToHandle.message = + summary + "\n\nThis error is located at:" + componentStack; + } catch (e) {} + } else if (typeof error === "string") { + errorToHandle = new Error( + error + "\n\nThis error is located at:" + componentStack ); - return c; + } else { + errorToHandle = new Error("Unspecified error at:" + componentStack); } - function getRootHostContainer() { - var rootInstance = requiredContext(rootInstanceStackCursor.current); - return rootInstance; - } + ExceptionsManager.handleException(errorToHandle, false); + + // Return false here to prevent ReactFiberErrorLogger default behavior of + // logging error details to console.error. Calls to console.error are + // automatically routed to the native redbox controller, which we've already + // done above by calling ExceptionsManager. + return false; +} - function pushHostContainer(fiber, nextRootInstance) { - // Push current root instance onto the stack; - // This allows us to reset root when portals are popped. - push(rootInstanceStackCursor, nextRootInstance, fiber); - // Track the context and the Fiber that provided it. - // This enables us to pop only Fibers that provide unique contexts. - push(contextFiberStackCursor, fiber, fiber); +function logCapturedError(capturedError) { + var logError = showErrorDialog(capturedError); - // 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); + // Allow injected showErrorDialog() to prevent default console.error logging. + // This enables renderers like ReactNative to better manage redbox behavior. + if (logError === false) { + return; } - function popHostContainer(fiber) { - pop(contextStackCursor, fiber); - pop(contextFiberStackCursor, fiber); - pop(rootInstanceStackCursor, fiber); + var error = capturedError.error; + var suppressLogging = error && error.suppressReactErrorLogging; + if (suppressLogging) { + return; } - function getHostContext() { - var context = requiredContext(contextStackCursor.current); - return context; - } + { + var componentName = capturedError.componentName, + componentStack = capturedError.componentStack, + errorBoundaryName = capturedError.errorBoundaryName, + errorBoundaryFound = capturedError.errorBoundaryFound, + willRetry = capturedError.willRetry; - function pushHostContext(fiber) { - var rootInstance = requiredContext(rootInstanceStackCursor.current); - var context = requiredContext(contextStackCursor.current); - var nextContext = getChildHostContext(context, fiber.type, rootInstance); + var componentNameMessage = componentName + ? "The above error occurred in the <" + componentName + "> component:" + : "The above error occurred in one of your React components:"; - // Don't push this Fiber's context unless it's unique. - if (context === nextContext) { - return; + var errorBoundaryMessage = void 0; + // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow. + if (errorBoundaryFound && errorBoundaryName) { + if (willRetry) { + errorBoundaryMessage = + "React will try to recreate this component tree from scratch " + + ("using the error boundary you provided, " + errorBoundaryName + "."); + } else { + errorBoundaryMessage = + "This error was initially handled by the error boundary " + + errorBoundaryName + + ".\n" + + "Recreating the tree from scratch failed so React will unmount the tree."; + } + } else { + errorBoundaryMessage = + "Consider adding an error boundary to your tree to customize error handling behavior.\n" + + "Visit https://fb.me/react-error-boundaries to learn more about error boundaries."; } + var combinedMessage = + "" + + componentNameMessage + + componentStack + + "\n\n" + + ("" + errorBoundaryMessage); - // Track the context and the Fiber that provided it. - // This enables us to pop only Fibers that provide unique contexts. - push(contextFiberStackCursor, fiber, fiber); - push(contextStackCursor, nextContext, fiber); + // In development, we provide our own message with just the component stack. + // We don't include the original error message and JS stack because the browser + // has already printed it. Even if the application swallows the error, it is still + // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils. + console.error(combinedMessage); } +} - function popHostContext(fiber) { - // Do not pop unless this Fiber provided the current context. - // pushHostContext() only pushes Fibers that provide unique contexts. - if (contextFiberStackCursor.current !== fiber) { - return; +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; + if (stack === null && source !== null) { + stack = getStackAddendumByWorkInProgressFiber(source); + } + + var capturedError = { + componentName: source !== null ? getComponentName(source) : null, + componentStack: stack !== null ? stack : "", + error: errorInfo.value, + errorBoundary: null, + errorBoundaryName: null, + errorBoundaryFound: false, + willRetry: false + }; + + if (boundary !== null && boundary.tag === ClassComponent) { + capturedError.errorBoundary = boundary.stateNode; + capturedError.errorBoundaryName = getComponentName(boundary); + capturedError.errorBoundaryFound = true; + capturedError.willRetry = true; + } + + try { + logCapturedError(capturedError); + } catch (e) { + // Prevent cycle if logCapturedError() throws. + // A cycle may still occur if logCapturedError renders a component that throws. + var suppressLogging = e && e.suppressReactErrorLogging; + if (!suppressLogging) { + console.error(e); } - - pop(contextStackCursor, fiber); - pop(contextFiberStackCursor, fiber); } +} - return { - getHostContext: getHostContext, - getRootHostContainer: getRootHostContainer, - popHostContainer: popHostContainer, - popHostContext: popHostContext, - pushHostContainer: pushHostContainer, - pushHostContext: pushHostContext - }; +var callComponentWillUnmountWithTimer = function(current, instance) { + startPhaseTimer(current, "componentWillUnmount"); + instance.props = current.memoizedProps; + instance.state = current.memoizedState; + instance.componentWillUnmount(); + stopPhaseTimer(); }; -var ReactFiberHydrationContext = function(config) { - var shouldSetTextContent = config.shouldSetTextContent, - hydration = config.hydration; - - // If this doesn't have hydration mode. - - if (!hydration) { - return { - enterHydrationState: function() { - return false; - }, - resetHydrationState: function() {}, - tryToClaimNextHydratableInstance: function() {}, - prepareToHydrateHostInstance: function() { - invariant( - false, - "Expected prepareToHydrateHostInstance() to never be called. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - }, - prepareToHydrateHostTextInstance: function() { - invariant( - false, - "Expected prepareToHydrateHostTextInstance() to never be called. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - }, - popHydrationState: function(fiber) { - return false; - } - }; - } - - var canHydrateInstance = hydration.canHydrateInstance, - canHydrateTextInstance = hydration.canHydrateTextInstance, - getNextHydratableSibling = hydration.getNextHydratableSibling, - getFirstHydratableChild = hydration.getFirstHydratableChild, - hydrateInstance = hydration.hydrateInstance, - hydrateTextInstance = hydration.hydrateTextInstance, - didNotMatchHydratedContainerTextInstance = - hydration.didNotMatchHydratedContainerTextInstance, - didNotMatchHydratedTextInstance = hydration.didNotMatchHydratedTextInstance, - didNotHydrateContainerInstance = hydration.didNotHydrateContainerInstance, - didNotHydrateInstance = hydration.didNotHydrateInstance, - didNotFindHydratableContainerInstance = - hydration.didNotFindHydratableContainerInstance, - didNotFindHydratableContainerTextInstance = - hydration.didNotFindHydratableContainerTextInstance, - didNotFindHydratableInstance = hydration.didNotFindHydratableInstance, - didNotFindHydratableTextInstance = - hydration.didNotFindHydratableTextInstance; - - // The deepest Fiber on the stack involved in a hydration context. - // This may have been an insertion or a hydration. - - var hydrationParentFiber = null; - var nextHydratableInstance = null; - var isHydrating = false; - - function enterHydrationState(fiber) { - var parentInstance = fiber.stateNode.containerInfo; - nextHydratableInstance = getFirstHydratableChild(parentInstance); - hydrationParentFiber = fiber; - isHydrating = true; - return true; +// Capture errors so they don't interrupt unmounting. +function safelyCallComponentWillUnmount(current, instance) { + { + invokeGuardedCallback$3( + null, + callComponentWillUnmountWithTimer, + null, + current, + instance + ); + if (hasCaughtError$1()) { + var unmountError = clearCaughtError$1(); + captureCommitPhaseError(current, unmountError); + } } +} - function deleteHydratableInstance(returnFiber, instance) { - { - switch (returnFiber.tag) { - case HostRoot: - didNotHydrateContainerInstance( - returnFiber.stateNode.containerInfo, - instance - ); - break; - case HostComponent: - didNotHydrateInstance( - returnFiber.type, - returnFiber.memoizedProps, - returnFiber.stateNode, - instance - ); - break; +function safelyDetachRef(current) { + var ref = current.ref; + if (ref !== null) { + if (typeof ref === "function") { + { + invokeGuardedCallback$3(null, ref, null, null); + if (hasCaughtError$1()) { + var refError = clearCaughtError$1(); + captureCommitPhaseError(current, refError); + } } - } - - var childToDelete = createFiberFromHostInstanceForDeletion(); - childToDelete.stateNode = instance; - childToDelete.return = returnFiber; - childToDelete.effectTag = Deletion; - - // This might seem like it belongs on progressedFirstDeletion. However, - // these children are not part of the reconciliation list of children. - // Even if we abort and rereconcile the children, that will try to hydrate - // again and the nodes are still in the host tree so these will be - // recreated. - if (returnFiber.lastEffect !== null) { - returnFiber.lastEffect.nextEffect = childToDelete; - returnFiber.lastEffect = childToDelete; } else { - returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; + ref.current = null; } } +} - function insertNonHydratedInstance(returnFiber, fiber) { - fiber.effectTag |= Placement; - { - switch (returnFiber.tag) { - case HostRoot: { - var parentContainer = returnFiber.stateNode.containerInfo; - switch (fiber.tag) { - case HostComponent: - var type = fiber.type; - var props = fiber.pendingProps; - didNotFindHydratableContainerInstance( - parentContainer, - type, - props - ); - break; - case HostText: - var text = fiber.pendingProps; - didNotFindHydratableContainerTextInstance(parentContainer, text); - break; - } - break; - } - case HostComponent: { - var parentType = returnFiber.type; - var parentProps = returnFiber.memoizedProps; - var parentInstance = returnFiber.stateNode; - switch (fiber.tag) { - case HostComponent: - var _type = fiber.type; - var _props = fiber.pendingProps; - didNotFindHydratableInstance( - parentType, - parentProps, - parentInstance, - _type, - _props - ); - break; - case HostText: - var _text = fiber.pendingProps; - didNotFindHydratableTextInstance( - parentType, - parentProps, - parentInstance, - _text +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) ); - break; + } } - break; + instance.__reactInternalSnapshotBeforeUpdate = snapshot; + stopPhaseTimer(); } - default: - return; } + 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." + ); } } +} - function tryHydrate(fiber, nextInstance) { - switch (fiber.tag) { - case HostComponent: { - var type = fiber.type; - var props = fiber.pendingProps; - var instance = canHydrateInstance(nextInstance, type, props); - if (instance !== null) { - fiber.stateNode = instance; - return true; +function commitLifeCycles( + finishedRoot, + current, + finishedWork, + currentTime, + committedExpirationTime +) { + switch (finishedWork.tag) { + case ClassComponent: { + var instance = finishedWork.stateNode; + if (finishedWork.effectTag & Update) { + if (current === null) { + startPhaseTimer(finishedWork, "componentDidMount"); + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + instance.componentDidMount(); + stopPhaseTimer(); + } else { + var prevProps = current.memoizedProps; + var prevState = current.memoizedState; + startPhaseTimer(finishedWork, "componentDidUpdate"); + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + instance.componentDidUpdate( + prevProps, + prevState, + instance.__reactInternalSnapshotBeforeUpdate + ); + stopPhaseTimer(); } - return false; } - case HostText: { - var text = fiber.pendingProps; - var textInstance = canHydrateTextInstance(nextInstance, text); - if (textInstance !== null) { - fiber.stateNode = textInstance; - return true; - } - return false; + var updateQueue = finishedWork.updateQueue; + if (updateQueue !== null) { + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + commitUpdateQueue( + finishedWork, + updateQueue, + instance, + committedExpirationTime + ); } - default: - return false; - } - } - - function tryToClaimNextHydratableInstance(fiber) { - if (!isHydrating) { - return; - } - var nextInstance = nextHydratableInstance; - if (!nextInstance) { - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance(hydrationParentFiber, fiber); - isHydrating = false; - hydrationParentFiber = fiber; return; } - if (!tryHydrate(fiber, nextInstance)) { - // If we can't hydrate this instance let's try the next one. - // We use this as a heuristic. It's based on intuition and not data so it - // might be flawed or unnecessary. - nextInstance = getNextHydratableSibling(nextInstance); - if (!nextInstance || !tryHydrate(fiber, nextInstance)) { - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance(hydrationParentFiber, fiber); - isHydrating = false; - hydrationParentFiber = fiber; - return; - } - // We matched the next one, we'll now assume that the first one was - // superfluous and we'll delete it. Since we can't eagerly delete it - // we'll have to schedule a deletion. To do that, this node needs a dummy - // fiber associated with it. - deleteHydratableInstance(hydrationParentFiber, nextHydratableInstance); - } - hydrationParentFiber = fiber; - nextHydratableInstance = getFirstHydratableChild(nextInstance); - } - - function prepareToHydrateHostInstance( - fiber, - rootContainerInstance, - hostContext - ) { - var instance = fiber.stateNode; - var updatePayload = hydrateInstance( - instance, - fiber.type, - fiber.memoizedProps, - rootContainerInstance, - hostContext, - fiber - ); - // TODO: Type this specific to this type of component. - fiber.updateQueue = updatePayload; - // If the update payload indicates that there is a change or if there - // is a new ref we mark this as an update. - if (updatePayload !== null) { - return true; - } - return false; - } - - function prepareToHydrateHostTextInstance(fiber) { - var textInstance = fiber.stateNode; - var textContent = fiber.memoizedProps; - var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber); - { - if (shouldUpdate) { - // We assume that prepareToHydrateHostTextInstance is called in a context where the - // hydration parent is the parent host component of this host text. - var returnFiber = hydrationParentFiber; - if (returnFiber !== null) { - switch (returnFiber.tag) { - case HostRoot: { - var parentContainer = returnFiber.stateNode.containerInfo; - didNotMatchHydratedContainerTextInstance( - parentContainer, - textInstance, - textContent - ); + case HostRoot: { + var _updateQueue = finishedWork.updateQueue; + if (_updateQueue !== null) { + var _instance = null; + if (finishedWork.child !== null) { + switch (finishedWork.child.tag) { + case HostComponent: + _instance = getPublicInstance(finishedWork.child.stateNode); break; - } - case HostComponent: { - var parentType = returnFiber.type; - var parentProps = returnFiber.memoizedProps; - var parentInstance = returnFiber.stateNode; - didNotMatchHydratedTextInstance( - parentType, - parentProps, - parentInstance, - textInstance, - textContent - ); + case ClassComponent: + _instance = finishedWork.child.stateNode; break; - } } } + commitUpdateQueue( + finishedWork, + _updateQueue, + _instance, + committedExpirationTime + ); } + return; } - return shouldUpdate; - } - - function popToNextHostParent(fiber) { - var parent = fiber.return; - while ( - parent !== null && - parent.tag !== HostComponent && - parent.tag !== HostRoot - ) { - parent = parent.return; - } - hydrationParentFiber = parent; - } - - function popHydrationState(fiber) { - if (fiber !== hydrationParentFiber) { - // We're deeper than the current hydration context, inside an inserted - // tree. - return false; - } - if (!isHydrating) { - // If we're not currently hydrating but we're in a hydration context, then - // we were an insertion and now need to pop up reenter hydration of our - // siblings. - popToNextHostParent(fiber); - isHydrating = true; - return false; - } - - var type = fiber.type; - - // If we have any remaining hydratable nodes, we need to delete them now. - // We only do this deeper than head and body since they tend to have random - // other nodes in them. We also ignore components with pure text content in - // side of them. - // TODO: Better heuristic. - if ( - fiber.tag !== HostComponent || - (type !== "head" && - type !== "body" && - !shouldSetTextContent(type, fiber.memoizedProps)) - ) { - var nextInstance = nextHydratableInstance; - while (nextInstance) { - deleteHydratableInstance(fiber, nextInstance); - nextInstance = getNextHydratableSibling(nextInstance); - } - } - - popToNextHostParent(fiber); - nextHydratableInstance = hydrationParentFiber - ? getNextHydratableSibling(fiber.stateNode) - : null; - return true; - } - - function resetHydrationState() { - hydrationParentFiber = null; - nextHydratableInstance = null; - isHydrating = false; - } + case HostComponent: { + var _instance2 = finishedWork.stateNode; - return { - enterHydrationState: enterHydrationState, - resetHydrationState: resetHydrationState, - tryToClaimNextHydratableInstance: tryToClaimNextHydratableInstance, - prepareToHydrateHostInstance: prepareToHydrateHostInstance, - prepareToHydrateHostTextInstance: prepareToHydrateHostTextInstance, - popHydrationState: popHydrationState - }; -}; - -// This lets us hook into Fiber to debug what it's doing. -// See https://github.com/facebook/react/pull/8033. -// This is not part of the public API, not even for React DevTools. -// You may only inject a debugTool if you work on React Fiber itself. -var ReactFiberInstrumentation = { - debugTool: null -}; - -var ReactFiberInstrumentation_1 = ReactFiberInstrumentation; - -// TODO: Offscreen updates - -function markPendingPriorityLevel(root, expirationTime) { - if (enableSuspense) { - // Update the latest and earliest pending times - var earliestPendingTime = root.earliestPendingTime; - if (earliestPendingTime === NoWork) { - // No other pending updates. - root.earliestPendingTime = root.latestPendingTime = expirationTime; - } else { - if (earliestPendingTime > expirationTime) { - // This is the earliest pending update. - root.earliestPendingTime = expirationTime; - } else { - var latestPendingTime = root.latestPendingTime; - if (latestPendingTime < expirationTime) { - // This is the latest pending update - root.latestPendingTime = expirationTime; - } + // Renderers may schedule work to be done after host components are mounted + // (eg DOM renderer may schedule auto-focus for inputs and form controls). + // These effects should only be committed when components are first mounted, + // aka when there is no current/alternate. + if (current === null && finishedWork.effectTag & Update) { + var type = finishedWork.type; + var props = finishedWork.memoizedProps; + commitMount(_instance2, type, props, finishedWork); } - } - } -} -function markCommittedPriorityLevels(root, currentTime, earliestRemainingTime) { - if (enableSuspense) { - if (earliestRemainingTime === NoWork) { - // Fast path. There's no remaining work. Clear everything. - root.earliestPendingTime = NoWork; - root.latestPendingTime = NoWork; - root.earliestSuspendedTime = NoWork; - root.latestSuspendedTime = NoWork; - root.latestPingedTime = NoWork; return; } - - // Let's see if the previous latest known pending level was just flushed. - var latestPendingTime = root.latestPendingTime; - if (latestPendingTime !== NoWork) { - if (latestPendingTime < earliestRemainingTime) { - // We've flushed all the known pending levels. - root.earliestPendingTime = root.latestPendingTime = NoWork; - } else { - var earliestPendingTime = root.earliestPendingTime; - if (earliestPendingTime < earliestRemainingTime) { - // We've flushed the earliest known pending level. Set this to the - // latest pending time. - root.earliestPendingTime = root.latestPendingTime; - } - } + case HostText: { + // We have no life-cycles associated with text. + return; } - - // Now let's handle the earliest remaining level in the whole tree. We need to - // decide whether to treat it as a pending level or as suspended. Check - // it falls within the range of known suspended levels. - - var earliestSuspendedTime = root.earliestSuspendedTime; - if (earliestSuspendedTime === NoWork) { - // There's no suspended work. Treat the earliest remaining level as a - // pending level. - markPendingPriorityLevel(root, earliestRemainingTime); + case HostPortal: { + // We have no life-cycles associated with portals. return; } - - var latestSuspendedTime = root.latestSuspendedTime; - if (earliestRemainingTime > latestSuspendedTime) { - // The earliest remaining level is later than all the suspended work. That - // means we've flushed all the suspended work. - root.earliestSuspendedTime = NoWork; - root.latestSuspendedTime = NoWork; - root.latestPingedTime = NoWork; - - // There's no suspended work. Treat the earliest remaining level as a - // pending level. - markPendingPriorityLevel(root, earliestRemainingTime); + case Profiler: { + // We have no life-cycles associated with Profiler. return; } - - if (earliestRemainingTime < earliestSuspendedTime) { - // The earliest remaining time is earlier than all the suspended work. - // Treat it as a pending update. - markPendingPriorityLevel(root, earliestRemainingTime); + case TimeoutComponent: { + // We have no life-cycles associated with Timeouts. return; } - - // The earliest remaining time falls within the range of known suspended - // levels. We should treat this as suspended work. + 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." + ); + } } } -function markSuspendedPriorityLevel(root, suspendedTime) { - if (enableSuspense) { - // First, check the known pending levels and update them if needed. - var earliestPendingTime = root.earliestPendingTime; - var latestPendingTime = root.latestPendingTime; - if (earliestPendingTime === suspendedTime) { - if (latestPendingTime === suspendedTime) { - // Both known pending levels were suspended. Clear them. - root.earliestPendingTime = root.latestPendingTime = NoWork; - } else { - // The earliest pending level was suspended. Clear by setting it to the - // latest pending level. - root.earliestPendingTime = latestPendingTime; - } - } else if (latestPendingTime === suspendedTime) { - // The latest pending level was suspended. Clear by setting it to the - // latest pending level. - root.latestPendingTime = earliestPendingTime; - } - - // Next, if we're working on the lowest known suspended level, clear the ping. - // TODO: What if a promise suspends and pings before the root completes? - var latestSuspendedTime = root.latestSuspendedTime; - if (latestSuspendedTime === suspendedTime) { - root.latestPingedTime = NoWork; +function commitAttachRef(finishedWork) { + var ref = finishedWork.ref; + if (ref !== null) { + var instance = finishedWork.stateNode; + var instanceToUse = void 0; + switch (finishedWork.tag) { + case HostComponent: + instanceToUse = getPublicInstance(instance); + break; + default: + instanceToUse = instance; } - - // Finally, update the known suspended levels. - var earliestSuspendedTime = root.earliestSuspendedTime; - if (earliestSuspendedTime === NoWork) { - // No other suspended levels. - root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime; + if (typeof ref === "function") { + ref(instanceToUse); } else { - if (earliestSuspendedTime > suspendedTime) { - // This is the earliest suspended level. - root.earliestSuspendedTime = suspendedTime; - } else if (latestSuspendedTime < suspendedTime) { - // This is the latest suspended level - root.latestSuspendedTime = suspendedTime; + { + 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; } } } -function markPingedPriorityLevel(root, pingedTime) { - if (enableSuspense) { - var latestSuspendedTime = root.latestSuspendedTime; - if (latestSuspendedTime !== NoWork && latestSuspendedTime <= pingedTime) { - var latestPingedTime = root.latestPingedTime; - if (latestPingedTime === NoWork || latestPingedTime < pingedTime) { - root.latestPingedTime = pingedTime; - } +function commitDetachRef(current) { + var currentRef = current.ref; + if (currentRef !== null) { + if (typeof currentRef === "function") { + currentRef(null); + } else { + currentRef.current = null; } } } -function findNextPendingPriorityLevel(root) { - if (enableSuspense) { - var earliestSuspendedTime = root.earliestSuspendedTime; - var earliestPendingTime = root.earliestPendingTime; - if (earliestSuspendedTime === NoWork) { - // Fast path. There's no suspended work. - return earliestPendingTime; - } +// User-originating errors (lifecycles and refs) should not interrupt +// deletion, so don't let them throw. Host-originating errors should +// interrupt deletion, so it's okay +function commitUnmount(current) { + if (typeof onCommitUnmount === "function") { + onCommitUnmount(current); + } - // First, check if there's known pending work. - if (earliestPendingTime !== NoWork) { - return earliestPendingTime; + switch (current.tag) { + case ClassComponent: { + safelyDetachRef(current); + var instance = current.stateNode; + if (typeof instance.componentWillUnmount === "function") { + safelyCallComponentWillUnmount(current, instance); + } + return; + } + case HostComponent: { + safelyDetachRef(current); + return; + } + case HostPortal: { + // TODO: this is recursive. + // We are also not using this parent because + // the portal will get pushed immediately. + if (supportsMutation) { + unmountHostComponents(current); + } else if (supportsPersistence) { + emptyPortalContainer(current); + } + return; } - - // Finally, if a suspended level was pinged, work on that. Otherwise there's - // nothing to work on. - return root.latestPingedTime; - } else { - return root.current.expirationTime; } } -var warnedAboutMissingGetChildContext = void 0; - -{ - warnedAboutMissingGetChildContext = {}; +function commitNestedUnmounts(root) { + // While we're inside a removed host node we don't want to call + // removeChild on the inner nodes because they're removed by the top + // call anyway. We also want to call componentWillUnmount on all + // composites before this host node is removed from the tree. Therefore + var node = root; + while (true) { + commitUnmount(node); + // Visit children because they may contain more composite or host nodes. + // Skip portals because commitUnmount() currently visits them recursively. + if ( + node.child !== null && + // If we use mutation we drill down into portals using commitUnmount above. + // If we don't use mutation we drill down into portals here instead. + (!supportsMutation || node.tag !== HostPortal) + ) { + node.child.return = node; + node = node.child; + continue; + } + if (node === root) { + return; + } + while (node.sibling === null) { + if (node.return === null || node.return === root) { + return; + } + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } } -var ReactFiberLegacyContext = function(stack) { - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; +function detachFiber(current) { + // Cut off the return pointers to disconnect it from the tree. Ideally, we + // should clear the child pointer of the parent alternate to let this + // get GC:ed but we don't know which for sure which parent is the current + // one so we'll settle for GC:ing the subtree of this child. This child + // itself will be GC:ed when the parent updates the next time. + current.return = null; + current.child = null; + if (current.alternate) { + current.alternate.child = null; + current.alternate.return = null; + } +} - // A cursor to the current merged context object on the stack. +function emptyPortalContainer(current) { + if (!supportsPersistence) { + return; + } - 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; + var portal = current.stateNode; + var containerInfo = portal.containerInfo; - 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; - } + var emptyChildSet = createContainerChildSet(containerInfo); +} - function cacheContext(workInProgress, unmaskedContext, maskedContext) { - var instance = workInProgress.stateNode; - instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; - instance.__reactInternalMemoizedMaskedChildContext = maskedContext; +function commitContainer(finishedWork) { + if (!supportsPersistence) { + return; } - function getMaskedContext(workInProgress, unmaskedContext) { - var type = workInProgress.type; - var contextTypes = type.contextTypes; - if (!contextTypes) { - return emptyObject; + switch (finishedWork.tag) { + case ClassComponent: { + return; } - - // 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; + case HostComponent: { + return; } - - var context = {}; - for (var key in contextTypes) { - context[key] = unmaskedContext[key]; + case HostText: { + return; } + case HostRoot: + case HostPortal: { + var portalOrRoot = finishedWork.stateNode; + var containerInfo = portalOrRoot.containerInfo, + _pendingChildren = portalOrRoot.pendingChildren; - { - var name = getComponentName(workInProgress) || "Unknown"; - checkPropTypes( - contextTypes, - context, - "context", - name, - ReactDebugCurrentFiber.getCurrentFiberStackAddendum + 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." ); } + } +} - // 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); +function getHostParentFiber(fiber) { + var parent = fiber.return; + while (parent !== null) { + if (isHostParent(parent)) { + return parent; } - - return context; + parent = parent.return; } + invariant( + false, + "Expected to find a host parent. This error is likely caused by a bug " + + "in React. Please file an issue." + ); +} - function hasContextChanged() { - return didPerformWorkStackCursor.current; - } +function isHostParent(fiber) { + return ( + fiber.tag === HostComponent || + fiber.tag === HostRoot || + fiber.tag === HostPortal + ); +} - function isContextConsumer(fiber) { - return fiber.tag === ClassComponent && fiber.type.contextTypes != null; +function getHostSibling(fiber) { + // We're going to search forward into the tree until we find a sibling host + // node. Unfortunately, if multiple insertions are done in a row we have to + // search past them. This leads to exponential search for the next sibling. + var node = fiber; + siblings: while (true) { + // If we didn't find anything, let's try the next sibling. + while (node.sibling === null) { + if (node.return === null || isHostParent(node.return)) { + // If we pop out of the root or hit the parent the fiber we are the + // last sibling. + return null; + } + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + while (node.tag !== HostComponent && node.tag !== HostText) { + // If it is not host node and, we might have a host node inside it. + // Try to search down until we find one. + if (node.effectTag & Placement) { + // If we don't have a child, try the siblings instead. + continue siblings; + } + // If we don't have a child, try the siblings instead. + // We also skip portals because they are not part of this host tree. + if (node.child === null || node.tag === HostPortal) { + continue siblings; + } else { + node.child.return = node; + node = node.child; + } + } + // Check if this host node is stable or about to be placed. + if (!(node.effectTag & Placement)) { + // Found it! + return node.stateNode; + } } +} - function isContextProvider(fiber) { - return fiber.tag === ClassComponent && fiber.type.childContextTypes != null; +function commitPlacement(finishedWork) { + if (!supportsMutation) { + return; } - function popContextProvider(fiber) { - if (!isContextProvider(fiber)) { - return; - } - - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + // Recursively insert all host nodes into the parent. + var parentFiber = getHostParentFiber(finishedWork); + var parent = void 0; + var isContainer = void 0; + switch (parentFiber.tag) { + case HostComponent: + parent = parentFiber.stateNode; + isContainer = false; + break; + case HostRoot: + parent = parentFiber.stateNode.containerInfo; + isContainer = true; + break; + case HostPortal: + parent = parentFiber.stateNode.containerInfo; + isContainer = true; + break; + default: + invariant( + false, + "Invalid host parent fiber. This error is likely caused by a bug " + + "in React. Please file an issue." + ); } - - function popTopLevelContextObject(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + if (parentFiber.effectTag & ContentReset) { + // Reset the text content of the parent before doing any insertions + resetTextContent(parent); + // Clear ContentReset from the effect tag + parentFiber.effectTag &= ~ContentReset; } - 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); + var before = getHostSibling(finishedWork); + // We only have the top Fiber that was inserted but we need recurse down its + // children to find all the terminal nodes. + var node = finishedWork; + while (true) { + if (node.tag === HostComponent || node.tag === HostText) { + if (before) { + if (isContainer) { + insertInContainerBefore(parent, node.stateNode, before); + } else { + insertBefore(parent, node.stateNode, before); + } + } else { + if (isContainer) { + appendChildToContainer(parent, node.stateNode); + } else { + appendChild$1(parent, node.stateNode); + } + } + } else if (node.tag === HostPortal) { + // If the insertion itself is a portal, then we don't want to traverse + // down its children. Instead, we'll get insertions from each child in + // the portal directly. + } else if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; + } + if (node === finishedWork) { + return; + } + while (node.sibling === null) { + if (node.return === null || node.return === finishedWork) { + return; + } + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; } +} - function processChildContext(fiber, parentContext) { - var instance = fiber.stateNode; - var childContextTypes = fiber.type.childContextTypes; +function unmountHostComponents(current) { + // We only have the top Fiber that was inserted but we need recurse down its + var node = current; - // 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"; + // Each iteration, currentParent is populated with node's host parent if not + // currentParentIsValid. + var currentParentIsValid = false; + var currentParent = void 0; + var currentParentIsContainer = void 0; - 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 - ); + while (true) { + if (!currentParentIsValid) { + var parent = node.return; + findParent: while (true) { + invariant( + parent !== null, + "Expected to find a host parent. This error is likely caused by " + + "a bug in React. Please file an issue." + ); + switch (parent.tag) { + case HostComponent: + currentParent = parent.stateNode; + currentParentIsContainer = false; + break findParent; + case HostRoot: + currentParent = parent.stateNode.containerInfo; + currentParentIsContainer = true; + break findParent; + case HostPortal: + currentParent = parent.stateNode.containerInfo; + currentParentIsContainer = true; + break findParent; } + parent = parent.return; } - return parentContext; + currentParentIsValid = true; } - var childContext = void 0; - { - ReactDebugCurrentFiber.setCurrentPhase("getChildContext"); - } - startPhaseTimer(fiber, "getChildContext"); - childContext = instance.getChildContext(); - stopPhaseTimer(); - { - ReactDebugCurrentFiber.setCurrentPhase(null); + if (node.tag === HostComponent || node.tag === HostText) { + commitNestedUnmounts(node); + // After all the children have unmounted, it is now safe to remove the + // node from the tree. + if (currentParentIsContainer) { + removeChildFromContainer(currentParent, node.stateNode); + } else { + removeChild(currentParent, node.stateNode); + } + // Don't visit children because we already visited them. + } else if (node.tag === HostPortal) { + // When we go into a portal, it becomes the parent to remove from. + // We will reassign it back when we pop the portal on the way up. + currentParent = node.stateNode.containerInfo; + // Visit children because portals might contain host components. + if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; + } + } else { + commitUnmount(node); + // Visit children because we may find more host components below. + if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; + } } - for (var contextKey in childContext) { - invariant( - contextKey in childContextTypes, - '%s.getChildContext(): key "%s" is not defined in childContextTypes.', - getComponentName(fiber) || "Unknown", - contextKey - ); + if (node === current) { + return; } - { - 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 - ); + while (node.sibling === null) { + if (node.return === null || node.return === current) { + return; + } + node = node.return; + if (node.tag === HostPortal) { + // When we go out of the portal, we need to restore the parent. + // Since we don't keep a stack of them, we will search for it. + currentParentIsValid = false; + } } - - return Object.assign({}, parentContext, childContext); + node.sibling.return = node.return; + node = node.sibling; } +} - 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 commitDeletion(current) { + if (supportsMutation) { + // Recursively delete all host nodes from the parent. + // Detach refs and call componentWillUnmount() on the whole subtree. + unmountHostComponents(current); + } else { + // Detach refs and call componentWillUnmount() on the whole subtree. + commitNestedUnmounts(current); } + detachFiber(current); +} - 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 commitWork(current, finishedWork) { + if (!supportsMutation) { + commitContainer(finishedWork); + return; } - 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; + switch (finishedWork.tag) { + case ClassComponent: { + return; + } + case HostComponent: { + var instance = finishedWork.stateNode; + if (instance != null) { + // Commit the work prepared earlier. + var newProps = finishedWork.memoizedProps; + // For hydration we reuse the update path but we treat the oldProps + // as the newProps. The updatePayload will contain the real change in + // this case. + var oldProps = current !== null ? current.memoizedProps : newProps; + var type = finishedWork.type; + // TODO: Type the updateQueue to be specific to host components. + var updatePayload = finishedWork.updateQueue; + finishedWork.updateQueue = null; + if (updatePayload !== null) { + commitUpdate( + instance, + updatePayload, + type, + oldProps, + newProps, + finishedWork + ); + } } - var parent = node.return; + return; + } + case HostText: { invariant( - parent, - "Found unexpected detached subtree parent. " + - "This error is likely caused by a bug in React. Please file an issue." + finishedWork.stateNode !== null, + "This should have a text node initialized. This error is likely " + + "caused by a bug in React. Please file an issue." ); - node = parent; + var textInstance = finishedWork.stateNode; + var newText = finishedWork.memoizedProps; + // For hydration we reuse the update path but we treat the oldProps + // as the newProps. The updatePayload will contain the real change in + // this case. + var oldText = current !== null ? current.memoizedProps : newText; + commitTextUpdate(textInstance, oldText, newText); + return; } - 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, isPrimaryRenderer) { - 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; - - if (isPrimaryRenderer) { - 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 === undefined || - 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; - } - } else { - push(changedBitsCursor, context._changedBits2, providerFiber); - push(valueCursor, context._currentValue2, providerFiber); - push(providerCursor, providerFiber, providerFiber); - - context._currentValue2 = providerFiber.pendingProps.value; - context._changedBits2 = providerFiber.stateNode; - { - !( - context._currentRenderer2 === undefined || - context._currentRenderer2 === null || - context._currentRenderer2 === rendererSigil - ) - ? warning( - false, - "Detected multiple renderers concurrently rendering the " + - "same context provider. This is currently unsupported." - ) - : void 0; - context._currentRenderer2 = rendererSigil; + case HostRoot: { + return; + } + case Profiler: { + if (enableProfilerTimer) { + var onRender = finishedWork.memoizedProps.onRender; + onRender( + finishedWork.memoizedProps.id, + current === null ? "mount" : "update", + finishedWork.actualDuration, + finishedWork.treeBaseTime, + finishedWork.actualStartTime, + getCommitTime() + ); } + return; } - } - - 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; - if (isPrimaryRenderer) { - context._currentValue = currentValue; - context._changedBits = changedBits; - } else { - context._currentValue2 = currentValue; - context._changedBits2 = changedBits; + case TimeoutComponent: { + 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." + ); } } +} - function getContextCurrentValue(context) { - return isPrimaryRenderer ? context._currentValue : context._currentValue2; - } - - function getContextChangedBits(context) { - return isPrimaryRenderer ? context._changedBits : context._changedBits2; +function commitResetTextContent(current) { + if (!supportsMutation) { + return; } + resetTextContent(current.stateNode); +} - return { - pushProvider: pushProvider, - popProvider: popProvider, - getContextCurrentValue: getContextCurrentValue, - getContextChangedBits: getContextChangedBits +function createRootErrorUpdate(fiber, errorInfo, expirationTime) { + var update = createUpdate(expirationTime); + // Unmount the root by rendering null. + update.tag = CaptureUpdate; + // Caution: React DevTools currently depends on this property + // being called "element". + update.payload = { element: null }; + var error = errorInfo.value; + update.callback = function() { + onUncaughtError(error); + logError(fiber, errorInfo); }; -}; - -var ReactFiberStack = function() { - var valueStack = []; - - var fiberStack = void 0; + return update; +} - { - fiberStack = []; +function createClassErrorUpdate(fiber, errorInfo, expirationTime) { + var update = createUpdate(expirationTime); + update.tag = CaptureUpdate; + var getDerivedStateFromCatch = fiber.type.getDerivedStateFromCatch; + if ( + enableGetDerivedStateFromCatch && + typeof getDerivedStateFromCatch === "function" + ) { + var error = errorInfo.value; + update.payload = function() { + return getDerivedStateFromCatch(error); + }; } - var index = -1; - - function createCursor(defaultValue) { - return { - current: defaultValue + var inst = fiber.stateNode; + if (inst !== null && typeof inst.componentDidCatch === "function") { + update.callback = function callback() { + if ( + !enableGetDerivedStateFromCatch || + getDerivedStateFromCatch !== "function" + ) { + // To preserve the preexisting retry behavior of error boundaries, + // we keep track of which ones already failed during this batch. + // This gets reset before we yield back to the browser. + // TODO: Warn in strict mode if getDerivedStateFromCatch is + // not defined. + markLegacyErrorBoundaryAsFailed(this); + } + var error = errorInfo.value; + var stack = errorInfo.stack; + logError(fiber, errorInfo); + this.componentDidCatch(error, { + componentStack: stack !== null ? stack : "" + }); }; } + return update; +} + +function schedulePing(finishedWork) { + // Once the promise resolves, we should try rendering the non- + // placeholder state again. + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, finishedWork); + var recoveryUpdate = createUpdate(expirationTime); + enqueueUpdate(finishedWork, recoveryUpdate, expirationTime); + scheduleWork(finishedWork, expirationTime); +} + +function throwException( + root, + returnFiber, + sourceFiber, + value, + renderExpirationTime, + currentTimeMs +) { + // The source fiber did not complete. + sourceFiber.effectTag |= Incomplete; + // Its effect list is no longer valid. + sourceFiber.firstEffect = sourceFiber.lastEffect = null; + + if ( + enableSuspense && + value !== null && + typeof value === "object" && + typeof value.then === "function" + ) { + // This is a thenable. + var thenable = value; + + // TODO: Should use the earliest known expiration time + var expirationTimeMs = expirationTimeToMs(renderExpirationTime); + var startTimeMs = expirationTimeMs - 5000; + var elapsedMs = currentTimeMs - startTimeMs; + if (elapsedMs < 0) { + elapsedMs = 0; + } + var remainingTimeMs = expirationTimeMs - currentTimeMs; + + // Find the earliest timeout of all the timeouts in the ancestor path. + // TODO: Alternatively, we could store the earliest timeout on the context + // stack, rather than searching on every suspend. + var _workInProgress = returnFiber; + var earliestTimeoutMs = -1; + searchForEarliestTimeout: do { + if (_workInProgress.tag === TimeoutComponent) { + var current = _workInProgress.alternate; + if (current !== null && current.memoizedState === true) { + // A parent Timeout already committed in a placeholder state. We + // need to handle this promise immediately. In other words, we + // should never suspend inside a tree that already expired. + earliestTimeoutMs = 0; + break searchForEarliestTimeout; + } + var timeoutPropMs = _workInProgress.pendingProps.ms; + if (typeof timeoutPropMs === "number") { + if (timeoutPropMs <= 0) { + earliestTimeoutMs = 0; + break searchForEarliestTimeout; + } else if ( + earliestTimeoutMs === -1 || + timeoutPropMs < earliestTimeoutMs + ) { + earliestTimeoutMs = timeoutPropMs; + } + } else if (earliestTimeoutMs === -1) { + earliestTimeoutMs = remainingTimeMs; + } + } + _workInProgress = _workInProgress.return; + } while (_workInProgress !== null); - function isEmpty() { - return index === -1; - } + // Compute the remaining time until the timeout. + var msUntilTimeout = earliestTimeoutMs - elapsedMs; - function pop(cursor, fiber) { - if (index < 0) { - { - warning(false, "Unexpected pop."); - } + if (renderExpirationTime === Never || msUntilTimeout > 0) { + // There's still time remaining. + markTimeout(root, thenable, msUntilTimeout, renderExpirationTime); + var onResolveOrReject = function() { + retrySuspendedRoot(root, renderExpirationTime); + }; + thenable.then(onResolveOrReject, onResolveOrReject); + return; + } else { + // No time remaining. Need to fallback to placeholder. + // Find the nearest timeout that can be retried. + _workInProgress = returnFiber; + do { + switch (_workInProgress.tag) { + case HostRoot: { + // The root expired, but no fallback was provided. Throw a + // helpful error. + var message = + renderExpirationTime === Sync + ? "A synchronous update was suspended, but no fallback UI " + + "was provided." + : "An update was suspended for longer than the timeout, " + + "but no fallback UI was provided."; + value = new Error(message); + break; + } + case TimeoutComponent: { + if ((_workInProgress.effectTag & DidCapture) === NoEffect) { + _workInProgress.effectTag |= ShouldCapture; + var _onResolveOrReject = schedulePing.bind(null, _workInProgress); + thenable.then(_onResolveOrReject, _onResolveOrReject); + return; + } + // Already captured during this render. Continue to the next + // Timeout ancestor. + break; + } + } + _workInProgress = _workInProgress.return; + } while (_workInProgress !== null); + } + } else { + // This is an error. + markError(root); + if ( + // Retry (at the same priority) one more time before handling the error. + // The retry will flush synchronously. (Unless we're already rendering + // synchronously, in which case move to the next check.) + (!root.didError && renderExpirationTime !== Sync) || + // There's lower priority work. If so, it may have the effect of fixing + // the exception that was just thrown. + hasLowerPriorityWork(root, renderExpirationTime) + ) { return; } + } - { - if (fiber !== fiberStack[index]) { - warning(false, "Unexpected Fiber popped."); + // We didn't find a boundary that could handle this type of exception. Start + // over and traverse parent path again, this time treating the exception + // as an error. + value = createCapturedValue(value, sourceFiber); + var workInProgress = returnFiber; + do { + switch (workInProgress.tag) { + case HostRoot: { + var _errorInfo = value; + workInProgress.effectTag |= ShouldCapture; + var update = createRootErrorUpdate( + workInProgress, + _errorInfo, + renderExpirationTime + ); + enqueueCapturedUpdate(workInProgress, update, renderExpirationTime); + return; } + case ClassComponent: + // Capture and retry + var errorInfo = value; + var ctor = workInProgress.type; + var instance = workInProgress.stateNode; + if ( + (workInProgress.effectTag & DidCapture) === NoEffect && + ((typeof ctor.getDerivedStateFromCatch === "function" && + enableGetDerivedStateFromCatch) || + (instance !== null && + typeof instance.componentDidCatch === "function" && + !isAlreadyFailedLegacyErrorBoundary(instance))) + ) { + workInProgress.effectTag |= ShouldCapture; + // Schedule the error boundary to re-render using updated state + var _update = createClassErrorUpdate( + workInProgress, + errorInfo, + renderExpirationTime + ); + enqueueCapturedUpdate(workInProgress, _update, renderExpirationTime); + return; + } + break; + default: + break; } + workInProgress = workInProgress.return; + } while (workInProgress !== null); +} - cursor.current = valueStack[index]; - - valueStack[index] = null; - - { - fiberStack[index] = null; +function unwindWork(workInProgress, renderExpirationTime) { + if (enableProfilerTimer) { + if (workInProgress.mode & ProfileMode) { + recordElapsedActualRenderTime(workInProgress); } - - index--; } - function push(cursor, value, fiber) { - index++; - - valueStack[index] = cursor.current; - - { - fiberStack[index] = fiber; + switch (workInProgress.tag) { + case ClassComponent: { + popContextProvider(workInProgress); + var effectTag = workInProgress.effectTag; + if (effectTag & ShouldCapture) { + workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture; + return workInProgress; + } + return null; } - - cursor.current = value; - } - - function checkThatStackIsEmpty() { - { - if (index !== -1) { - warning( - false, - "Expected an empty stack. Something was not reset properly." - ); + case HostRoot: { + popHostContainer(workInProgress); + popTopLevelContextObject(workInProgress); + var _effectTag = workInProgress.effectTag; + if (_effectTag & ShouldCapture) { + workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture; + return workInProgress; + } + return null; + } + case HostComponent: { + popHostContext(workInProgress); + return null; + } + case TimeoutComponent: { + var _effectTag2 = workInProgress.effectTag; + if (_effectTag2 & ShouldCapture) { + workInProgress.effectTag = (_effectTag2 & ~ShouldCapture) | DidCapture; + return workInProgress; } + return null; } + case HostPortal: + popHostContainer(workInProgress); + return null; + case ContextProvider: + popProvider(workInProgress); + return null; + default: + return null; } +} - function resetStackAfterFatalErrorInDev() { - { - index = -1; - valueStack.length = 0; - fiberStack.length = 0; +function unwindInterruptedWork(interruptedWork) { + if (enableProfilerTimer) { + if (interruptedWork.mode & ProfileMode) { + // Resume in case we're picking up on work that was paused. + resumeActualRenderTimerIfPaused(); + recordElapsedActualRenderTime(interruptedWork); } } - return { - createCursor: createCursor, - isEmpty: isEmpty, - pop: pop, - push: push, - checkThatStackIsEmpty: checkThatStackIsEmpty, - resetStackAfterFatalErrorInDev: resetStackAfterFatalErrorInDev - }; -}; + switch (interruptedWork.tag) { + case ClassComponent: { + popContextProvider(interruptedWork); + break; + } + case HostRoot: { + popHostContainer(interruptedWork); + popTopLevelContextObject(interruptedWork); + break; + } + case HostComponent: { + popHostContext(interruptedWork); + break; + } + case HostPortal: + popHostContainer(interruptedWork); + break; + case ContextProvider: + popProvider(interruptedWork); + break; + default: + break; + } +} var invokeGuardedCallback$2 = ReactErrorUtils.invokeGuardedCallback; var hasCaughtError = ReactErrorUtils.hasCaughtError; @@ -12330,1821 +12140,1713 @@ var warnAboutInvalidUpdates = void 0; }; } -var ReactFiberScheduler = function(config) { - var now = config.now, - scheduleDeferredCallback = config.scheduleDeferredCallback, - cancelDeferredCallback = config.cancelDeferredCallback, - prepareForCommit = config.prepareForCommit, - resetAfterCommit = config.resetAfterCommit; - - var stack = ReactFiberStack(); - var hostContext = ReactFiberHostContext(config, stack); - var legacyContext = ReactFiberLegacyContext(stack); - var newContext = ReactFiberNewContext(stack, config.isPrimaryRenderer); - var profilerTimer = createProfilerTimer(now); - var popHostContext = hostContext.popHostContext, - popHostContainer = hostContext.popHostContainer; - var popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popLegacyContextProvider = legacyContext.popContextProvider; - var popProvider = newContext.popProvider; - - var hydrationContext = ReactFiberHydrationContext(config); - - var _ReactFiberBeginWork = ReactFiberBeginWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - scheduleWork, - computeExpirationForFiber, - profilerTimer, - recalculateCurrentTime - ), - beginWork = _ReactFiberBeginWork.beginWork; - - var _ReactFiberCompleteWo = ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - profilerTimer - ), - completeWork = _ReactFiberCompleteWo.completeWork; - - var _ReactFiberUnwindWork = ReactFiberUnwindWork( - config, - hostContext, - legacyContext, - newContext, - scheduleWork, - computeExpirationForFiber, - recalculateCurrentTime, - markLegacyErrorBoundaryAsFailed, - isAlreadyFailedLegacyErrorBoundary, - onUncaughtError, - profilerTimer, - suspendRoot, - retrySuspendedRoot - ), - throwException = _ReactFiberUnwindWork.throwException, - unwindWork = _ReactFiberUnwindWork.unwindWork, - unwindInterruptedWork = _ReactFiberUnwindWork.unwindInterruptedWork, - createRootErrorUpdate = _ReactFiberUnwindWork.createRootErrorUpdate, - createClassErrorUpdate = _ReactFiberUnwindWork.createClassErrorUpdate; - - var _ReactFiberCommitWork = ReactFiberCommitWork( - config, - onCommitPhaseError, - scheduleWork, - computeExpirationForFiber, - markLegacyErrorBoundaryAsFailed, - recalculateCurrentTime - ), - commitBeforeMutationLifeCycles = - _ReactFiberCommitWork.commitBeforeMutationLifeCycles, - commitResetTextContent = _ReactFiberCommitWork.commitResetTextContent, - commitPlacement = _ReactFiberCommitWork.commitPlacement, - commitDeletion = _ReactFiberCommitWork.commitDeletion, - commitWork = _ReactFiberCommitWork.commitWork, - commitLifeCycles = _ReactFiberCommitWork.commitLifeCycles, - commitAttachRef = _ReactFiberCommitWork.commitAttachRef, - commitDetachRef = _ReactFiberCommitWork.commitDetachRef; - - var checkActualRenderTimeStackEmpty = - profilerTimer.checkActualRenderTimeStackEmpty, - pauseActualRenderTimerIfRunning = - profilerTimer.pauseActualRenderTimerIfRunning, - recordElapsedBaseRenderTimeIfRunning = - profilerTimer.recordElapsedBaseRenderTimeIfRunning, - resetActualRenderTimer = profilerTimer.resetActualRenderTimer, - resumeActualRenderTimerIfPaused = - profilerTimer.resumeActualRenderTimerIfPaused, - startBaseRenderTimer = profilerTimer.startBaseRenderTimer, - stopBaseRenderTimerIfRunning = profilerTimer.stopBaseRenderTimerIfRunning; - - // Represents the current time in ms. - - var originalStartTimeMs = now(); - var mostRecentCurrentTime = msToExpirationTime(0); - var mostRecentCurrentTimeMs = originalStartTimeMs; - - // Used to ensure computeUniqueAsyncExpiration is monotonically increases. - var lastUniqueAsyncExpiration = 0; - - // Represents the expiration time that incoming updates should use. (If this - // is NoWork, use the default strategy: async updates in async mode, sync - // updates in sync mode.) - var expirationContext = NoWork; - - var isWorking = false; - - // The next work in progress fiber that we're currently working on. - var nextUnitOfWork = null; - var nextRoot = null; - // The time at which we're currently rendering work. - var nextRenderExpirationTime = NoWork; - var nextLatestTimeoutMs = -1; - var nextRenderIsExpired = false; - - // The next fiber with an effect that we're currently committing. - var nextEffect = null; - - var isCommitting = false; - - var isRootReadyForCommit = false; - - var legacyErrorBoundariesThatAlreadyFailed = null; - - // Used for performance tracking. - var interruptedBy = null; - - 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, thrownValue, isAsync) { - if ( - thrownValue !== null && - typeof thrownValue === "object" && - typeof thrownValue.then === "function" - ) { - // Don't replay promises. Treat everything else like an error. - // TODO: Need to figure out a different strategy if/when we add - // support for catching other types. - return; - } +// Represents the current time in ms. +var originalStartTimeMs = now(); +var mostRecentCurrentTime = msToExpirationTime(0); +var mostRecentCurrentTimeMs = originalStartTimeMs; - // Restore the original state of the work-in-progress - if (stashedWorkInProgressProperties === null) { - // This should never happen. Don't throw because this code is DEV-only. - warning( - false, - "Could not replay rendering after an error. This is likely a bug in React. " + - "Please file an issue." - ); - return; - } - assignFiberPropertiesInDEV( - failedUnitOfWork, - stashedWorkInProgressProperties - ); +// Used to ensure computeUniqueAsyncExpiration is monotonically increases. +var lastUniqueAsyncExpiration = 0; - switch (failedUnitOfWork.tag) { - case HostRoot: - popHostContainer(failedUnitOfWork); - popTopLevelLegacyContextObject(failedUnitOfWork); - break; - case HostComponent: - popHostContext(failedUnitOfWork); - break; - case ClassComponent: - popLegacyContextProvider(failedUnitOfWork); - break; - case HostPortal: - popHostContainer(failedUnitOfWork); - break; - case ContextProvider: - popProvider(failedUnitOfWork); - break; - } - // Replay the begin phase. - isReplayingFailedUnitOfWork = true; - originalReplayError = thrownValue; - invokeGuardedCallback$2(null, workLoop, null, isAsync); - isReplayingFailedUnitOfWork = false; - originalReplayError = null; - if (hasCaughtError()) { - clearCaughtError(); +// Represents the expiration time that incoming updates should use. (If this +// is NoWork, use the default strategy: async updates in async mode, sync +// updates in sync mode.) +var expirationContext = NoWork; - if (enableProfilerTimer) { - // Stop "base" render timer again (after the re-thrown error). - stopBaseRenderTimerIfRunning(); - } - } else { - // If the begin phase did not fail the second time, set this pointer - // back to the original value. - nextUnitOfWork = failedUnitOfWork; - } - }; - rethrowOriginalError = function() { - throw originalReplayError; - }; - } +var isWorking = false; - function resetStack() { - if (nextUnitOfWork !== null) { - var interruptedWork = nextUnitOfWork.return; - while (interruptedWork !== null) { - unwindInterruptedWork(interruptedWork); - interruptedWork = interruptedWork.return; - } - } +// The next work in progress fiber that we're currently working on. +var nextUnitOfWork = null; +var nextRoot = null; +// The time at which we're currently rendering work. +var nextRenderExpirationTime = NoWork; +var nextLatestTimeoutMs = -1; +var nextRenderDidError = false; - { - ReactStrictModeWarnings.discardPendingWarnings(); - stack.checkThatStackIsEmpty(); - } +// The next fiber with an effect that we're currently committing. +var nextEffect = null; - nextRoot = null; - nextRenderExpirationTime = NoWork; - nextLatestTimeoutMs = -1; - nextRenderIsExpired = false; - nextUnitOfWork = null; +var isCommitting$1 = false; - isRootReadyForCommit = false; - } +var legacyErrorBoundariesThatAlreadyFailed = null; - function commitAllHostEffects() { - while (nextEffect !== null) { - { - ReactDebugCurrentFiber.setCurrentFiber(nextEffect); - } - recordEffect(); +// Used for performance tracking. +var interruptedBy = null; + +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, thrownValue, isYieldy) { + if ( + thrownValue !== null && + typeof thrownValue === "object" && + typeof thrownValue.then === "function" + ) { + // Don't replay promises. Treat everything else like an error. + // TODO: Need to figure out a different strategy if/when we add + // support for catching other types. + return; + } - var effectTag = nextEffect.effectTag; + // Restore the original state of the work-in-progress + if (stashedWorkInProgressProperties === null) { + // This should never happen. Don't throw because this code is DEV-only. + warning( + false, + "Could not replay rendering after an error. This is likely a bug in React. " + + "Please file an issue." + ); + return; + } + assignFiberPropertiesInDEV( + failedUnitOfWork, + stashedWorkInProgressProperties + ); - if (effectTag & ContentReset) { - commitResetTextContent(nextEffect); - } + switch (failedUnitOfWork.tag) { + case HostRoot: + popHostContainer(failedUnitOfWork); + popTopLevelContextObject(failedUnitOfWork); + break; + case HostComponent: + popHostContext(failedUnitOfWork); + break; + case ClassComponent: + popContextProvider(failedUnitOfWork); + break; + case HostPortal: + popHostContainer(failedUnitOfWork); + break; + case ContextProvider: + popProvider(failedUnitOfWork); + break; + } + // Replay the begin phase. + isReplayingFailedUnitOfWork = true; + originalReplayError = thrownValue; + invokeGuardedCallback$2(null, workLoop, null, isYieldy); + isReplayingFailedUnitOfWork = false; + originalReplayError = null; + if (hasCaughtError()) { + clearCaughtError(); - if (effectTag & Ref) { - var current = nextEffect.alternate; - if (current !== null) { - commitDetachRef(current); + if (enableProfilerTimer) { + if (failedUnitOfWork.mode & ProfileMode) { + recordElapsedActualRenderTime(failedUnitOfWork); } - } - // The following switch statement is only concerned about placement, - // updates, and deletions. To avoid needing to add a case for every - // possible bitmap value, we remove the secondary effects from the - // effect tag and switch on that value. - var primaryEffectTag = effectTag & (Placement | Update | Deletion); - switch (primaryEffectTag) { - case Placement: { - commitPlacement(nextEffect); - // Clear the "placement" from effect tag so that we know that this is inserted, before - // any life-cycles like componentDidMount gets called. - // TODO: findDOMNode doesn't rely on this any more but isMounted - // does and isMounted is deprecated anyway so we should be able - // to kill this. - nextEffect.effectTag &= ~Placement; - break; - } - case PlacementAndUpdate: { - // Placement - commitPlacement(nextEffect); - // Clear the "placement" from effect tag so that we know that this is inserted, before - // any life-cycles like componentDidMount gets called. - nextEffect.effectTag &= ~Placement; - - // Update - var _current = nextEffect.alternate; - commitWork(_current, nextEffect); - break; - } - case Update: { - var _current2 = nextEffect.alternate; - commitWork(_current2, nextEffect); - break; - } - case Deletion: { - commitDeletion(nextEffect); - break; - } + // Stop "base" render timer again (after the re-thrown error). + stopBaseRenderTimerIfRunning(); } - nextEffect = nextEffect.nextEffect; + } else { + // If the begin phase did not fail the second time, set this pointer + // back to the original value. + nextUnitOfWork = failedUnitOfWork; } + }; + rethrowOriginalError = function() { + throw originalReplayError; + }; +} - { - ReactDebugCurrentFiber.resetCurrentFiber(); +function resetStack() { + if (nextUnitOfWork !== null) { + var interruptedWork = nextUnitOfWork.return; + while (interruptedWork !== null) { + unwindInterruptedWork(interruptedWork); + interruptedWork = interruptedWork.return; } } - function commitBeforeMutationLifecycles() { - while (nextEffect !== null) { - var effectTag = nextEffect.effectTag; + { + ReactStrictModeWarnings.discardPendingWarnings(); + checkThatStackIsEmpty(); + } - if (effectTag & Snapshot) { - recordEffect(); - var current = nextEffect.alternate; - commitBeforeMutationLifeCycles(current, nextEffect); - } + nextRoot = null; + nextRenderExpirationTime = NoWork; + nextLatestTimeoutMs = -1; + nextRenderDidError = false; + nextUnitOfWork = null; +} - // Don't cleanup effects yet; - // This will be done by commitAllLifeCycles() - nextEffect = nextEffect.nextEffect; +function commitAllHostEffects() { + while (nextEffect !== null) { + { + ReactDebugCurrentFiber.setCurrentFiber(nextEffect); } - } + recordEffect(); - function commitAllLifeCycles( - finishedRoot, - currentTime, - committedExpirationTime - ) { - { - ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings(); + var effectTag = nextEffect.effectTag; + + if (effectTag & ContentReset) { + commitResetTextContent(nextEffect); + } - if (warnAboutDeprecatedLifecycles) { - ReactStrictModeWarnings.flushPendingDeprecationWarnings(); + if (effectTag & Ref) { + var current = nextEffect.alternate; + if (current !== null) { + commitDetachRef(current); } } - while (nextEffect !== null) { - var effectTag = nextEffect.effectTag; - if (effectTag & (Update | Callback)) { - recordEffect(); - var current = nextEffect.alternate; - commitLifeCycles( - finishedRoot, - current, - nextEffect, - currentTime, - committedExpirationTime - ); + // The following switch statement is only concerned about placement, + // updates, and deletions. To avoid needing to add a case for every + // possible bitmap value, we remove the secondary effects from the + // effect tag and switch on that value. + var primaryEffectTag = effectTag & (Placement | Update | Deletion); + switch (primaryEffectTag) { + case Placement: { + commitPlacement(nextEffect); + // Clear the "placement" from effect tag so that we know that this is inserted, before + // any life-cycles like componentDidMount gets called. + // TODO: findDOMNode doesn't rely on this any more but isMounted + // does and isMounted is deprecated anyway so we should be able + // to kill this. + nextEffect.effectTag &= ~Placement; + break; } + case PlacementAndUpdate: { + // Placement + commitPlacement(nextEffect); + // Clear the "placement" from effect tag so that we know that this is inserted, before + // any life-cycles like componentDidMount gets called. + nextEffect.effectTag &= ~Placement; - if (effectTag & Ref) { - recordEffect(); - commitAttachRef(nextEffect); + // Update + var _current = nextEffect.alternate; + commitWork(_current, nextEffect); + break; } + case Update: { + var _current2 = nextEffect.alternate; + commitWork(_current2, nextEffect); + break; + } + case Deletion: { + commitDeletion(nextEffect); + break; + } + } + nextEffect = nextEffect.nextEffect; + } + + { + ReactDebugCurrentFiber.resetCurrentFiber(); + } +} - var next = nextEffect.nextEffect; - // Ensure that we clean these up so that we don't accidentally keep them. - // I'm not actually sure this matters because we can't reset firstEffect - // and lastEffect since they're on every node, not just the effectful - // ones. So we have to clean everything as we reuse nodes anyway. - nextEffect.nextEffect = null; - // Ensure that we reset the effectTag here so that we can rely on effect - // tags to reason about the current life-cycle. - nextEffect = next; +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 isAlreadyFailedLegacyErrorBoundary(instance) { - return ( - legacyErrorBoundariesThatAlreadyFailed !== null && - legacyErrorBoundariesThatAlreadyFailed.has(instance) - ); +function commitAllLifeCycles( + finishedRoot, + currentTime, + committedExpirationTime +) { + { + ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings(); + + if (warnAboutDeprecatedLifecycles) { + ReactStrictModeWarnings.flushPendingDeprecationWarnings(); + } + + if (warnAboutLegacyContextAPI) { + ReactStrictModeWarnings.flushLegacyContextWarning(); + } } + while (nextEffect !== null) { + var effectTag = nextEffect.effectTag; - function markLegacyErrorBoundaryAsFailed(instance) { - if (legacyErrorBoundariesThatAlreadyFailed === null) { - legacyErrorBoundariesThatAlreadyFailed = new Set([instance]); - } else { - legacyErrorBoundariesThatAlreadyFailed.add(instance); + if (effectTag & (Update | Callback)) { + recordEffect(); + var current = nextEffect.alternate; + commitLifeCycles( + finishedRoot, + current, + nextEffect, + currentTime, + committedExpirationTime + ); + } + + if (effectTag & Ref) { + recordEffect(); + commitAttachRef(nextEffect); } + + var next = nextEffect.nextEffect; + // Ensure that we clean these up so that we don't accidentally keep them. + // I'm not actually sure this matters because we can't reset firstEffect + // and lastEffect since they're on every node, not just the effectful + // ones. So we have to clean everything as we reuse nodes anyway. + nextEffect.nextEffect = null; + // Ensure that we reset the effectTag here so that we can rely on effect + // tags to reason about the current life-cycle. + nextEffect = next; } +} - function commitRoot(finishedWork) { - isWorking = true; - isCommitting = true; - startCommitTimer(); +function isAlreadyFailedLegacyErrorBoundary(instance) { + return ( + legacyErrorBoundariesThatAlreadyFailed !== null && + legacyErrorBoundariesThatAlreadyFailed.has(instance) + ); +} - var root = finishedWork.stateNode; - invariant( - root.current !== finishedWork, - "Cannot commit the same tree as before. This is probably a bug " + - "related to the return field. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - var committedExpirationTime = root.pendingCommitExpirationTime; - invariant( - committedExpirationTime !== NoWork, - "Cannot commit an incomplete root. This error is likely caused by a " + - "bug in React. Please file an issue." - ); - root.pendingCommitExpirationTime = NoWork; +function markLegacyErrorBoundaryAsFailed(instance) { + if (legacyErrorBoundariesThatAlreadyFailed === null) { + legacyErrorBoundariesThatAlreadyFailed = new Set([instance]); + } else { + legacyErrorBoundariesThatAlreadyFailed.add(instance); + } +} - var currentTime = recalculateCurrentTime(); +function commitRoot(root, finishedWork) { + isWorking = true; + isCommitting$1 = true; + startCommitTimer(); - // Reset this to null before calling lifecycles - ReactCurrentOwner.current = null; - - var firstEffect = void 0; - if (finishedWork.effectTag > PerformedWork) { - // A fiber's effect list consists only of its children, not itself. So if - // the root has an effect, we need to add it to the end of the list. The - // resulting list is the set that would belong to the root's parent, if - // it had one; that is, all the effects in the tree including the root. - if (finishedWork.lastEffect !== null) { - finishedWork.lastEffect.nextEffect = finishedWork; - firstEffect = finishedWork.firstEffect; - } else { - firstEffect = finishedWork; - } - } else { - // There is no effect on the root. + invariant( + root.current !== finishedWork, + "Cannot commit the same tree as before. This is probably a bug " + + "related to the return field. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + var committedExpirationTime = root.pendingCommitExpirationTime; + invariant( + committedExpirationTime !== NoWork, + "Cannot commit an incomplete root. This error is likely caused by a " + + "bug in React. Please file an issue." + ); + root.pendingCommitExpirationTime = NoWork; + + // Update the pending priority levels to account for the work that we are + // about to commit. This needs to happen before calling the lifecycles, since + // they may schedule additional updates. + var earliestRemainingTime = finishedWork.expirationTime; + var currentTime = recalculateCurrentTime(); + markCommittedPriorityLevels(root, currentTime, earliestRemainingTime); + + // Reset this to null before calling lifecycles + ReactCurrentOwner.current = null; + + var firstEffect = void 0; + if (finishedWork.effectTag > PerformedWork) { + // A fiber's effect list consists only of its children, not itself. So if + // the root has an effect, we need to add it to the end of the list. The + // resulting list is the set that would belong to the root's parent, if + // it had one; that is, all the effects in the tree including the root. + if (finishedWork.lastEffect !== null) { + finishedWork.lastEffect.nextEffect = finishedWork; firstEffect = finishedWork.firstEffect; + } else { + firstEffect = finishedWork; } + } else { + // There is no effect on the root. + firstEffect = finishedWork.firstEffect; + } - prepareForCommit(root.containerInfo); + prepareForCommit(root.containerInfo); - // Invoke instances of getSnapshotBeforeUpdate before mutation. - nextEffect = firstEffect; - startCommitSnapshotEffectsTimer(); - while (nextEffect !== null) { - var didError = false; - var error = void 0; - { - invokeGuardedCallback$2(null, commitBeforeMutationLifecycles, null); - if (hasCaughtError()) { - didError = true; - error = clearCaughtError(); - } + // Invoke instances of getSnapshotBeforeUpdate before mutation. + nextEffect = firstEffect; + startCommitSnapshotEffectsTimer(); + while (nextEffect !== null) { + var didError = false; + var error = void 0; + { + invokeGuardedCallback$2(null, commitBeforeMutationLifecycles, 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; - } + } + if (didError) { + invariant( + nextEffect !== null, + "Should have next effect. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + captureCommitPhaseError(nextEffect, error); + // Clean-up + if (nextEffect !== null) { + nextEffect = nextEffect.nextEffect; } } - stopCommitSnapshotEffectsTimer(); + } + 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 (enableProfilerTimer) { + // Mark the current commit time to be shared by all Profilers in this batch. + // This enables them to be grouped later. + recordCommitTime(); + } + + // 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; - } + } + if (_didError) { + invariant( + nextEffect !== null, + "Should have next effect. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + captureCommitPhaseError(nextEffect, _error); + // Clean-up + if (nextEffect !== null) { + nextEffect = nextEffect.nextEffect; } } - stopCommitHostEffectsTimer(); + } + stopCommitHostEffectsTimer(); - resetAfterCommit(root.containerInfo); + resetAfterCommit(root.containerInfo); - // The work-in-progress tree is now the current tree. This must come after - // the first pass of the commit phase, so that the previous tree is still - // current during componentWillUnmount, but before the second pass, so that - // the finished work is current during componentDidMount/Update. - root.current = finishedWork; + // The work-in-progress tree is now the current tree. This must come after + // the first pass of the commit phase, so that the previous tree is still + // current during componentWillUnmount, but before the second pass, so that + // the finished work is current during componentDidMount/Update. + root.current = finishedWork; - // In the second pass we'll perform all life-cycles and ref callbacks. - // Life-cycles happen as a separate pass so that all placements, updates, - // and deletions in the entire tree have already been invoked. - // This pass also triggers any renderer-specific initial effects. - nextEffect = firstEffect; - startCommitLifeCyclesTimer(); - while (nextEffect !== null) { - var _didError2 = false; - var _error2 = void 0; - { - invokeGuardedCallback$2( - null, - commitAllLifeCycles, - null, - root, - currentTime, - committedExpirationTime - ); - if (hasCaughtError()) { - _didError2 = true; - _error2 = clearCaughtError(); - } - } - if (_didError2) { - invariant( - nextEffect !== null, - "Should have next effect. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - onCommitPhaseError(nextEffect, _error2); - if (nextEffect !== null) { - nextEffect = nextEffect.nextEffect; - } + // In the second pass we'll perform all life-cycles and ref callbacks. + // Life-cycles happen as a separate pass so that all placements, updates, + // and deletions in the entire tree have already been invoked. + // This pass also triggers any renderer-specific initial effects. + nextEffect = firstEffect; + startCommitLifeCyclesTimer(); + while (nextEffect !== null) { + var _didError2 = false; + var _error2 = void 0; + { + invokeGuardedCallback$2( + null, + commitAllLifeCycles, + null, + root, + currentTime, + committedExpirationTime + ); + if (hasCaughtError()) { + _didError2 = true; + _error2 = clearCaughtError(); } } - - if (enableProfilerTimer) { - { - checkActualRenderTimeStackEmpty(); + if (_didError2) { + invariant( + nextEffect !== null, + "Should have next effect. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + captureCommitPhaseError(nextEffect, _error2); + if (nextEffect !== null) { + nextEffect = nextEffect.nextEffect; } - resetActualRenderTimer(); } + } - isCommitting = false; - isWorking = false; - stopCommitLifeCyclesTimer(); - stopCommitTimer(); - if (typeof onCommitRoot === "function") { - onCommitRoot(finishedWork.stateNode); - } - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork); + if (enableProfilerTimer) { + { + checkActualRenderTimeStackEmpty(); } + resetActualRenderTimer(); + } - markCommittedPriorityLevels(root, currentTime, root.current.expirationTime); - var remainingTime = findNextPendingPriorityLevel(root); - if (remainingTime === NoWork) { - // If there's no remaining work, we can clear the set of already failed - // error boundaries. - legacyErrorBoundariesThatAlreadyFailed = null; - } - return remainingTime; + isCommitting$1 = false; + isWorking = false; + stopCommitLifeCyclesTimer(); + stopCommitTimer(); + if (typeof onCommitRoot === "function") { + onCommitRoot(finishedWork.stateNode); + } + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork); } - function resetExpirationTime(workInProgress, renderTime) { - if (renderTime !== Never && workInProgress.expirationTime === Never) { - // The children of this component are hidden. Don't bubble their - // expiration times. - return; - } + var expirationTime = root.expirationTime; + if (expirationTime === NoWork) { + // If there's no remaining work, we can clear the set of already failed + // error boundaries. + legacyErrorBoundariesThatAlreadyFailed = null; + } + onCommit(root, expirationTime); +} - // Check for pending updates. - var newExpirationTime = NoWork; - switch (workInProgress.tag) { - case HostRoot: - case ClassComponent: { - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - newExpirationTime = updateQueue.expirationTime; - } +function resetExpirationTime(workInProgress, renderTime) { + if (renderTime !== Never && workInProgress.expirationTime === Never) { + // The children of this component are hidden. Don't bubble their + // expiration times. + return; + } + + // Check for pending updates. + var newExpirationTime = NoWork; + switch (workInProgress.tag) { + case HostRoot: + case ClassComponent: { + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + newExpirationTime = updateQueue.expirationTime; } } + } - // TODO: Calls need to visit stateNode + // TODO: Calls need to visit stateNode - // Bubble up the earliest expiration time. - // (And "base" render timers if that feature flag is enabled) - if (enableProfilerTimer && workInProgress.mode & ProfileMode) { - var treeBaseTime = workInProgress.selfBaseTime; - var child = workInProgress.child; - while (child !== null) { - treeBaseTime += child.treeBaseTime; - if ( - child.expirationTime !== NoWork && - (newExpirationTime === NoWork || - newExpirationTime > child.expirationTime) - ) { - newExpirationTime = child.expirationTime; - } - child = child.sibling; + // Bubble up the earliest expiration time. + // (And "base" render timers if that feature flag is enabled) + if (enableProfilerTimer && workInProgress.mode & ProfileMode) { + var treeBaseTime = workInProgress.selfBaseTime; + var child = workInProgress.child; + while (child !== null) { + treeBaseTime += child.treeBaseTime; + if ( + child.expirationTime !== NoWork && + (newExpirationTime === NoWork || + newExpirationTime > child.expirationTime) + ) { + newExpirationTime = child.expirationTime; } - workInProgress.treeBaseTime = treeBaseTime; - } else { - var _child = workInProgress.child; - while (_child !== null) { - if ( - _child.expirationTime !== NoWork && - (newExpirationTime === NoWork || - newExpirationTime > _child.expirationTime) - ) { - newExpirationTime = _child.expirationTime; - } - _child = _child.sibling; + child = child.sibling; + } + workInProgress.treeBaseTime = treeBaseTime; + } else { + var _child = workInProgress.child; + while (_child !== null) { + if ( + _child.expirationTime !== NoWork && + (newExpirationTime === NoWork || + newExpirationTime > _child.expirationTime) + ) { + newExpirationTime = _child.expirationTime; } + _child = _child.sibling; } - - workInProgress.expirationTime = newExpirationTime; } - function completeUnitOfWork(workInProgress) { - // Attempt to complete the current unit of work, then move to the - // next sibling. If there are no more siblings, return to the - // parent fiber. - while (true) { - // The current, flushed, state of this fiber is the alternate. - // Ideally nothing should rely on this, but relying on it here - // means that we don't need an additional field on the work in - // progress. - var current = workInProgress.alternate; + workInProgress.expirationTime = newExpirationTime; +} + +function completeUnitOfWork(workInProgress) { + // Attempt to complete the current unit of work, then move to the + // next sibling. If there are no more siblings, return to the + // parent fiber. + while (true) { + // The current, flushed, state of this fiber is the alternate. + // Ideally nothing should rely on this, but relying on it here + // means that we don't need an additional field on the work in + // progress. + var current = workInProgress.alternate; + { + ReactDebugCurrentFiber.setCurrentFiber(workInProgress); + } + + var returnFiber = workInProgress.return; + var siblingFiber = workInProgress.sibling; + + if ((workInProgress.effectTag & Incomplete) === NoEffect) { + // This fiber completed. + var next = completeWork( + current, + workInProgress, + nextRenderExpirationTime + ); + stopWorkTimer(workInProgress); + resetExpirationTime(workInProgress, nextRenderExpirationTime); { - ReactDebugCurrentFiber.setCurrentFiber(workInProgress); + ReactDebugCurrentFiber.resetCurrentFiber(); } - var returnFiber = workInProgress.return; - var siblingFiber = workInProgress.sibling; - - if ((workInProgress.effectTag & Incomplete) === NoEffect) { - // This fiber completed. - var next = completeWork( - current, - workInProgress, - nextRenderExpirationTime - ); + if (next !== null) { stopWorkTimer(workInProgress); - resetExpirationTime(workInProgress, nextRenderExpirationTime); - { - ReactDebugCurrentFiber.resetCurrentFiber(); + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); } + // If completing this work spawned new work, do that next. We'll come + // back here again. + return next; + } - if (next !== null) { - stopWorkTimer(workInProgress); - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCompleteWork( - workInProgress - ); + if ( + returnFiber !== null && + // Do not append effects to parents if a sibling failed to complete + (returnFiber.effectTag & Incomplete) === NoEffect + ) { + // Append all the effects of the subtree and this fiber onto the effect + // list of the parent. The completion order of the children affects the + // side-effect order. + if (returnFiber.firstEffect === null) { + returnFiber.firstEffect = workInProgress.firstEffect; + } + if (workInProgress.lastEffect !== null) { + if (returnFiber.lastEffect !== null) { + returnFiber.lastEffect.nextEffect = workInProgress.firstEffect; } - // If completing this work spawned new work, do that next. We'll come - // back here again. - return next; + returnFiber.lastEffect = workInProgress.lastEffect; } - if ( - returnFiber !== null && - // Do not append effects to parents if a sibling failed to complete - (returnFiber.effectTag & Incomplete) === NoEffect - ) { - // Append all the effects of the subtree and this fiber onto the effect - // list of the parent. The completion order of the children affects the - // side-effect order. - if (returnFiber.firstEffect === null) { - returnFiber.firstEffect = workInProgress.firstEffect; - } - if (workInProgress.lastEffect !== null) { - if (returnFiber.lastEffect !== null) { - returnFiber.lastEffect.nextEffect = workInProgress.firstEffect; - } - returnFiber.lastEffect = workInProgress.lastEffect; - } - - // If this fiber had side-effects, we append it AFTER the children's - // side-effects. We can perform certain side-effects earlier if - // needed, by doing multiple passes over the effect list. We don't want - // to schedule our own side-effect on our own list because if end up - // reusing children we'll schedule this effect onto itself since we're - // at the end. - var effectTag = workInProgress.effectTag; - // Skip both NoWork and PerformedWork tags when creating the effect list. - // PerformedWork effect is read by React DevTools but shouldn't be committed. - if (effectTag > PerformedWork) { - if (returnFiber.lastEffect !== null) { - returnFiber.lastEffect.nextEffect = workInProgress; - } else { - returnFiber.firstEffect = workInProgress; - } - returnFiber.lastEffect = workInProgress; + // If this fiber had side-effects, we append it AFTER the children's + // side-effects. We can perform certain side-effects earlier if + // needed, by doing multiple passes over the effect list. We don't want + // to schedule our own side-effect on our own list because if end up + // reusing children we'll schedule this effect onto itself since we're + // at the end. + var effectTag = workInProgress.effectTag; + // Skip both NoWork and PerformedWork tags when creating the effect list. + // PerformedWork effect is read by React DevTools but shouldn't be committed. + if (effectTag > PerformedWork) { + if (returnFiber.lastEffect !== null) { + returnFiber.lastEffect.nextEffect = workInProgress; + } else { + returnFiber.firstEffect = workInProgress; } + returnFiber.lastEffect = workInProgress; } + } - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); - } + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); + } - if (siblingFiber !== null) { - // If there is more work to do in this returnFiber, do that next. - return siblingFiber; - } else if (returnFiber !== null) { - // If there's no more work in this returnFiber. Complete the returnFiber. - workInProgress = returnFiber; - continue; - } else { - // We've reached the root. - isRootReadyForCommit = true; - return null; - } + if (siblingFiber !== null) { + // If there is more work to do in this returnFiber, do that next. + return siblingFiber; + } else if (returnFiber !== null) { + // If there's no more work in this returnFiber. Complete the returnFiber. + workInProgress = returnFiber; + continue; } else { - // This fiber did not complete because something threw. Pop values off - // the stack without entering the complete phase. If this is a boundary, - // capture values if possible. - var _next = unwindWork( - workInProgress, - nextRenderIsExpired, - nextRenderExpirationTime - ); - // Because this fiber did not complete, don't reset its expiration time. - if (workInProgress.effectTag & DidCapture) { - // Restarting an error boundary - stopFailedWorkTimer(workInProgress); - } else { - stopWorkTimer(workInProgress); - } - - { - ReactDebugCurrentFiber.resetCurrentFiber(); - } - - if (_next !== null) { - stopWorkTimer(workInProgress); - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCompleteWork( - workInProgress - ); - } - // If completing this work spawned new work, do that next. We'll come - // back here again. - // Since we're restarting, remove anything that is not a host effect - // from the effect tag. - _next.effectTag &= HostEffectMask; - return _next; - } + // We've reached the root. + return null; + } + } else { + // This fiber did not complete because something threw. Pop values off + // the stack without entering the complete phase. If this is a boundary, + // capture values if possible. + var _next = unwindWork(workInProgress, nextRenderExpirationTime); + // Because this fiber did not complete, don't reset its expiration time. + if (workInProgress.effectTag & DidCapture) { + // Restarting an error boundary + stopFailedWorkTimer(workInProgress); + } else { + stopWorkTimer(workInProgress); + } - if (returnFiber !== null) { - // Mark the parent fiber as incomplete and clear its effect list. - returnFiber.firstEffect = returnFiber.lastEffect = null; - returnFiber.effectTag |= Incomplete; - } + { + ReactDebugCurrentFiber.resetCurrentFiber(); + } + if (_next !== null) { + stopWorkTimer(workInProgress); if (true && ReactFiberInstrumentation_1.debugTool) { ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); } + // If completing this work spawned new work, do that next. We'll come + // back here again. + // Since we're restarting, remove anything that is not a host effect + // from the effect tag. + _next.effectTag &= HostEffectMask; + return _next; + } - if (siblingFiber !== null) { - // If there is more work to do in this returnFiber, do that next. - return siblingFiber; - } else if (returnFiber !== null) { - // If there's no more work in this returnFiber. Complete the returnFiber. - workInProgress = returnFiber; - continue; - } else { - return null; - } + if (returnFiber !== null) { + // Mark the parent fiber as incomplete and clear its effect list. + returnFiber.firstEffect = returnFiber.lastEffect = null; + returnFiber.effectTag |= Incomplete; + } + + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); + } + + if (siblingFiber !== null) { + // If there is more work to do in this returnFiber, do that next. + return siblingFiber; + } else if (returnFiber !== null) { + // If there's no more work in this returnFiber. Complete the returnFiber. + workInProgress = returnFiber; + continue; + } else { + return null; } } + } - // Without this explicit null return Flow complains of invalid return type - // TODO Remove the above while(true) loop - // eslint-disable-next-line no-unreachable - return null; + // Without this explicit null return Flow complains of invalid return type + // TODO Remove the above while(true) loop + // eslint-disable-next-line no-unreachable + return null; +} + +function performUnitOfWork(workInProgress) { + // The current, flushed, state of this fiber is the alternate. + // Ideally nothing should rely on this, but relying on it here + // means that we don't need an additional field on the work in + // progress. + var current = workInProgress.alternate; + + // See if beginning this work spawns more work. + startWorkTimer(workInProgress); + { + ReactDebugCurrentFiber.setCurrentFiber(workInProgress); } - function performUnitOfWork(workInProgress) { - // The current, flushed, state of this fiber is the alternate. - // Ideally nothing should rely on this, but relying on it here - // means that we don't need an additional field on the work in - // progress. - var current = workInProgress.alternate; + if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { + stashedWorkInProgressProperties = assignFiberPropertiesInDEV( + stashedWorkInProgressProperties, + workInProgress + ); + } - // See if beginning this work spawns more work. - startWorkTimer(workInProgress); - { - ReactDebugCurrentFiber.setCurrentFiber(workInProgress); + var next = void 0; + if (enableProfilerTimer) { + if (workInProgress.mode & ProfileMode) { + startBaseRenderTimer(); } - if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { - stashedWorkInProgressProperties = assignFiberPropertiesInDEV( - stashedWorkInProgressProperties, - workInProgress - ); + next = beginWork(current, workInProgress, nextRenderExpirationTime); + + if (workInProgress.mode & ProfileMode) { + // Update "base" time if the render wasn't bailed out on. + recordElapsedBaseRenderTimeIfRunning(workInProgress); + stopBaseRenderTimerIfRunning(); } + } else { + next = beginWork(current, workInProgress, nextRenderExpirationTime); + } - var next = void 0; - if (enableProfilerTimer) { - if (workInProgress.mode & ProfileMode) { - startBaseRenderTimer(); - } + { + 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); + } - next = beginWork(current, workInProgress, nextRenderExpirationTime); + if (next === null) { + // If this doesn't spawn new work, complete the current work. + next = completeUnitOfWork(workInProgress); + } - if (workInProgress.mode & ProfileMode) { - // Update "base" time if the render wasn't bailed out on. - recordElapsedBaseRenderTimeIfRunning(workInProgress); - stopBaseRenderTimerIfRunning(); - } - } else { - next = beginWork(current, workInProgress, nextRenderExpirationTime); - } + ReactCurrentOwner.current = null; - { - 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(); - } + return next; +} + +function workLoop(isYieldy) { + if (!isYieldy) { + // Flush work without yielding + while (nextUnitOfWork !== null) { + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); } - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress); + } else { + // Flush asynchronous work until the deadline runs out of time. + while (nextUnitOfWork !== null && !shouldYield()) { + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); } - if (next === null) { - // If this doesn't spawn new work, complete the current work. - next = completeUnitOfWork(workInProgress); + if (enableProfilerTimer) { + // If we didn't finish, pause the "actual" render timer. + // We'll restart it when we resume work. + pauseActualRenderTimerIfRunning(); } - - ReactCurrentOwner.current = null; - - return next; } +} - function workLoop(isAsync) { - if (!isAsync) { - // Flush all expired work. - while (nextUnitOfWork !== null) { - nextUnitOfWork = performUnitOfWork(nextUnitOfWork); - } - } else { - // Flush asynchronous work until the deadline runs out of time. - while (nextUnitOfWork !== null && !shouldYield()) { - nextUnitOfWork = performUnitOfWork(nextUnitOfWork); - } +function renderRoot(root, isYieldy) { + invariant( + !isWorking, + "renderRoot was called recursively. This error is likely caused " + + "by a bug in React. Please file an issue." + ); + isWorking = true; - if (enableProfilerTimer) { - // If we didn't finish, pause the "actual" render timer. - // We'll restart it when we resume work. - pauseActualRenderTimerIfRunning(); - } - } - } + var expirationTime = root.nextExpirationTimeToWorkOn; - function renderRoot(root, expirationTime, isAsync) { - invariant( - !isWorking, - "renderRoot was called recursively. This error is likely caused " + - "by a bug in React. Please file an issue." + // Check if we're starting from a fresh stack, or if we're resuming from + // previously yielded work. + if ( + expirationTime !== nextRenderExpirationTime || + root !== nextRoot || + nextUnitOfWork === null + ) { + // Reset the stack and start working from the root. + resetStack(); + nextRoot = root; + nextRenderExpirationTime = expirationTime; + nextLatestTimeoutMs = -1; + nextRenderDidError = false; + nextUnitOfWork = createWorkInProgress( + nextRoot.current, + null, + nextRenderExpirationTime ); - isWorking = true; + root.pendingCommitExpirationTime = NoWork; + } - // Check if we're starting from a fresh stack, or if we're resuming from - // previously yielded work. - if ( - expirationTime !== nextRenderExpirationTime || - root !== nextRoot || - nextUnitOfWork === null - ) { - // Reset the stack and start working from the root. - resetStack(); - nextRoot = root; - nextRenderExpirationTime = expirationTime; - nextLatestTimeoutMs = -1; - nextUnitOfWork = createWorkInProgress( - nextRoot.current, - null, - nextRenderExpirationTime - ); - root.pendingCommitExpirationTime = NoWork; - } + var didFatal = false; - var didFatal = false; + startWorkLoopTimer(nextUnitOfWork); - nextRenderIsExpired = - !isAsync || nextRenderExpirationTime <= mostRecentCurrentTime; + do { + try { + workLoop(isYieldy); + } catch (thrownValue) { + if (enableProfilerTimer) { + // Stop "base" render timer in the event of an error. + stopBaseRenderTimerIfRunning(); + } - startWorkLoopTimer(nextUnitOfWork); + if (nextUnitOfWork === null) { + // This is a fatal error. + didFatal = true; + onUncaughtError(thrownValue); + } else { + { + // Reset global debug state + // We assume this is defined in DEV + resetCurrentlyProcessingQueue(); + } - do { - try { - workLoop(isAsync); - } catch (thrownValue) { - if (enableProfilerTimer) { - // Stop "base" render timer in the event of an error. - stopBaseRenderTimerIfRunning(); + var failedUnitOfWork = nextUnitOfWork; + if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { + replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy); } - if (nextUnitOfWork === null) { - // This is a fatal error. + // TODO: we already know this isn't true in some cases. + // At least this shows a nicer error message until we figure out the cause. + // https://github.com/facebook/react/issues/12449#issuecomment-386727431 + invariant( + nextUnitOfWork !== null, + "Failed to replay rendering after an error. This " + + "is likely caused by a bug in React. Please file an issue " + + "with a reproducing case to help us find it." + ); + + 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. didFatal = true; onUncaughtError(thrownValue); - } else { - { - // Reset global debug state - // We assume this is defined in DEV - resetCurrentlyProcessingQueue(); - } - - var failedUnitOfWork = nextUnitOfWork; - if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { - replayUnitOfWork(failedUnitOfWork, thrownValue, isAsync); - } - - // TODO: we already know this isn't true in some cases. - // At least this shows a nicer error message until we figure out the cause. - // https://github.com/facebook/react/issues/12449#issuecomment-386727431 - invariant( - nextUnitOfWork !== null, - "Failed to replay rendering after an error. This " + - "is likely caused by a bug in React. Please file an issue " + - "with a reproducing case to help us find it." - ); - - 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. - didFatal = true; - onUncaughtError(thrownValue); - break; - } - throwException( - root, - returnFiber, - sourceFiber, - thrownValue, - nextRenderIsExpired, - nextRenderExpirationTime, - mostRecentCurrentTimeMs - ); - nextUnitOfWork = completeUnitOfWork(sourceFiber); + break; } - } - break; - } while (true); - - // We're done performing work. Time to clean up. - var didCompleteRoot = false; - 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( - !nextRenderIsExpired, - "Expired work should have completed. This error is likely caused " + - "by a bug in React. Please file an issue." + throwException( + root, + returnFiber, + sourceFiber, + thrownValue, + nextRenderExpirationTime, + mostRecentCurrentTimeMs ); - markSuspendedPriorityLevel(root, expirationTime); - if (nextLatestTimeoutMs >= 0) { - setTimeout(function() { - retrySuspendedRoot(root, expirationTime); - }, nextLatestTimeoutMs); - } - var firstUnblockedExpirationTime = findNextPendingPriorityLevel(root); - onBlock(firstUnblockedExpirationTime); - return null; + nextUnitOfWork = completeUnitOfWork(sourceFiber); } + } + break; + } while (true); + + // We're done performing work. Time to clean up. + isWorking = false; + + // Yield back to main thread. + if (didFatal) { + var didCompleteRoot = false; + stopWorkLoopTimer(interruptedBy, didCompleteRoot); + interruptedBy = null; + // There was a fatal error. + { + resetStackAfterFatalErrorInDev(); + } + onFatal(root); + } else if (nextUnitOfWork === null) { + // We reached the root. + var rootWorkInProgress = root.current.alternate; + invariant( + rootWorkInProgress !== null, + "Finished root should have a work-in-progress. This error is likely " + + "caused by a bug in React. Please file an issue." + ); + if ((rootWorkInProgress.effectTag & Incomplete) === NoEffect) { + var _didCompleteRoot = true; + stopWorkLoopTimer(interruptedBy, _didCompleteRoot); + interruptedBy = null; + // The root successfully completed. + onComplete(root, rootWorkInProgress, expirationTime); } else { - stopWorkLoopTimer(interruptedBy, didCompleteRoot); + // The root did not complete. + var _didCompleteRoot2 = false; + stopWorkLoopTimer(interruptedBy, _didCompleteRoot2); interruptedBy = null; - // There's more work to do, but we ran out of time. Yield back to - // the renderer. - return null; + markSuspendedPriorityLevel(root, expirationTime, nextRenderDidError); + var suspendedExpirationTime = expirationTime; + var newExpirationTime = root.expirationTime; + onSuspend( + root, + suspendedExpirationTime, + newExpirationTime, + nextLatestTimeoutMs + ); } + } else { + var _didCompleteRoot3 = false; + stopWorkLoopTimer(interruptedBy, _didCompleteRoot3); + interruptedBy = null; + onYield(root); } +} - function dispatch(sourceFiber, value, expirationTime) { - invariant( - !isWorking || isCommitting, - "dispatch: Cannot dispatch during the render phase." - ); +function dispatch(sourceFiber, value, expirationTime) { + invariant( + !isWorking || isCommitting$1, + "dispatch: Cannot dispatch during the render phase." + ); - var fiber = sourceFiber.return; - while (fiber !== null) { - switch (fiber.tag) { - case ClassComponent: - var ctor = fiber.type; - var instance = fiber.stateNode; - if ( - typeof ctor.getDerivedStateFromCatch === "function" || - (typeof instance.componentDidCatch === "function" && - !isAlreadyFailedLegacyErrorBoundary(instance)) - ) { - var errorInfo = createCapturedValue(value, sourceFiber); - var update = createClassErrorUpdate( - fiber, - errorInfo, - expirationTime - ); - enqueueUpdate(fiber, update, expirationTime); - scheduleWork(fiber, expirationTime); - return; - } - break; - case HostRoot: { - var _errorInfo = createCapturedValue(value, sourceFiber); - var _update = createRootErrorUpdate( - fiber, - _errorInfo, - expirationTime - ); - enqueueUpdate(fiber, _update, expirationTime); + var fiber = sourceFiber.return; + while (fiber !== null) { + switch (fiber.tag) { + case ClassComponent: + var ctor = fiber.type; + var instance = fiber.stateNode; + if ( + typeof ctor.getDerivedStateFromCatch === "function" || + (typeof instance.componentDidCatch === "function" && + !isAlreadyFailedLegacyErrorBoundary(instance)) + ) { + var errorInfo = createCapturedValue(value, sourceFiber); + var update = createClassErrorUpdate(fiber, errorInfo, expirationTime); + enqueueUpdate(fiber, update, expirationTime); scheduleWork(fiber, expirationTime); return; } + break; + case HostRoot: { + var _errorInfo = createCapturedValue(value, sourceFiber); + var _update = createRootErrorUpdate(fiber, _errorInfo, expirationTime); + enqueueUpdate(fiber, _update, expirationTime); + scheduleWork(fiber, expirationTime); + return; } - fiber = fiber.return; - } - - if (sourceFiber.tag === HostRoot) { - // Error was thrown at the root. There is no parent, so the root - // itself should capture it. - var rootFiber = sourceFiber; - var _errorInfo2 = createCapturedValue(value, rootFiber); - var _update2 = createRootErrorUpdate( - rootFiber, - _errorInfo2, - expirationTime - ); - enqueueUpdate(rootFiber, _update2, expirationTime); - scheduleWork(rootFiber, expirationTime); } + fiber = fiber.return; } - function onCommitPhaseError(fiber, error) { - return dispatch(fiber, error, Sync); + if (sourceFiber.tag === HostRoot) { + // Error was thrown at the root. There is no parent, so the root + // itself should capture it. + var rootFiber = sourceFiber; + var _errorInfo2 = createCapturedValue(value, rootFiber); + var _update2 = createRootErrorUpdate( + rootFiber, + _errorInfo2, + expirationTime + ); + enqueueUpdate(rootFiber, _update2, expirationTime); + scheduleWork(rootFiber, expirationTime); } +} - function computeAsyncExpiration(currentTime) { - // Given the current clock time, returns an expiration time. We use rounding - // to batch like updates together. - // Should complete within ~1000ms. 1200ms max. - var expirationMs = 5000; - var bucketSizeMs = 250; - return computeExpirationBucket(currentTime, expirationMs, bucketSizeMs); - } +function captureCommitPhaseError(fiber, error) { + return dispatch(fiber, error, Sync); +} - function computeInteractiveExpiration(currentTime) { - var expirationMs = void 0; - // We intentionally set a higher expiration time for interactive updates in - // dev than in production. - // If the main thread is being blocked so long that you hit the expiration, - // it's a problem that could be solved with better scheduling. - // People will be more likely to notice this and fix it with the long - // expiration time in development. - // In production we opt for better UX at the risk of masking scheduling - // problems, by expiring fast. - { - // Should complete within ~500ms. 600ms max. - expirationMs = 500; - } - var bucketSizeMs = 100; - return computeExpirationBucket(currentTime, expirationMs, bucketSizeMs); - } +function computeAsyncExpiration(currentTime) { + // Given the current clock time, returns an expiration time. We use rounding + // to batch like updates together. + // Should complete within ~5000ms. 5250ms max. + var expirationMs = 5000; + var bucketSizeMs = 250; + return computeExpirationBucket(currentTime, expirationMs, bucketSizeMs); +} - // Creates a unique async expiration time. - function computeUniqueAsyncExpiration() { - var currentTime = recalculateCurrentTime(); - var result = computeAsyncExpiration(currentTime); - if (result <= lastUniqueAsyncExpiration) { - // Since we assume the current time monotonically increases, we only hit - // this branch when computeUniqueAsyncExpiration is fired multiple times - // within a 200ms window (or whatever the async bucket size is). - result = lastUniqueAsyncExpiration + 1; - } - lastUniqueAsyncExpiration = result; - return lastUniqueAsyncExpiration; - } - - function computeExpirationForFiber(currentTime, fiber) { - var expirationTime = void 0; - if (expirationContext !== NoWork) { - // An explicit expiration context was set; - expirationTime = expirationContext; - } else if (isWorking) { - if (isCommitting) { - // Updates that occur during the commit phase should have sync priority - // by default. - expirationTime = Sync; - } else { - // Updates during the render phase should expire at the same time as - // the work that is being rendered. - expirationTime = nextRenderExpirationTime; - } +function computeInteractiveExpiration(currentTime) { + var expirationMs = void 0; + // We intentionally set a higher expiration time for interactive updates in + // dev than in production. + // If the main thread is being blocked so long that you hit the expiration, + // it's a problem that could be solved with better scheduling. + // People will be more likely to notice this and fix it with the long + // expiration time in development. + // In production we opt for better UX at the risk of masking scheduling + // problems, by expiring fast. + { + // Should complete within ~500ms. 600ms max. + expirationMs = 500; + } + var bucketSizeMs = 100; + return computeExpirationBucket(currentTime, expirationMs, bucketSizeMs); +} + +// Creates a unique async expiration time. +function computeUniqueAsyncExpiration() { + var currentTime = recalculateCurrentTime(); + var result = computeAsyncExpiration(currentTime); + if (result <= lastUniqueAsyncExpiration) { + // Since we assume the current time monotonically increases, we only hit + // this branch when computeUniqueAsyncExpiration is fired multiple times + // within a 200ms window (or whatever the async bucket size is). + result = lastUniqueAsyncExpiration + 1; + } + lastUniqueAsyncExpiration = result; + return lastUniqueAsyncExpiration; +} + +function computeExpirationForFiber(currentTime, fiber) { + var expirationTime = void 0; + if (expirationContext !== NoWork) { + // An explicit expiration context was set; + expirationTime = expirationContext; + } else if (isWorking) { + if (isCommitting$1) { + // Updates that occur during the commit phase should have sync priority + // by default. + expirationTime = Sync; } else { - // No explicit expiration context was set, and we're not currently - // performing work. Calculate a new expiration time. - if (fiber.mode & AsyncMode) { - if (isBatchingInteractiveUpdates) { - // This is an interactive update - expirationTime = computeInteractiveExpiration(currentTime); - } else { - // This is an async update - expirationTime = computeAsyncExpiration(currentTime); - } + // Updates during the render phase should expire at the same time as + // the work that is being rendered. + expirationTime = nextRenderExpirationTime; + } + } else { + // No explicit expiration context was set, and we're not currently + // performing work. Calculate a new expiration time. + if (fiber.mode & AsyncMode) { + if (isBatchingInteractiveUpdates) { + // This is an interactive update + expirationTime = computeInteractiveExpiration(currentTime); } else { - // This is a sync update - expirationTime = Sync; + // This is an async update + expirationTime = computeAsyncExpiration(currentTime); } + } else { + // This is a sync update + expirationTime = Sync; } - if (isBatchingInteractiveUpdates) { - // This is an interactive update. Keep track of the lowest pending - // interactive expiration time. This allows us to synchronously flush - // all interactive updates when needed. - if ( - lowestPendingInteractiveExpirationTime === NoWork || - expirationTime > lowestPendingInteractiveExpirationTime - ) { - lowestPendingInteractiveExpirationTime = expirationTime; - } + } + if (isBatchingInteractiveUpdates) { + // This is an interactive update. Keep track of the lowest pending + // interactive expiration time. This allows us to synchronously flush + // all interactive updates when needed. + if ( + lowestPendingInteractiveExpirationTime === NoWork || + expirationTime > lowestPendingInteractiveExpirationTime + ) { + lowestPendingInteractiveExpirationTime = expirationTime; } - return expirationTime; } + return expirationTime; +} - // TODO: Rename this to scheduleTimeout or something - function suspendRoot(root, thenable, timeoutMs, suspendedTime) { - // Schedule the timeout. - if (timeoutMs >= 0 && nextLatestTimeoutMs < timeoutMs) { - nextLatestTimeoutMs = timeoutMs; - } +function markTimeout(root, thenable, timeoutMs, suspendedTime) { + // Schedule the timeout. + if (timeoutMs >= 0 && nextLatestTimeoutMs < timeoutMs) { + nextLatestTimeoutMs = timeoutMs; } +} - function retrySuspendedRoot(root, suspendedTime) { - markPingedPriorityLevel(root, suspendedTime); - var retryTime = findNextPendingPriorityLevel(root); - if (retryTime !== NoWork) { - requestRetry(root, retryTime); - } +function markError(root) { + nextRenderDidError = true; +} + +function retrySuspendedRoot(root, suspendedTime) { + markPingedPriorityLevel(root, suspendedTime); + var retryTime = root.expirationTime; + if (retryTime !== NoWork) { + requestWork(root, retryTime); } +} - function scheduleWork(fiber, expirationTime) { - recordScheduleUpdate(); +function scheduleWork(fiber, expirationTime) { + recordScheduleUpdate(); - { - if (fiber.tag === ClassComponent) { - var instance = fiber.stateNode; - warnAboutInvalidUpdates(instance); - } + { + if (fiber.tag === ClassComponent) { + var instance = fiber.stateNode; + warnAboutInvalidUpdates(instance); } + } - var node = fiber; - while (node !== null) { - // Walk the parent path to the root and update each node's - // expiration time. + var node = fiber; + while (node !== null) { + // Walk the parent path to the root and update each node's + // expiration time. + if ( + node.expirationTime === NoWork || + node.expirationTime > expirationTime + ) { + node.expirationTime = expirationTime; + } + if (node.alternate !== null) { if ( - node.expirationTime === NoWork || - node.expirationTime > expirationTime + node.alternate.expirationTime === NoWork || + node.alternate.expirationTime > expirationTime ) { - node.expirationTime = expirationTime; + node.alternate.expirationTime = expirationTime; } - if (node.alternate !== null) { + } + if (node.return === null) { + if (node.tag === HostRoot) { + var root = node.stateNode; if ( - node.alternate.expirationTime === NoWork || - node.alternate.expirationTime > expirationTime + !isWorking && + nextRenderExpirationTime !== NoWork && + expirationTime < nextRenderExpirationTime ) { - node.alternate.expirationTime = expirationTime; + // This is an interruption. (Used for performance tracking.) + interruptedBy = fiber; + resetStack(); } - } - if (node.return === null) { - if (node.tag === HostRoot) { - var root = node.stateNode; - if ( - !isWorking && - nextRenderExpirationTime !== NoWork && - expirationTime < nextRenderExpirationTime - ) { - // This is an interruption. (Used for performance tracking.) - interruptedBy = fiber; - resetStack(); - } - markPendingPriorityLevel(root, expirationTime); - var nextExpirationTimeToWorkOn = findNextPendingPriorityLevel(root); - 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 - ) { - requestWork(root, nextExpirationTimeToWorkOn); - } - if (nestedUpdateCount > NESTED_UPDATE_LIMIT) { - invariant( - false, - "Maximum update depth exceeded. This can happen when a " + - "component repeatedly calls setState inside " + - "componentWillUpdate or componentDidUpdate. React limits " + - "the number of nested updates to prevent infinite loops." - ); - } - } else { - { - if (fiber.tag === ClassComponent) { - warnAboutUpdateOnUnmounted(fiber); - } + markPendingPriorityLevel(root, expirationTime); + 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$1 || + // ...unless this is a different root than the one we're rendering. + nextRoot !== root + ) { + var rootExpirationTime = root.expirationTime; + requestWork(root, rootExpirationTime); + } + if (nestedUpdateCount > NESTED_UPDATE_LIMIT) { + invariant( + false, + "Maximum update depth exceeded. This can happen when a " + + "component repeatedly calls setState inside " + + "componentWillUpdate or componentDidUpdate. React limits " + + "the number of nested updates to prevent infinite loops." + ); + } + } else { + { + if (fiber.tag === ClassComponent) { + warnAboutUpdateOnUnmounted(fiber); } - return; } + return; } - node = node.return; } + node = node.return; } +} - function recalculateCurrentTime() { - // Subtract initial time so it fits inside 32bits - mostRecentCurrentTimeMs = now() - originalStartTimeMs; - mostRecentCurrentTime = msToExpirationTime(mostRecentCurrentTimeMs); - return mostRecentCurrentTime; - } +function recalculateCurrentTime() { + // Subtract initial time so it fits inside 32bits + mostRecentCurrentTimeMs = now() - originalStartTimeMs; + mostRecentCurrentTime = msToExpirationTime(mostRecentCurrentTimeMs); + return mostRecentCurrentTime; +} - function deferredUpdates(fn) { - var previousExpirationContext = expirationContext; - var currentTime = recalculateCurrentTime(); - expirationContext = computeAsyncExpiration(currentTime); - try { - return fn(); - } finally { - expirationContext = previousExpirationContext; - } +function deferredUpdates(fn) { + var previousExpirationContext = expirationContext; + var currentTime = recalculateCurrentTime(); + expirationContext = computeAsyncExpiration(currentTime); + try { + return fn(); + } finally { + expirationContext = previousExpirationContext; } - function syncUpdates(fn, a, b, c, d) { - var previousExpirationContext = expirationContext; - expirationContext = Sync; - try { - return fn(a, b, c, d); - } finally { - expirationContext = previousExpirationContext; - } +} +function syncUpdates(fn, a, b, c, d) { + var previousExpirationContext = expirationContext; + expirationContext = Sync; + try { + return fn(a, b, c, d); + } finally { + expirationContext = previousExpirationContext; } +} - // TODO: Everything below this is written as if it has been lifted to the - // renderers. I'll do this in a follow-up. +// TODO: Everything below this is written as if it has been lifted to the +// renderers. I'll do this in a follow-up. - // Linked-list of roots - var firstScheduledRoot = null; - var lastScheduledRoot = null; +// Linked-list of roots +var firstScheduledRoot = null; +var lastScheduledRoot = null; - var callbackExpirationTime = NoWork; - var callbackID = -1; - var isRendering = false; - var nextFlushedRoot = null; - var nextFlushedExpirationTime = NoWork; - var lowestPendingInteractiveExpirationTime = NoWork; - var deadlineDidExpire = false; - var hasUnhandledError = false; - var unhandledError = null; - var deadline = null; +var callbackExpirationTime = NoWork; +var callbackID = void 0; +var isRendering = false; +var nextFlushedRoot = null; +var nextFlushedExpirationTime = NoWork; +var lowestPendingInteractiveExpirationTime = NoWork; +var deadlineDidExpire = false; +var hasUnhandledError = false; +var unhandledError = null; +var deadline = null; - var isBatchingUpdates = false; - var isUnbatchingUpdates = false; - var isBatchingInteractiveUpdates = false; +var isBatchingUpdates = false; +var isUnbatchingUpdates = false; +var isBatchingInteractiveUpdates = false; - var completedBatches = null; +var completedBatches = null; - // Use these to prevent an infinite loop of nested updates - var NESTED_UPDATE_LIMIT = 1000; - var nestedUpdateCount = 0; +// Use these to prevent an infinite loop of nested updates +var NESTED_UPDATE_LIMIT = 1000; +var nestedUpdateCount = 0; - var timeHeuristicForUnitOfWork = 1; +var timeHeuristicForUnitOfWork = 1; - function scheduleCallbackWithExpiration(expirationTime) { - if (callbackExpirationTime !== NoWork) { - // A callback is already scheduled. Check its expiration time (timeout). - if (expirationTime > callbackExpirationTime) { - // Existing callback has sufficient timeout. Exit. - return; - } else { +function scheduleCallbackWithExpirationTime(expirationTime) { + if (callbackExpirationTime !== NoWork) { + // A callback is already scheduled. Check its expiration time (timeout). + if (expirationTime > callbackExpirationTime) { + // Existing callback has sufficient timeout. Exit. + return; + } else { + if (callbackID !== null) { // Existing callback has insufficient timeout. Cancel and schedule a // new one. cancelDeferredCallback(callbackID); } - // The request callback timer is already running. Don't start a new one. - } else { - startRequestCallbackTimer(); } + // The request callback timer is already running. Don't start a new one. + } else { + startRequestCallbackTimer(); + } - // Compute a timeout for the given expiration time. - var currentMs = now() - originalStartTimeMs; - var expirationMs = expirationTimeToMs(expirationTime); - var timeout = expirationMs - currentMs; + callbackExpirationTime = expirationTime; + var currentMs = now() - originalStartTimeMs; + var expirationTimeMs = expirationTimeToMs(expirationTime); + var timeout = expirationTimeMs - currentMs; + callbackID = scheduleDeferredCallback(performAsyncWork, { timeout: timeout }); +} - callbackExpirationTime = expirationTime; - callbackID = scheduleDeferredCallback(performAsyncWork, { - timeout: timeout - }); - } +// For every call to renderRoot, one of onFatal, onComplete, onSuspend, and +// onYield is called upon exiting. We use these in lieu of returning a tuple. +// I've also chosen not to inline them into renderRoot because these will +// eventually be lifted into the renderer. +function onFatal(root) { + root.finishedWork = null; +} - function requestRetry(root, expirationTime) { - if ( - root.remainingExpirationTime === NoWork || - root.remainingExpirationTime < expirationTime - ) { - // For a retry, only update the remaining expiration time if it has a - // *lower priority* than the existing value. This is because, on a retry, - // we should attempt to coalesce as much as possible. - requestWork(root, expirationTime); - } +function onComplete(root, finishedWork, expirationTime) { + root.pendingCommitExpirationTime = expirationTime; + root.finishedWork = finishedWork; +} + +function onSuspend(root, suspendedExpirationTime, expirationTime, timeoutMs) { + if (timeoutMs >= 0) { + var suspendedRoot = root; + setTimeout(function() { + retrySuspendedRoot(suspendedRoot, suspendedExpirationTime); + }, timeoutMs); } + root.expirationTime = expirationTime; +} - // requestWork is called by the scheduler whenever a root receives an update. - // It's up to the renderer to call renderRoot at some point in the future. - function requestWork(root, expirationTime) { - addRootToSchedule(root, expirationTime); +function onYield(root) { + root.finishedWork = null; +} - if (isRendering) { - // Prevent reentrancy. Remaining work will be scheduled at the end of - // the currently rendering batch. - return; - } +function onCommit(root, expirationTime) { + root.expirationTime = expirationTime; + root.finishedWork = null; +} - if (isBatchingUpdates) { - // Flush work at the end of the batch. - if (isUnbatchingUpdates) { - // ...unless we're inside unbatchedUpdates, in which case we should - // flush it now. - nextFlushedRoot = root; - nextFlushedExpirationTime = Sync; - performWorkOnRoot(root, Sync, false); - } - return; - } +// requestWork is called by the scheduler whenever a root receives an update. +// It's up to the renderer to call renderRoot at some point in the future. +function requestWork(root, expirationTime) { + addRootToSchedule(root, expirationTime); - // TODO: Get rid of Sync and use current time? - if (expirationTime === Sync) { - performSyncWork(); - } else { - scheduleCallbackWithExpiration(expirationTime); - } + if (isRendering) { + // Prevent reentrancy. Remaining work will be scheduled at the end of + // the currently rendering batch. + return; } - function addRootToSchedule(root, expirationTime) { - // Add the root to the schedule. - // Check if this root is already part of the schedule. - if (root.nextScheduledRoot === null) { - // This root is not already scheduled. Add it. - root.remainingExpirationTime = expirationTime; - if (lastScheduledRoot === null) { - firstScheduledRoot = lastScheduledRoot = root; - root.nextScheduledRoot = root; - } else { - lastScheduledRoot.nextScheduledRoot = root; - lastScheduledRoot = root; - lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; - } - } else { - // This root is already scheduled, but its priority may have increased. - var remainingExpirationTime = root.remainingExpirationTime; - if ( - remainingExpirationTime === NoWork || - expirationTime < remainingExpirationTime - ) { - // Update the priority. - root.remainingExpirationTime = expirationTime; - } + if (isBatchingUpdates) { + // Flush work at the end of the batch. + if (isUnbatchingUpdates) { + // ...unless we're inside unbatchedUpdates, in which case we should + // flush it now. + nextFlushedRoot = root; + nextFlushedExpirationTime = Sync; + performWorkOnRoot(root, Sync, false); } + return; } - function findHighestPriorityRoot() { - var highestPriorityWork = NoWork; - var highestPriorityRoot = null; - if (lastScheduledRoot !== null) { - var previousScheduledRoot = lastScheduledRoot; - var root = firstScheduledRoot; - while (root !== null) { - var remainingExpirationTime = root.remainingExpirationTime; - if (remainingExpirationTime === NoWork) { - // This root no longer has work. Remove it from the scheduler. + // TODO: Get rid of Sync and use current time? + if (expirationTime === Sync) { + performSyncWork(); + } else { + scheduleCallbackWithExpirationTime(expirationTime); + } +} - // TODO: This check is redudant, but Flow is confused by the branch - // below where we set lastScheduledRoot to null, even though we break - // from the loop right after. - invariant( - previousScheduledRoot !== null && lastScheduledRoot !== null, - "Should have a previous and last root. This error is likely " + - "caused by a bug in React. Please file an issue." - ); - if (root === root.nextScheduledRoot) { - // This is the only root in the list. - root.nextScheduledRoot = null; - firstScheduledRoot = lastScheduledRoot = null; - break; - } else if (root === firstScheduledRoot) { - // This is the first root in the list. - var next = root.nextScheduledRoot; - firstScheduledRoot = next; - lastScheduledRoot.nextScheduledRoot = next; - root.nextScheduledRoot = null; - } else if (root === lastScheduledRoot) { - // This is the last root in the list. - lastScheduledRoot = previousScheduledRoot; - lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; - root.nextScheduledRoot = null; - break; - } else { - previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot; - root.nextScheduledRoot = null; - } - root = previousScheduledRoot.nextScheduledRoot; - } else { - if ( - highestPriorityWork === NoWork || - remainingExpirationTime < highestPriorityWork - ) { - // Update the priority, if it's higher - highestPriorityWork = remainingExpirationTime; - highestPriorityRoot = root; - } - if (root === lastScheduledRoot) { - break; - } - previousScheduledRoot = root; - root = root.nextScheduledRoot; - } - } +function addRootToSchedule(root, expirationTime) { + // Add the root to the schedule. + // Check if this root is already part of the schedule. + if (root.nextScheduledRoot === null) { + // This root is not already scheduled. Add it. + root.expirationTime = expirationTime; + if (lastScheduledRoot === null) { + firstScheduledRoot = lastScheduledRoot = root; + root.nextScheduledRoot = root; + } else { + lastScheduledRoot.nextScheduledRoot = root; + lastScheduledRoot = root; + lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; } - - // If the next root is the same as the previous root, this is a nested - // update. To prevent an infinite loop, increment the nested update count. - var previousFlushedRoot = nextFlushedRoot; + } else { + // This root is already scheduled, but its priority may have increased. + var remainingExpirationTime = root.expirationTime; if ( - previousFlushedRoot !== null && - previousFlushedRoot === highestPriorityRoot && - highestPriorityWork === Sync + remainingExpirationTime === NoWork || + expirationTime < remainingExpirationTime ) { - nestedUpdateCount++; - } else { - // Reset whenever we switch roots. - nestedUpdateCount = 0; + // Update the priority. + root.expirationTime = expirationTime; } - nextFlushedRoot = highestPriorityRoot; - nextFlushedExpirationTime = highestPriorityWork; } +} + +function findHighestPriorityRoot() { + var highestPriorityWork = NoWork; + var highestPriorityRoot = null; + if (lastScheduledRoot !== null) { + var previousScheduledRoot = lastScheduledRoot; + var root = firstScheduledRoot; + while (root !== null) { + var remainingExpirationTime = root.expirationTime; + if (remainingExpirationTime === NoWork) { + // This root no longer has work. Remove it from the scheduler. - function performAsyncWork(dl) { - performWork(NoWork, true, dl); + // TODO: This check is redudant, but Flow is confused by the branch + // below where we set lastScheduledRoot to null, even though we break + // from the loop right after. + invariant( + previousScheduledRoot !== null && lastScheduledRoot !== null, + "Should have a previous and last root. This error is likely " + + "caused by a bug in React. Please file an issue." + ); + if (root === root.nextScheduledRoot) { + // This is the only root in the list. + root.nextScheduledRoot = null; + firstScheduledRoot = lastScheduledRoot = null; + break; + } else if (root === firstScheduledRoot) { + // This is the first root in the list. + var next = root.nextScheduledRoot; + firstScheduledRoot = next; + lastScheduledRoot.nextScheduledRoot = next; + root.nextScheduledRoot = null; + } else if (root === lastScheduledRoot) { + // This is the last root in the list. + lastScheduledRoot = previousScheduledRoot; + lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; + root.nextScheduledRoot = null; + break; + } else { + previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot; + root.nextScheduledRoot = null; + } + root = previousScheduledRoot.nextScheduledRoot; + } else { + if ( + highestPriorityWork === NoWork || + remainingExpirationTime < highestPriorityWork + ) { + // Update the priority, if it's higher + highestPriorityWork = remainingExpirationTime; + highestPriorityRoot = root; + } + if (root === lastScheduledRoot) { + break; + } + previousScheduledRoot = root; + root = root.nextScheduledRoot; + } + } } - function performSyncWork() { - performWork(Sync, false, null); + // If the next root is the same as the previous root, this is a nested + // update. To prevent an infinite loop, increment the nested update count. + var previousFlushedRoot = nextFlushedRoot; + if ( + previousFlushedRoot !== null && + previousFlushedRoot === highestPriorityRoot && + highestPriorityWork === Sync + ) { + nestedUpdateCount++; + } else { + // Reset whenever we switch roots. + nestedUpdateCount = 0; } + nextFlushedRoot = highestPriorityRoot; + nextFlushedExpirationTime = highestPriorityWork; +} - function performWork(minExpirationTime, isAsync, dl) { - deadline = dl; +function performAsyncWork(dl) { + performWork(NoWork, dl); +} - // Keep working on roots until there's no more work, or until the we reach - // the deadline. - findHighestPriorityRoot(); +function performSyncWork() { + performWork(Sync, null); +} - if (enableProfilerTimer) { - resumeActualRenderTimerIfPaused(); - } +function performWork(minExpirationTime, dl) { + deadline = dl; - if (enableUserTimingAPI && deadline !== null) { - var didExpire = nextFlushedExpirationTime < recalculateCurrentTime(); - var timeout = expirationTimeToMs(nextFlushedExpirationTime); - stopRequestCallbackTimer(didExpire, timeout); - } + // Keep working on roots until there's no more work, or until the we reach + // the deadline. + findHighestPriorityRoot(); - if (isAsync) { - while ( - nextFlushedRoot !== null && - nextFlushedExpirationTime !== NoWork && - (minExpirationTime === NoWork || - minExpirationTime >= nextFlushedExpirationTime) && - (!deadlineDidExpire || - recalculateCurrentTime() >= nextFlushedExpirationTime) - ) { - recalculateCurrentTime(); - performWorkOnRoot( - nextFlushedRoot, - nextFlushedExpirationTime, - !deadlineDidExpire - ); - findHighestPriorityRoot(); - } - } else { - while ( - nextFlushedRoot !== null && - nextFlushedExpirationTime !== NoWork && - (minExpirationTime === NoWork || - minExpirationTime >= nextFlushedExpirationTime) - ) { - performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false); - findHighestPriorityRoot(); - } - } + if (enableProfilerTimer) { + resumeActualRenderTimerIfPaused(); + } - // We're done flushing work. Either we ran out of time in this callback, - // or there's no more work left with sufficient priority. + if (enableUserTimingAPI && deadline !== null) { + var didExpire = nextFlushedExpirationTime < recalculateCurrentTime(); + var timeout = expirationTimeToMs(nextFlushedExpirationTime); + stopRequestCallbackTimer(didExpire, timeout); + } - // If we're inside a callback, set this to false since we just completed it. - if (deadline !== null) { - callbackExpirationTime = NoWork; - callbackID = -1; + if (deadline !== null) { + while ( + nextFlushedRoot !== null && + nextFlushedExpirationTime !== NoWork && + (minExpirationTime === NoWork || + minExpirationTime >= nextFlushedExpirationTime) && + (!deadlineDidExpire || + recalculateCurrentTime() >= nextFlushedExpirationTime) + ) { + recalculateCurrentTime(); + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, true); + findHighestPriorityRoot(); } - // If there's work left over, schedule a new callback. - if (nextFlushedExpirationTime !== NoWork) { - scheduleCallbackWithExpiration(nextFlushedExpirationTime); + } else { + while ( + nextFlushedRoot !== null && + nextFlushedExpirationTime !== NoWork && + (minExpirationTime === NoWork || + minExpirationTime >= nextFlushedExpirationTime) + ) { + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false); + findHighestPriorityRoot(); } + } - // Clean-up. - deadline = null; - deadlineDidExpire = false; + // We're done flushing work. Either we ran out of time in this callback, + // or there's no more work left with sufficient priority. - finishRendering(); + // If we're inside a callback, set this to false since we just completed it. + if (deadline !== null) { + callbackExpirationTime = NoWork; + callbackID = null; } - - function flushRoot(root, expirationTime) { - invariant( - !isRendering, - "work.commit(): Cannot commit while already rendering. This likely " + - "means you attempted to commit from inside a lifecycle method." - ); - // 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(); + // If there's work left over, schedule a new callback. + if (nextFlushedExpirationTime !== NoWork) { + scheduleCallbackWithExpirationTime(nextFlushedExpirationTime); } - function finishRendering() { - nestedUpdateCount = 0; + // Clean-up. + deadline = null; + deadlineDidExpire = false; - if (completedBatches !== null) { - var batches = completedBatches; - completedBatches = null; - for (var i = 0; i < batches.length; i++) { - var batch = batches[i]; - try { - batch._onComplete(); - } catch (error) { - if (!hasUnhandledError) { - hasUnhandledError = true; - unhandledError = error; - } + finishRendering(); +} + +function flushRoot(root, expirationTime) { + invariant( + !isRendering, + "work.commit(): Cannot commit while already rendering. This likely " + + "means you attempted to commit from inside a lifecycle method." + ); + // 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(); +} + +function finishRendering() { + nestedUpdateCount = 0; + + if (completedBatches !== null) { + var batches = completedBatches; + completedBatches = null; + for (var i = 0; i < batches.length; i++) { + var batch = batches[i]; + try { + batch._onComplete(); + } catch (error) { + if (!hasUnhandledError) { + hasUnhandledError = true; + unhandledError = error; } } } + } - if (hasUnhandledError) { - var error = unhandledError; - unhandledError = null; - hasUnhandledError = false; - throw error; - } + if (hasUnhandledError) { + var error = unhandledError; + unhandledError = null; + hasUnhandledError = false; + throw error; } +} - function performWorkOnRoot(root, expirationTime, isAsync) { - invariant( - !isRendering, - "performWorkOnRoot was called recursively. This error is likely caused " + - "by a bug in React. Please file an issue." - ); +function performWorkOnRoot(root, expirationTime, isYieldy) { + invariant( + !isRendering, + "performWorkOnRoot was called recursively. This error is likely caused " + + "by a bug in React. Please file an issue." + ); - isRendering = true; + isRendering = true; - // Check if this is async work or sync/expired work. - if (!isAsync) { - // Flush sync work. - var finishedWork = root.finishedWork; + // Check if this is async work or sync/expired work. + if (!isYieldy) { + // Flush work without yielding. + var finishedWork = root.finishedWork; + if (finishedWork !== null) { + // This root is already complete. We can commit it. + completeRoot$1(root, finishedWork, expirationTime); + } else { + root.finishedWork = null; + renderRoot(root, false); + finishedWork = root.finishedWork; if (finishedWork !== null) { - // This root is already complete. We can commit it. - completeRoot$$1(root, finishedWork, expirationTime); - } else { - root.finishedWork = null; - finishedWork = renderRoot(root, expirationTime, false); - if (finishedWork !== null) { - // We've completed the root. Commit it. - completeRoot$$1(root, finishedWork, expirationTime); - } + // We've completed the root. Commit it. + completeRoot$1(root, finishedWork, expirationTime); } + } + } else { + // Flush async work. + var _finishedWork = root.finishedWork; + if (_finishedWork !== null) { + // This root is already complete. We can commit it. + completeRoot$1(root, _finishedWork, expirationTime); } else { - // Flush async work. - var _finishedWork = root.finishedWork; - if (_finishedWork !== null) { - // This root is already complete. We can commit it. - completeRoot$$1(root, _finishedWork, expirationTime); - } else { - root.finishedWork = null; - _finishedWork = renderRoot(root, expirationTime, true); - if (_finishedWork !== null) { - // We've completed the root. Check the deadline one more time - // before committing. - if (!shouldYield()) { - // Still time left. Commit the root. - completeRoot$$1(root, _finishedWork, expirationTime); - } else { - // There's no time left. Mark this root as complete. We'll come - // back and commit it later. - root.finishedWork = _finishedWork; - - if (enableProfilerTimer) { - // If we didn't finish, pause the "actual" render timer. - // We'll restart it when we resume work. - pauseActualRenderTimerIfRunning(); - } + root.finishedWork = null; + renderRoot(root, true); + _finishedWork = root.finishedWork; + if (_finishedWork !== null) { + // We've completed the root. Check the deadline one more time + // before committing. + if (!shouldYield()) { + // Still time left. Commit the root. + completeRoot$1(root, _finishedWork, expirationTime); + } else { + // There's no time left. Mark this root as complete. We'll come + // back and commit it later. + root.finishedWork = _finishedWork; + + if (enableProfilerTimer) { + // If we didn't finish, pause the "actual" render timer. + // We'll restart it when we resume work. + pauseActualRenderTimerIfRunning(); } } } } - - isRendering = false; } - function completeRoot$$1(root, finishedWork, expirationTime) { - // Check if there's a batch that matches this expiration time. - var firstBatch = root.firstBatch; - if (firstBatch !== null && firstBatch._expirationTime <= expirationTime) { - if (completedBatches === null) { - completedBatches = [firstBatch]; - } else { - completedBatches.push(firstBatch); - } - if (firstBatch._defer) { - // This root is blocked from committing by a batch. Unschedule it until - // we receive another update. - root.finishedWork = finishedWork; - root.remainingExpirationTime = NoWork; - return; - } - } - - // Commit the root. - root.finishedWork = null; - root.remainingExpirationTime = commitRoot(finishedWork); - } + isRendering = false; +} - // When working on async work, the reconciler asks the renderer if it should - // yield execution. For DOM, we implement this with requestIdleCallback. - function shouldYield() { - if (deadline === null) { - return false; +function completeRoot$1(root, finishedWork, expirationTime) { + // Check if there's a batch that matches this expiration time. + var firstBatch = root.firstBatch; + if (firstBatch !== null && firstBatch._expirationTime <= expirationTime) { + if (completedBatches === null) { + completedBatches = [firstBatch]; + } else { + completedBatches.push(firstBatch); } - if (deadline.timeRemaining() > timeHeuristicForUnitOfWork) { - // Disregard deadline.didTimeout. Only expired work should be flushed - // during a timeout. This path is only hit for non-expired work. - return false; + if (firstBatch._defer) { + // This root is blocked from committing by a batch. Unschedule it until + // we receive another update. + root.finishedWork = finishedWork; + root.expirationTime = NoWork; + return; } - deadlineDidExpire = true; - return true; } - function onUncaughtError(error) { - invariant( - nextFlushedRoot !== null, - "Should be working on a root. This error is likely caused by a bug in " + - "React. Please file an issue." - ); - // Unschedule this root so we don't work on it again until there's - // another update. - nextFlushedRoot.remainingExpirationTime = NoWork; - if (!hasUnhandledError) { - hasUnhandledError = true; - unhandledError = error; - } - } + // Commit the root. + root.finishedWork = null; + commitRoot(root, finishedWork); +} - function onBlock(remainingExpirationTime) { - invariant( - nextFlushedRoot !== null, - "Should be working on a root. This error is likely caused by a bug in " + - "React. Please file an issue." - ); - // This root was blocked. Unschedule it until there's another update. - nextFlushedRoot.remainingExpirationTime = remainingExpirationTime; +// When working on async work, the reconciler asks the renderer if it should +// yield execution. For DOM, we implement this with requestIdleCallback. +function shouldYield() { + if (deadline === null || deadlineDidExpire) { + return false; } - - // TODO: Batching should be implemented at the renderer level, not inside - // the reconciler. - function batchedUpdates(fn, a) { - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = true; - try { - return fn(a); - } finally { - isBatchingUpdates = previousIsBatchingUpdates; - if (!isBatchingUpdates && !isRendering) { - performSyncWork(); - } - } + if (deadline.timeRemaining() > timeHeuristicForUnitOfWork) { + // Disregard deadline.didTimeout. Only expired work should be flushed + // during a timeout. This path is only hit for non-expired work. + return false; } + deadlineDidExpire = true; + return true; +} - // TODO: Batching should be implemented at the renderer level, not inside - // the reconciler. - function unbatchedUpdates(fn, a) { - if (isBatchingUpdates && !isUnbatchingUpdates) { - isUnbatchingUpdates = true; - try { - return fn(a); - } finally { - isUnbatchingUpdates = false; - } - } - return fn(a); +function onUncaughtError(error) { + invariant( + nextFlushedRoot !== null, + "Should be working on a root. This error is likely caused by a bug in " + + "React. Please file an issue." + ); + // Unschedule this root so we don't work on it again until there's + // another update. + nextFlushedRoot.expirationTime = NoWork; + if (!hasUnhandledError) { + hasUnhandledError = true; + unhandledError = error; } +} - // TODO: Batching should be implemented at the renderer level, not within - // the reconciler. - function flushSync(fn, a) { - invariant( - !isRendering, - "flushSync was called from inside a lifecycle method. It cannot be " + - "called when React is already rendering." - ); - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = true; - try { - return syncUpdates(fn, a); - } finally { - isBatchingUpdates = previousIsBatchingUpdates; +// TODO: Batching should be implemented at the renderer level, not inside +// the reconciler. +function batchedUpdates$1(fn, a) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = true; + try { + return fn(a); + } finally { + isBatchingUpdates = previousIsBatchingUpdates; + if (!isBatchingUpdates && !isRendering) { performSyncWork(); } } +} - function interactiveUpdates(fn, a, b) { - if (isBatchingInteractiveUpdates) { - return fn(a, b); - } - // If there are any pending interactive updates, synchronously flush them. - // This needs to happen before we read any handlers, because the effect of - // the previous event may influence which handlers are called during - // this event. - if ( - !isBatchingUpdates && - !isRendering && - lowestPendingInteractiveExpirationTime !== NoWork - ) { - // Synchronously flush pending interactive updates. - performWork(lowestPendingInteractiveExpirationTime, false, null); - lowestPendingInteractiveExpirationTime = NoWork; - } - var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates; - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingInteractiveUpdates = true; - isBatchingUpdates = true; +// TODO: Batching should be implemented at the renderer level, not inside +// the reconciler. +function unbatchedUpdates(fn, a) { + if (isBatchingUpdates && !isUnbatchingUpdates) { + isUnbatchingUpdates = true; try { - return fn(a, b); + return fn(a); } finally { - isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates; - isBatchingUpdates = previousIsBatchingUpdates; - if (!isBatchingUpdates && !isRendering) { - performSyncWork(); - } + isUnbatchingUpdates = false; } } + return fn(a); +} + +// TODO: Batching should be implemented at the renderer level, not within +// the reconciler. +function flushSync(fn, a) { + invariant( + !isRendering, + "flushSync was called from inside a lifecycle method. It cannot be " + + "called when React is already rendering." + ); + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = true; + try { + return syncUpdates(fn, a); + } finally { + isBatchingUpdates = previousIsBatchingUpdates; + performSyncWork(); + } +} - function flushInteractiveUpdates() { - if (!isRendering && lowestPendingInteractiveExpirationTime !== NoWork) { - // Synchronously flush pending interactive updates. - performWork(lowestPendingInteractiveExpirationTime, false, null); - lowestPendingInteractiveExpirationTime = NoWork; +function interactiveUpdates$1(fn, a, b) { + if (isBatchingInteractiveUpdates) { + return fn(a, b); + } + // If there are any pending interactive updates, synchronously flush them. + // This needs to happen before we read any handlers, because the effect of + // the previous event may influence which handlers are called during + // this event. + if ( + !isBatchingUpdates && + !isRendering && + lowestPendingInteractiveExpirationTime !== NoWork + ) { + // Synchronously flush pending interactive updates. + performWork(lowestPendingInteractiveExpirationTime, null); + lowestPendingInteractiveExpirationTime = NoWork; + } + var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates; + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingInteractiveUpdates = true; + isBatchingUpdates = true; + try { + return fn(a, b); + } finally { + isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates; + isBatchingUpdates = previousIsBatchingUpdates; + if (!isBatchingUpdates && !isRendering) { + performSyncWork(); } } +} - function flushControlled(fn) { - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = true; - try { - syncUpdates(fn); - } finally { - isBatchingUpdates = previousIsBatchingUpdates; - if (!isBatchingUpdates && !isRendering) { - performWork(Sync, false, null); - } +function flushInteractiveUpdates$1() { + if (!isRendering && lowestPendingInteractiveExpirationTime !== NoWork) { + // Synchronously flush pending interactive updates. + performWork(lowestPendingInteractiveExpirationTime, null); + lowestPendingInteractiveExpirationTime = NoWork; + } +} + +function flushControlled(fn) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = true; + try { + syncUpdates(fn); + } finally { + isBatchingUpdates = previousIsBatchingUpdates; + if (!isBatchingUpdates && !isRendering) { + performWork(Sync, null); } } +} - return { - recalculateCurrentTime: recalculateCurrentTime, - computeExpirationForFiber: computeExpirationForFiber, - scheduleWork: scheduleWork, - requestWork: requestWork, - flushRoot: flushRoot, - batchedUpdates: batchedUpdates, - unbatchedUpdates: unbatchedUpdates, - flushSync: flushSync, - flushControlled: flushControlled, - deferredUpdates: deferredUpdates, - syncUpdates: syncUpdates, - interactiveUpdates: interactiveUpdates, - flushInteractiveUpdates: flushInteractiveUpdates, - computeUniqueAsyncExpiration: computeUniqueAsyncExpiration, - legacyContext: legacyContext - }; -}; +// 0 is PROD, 1 is DEV. +// Might add PROFILE later. var didWarnAboutNestedUpdates = void 0; @@ -14152,318 +13854,407 @@ var didWarnAboutNestedUpdates = void 0; didWarnAboutNestedUpdates = false; } -// 0 is PROD, 1 is DEV. -// Might add PROFILE later. +function getContextForSubtree(parentComponent) { + if (!parentComponent) { + return emptyObject; + } -var ReactFiberReconciler$1 = function(config) { - var getPublicInstance = config.getPublicInstance; - - var _ReactFiberScheduler = ReactFiberScheduler(config), - computeUniqueAsyncExpiration = - _ReactFiberScheduler.computeUniqueAsyncExpiration, - recalculateCurrentTime = _ReactFiberScheduler.recalculateCurrentTime, - computeExpirationForFiber = _ReactFiberScheduler.computeExpirationForFiber, - scheduleWork = _ReactFiberScheduler.scheduleWork, - requestWork = _ReactFiberScheduler.requestWork, - flushRoot = _ReactFiberScheduler.flushRoot, - batchedUpdates = _ReactFiberScheduler.batchedUpdates, - unbatchedUpdates = _ReactFiberScheduler.unbatchedUpdates, - flushSync = _ReactFiberScheduler.flushSync, - flushControlled = _ReactFiberScheduler.flushControlled, - 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$1(parentComponent); - var parentContext = findCurrentUnmaskedContext(fiber); - return isContextProvider(fiber) - ? processChildContext(fiber, parentContext) - : parentContext; - } - - function scheduleRootUpdate(current, element, expirationTime, callback) { - { - if ( - ReactDebugCurrentFiber.phase === "render" && - ReactDebugCurrentFiber.current !== null && - !didWarnAboutNestedUpdates - ) { - didWarnAboutNestedUpdates = true; - warning( + var fiber = get$1(parentComponent); + var parentContext = findCurrentUnmaskedContext(fiber); + return isContextProvider(fiber) + ? processChildContext(fiber, parentContext) + : parentContext; +} + +function scheduleRootUpdate(current, element, expirationTime, callback) { + { + if ( + ReactDebugCurrentFiber.phase === "render" && + ReactDebugCurrentFiber.current !== null && + !didWarnAboutNestedUpdates + ) { + didWarnAboutNestedUpdates = true; + warning( + false, + "Render methods should be a pure function of props and state; " + + "triggering nested component updates from render is not allowed. " + + "If necessary, trigger nested updates in componentDidUpdate.\n\n" + + "Check the render method of %s.", + getComponentName(ReactDebugCurrentFiber.current) || "Unknown" + ); + } + } + + var update = createUpdate(expirationTime); + // Caution: React DevTools currently depends on this property + // being called "element". + update.payload = { element: element }; + + callback = callback === undefined ? null : callback; + if (callback !== null) { + !(typeof callback === "function") + ? warning( false, - "Render methods should be a pure function of props and state; " + - "triggering nested component updates from render is not allowed. " + - "If necessary, trigger nested updates in componentDidUpdate.\n\n" + - "Check the render method of %s.", - getComponentName(ReactDebugCurrentFiber.current) || "Unknown" - ); + "render(...): Expected the last optional `callback` argument to be a " + + "function. Instead received: %s.", + callback + ) + : void 0; + update.callback = callback; + } + enqueueUpdate(current, update, expirationTime); + + scheduleWork(current, expirationTime); + return expirationTime; +} + +function updateContainerAtExpirationTime( + element, + container, + parentComponent, + expirationTime, + callback +) { + // TODO: If this is a nested container, this won't be the root. + var current = container.current; + + { + if (ReactFiberInstrumentation_1.debugTool) { + if (current.alternate === null) { + ReactFiberInstrumentation_1.debugTool.onMountContainer(container); + } else if (element === null) { + ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container); + } else { + ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container); } } + } - var update = createUpdate(expirationTime); - // Caution: React DevTools currently depends on this property - // being called "element". - update.payload = { element: element }; + var context = getContextForSubtree(parentComponent); + if (container.context === null) { + container.context = context; + } else { + container.pendingContext = context; + } - callback = callback === undefined ? null : callback; - if (callback !== null) { - !(typeof callback === "function") - ? warning( - false, - "render(...): Expected the last optional `callback` argument to be a " + - "function. Instead received: %s.", - callback - ) - : void 0; - update.callback = callback; - } - enqueueUpdate(current, update, expirationTime); + return scheduleRootUpdate(current, element, expirationTime, callback); +} - scheduleWork(current, expirationTime); - return expirationTime; +function findHostInstance$1(component) { + var fiber = get$1(component); + if (fiber === undefined) { + if (typeof component.render === "function") { + invariant(false, "Unable to find node on an unmounted component."); + } else { + invariant( + false, + "Argument appears to not be a ReactComponent. Keys: %s", + Object.keys(component) + ); + } + } + var hostFiber = findCurrentHostFiber(fiber); + if (hostFiber === null) { + return null; } + return hostFiber.stateNode; +} + +function createContainer(containerInfo, isAsync, hydrate) { + return createFiberRoot(containerInfo, isAsync, hydrate); +} - function updateContainerAtExpirationTime( +function updateContainer(element, container, parentComponent, callback) { + var current = container.current; + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, current); + return updateContainerAtExpirationTime( element, container, parentComponent, expirationTime, callback - ) { - // TODO: If this is a nested container, this won't be the root. - var current = container.current; - - { - if (ReactFiberInstrumentation_1.debugTool) { - if (current.alternate === null) { - ReactFiberInstrumentation_1.debugTool.onMountContainer(container); - } else if (element === null) { - ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container); - } else { - ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container); - } - } - } + ); +} - var context = getContextForSubtree(parentComponent); - if (container.context === null) { - container.context = context; - } else { - container.pendingContext = context; - } +function getPublicRootInstance(container) { + var containerFiber = container.current; + if (!containerFiber.child) { + return null; + } + switch (containerFiber.child.tag) { + case HostComponent: + return getPublicInstance(containerFiber.child.stateNode); + default: + return containerFiber.child.stateNode; + } +} - return scheduleRootUpdate(current, element, expirationTime, callback); +function findHostInstanceWithNoPortals(fiber) { + var hostFiber = findCurrentHostFiberWithNoPortals(fiber); + if (hostFiber === null) { + return null; } + return hostFiber.stateNode; +} - function findHostInstance(component) { - var fiber = get$1(component); - if (fiber === undefined) { - if (typeof component.render === "function") { - invariant(false, "Unable to find node on an unmounted component."); - } else { - invariant( - false, - "Argument appears to not be a ReactComponent. Keys: %s", - Object.keys(component) - ); +function injectIntoDevTools(devToolsConfig) { + var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; + + return injectInternals( + Object.assign({}, devToolsConfig, { + findHostInstanceByFiber: function(fiber) { + var hostFiber = findCurrentHostFiber(fiber); + if (hostFiber === null) { + return null; + } + return hostFiber.stateNode; + }, + findFiberByHostInstance: function(instance) { + if (!findFiberByHostInstance) { + // Might not be implemented by the renderer. + return null; + } + return findFiberByHostInstance(instance); } - } - var hostFiber = findCurrentHostFiber(fiber); - if (hostFiber === null) { - return null; - } - return hostFiber.stateNode; - } + }) + ); +} + +// This file intentionally does *not* have the Flow annotation. +// Don't add it. See `./inline-typed.js` for an explanation. + +var ReactFabricRenderer = Object.freeze({ + updateContainerAtExpirationTime: updateContainerAtExpirationTime, + createContainer: createContainer, + updateContainer: updateContainer, + flushRoot: flushRoot, + requestWork: requestWork, + computeUniqueAsyncExpiration: computeUniqueAsyncExpiration, + batchedUpdates: batchedUpdates$1, + unbatchedUpdates: unbatchedUpdates, + deferredUpdates: deferredUpdates, + syncUpdates: syncUpdates, + interactiveUpdates: interactiveUpdates$1, + flushInteractiveUpdates: flushInteractiveUpdates$1, + flushControlled: flushControlled, + flushSync: flushSync, + getPublicRootInstance: getPublicRootInstance, + findHostInstance: findHostInstance$1, + findHostInstanceWithNoPortals: findHostInstanceWithNoPortals, + injectIntoDevTools: injectIntoDevTools +}); + +function createPortal( + children, + containerInfo, + // TODO: figure out the API for cross-renderer implementation. + implementation +) { + var key = + arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; return { - createContainer: function(containerInfo, isAsync, hydrate) { - return createFiberRoot(containerInfo, isAsync, hydrate); + // This tag allow us to uniquely identify this as a React Portal + $$typeof: REACT_PORTAL_TYPE, + key: key == null ? null : "" + key, + children: children, + containerInfo: containerInfo, + implementation: implementation + }; +} + +// TODO: this is special because it gets imported during build. + +var ReactVersion = "16.4.1"; + +// Modules provided by RN: +var NativeMethodsMixin = function(findNodeHandle, findHostInstance) { + /** + * `NativeMethodsMixin` provides methods to access the underlying native + * component directly. This can be useful in cases when you want to focus + * a view or measure its on-screen dimensions, for example. + * + * The methods described here are available on most of the default components + * provided by React Native. Note, however, that they are *not* available on + * composite components that aren't directly backed by a native view. This will + * generally include most components that you define in your own app. For more + * information, see [Direct + * Manipulation](docs/direct-manipulation.html). + * + * Note the Flow $Exact<> syntax is required to support mixins. + * React createClass mixins can only be used with exact types. + */ + var NativeMethodsMixin = { + /** + * Determines the location on screen, width, and height of the given view and + * returns the values via an async callback. If successful, the callback will + * be called with the following arguments: + * + * - x + * - y + * - width + * - height + * - pageX + * - pageY + * + * Note that these measurements are not available until after the rendering + * has been completed in native. If you need the measurements as soon as + * possible, consider using the [`onLayout` + * prop](docs/view.html#onlayout) instead. + */ + measure: function(callback) { + UIManager.measure( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); }, - updateContainer: function(element, container, parentComponent, callback) { - var current = container.current; - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, current); - return updateContainerAtExpirationTime( - element, - container, - parentComponent, - expirationTime, - callback + + /** + * Determines the location of the given view in the window and returns the + * values via an async callback. If the React root view is embedded in + * another native view, this will give you the absolute coordinates. If + * successful, the callback will be called with the following + * arguments: + * + * - x + * - y + * - width + * - height + * + * Note that these measurements are not available until after the rendering + * has been completed in native. + */ + measureInWindow: function(callback) { + UIManager.measureInWindow( + findNodeHandle(this), + mountSafeCallback(this, callback) ); }, - updateContainerAtExpirationTime: function( - element, - container, - parentComponent, - expirationTime, - callback + + /** + * Like [`measure()`](#measure), but measures the view relative an ancestor, + * specified as `relativeToNativeNode`. This means that the returned x, y + * are relative to the origin x, y of the ancestor view. + * + * As always, to obtain a native node handle for a component, you can use + * `findNodeHandle(component)`. + */ + measureLayout: function( + relativeToNativeNode, + onSuccess, + onFail /* currently unused */ ) { - return updateContainerAtExpirationTime( - element, - container, - parentComponent, - expirationTime, - callback + UIManager.measureLayout( + findNodeHandle(this), + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) ); }, - flushRoot: flushRoot, - - requestWork: requestWork, - - computeUniqueAsyncExpiration: computeUniqueAsyncExpiration, - - batchedUpdates: batchedUpdates, - - unbatchedUpdates: unbatchedUpdates, - - deferredUpdates: deferredUpdates, + /** + * This function sends props straight to native. They will not participate in + * future diff process - this means that if you do not include them in the + * next render, they will remain active (see [Direct + * Manipulation](docs/direct-manipulation.html)). + */ + setNativeProps: function(nativeProps) { + // Class components don't have viewConfig -> validateAttributes. + // Nor does it make sense to set native props on a non-native component. + // Instead, find the nearest host component and set props on it. + // Use findNodeHandle() rather than findNodeHandle() because + // We want the instance/wrapper (not the native tag). + var maybeInstance = void 0; - syncUpdates: syncUpdates, + // Fiber errors if findNodeHandle is called for an umounted component. + // Tests using ReactTestRenderer will trigger this case indirectly. + // Mimicking stack behavior, we should silently ignore this case. + // TODO Fix ReactTestRenderer so we can remove this try/catch. + try { + maybeInstance = findHostInstance(this); + } catch (error) {} - interactiveUpdates: interactiveUpdates, + // If there is no host component beneath this we should fail silently. + // This is not an error; it could mean a class component rendered null. + if (maybeInstance == null) { + return; + } - flushInteractiveUpdates: flushInteractiveUpdates, + var viewConfig = maybeInstance.viewConfig; - flushControlled: flushControlled, + { + warnForStyleProps(nativeProps, viewConfig.validAttributes); + } - flushSync: flushSync, + var updatePayload = create(nativeProps, viewConfig.validAttributes); - getPublicRootInstance: function(container) { - var containerFiber = container.current; - if (!containerFiber.child) { - return null; - } - switch (containerFiber.child.tag) { - case HostComponent: - return getPublicInstance(containerFiber.child.stateNode); - default: - return containerFiber.child.stateNode; + // Avoid the overhead of bridge calls if there's no update. + // This is an expensive no-op for Android, and causes an unnecessary + // view invalidation for certain components (eg RCTTextInput) on iOS. + if (updatePayload != null) { + UIManager.updateView( + maybeInstance._nativeTag, + viewConfig.uiViewClassName, + updatePayload + ); } }, - findHostInstance: findHostInstance, - - findHostInstanceWithNoPortals: function(fiber) { - var hostFiber = findCurrentHostFiberWithNoPortals(fiber); - if (hostFiber === null) { - return null; - } - return hostFiber.stateNode; + /** + * Requests focus for the given input or view. The exact behavior triggered + * will depend on the platform and type of view. + */ + focus: function() { + TextInputState.focusTextInput(findNodeHandle(this)); }, - injectIntoDevTools: function(devToolsConfig) { - var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; - - return injectInternals( - Object.assign({}, devToolsConfig, { - findHostInstanceByFiber: function(fiber) { - var hostFiber = findCurrentHostFiber(fiber); - if (hostFiber === null) { - return null; - } - return hostFiber.stateNode; - }, - findFiberByHostInstance: function(instance) { - if (!findFiberByHostInstance) { - // Might not be implemented by the renderer. - return null; - } - return findFiberByHostInstance(instance); - } - }) - ); + + /** + * Removes focus from an input or view. This is the opposite of `focus()`. + */ + blur: function() { + TextInputState.blurTextInput(findNodeHandle(this)); } }; -}; - -var ReactFiberReconciler$2 = Object.freeze({ - default: ReactFiberReconciler$1 -}); - -var ReactFiberReconciler$3 = - (ReactFiberReconciler$2 && ReactFiberReconciler$1) || ReactFiberReconciler$2; - -// TODO: bundle Flow types with the package. - -// TODO: decide on the top-level export form. -// This is hacky but makes it work with both Rollup and Jest. -var reactReconciler = ReactFiberReconciler$3.default - ? ReactFiberReconciler$3.default - : ReactFiberReconciler$3; -var hasNativePerformanceNow = - typeof performance === "object" && typeof performance.now === "function"; - -var now = hasNativePerformanceNow - ? function() { - return performance.now(); - } - : function() { - return Date.now(); + { + // hide this from Flow since we can't define these properties outside of + // true without actually implementing them (setting them to undefined + // isn't allowed by ReactClass) + var NativeMethodsMixin_DEV = NativeMethodsMixin; + invariant( + !NativeMethodsMixin_DEV.componentWillMount && + !NativeMethodsMixin_DEV.componentWillReceiveProps && + !NativeMethodsMixin_DEV.UNSAFE_componentWillMount && + !NativeMethodsMixin_DEV.UNSAFE_componentWillReceiveProps, + "Do not override existing functions." + ); + // TODO (bvaughn) Remove cWM and cWRP in a future version of React Native, + // Once these lifecycles have been remove from the reconciler. + NativeMethodsMixin_DEV.componentWillMount = function() { + throwOnStylesProp(this, this.props); + }; + NativeMethodsMixin_DEV.componentWillReceiveProps = function(newProps) { + throwOnStylesProp(this, newProps); + }; + NativeMethodsMixin_DEV.UNSAFE_componentWillMount = function() { + throwOnStylesProp(this, this.props); + }; + NativeMethodsMixin_DEV.UNSAFE_componentWillReceiveProps = function( + newProps + ) { + throwOnStylesProp(this, newProps); }; -var scheduledCallback = null; -var frameDeadline = 0; - -var frameDeadlineObject = { - timeRemaining: function() { - return frameDeadline - now(); - }, - didTimeout: false -}; - -function setTimeoutCallback() { - // TODO (bvaughn) Hard-coded 5ms unblocks initial async testing. - // React API probably changing to boolean rather than time remaining. - // Longer-term plan is to rewrite this using shared memory, - // And just return the value of the bit as the boolean. - frameDeadline = now() + 5; - - var callback = scheduledCallback; - scheduledCallback = null; - if (callback !== null) { - callback(frameDeadlineObject); + // React may warn about cWM/cWRP/cWU methods being deprecated. + // Add a flag to suppress these warnings for this special case. + // TODO (bvaughn) Remove this flag once the above methods have been removed. + NativeMethodsMixin_DEV.componentWillMount.__suppressDeprecationWarning = true; + NativeMethodsMixin_DEV.componentWillReceiveProps.__suppressDeprecationWarning = true; } -} - -// RN has a poor polyfill for requestIdleCallback so we aren't using it. -// This implementation is only intended for short-term use anyway. -// We also don't implement cancel functionality b'c Fiber doesn't currently need it. -function scheduleDeferredCallback(callback) { - // We assume only one callback is scheduled at a time b'c that's how Fiber works. - scheduledCallback = callback; - return setTimeout(setTimeoutCallback, 1); -} - -function cancelDeferredCallback(callbackID) { - scheduledCallback = null; - clearTimeout(callbackID); -} -function dispatchEvent(target, topLevelType, nativeEvent) { - var targetFiber = target; - batchedUpdates(function() { - runExtractedEventsInBatch( - topLevelType, - targetFiber, - nativeEvent, - nativeEvent.target - ); - }); - // React Native doesn't use ReactControlledComponent but if it did, here's - // where it would do it. -} + return NativeMethodsMixin; +}; function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { @@ -14471,292 +14262,210 @@ function _classCallCheck$1(instance, Constructor) { } } -// Modules provided by RN: -// Counter for uniquely identifying views. -// % 10 === 1 means it is a rootTag. -// % 2 === 0 means it is a Fabric tag. -// This means that they never overlap. -var nextReactTag = 2; - -// TODO: Remove this conditional once all changes have propagated. -if (FabricUIManager.registerEventHandler) { - /** - * Register the event emitter with the native bridge - */ - FabricUIManager.registerEventHandler(dispatchEvent); -} - -/** - * This is used for refs on host components. - */ - -var ReactFabricHostComponent = (function() { - function ReactFabricHostComponent(tag, viewConfig, props) { - _classCallCheck$1(this, ReactFabricHostComponent); - - this._nativeTag = tag; - this.viewConfig = viewConfig; - this.currentProps = props; - } - - ReactFabricHostComponent.prototype.blur = function blur() { - TextInputState.blurTextInput(this._nativeTag); - }; - - ReactFabricHostComponent.prototype.focus = function focus() { - TextInputState.focusTextInput(this._nativeTag); - }; - - ReactFabricHostComponent.prototype.measure = function measure(callback) { - UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); - }; - - ReactFabricHostComponent.prototype.measureInWindow = function measureInWindow( - callback - ) { - UIManager.measureInWindow( - this._nativeTag, - mountSafeCallback(this, callback) +function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError( + "this hasn't been initialised - super() hasn't been called" ); - }; + } + return call && (typeof call === "object" || typeof call === "function") + ? call + : self; +} - ReactFabricHostComponent.prototype.measureLayout = function measureLayout( - relativeToNativeNode, - onSuccess, - onFail /* currently unused */ - ) { - UIManager.measureLayout( - this._nativeTag, - relativeToNativeNode, - mountSafeCallback(this, onFail), - mountSafeCallback(this, onSuccess) +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError( + "Super expression must either be null or a function, not " + + typeof superClass ); - }; - - ReactFabricHostComponent.prototype.setNativeProps = function setNativeProps( - nativeProps - ) { - { - warnForStyleProps(nativeProps, this.viewConfig.validAttributes); + } + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true } + }); + if (superClass) + Object.setPrototypeOf + ? Object.setPrototypeOf(subClass, superClass) + : (subClass.__proto__ = superClass); +} - var updatePayload = create(nativeProps, this.viewConfig.validAttributes); +// Modules provided by RN: +var ReactNativeComponent = function(findNodeHandle, findHostInstance) { + /** + * Superclass that provides methods to access the underlying native component. + * This can be useful when you want to focus a view or measure its dimensions. + * + * Methods implemented by this class are available on most default components + * provided by React Native. However, they are *not* available on composite + * components that are not directly backed by a native view. For more + * information, see [Direct Manipulation](docs/direct-manipulation.html). + * + * @abstract + */ + var ReactNativeComponent = (function(_React$Component) { + _inherits(ReactNativeComponent, _React$Component); - // Avoid the overhead of bridge calls if there's no update. - // This is an expensive no-op for Android, and causes an unnecessary - // view invalidation for certain components (eg RCTTextInput) on iOS. - if (updatePayload != null) { - UIManager.updateView( - this._nativeTag, - this.viewConfig.uiViewClassName, - updatePayload + function ReactNativeComponent() { + _classCallCheck$1(this, ReactNativeComponent); + + return _possibleConstructorReturn( + this, + _React$Component.apply(this, arguments) ); } - }; - - return ReactFabricHostComponent; -})(); -var ReactFabricHostConfig = { - appendInitialChild: function(parentInstance, child) { - FabricUIManager.appendChild(parentInstance.node, child.node); - }, - createInstance: function( - type, - props, - rootContainerInstance, - hostContext, - internalInstanceHandle - ) { - var tag = nextReactTag; - nextReactTag += 2; + /** + * Removes focus. This is the opposite of `focus()`. + */ - var viewConfig = ReactNativeViewConfigRegistry.get(type); + /** + * Due to bugs in Flow's handling of React.createClass, some fields already + * declared in the base class need to be redeclared below. + */ + ReactNativeComponent.prototype.blur = function blur() { + TextInputState.blurTextInput(findNodeHandle(this)); + }; - { - for (var key in viewConfig.validAttributes) { - if (props.hasOwnProperty(key)) { - deepFreezeAndThrowOnMutationInDev(props[key]); - } - } - } + /** + * Requests focus. The exact behavior depends on the platform and view. + */ - invariant( - type !== "RCTView" || !hostContext.isInAParentText, - "Nesting of within is not currently supported." - ); + ReactNativeComponent.prototype.focus = function focus() { + TextInputState.focusTextInput(findNodeHandle(this)); + }; - var updatePayload = create(props, viewConfig.validAttributes); + /** + * Measures the on-screen location and dimensions. If successful, the callback + * will be called asynchronously with the following arguments: + * + * - x + * - y + * - width + * - height + * - pageX + * - pageY + * + * These values are not available until after natives rendering completes. If + * you need the measurements as soon as possible, consider using the + * [`onLayout` prop](docs/view.html#onlayout) instead. + */ - var node = FabricUIManager.createNode( - tag, // reactTag - viewConfig.uiViewClassName, // viewName - rootContainerInstance, // rootTag - updatePayload, // props - internalInstanceHandle // internalInstanceHandle - ); + ReactNativeComponent.prototype.measure = function measure(callback) { + UIManager.measure( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }; - var component = new ReactFabricHostComponent(tag, viewConfig, props); + /** + * Measures the on-screen location and dimensions. Even if the React Native + * root view is embedded within another native view, this method will give you + * the absolute coordinates measured from the window. If successful, the + * callback will be called asynchronously with the following arguments: + * + * - x + * - y + * - width + * - height + * + * These values are not available until after natives rendering completes. + */ - return { - node: node, - canonical: component + ReactNativeComponent.prototype.measureInWindow = function measureInWindow( + callback + ) { + UIManager.measureInWindow( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); }; - }, - createTextInstance: function( - text, - rootContainerInstance, - hostContext, - internalInstanceHandle - ) { - invariant( - hostContext.isInAParentText, - "Text strings must be rendered within a component." - ); - - var tag = nextReactTag; - nextReactTag += 2; - var node = FabricUIManager.createNode( - tag, // reactTag - "RCTRawText", // viewName - rootContainerInstance, // rootTag - { text: text }, // props - internalInstanceHandle // instance handle - ); + /** + * Similar to [`measure()`](#measure), but the resulting location will be + * relative to the supplied ancestor's location. + * + * Obtain a native node handle with `ReactNative.findNodeHandle(component)`. + */ - return { - node: node + ReactNativeComponent.prototype.measureLayout = function measureLayout( + relativeToNativeNode, + onSuccess, + onFail /* currently unused */ + ) { + UIManager.measureLayout( + findNodeHandle(this), + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); }; - }, - finalizeInitialChildren: function( - parentInstance, - type, - props, - rootContainerInstance - ) { - return false; - }, - getRootHostContext: function(rootContainerInstance) { - return { isInAParentText: false }; - }, - getChildHostContext: function(parentHostContext, type) { - var prevIsInAParentText = parentHostContext.isInAParentText; - var isInAParentText = - type === "AndroidTextInput" || // Android - type === "RCTMultilineTextInputView" || // iOS - type === "RCTSinglelineTextInputView" || // iOS - type === "RCTText" || - type === "RCTVirtualText"; - - if (prevIsInAParentText !== isInAParentText) { - return { isInAParentText: isInAParentText }; - } else { - return parentHostContext; - } - }, - getPublicInstance: function(instance) { - return instance.canonical; - }, - now: now, + /** + * This function sends props straight to native. They will not participate in + * future diff process - this means that if you do not include them in the + * next render, they will remain active (see [Direct + * Manipulation](docs/direct-manipulation.html)). + */ - // The Fabric renderer is secondary to the existing React Native renderer. - isPrimaryRenderer: false, + ReactNativeComponent.prototype.setNativeProps = function setNativeProps( + nativeProps + ) { + // Class components don't have viewConfig -> validateAttributes. + // Nor does it make sense to set native props on a non-native component. + // Instead, find the nearest host component and set props on it. + // Use findNodeHandle() rather than ReactNative.findNodeHandle() because + // We want the instance/wrapper (not the native tag). + var maybeInstance = void 0; - prepareForCommit: function() { - // Noop - }, - prepareUpdate: function( - instance, - type, - oldProps, - newProps, - rootContainerInstance, - hostContext - ) { - var viewConfig = instance.canonical.viewConfig; - var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); - // TODO: If the event handlers have changed, we need to update the current props - // in the commit phase but there is no host config hook to do it yet. - return updatePayload; - }, - resetAfterCommit: function() { - // Noop - }, + // Fiber errors if findNodeHandle is called for an umounted component. + // Tests using ReactTestRenderer will trigger this case indirectly. + // Mimicking stack behavior, we should silently ignore this case. + // TODO Fix ReactTestRenderer so we can remove this try/catch. + try { + maybeInstance = findHostInstance(this); + } catch (error) {} - scheduleDeferredCallback: scheduleDeferredCallback, - cancelDeferredCallback: cancelDeferredCallback, + // If there is no host component beneath this we should fail silently. + // This is not an error; it could mean a class component rendered null. + if (maybeInstance == null) { + return; + } - shouldDeprioritizeSubtree: function(type, props) { - return false; - }, - shouldSetTextContent: function(type, props) { - // TODO (bvaughn) Revisit this decision. - // Always returning false simplifies the createInstance() implementation, - // But creates an additional child Fiber for raw text children. - // No additional native views are created though. - // It's not clear to me which is better so I'm deferring for now. - // More context @ github.com/facebook/react/pull/8560#discussion_r92111303 - return false; - }, + var viewConfig = + maybeInstance.viewConfig || maybeInstance.canonical.viewConfig; - persistence: { - cloneInstance: function( - instance, - updatePayload, - type, - oldProps, - newProps, - internalInstanceHandle, - keepChildren, - recyclableInstance - ) { - var node = instance.node; - var clone = void 0; - if (keepChildren) { - if (updatePayload !== null) { - clone = FabricUIManager.cloneNodeWithNewProps( - node, - updatePayload, - internalInstanceHandle - ); - } else { - clone = FabricUIManager.cloneNode(node, internalInstanceHandle); - } - } else { - if (updatePayload !== null) { - clone = FabricUIManager.cloneNodeWithNewChildrenAndProps( - node, - updatePayload, - internalInstanceHandle - ); - } else { - clone = FabricUIManager.cloneNodeWithNewChildren( - node, - internalInstanceHandle - ); - } + var updatePayload = create(nativeProps, viewConfig.validAttributes); + + // Avoid the overhead of bridge calls if there's no update. + // This is an expensive no-op for Android, and causes an unnecessary + // view invalidation for certain components (eg RCTTextInput) on iOS. + if (updatePayload != null) { + UIManager.updateView( + maybeInstance._nativeTag, + viewConfig.uiViewClassName, + updatePayload + ); } - return { - node: clone, - canonical: instance.canonical - }; - }, - createContainerChildSet: function(container) { - return FabricUIManager.createChildSet(container); - }, - appendChildToContainerChildSet: function(childSet, child) { - FabricUIManager.appendChildToSet(childSet, child.node); - }, - finalizeContainerChildren: function(container, newChildren) { - FabricUIManager.completeRoot(container, newChildren); - }, - replaceContainerChildren: function(container, newChildren) {} - } + }; + + return ReactNativeComponent; + })(React.Component); + + // eslint-disable-next-line no-unused-expressions + + return ReactNativeComponent; }; -var ReactFabricRenderer = reactReconciler(ReactFabricHostConfig); +var instanceCache = {}; + +function getInstanceFromTag(tag) { + return instanceCache[tag] || null; +} // Module provided by RN: var getInspectorDataForViewTag = void 0; @@ -14860,7 +14569,7 @@ var getInspectorDataForViewTag = void 0; }; } -var findHostInstance = ReactFabricRenderer.findHostInstance; +var findHostInstance = findHostInstance$1; function findNodeHandle(componentOrHandle) { { @@ -14898,6 +14607,8 @@ function findNodeHandle(componentOrHandle) { if (hostInstance == null) { return hostInstance; } + // TODO: the code is right but the types here are wrong. + // https://github.com/facebook/react/pull/12863 if (hostInstance.canonical) { // Fabric return hostInstance.canonical._nativeTag; @@ -14920,18 +14631,18 @@ var ReactFabric = { if (!root) { // TODO (bvaughn): If we decide to keep the wrapper component, // We could create a wrapper for containerTag as well to reduce special casing. - root = ReactFabricRenderer.createContainer(containerTag, false, false); + root = createContainer(containerTag, false, false); roots.set(containerTag, root); } - ReactFabricRenderer.updateContainer(element, root, null, callback); + updateContainer(element, root, null, callback); - return ReactFabricRenderer.getPublicRootInstance(root); + return getPublicRootInstance(root); }, unmountComponentAtNode: function(containerTag) { var root = roots.get(containerTag); if (root) { // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred? - ReactFabricRenderer.updateContainer(null, root, null, function() { + updateContainer(null, root, null, function() { roots.delete(containerTag); }); } @@ -14945,14 +14656,12 @@ var ReactFabric = { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: { // Used as a mixin in many createClass-based components - NativeMethodsMixin: NativeMethodsMixin(findNodeHandle, findHostInstance), - // Used by react-native-github/Libraries/ components - ReactNativeComponentTree: ReactNativeComponentTree // ScrollResponder + NativeMethodsMixin: NativeMethodsMixin(findNodeHandle, findHostInstance) } }; -ReactFabricRenderer.injectIntoDevTools({ - findFiberByHostInstance: getInstanceFromTag, +injectIntoDevTools({ + findFiberByHostInstance: getInstanceFromInstance, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 1, version: ReactVersion, diff --git a/Libraries/Renderer/oss/ReactFabric-prod.js b/Libraries/Renderer/oss/ReactFabric-prod.js index 6f17e0bfb3a8ae..b64b8908f410a8 100644 --- a/Libraries/Renderer/oss/ReactFabric-prod.js +++ b/Libraries/Renderer/oss/ReactFabric-prod.js @@ -13,17 +13,15 @@ "use strict"; require("InitializeCore"); var invariant = require("fbjs/lib/invariant"), - emptyFunction = require("fbjs/lib/emptyFunction"), ReactNativeViewConfigRegistry = require("ReactNativeViewConfigRegistry"), UIManager = require("UIManager"), - TextInputState = require("TextInputState"), - deepDiffer = require("deepDiffer"), - flattenStyle = require("flattenStyle"), React = require("react"), emptyObject = require("fbjs/lib/emptyObject"), - shallowEqual = require("fbjs/lib/shallowEqual"), - ExceptionsManager = require("ExceptionsManager"), - FabricUIManager = require("FabricUIManager"); + deepDiffer = require("deepDiffer"), + flattenStyle = require("flattenStyle"), + TextInputState = require("TextInputState"), + FabricUIManager = require("FabricUIManager"), + ExceptionsManager = require("ExceptionsManager"); function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) { this._hasCaughtError = !1; this._caughtError = null; @@ -350,21 +348,14 @@ function accumulateDirectDispatchesSingle(event) { } } var shouldBeReleasedProperties = "dispatchConfig _targetInst nativeEvent isDefaultPrevented isPropagationStopped _dispatchListeners _dispatchInstances".split( - " " - ), - EventInterface = { - type: null, - target: null, - currentTarget: emptyFunction.thatReturnsNull, - eventPhase: null, - bubbles: null, - cancelable: null, - timeStamp: function(event) { - return event.timeStamp || Date.now(); - }, - defaultPrevented: null, - isTrusted: null - }; + " " +); +function functionThatReturnsTrue() { + return !0; +} +function functionThatReturnsFalse() { + return !1; +} function SyntheticEvent( dispatchConfig, targetInst, @@ -385,9 +376,9 @@ function SyntheticEvent( this.isDefaultPrevented = (null != nativeEvent.defaultPrevented ? nativeEvent.defaultPrevented : !1 === nativeEvent.returnValue) - ? emptyFunction.thatReturnsTrue - : emptyFunction.thatReturnsFalse; - this.isPropagationStopped = emptyFunction.thatReturnsFalse; + ? functionThatReturnsTrue + : functionThatReturnsFalse; + this.isPropagationStopped = functionThatReturnsFalse; return this; } Object.assign(SyntheticEvent.prototype, { @@ -398,7 +389,7 @@ Object.assign(SyntheticEvent.prototype, { (event.preventDefault ? event.preventDefault() : "unknown" !== typeof event.returnValue && (event.returnValue = !1), - (this.isDefaultPrevented = emptyFunction.thatReturnsTrue)); + (this.isDefaultPrevented = functionThatReturnsTrue)); }, stopPropagation: function() { var event = this.nativeEvent; @@ -406,12 +397,12 @@ Object.assign(SyntheticEvent.prototype, { (event.stopPropagation ? event.stopPropagation() : "unknown" !== typeof event.cancelBubble && (event.cancelBubble = !0), - (this.isPropagationStopped = emptyFunction.thatReturnsTrue)); + (this.isPropagationStopped = functionThatReturnsTrue)); }, persist: function() { - this.isPersistent = emptyFunction.thatReturnsTrue; + this.isPersistent = functionThatReturnsTrue; }, - isPersistent: emptyFunction.thatReturnsFalse, + isPersistent: functionThatReturnsFalse, destructor: function() { var Interface = this.constructor.Interface, propName; @@ -424,7 +415,21 @@ Object.assign(SyntheticEvent.prototype, { this[shouldBeReleasedProperties[Interface]] = null; } }); -SyntheticEvent.Interface = EventInterface; +SyntheticEvent.Interface = { + type: null, + target: null, + currentTarget: function() { + return null; + }, + eventPhase: null, + bubbles: null, + cancelable: null, + timeStamp: function(event) { + return event.timeStamp || Date.now(); + }, + defaultPrevented: null, + isTrusted: null +}; SyntheticEvent.extend = function(Interface) { function E() {} function Class() { @@ -984,55 +989,47 @@ var eventTypes$1 = { else return null; return topLevelType; } - }, - instanceCache = {}, - instanceProps = {}; -function getInstanceFromTag(tag) { - return "number" === typeof tag ? instanceCache[tag] || null : tag; -} -var ReactNativeComponentTree = Object.freeze({ - precacheFiberNode: function(hostInst, tag) { - instanceCache[tag] = hostInst; - }, - uncacheFiberNode: function(tag) { - delete instanceCache[tag]; - delete instanceProps[tag]; - }, - getClosestInstanceFromNode: getInstanceFromTag, - getInstanceFromNode: getInstanceFromTag, - getNodeFromInstance: function(inst) { - var tag = inst.stateNode._nativeTag; - void 0 === tag && (tag = inst.stateNode.canonical._nativeTag); - invariant(tag, "All native instances should have a tag."); - return tag; - }, - getFiberCurrentPropsFromNode: function(stateNode) { - return instanceProps[stateNode._nativeTag] || null; - }, - updateFiberProps: function(tag, props) { - instanceProps[tag] = props; - } -}); + }; injection.injectEventPluginOrder([ "ResponderEventPlugin", "ReactNativeBridgeEventPlugin" ]); +injection.injectEventPluginsByName({ + ResponderEventPlugin: ResponderEventPlugin, + ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin +}); +function getInstanceFromInstance(instanceHandle) { + return instanceHandle; +} +var Injected$jscomp$inline_574 = { + getClosestInstanceFromNode: getInstanceFromInstance, + getInstanceFromNode: getInstanceFromInstance, + getNodeFromInstance: function(inst) { + inst = inst.stateNode.canonical._nativeTag; + invariant(inst, "All native instances should have a tag."); + return inst; + }, + getFiberCurrentPropsFromNode: function(inst) { + return inst.canonical.currentProps; + } +}; getFiberCurrentPropsFromNode = - ReactNativeComponentTree.getFiberCurrentPropsFromNode; -getInstanceFromNode = ReactNativeComponentTree.getInstanceFromNode; -getNodeFromInstance = ReactNativeComponentTree.getNodeFromInstance; + Injected$jscomp$inline_574.getFiberCurrentPropsFromNode; +getInstanceFromNode = Injected$jscomp$inline_574.getInstanceFromNode; +getNodeFromInstance = Injected$jscomp$inline_574.getNodeFromInstance; ResponderEventPlugin.injection.injectGlobalResponderHandler({ onChange: function(from, to, blockNativeResponder) { null !== to - ? UIManager.setJSResponder(to.stateNode._nativeTag, blockNativeResponder) + ? UIManager.setJSResponder( + to.stateNode.canonical._nativeTag, + blockNativeResponder + ) : UIManager.clearJSResponder(); } }); -injection.injectEventPluginsByName({ - ResponderEventPlugin: ResponderEventPlugin, - ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin -}); -var hasSymbol = "function" === typeof Symbol && Symbol.for, +var ReactCurrentOwner = + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, + hasSymbol = "function" === typeof Symbol && Symbol.for, REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 60103, REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 60106, REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 60107, @@ -1052,53 +1049,175 @@ function getIteratorFn(maybeIterable) { maybeIterable["@@iterator"]; return "function" === typeof maybeIterable ? maybeIterable : null; } -function createPortal(children, containerInfo, implementation) { - var key = - 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null; - return { - $$typeof: REACT_PORTAL_TYPE, - key: null == key ? null : "" + key, - children: children, - containerInfo: containerInfo, - implementation: implementation - }; +function getComponentName(fiber) { + var type = fiber.type; + if ("function" === typeof type) return type.displayName || type.name; + if ("string" === typeof type) return type; + switch (type) { + case REACT_ASYNC_MODE_TYPE: + return "AsyncMode"; + case REACT_CONTEXT_TYPE: + return "Context.Consumer"; + case REACT_FRAGMENT_TYPE: + return "ReactFragment"; + case REACT_PORTAL_TYPE: + return "ReactPortal"; + case REACT_PROFILER_TYPE: + return "Profiler(" + fiber.pendingProps.id + ")"; + case REACT_PROVIDER_TYPE: + return "Context.Provider"; + case REACT_STRICT_MODE_TYPE: + return "StrictMode"; + case REACT_TIMEOUT_TYPE: + return "Timeout"; + } + if ("object" === typeof type && null !== type) + switch (type.$$typeof) { + case REACT_FORWARD_REF_TYPE: + return ( + (fiber = type.render.displayName || type.render.name || ""), + "" !== fiber ? "ForwardRef(" + fiber + ")" : "ForwardRef" + ); + } + return null; } -var restoreTarget = null, - restoreQueue = null; -function restoreStateOfTarget(target) { - if ((target = getInstanceFromNode(target))) { +function isFiberMountedImpl(fiber) { + var node = fiber; + if (fiber.alternate) for (; node.return; ) node = node.return; + else { + if (0 !== (node.effectTag & 2)) return 1; + for (; node.return; ) + if (((node = node.return), 0 !== (node.effectTag & 2))) return 1; + } + return 3 === node.tag ? 2 : 3; +} +function assertIsMounted(fiber) { + invariant( + 2 === isFiberMountedImpl(fiber), + "Unable to find node on an unmounted component." + ); +} +function findCurrentFiberUsingSlowPath(fiber) { + var alternate = fiber.alternate; + if (!alternate) + return ( + (alternate = isFiberMountedImpl(fiber)), + invariant( + 3 !== alternate, + "Unable to find node on an unmounted component." + ), + 1 === alternate ? null : fiber + ); + for (var a = fiber, b = alternate; ; ) { + var parentA = a.return, + parentB = parentA ? parentA.alternate : null; + if (!parentA || !parentB) break; + if (parentA.child === parentB.child) { + for (var child = parentA.child; child; ) { + if (child === a) return assertIsMounted(parentA), fiber; + if (child === b) return assertIsMounted(parentA), alternate; + child = child.sibling; + } + invariant(!1, "Unable to find node on an unmounted component."); + } + if (a.return !== b.return) (a = parentA), (b = parentB); + else { + child = !1; + for (var _child = parentA.child; _child; ) { + if (_child === a) { + child = !0; + a = parentA; + b = parentB; + break; + } + if (_child === b) { + child = !0; + b = parentA; + a = parentB; + break; + } + _child = _child.sibling; + } + if (!child) { + for (_child = parentB.child; _child; ) { + if (_child === a) { + child = !0; + a = parentB; + b = parentA; + break; + } + if (_child === b) { + child = !0; + b = parentB; + a = parentA; + break; + } + _child = _child.sibling; + } + invariant( + child, + "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue." + ); + } + } invariant( - null, - "Fiber needs to be injected to handle a fiber target for controlled events. This error is likely caused by a bug in React. Please file an issue." + a.alternate === b, + "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." ); - var props = getFiberCurrentPropsFromNode(target.stateNode); - null.restoreControlledState(target.stateNode, target.type, props); } + invariant(3 === a.tag, "Unable to find node on an unmounted component."); + return a.stateNode.current === a ? fiber : alternate; } -function _batchedUpdates(fn, bookkeeping) { - return fn(bookkeeping); +function findCurrentHostFiber(parent) { + parent = findCurrentFiberUsingSlowPath(parent); + if (!parent) return null; + for (var node = parent; ; ) { + if (5 === node.tag || 6 === node.tag) return node; + if (node.child) (node.child.return = node), (node = node.child); + else { + if (node === parent) break; + for (; !node.sibling; ) { + if (!node.return || node.return === parent) return null; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + } + return null; } -function _flushInteractiveUpdates() {} -var isBatching = !1; -function batchedUpdates(fn, bookkeeping) { - if (isBatching) return fn(bookkeeping); - isBatching = !0; - try { - return _batchedUpdates(fn, bookkeeping); - } finally { - if (((isBatching = !1), null !== restoreTarget || null !== restoreQueue)) - if ( - (_flushInteractiveUpdates(), - restoreTarget && - ((bookkeeping = restoreTarget), - (fn = restoreQueue), - (restoreQueue = restoreTarget = null), - restoreStateOfTarget(bookkeeping), - fn)) - ) - for (bookkeeping = 0; bookkeeping < fn.length; bookkeeping++) - restoreStateOfTarget(fn[bookkeeping]); +function findCurrentHostFiberWithNoPortals(parent) { + parent = findCurrentFiberUsingSlowPath(parent); + if (!parent) return null; + for (var node = parent; ; ) { + if (5 === node.tag || 6 === node.tag) return node; + if (node.child && 4 !== node.tag) + (node.child.return = node), (node = node.child); + else { + if (node === parent) break; + for (; !node.sibling; ) { + if (!node.return || node.return === parent) return null; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } } + return null; +} +function mountSafeCallback(context, callback) { + return function() { + if (callback) { + if ("boolean" === typeof context.__isMounted) { + if (!context.__isMounted) return; + } else if ( + "function" === typeof context.isMounted && + !context.isMounted() + ) + return; + return callback.apply(context, arguments); + } + }; } var emptyObject$1 = {}, removedKeys = null, @@ -1318,199 +1437,310 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) { ))))); return updatePayload; } -function mountSafeCallback(context, callback) { - return function() { - if (callback) { - if ("boolean" === typeof context.__isMounted) { - if (!context.__isMounted) return; - } else if ( - "function" === typeof context.isMounted && - !context.isMounted() - ) - return; - return callback.apply(context, arguments); - } - }; -} -function _inherits(subClass, superClass) { - if ("function" !== typeof superClass && null !== superClass) - throw new TypeError( - "Super expression must either be null or a function, not " + - typeof superClass +var now$1 = + "object" === typeof performance && "function" === typeof performance.now + ? function() { + return performance.now(); + } + : function() { + return Date.now(); + }, + scheduledCallback = null, + frameDeadline = 0, + frameDeadlineObject = { + timeRemaining: function() { + return frameDeadline - now$1(); + }, + didTimeout: !1 + }; +function setTimeoutCallback() { + frameDeadline = now$1() + 5; + var callback = scheduledCallback; + scheduledCallback = null; + null !== callback && callback(frameDeadlineObject); +} +var restoreTarget = null, + restoreQueue = null; +function restoreStateOfTarget(target) { + if ((target = getInstanceFromNode(target))) { + invariant( + null, + "Fiber needs to be injected to handle a fiber target for controlled events. This error is likely caused by a bug in React. Please file an issue." ); - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: !1, - writable: !0, - configurable: !0 + var props = getFiberCurrentPropsFromNode(target.stateNode); + null.restoreControlledState(target.stateNode, target.type, props); + } +} +function _batchedUpdates(fn, bookkeeping) { + return fn(bookkeeping); +} +function _flushInteractiveUpdates() {} +var isBatching = !1; +function batchedUpdates(fn, bookkeeping) { + if (isBatching) return fn(bookkeeping); + isBatching = !0; + try { + return _batchedUpdates(fn, bookkeeping); + } finally { + if (((isBatching = !1), null !== restoreTarget || null !== restoreQueue)) + if ( + (_flushInteractiveUpdates(), + restoreTarget && + ((bookkeeping = restoreTarget), + (fn = restoreQueue), + (restoreQueue = restoreTarget = null), + restoreStateOfTarget(bookkeeping), + fn)) + ) + for (bookkeeping = 0; bookkeeping < fn.length; bookkeeping++) + restoreStateOfTarget(fn[bookkeeping]); + } +} +function dispatchEvent(target, topLevelType, nativeEvent) { + batchedUpdates(function() { + var events = nativeEvent.target; + for (var events$jscomp$0 = null, i = 0; i < plugins.length; i++) { + var possiblePlugin = plugins[i]; + possiblePlugin && + (possiblePlugin = possiblePlugin.extractEvents( + topLevelType, + target, + nativeEvent, + events + )) && + (events$jscomp$0 = accumulateInto(events$jscomp$0, possiblePlugin)); } + events = events$jscomp$0; + null !== events && (eventQueue = accumulateInto(eventQueue, events)); + events = eventQueue; + eventQueue = null; + events && + (forEachAccumulated(events, executeDispatchesAndReleaseTopLevel), + invariant( + !eventQueue, + "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented." + ), + ReactErrorUtils.rethrowCaughtError()); }); - superClass && - (Object.setPrototypeOf - ? Object.setPrototypeOf(subClass, superClass) - : (subClass.__proto__ = superClass)); } -var ReactCurrentOwner = - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner; -function getComponentName(fiber) { - var type = fiber.type; - if ("function" === typeof type) return type.displayName || type.name; - if ("string" === typeof type) return type; - switch (type) { - case REACT_ASYNC_MODE_TYPE: - return "AsyncMode"; - case REACT_CONTEXT_TYPE: - return "Context.Consumer"; - case REACT_FRAGMENT_TYPE: - return "ReactFragment"; - case REACT_PORTAL_TYPE: - return "ReactPortal"; - case REACT_PROFILER_TYPE: - return "Profiler(" + fiber.pendingProps.id + ")"; - case REACT_PROVIDER_TYPE: - return "Context.Provider"; - case REACT_STRICT_MODE_TYPE: - return "StrictMode"; +function shim$1() { + invariant( + !1, + "The current renderer does not support hyration. This error is likely caused by a bug in React. Please file an issue." + ); +} +var nextReactTag = 2; +FabricUIManager.registerEventHandler && + FabricUIManager.registerEventHandler(dispatchEvent); +var ReactFabricHostComponent = (function() { + function ReactFabricHostComponent(tag, viewConfig, props) { + if (!(this instanceof ReactFabricHostComponent)) + throw new TypeError("Cannot call a class as a function"); + this._nativeTag = tag; + this.viewConfig = viewConfig; + this.currentProps = props; } - if ("object" === typeof type && null !== type) - switch (type.$$typeof) { - case REACT_FORWARD_REF_TYPE: - return ( - (fiber = type.render.displayName || type.render.name || ""), - "" !== fiber ? "ForwardRef(" + fiber + ")" : "ForwardRef" - ); + ReactFabricHostComponent.prototype.blur = function() { + TextInputState.blurTextInput(this._nativeTag); + }; + ReactFabricHostComponent.prototype.focus = function() { + TextInputState.focusTextInput(this._nativeTag); + }; + ReactFabricHostComponent.prototype.measure = function(callback) { + UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); + }; + ReactFabricHostComponent.prototype.measureInWindow = function(callback) { + UIManager.measureInWindow( + this._nativeTag, + mountSafeCallback(this, callback) + ); + }; + ReactFabricHostComponent.prototype.measureLayout = function( + relativeToNativeNode, + onSuccess, + onFail + ) { + UIManager.measureLayout( + this._nativeTag, + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }; + ReactFabricHostComponent.prototype.setNativeProps = function(nativeProps) { + nativeProps = diffProperties( + null, + emptyObject$1, + nativeProps, + this.viewConfig.validAttributes + ); + null != nativeProps && + UIManager.updateView( + this._nativeTag, + this.viewConfig.uiViewClassName, + nativeProps + ); + }; + return ReactFabricHostComponent; +})(); +function createTextInstance( + text, + rootContainerInstance, + hostContext, + internalInstanceHandle +) { + invariant( + hostContext.isInAParentText, + "Text strings must be rendered within a component." + ); + hostContext = nextReactTag; + nextReactTag += 2; + return { + node: FabricUIManager.createNode( + hostContext, + "RCTRawText", + rootContainerInstance, + { text: text }, + internalInstanceHandle + ) + }; +} +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 = ""; } - return null; + info += JSCompiler_inline_result; + workInProgress = workInProgress.return; + } while (workInProgress); + return info; } -function isFiberMountedImpl(fiber) { - var node = fiber; - if (fiber.alternate) for (; node.return; ) node = node.return; - else { - if (0 !== (node.effectTag & 2)) return 1; - for (; node.return; ) - if (((node = node.return), 0 !== (node.effectTag & 2))) return 1; - } - return 3 === node.tag ? 2 : 3; +new Set(); +var valueStack = [], + index = -1; +function createCursor(defaultValue) { + return { current: defaultValue }; } -function isMounted(component) { - return (component = component._reactInternalFiber) - ? 2 === isFiberMountedImpl(component) - : !1; +function pop(cursor) { + 0 > index || + ((cursor.current = valueStack[index]), (valueStack[index] = null), index--); } -function assertIsMounted(fiber) { +function push(cursor, value) { + index++; + valueStack[index] = cursor.current; + cursor.current = value; +} +var contextStackCursor = createCursor(emptyObject), + didPerformWorkStackCursor = createCursor(!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 popTopLevelContextObject(fiber) { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} +function pushTopLevelContextObject(fiber, context, didChange) { invariant( - 2 === isFiberMountedImpl(fiber), - "Unable to find node on an unmounted component." + contextStackCursor.current === emptyObject, + "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 findCurrentFiberUsingSlowPath(fiber) { - var alternate = fiber.alternate; - if (!alternate) - return ( - (alternate = isFiberMountedImpl(fiber)), - invariant( - 3 !== alternate, - "Unable to find node on an unmounted component." - ), - 1 === alternate ? null : fiber - ); - for (var a = fiber, b = alternate; ; ) { - var parentA = a.return, - parentB = parentA ? parentA.alternate : null; - if (!parentA || !parentB) break; - if (parentA.child === parentB.child) { - for (var child = parentA.child; child; ) { - if (child === a) return assertIsMounted(parentA), fiber; - if (child === b) return assertIsMounted(parentA), alternate; - child = child.sibling; - } - invariant(!1, "Unable to find node on an unmounted component."); - } - if (a.return !== b.return) (a = parentA), (b = parentB); - else { - child = !1; - for (var _child = parentA.child; _child; ) { - if (_child === a) { - child = !0; - a = parentA; - b = parentB; - break; - } - if (_child === b) { - child = !0; - b = parentA; - a = parentB; - break; - } - _child = _child.sibling; - } - if (!child) { - for (_child = parentB.child; _child; ) { - if (_child === a) { - child = !0; - a = parentB; - b = parentA; - break; - } - if (_child === b) { - child = !0; - b = parentB; - a = parentA; - break; - } - _child = _child.sibling; - } - invariant( - child, - "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue." - ); - } - } +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( - a.alternate === b, - "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." + contextKey in childContextTypes, + '%s.getChildContext(): key "%s" is not defined in childContextTypes.', + getComponentName(fiber) || "Unknown", + contextKey ); - } - invariant(3 === a.tag, "Unable to find node on an unmounted component."); - return a.stateNode.current === a ? fiber : alternate; + return Object.assign({}, parentContext, instance); } -function findCurrentHostFiber(parent) { - parent = findCurrentFiberUsingSlowPath(parent); - if (!parent) return null; - for (var node = parent; ; ) { - if (5 === node.tag || 6 === node.tag) return node; - if (node.child) (node.child.return = node), (node = node.child); - else { - if (node === parent) break; - for (; !node.sibling; ) { - if (!node.return || node.return === parent) return null; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } - } - return null; +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 findCurrentHostFiberWithNoPortals(parent) { - parent = findCurrentFiberUsingSlowPath(parent); - if (!parent) return null; - for (var node = parent; ; ) { - if (5 === node.tag || 6 === node.tag) return node; - if (node.child && 4 !== node.tag) - (node.child.return = node), (node = node.child); - else { - if (node === parent) break; - for (; !node.sibling; ) { - if (!node.return || node.return === parent) return null; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } - } - return null; +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; @@ -1583,7 +1813,6 @@ function createFiberFromElement(element, mode, expirationTime) { (type = new FiberNode(15, element, key, mode | 4)), (type.type = REACT_PROFILER_TYPE), (type.expirationTime = expirationTime), - (type.stateNode = { duration: 0, startTime: 0 }), type ); case REACT_TIMEOUT_TYPE: @@ -1645,6 +1874,30 @@ function createFiberFromPortal(portal, mode, expirationTime) { }; return mode; } +function createFiberRoot(containerInfo, isAsync, hydrate) { + isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0); + containerInfo = { + current: isAsync, + containerInfo: containerInfo, + pendingChildren: null, + earliestPendingTime: 0, + latestPendingTime: 0, + earliestSuspendedTime: 0, + latestSuspendedTime: 0, + latestPingedTime: 0, + didError: !1, + pendingCommitExpirationTime: 0, + finishedWork: null, + context: null, + pendingContext: null, + hydrate: hydrate, + nextExpirationTimeToWorkOn: 0, + expirationTime: 0, + firstBatch: null, + nextScheduledRoot: null + }; + return (isAsync.stateNode = containerInfo); +} var onCommitFiberRoot = null, onCommitFiberUnmount = null; function catchErrors(fn) { @@ -1675,53 +1928,35 @@ 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; +function markPendingPriorityLevel(root, expirationTime) { + root.didError = !1; + var earliestPendingTime = root.earliestPendingTime; + 0 === earliestPendingTime + ? (root.earliestPendingTime = root.latestPendingTime = expirationTime) + : earliestPendingTime > expirationTime + ? (root.earliestPendingTime = expirationTime) + : root.latestPendingTime < expirationTime && + (root.latestPendingTime = expirationTime); + findNextPendingPriorityLevel(root); } -function createProfilerTimer() { - return { - checkActualRenderTimeStackEmpty: function() {}, - markActualRenderTimeStarted: function() {}, - pauseActualRenderTimerIfRunning: function() {}, - recordElapsedActualRenderTime: function() {}, - resetActualRenderTimer: function() {}, - resumeActualRenderTimerIfPaused: function() {}, - recordElapsedBaseRenderTimeIfRunning: function() {}, - startBaseRenderTimer: function() {}, - stopBaseRenderTimerIfRunning: function() {} - }; +function findNextPendingPriorityLevel(root) { + var earliestSuspendedTime = root.earliestSuspendedTime, + earliestPendingTime = root.earliestPendingTime; + if (0 === earliestSuspendedTime) + var nextExpirationTimeToWorkOn = (earliestSuspendedTime = earliestPendingTime); + else + 0 !== earliestPendingTime + ? ((nextExpirationTimeToWorkOn = earliestPendingTime), + (earliestSuspendedTime = + earliestSuspendedTime < earliestPendingTime + ? earliestSuspendedTime + : earliestPendingTime)) + : (nextExpirationTimeToWorkOn = earliestSuspendedTime = + root.latestPingedTime); + root.didError && (earliestSuspendedTime = 1); + root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn; + root.expirationTime = earliestSuspendedTime; } -new Set(); var hasForceUpdate = !1; function createUpdateQueue(baseState) { return { @@ -1979,6 +2214,85 @@ function commitUpdateQueue(finishedWork, finishedQueue, instance) { ((finishedWork.callback = null), callCallback(finishedQueue, instance)), (finishedWork = finishedWork.nextEffect); } +function createCapturedValue(value, source) { + return { + value: value, + source: source, + stack: getStackAddendumByWorkInProgressFiber(source) + }; +} +var providerCursor = createCursor(null), + valueCursor = createCursor(null), + changedBitsCursor = createCursor(0); +function pushProvider(providerFiber) { + var context = providerFiber.type._context; + push(changedBitsCursor, context._changedBits2, providerFiber); + push(valueCursor, context._currentValue2, providerFiber); + push(providerCursor, providerFiber, providerFiber); + context._currentValue2 = providerFiber.pendingProps.value; + context._changedBits2 = providerFiber.stateNode; +} +function popProvider(providerFiber) { + var changedBits = changedBitsCursor.current, + currentValue = valueCursor.current; + pop(providerCursor, providerFiber); + pop(valueCursor, providerFiber); + pop(changedBitsCursor, providerFiber); + providerFiber = providerFiber.type._context; + providerFiber._currentValue2 = currentValue; + providerFiber._changedBits2 = changedBits; +} +var NO_CONTEXT = {}, + contextStackCursor$1 = createCursor(NO_CONTEXT), + contextFiberStackCursor = createCursor(NO_CONTEXT), + rootInstanceStackCursor = createCursor(NO_CONTEXT); +function requiredContext(c) { + invariant( + c !== NO_CONTEXT, + "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." + ); + return c; +} +function pushHostContainer(fiber, nextRootInstance) { + push(rootInstanceStackCursor, nextRootInstance, fiber); + push(contextFiberStackCursor, fiber, fiber); + push(contextStackCursor$1, NO_CONTEXT, fiber); + pop(contextStackCursor$1, fiber); + push(contextStackCursor$1, { isInAParentText: !1 }, fiber); +} +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} +function popHostContext(fiber) { + contextFiberStackCursor.current === fiber && + (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); +} +var hasOwnProperty = Object.prototype.hasOwnProperty; +function is(x, y) { + return x === y ? 0 !== x || 0 !== y || 1 / x === 1 / y : x !== x && y !== y; +} +function shallowEqual(objA, objB) { + if (is(objA, objB)) return !0; + if ( + "object" !== typeof objA || + null === objA || + "object" !== typeof objB || + null === objB + ) + return !1; + var keysA = Object.keys(objA), + keysB = Object.keys(objB); + if (keysA.length !== keysB.length) return !1; + for (keysB = 0; keysB < keysA.length; keysB++) + if ( + !hasOwnProperty.call(objB, keysA[keysB]) || + !is(objA[keysA[keysB]], objB[keysA[keysB]]) + ) + return !1; + return !0; +} function applyDerivedStateFromProps( workInProgress, getDerivedStateFromProps, @@ -1996,351 +2310,120 @@ function applyDerivedStateFromProps( 0 === workInProgress.expirationTime && (workInProgress.baseState = prevState); } -function ReactFiberClassComponent( - legacyContext, - scheduleWork, - computeExpirationForFiber, - memoizeProps, - memoizeState, - recalculateCurrentTime -) { - function checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - newState, - newContext - ) { - var instance = workInProgress.stateNode; - workInProgress = workInProgress.type; - return "function" === typeof instance.shouldComponentUpdate - ? instance.shouldComponentUpdate(newProps, newState, newContext) - : workInProgress.prototype && - workInProgress.prototype.isPureReactComponent - ? !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) - : !0; - } - function adoptClassInstance(workInProgress, instance) { - instance.updater = classComponentUpdater; - workInProgress.stateNode = instance; - instance._reactInternalFiber = workInProgress; - } - function callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newContext - ) { - workInProgress = instance.state; - "function" === typeof instance.componentWillReceiveProps && - instance.componentWillReceiveProps(newProps, newContext); - "function" === typeof instance.UNSAFE_componentWillReceiveProps && - instance.UNSAFE_componentWillReceiveProps(newProps, newContext); - instance.state !== workInProgress && - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); +var classComponentUpdater = { + isMounted: function(component) { + return (component = component._reactInternalFiber) + ? 2 === isFiberMountedImpl(component) + : !1; + }, + enqueueSetState: function(inst, payload, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.payload = payload; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + }, + enqueueReplaceState: function(inst, payload, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.tag = 1; + update.payload = payload; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + }, + enqueueForceUpdate: function(inst, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.tag = 2; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); } - var cacheContext = legacyContext.cacheContext, - getMaskedContext = legacyContext.getMaskedContext, - getUnmaskedContext = legacyContext.getUnmaskedContext, - isContextConsumer = legacyContext.isContextConsumer, - hasContextChanged = legacyContext.hasContextChanged, - classComponentUpdater = { - isMounted: isMounted, - enqueueSetState: function(inst, payload, callback) { - inst = inst._reactInternalFiber; - var currentTime = recalculateCurrentTime(); - currentTime = computeExpirationForFiber(currentTime, inst); - var update = createUpdate(currentTime); - update.payload = payload; - void 0 !== callback && - null !== callback && - (update.callback = callback); - enqueueUpdate(inst, update, currentTime); - scheduleWork(inst, currentTime); - }, - enqueueReplaceState: function(inst, payload, callback) { - inst = inst._reactInternalFiber; - var currentTime = recalculateCurrentTime(); - currentTime = computeExpirationForFiber(currentTime, inst); - var update = createUpdate(currentTime); - update.tag = 1; - update.payload = payload; - void 0 !== callback && - null !== callback && - (update.callback = callback); - enqueueUpdate(inst, update, currentTime); - scheduleWork(inst, currentTime); - }, - enqueueForceUpdate: function(inst, callback) { - inst = inst._reactInternalFiber; - var currentTime = recalculateCurrentTime(); - currentTime = computeExpirationForFiber(currentTime, inst); - var update = createUpdate(currentTime); - update.tag = 2; - void 0 !== callback && - null !== callback && - (update.callback = callback); - enqueueUpdate(inst, update, currentTime); - scheduleWork(inst, currentTime); - } - }; - return { - adoptClassInstance: adoptClassInstance, - constructClassInstance: function(workInProgress, props) { - var ctor = workInProgress.type, - unmaskedContext = getUnmaskedContext(workInProgress), - needsContext = isContextConsumer(workInProgress), - context = needsContext - ? getMaskedContext(workInProgress, unmaskedContext) - : emptyObject; - props = new ctor(props, context); - workInProgress.memoizedState = - null !== props.state && void 0 !== props.state ? props.state : null; - adoptClassInstance(workInProgress, props); - needsContext && cacheContext(workInProgress, unmaskedContext, context); - return props; - }, - mountClassInstance: function(workInProgress, renderExpirationTime) { - var ctor = workInProgress.type, - instance = workInProgress.stateNode, - props = workInProgress.pendingProps, - unmaskedContext = getUnmaskedContext(workInProgress); - instance.props = props; - instance.state = workInProgress.memoizedState; - instance.refs = emptyObject; - instance.context = getMaskedContext(workInProgress, unmaskedContext); - unmaskedContext = workInProgress.updateQueue; - null !== unmaskedContext && - (processUpdateQueue( - workInProgress, - unmaskedContext, - props, - instance, - renderExpirationTime - ), - (instance.state = workInProgress.memoizedState)); - unmaskedContext = workInProgress.type.getDerivedStateFromProps; - "function" === typeof unmaskedContext && - (applyDerivedStateFromProps(workInProgress, unmaskedContext, props), - (instance.state = workInProgress.memoizedState)); - "function" === typeof ctor.getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate || - ("function" !== typeof instance.UNSAFE_componentWillMount && - "function" !== typeof instance.componentWillMount) || - ((ctor = instance.state), - "function" === typeof instance.componentWillMount && - instance.componentWillMount(), - "function" === typeof instance.UNSAFE_componentWillMount && - instance.UNSAFE_componentWillMount(), - ctor !== instance.state && - classComponentUpdater.enqueueReplaceState( - instance, - instance.state, - null - ), - (unmaskedContext = workInProgress.updateQueue), - null !== unmaskedContext && - (processUpdateQueue( - workInProgress, - unmaskedContext, - props, - instance, - renderExpirationTime - ), - (instance.state = workInProgress.memoizedState))); - "function" === typeof instance.componentDidMount && - (workInProgress.effectTag |= 4); - }, - resumeMountClassInstance: function(workInProgress, renderExpirationTime) { - var ctor = workInProgress.type, - instance = workInProgress.stateNode, - oldProps = workInProgress.memoizedProps, - newProps = workInProgress.pendingProps; - instance.props = oldProps; - var oldContext = instance.context, - newUnmaskedContext = getUnmaskedContext(workInProgress); - newUnmaskedContext = getMaskedContext(workInProgress, newUnmaskedContext); - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - (ctor = - "function" === typeof getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate) || - ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && - "function" !== typeof instance.componentWillReceiveProps) || - ((oldProps !== newProps || oldContext !== newUnmaskedContext) && - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newUnmaskedContext - )); - hasForceUpdate = !1; - var oldState = workInProgress.memoizedState; - oldContext = instance.state = oldState; - var updateQueue = workInProgress.updateQueue; - null !== updateQueue && - (processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime - ), - (oldContext = workInProgress.memoizedState)); - if ( - oldProps === newProps && - oldState === oldContext && - !hasContextChanged() && - !hasForceUpdate - ) - return ( - "function" === typeof instance.componentDidMount && - (workInProgress.effectTag |= 4), - !1 - ); - "function" === typeof getDerivedStateFromProps && - (applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - newProps - ), - (oldContext = workInProgress.memoizedState)); - (renderExpirationTime = - hasForceUpdate || - checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - oldContext, - 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 && - (workInProgress.effectTag |= 4)) - : ("function" === typeof instance.componentDidMount && - (workInProgress.effectTag |= 4), - (workInProgress.memoizedProps = newProps), - (workInProgress.memoizedState = oldContext)); - instance.props = newProps; - instance.state = oldContext; - instance.context = newUnmaskedContext; - return renderExpirationTime; - }, - updateClassInstance: function( - current, +}; +function checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext +) { + var instance = workInProgress.stateNode; + workInProgress = workInProgress.type; + return "function" === typeof instance.shouldComponentUpdate + ? instance.shouldComponentUpdate(newProps, newState, newContext) + : workInProgress.prototype && workInProgress.prototype.isPureReactComponent + ? !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) + : !0; +} +function callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext +) { + workInProgress = instance.state; + "function" === typeof instance.componentWillReceiveProps && + instance.componentWillReceiveProps(newProps, newContext); + "function" === typeof instance.UNSAFE_componentWillReceiveProps && + instance.UNSAFE_componentWillReceiveProps(newProps, newContext); + instance.state !== workInProgress && + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); +} +function mountClassInstance(workInProgress, renderExpirationTime) { + var ctor = workInProgress.type, + instance = workInProgress.stateNode, + props = workInProgress.pendingProps, + unmaskedContext = getUnmaskedContext(workInProgress); + instance.props = props; + instance.state = workInProgress.memoizedState; + instance.refs = emptyObject; + instance.context = getMaskedContext(workInProgress, unmaskedContext); + unmaskedContext = workInProgress.updateQueue; + null !== unmaskedContext && + (processUpdateQueue( workInProgress, + unmaskedContext, + props, + instance, renderExpirationTime - ) { - var ctor = workInProgress.type, - instance = workInProgress.stateNode, - oldProps = workInProgress.memoizedProps, - newProps = workInProgress.pendingProps; - instance.props = oldProps; - var oldContext = instance.context, - newUnmaskedContext = getUnmaskedContext(workInProgress); - newUnmaskedContext = getMaskedContext(workInProgress, newUnmaskedContext); - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - (ctor = - "function" === typeof getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate) || - ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && - "function" !== typeof instance.componentWillReceiveProps) || - ((oldProps !== newProps || oldContext !== newUnmaskedContext) && - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newUnmaskedContext - )); - hasForceUpdate = !1; - oldContext = workInProgress.memoizedState; - var newState = (instance.state = oldContext), - updateQueue = workInProgress.updateQueue; - null !== updateQueue && - (processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime - ), - (newState = workInProgress.memoizedState)); - if ( - oldProps === newProps && - oldContext === newState && - !hasContextChanged() && - !hasForceUpdate - ) - return ( - "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 |= 256), - !1 - ); - "function" === typeof getDerivedStateFromProps && - (applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - newProps - ), - (newState = workInProgress.memoizedState)); - (renderExpirationTime = - hasForceUpdate || - checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldContext, - newState, - newUnmaskedContext - )) - ? (ctor || - ("function" !== typeof instance.UNSAFE_componentWillUpdate && - "function" !== typeof instance.componentWillUpdate) || - ("function" === typeof instance.componentWillUpdate && - instance.componentWillUpdate( - newProps, - newState, - newUnmaskedContext - ), - "function" === typeof instance.UNSAFE_componentWillUpdate && - instance.UNSAFE_componentWillUpdate( - newProps, - newState, - newUnmaskedContext - )), - "function" === typeof instance.componentDidUpdate && - (workInProgress.effectTag |= 4), - "function" === typeof instance.getSnapshotBeforeUpdate && - (workInProgress.effectTag |= 256)) - : ("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 |= 256), - (workInProgress.memoizedProps = newProps), - (workInProgress.memoizedState = newState)); - instance.props = newProps; - instance.state = newState; - instance.context = newUnmaskedContext; - return renderExpirationTime; - } - }; + ), + (instance.state = workInProgress.memoizedState)); + unmaskedContext = workInProgress.type.getDerivedStateFromProps; + "function" === typeof unmaskedContext && + (applyDerivedStateFromProps(workInProgress, unmaskedContext, props), + (instance.state = workInProgress.memoizedState)); + "function" === typeof ctor.getDerivedStateFromProps || + "function" === typeof instance.getSnapshotBeforeUpdate || + ("function" !== typeof instance.UNSAFE_componentWillMount && + "function" !== typeof instance.componentWillMount) || + ((ctor = instance.state), + "function" === typeof instance.componentWillMount && + instance.componentWillMount(), + "function" === typeof instance.UNSAFE_componentWillMount && + instance.UNSAFE_componentWillMount(), + ctor !== instance.state && + classComponentUpdater.enqueueReplaceState(instance, instance.state, null), + (unmaskedContext = workInProgress.updateQueue), + null !== unmaskedContext && + (processUpdateQueue( + workInProgress, + unmaskedContext, + props, + instance, + renderExpirationTime + ), + (instance.state = workInProgress.memoizedState))); + "function" === typeof instance.componentDidMount && + (workInProgress.effectTag |= 4); } var isArray$1 = Array.isArray; function coerceRef(returnFiber, current, element) { @@ -2368,6 +2451,7 @@ function coerceRef(returnFiber, current, element) { if ( null !== current && null !== current.ref && + "function" === typeof current.ref && current.ref._stringRef === stringRef ) return current.ref; @@ -2863,27 +2947,35 @@ function ChildReconciler(shouldTrackSideEffects) { return iteratorFn; } return function(returnFiber, currentFirstChild, newChild, expirationTime) { - "object" === typeof newChild && + var isUnkeyedTopLevelFragment = + "object" === typeof newChild && null !== newChild && newChild.type === REACT_FRAGMENT_TYPE && - null === newChild.key && - (newChild = newChild.props.children); + null === newChild.key; + isUnkeyedTopLevelFragment && (newChild = newChild.props.children); var isObject = "object" === typeof newChild && null !== newChild; if (isObject) switch (newChild.$$typeof) { case REACT_ELEMENT_TYPE: a: { - var key = newChild.key; - for (isObject = currentFirstChild; null !== isObject; ) { - if (isObject.key === key) + isObject = newChild.key; + for ( + isUnkeyedTopLevelFragment = currentFirstChild; + null !== isUnkeyedTopLevelFragment; + + ) { + if (isUnkeyedTopLevelFragment.key === isObject) if ( - 10 === isObject.tag + 10 === isUnkeyedTopLevelFragment.tag ? newChild.type === REACT_FRAGMENT_TYPE - : isObject.type === newChild.type + : isUnkeyedTopLevelFragment.type === newChild.type ) { - deleteRemainingChildren(returnFiber, isObject.sibling); + deleteRemainingChildren( + returnFiber, + isUnkeyedTopLevelFragment.sibling + ); currentFirstChild = useFiber( - isObject, + isUnkeyedTopLevelFragment, newChild.type === REACT_FRAGMENT_TYPE ? newChild.props.children : newChild.props, @@ -2891,18 +2983,21 @@ function ChildReconciler(shouldTrackSideEffects) { ); currentFirstChild.ref = coerceRef( returnFiber, - isObject, + isUnkeyedTopLevelFragment, newChild ); currentFirstChild.return = returnFiber; returnFiber = currentFirstChild; break a; } else { - deleteRemainingChildren(returnFiber, isObject); + deleteRemainingChildren( + returnFiber, + isUnkeyedTopLevelFragment + ); break; } - else deleteChild(returnFiber, isObject); - isObject = isObject.sibling; + else deleteChild(returnFiber, isUnkeyedTopLevelFragment); + isUnkeyedTopLevelFragment = isUnkeyedTopLevelFragment.sibling; } newChild.type === REACT_FRAGMENT_TYPE ? ((currentFirstChild = createFiberFromFragment( @@ -2929,8 +3024,12 @@ function ChildReconciler(shouldTrackSideEffects) { return placeSingleChild(returnFiber); case REACT_PORTAL_TYPE: a: { - for (isObject = newChild.key; null !== currentFirstChild; ) { - if (currentFirstChild.key === isObject) + for ( + isUnkeyedTopLevelFragment = newChild.key; + null !== currentFirstChild; + + ) { + if (currentFirstChild.key === isUnkeyedTopLevelFragment) if ( 4 === currentFirstChild.tag && currentFirstChild.stateNode.containerInfo === @@ -3004,7 +3103,7 @@ function ChildReconciler(shouldTrackSideEffects) { expirationTime ); isObject && throwOnInvalidObjectType(returnFiber, newChild); - if ("undefined" === typeof newChild) + if ("undefined" === typeof newChild && !isUnkeyedTopLevelFragment) switch (returnFiber.tag) { case 2: case 1: @@ -3018,185 +3117,235 @@ function ChildReconciler(shouldTrackSideEffects) { return deleteRemainingChildren(returnFiber, currentFirstChild); }; } -var reconcileChildFibers = ChildReconciler(!0), - mountChildFibers = ChildReconciler(!1); -function ReactFiberBeginWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - scheduleWork, - computeExpirationForFiber, - profilerTimer, - recalculateCurrentTime -) { - function reconcileChildren(current, workInProgress, nextChildren) { - reconcileChildrenAtExpirationTime( - current, - workInProgress, - nextChildren, - workInProgress.expirationTime - ); +var reconcileChildFibers = ChildReconciler(!0), + mountChildFibers = ChildReconciler(!1), + hydrationParentFiber = null, + nextHydratableInstance = null, + isHydrating = !1; +function tryHydrate(fiber, nextInstance) { + switch (fiber.tag) { + case 5: + return ( + (nextInstance = shim$1(nextInstance, fiber.type, fiber.pendingProps)), + null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 + ); + case 6: + return ( + (nextInstance = shim$1(nextInstance, fiber.pendingProps)), + null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 + ); + default: + return !1; + } +} +function tryToClaimNextHydratableInstance(fiber$jscomp$0) { + if (isHydrating) { + var nextInstance = nextHydratableInstance; + if (nextInstance) { + var firstAttemptedInstance = nextInstance; + if (!tryHydrate(fiber$jscomp$0, nextInstance)) { + nextInstance = shim$1(firstAttemptedInstance); + if (!nextInstance || !tryHydrate(fiber$jscomp$0, nextInstance)) { + fiber$jscomp$0.effectTag |= 2; + isHydrating = !1; + hydrationParentFiber = fiber$jscomp$0; + return; + } + var returnFiber = hydrationParentFiber, + fiber = new FiberNode(5, null, null, 0); + fiber.type = "DELETED"; + fiber.stateNode = firstAttemptedInstance; + fiber.return = returnFiber; + fiber.effectTag = 8; + null !== returnFiber.lastEffect + ? ((returnFiber.lastEffect.nextEffect = fiber), + (returnFiber.lastEffect = fiber)) + : (returnFiber.firstEffect = returnFiber.lastEffect = fiber); + } + hydrationParentFiber = fiber$jscomp$0; + nextHydratableInstance = shim$1(nextInstance); + } else + (fiber$jscomp$0.effectTag |= 2), + (isHydrating = !1), + (hydrationParentFiber = fiber$jscomp$0); } - function reconcileChildrenAtExpirationTime( +} +function reconcileChildren(current, workInProgress, nextChildren) { + reconcileChildrenAtExpirationTime( current, workInProgress, nextChildren, - renderExpirationTime - ) { - workInProgress.child = - null === current - ? mountChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime - ) - : reconcileChildFibers( - workInProgress, - current.child, - nextChildren, - renderExpirationTime - ); - } - function markRef(current, workInProgress) { - var ref = workInProgress.ref; - if ( - (null === current && null !== ref) || - (null !== current && current.ref !== ref) - ) - workInProgress.effectTag |= 128; - } - function finishClassComponent( - current, - workInProgress, - shouldUpdate, - hasContext, - renderExpirationTime - ) { - markRef(current, workInProgress); - var didCaptureError = 0 !== (workInProgress.effectTag & 64); - if (!shouldUpdate && !didCaptureError) - return ( - hasContext && invalidateContextProvider(workInProgress, !1), - bailoutOnAlreadyFinishedWork(current, workInProgress) - ); - shouldUpdate = workInProgress.stateNode; - ReactCurrentOwner.current = workInProgress; - var nextChildren = didCaptureError ? null : shouldUpdate.render(); - workInProgress.effectTag |= 1; - didCaptureError && - (reconcileChildrenAtExpirationTime( - current, - workInProgress, - null, - renderExpirationTime - ), - (workInProgress.child = null)); - reconcileChildrenAtExpirationTime( + workInProgress.expirationTime + ); +} +function reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime +) { + workInProgress.child = + null === current + ? mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ) + : reconcileChildFibers( + workInProgress, + current.child, + nextChildren, + renderExpirationTime + ); +} +function markRef(current, workInProgress) { + var ref = workInProgress.ref; + if ( + (null === current && null !== ref) || + (null !== current && current.ref !== ref) + ) + workInProgress.effectTag |= 128; +} +function finishClassComponent( + current, + workInProgress, + shouldUpdate, + hasContext, + renderExpirationTime +) { + markRef(current, workInProgress); + var didCaptureError = 0 !== (workInProgress.effectTag & 64); + if (!shouldUpdate && !didCaptureError) + return ( + hasContext && invalidateContextProvider(workInProgress, !1), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + shouldUpdate = workInProgress.stateNode; + ReactCurrentOwner.current = workInProgress; + var nextChildren = didCaptureError ? null : shouldUpdate.render(); + workInProgress.effectTag |= 1; + didCaptureError && + (reconcileChildrenAtExpirationTime( current, workInProgress, - nextChildren, + null, renderExpirationTime - ); - workInProgress.memoizedState = shouldUpdate.state; - workInProgress.memoizedProps = shouldUpdate.props; - hasContext && invalidateContextProvider(workInProgress, !0); - return workInProgress.child; - } - function pushHostRootContext(workInProgress) { - var root = workInProgress.stateNode; - root.pendingContext - ? pushTopLevelContextObject( - workInProgress, - root.pendingContext, - root.pendingContext !== root.context - ) - : root.context && - pushTopLevelContextObject(workInProgress, root.context, !1); - pushHostContainer(workInProgress, root.containerInfo); - } - function propagateContextChange( + ), + (workInProgress.child = null)); + reconcileChildrenAtExpirationTime( + current, workInProgress, - context, - changedBits, + nextChildren, renderExpirationTime - ) { - var fiber = workInProgress.child; - null !== fiber && (fiber.return = workInProgress); - for (; null !== fiber; ) { - switch (fiber.tag) { - case 12: - var nextFiber = fiber.stateNode | 0; - if (fiber.type === context && 0 !== (nextFiber & changedBits)) { - for (nextFiber = fiber; null !== nextFiber; ) { - var alternate = nextFiber.alternate; - if ( - 0 === nextFiber.expirationTime || - nextFiber.expirationTime > renderExpirationTime - ) - (nextFiber.expirationTime = renderExpirationTime), - null !== alternate && - (0 === alternate.expirationTime || - alternate.expirationTime > renderExpirationTime) && - (alternate.expirationTime = renderExpirationTime); - else if ( + ); + workInProgress.memoizedState = shouldUpdate.state; + workInProgress.memoizedProps = shouldUpdate.props; + hasContext && invalidateContextProvider(workInProgress, !0); + return workInProgress.child; +} +function pushHostRootContext(workInProgress) { + var root = workInProgress.stateNode; + root.pendingContext + ? pushTopLevelContextObject( + workInProgress, + root.pendingContext, + root.pendingContext !== root.context + ) + : root.context && + pushTopLevelContextObject(workInProgress, root.context, !1); + pushHostContainer(workInProgress, root.containerInfo); +} +function propagateContextChange( + workInProgress, + context, + changedBits, + renderExpirationTime +) { + var fiber = workInProgress.child; + null !== fiber && (fiber.return = workInProgress); + for (; null !== fiber; ) { + switch (fiber.tag) { + case 12: + var nextFiber = fiber.stateNode | 0; + if (fiber.type === context && 0 !== (nextFiber & changedBits)) { + for (nextFiber = fiber; null !== nextFiber; ) { + var alternate = nextFiber.alternate; + if ( + 0 === nextFiber.expirationTime || + nextFiber.expirationTime > renderExpirationTime + ) + (nextFiber.expirationTime = renderExpirationTime), null !== alternate && - (0 === alternate.expirationTime || - alternate.expirationTime > renderExpirationTime) - ) - alternate.expirationTime = renderExpirationTime; - else break; - nextFiber = nextFiber.return; - } - nextFiber = null; - } else nextFiber = fiber.child; + (0 === alternate.expirationTime || + alternate.expirationTime > renderExpirationTime) && + (alternate.expirationTime = renderExpirationTime); + else if ( + null !== alternate && + (0 === alternate.expirationTime || + alternate.expirationTime > renderExpirationTime) + ) + alternate.expirationTime = renderExpirationTime; + else break; + nextFiber = nextFiber.return; + } + nextFiber = null; + } else nextFiber = fiber.child; + break; + case 13: + nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + break; + default: + nextFiber = fiber.child; + } + if (null !== nextFiber) nextFiber.return = fiber; + else + for (nextFiber = fiber; null !== nextFiber; ) { + if (nextFiber === workInProgress) { + nextFiber = null; break; - case 13: - nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + } + fiber = nextFiber.sibling; + if (null !== fiber) { + fiber.return = nextFiber.return; + nextFiber = fiber; break; - default: - nextFiber = fiber.child; - } - if (null !== nextFiber) nextFiber.return = fiber; - else - for (nextFiber = fiber; null !== nextFiber; ) { - if (nextFiber === workInProgress) { - nextFiber = null; - break; - } - fiber = nextFiber.sibling; - if (null !== fiber) { - fiber.return = nextFiber.return; - nextFiber = fiber; - break; - } - nextFiber = nextFiber.return; } - fiber = nextFiber; - } + nextFiber = nextFiber.return; + } + fiber = nextFiber; } - function updateContextProvider( - current, - workInProgress, - renderExpirationTime - ) { - var context = workInProgress.type._context, - newProps = workInProgress.pendingProps, - oldProps = workInProgress.memoizedProps, - canBailOnProps = !0; - if (hasLegacyContextChanged()) canBailOnProps = !1; - else if (oldProps === newProps) +} +function updateContextProvider(current, workInProgress, renderExpirationTime) { + var context = workInProgress.type._context, + newProps = workInProgress.pendingProps, + oldProps = workInProgress.memoizedProps, + canBailOnProps = !0; + if (didPerformWorkStackCursor.current) canBailOnProps = !1; + else if (oldProps === newProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + var newValue = newProps.value; + workInProgress.memoizedProps = newProps; + if (null === oldProps) newValue = 1073741823; + else if (oldProps.value === newProps.value) { + if (oldProps.children === newProps.children && canBailOnProps) return ( (workInProgress.stateNode = 0), pushProvider(workInProgress), bailoutOnAlreadyFinishedWork(current, workInProgress) ); - var newValue = newProps.value; - workInProgress.memoizedProps = newProps; - if (null === oldProps) newValue = 1073741823; - else if (oldProps.value === newProps.value) { + newValue = 0; + } else { + var oldValue = oldProps.value; + if ( + (oldValue === newValue && + (0 !== oldValue || 1 / oldValue === 1 / newValue)) || + (oldValue !== oldValue && newValue !== newValue) + ) { if (oldProps.children === newProps.children && canBailOnProps) return ( (workInProgress.stateNode = 0), @@ -3204,393 +3353,364 @@ function ReactFiberBeginWork( bailoutOnAlreadyFinishedWork(current, workInProgress) ); newValue = 0; - } else { - var oldValue = oldProps.value; - if ( - (oldValue === newValue && - (0 !== oldValue || 1 / oldValue === 1 / newValue)) || - (oldValue !== oldValue && newValue !== newValue) - ) { - if (oldProps.children === newProps.children && canBailOnProps) - return ( - (workInProgress.stateNode = 0), - pushProvider(workInProgress), - bailoutOnAlreadyFinishedWork(current, workInProgress) - ); - newValue = 0; - } else if ( - ((newValue = - "function" === typeof context._calculateChangedBits - ? context._calculateChangedBits(oldValue, newValue) - : 1073741823), - (newValue |= 0), - 0 === newValue) - ) { - if (oldProps.children === newProps.children && canBailOnProps) - return ( - (workInProgress.stateNode = 0), - pushProvider(workInProgress), - bailoutOnAlreadyFinishedWork(current, workInProgress) - ); - } else - propagateContextChange( + } else if ( + ((newValue = + "function" === typeof context._calculateChangedBits + ? context._calculateChangedBits(oldValue, newValue) + : 1073741823), + (newValue |= 0), + 0 === newValue) + ) { + if (oldProps.children === newProps.children && canBailOnProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + } else + propagateContextChange( + workInProgress, + context, + newValue, + renderExpirationTime + ); + } + workInProgress.stateNode = newValue; + pushProvider(workInProgress); + reconcileChildren(current, workInProgress, newProps.children); + return workInProgress.child; +} +function bailoutOnAlreadyFinishedWork(current, workInProgress) { + invariant( + null === current || workInProgress.child === current.child, + "Resuming work not yet implemented." + ); + if (null !== workInProgress.child) { + current = workInProgress.child; + var newChild = createWorkInProgress( + current, + current.pendingProps, + current.expirationTime + ); + workInProgress.child = newChild; + for (newChild.return = workInProgress; null !== current.sibling; ) + (current = current.sibling), + (newChild = newChild.sibling = createWorkInProgress( + current, + current.pendingProps, + current.expirationTime + )), + (newChild.return = workInProgress); + newChild.sibling = null; + } + return workInProgress.child; +} +function beginWork(current, workInProgress, renderExpirationTime) { + if ( + 0 === workInProgress.expirationTime || + workInProgress.expirationTime > renderExpirationTime + ) { + switch (workInProgress.tag) { + case 3: + pushHostRootContext(workInProgress); + break; + case 2: + pushContextProvider(workInProgress); + break; + case 4: + pushHostContainer( workInProgress, - context, - newValue, - renderExpirationTime + workInProgress.stateNode.containerInfo ); + break; + case 13: + pushProvider(workInProgress); } - workInProgress.stateNode = newValue; - pushProvider(workInProgress); - reconcileChildren(current, workInProgress, newProps.children); - return workInProgress.child; + return null; } - function bailoutOnAlreadyFinishedWork(current, workInProgress) { - invariant( - null === current || workInProgress.child === current.child, - "Resuming work not yet implemented." - ); - if (null !== workInProgress.child) { - current = workInProgress.child; - var newChild = createWorkInProgress( - current, - current.pendingProps, - current.expirationTime + switch (workInProgress.tag) { + case 0: + invariant( + null === current, + "An indeterminate component should never have mounted. This error is likely caused by a bug in React. Please file an issue." ); - workInProgress.child = newChild; - for (newChild.return = workInProgress; null !== current.sibling; ) - (current = current.sibling), - (newChild = newChild.sibling = createWorkInProgress( + var fn = workInProgress.type, + props = workInProgress.pendingProps, + unmaskedContext = getUnmaskedContext(workInProgress); + unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + fn = fn(props, unmaskedContext); + workInProgress.effectTag |= 1; + "object" === typeof fn && + null !== fn && + "function" === typeof fn.render && + void 0 === fn.$$typeof + ? ((unmaskedContext = workInProgress.type), + (workInProgress.tag = 2), + (workInProgress.memoizedState = + null !== fn.state && void 0 !== fn.state ? fn.state : null), + (unmaskedContext = unmaskedContext.getDerivedStateFromProps), + "function" === typeof unmaskedContext && + applyDerivedStateFromProps(workInProgress, unmaskedContext, props), + (props = pushContextProvider(workInProgress)), + (fn.updater = classComponentUpdater), + (workInProgress.stateNode = fn), + (fn._reactInternalFiber = workInProgress), + mountClassInstance(workInProgress, renderExpirationTime), + (current = finishClassComponent( current, - current.pendingProps, - current.expirationTime - )), - (newChild.return = workInProgress); - newChild.sibling = null; - } - return workInProgress.child; - } - var shouldSetTextContent = config.shouldSetTextContent, - shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree, - pushHostContext = hostContext.pushHostContext, - pushHostContainer = hostContext.pushHostContainer, - pushProvider = newContext.pushProvider, - getContextCurrentValue = newContext.getContextCurrentValue, - getContextChangedBits = newContext.getContextChangedBits, - 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) { - workInProgress.memoizedProps = nextProps; - }, - function(workInProgress, nextState) { - workInProgress.memoizedState = nextState; - }, - recalculateCurrentTime - ); - var adoptClassInstance = config.adoptClassInstance, - constructClassInstance = config.constructClassInstance, - mountClassInstance = config.mountClassInstance, - resumeMountClassInstance = config.resumeMountClassInstance, - updateClassInstance = config.updateClassInstance; - return { - beginWork: function(current, workInProgress, renderExpirationTime) { - if ( - 0 === workInProgress.expirationTime || - workInProgress.expirationTime > renderExpirationTime - ) { - switch (workInProgress.tag) { - case 3: - pushHostRootContext(workInProgress); - break; - case 2: - pushLegacyContextProvider(workInProgress); - break; - case 4: - pushHostContainer( - workInProgress, - workInProgress.stateNode.containerInfo - ); - break; - case 13: - pushProvider(workInProgress); - } - return null; - } - switch (workInProgress.tag) { - case 0: - invariant( - null === current, - "An indeterminate component should never have mounted. This error is likely caused by a bug in React. Please file an issue." - ); - var fn = workInProgress.type, - props = workInProgress.pendingProps, - unmaskedContext = getUnmaskedContext(workInProgress); - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); - fn = fn(props, unmaskedContext); - workInProgress.effectTag |= 1; - "object" === typeof fn && - null !== fn && - "function" === typeof fn.render && - void 0 === fn.$$typeof - ? ((unmaskedContext = workInProgress.type), - (workInProgress.tag = 2), - (workInProgress.memoizedState = - null !== fn.state && void 0 !== fn.state ? fn.state : null), - (unmaskedContext = unmaskedContext.getDerivedStateFromProps), - "function" === typeof unmaskedContext && - applyDerivedStateFromProps( - workInProgress, - unmaskedContext, - props - ), - (props = pushLegacyContextProvider(workInProgress)), - adoptClassInstance(workInProgress, fn), - mountClassInstance(workInProgress, renderExpirationTime), - (current = finishClassComponent( - current, + workInProgress, + !0, + props, + renderExpirationTime + ))) + : ((workInProgress.tag = 1), + reconcileChildren(current, workInProgress, fn), + (workInProgress.memoizedProps = props), + (current = workInProgress.child)); + return current; + case 1: + return ( + (props = workInProgress.type), + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime + ? ((fn = getUnmaskedContext(workInProgress)), + (fn = getMaskedContext(workInProgress, fn)), + (props = props(renderExpirationTime, fn)), + (workInProgress.effectTag |= 1), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 2: + props = pushContextProvider(workInProgress); + if (null === current) + if (null === workInProgress.stateNode) { + var props$jscomp$0 = workInProgress.pendingProps, + ctor = workInProgress.type; + fn = getUnmaskedContext(workInProgress); + var needsContext = + 2 === workInProgress.tag && + null != workInProgress.type.contextTypes; + unmaskedContext = needsContext + ? getMaskedContext(workInProgress, fn) + : emptyObject; + props$jscomp$0 = new ctor(props$jscomp$0, unmaskedContext); + workInProgress.memoizedState = + null !== props$jscomp$0.state && void 0 !== props$jscomp$0.state + ? props$jscomp$0.state + : null; + props$jscomp$0.updater = classComponentUpdater; + workInProgress.stateNode = props$jscomp$0; + props$jscomp$0._reactInternalFiber = workInProgress; + needsContext && + ((needsContext = workInProgress.stateNode), + (needsContext.__reactInternalMemoizedUnmaskedChildContext = fn), + (needsContext.__reactInternalMemoizedMaskedChildContext = unmaskedContext)); + mountClassInstance(workInProgress, renderExpirationTime); + fn = !0; + } else { + ctor = workInProgress.type; + fn = workInProgress.stateNode; + needsContext = workInProgress.memoizedProps; + unmaskedContext = workInProgress.pendingProps; + fn.props = needsContext; + var oldContext = fn.context; + props$jscomp$0 = getUnmaskedContext(workInProgress); + props$jscomp$0 = getMaskedContext(workInProgress, props$jscomp$0); + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + (ctor = + "function" === typeof getDerivedStateFromProps || + "function" === typeof fn.getSnapshotBeforeUpdate) || + ("function" !== typeof fn.UNSAFE_componentWillReceiveProps && + "function" !== typeof fn.componentWillReceiveProps) || + ((needsContext !== unmaskedContext || + oldContext !== props$jscomp$0) && + callComponentWillReceiveProps( workInProgress, - !0, - props, - renderExpirationTime - ))) - : ((workInProgress.tag = 1), - reconcileChildren(current, workInProgress, fn), - (workInProgress.memoizedProps = props), - (current = workInProgress.child)); - return current; - case 1: - return ( - (props = workInProgress.type), - (renderExpirationTime = workInProgress.pendingProps), - hasLegacyContextChanged() || - workInProgress.memoizedProps !== renderExpirationTime - ? ((fn = getUnmaskedContext(workInProgress)), - (fn = getMaskedContext(workInProgress, fn)), - (props = props(renderExpirationTime, fn)), - (workInProgress.effectTag |= 1), - reconcileChildren(current, workInProgress, props), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 2: - return ( - (props = pushLegacyContextProvider(workInProgress)), - null === current - ? null === workInProgress.stateNode - ? (constructClassInstance( - workInProgress, - workInProgress.pendingProps, - renderExpirationTime - ), - mountClassInstance(workInProgress, renderExpirationTime), - (fn = !0)) - : (fn = resumeMountClassInstance( - workInProgress, - renderExpirationTime - )) - : (fn = updateClassInstance( - current, - workInProgress, - renderExpirationTime - )), - finishClassComponent( - current, + fn, + unmaskedContext, + props$jscomp$0 + )); + hasForceUpdate = !1; + var oldState = workInProgress.memoizedState; + oldContext = fn.state = oldState; + var updateQueue = workInProgress.updateQueue; + null !== updateQueue && + (processUpdateQueue( workInProgress, + updateQueue, + unmaskedContext, fn, - props, renderExpirationTime - ) - ); - case 3: - return ( - pushHostRootContext(workInProgress), - (props = workInProgress.updateQueue), - null !== props - ? ((fn = workInProgress.memoizedState), - (fn = null !== fn ? fn.element : null), - processUpdateQueue( - workInProgress, - props, - workInProgress.pendingProps, - null, - renderExpirationTime - ), - (props = workInProgress.memoizedState.element), - props === fn - ? (resetHydrationState(), - (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - ))) - : ((fn = workInProgress.stateNode), - (null === current || null === current.child) && - fn.hydrate && - enterHydrationState(workInProgress) - ? ((workInProgress.effectTag |= 2), - (workInProgress.child = mountChildFibers( - workInProgress, - null, - props, - renderExpirationTime - ))) - : (resetHydrationState(), - reconcileChildren(current, workInProgress, props)), - (current = workInProgress.child))) - : (resetHydrationState(), - (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - ))), - current - ); - case 5: - a: { - pushHostContext(workInProgress); - null === current && - tryToClaimNextHydratableInstance(workInProgress); - props = workInProgress.type; - var memoizedProps = workInProgress.memoizedProps; - fn = workInProgress.pendingProps; - unmaskedContext = null !== current ? current.memoizedProps : null; - if (!hasLegacyContextChanged() && memoizedProps === fn) { - if ( - (memoizedProps = - workInProgress.mode & 1 && - shouldDeprioritizeSubtree(props, fn)) - ) - workInProgress.expirationTime = 1073741823; - if (!memoizedProps || 1073741823 !== renderExpirationTime) { - current = bailoutOnAlreadyFinishedWork(current, workInProgress); - break a; - } - } - memoizedProps = fn.children; - shouldSetTextContent(props, fn) - ? (memoizedProps = null) - : unmaskedContext && - shouldSetTextContent(props, unmaskedContext) && - (workInProgress.effectTag |= 16); - markRef(current, workInProgress); - 1073741823 !== renderExpirationTime && - workInProgress.mode & 1 && - shouldDeprioritizeSubtree(props, fn) - ? ((workInProgress.expirationTime = 1073741823), - (workInProgress.memoizedProps = fn), - (current = null)) - : (reconcileChildren(current, workInProgress, memoizedProps), - (workInProgress.memoizedProps = fn), - (current = workInProgress.child)); - } - return current; - case 6: - return ( - null === current && - tryToClaimNextHydratableInstance(workInProgress), - (workInProgress.memoizedProps = workInProgress.pendingProps), - null - ); - case 16: - return null; - case 4: - return ( - pushHostContainer( - workInProgress, - workInProgress.stateNode.containerInfo ), - (props = workInProgress.pendingProps), - hasLegacyContextChanged() || workInProgress.memoizedProps !== props - ? (null === current - ? (workInProgress.child = reconcileChildFibers( - workInProgress, - null, - props, - renderExpirationTime - )) - : reconcileChildren(current, workInProgress, props), - (workInProgress.memoizedProps = props), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 14: - return ( - (props = workInProgress.type.render), - (renderExpirationTime = workInProgress.pendingProps), - (fn = workInProgress.ref), - hasLegacyContextChanged() || - workInProgress.memoizedProps !== renderExpirationTime || - fn !== (null !== current ? current.ref : null) - ? ((props = props(renderExpirationTime, fn)), - reconcileChildren(current, workInProgress, props), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 10: - return ( - (renderExpirationTime = workInProgress.pendingProps), - hasLegacyContextChanged() || - workInProgress.memoizedProps !== renderExpirationTime - ? (reconcileChildren( - current, + (oldContext = workInProgress.memoizedState)); + needsContext !== unmaskedContext || + oldState !== oldContext || + didPerformWorkStackCursor.current || + hasForceUpdate + ? ("function" === typeof getDerivedStateFromProps && + (applyDerivedStateFromProps( workInProgress, - renderExpirationTime + getDerivedStateFromProps, + unmaskedContext ), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 11: - return ( - (renderExpirationTime = workInProgress.pendingProps.children), - hasLegacyContextChanged() || - (null !== renderExpirationTime && - workInProgress.memoizedProps !== renderExpirationTime) - ? (reconcileChildren( - current, + (oldContext = workInProgress.memoizedState)), + (needsContext = + hasForceUpdate || + checkShouldComponentUpdate( + workInProgress, + needsContext, + unmaskedContext, + oldState, + oldContext, + props$jscomp$0 + )) + ? (ctor || + ("function" !== typeof fn.UNSAFE_componentWillMount && + "function" !== typeof fn.componentWillMount) || + ("function" === typeof fn.componentWillMount && + fn.componentWillMount(), + "function" === typeof fn.UNSAFE_componentWillMount && + fn.UNSAFE_componentWillMount()), + "function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4)) + : ("function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4), + (workInProgress.memoizedProps = unmaskedContext), + (workInProgress.memoizedState = oldContext)), + (fn.props = unmaskedContext), + (fn.state = oldContext), + (fn.context = props$jscomp$0), + (fn = needsContext)) + : ("function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4), + (fn = !1)); + } + else + (ctor = workInProgress.type), + (fn = workInProgress.stateNode), + (unmaskedContext = workInProgress.memoizedProps), + (needsContext = workInProgress.pendingProps), + (fn.props = unmaskedContext), + (oldContext = fn.context), + (props$jscomp$0 = getUnmaskedContext(workInProgress)), + (props$jscomp$0 = getMaskedContext(workInProgress, props$jscomp$0)), + (getDerivedStateFromProps = ctor.getDerivedStateFromProps), + (ctor = + "function" === typeof getDerivedStateFromProps || + "function" === typeof fn.getSnapshotBeforeUpdate) || + ("function" !== typeof fn.UNSAFE_componentWillReceiveProps && + "function" !== typeof fn.componentWillReceiveProps) || + ((unmaskedContext !== needsContext || + oldContext !== props$jscomp$0) && + callComponentWillReceiveProps( + workInProgress, + fn, + needsContext, + props$jscomp$0 + )), + (hasForceUpdate = !1), + (oldContext = workInProgress.memoizedState), + (oldState = fn.state = oldContext), + (updateQueue = workInProgress.updateQueue), + null !== updateQueue && + (processUpdateQueue( + workInProgress, + updateQueue, + needsContext, + fn, + renderExpirationTime + ), + (oldState = workInProgress.memoizedState)), + unmaskedContext !== needsContext || + oldContext !== oldState || + didPerformWorkStackCursor.current || + hasForceUpdate + ? ("function" === typeof getDerivedStateFromProps && + (applyDerivedStateFromProps( workInProgress, - renderExpirationTime + getDerivedStateFromProps, + needsContext ), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 15: - return ( - (renderExpirationTime = workInProgress.pendingProps), - workInProgress.memoizedProps === renderExpirationTime + (oldState = workInProgress.memoizedState)), + (getDerivedStateFromProps = + hasForceUpdate || + checkShouldComponentUpdate( + workInProgress, + unmaskedContext, + needsContext, + oldContext, + oldState, + props$jscomp$0 + )) + ? (ctor || + ("function" !== typeof fn.UNSAFE_componentWillUpdate && + "function" !== typeof fn.componentWillUpdate) || + ("function" === typeof fn.componentWillUpdate && + fn.componentWillUpdate( + needsContext, + oldState, + props$jscomp$0 + ), + "function" === typeof fn.UNSAFE_componentWillUpdate && + fn.UNSAFE_componentWillUpdate( + needsContext, + oldState, + props$jscomp$0 + )), + "function" === typeof fn.componentDidUpdate && + (workInProgress.effectTag |= 4), + "function" === typeof fn.getSnapshotBeforeUpdate && + (workInProgress.effectTag |= 256)) + : ("function" !== typeof fn.componentDidUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 4), + "function" !== typeof fn.getSnapshotBeforeUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 256), + (workInProgress.memoizedProps = needsContext), + (workInProgress.memoizedState = oldState)), + (fn.props = needsContext), + (fn.state = oldState), + (fn.context = props$jscomp$0), + (fn = getDerivedStateFromProps)) + : ("function" !== typeof fn.componentDidUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 4), + "function" !== typeof fn.getSnapshotBeforeUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 256), + (fn = !1)); + return finishClassComponent( + current, + workInProgress, + fn, + props, + renderExpirationTime + ); + case 3: + return ( + pushHostRootContext(workInProgress), + (props = workInProgress.updateQueue), + null !== props + ? ((fn = workInProgress.memoizedState), + (fn = null !== fn ? fn.element : null), + processUpdateQueue( + workInProgress, + props, + workInProgress.pendingProps, + null, + renderExpirationTime + ), + (renderExpirationTime = workInProgress.memoizedState.element), + renderExpirationTime === fn ? (current = bailoutOnAlreadyFinishedWork( current, workInProgress @@ -3598,347 +3718,403 @@ function ReactFiberBeginWork( : (reconcileChildren( current, workInProgress, - renderExpirationTime.children + renderExpirationTime ), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)), - current - ); - case 13: - return updateContextProvider( - current, - workInProgress, - renderExpirationTime - ); - case 12: - a: { - fn = workInProgress.type; - unmaskedContext = workInProgress.pendingProps; - memoizedProps = workInProgress.memoizedProps; - props = getContextCurrentValue(fn); - var changedBits = getContextChangedBits(fn); - if ( - hasLegacyContextChanged() || - 0 !== changedBits || - memoizedProps !== 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( + (current = workInProgress.child))) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 5: + return ( + requiredContext(rootInstanceStackCursor.current), + (renderExpirationTime = requiredContext(contextStackCursor$1.current)), + (props = workInProgress.type), + (props = + "AndroidTextInput" === props || + "RCTMultilineTextInputView" === props || + "RCTSinglelineTextInputView" === props || + "RCTText" === props || + "RCTVirtualText" === props), + (props = + renderExpirationTime.isInAParentText !== props + ? { isInAParentText: props } + : renderExpirationTime), + renderExpirationTime !== props && + (push(contextFiberStackCursor, workInProgress, workInProgress), + push(contextStackCursor$1, props, workInProgress)), + null === current && tryToClaimNextHydratableInstance(workInProgress), + (props = workInProgress.memoizedProps), + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || props !== renderExpirationTime + ? ((props = renderExpirationTime.children), + markRef(current, workInProgress), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 6: + return ( + null === current && tryToClaimNextHydratableInstance(workInProgress), + (workInProgress.memoizedProps = workInProgress.pendingProps), + null + ); + case 16: + return null; + case 4: + return ( + pushHostContainer( + workInProgress, + workInProgress.stateNode.containerInfo + ), + (props = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== props + ? (null === current + ? (workInProgress.child = reconcileChildFibers( workInProgress, - fn, - changedBits, + null, + props, renderExpirationTime - ); - else if (memoizedProps === unmaskedContext) { - current = bailoutOnAlreadyFinishedWork(current, workInProgress); - break a; - } - renderExpirationTime = unmaskedContext.children; - renderExpirationTime = renderExpirationTime(props); - workInProgress.effectTag |= 1; - reconcileChildren(current, workInProgress, renderExpirationTime); - current = workInProgress.child; - } else - current = bailoutOnAlreadyFinishedWork(current, workInProgress); - } - return current; - default: - invariant( - !1, - "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + )) + : reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = props), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 14: + return ( + (props = workInProgress.type.render), + (renderExpirationTime = workInProgress.pendingProps), + (fn = workInProgress.ref), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime || + fn !== (null !== current ? current.ref : null) + ? ((props = props(renderExpirationTime, fn)), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 10: + return ( + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime + ? (reconcileChildren(current, workInProgress, renderExpirationTime), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 11: + return ( + (renderExpirationTime = workInProgress.pendingProps.children), + didPerformWorkStackCursor.current || + (null !== renderExpirationTime && + workInProgress.memoizedProps !== renderExpirationTime) + ? (reconcileChildren(current, workInProgress, renderExpirationTime), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 15: + return ( + (renderExpirationTime = workInProgress.pendingProps), + workInProgress.memoizedProps === renderExpirationTime + ? (current = bailoutOnAlreadyFinishedWork(current, workInProgress)) + : (reconcileChildren( + current, + workInProgress, + renderExpirationTime.children + ), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)), + current + ); + case 13: + return updateContextProvider( + current, + workInProgress, + renderExpirationTime + ); + case 12: + a: if ( + ((fn = workInProgress.type), + (unmaskedContext = workInProgress.pendingProps), + (needsContext = workInProgress.memoizedProps), + (props = fn._currentValue2), + (props$jscomp$0 = fn._changedBits2), + didPerformWorkStackCursor.current || + 0 !== props$jscomp$0 || + needsContext !== unmaskedContext) + ) { + workInProgress.memoizedProps = unmaskedContext; + ctor = unmaskedContext.unstable_observedBits; + if (void 0 === ctor || null === ctor) ctor = 1073741823; + workInProgress.stateNode = ctor; + if (0 !== (props$jscomp$0 & ctor)) + propagateContextChange( + workInProgress, + fn, + props$jscomp$0, + renderExpirationTime ); - } - } - }; + else if (needsContext === unmaskedContext) { + current = bailoutOnAlreadyFinishedWork(current, workInProgress); + break a; + } + renderExpirationTime = unmaskedContext.children; + renderExpirationTime = renderExpirationTime(props); + workInProgress.effectTag |= 1; + reconcileChildren(current, workInProgress, renderExpirationTime); + current = workInProgress.child; + } else current = bailoutOnAlreadyFinishedWork(current, workInProgress); + return current; + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } } -function ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext -) { - function markUpdate(workInProgress) { - workInProgress.effectTag |= 4; +function appendAllChildren(parent, workInProgress) { + for (var node = workInProgress.child; null !== node; ) { + if (5 === node.tag || 6 === node.tag) + FabricUIManager.appendChild(parent.node, node.stateNode.node); + else if (4 !== node.tag && null !== node.child) { + node.child.return = node; + node = node.child; + continue; + } + if (node === workInProgress) break; + for (; null === node.sibling; ) { + if (null === node.return || node.return === workInProgress) return; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; } - function appendAllChildren(parent, workInProgress) { - for (var node = workInProgress.child; null !== node; ) { +} +var updateHostContainer = void 0, + updateHostComponent$1 = void 0, + updateHostText$1 = void 0; +updateHostContainer = function(workInProgress) { + var portalOrRoot = workInProgress.stateNode; + if (null !== workInProgress.firstEffect) { + var container = portalOrRoot.containerInfo, + newChildSet = FabricUIManager.createChildSet(container); + a: for (var node = workInProgress.child; null !== node; ) { if (5 === node.tag || 6 === node.tag) - appendInitialChild(parent, node.stateNode); + FabricUIManager.appendChildToSet(newChildSet, node.stateNode.node); else if (4 !== node.tag && null !== node.child) { node.child.return = node; node = node.child; continue; } - if (node === workInProgress) break; + if (node === workInProgress) break a; for (; null === node.sibling; ) { - if (null === node.return || node.return === workInProgress) return; + if (null === node.return || node.return === workInProgress) break a; node = node.return; } node.sibling.return = node.return; node = node.sibling; } + portalOrRoot.pendingChildren = newChildSet; + workInProgress.effectTag |= 4; + FabricUIManager.completeRoot(container, newChildSet); } - var createInstance = config.createInstance, - createTextInstance = config.createTextInstance, - appendInitialChild = config.appendInitialChild, - finalizeInitialChildren = config.finalizeInitialChildren, - prepareUpdate = config.prepareUpdate, - persistence = config.persistence, - getRootHostContainer = hostContext.getRootHostContainer, - popHostContext = hostContext.popHostContext, - getHostContext = hostContext.getHostContext, - popHostContainer = hostContext.popHostContainer, - popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popProvider = newContext.popProvider, - prepareToHydrateHostInstance = - hydrationContext.prepareToHydrateHostInstance, - prepareToHydrateHostTextInstance = - hydrationContext.prepareToHydrateHostTextInstance, - popHydrationState = hydrationContext.popHydrationState, - updateHostContainer = void 0, - updateHostComponent = void 0, - updateHostText = void 0; - if (config.mutation) invariant(!1, "Mutating reconciler is disabled."); - else if (persistence) { - var cloneInstance = persistence.cloneInstance, - createContainerChildSet = persistence.createContainerChildSet, - appendChildToContainerChildSet = - persistence.appendChildToContainerChildSet, - finalizeContainerChildren = persistence.finalizeContainerChildren; - updateHostContainer = function(workInProgress) { - var portalOrRoot = workInProgress.stateNode; - if (null !== workInProgress.firstEffect) { - var container = portalOrRoot.containerInfo, - newChildSet = createContainerChildSet(container); - a: for (var node = workInProgress.child; null !== node; ) { - if (5 === node.tag || 6 === node.tag) - appendChildToContainerChildSet(newChildSet, node.stateNode); - else if (4 !== node.tag && null !== node.child) { - node.child.return = node; - node = node.child; - continue; - } - if (node === workInProgress) break a; - for (; null === node.sibling; ) { - if (null === node.return || node.return === workInProgress) break a; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } - portalOrRoot.pendingChildren = newChildSet; - markUpdate(workInProgress); - finalizeContainerChildren(container, newChildSet); - } +}; +updateHostComponent$1 = function(current, workInProgress, updatePayload) { + var childrenUnchanged = null === workInProgress.firstEffect; + current = current.stateNode; + if (childrenUnchanged && null === updatePayload) + workInProgress.stateNode = current; + else { + var node = current.node; + updatePayload = { + node: childrenUnchanged + ? null !== updatePayload + ? FabricUIManager.cloneNodeWithNewProps( + node, + updatePayload, + workInProgress + ) + : FabricUIManager.cloneNode(node, workInProgress) + : null !== updatePayload + ? FabricUIManager.cloneNodeWithNewChildrenAndProps( + node, + updatePayload, + workInProgress + ) + : FabricUIManager.cloneNodeWithNewChildren(node, workInProgress), + canonical: current.canonical }; - updateHostComponent = function( + workInProgress.stateNode = updatePayload; + childrenUnchanged + ? (workInProgress.effectTag |= 4) + : appendAllChildren(updatePayload, workInProgress); + } +}; +updateHostText$1 = function(current, workInProgress, oldText, newText) { + oldText !== newText && + ((current = requiredContext(rootInstanceStackCursor.current)), + (oldText = requiredContext(contextStackCursor$1.current)), + (workInProgress.stateNode = createTextInstance( + newText, current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ) { - var childrenUnchanged = null === workInProgress.firstEffect; - current = current.stateNode; - childrenUnchanged && null === updatePayload - ? (workInProgress.stateNode = current) - : ((updatePayload = cloneInstance( - current, - updatePayload, - type, + oldText, + workInProgress + )), + (workInProgress.effectTag |= 4)); +}; +function completeWork(current, workInProgress) { + var newProps = workInProgress.pendingProps; + switch (workInProgress.tag) { + case 1: + return null; + case 2: + return popContextProvider(workInProgress), null; + case 3: + popHostContainer(workInProgress); + popTopLevelContextObject(workInProgress); + newProps = workInProgress.stateNode; + newProps.pendingContext && + ((newProps.context = newProps.pendingContext), + (newProps.pendingContext = null)); + if (null === current || null === current.child) + workInProgress.effectTag &= -3; + updateHostContainer(workInProgress); + return null; + case 5: + popHostContext(workInProgress); + var rootContainerInstance = requiredContext( + rootInstanceStackCursor.current + ), + type = workInProgress.type; + if (null !== current && null != workInProgress.stateNode) { + var oldProps = current.memoizedProps, + instance = workInProgress.stateNode, + currentHostContext = requiredContext(contextStackCursor$1.current), + updatePayload = diffProperties( + null, oldProps, newProps, - workInProgress, - childrenUnchanged, - workInProgress.stateNode - )), - finalizeInitialChildren( - updatePayload, - type, - newProps, - rootContainerInstance, - currentHostContext - ) && markUpdate(workInProgress), - (workInProgress.stateNode = updatePayload), - childrenUnchanged - ? markUpdate(workInProgress) - : appendAllChildren(updatePayload, workInProgress)); - }; - updateHostText = function(current, workInProgress, oldText, newText) { - oldText !== newText && - ((current = getRootHostContainer()), - (oldText = getHostContext()), - (workInProgress.stateNode = createTextInstance( - newText, + instance.canonical.viewConfig.validAttributes + ); + instance.canonical.currentProps = newProps; + updateHostComponent$1( current, - oldText, - workInProgress - )), - markUpdate(workInProgress)); - }; - } else invariant(!1, "Noop reconciler is disabled."); - return { - completeWork: function(current, workInProgress) { - var newProps = workInProgress.pendingProps; - switch (workInProgress.tag) { - case 1: - return null; - case 2: - return popLegacyContextProvider(workInProgress), null; - case 3: - popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); - newProps = workInProgress.stateNode; - newProps.pendingContext && - ((newProps.context = newProps.pendingContext), - (newProps.pendingContext = null)); - if (null === current || null === current.child) - popHydrationState(workInProgress), (workInProgress.effectTag &= -3); - updateHostContainer(workInProgress); - return null; - case 5: - popHostContext(workInProgress); - var rootContainerInstance = getRootHostContainer(), - type = workInProgress.type; - if (null !== current && null != workInProgress.stateNode) { - var oldProps = current.memoizedProps, - instance = workInProgress.stateNode, - currentHostContext = getHostContext(); - instance = prepareUpdate( - instance, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ); - updateHostComponent( - current, - workInProgress, - instance, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ); - current.ref !== workInProgress.ref && - (workInProgress.effectTag |= 128); - } else { - if (!newProps) - return ( - invariant( - null !== workInProgress.stateNode, - "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." - ), - null - ); - current = getHostContext(); - popHydrationState(workInProgress) - ? prepareToHydrateHostInstance( - workInProgress, - rootContainerInstance, - current - ) && markUpdate(workInProgress) - : ((oldProps = createInstance( - type, - newProps, - rootContainerInstance, - current, - workInProgress - )), - appendAllChildren(oldProps, workInProgress), - finalizeInitialChildren( - oldProps, - type, - newProps, - rootContainerInstance, - current - ) && markUpdate(workInProgress), - (workInProgress.stateNode = oldProps)); - null !== workInProgress.ref && (workInProgress.effectTag |= 128); - } - return null; - case 6: - if (current && null != workInProgress.stateNode) - updateHostText( - current, - workInProgress, - current.memoizedProps, - newProps - ); - else { - if ("string" !== typeof newProps) - return ( - invariant( - null !== workInProgress.stateNode, - "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." - ), - null - ); - rootContainerInstance = getRootHostContainer(); - type = getHostContext(); - popHydrationState(workInProgress) - ? prepareToHydrateHostTextInstance(workInProgress) && - markUpdate(workInProgress) - : (workInProgress.stateNode = createTextInstance( - newProps, - rootContainerInstance, - type, - workInProgress - )); - } - return null; - case 14: - return null; - case 16: - return null; - case 10: - return null; - case 11: - return null; - case 15: - return null; - case 4: + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ); + current.ref !== workInProgress.ref && (workInProgress.effectTag |= 128); + } else { + if (!newProps) return ( - popHostContainer(workInProgress), - updateHostContainer(workInProgress), + invariant( + null !== workInProgress.stateNode, + "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." + ), null ); - case 13: - return popProvider(workInProgress), null; - case 12: - return null; - case 0: - invariant( - !1, - "An indeterminate component should have become determinate before completing. This error is likely caused by a bug in React. Please file an issue." - ); - default: - invariant( - !1, - "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + instance = requiredContext(contextStackCursor$1.current); + current = nextReactTag; + nextReactTag += 2; + oldProps = ReactNativeViewConfigRegistry.get(type); + invariant( + "RCTView" !== type || !instance.isInAParentText, + "Nesting of within is not currently supported." + ); + type = diffProperties( + null, + emptyObject$1, + newProps, + oldProps.validAttributes + ); + rootContainerInstance = FabricUIManager.createNode( + current, + oldProps.uiViewClassName, + rootContainerInstance, + type, + workInProgress + ); + newProps = new ReactFabricHostComponent(current, oldProps, newProps); + newProps = { node: rootContainerInstance, canonical: newProps }; + appendAllChildren(newProps, workInProgress); + workInProgress.stateNode = newProps; + null !== workInProgress.ref && (workInProgress.effectTag |= 128); + } + return null; + case 6: + if (current && null != workInProgress.stateNode) + updateHostText$1( + current, + workInProgress, + current.memoizedProps, + newProps + ); + else { + if ("string" !== typeof newProps) + return ( + invariant( + null !== workInProgress.stateNode, + "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." + ), + null ); + rootContainerInstance = requiredContext( + rootInstanceStackCursor.current + ); + type = requiredContext(contextStackCursor$1.current); + workInProgress.stateNode = createTextInstance( + newProps, + rootContainerInstance, + type, + workInProgress + ); } - } - }; -} -function createCapturedValue(value, source) { - return { - value: value, - source: source, - stack: getStackAddendumByWorkInProgressFiber(source) - }; + return null; + case 14: + return null; + case 16: + return null; + case 10: + return null; + case 11: + return null; + case 15: + return null; + case 4: + return ( + popHostContainer(workInProgress), + updateHostContainer(workInProgress), + null + ); + case 13: + return popProvider(workInProgress), null; + case 12: + return null; + case 0: + invariant( + !1, + "An indeterminate component should have become determinate before completing. This error is likely caused by a bug in React. Please file an issue." + ); + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } } function logError(boundary, errorInfo) { var source = errorInfo.source, @@ -3966,2074 +4142,1290 @@ function logError(boundary, errorInfo) { "string" === typeof errorInfo ? Error(errorInfo + "\n\nThis error is located at:" + source) : Error("Unspecified error at:" + source); - ExceptionsManager.handleException(errorToHandle, !1); - } catch (e) { - (e && e.suppressReactErrorLogging) || console.error(e); - } -} -function ReactFiberCommitWork(config, captureError) { - function safelyDetachRef(current) { - var ref = current.ref; - if (null !== ref) - if ("function" === typeof ref) - try { - ref(null); - } catch (refError) { - captureError(current, refError); - } - else ref.current = null; - } - function commitBeforeMutationLifeCycles(current, finishedWork) { - switch (finishedWork.tag) { - case 2: - if (finishedWork.effectTag & 256 && 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." - ); - } - } - function commitLifeCycles( - finishedRoot, - current, - finishedWork, - currentTime, - committedExpirationTime - ) { - switch (finishedWork.tag) { - case 2: - finishedRoot = finishedWork.stateNode; - finishedWork.effectTag & 4 && - (null === current - ? ((finishedRoot.props = finishedWork.memoizedProps), - (finishedRoot.state = finishedWork.memoizedState), - finishedRoot.componentDidMount()) - : ((currentTime = current.memoizedProps), - (current = current.memoizedState), - (finishedRoot.props = finishedWork.memoizedProps), - (finishedRoot.state = finishedWork.memoizedState), - finishedRoot.componentDidUpdate( - currentTime, - current, - finishedRoot.__reactInternalSnapshotBeforeUpdate - ))); - current = finishedWork.updateQueue; - null !== current && - ((finishedRoot.props = finishedWork.memoizedProps), - (finishedRoot.state = finishedWork.memoizedState), - commitUpdateQueue( - finishedWork, - current, - finishedRoot, - committedExpirationTime - )); - break; - case 3: - current = finishedWork.updateQueue; - if (null !== current) { - finishedRoot = null; - if (null !== finishedWork.child) - switch (finishedWork.child.tag) { - case 5: - finishedRoot = getPublicInstance(finishedWork.child.stateNode); - break; - case 2: - finishedRoot = finishedWork.child.stateNode; - } - commitUpdateQueue( - finishedWork, - current, - finishedRoot, - committedExpirationTime - ); - } - break; - case 5: - committedExpirationTime = finishedWork.stateNode; - null === current && - finishedWork.effectTag & 4 && - commitMount( - committedExpirationTime, - finishedWork.type, - finishedWork.memoizedProps, - finishedWork - ); - break; - case 6: - break; - case 4: - break; - case 15: - break; - case 16: - 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." - ); - } + ExceptionsManager.handleException(errorToHandle, !1); + } catch (e) { + (e && e.suppressReactErrorLogging) || console.error(e); } - function commitAttachRef(finishedWork) { - var ref = finishedWork.ref; - if (null !== ref) { - var _instance5 = finishedWork.stateNode; - switch (finishedWork.tag) { - case 5: - finishedWork = getPublicInstance(_instance5); - break; - default: - finishedWork = _instance5; +} +function safelyDetachRef(current) { + var ref = current.ref; + if (null !== ref) + if ("function" === typeof ref) + try { + ref(null); + } catch (refError) { + captureCommitPhaseError(current, refError); } - "function" === typeof ref - ? ref(finishedWork) - : (ref.current = finishedWork); - } - } - function commitDetachRef(current) { - current = current.ref; - null !== current && - ("function" === typeof current - ? current(null) - : (current.current = null)); - } - var getPublicInstance = config.getPublicInstance, - mutation = config.mutation, - persistence = config.persistence, - emptyPortalContainer = void 0; - if (!mutation) { - var commitContainer = void 0; - if (persistence) { - var replaceContainerChildren = persistence.replaceContainerChildren, - createContainerChildSet = persistence.createContainerChildSet; - emptyPortalContainer = function(current) { - current = current.stateNode.containerInfo; - var emptyChildSet = createContainerChildSet(current); - replaceContainerChildren(current, emptyChildSet); - }; - commitContainer = function(finishedWork) { - switch (finishedWork.tag) { - case 2: - break; - case 5: - break; - case 6: - break; - case 3: - case 4: - finishedWork = finishedWork.stateNode; - replaceContainerChildren( - finishedWork.containerInfo, - finishedWork.pendingChildren - ); - 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 commitContainer = function() {}; - return { - commitResetTextContent: function() {}, - commitPlacement: function() {}, - commitDeletion: function(current$jscomp$0) { - a: for (var node = current$jscomp$0; ; ) { - var current = node; - "function" === typeof onCommitUnmount && onCommitUnmount(current); - switch (current.tag) { - case 2: - safelyDetachRef(current); - var _instance6 = current.stateNode; - if ("function" === typeof _instance6.componentWillUnmount) - try { - (_instance6.props = current.memoizedProps), - (_instance6.state = current.memoizedState), - _instance6.componentWillUnmount(); - } catch (unmountError) { - captureError(current, unmountError); - } - break; - case 5: - safelyDetachRef(current); - break; - case 4: - persistence && emptyPortalContainer(current); - } - if (null === node.child || (mutation && 4 === node.tag)) { - if (node === current$jscomp$0) break; - for (; null === node.sibling; ) { - if (null === node.return || node.return === current$jscomp$0) - break a; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } else (node.child.return = node), (node = node.child); - } - current$jscomp$0.return = null; - current$jscomp$0.child = null; - current$jscomp$0.alternate && - ((current$jscomp$0.alternate.child = null), - (current$jscomp$0.alternate.return = null)); - }, - commitWork: function(current, finishedWork) { - commitContainer(finishedWork); - }, - commitLifeCycles: commitLifeCycles, - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, - commitAttachRef: commitAttachRef, - commitDetachRef: commitDetachRef - }; + else ref.current = null; +} +function commitWork(current, finishedWork) { + switch (finishedWork.tag) { + case 2: + break; + case 5: + break; + case 6: + break; + case 3: + 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." + ); } - var commitMount = mutation.commitMount; - invariant(!1, "Mutating reconciler is disabled."); } -function ReactFiberUnwindWork( - config, - hostContext, - legacyContext, - newContext, - scheduleWork, - computeExpirationForFiber, - recalculateCurrentTime, - markLegacyErrorBoundaryAsFailed, - isAlreadyFailedLegacyErrorBoundary, - onUncaughtError -) { - function createRootErrorUpdate(fiber, errorInfo, expirationTime) { - expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; - expirationTime.payload = { element: null }; - var error = errorInfo.value; - expirationTime.callback = function() { - onUncaughtError(error); +function createRootErrorUpdate(fiber, errorInfo, expirationTime) { + expirationTime = createUpdate(expirationTime); + expirationTime.tag = 3; + expirationTime.payload = { element: null }; + var error = errorInfo.value; + expirationTime.callback = function() { + onUncaughtError(error); + logError(fiber, errorInfo); + }; + return expirationTime; +} +function createClassErrorUpdate(fiber, errorInfo, expirationTime) { + expirationTime = createUpdate(expirationTime); + expirationTime.tag = 3; + var inst = fiber.stateNode; + null !== inst && + "function" === typeof inst.componentDidCatch && + (expirationTime.callback = function() { + null === legacyErrorBoundariesThatAlreadyFailed + ? (legacyErrorBoundariesThatAlreadyFailed = new Set([this])) + : legacyErrorBoundariesThatAlreadyFailed.add(this); + var error = errorInfo.value, + stack = errorInfo.stack; logError(fiber, errorInfo); - }; - return expirationTime; - } - function createClassErrorUpdate(fiber, errorInfo, expirationTime) { - expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; - var inst = fiber.stateNode; - null !== inst && - "function" === typeof inst.componentDidCatch && - (expirationTime.callback = function() { - markLegacyErrorBoundaryAsFailed(this); - var error = errorInfo.value, - stack = errorInfo.stack; - logError(fiber, errorInfo); - this.componentDidCatch(error, { - componentStack: null !== stack ? stack : "" - }); + this.componentDidCatch(error, { + componentStack: null !== stack ? stack : "" }); - return expirationTime; + }); + return expirationTime; +} +function unwindWork(workInProgress) { + switch (workInProgress.tag) { + case 2: + popContextProvider(workInProgress); + var effectTag = workInProgress.effectTag; + return effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null; + case 3: + return ( + popHostContainer(workInProgress), + popTopLevelContextObject(workInProgress), + (effectTag = workInProgress.effectTag), + effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null + ); + case 5: + return popHostContext(workInProgress), null; + case 16: + return ( + (effectTag = workInProgress.effectTag), + effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null + ); + case 4: + return popHostContainer(workInProgress), null; + case 13: + return popProvider(workInProgress), null; + default: + return null; } - var popHostContainer = hostContext.popHostContainer, - popHostContext = hostContext.popHostContext, - popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popProvider = newContext.popProvider; - return { - throwException: function( - root, - returnFiber, - sourceFiber, - value, - renderIsExpired, - renderExpirationTime +} +var originalStartTimeMs = now$1(), + mostRecentCurrentTime = 2, + mostRecentCurrentTimeMs = originalStartTimeMs, + lastUniqueAsyncExpiration = 0, + expirationContext = 0, + isWorking = !1, + nextUnitOfWork = null, + nextRoot = null, + nextRenderExpirationTime = 0, + nextLatestTimeoutMs = -1, + nextRenderDidError = !1, + nextEffect = null, + isCommitting$1 = !1, + legacyErrorBoundariesThatAlreadyFailed = null; +function resetStack() { + if (null !== nextUnitOfWork) + for ( + var interruptedWork = nextUnitOfWork.return; + null !== interruptedWork; + ) { - sourceFiber.effectTag |= 512; - sourceFiber.firstEffect = sourceFiber.lastEffect = null; - value = createCapturedValue(value, sourceFiber); - root = returnFiber; - do { - switch (root.tag) { - case 3: - root.effectTag |= 1024; - value = createRootErrorUpdate(root, value, renderExpirationTime); - enqueueCapturedUpdate(root, value, renderExpirationTime); - return; - case 2: - if ( - ((returnFiber = value), - (sourceFiber = root.stateNode), - 0 === (root.effectTag & 64) && - null !== sourceFiber && - "function" === typeof sourceFiber.componentDidCatch && - !isAlreadyFailedLegacyErrorBoundary(sourceFiber)) - ) { - root.effectTag |= 1024; - value = createClassErrorUpdate( - root, - returnFiber, - renderExpirationTime - ); - enqueueCapturedUpdate(root, value, renderExpirationTime); - return; - } - } - root = root.return; - } while (null !== root); - }, - unwindWork: function(workInProgress) { - switch (workInProgress.tag) { - case 2: - popLegacyContextProvider(workInProgress); - var effectTag = workInProgress.effectTag; - return effectTag & 1024 - ? ((workInProgress.effectTag = (effectTag & -1025) | 64), - workInProgress) - : null; - case 3: - return ( - popHostContainer(workInProgress), - popTopLevelLegacyContextObject(workInProgress), - (effectTag = workInProgress.effectTag), - effectTag & 1024 - ? ((workInProgress.effectTag = (effectTag & -1025) | 64), - workInProgress) - : null - ); - case 5: - return popHostContext(workInProgress), null; - case 16: - return ( - (effectTag = workInProgress.effectTag), - effectTag & 1024 - ? ((workInProgress.effectTag = (effectTag & -1025) | 64), - workInProgress) - : null - ); - case 4: - return popHostContainer(workInProgress), null; - case 13: - return popProvider(workInProgress), null; - default: - return null; - } - }, - unwindInterruptedWork: function(interruptedWork) { - switch (interruptedWork.tag) { + var interruptedWork$jscomp$0 = interruptedWork; + switch (interruptedWork$jscomp$0.tag) { case 2: - popLegacyContextProvider(interruptedWork); + popContextProvider(interruptedWork$jscomp$0); break; case 3: - popHostContainer(interruptedWork); - popTopLevelLegacyContextObject(interruptedWork); + popHostContainer(interruptedWork$jscomp$0); + popTopLevelContextObject(interruptedWork$jscomp$0); break; case 5: - popHostContext(interruptedWork); + popHostContext(interruptedWork$jscomp$0); break; case 4: - popHostContainer(interruptedWork); + popHostContainer(interruptedWork$jscomp$0); break; case 13: - popProvider(interruptedWork); - } - }, - createRootErrorUpdate: createRootErrorUpdate, - createClassErrorUpdate: createClassErrorUpdate - }; -} -var NO_CONTEXT = {}; -function ReactFiberHostContext(config, stack) { - function requiredContext(c) { - invariant( - c !== NO_CONTEXT, - "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." - ); - 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); - return { - getHostContext: function() { - return requiredContext(contextStackCursor.current); - }, - getRootHostContainer: function() { - return requiredContext(rootInstanceStackCursor.current); - }, - popHostContainer: function(fiber) { - pop(contextStackCursor, fiber); - pop(contextFiberStackCursor, fiber); - pop(rootInstanceStackCursor, fiber); - }, - popHostContext: function(fiber) { - contextFiberStackCursor.current === fiber && - (pop(contextStackCursor, fiber), pop(contextFiberStackCursor, fiber)); - }, - pushHostContainer: function(fiber, nextRootInstance) { - push(rootInstanceStackCursor, nextRootInstance, fiber); - push(contextFiberStackCursor, fiber, fiber); - push(contextStackCursor, NO_CONTEXT, fiber); - nextRootInstance = getRootHostContext(nextRootInstance); - pop(contextStackCursor, fiber); - push(contextStackCursor, nextRootInstance, fiber); - }, - pushHostContext: function(fiber) { - var rootInstance = requiredContext(rootInstanceStackCursor.current), - context = requiredContext(contextStackCursor.current); - rootInstance = getChildHostContext(context, fiber.type, rootInstance); - context !== rootInstance && - (push(contextFiberStackCursor, fiber, fiber), - push(contextStackCursor, rootInstance, fiber)); - } - }; -} -function ReactFiberHydrationContext(config) { - function deleteHydratableInstance(returnFiber, instance) { - var fiber = new FiberNode(5, null, null, 0); - fiber.type = "DELETED"; - fiber.stateNode = instance; - fiber.return = returnFiber; - fiber.effectTag = 8; - null !== returnFiber.lastEffect - ? ((returnFiber.lastEffect.nextEffect = fiber), - (returnFiber.lastEffect = fiber)) - : (returnFiber.firstEffect = returnFiber.lastEffect = fiber); - } - function tryHydrate(fiber, nextInstance) { - switch (fiber.tag) { - case 5: - return ( - (nextInstance = canHydrateInstance( - nextInstance, - fiber.type, - fiber.pendingProps - )), - null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 - ); - case 6: - return ( - (nextInstance = canHydrateTextInstance( - nextInstance, - fiber.pendingProps - )), - null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 - ); - default: - return !1; - } - } - function popToNextHostParent(fiber) { - for ( - fiber = fiber.return; - null !== fiber && 5 !== fiber.tag && 3 !== fiber.tag; - - ) - fiber = fiber.return; - hydrationParentFiber = fiber; - } - var shouldSetTextContent = config.shouldSetTextContent; - config = config.hydration; - if (!config) - return { - enterHydrationState: function() { - return !1; - }, - resetHydrationState: function() {}, - tryToClaimNextHydratableInstance: function() {}, - prepareToHydrateHostInstance: function() { - invariant( - !1, - "Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue." - ); - }, - prepareToHydrateHostTextInstance: function() { - invariant( - !1, - "Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue." - ); - }, - popHydrationState: function() { - return !1; - } - }; - var canHydrateInstance = config.canHydrateInstance, - canHydrateTextInstance = config.canHydrateTextInstance, - getNextHydratableSibling = config.getNextHydratableSibling, - getFirstHydratableChild = config.getFirstHydratableChild, - hydrateInstance = config.hydrateInstance, - hydrateTextInstance = config.hydrateTextInstance, - hydrationParentFiber = null, - nextHydratableInstance = null, - isHydrating = !1; - return { - enterHydrationState: function(fiber) { - nextHydratableInstance = getFirstHydratableChild( - fiber.stateNode.containerInfo - ); - hydrationParentFiber = fiber; - return (isHydrating = !0); - }, - resetHydrationState: function() { - nextHydratableInstance = hydrationParentFiber = null; - isHydrating = !1; - }, - tryToClaimNextHydratableInstance: function(fiber) { - if (isHydrating) { - var nextInstance = nextHydratableInstance; - if (nextInstance) { - if (!tryHydrate(fiber, nextInstance)) { - nextInstance = getNextHydratableSibling(nextInstance); - if (!nextInstance || !tryHydrate(fiber, nextInstance)) { - fiber.effectTag |= 2; - isHydrating = !1; - hydrationParentFiber = fiber; - return; - } - deleteHydratableInstance( - hydrationParentFiber, - nextHydratableInstance - ); - } - hydrationParentFiber = fiber; - nextHydratableInstance = getFirstHydratableChild(nextInstance); - } else - (fiber.effectTag |= 2), - (isHydrating = !1), - (hydrationParentFiber = fiber); + popProvider(interruptedWork$jscomp$0); } - }, - prepareToHydrateHostInstance: function( - fiber, - rootContainerInstance, - hostContext - ) { - rootContainerInstance = hydrateInstance( - fiber.stateNode, - fiber.type, - fiber.memoizedProps, - rootContainerInstance, - hostContext, - fiber - ); - fiber.updateQueue = rootContainerInstance; - return null !== rootContainerInstance ? !0 : !1; - }, - prepareToHydrateHostTextInstance: function(fiber) { - return hydrateTextInstance(fiber.stateNode, fiber.memoizedProps, fiber); - }, - popHydrationState: function(fiber) { - if (fiber !== hydrationParentFiber) return !1; - if (!isHydrating) - return popToNextHostParent(fiber), (isHydrating = !0), !1; - var type = fiber.type; - if ( - 5 !== fiber.tag || - ("head" !== type && - "body" !== type && - !shouldSetTextContent(type, fiber.memoizedProps)) - ) - for (type = nextHydratableInstance; type; ) - deleteHydratableInstance(fiber, type), - (type = getNextHydratableSibling(type)); - popToNextHostParent(fiber); - nextHydratableInstance = hydrationParentFiber - ? getNextHydratableSibling(fiber.stateNode) - : null; - return !0; + interruptedWork = interruptedWork.return; } - }; + nextRoot = null; + nextRenderExpirationTime = 0; + nextLatestTimeoutMs = -1; + nextRenderDidError = !1; + nextUnitOfWork = null; } -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 +function completeUnitOfWork(workInProgress$jscomp$0) { + for (;;) { + var current = workInProgress$jscomp$0.alternate, + returnFiber = workInProgress$jscomp$0.return, + siblingFiber = workInProgress$jscomp$0.sibling; + if (0 === (workInProgress$jscomp$0.effectTag & 512)) { + current = completeWork( + current, + workInProgress$jscomp$0, + nextRenderExpirationTime ); - 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; + var workInProgress = workInProgress$jscomp$0; 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; - + 1073741823 === nextRenderExpirationTime || + 1073741823 !== workInProgress.expirationTime ) { - 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, isPrimaryRenderer) { - 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; - isPrimaryRenderer - ? (push(changedBitsCursor, context._changedBits, providerFiber), - push(valueCursor, context._currentValue, providerFiber), - push(providerCursor, providerFiber, providerFiber), - (context._currentValue = providerFiber.pendingProps.value), - (context._changedBits = providerFiber.stateNode)) - : (push(changedBitsCursor, context._changedBits2, providerFiber), - push(valueCursor, context._currentValue2, providerFiber), - push(providerCursor, providerFiber, providerFiber), - (context._currentValue2 = providerFiber.pendingProps.value), - (context._changedBits2 = 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; - isPrimaryRenderer - ? ((providerFiber._currentValue = currentValue), - (providerFiber._changedBits = changedBits)) - : ((providerFiber._currentValue2 = currentValue), - (providerFiber._changedBits2 = changedBits)); - }, - getContextCurrentValue: function(context) { - return isPrimaryRenderer ? context._currentValue : context._currentValue2; - }, - getContextChangedBits: function(context) { - return isPrimaryRenderer ? context._changedBits : context._changedBits2; - } - }; -} -function ReactFiberStack() { - var valueStack = [], - index = -1; - return { - createCursor: function(defaultValue) { - return { current: defaultValue }; - }, - isEmpty: function() { - return -1 === index; - }, - pop: function(cursor) { - 0 > index || - ((cursor.current = valueStack[index]), - (valueStack[index] = null), - index--); - }, - push: function(cursor, value) { - index++; - valueStack[index] = cursor.current; - cursor.current = value; - }, - checkThatStackIsEmpty: function() {}, - resetStackAfterFatalErrorInDev: function() {} - }; -} -function ReactFiberScheduler(config) { - function resetStack() { - if (null !== nextUnitOfWork) - for ( - var interruptedWork = nextUnitOfWork.return; - null !== interruptedWork; - - ) - unwindInterruptedWork(interruptedWork), - (interruptedWork = interruptedWork.return); - nextRoot = null; - nextRenderExpirationTime = 0; - nextLatestTimeoutMs = -1; - nextRenderIsExpired = !1; - nextUnitOfWork = null; - isRootReadyForCommit = !1; - } - function isAlreadyFailedLegacyErrorBoundary(instance) { - return ( - null !== legacyErrorBoundariesThatAlreadyFailed && - legacyErrorBoundariesThatAlreadyFailed.has(instance) - ); - } - function markLegacyErrorBoundaryAsFailed(instance) { - null === legacyErrorBoundariesThatAlreadyFailed - ? (legacyErrorBoundariesThatAlreadyFailed = new Set([instance])) - : legacyErrorBoundariesThatAlreadyFailed.add(instance); - } - function completeUnitOfWork(workInProgress$jscomp$0) { - for (;;) { - var current = workInProgress$jscomp$0.alternate, - returnFiber = workInProgress$jscomp$0.return, - siblingFiber = workInProgress$jscomp$0.sibling; - if (0 === (workInProgress$jscomp$0.effectTag & 512)) { - current = completeWork( - current, - workInProgress$jscomp$0, - nextRenderExpirationTime - ); - var workInProgress = workInProgress$jscomp$0; - if ( - 1073741823 === nextRenderExpirationTime || - 1073741823 !== workInProgress.expirationTime - ) { - var newExpirationTime = 0; - switch (workInProgress.tag) { - case 3: - case 2: - var updateQueue = workInProgress.updateQueue; - null !== updateQueue && - (newExpirationTime = updateQueue.expirationTime); - } - for (updateQueue = workInProgress.child; null !== updateQueue; ) - 0 !== updateQueue.expirationTime && - (0 === newExpirationTime || - newExpirationTime > updateQueue.expirationTime) && - (newExpirationTime = updateQueue.expirationTime), - (updateQueue = updateQueue.sibling); - workInProgress.expirationTime = newExpirationTime; - } - if (null !== current) return current; - null !== returnFiber && - 0 === (returnFiber.effectTag & 512) && - (null === returnFiber.firstEffect && - (returnFiber.firstEffect = workInProgress$jscomp$0.firstEffect), - null !== workInProgress$jscomp$0.lastEffect && - (null !== returnFiber.lastEffect && - (returnFiber.lastEffect.nextEffect = - workInProgress$jscomp$0.firstEffect), - (returnFiber.lastEffect = workInProgress$jscomp$0.lastEffect)), - 1 < workInProgress$jscomp$0.effectTag && - (null !== returnFiber.lastEffect - ? (returnFiber.lastEffect.nextEffect = workInProgress$jscomp$0) - : (returnFiber.firstEffect = workInProgress$jscomp$0), - (returnFiber.lastEffect = workInProgress$jscomp$0))); - if (null !== siblingFiber) return siblingFiber; - if (null !== returnFiber) workInProgress$jscomp$0 = returnFiber; - else { - isRootReadyForCommit = !0; - break; + var newExpirationTime = 0; + switch (workInProgress.tag) { + case 3: + case 2: + var updateQueue = workInProgress.updateQueue; + null !== updateQueue && + (newExpirationTime = updateQueue.expirationTime); } - } else { - workInProgress$jscomp$0 = unwindWork( - workInProgress$jscomp$0, - nextRenderIsExpired, - nextRenderExpirationTime - ); - if (null !== workInProgress$jscomp$0) - return ( - (workInProgress$jscomp$0.effectTag &= 511), workInProgress$jscomp$0 - ); - null !== returnFiber && - ((returnFiber.firstEffect = returnFiber.lastEffect = null), - (returnFiber.effectTag |= 512)); - if (null !== siblingFiber) return siblingFiber; - if (null !== returnFiber) workInProgress$jscomp$0 = returnFiber; - else break; + for (updateQueue = workInProgress.child; null !== updateQueue; ) + 0 !== updateQueue.expirationTime && + (0 === newExpirationTime || + newExpirationTime > updateQueue.expirationTime) && + (newExpirationTime = updateQueue.expirationTime), + (updateQueue = updateQueue.sibling); + workInProgress.expirationTime = newExpirationTime; } + if (null !== current) return current; + null !== returnFiber && + 0 === (returnFiber.effectTag & 512) && + (null === returnFiber.firstEffect && + (returnFiber.firstEffect = workInProgress$jscomp$0.firstEffect), + null !== workInProgress$jscomp$0.lastEffect && + (null !== returnFiber.lastEffect && + (returnFiber.lastEffect.nextEffect = + workInProgress$jscomp$0.firstEffect), + (returnFiber.lastEffect = workInProgress$jscomp$0.lastEffect)), + 1 < workInProgress$jscomp$0.effectTag && + (null !== returnFiber.lastEffect + ? (returnFiber.lastEffect.nextEffect = workInProgress$jscomp$0) + : (returnFiber.firstEffect = workInProgress$jscomp$0), + (returnFiber.lastEffect = workInProgress$jscomp$0))); + } else { + workInProgress$jscomp$0 = unwindWork( + workInProgress$jscomp$0, + nextRenderExpirationTime + ); + if (null !== workInProgress$jscomp$0) + return ( + (workInProgress$jscomp$0.effectTag &= 511), workInProgress$jscomp$0 + ); + null !== returnFiber && + ((returnFiber.firstEffect = returnFiber.lastEffect = null), + (returnFiber.effectTag |= 512)); } - return null; + if (null !== siblingFiber) return siblingFiber; + if (null !== returnFiber) workInProgress$jscomp$0 = returnFiber; + else break; } - function performUnitOfWork(workInProgress) { - var next = beginWork( - workInProgress.alternate, - workInProgress, - nextRenderExpirationTime - ); - null === next && (next = completeUnitOfWork(workInProgress)); - ReactCurrentOwner.current = null; - return next; - } - function renderRoot(root, expirationTime, isAsync) { - invariant( - !isWorking, - "renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." - ); - isWorking = !0; - if ( - expirationTime !== nextRenderExpirationTime || - root !== nextRoot || - null === nextUnitOfWork - ) - resetStack(), - (nextRoot = root), - (nextRenderExpirationTime = expirationTime), - (nextLatestTimeoutMs = -1), - (nextUnitOfWork = createWorkInProgress( - nextRoot.current, - null, - nextRenderExpirationTime - )), - (root.pendingCommitExpirationTime = 0); - var didFatal = !1; - nextRenderIsExpired = - !isAsync || nextRenderExpirationTime <= mostRecentCurrentTime; - do { - try { - if (isAsync) - for (; null !== nextUnitOfWork && !shouldYield(); ) - nextUnitOfWork = performUnitOfWork(nextUnitOfWork); - else - for (; null !== nextUnitOfWork; ) - nextUnitOfWork = performUnitOfWork(nextUnitOfWork); - } catch (thrownValue) { - if (null === nextUnitOfWork) - (didFatal = !0), onUncaughtError(thrownValue); - else { - invariant( - null !== nextUnitOfWork, - "Failed to replay rendering after an error. This is likely caused by a bug in React. Please file an issue with a reproducing case to help us find it." - ); - isAsync = nextUnitOfWork; - var returnFiber = isAsync.return; - if (null === returnFiber) { - didFatal = !0; - onUncaughtError(thrownValue); - break; + return null; +} +function performUnitOfWork(workInProgress) { + var next = beginWork( + workInProgress.alternate, + workInProgress, + nextRenderExpirationTime + ); + null === next && (next = completeUnitOfWork(workInProgress)); + ReactCurrentOwner.current = null; + return next; +} +function renderRoot(root$jscomp$0, isYieldy) { + invariant( + !isWorking, + "renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." + ); + isWorking = !0; + var expirationTime = root$jscomp$0.nextExpirationTimeToWorkOn; + if ( + expirationTime !== nextRenderExpirationTime || + root$jscomp$0 !== nextRoot || + null === nextUnitOfWork + ) + resetStack(), + (nextRoot = root$jscomp$0), + (nextRenderExpirationTime = expirationTime), + (nextLatestTimeoutMs = -1), + (nextRenderDidError = !1), + (nextUnitOfWork = createWorkInProgress( + nextRoot.current, + null, + nextRenderExpirationTime + )), + (root$jscomp$0.pendingCommitExpirationTime = 0); + var didFatal = !1; + do { + try { + if (isYieldy) + for (; null !== nextUnitOfWork && !shouldYield(); ) + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + else + for (; null !== nextUnitOfWork; ) + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + } catch (thrownValue) { + if (null === nextUnitOfWork) + (didFatal = !0), onUncaughtError(thrownValue); + else { + invariant( + null !== nextUnitOfWork, + "Failed to replay rendering after an error. This is likely caused by a bug in React. Please file an issue with a reproducing case to help us find it." + ); + isYieldy = nextUnitOfWork; + var returnFiber = isYieldy.return; + if (null === returnFiber) { + didFatal = !0; + onUncaughtError(thrownValue); + break; + } + a: { + var root = root$jscomp$0, + returnFiber$jscomp$0 = returnFiber, + sourceFiber = isYieldy, + value = thrownValue; + returnFiber = nextRenderExpirationTime; + sourceFiber.effectTag |= 512; + sourceFiber.firstEffect = sourceFiber.lastEffect = null; + nextRenderDidError = !0; + if ( + (root.didError || 1 === returnFiber) && + (returnFiber === root.latestPendingTime || + returnFiber === root.latestSuspendedTime) + ) { + value = createCapturedValue(value, sourceFiber); + root = returnFiber$jscomp$0; + do { + switch (root.tag) { + case 3: + root.effectTag |= 1024; + value = createRootErrorUpdate(root, value, returnFiber); + enqueueCapturedUpdate(root, value, returnFiber); + break a; + case 2: + if ( + ((returnFiber$jscomp$0 = value), + (sourceFiber = root.stateNode), + 0 === (root.effectTag & 64) && + null !== sourceFiber && + "function" === typeof sourceFiber.componentDidCatch && + (null === legacyErrorBoundariesThatAlreadyFailed || + !legacyErrorBoundariesThatAlreadyFailed.has( + sourceFiber + ))) + ) { + root.effectTag |= 1024; + value = createClassErrorUpdate( + root, + returnFiber$jscomp$0, + returnFiber + ); + enqueueCapturedUpdate(root, value, returnFiber); + break a; + } + } + root = root.return; + } while (null !== root); } - throwException( - root, - returnFiber, - isAsync, - thrownValue, - nextRenderIsExpired, - nextRenderExpirationTime, - mostRecentCurrentTimeMs - ); - nextUnitOfWork = completeUnitOfWork(isAsync); } + nextUnitOfWork = completeUnitOfWork(isYieldy); } - break; - } while (1); - isWorking = !1; - if (didFatal) return null; - if (null === nextUnitOfWork) { - if (isRootReadyForCommit) - return ( - (root.pendingCommitExpirationTime = expirationTime), - root.current.alternate - ); - invariant( - !nextRenderIsExpired, - "Expired work should have completed. This error is likely caused by a bug in React. Please file an issue." - ); - 0 <= nextLatestTimeoutMs && - setTimeout(function() { - retrySuspendedRoot(root, expirationTime); - }, nextLatestTimeoutMs); - onBlock(root.current.expirationTime); } - return null; - } - function onCommitPhaseError(fiber, error) { - var JSCompiler_inline_result; - a: { - invariant( - !isWorking || isCommitting, - "dispatch: Cannot dispatch during the render phase." - ); - for ( - JSCompiler_inline_result = fiber.return; - null !== JSCompiler_inline_result; + break; + } while (1); + isWorking = !1; + didFatal + ? (root$jscomp$0.finishedWork = null) + : null === nextUnitOfWork + ? ((didFatal = root$jscomp$0.current.alternate), + invariant( + null !== didFatal, + "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue." + ), + 0 === (didFatal.effectTag & 512) + ? ((root$jscomp$0.pendingCommitExpirationTime = expirationTime), + (root$jscomp$0.finishedWork = didFatal)) + : (!nextRenderDidError || + (expirationTime !== root$jscomp$0.latestPendingTime && + expirationTime !== root$jscomp$0.latestSuspendedTime) + ? ((didFatal = root$jscomp$0.earliestPendingTime), + (isYieldy = root$jscomp$0.latestPendingTime), + didFatal === expirationTime + ? (root$jscomp$0.earliestPendingTime = + isYieldy === expirationTime + ? (root$jscomp$0.latestPendingTime = 0) + : isYieldy) + : isYieldy === expirationTime && + (root$jscomp$0.latestPendingTime = didFatal), + (didFatal = root$jscomp$0.latestSuspendedTime), + didFatal === expirationTime && + (root$jscomp$0.latestPingedTime = 0), + (isYieldy = root$jscomp$0.earliestSuspendedTime), + 0 === isYieldy + ? (root$jscomp$0.earliestSuspendedTime = root$jscomp$0.latestSuspendedTime = expirationTime) + : isYieldy > expirationTime + ? (root$jscomp$0.earliestSuspendedTime = expirationTime) + : didFatal < expirationTime && + (root$jscomp$0.latestSuspendedTime = expirationTime)) + : (root$jscomp$0.didError = !0), + findNextPendingPriorityLevel(root$jscomp$0), + onSuspend( + root$jscomp$0, + expirationTime, + root$jscomp$0.expirationTime, + nextLatestTimeoutMs + ))) + : (root$jscomp$0.finishedWork = null); +} +function captureCommitPhaseError(fiber, error) { + var JSCompiler_inline_result; + a: { + invariant( + !isWorking || isCommitting$1, + "dispatch: Cannot dispatch during the render phase." + ); + for ( + JSCompiler_inline_result = fiber.return; + null !== JSCompiler_inline_result; - ) { - switch (JSCompiler_inline_result.tag) { - case 2: - var instance = JSCompiler_inline_result.stateNode; - if ( - "function" === - typeof JSCompiler_inline_result.type.getDerivedStateFromCatch || - ("function" === typeof instance.componentDidCatch && - !isAlreadyFailedLegacyErrorBoundary(instance)) - ) { - fiber = createCapturedValue(error, fiber); - fiber = createClassErrorUpdate( - JSCompiler_inline_result, - fiber, - 1 - ); - enqueueUpdate(JSCompiler_inline_result, fiber, 1); - scheduleWork(JSCompiler_inline_result, 1); - JSCompiler_inline_result = void 0; - break a; - } - break; - case 3: + ) { + switch (JSCompiler_inline_result.tag) { + case 2: + var instance = JSCompiler_inline_result.stateNode; + if ( + "function" === + typeof JSCompiler_inline_result.type.getDerivedStateFromCatch || + ("function" === typeof instance.componentDidCatch && + (null === legacyErrorBoundariesThatAlreadyFailed || + !legacyErrorBoundariesThatAlreadyFailed.has(instance))) + ) { fiber = createCapturedValue(error, fiber); - fiber = createRootErrorUpdate(JSCompiler_inline_result, fiber, 1); + fiber = createClassErrorUpdate(JSCompiler_inline_result, fiber, 1); enqueueUpdate(JSCompiler_inline_result, fiber, 1); scheduleWork(JSCompiler_inline_result, 1); JSCompiler_inline_result = void 0; break a; - } - JSCompiler_inline_result = JSCompiler_inline_result.return; + } + break; + case 3: + fiber = createCapturedValue(error, fiber); + fiber = createRootErrorUpdate(JSCompiler_inline_result, fiber, 1); + enqueueUpdate(JSCompiler_inline_result, fiber, 1); + scheduleWork(JSCompiler_inline_result, 1); + JSCompiler_inline_result = void 0; + break a; } - 3 === fiber.tag && - ((JSCompiler_inline_result = createCapturedValue(error, fiber)), - (JSCompiler_inline_result = createRootErrorUpdate( - fiber, - JSCompiler_inline_result, - 1 - )), - enqueueUpdate(fiber, JSCompiler_inline_result, 1), - scheduleWork(fiber, 1)); - JSCompiler_inline_result = void 0; - } - return JSCompiler_inline_result; - } - function computeExpirationForFiber(currentTime, fiber) { - currentTime = - 0 !== expirationContext - ? expirationContext - : isWorking - ? isCommitting ? 1 : nextRenderExpirationTime - : fiber.mode & 1 - ? isBatchingInteractiveUpdates - ? 2 + 10 * ((((currentTime - 2 + 15) / 10) | 0) + 1) - : 2 + 25 * ((((currentTime - 2 + 500) / 25) | 0) + 1) - : 1; - isBatchingInteractiveUpdates && - (0 === lowestPendingInteractiveExpirationTime || - currentTime > lowestPendingInteractiveExpirationTime) && - (lowestPendingInteractiveExpirationTime = currentTime); - return currentTime; - } - function retrySuspendedRoot(root) { - var retryTime = root.current.expirationTime; - 0 !== retryTime && - (0 === root.remainingExpirationTime || - root.remainingExpirationTime < retryTime) && - requestWork(root, retryTime); - } - function scheduleWork(fiber, expirationTime) { - for (; null !== fiber; ) { - if (0 === fiber.expirationTime || fiber.expirationTime > expirationTime) - fiber.expirationTime = expirationTime; - null !== fiber.alternate && - (0 === fiber.alternate.expirationTime || - fiber.alternate.expirationTime > expirationTime) && - (fiber.alternate.expirationTime = expirationTime); - if (null === fiber.return) - if (3 === fiber.tag) { - var root = fiber.stateNode; - !isWorking && - 0 !== nextRenderExpirationTime && - expirationTime < nextRenderExpirationTime && - resetStack(); - var nextExpirationTimeToWorkOn = root.current.expirationTime; - (isWorking && !isCommitting && nextRoot === root) || - requestWork(root, nextExpirationTimeToWorkOn); - nestedUpdateCount > NESTED_UPDATE_LIMIT && - invariant( - !1, - "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops." - ); - } else break; - fiber = fiber.return; + JSCompiler_inline_result = JSCompiler_inline_result.return; } + 3 === fiber.tag && + ((JSCompiler_inline_result = createCapturedValue(error, fiber)), + (JSCompiler_inline_result = createRootErrorUpdate( + fiber, + JSCompiler_inline_result, + 1 + )), + enqueueUpdate(fiber, JSCompiler_inline_result, 1), + scheduleWork(fiber, 1)); + JSCompiler_inline_result = void 0; } - function recalculateCurrentTime() { - mostRecentCurrentTimeMs = now() - originalStartTimeMs; - return (mostRecentCurrentTime = ((mostRecentCurrentTimeMs / 10) | 0) + 2); + return JSCompiler_inline_result; +} +function computeExpirationForFiber(currentTime, fiber) { + currentTime = + 0 !== expirationContext + ? expirationContext + : isWorking + ? isCommitting$1 ? 1 : nextRenderExpirationTime + : fiber.mode & 1 + ? isBatchingInteractiveUpdates + ? 2 + 10 * ((((currentTime - 2 + 15) / 10) | 0) + 1) + : 2 + 25 * ((((currentTime - 2 + 500) / 25) | 0) + 1) + : 1; + isBatchingInteractiveUpdates && + (0 === lowestPendingInteractiveExpirationTime || + currentTime > lowestPendingInteractiveExpirationTime) && + (lowestPendingInteractiveExpirationTime = currentTime); + return currentTime; +} +function scheduleWork(fiber, expirationTime) { + for (; null !== fiber; ) { + if (0 === fiber.expirationTime || fiber.expirationTime > expirationTime) + fiber.expirationTime = expirationTime; + null !== fiber.alternate && + (0 === fiber.alternate.expirationTime || + fiber.alternate.expirationTime > expirationTime) && + (fiber.alternate.expirationTime = expirationTime); + if (null === fiber.return) + if (3 === fiber.tag) { + var root = fiber.stateNode; + !isWorking && + 0 !== nextRenderExpirationTime && + expirationTime < nextRenderExpirationTime && + resetStack(); + markPendingPriorityLevel(root, expirationTime); + (isWorking && !isCommitting$1 && nextRoot === root) || + requestWork(root, root.expirationTime); + nestedUpdateCount > NESTED_UPDATE_LIMIT && + invariant( + !1, + "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops." + ); + } else break; + fiber = fiber.return; } - function syncUpdates(fn, a, b, c, d) { - var previousExpirationContext = expirationContext; - expirationContext = 1; - try { - return fn(a, b, c, d); - } finally { - expirationContext = previousExpirationContext; - } +} +function recalculateCurrentTime() { + mostRecentCurrentTimeMs = now$1() - originalStartTimeMs; + return (mostRecentCurrentTime = ((mostRecentCurrentTimeMs / 10) | 0) + 2); +} +function syncUpdates(fn, a, b, c, d) { + var previousExpirationContext = expirationContext; + expirationContext = 1; + try { + return fn(a, b, c, d); + } finally { + expirationContext = previousExpirationContext; } - function scheduleCallbackWithExpiration(expirationTime) { - if (0 !== callbackExpirationTime) { - if (expirationTime > callbackExpirationTime) return; - cancelDeferredCallback(callbackID); +} +var firstScheduledRoot = null, + lastScheduledRoot = null, + callbackExpirationTime = 0, + callbackID = void 0, + isRendering = !1, + nextFlushedRoot = null, + nextFlushedExpirationTime = 0, + lowestPendingInteractiveExpirationTime = 0, + deadlineDidExpire = !1, + hasUnhandledError = !1, + unhandledError = null, + deadline = null, + isBatchingUpdates = !1, + isUnbatchingUpdates = !1, + isBatchingInteractiveUpdates = !1, + completedBatches = null, + NESTED_UPDATE_LIMIT = 1e3, + nestedUpdateCount = 0, + timeHeuristicForUnitOfWork = 1; +function scheduleCallbackWithExpirationTime(expirationTime) { + if (0 !== callbackExpirationTime) { + if (expirationTime > callbackExpirationTime) return; + if (null !== callbackID) { + var callbackID$jscomp$0 = callbackID; + scheduledCallback = null; + clearTimeout(callbackID$jscomp$0); } - var currentMs = now() - originalStartTimeMs; - callbackExpirationTime = expirationTime; - callbackID = scheduleDeferredCallback(performAsyncWork, { - timeout: 10 * (expirationTime - 2) - currentMs - }); } - function requestWork(root, expirationTime) { - if (null === root.nextScheduledRoot) - (root.remainingExpirationTime = expirationTime), - null === lastScheduledRoot - ? ((firstScheduledRoot = lastScheduledRoot = root), - (root.nextScheduledRoot = root)) - : ((lastScheduledRoot = lastScheduledRoot.nextScheduledRoot = root), - (lastScheduledRoot.nextScheduledRoot = firstScheduledRoot)); - else { - var remainingExpirationTime = root.remainingExpirationTime; - if ( - 0 === remainingExpirationTime || - expirationTime < remainingExpirationTime - ) - root.remainingExpirationTime = expirationTime; - } - isRendering || - (isBatchingUpdates - ? isUnbatchingUpdates && - ((nextFlushedRoot = root), - (nextFlushedExpirationTime = 1), - performWorkOnRoot(root, 1, !1)) - : 1 === expirationTime - ? performSyncWork() - : scheduleCallbackWithExpiration(expirationTime)); + callbackExpirationTime = expirationTime; + now$1(); + scheduledCallback = performAsyncWork; + callbackID = setTimeout(setTimeoutCallback, 1); +} +function onSuspend(root, suspendedExpirationTime, expirationTime, timeoutMs) { + 0 <= timeoutMs && + setTimeout(function() { + var latestSuspendedTime = root.latestSuspendedTime; + 0 !== latestSuspendedTime && + latestSuspendedTime <= suspendedExpirationTime && + ((latestSuspendedTime = root.latestPingedTime), + 0 === latestSuspendedTime || + latestSuspendedTime < suspendedExpirationTime) && + (root.latestPingedTime = suspendedExpirationTime); + findNextPendingPriorityLevel(root); + latestSuspendedTime = root.expirationTime; + 0 !== latestSuspendedTime && requestWork(root, latestSuspendedTime); + }, timeoutMs); + root.expirationTime = expirationTime; +} +function requestWork(root, expirationTime) { + if (null === root.nextScheduledRoot) + (root.expirationTime = expirationTime), + null === lastScheduledRoot + ? ((firstScheduledRoot = lastScheduledRoot = root), + (root.nextScheduledRoot = root)) + : ((lastScheduledRoot = lastScheduledRoot.nextScheduledRoot = root), + (lastScheduledRoot.nextScheduledRoot = firstScheduledRoot)); + else { + var remainingExpirationTime = root.expirationTime; + if ( + 0 === remainingExpirationTime || + expirationTime < remainingExpirationTime + ) + root.expirationTime = expirationTime; } - function findHighestPriorityRoot() { - var highestPriorityWork = 0, - highestPriorityRoot = null; - if (null !== lastScheduledRoot) - for ( - var previousScheduledRoot = lastScheduledRoot, - root = firstScheduledRoot; - null !== root; + isRendering || + (isBatchingUpdates + ? isUnbatchingUpdates && + ((nextFlushedRoot = root), + (nextFlushedExpirationTime = 1), + performWorkOnRoot(root, 1, !1)) + : 1 === expirationTime + ? performWork(1, null) + : scheduleCallbackWithExpirationTime(expirationTime)); +} +function findHighestPriorityRoot() { + var highestPriorityWork = 0, + highestPriorityRoot = null; + if (null !== lastScheduledRoot) + for ( + var previousScheduledRoot = lastScheduledRoot, root = firstScheduledRoot; + null !== root; - ) { - var remainingExpirationTime = root.remainingExpirationTime; - if (0 === remainingExpirationTime) { - invariant( - null !== previousScheduledRoot && null !== lastScheduledRoot, - "Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue." - ); - if (root === root.nextScheduledRoot) { - firstScheduledRoot = lastScheduledRoot = root.nextScheduledRoot = null; - break; - } else if (root === firstScheduledRoot) - (firstScheduledRoot = remainingExpirationTime = - root.nextScheduledRoot), - (lastScheduledRoot.nextScheduledRoot = remainingExpirationTime), - (root.nextScheduledRoot = null); - else if (root === lastScheduledRoot) { - lastScheduledRoot = previousScheduledRoot; - lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; - root.nextScheduledRoot = null; - break; - } else - (previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot), - (root.nextScheduledRoot = null); - root = previousScheduledRoot.nextScheduledRoot; - } else { - if ( - 0 === highestPriorityWork || - remainingExpirationTime < highestPriorityWork - ) - (highestPriorityWork = remainingExpirationTime), - (highestPriorityRoot = root); - if (root === lastScheduledRoot) break; - previousScheduledRoot = root; - root = root.nextScheduledRoot; - } + ) { + var remainingExpirationTime = root.expirationTime; + if (0 === remainingExpirationTime) { + invariant( + null !== previousScheduledRoot && null !== lastScheduledRoot, + "Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue." + ); + if (root === root.nextScheduledRoot) { + firstScheduledRoot = lastScheduledRoot = root.nextScheduledRoot = null; + break; + } else if (root === firstScheduledRoot) + (firstScheduledRoot = remainingExpirationTime = + root.nextScheduledRoot), + (lastScheduledRoot.nextScheduledRoot = remainingExpirationTime), + (root.nextScheduledRoot = null); + else if (root === lastScheduledRoot) { + lastScheduledRoot = previousScheduledRoot; + lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; + root.nextScheduledRoot = null; + break; + } else + (previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot), + (root.nextScheduledRoot = null); + root = previousScheduledRoot.nextScheduledRoot; + } else { + if ( + 0 === highestPriorityWork || + remainingExpirationTime < highestPriorityWork + ) + (highestPriorityWork = remainingExpirationTime), + (highestPriorityRoot = root); + if (root === lastScheduledRoot) break; + previousScheduledRoot = root; + root = root.nextScheduledRoot; } - previousScheduledRoot = nextFlushedRoot; - null !== previousScheduledRoot && - previousScheduledRoot === highestPriorityRoot && - 1 === highestPriorityWork - ? nestedUpdateCount++ - : (nestedUpdateCount = 0); - nextFlushedRoot = highestPriorityRoot; - nextFlushedExpirationTime = highestPriorityWork; - } - function performAsyncWork(dl) { - performWork(0, !0, dl); - } - function performSyncWork() { - performWork(1, !1, null); - } - function performWork(minExpirationTime, isAsync, dl) { - deadline = dl; - findHighestPriorityRoot(); - if (isAsync) - for ( - ; - null !== nextFlushedRoot && - 0 !== nextFlushedExpirationTime && - (0 === minExpirationTime || - minExpirationTime >= nextFlushedExpirationTime) && - (!deadlineDidExpire || - recalculateCurrentTime() >= nextFlushedExpirationTime); + } + previousScheduledRoot = nextFlushedRoot; + null !== previousScheduledRoot && + previousScheduledRoot === highestPriorityRoot && + 1 === highestPriorityWork + ? nestedUpdateCount++ + : (nestedUpdateCount = 0); + nextFlushedRoot = highestPriorityRoot; + nextFlushedExpirationTime = highestPriorityWork; +} +function performAsyncWork(dl) { + performWork(0, dl); +} +function performWork(minExpirationTime, dl) { + deadline = dl; + findHighestPriorityRoot(); + if (null !== deadline) + for ( + ; + null !== nextFlushedRoot && + 0 !== nextFlushedExpirationTime && + (0 === minExpirationTime || + minExpirationTime >= nextFlushedExpirationTime) && + (!deadlineDidExpire || + recalculateCurrentTime() >= nextFlushedExpirationTime); - ) - recalculateCurrentTime(), - performWorkOnRoot( - nextFlushedRoot, - nextFlushedExpirationTime, - !deadlineDidExpire - ), - findHighestPriorityRoot(); - else - for ( - ; - null !== nextFlushedRoot && - 0 !== nextFlushedExpirationTime && - (0 === minExpirationTime || - minExpirationTime >= nextFlushedExpirationTime); + ) + recalculateCurrentTime(), + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !0), + findHighestPriorityRoot(); + else + for ( + ; + null !== nextFlushedRoot && + 0 !== nextFlushedExpirationTime && + (0 === minExpirationTime || + minExpirationTime >= nextFlushedExpirationTime); - ) - performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !1), - findHighestPriorityRoot(); - null !== deadline && ((callbackExpirationTime = 0), (callbackID = -1)); - 0 !== nextFlushedExpirationTime && - scheduleCallbackWithExpiration(nextFlushedExpirationTime); - deadline = null; - deadlineDidExpire = !1; - finishRendering(); - } - function finishRendering() { - nestedUpdateCount = 0; - if (null !== completedBatches) { - var batches = completedBatches; - completedBatches = null; - for (var i = 0; i < batches.length; i++) { - var batch = batches[i]; - try { - batch._onComplete(); - } catch (error) { - hasUnhandledError || - ((hasUnhandledError = !0), (unhandledError = error)); - } + ) + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !1), + findHighestPriorityRoot(); + null !== deadline && ((callbackExpirationTime = 0), (callbackID = null)); + 0 !== nextFlushedExpirationTime && + scheduleCallbackWithExpirationTime(nextFlushedExpirationTime); + deadline = null; + deadlineDidExpire = !1; + finishRendering(); +} +function finishRendering() { + nestedUpdateCount = 0; + if (null !== completedBatches) { + var batches = completedBatches; + completedBatches = null; + for (var i = 0; i < batches.length; i++) { + var batch = batches[i]; + try { + batch._onComplete(); + } catch (error) { + hasUnhandledError || + ((hasUnhandledError = !0), (unhandledError = error)); } } - if (hasUnhandledError) - throw ((batches = unhandledError), - (unhandledError = null), - (hasUnhandledError = !1), - batches); } - function performWorkOnRoot(root, expirationTime, isAsync) { - invariant( - !isRendering, - "performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." - ); - isRendering = !0; - isAsync - ? ((isAsync = root.finishedWork), - null !== isAsync - ? completeRoot$$1(root, isAsync, expirationTime) - : ((root.finishedWork = null), - (isAsync = renderRoot(root, expirationTime, !0)), - null !== isAsync && - (shouldYield() - ? (root.finishedWork = isAsync) - : completeRoot$$1(root, isAsync, expirationTime)))) - : ((isAsync = root.finishedWork), - null !== isAsync - ? completeRoot$$1(root, isAsync, expirationTime) - : ((root.finishedWork = null), - (isAsync = renderRoot(root, expirationTime, !1)), - null !== isAsync && - completeRoot$$1(root, isAsync, expirationTime))); - isRendering = !1; + if (hasUnhandledError) + throw ((batches = unhandledError), + (unhandledError = null), + (hasUnhandledError = !1), + batches); +} +function performWorkOnRoot(root, expirationTime, isYieldy) { + invariant( + !isRendering, + "performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." + ); + isRendering = !0; + isYieldy + ? ((isYieldy = root.finishedWork), + null !== isYieldy + ? completeRoot$1(root, isYieldy, expirationTime) + : ((root.finishedWork = null), + renderRoot(root, !0), + (isYieldy = root.finishedWork), + null !== isYieldy && + (shouldYield() + ? (root.finishedWork = isYieldy) + : completeRoot$1(root, isYieldy, expirationTime)))) + : ((isYieldy = root.finishedWork), + null !== isYieldy + ? completeRoot$1(root, isYieldy, expirationTime) + : ((root.finishedWork = null), + renderRoot(root, !1), + (isYieldy = root.finishedWork), + null !== isYieldy && completeRoot$1(root, isYieldy, expirationTime))); + isRendering = !1; +} +function completeRoot$1(root, finishedWork$jscomp$0, expirationTime) { + var firstBatch = root.firstBatch; + if ( + null !== firstBatch && + firstBatch._expirationTime <= expirationTime && + (null === completedBatches + ? (completedBatches = [firstBatch]) + : completedBatches.push(firstBatch), + firstBatch._defer) + ) { + root.finishedWork = finishedWork$jscomp$0; + root.expirationTime = 0; + return; } - function completeRoot$$1(root, finishedWork, expirationTime) { - var firstBatch = root.firstBatch; - if ( - null !== firstBatch && - firstBatch._expirationTime <= expirationTime && - (null === completedBatches - ? (completedBatches = [firstBatch]) - : completedBatches.push(firstBatch), - firstBatch._defer) - ) { - root.finishedWork = finishedWork; - root.remainingExpirationTime = 0; - return; - } - root.finishedWork = null; - isCommitting = isWorking = !0; - expirationTime = finishedWork.stateNode; - invariant( - expirationTime.current !== finishedWork, - "Cannot commit the same tree as before. This is probably a bug related to the return field. This error is likely caused by a bug in React. Please file an issue." - ); - firstBatch = expirationTime.pendingCommitExpirationTime; - invariant( - 0 !== firstBatch, - "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." - ); - expirationTime.pendingCommitExpirationTime = 0; - var currentTime = recalculateCurrentTime(); - ReactCurrentOwner.current = null; - if (1 < finishedWork.effectTag) - if (null !== finishedWork.lastEffect) { - finishedWork.lastEffect.nextEffect = finishedWork; - var firstEffect = finishedWork.firstEffect; - } else firstEffect = finishedWork; - else firstEffect = finishedWork.firstEffect; - prepareForCommit(expirationTime.containerInfo); - for (nextEffect = firstEffect; null !== nextEffect; ) { - var didError = !1, - error = void 0; - try { - for (; null !== nextEffect; ) - nextEffect.effectTag & 256 && - 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; - effectTag & 16 && commitResetTextContent(nextEffect); - if (effectTag & 128) { - var current = nextEffect.alternate; - null !== current && commitDetachRef(current); - } - switch (effectTag & 14) { + root.finishedWork = null; + isCommitting$1 = isWorking = !0; + invariant( + root.current !== finishedWork$jscomp$0, + "Cannot commit the same tree as before. This is probably a bug related to the return field. This error is likely caused by a bug in React. Please file an issue." + ); + expirationTime = root.pendingCommitExpirationTime; + invariant( + 0 !== expirationTime, + "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." + ); + root.pendingCommitExpirationTime = 0; + firstBatch = finishedWork$jscomp$0.expirationTime; + recalculateCurrentTime(); + root.didError = !1; + if (0 === firstBatch) + (root.earliestPendingTime = 0), + (root.latestPendingTime = 0), + (root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0); + else { + var latestPendingTime = root.latestPendingTime; + 0 !== latestPendingTime && + (latestPendingTime < firstBatch + ? (root.earliestPendingTime = root.latestPendingTime = 0) + : root.earliestPendingTime < firstBatch && + (root.earliestPendingTime = root.latestPendingTime)); + latestPendingTime = root.earliestSuspendedTime; + 0 === latestPendingTime + ? markPendingPriorityLevel(root, firstBatch) + : firstBatch > root.latestSuspendedTime + ? ((root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0), + markPendingPriorityLevel(root, firstBatch)) + : firstBatch < latestPendingTime && + markPendingPriorityLevel(root, firstBatch); + } + findNextPendingPriorityLevel(root); + ReactCurrentOwner.current = null; + 1 < finishedWork$jscomp$0.effectTag + ? null !== finishedWork$jscomp$0.lastEffect + ? ((finishedWork$jscomp$0.lastEffect.nextEffect = finishedWork$jscomp$0), + (firstBatch = finishedWork$jscomp$0.firstEffect)) + : (firstBatch = finishedWork$jscomp$0) + : (firstBatch = finishedWork$jscomp$0.firstEffect); + for (nextEffect = firstBatch; null !== nextEffect; ) { + latestPendingTime = !1; + var error = void 0; + try { + for (; null !== nextEffect; ) { + if (nextEffect.effectTag & 256) { + var current = nextEffect.alternate, + finishedWork = nextEffect; + switch (finishedWork.tag) { case 2: - commitPlacement(nextEffect); - nextEffect.effectTag &= -3; + if (finishedWork.effectTag & 256 && null !== current) { + var prevProps = current.memoizedProps, + prevState = current.memoizedState, + instance = finishedWork.stateNode; + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + var snapshot = instance.getSnapshotBeforeUpdate( + prevProps, + prevState + ); + instance.__reactInternalSnapshotBeforeUpdate = snapshot; + } break; + case 3: + case 5: case 6: - commitPlacement(nextEffect); - nextEffect.effectTag &= -3; - commitWork(nextEffect.alternate, nextEffect); - break; case 4: - commitWork(nextEffect.alternate, nextEffect); break; - case 8: - commitDeletion(nextEffect); + 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." + ); } - nextEffect = nextEffect.nextEffect; } - } catch (e) { - (didError = !0), (error = e); + nextEffect = nextEffect.nextEffect; } - 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)); + } catch (e) { + (latestPendingTime = !0), (error = e); } - resetAfterCommit(expirationTime.containerInfo); - expirationTime.current = finishedWork; - for (nextEffect = firstEffect; null !== nextEffect; ) { - effectTag = !1; - current = void 0; - try { - for ( - firstEffect = expirationTime, - didError = currentTime, - error = firstBatch; - null !== nextEffect; - - ) { - var effectTag$jscomp$0 = nextEffect.effectTag; - effectTag$jscomp$0 & 36 && - commitLifeCycles( - firstEffect, - nextEffect.alternate, - nextEffect, - didError, - error - ); - effectTag$jscomp$0 & 128 && commitAttachRef(nextEffect); - var next = nextEffect.nextEffect; - nextEffect.nextEffect = null; - nextEffect = next; + latestPendingTime && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, error), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + for (nextEffect = firstBatch; null !== nextEffect; ) { + current = !1; + prevProps = void 0; + try { + for (; null !== nextEffect; ) { + var effectTag = nextEffect.effectTag; + if (effectTag & 128) { + var current$jscomp$0 = nextEffect.alternate; + if (null !== current$jscomp$0) { + var currentRef = current$jscomp$0.ref; + null !== currentRef && + ("function" === typeof currentRef + ? currentRef(null) + : (currentRef.current = null)); + } + } + switch (effectTag & 14) { + case 2: + nextEffect.effectTag &= -3; + break; + case 6: + nextEffect.effectTag &= -3; + commitWork(nextEffect.alternate, nextEffect); + break; + case 4: + commitWork(nextEffect.alternate, nextEffect); + break; + case 8: + prevState = nextEffect; + a: for (snapshot = instance = prevState; ; ) { + latestPendingTime = snapshot; + "function" === typeof onCommitUnmount && + onCommitUnmount(latestPendingTime); + switch (latestPendingTime.tag) { + case 2: + safelyDetachRef(latestPendingTime); + var instance$jscomp$0 = latestPendingTime.stateNode; + if ( + "function" === typeof instance$jscomp$0.componentWillUnmount + ) + try { + (instance$jscomp$0.props = + latestPendingTime.memoizedProps), + (instance$jscomp$0.state = + latestPendingTime.memoizedState), + instance$jscomp$0.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(latestPendingTime, unmountError); + } + break; + case 5: + safelyDetachRef(latestPendingTime); + break; + case 4: + FabricUIManager.createChildSet( + latestPendingTime.stateNode.containerInfo + ); + } + if (null !== snapshot.child) + (snapshot.child.return = snapshot), (snapshot = snapshot.child); + else { + if (snapshot === instance) break; + for (; null === snapshot.sibling; ) { + if (null === snapshot.return || snapshot.return === instance) + break a; + snapshot = snapshot.return; + } + snapshot.sibling.return = snapshot.return; + snapshot = snapshot.sibling; + } + } + prevState.return = null; + prevState.child = null; + prevState.alternate && + ((prevState.alternate.child = null), + (prevState.alternate.return = null)); } - } catch (e) { - (effectTag = !0), (current = e); + nextEffect = nextEffect.nextEffect; } - effectTag && - (invariant( - null !== nextEffect, - "Should have next effect. This error is likely caused by a bug in React. Please file an issue." - ), - onCommitPhaseError(nextEffect, current), - null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } catch (e) { + (current = !0), (prevProps = e); } - isWorking = isCommitting = !1; - "function" === typeof onCommitRoot && onCommitRoot(finishedWork.stateNode); - finishedWork = expirationTime.current.expirationTime; - 0 === finishedWork && (legacyErrorBoundariesThatAlreadyFailed = null); - root.remainingExpirationTime = finishedWork; - } - function shouldYield() { - return null === deadline || - deadline.timeRemaining() > timeHeuristicForUnitOfWork - ? !1 - : (deadlineDidExpire = !0); - } - function onUncaughtError(error) { - invariant( - null !== nextFlushedRoot, - "Should be working on a root. This error is likely caused by a bug in React. Please file an issue." - ); - nextFlushedRoot.remainingExpirationTime = 0; - hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error)); - } - function onBlock(remainingExpirationTime) { - invariant( - null !== nextFlushedRoot, - "Should be working on a root. This error is likely caused by a bug in React. Please file an issue." - ); - nextFlushedRoot.remainingExpirationTime = remainingExpirationTime; + current && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, prevProps), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); } - var now = config.now, - scheduleDeferredCallback = config.scheduleDeferredCallback, - cancelDeferredCallback = config.cancelDeferredCallback, - prepareForCommit = config.prepareForCommit, - resetAfterCommit = config.resetAfterCommit, - stack = ReactFiberStack(), - hostContext = ReactFiberHostContext(config, stack), - legacyContext = ReactFiberLegacyContext(stack); - stack = ReactFiberNewContext(stack, config.isPrimaryRenderer); - var profilerTimer = createProfilerTimer(now), - hydrationContext = ReactFiberHydrationContext(config), - beginWork = ReactFiberBeginWork( - config, - hostContext, - legacyContext, - stack, - hydrationContext, - scheduleWork, - computeExpirationForFiber, - profilerTimer, - recalculateCurrentTime - ).beginWork, - completeWork = ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - stack, - hydrationContext, - profilerTimer - ).completeWork; - hostContext = ReactFiberUnwindWork( - config, - hostContext, - legacyContext, - stack, - scheduleWork, - computeExpirationForFiber, - recalculateCurrentTime, - markLegacyErrorBoundaryAsFailed, - isAlreadyFailedLegacyErrorBoundary, - onUncaughtError, - profilerTimer, - function(root, thenable, timeoutMs) { - 0 <= timeoutMs && - nextLatestTimeoutMs < timeoutMs && - (nextLatestTimeoutMs = timeoutMs); - }, - retrySuspendedRoot - ); - var throwException = hostContext.throwException, - unwindWork = hostContext.unwindWork, - unwindInterruptedWork = hostContext.unwindInterruptedWork, - createRootErrorUpdate = hostContext.createRootErrorUpdate, - createClassErrorUpdate = hostContext.createClassErrorUpdate; - config = ReactFiberCommitWork( - config, - onCommitPhaseError, - scheduleWork, - computeExpirationForFiber, - markLegacyErrorBoundaryAsFailed, - recalculateCurrentTime - ); - var commitBeforeMutationLifeCycles = config.commitBeforeMutationLifeCycles, - commitResetTextContent = config.commitResetTextContent, - commitPlacement = config.commitPlacement, - commitDeletion = config.commitDeletion, - commitWork = config.commitWork, - commitLifeCycles = config.commitLifeCycles, - commitAttachRef = config.commitAttachRef, - commitDetachRef = config.commitDetachRef, - originalStartTimeMs = now(), - mostRecentCurrentTime = 2, - mostRecentCurrentTimeMs = originalStartTimeMs, - lastUniqueAsyncExpiration = 0, - expirationContext = 0, - isWorking = !1, - nextUnitOfWork = null, - nextRoot = null, - nextRenderExpirationTime = 0, - nextLatestTimeoutMs = -1, - nextRenderIsExpired = !1, - nextEffect = null, - isCommitting = !1, - isRootReadyForCommit = !1, - legacyErrorBoundariesThatAlreadyFailed = null, - firstScheduledRoot = null, - lastScheduledRoot = null, - callbackExpirationTime = 0, - callbackID = -1, - isRendering = !1, - nextFlushedRoot = null, - nextFlushedExpirationTime = 0, - lowestPendingInteractiveExpirationTime = 0, - deadlineDidExpire = !1, - hasUnhandledError = !1, - unhandledError = null, - deadline = null, - isBatchingUpdates = !1, - isUnbatchingUpdates = !1, - isBatchingInteractiveUpdates = !1, - completedBatches = null, - NESTED_UPDATE_LIMIT = 1e3, - nestedUpdateCount = 0, - timeHeuristicForUnitOfWork = 1; - return { - recalculateCurrentTime: recalculateCurrentTime, - computeExpirationForFiber: computeExpirationForFiber, - scheduleWork: scheduleWork, - requestWork: requestWork, - flushRoot: function(root, expirationTime) { - invariant( - !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) { - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = !0; - try { - return fn(a); - } finally { - (isBatchingUpdates = previousIsBatchingUpdates) || - isRendering || - performSyncWork(); - } - }, - unbatchedUpdates: function(fn, a) { - if (isBatchingUpdates && !isUnbatchingUpdates) { - isUnbatchingUpdates = !0; - try { - return fn(a); - } finally { - isUnbatchingUpdates = !1; + root.current = finishedWork$jscomp$0; + for (nextEffect = firstBatch; null !== nextEffect; ) { + effectTag = !1; + current$jscomp$0 = void 0; + try { + for (currentRef = expirationTime; null !== nextEffect; ) { + var effectTag$jscomp$0 = nextEffect.effectTag; + if (effectTag$jscomp$0 & 36) { + var current$jscomp$1 = nextEffect.alternate; + instance$jscomp$0 = nextEffect; + firstBatch = currentRef; + switch (instance$jscomp$0.tag) { + case 2: + var instance$jscomp$1 = instance$jscomp$0.stateNode; + if (instance$jscomp$0.effectTag & 4) + if (null === current$jscomp$1) + (instance$jscomp$1.props = instance$jscomp$0.memoizedProps), + (instance$jscomp$1.state = instance$jscomp$0.memoizedState), + instance$jscomp$1.componentDidMount(); + else { + var prevProps$jscomp$0 = current$jscomp$1.memoizedProps, + prevState$jscomp$0 = current$jscomp$1.memoizedState; + instance$jscomp$1.props = instance$jscomp$0.memoizedProps; + instance$jscomp$1.state = instance$jscomp$0.memoizedState; + instance$jscomp$1.componentDidUpdate( + prevProps$jscomp$0, + prevState$jscomp$0, + instance$jscomp$1.__reactInternalSnapshotBeforeUpdate + ); + } + var updateQueue = instance$jscomp$0.updateQueue; + null !== updateQueue && + ((instance$jscomp$1.props = instance$jscomp$0.memoizedProps), + (instance$jscomp$1.state = instance$jscomp$0.memoizedState), + commitUpdateQueue( + instance$jscomp$0, + updateQueue, + instance$jscomp$1, + firstBatch + )); + break; + case 3: + var _updateQueue = instance$jscomp$0.updateQueue; + if (null !== _updateQueue) { + current = null; + if (null !== instance$jscomp$0.child) + switch (instance$jscomp$0.child.tag) { + case 5: + current = instance$jscomp$0.child.stateNode.canonical; + break; + case 2: + current = instance$jscomp$0.child.stateNode; + } + commitUpdateQueue( + instance$jscomp$0, + _updateQueue, + current, + firstBatch + ); + } + break; + case 5: + null === current$jscomp$1 && + instance$jscomp$0.effectTag & 4 && + invariant( + !1, + "The current renderer does not support mutation. This error is likely caused by a bug in React. Please file an issue." + ); + break; + case 6: + break; + case 4: + break; + case 15: + break; + case 16: + 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." + ); + } + } + if (effectTag$jscomp$0 & 128) { + instance$jscomp$0 = void 0; + var ref = nextEffect.ref; + if (null !== ref) { + var instance$jscomp$2 = nextEffect.stateNode; + switch (nextEffect.tag) { + case 5: + instance$jscomp$0 = instance$jscomp$2.canonical; + break; + default: + instance$jscomp$0 = instance$jscomp$2; + } + "function" === typeof ref + ? ref(instance$jscomp$0) + : (ref.current = instance$jscomp$0); + } } + var next = nextEffect.nextEffect; + nextEffect.nextEffect = null; + nextEffect = next; } - return fn(a); - }, - flushSync: function(fn, a) { + } catch (e) { + (effectTag = !0), (current$jscomp$0 = e); + } + effectTag && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, current$jscomp$0), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + isWorking = isCommitting$1 = !1; + "function" === typeof onCommitRoot && + onCommitRoot(finishedWork$jscomp$0.stateNode); + finishedWork$jscomp$0 = root.expirationTime; + 0 === finishedWork$jscomp$0 && + (legacyErrorBoundariesThatAlreadyFailed = null); + root.expirationTime = finishedWork$jscomp$0; + root.finishedWork = null; +} +function shouldYield() { + return null === deadline || + deadlineDidExpire || + deadline.timeRemaining() > timeHeuristicForUnitOfWork + ? !1 + : (deadlineDidExpire = !0); +} +function onUncaughtError(error) { + invariant( + null !== nextFlushedRoot, + "Should be working on a root. This error is likely caused by a bug in React. Please file an issue." + ); + nextFlushedRoot.expirationTime = 0; + hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error)); +} +function updateContainerAtExpirationTime( + element, + container, + parentComponent, + expirationTime, + callback +) { + var current = container.current; + if (parentComponent) { + parentComponent = parentComponent._reactInternalFiber; + var parentContext; + b: { invariant( - !isRendering, - "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." + 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." ); - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = !0; - try { - return syncUpdates(fn, a); - } finally { - (isBatchingUpdates = previousIsBatchingUpdates), performSyncWork(); - } - }, - flushControlled: function(fn) { - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = !0; - try { - syncUpdates(fn); - } finally { - (isBatchingUpdates = previousIsBatchingUpdates) || - isRendering || - performWork(1, !1, null); - } - }, - deferredUpdates: function(fn) { - var previousExpirationContext = expirationContext; - expirationContext = - 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); - try { - return fn(); - } finally { - expirationContext = previousExpirationContext; - } - }, - syncUpdates: syncUpdates, - interactiveUpdates: function(fn, a, b) { - if (isBatchingInteractiveUpdates) return fn(a, b); - isBatchingUpdates || - isRendering || - 0 === lowestPendingInteractiveExpirationTime || - (performWork(lowestPendingInteractiveExpirationTime, !1, null), - (lowestPendingInteractiveExpirationTime = 0)); - var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates, - previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = isBatchingInteractiveUpdates = !0; - try { - return fn(a, b); - } finally { - (isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates), - (isBatchingUpdates = previousIsBatchingUpdates) || - isRendering || - performSyncWork(); + 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." + ); } - }, - flushInteractiveUpdates: function() { - isRendering || - 0 === lowestPendingInteractiveExpirationTime || - (performWork(lowestPendingInteractiveExpirationTime, !1, null), - (lowestPendingInteractiveExpirationTime = 0)); - }, - computeUniqueAsyncExpiration: function() { - var result = - 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); - result <= lastUniqueAsyncExpiration && - (result = lastUniqueAsyncExpiration + 1); - return (lastUniqueAsyncExpiration = result); - }, - legacyContext: legacyContext - }; + parentContext = parentContext.stateNode.context; + } + parentComponent = isContextProvider(parentComponent) + ? processChildContext(parentComponent, parentContext) + : parentContext; + } else parentComponent = emptyObject; + null === container.context + ? (container.context = parentComponent) + : (container.pendingContext = parentComponent); + container = callback; + callback = createUpdate(expirationTime); + callback.payload = { element: element }; + container = void 0 === container ? null : container; + null !== container && (callback.callback = container); + enqueueUpdate(current, callback, expirationTime); + scheduleWork(current, expirationTime); + return expirationTime; +} +function findHostInstance$1(component) { + var fiber = component._reactInternalFiber; + void 0 === fiber && + ("function" === typeof component.render + ? invariant(!1, "Unable to find node on an unmounted component.") + : invariant( + !1, + "Argument appears to not be a ReactComponent. Keys: %s", + Object.keys(component) + )); + component = findCurrentHostFiber(fiber); + return null === component ? null : component.stateNode; } -function ReactFiberReconciler$1(config) { - function updateContainerAtExpirationTime( +function updateContainer(element, container, parentComponent, callback) { + var current = container.current, + currentTime = recalculateCurrentTime(); + current = computeExpirationForFiber(currentTime, current); + return updateContainerAtExpirationTime( element, container, parentComponent, - expirationTime, + current, callback - ) { - var current = container.current; - if (parentComponent) { - parentComponent = parentComponent._reactInternalFiber; - var parentContext = findCurrentUnmaskedContext(parentComponent); - parentComponent = isContextProvider(parentComponent) - ? processChildContext(parentComponent, parentContext) - : parentContext; - } else parentComponent = emptyObject; - null === container.context - ? (container.context = parentComponent) - : (container.pendingContext = parentComponent); - container = callback; - callback = createUpdate(expirationTime); - callback.payload = { element: element }; - container = void 0 === container ? null : container; - null !== container && (callback.callback = container); - enqueueUpdate(current, callback, expirationTime); - scheduleWork(current, expirationTime); - return expirationTime; + ); +} +function getPublicRootInstance(container) { + container = container.current; + if (!container.child) return null; + switch (container.child.tag) { + case 5: + return container.child.stateNode.canonical; + default: + return container.child.stateNode; } - var getPublicInstance = config.getPublicInstance; - 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; - return { - createContainer: function(containerInfo, isAsync, hydrate) { - isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0); - containerInfo = { - current: isAsync, - containerInfo: containerInfo, - pendingChildren: null, - earliestPendingTime: 0, - latestPendingTime: 0, - earliestSuspendedTime: 0, - latestSuspendedTime: 0, - latestPingedTime: 0, - pendingCommitExpirationTime: 0, - finishedWork: null, - context: null, - pendingContext: null, - hydrate: hydrate, - remainingExpirationTime: 0, - firstBatch: null, - nextScheduledRoot: null - }; - return (isAsync.stateNode = containerInfo); - }, - updateContainer: function(element, container, parentComponent, callback) { - var current = container.current, - currentTime = recalculateCurrentTime(); - current = computeExpirationForFiber(currentTime, current); - return updateContainerAtExpirationTime( - element, - container, - parentComponent, - current, - callback - ); - }, - updateContainerAtExpirationTime: function( - element, - container, - parentComponent, - expirationTime, - callback - ) { - return updateContainerAtExpirationTime( - element, - container, - parentComponent, - expirationTime, - callback - ); - }, - flushRoot: config.flushRoot, - requestWork: config.requestWork, - computeUniqueAsyncExpiration: config.computeUniqueAsyncExpiration, - batchedUpdates: config.batchedUpdates, - unbatchedUpdates: config.unbatchedUpdates, - deferredUpdates: config.deferredUpdates, - syncUpdates: config.syncUpdates, - interactiveUpdates: config.interactiveUpdates, - flushInteractiveUpdates: config.flushInteractiveUpdates, - flushControlled: config.flushControlled, - flushSync: config.flushSync, - getPublicRootInstance: function(container) { - container = container.current; - if (!container.child) return null; - switch (container.child.tag) { - case 5: - return getPublicInstance(container.child.stateNode); - default: - return container.child.stateNode; +} +function injectIntoDevTools(devToolsConfig) { + var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; + return injectInternals( + Object.assign({}, devToolsConfig, { + findHostInstanceByFiber: function(fiber) { + fiber = findCurrentHostFiber(fiber); + return null === fiber ? null : fiber.stateNode; + }, + findFiberByHostInstance: function(instance) { + return findFiberByHostInstance + ? findFiberByHostInstance(instance) + : null; } - }, - findHostInstance: function(component) { - var fiber = component._reactInternalFiber; - void 0 === fiber && - ("function" === typeof component.render - ? invariant(!1, "Unable to find node on an unmounted component.") - : invariant( - !1, - "Argument appears to not be a ReactComponent. Keys: %s", - Object.keys(component) - )); - component = findCurrentHostFiber(fiber); - return null === component ? null : component.stateNode; - }, - findHostInstanceWithNoPortals: function(fiber) { - fiber = findCurrentHostFiberWithNoPortals(fiber); - return null === fiber ? null : fiber.stateNode; - }, - injectIntoDevTools: function(devToolsConfig) { - var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; - return injectInternals( - Object.assign({}, devToolsConfig, { - findHostInstanceByFiber: function(fiber) { - fiber = findCurrentHostFiber(fiber); - return null === fiber ? null : fiber.stateNode; - }, - findFiberByHostInstance: function(instance) { - return findFiberByHostInstance - ? findFiberByHostInstance(instance) - : null; - } - }) - ); - } - }; + }) + ); } -var ReactFiberReconciler$2 = Object.freeze({ default: ReactFiberReconciler$1 }), - ReactFiberReconciler$3 = - (ReactFiberReconciler$2 && ReactFiberReconciler$1) || - ReactFiberReconciler$2, - reactReconciler = ReactFiberReconciler$3.default - ? ReactFiberReconciler$3.default - : ReactFiberReconciler$3, - now = - "object" === typeof performance && "function" === typeof performance.now - ? function() { - return performance.now(); - } - : function() { - return Date.now(); - }, - scheduledCallback = null, - frameDeadline = 0, - frameDeadlineObject = { - timeRemaining: function() { - return frameDeadline - now(); - }, - didTimeout: !1 +var ReactFabricRenderer = { + updateContainerAtExpirationTime: updateContainerAtExpirationTime, + createContainer: function(containerInfo, isAsync, hydrate) { + return createFiberRoot(containerInfo, isAsync, hydrate); + }, + updateContainer: updateContainer, + flushRoot: function(root, expirationTime) { + invariant( + !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); + performWork(1, null); + finishRendering(); + }, + requestWork: requestWork, + computeUniqueAsyncExpiration: function() { + var result = + 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); + result <= lastUniqueAsyncExpiration && + (result = lastUniqueAsyncExpiration + 1); + return (lastUniqueAsyncExpiration = result); + }, + batchedUpdates: function(fn, a) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + return fn(a); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + unbatchedUpdates: function(fn, a) { + if (isBatchingUpdates && !isUnbatchingUpdates) { + isUnbatchingUpdates = !0; + try { + return fn(a); + } finally { + isUnbatchingUpdates = !1; + } + } + return fn(a); + }, + deferredUpdates: function(fn) { + var previousExpirationContext = expirationContext; + expirationContext = + 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); + try { + return fn(); + } finally { + expirationContext = previousExpirationContext; + } + }, + syncUpdates: syncUpdates, + interactiveUpdates: function(fn, a, b) { + if (isBatchingInteractiveUpdates) return fn(a, b); + isBatchingUpdates || + isRendering || + 0 === lowestPendingInteractiveExpirationTime || + (performWork(lowestPendingInteractiveExpirationTime, null), + (lowestPendingInteractiveExpirationTime = 0)); + var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates, + previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = isBatchingInteractiveUpdates = !0; + try { + return fn(a, b); + } finally { + (isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates), + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + flushInteractiveUpdates: function() { + isRendering || + 0 === lowestPendingInteractiveExpirationTime || + (performWork(lowestPendingInteractiveExpirationTime, null), + (lowestPendingInteractiveExpirationTime = 0)); + }, + flushControlled: function(fn) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + syncUpdates(fn); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + flushSync: function(fn, a) { + invariant( + !isRendering, + "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." + ); + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + return syncUpdates(fn, a); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates), performWork(1, null); + } + }, + getPublicRootInstance: getPublicRootInstance, + findHostInstance: findHostInstance$1, + findHostInstanceWithNoPortals: function(fiber) { + fiber = findCurrentHostFiberWithNoPortals(fiber); + return null === fiber ? null : fiber.stateNode; + }, + injectIntoDevTools: injectIntoDevTools +}; +function createPortal(children, containerInfo, implementation) { + var key = + 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null; + return { + $$typeof: REACT_PORTAL_TYPE, + key: null == key ? null : "" + key, + children: children, + containerInfo: containerInfo, + implementation: implementation }; -function setTimeoutCallback() { - frameDeadline = now() + 5; - var callback = scheduledCallback; - scheduledCallback = null; - null !== callback && callback(frameDeadlineObject); } -function dispatchEvent(target, topLevelType, nativeEvent) { - batchedUpdates(function() { - var events = nativeEvent.target; - for (var events$jscomp$0 = null, i = 0; i < plugins.length; i++) { - var possiblePlugin = plugins[i]; - possiblePlugin && - (possiblePlugin = possiblePlugin.extractEvents( - topLevelType, - target, - nativeEvent, - events - )) && - (events$jscomp$0 = accumulateInto(events$jscomp$0, possiblePlugin)); +function _inherits(subClass, superClass) { + if ("function" !== typeof superClass && null !== superClass) + throw new TypeError( + "Super expression must either be null or a function, not " + + typeof superClass + ); + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: !1, + writable: !0, + configurable: !0 } - events = events$jscomp$0; - null !== events && (eventQueue = accumulateInto(eventQueue, events)); - events = eventQueue; - eventQueue = null; - events && - (forEachAccumulated(events, executeDispatchesAndReleaseTopLevel), - invariant( - !eventQueue, - "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented." - ), - ReactErrorUtils.rethrowCaughtError()); }); + superClass && + (Object.setPrototypeOf + ? Object.setPrototypeOf(subClass, superClass) + : (subClass.__proto__ = superClass)); } -var nextReactTag = 2; -FabricUIManager.registerEventHandler && - FabricUIManager.registerEventHandler(dispatchEvent); -var ReactFabricHostComponent = (function() { - function ReactFabricHostComponent(tag, viewConfig, props) { - if (!(this instanceof ReactFabricHostComponent)) - throw new TypeError("Cannot call a class as a function"); - this._nativeTag = tag; - this.viewConfig = viewConfig; - this.currentProps = props; - } - ReactFabricHostComponent.prototype.blur = function() { - TextInputState.blurTextInput(this._nativeTag); - }; - ReactFabricHostComponent.prototype.focus = function() { - TextInputState.focusTextInput(this._nativeTag); - }; - ReactFabricHostComponent.prototype.measure = function(callback) { - UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); - }; - ReactFabricHostComponent.prototype.measureInWindow = function(callback) { - UIManager.measureInWindow( - this._nativeTag, - mountSafeCallback(this, callback) - ); - }; - ReactFabricHostComponent.prototype.measureLayout = function( - relativeToNativeNode, - onSuccess, - onFail - ) { - UIManager.measureLayout( - this._nativeTag, - relativeToNativeNode, - mountSafeCallback(this, onFail), - mountSafeCallback(this, onSuccess) - ); - }; - ReactFabricHostComponent.prototype.setNativeProps = function(nativeProps) { - nativeProps = diffProperties( - null, - emptyObject$1, - nativeProps, - this.viewConfig.validAttributes - ); - null != nativeProps && - UIManager.updateView( - this._nativeTag, - this.viewConfig.uiViewClassName, - nativeProps - ); - }; - return ReactFabricHostComponent; - })(), - ReactFabricRenderer = reactReconciler({ - appendInitialChild: function(parentInstance, child) { - FabricUIManager.appendChild(parentInstance.node, child.node); - }, - createInstance: function( - type, - props, - rootContainerInstance, - hostContext, - internalInstanceHandle - ) { - var tag = nextReactTag; - nextReactTag += 2; - var viewConfig = ReactNativeViewConfigRegistry.get(type); - invariant( - "RCTView" !== type || !hostContext.isInAParentText, - "Nesting of within is not currently supported." - ); - type = diffProperties( - null, - emptyObject$1, - props, - viewConfig.validAttributes - ); - rootContainerInstance = FabricUIManager.createNode( - tag, - viewConfig.uiViewClassName, - rootContainerInstance, - type, - internalInstanceHandle - ); - props = new ReactFabricHostComponent(tag, viewConfig, props); - return { node: rootContainerInstance, canonical: props }; - }, - createTextInstance: function( - text, - rootContainerInstance, - hostContext, - internalInstanceHandle - ) { - invariant( - hostContext.isInAParentText, - "Text strings must be rendered within a component." - ); - hostContext = nextReactTag; - nextReactTag += 2; - return { - node: FabricUIManager.createNode( - hostContext, - "RCTRawText", - rootContainerInstance, - { text: text }, - internalInstanceHandle - ) - }; - }, - finalizeInitialChildren: function() { - return !1; - }, - getRootHostContext: function() { - return { isInAParentText: !1 }; - }, - getChildHostContext: function(parentHostContext, type) { - type = - "AndroidTextInput" === type || - "RCTMultilineTextInputView" === type || - "RCTSinglelineTextInputView" === type || - "RCTText" === type || - "RCTVirtualText" === type; - return parentHostContext.isInAParentText !== type - ? { isInAParentText: type } - : parentHostContext; - }, - getPublicInstance: function(instance) { - return instance.canonical; - }, - now: now, - isPrimaryRenderer: !1, - prepareForCommit: function() {}, - prepareUpdate: function(instance, type, oldProps, newProps) { - return diffProperties( - null, - oldProps, - newProps, - instance.canonical.viewConfig.validAttributes - ); - }, - resetAfterCommit: function() {}, - scheduleDeferredCallback: function(callback) { - scheduledCallback = callback; - return setTimeout(setTimeoutCallback, 1); - }, - cancelDeferredCallback: function(callbackID) { - scheduledCallback = null; - clearTimeout(callbackID); - }, - shouldDeprioritizeSubtree: function() { - return !1; - }, - shouldSetTextContent: function() { - return !1; - }, - persistence: { - cloneInstance: function( - instance, - updatePayload, - type, - oldProps, - newProps, - internalInstanceHandle, - keepChildren - ) { - type = instance.node; - return { - node: keepChildren - ? null !== updatePayload - ? FabricUIManager.cloneNodeWithNewProps( - type, - updatePayload, - internalInstanceHandle - ) - : FabricUIManager.cloneNode(type, internalInstanceHandle) - : null !== updatePayload - ? FabricUIManager.cloneNodeWithNewChildrenAndProps( - type, - updatePayload, - internalInstanceHandle - ) - : FabricUIManager.cloneNodeWithNewChildren( - type, - internalInstanceHandle - ), - canonical: instance.canonical - }; - }, - createContainerChildSet: function(container) { - return FabricUIManager.createChildSet(container); - }, - appendChildToContainerChildSet: function(childSet, child) { - FabricUIManager.appendChildToSet(childSet, child.node); - }, - finalizeContainerChildren: function(container, newChildren) { - FabricUIManager.completeRoot(container, newChildren); - }, - replaceContainerChildren: function() {} - } - }), - getInspectorDataForViewTag = void 0; +var getInspectorDataForViewTag = void 0; getInspectorDataForViewTag = function() { invariant(!1, "getInspectorDataForViewTag() is not available in production"); }; -var findHostInstance = ReactFabricRenderer.findHostInstance; function findNodeHandle(componentOrHandle) { if (null == componentOrHandle) return null; if ("number" === typeof componentOrHandle) return componentOrHandle; if (componentOrHandle._nativeTag) return componentOrHandle._nativeTag; if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) return componentOrHandle.canonical._nativeTag; - componentOrHandle = findHostInstance(componentOrHandle); + componentOrHandle = findHostInstance$1(componentOrHandle); return null == componentOrHandle ? componentOrHandle : componentOrHandle.canonical @@ -6114,20 +5506,20 @@ var roots = new Map(), }; return ReactNativeComponent; })(React.Component); - })(findNodeHandle, findHostInstance), + })(findNodeHandle, findHostInstance$1), findNodeHandle: findNodeHandle, render: function(element, containerTag, callback) { var root = roots.get(containerTag); root || - ((root = ReactFabricRenderer.createContainer(containerTag, !1, !1)), + ((root = createFiberRoot(containerTag, !1, !1)), roots.set(containerTag, root)); - ReactFabricRenderer.updateContainer(element, root, null, callback); - return ReactFabricRenderer.getPublicRootInstance(root); + updateContainer(element, root, null, callback); + return getPublicRootInstance(root); }, unmountComponentAtNode: function(containerTag) { var root = roots.get(containerTag); root && - ReactFabricRenderer.updateContainer(null, root, null, function() { + updateContainer(null, root, null, function() { roots.delete(containerTag); }); }, @@ -6190,17 +5582,16 @@ var roots = new Map(), TextInputState.blurTextInput(findNodeHandle(this)); } }; - })(findNodeHandle, findHostInstance), - ReactNativeComponentTree: ReactNativeComponentTree + })(findNodeHandle, findHostInstance$1) } }; -ReactFabricRenderer.injectIntoDevTools({ - findFiberByHostInstance: getInstanceFromTag, +injectIntoDevTools({ + findFiberByHostInstance: getInstanceFromInstance, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 0, - version: "16.3.2", + version: "16.4.1", rendererPackageName: "react-native-renderer" }); -var ReactFabric$2 = Object.freeze({ default: ReactFabric }), +var ReactFabric$2 = { default: ReactFabric }, ReactFabric$3 = (ReactFabric$2 && ReactFabric) || ReactFabric$2; module.exports = ReactFabric$3.default ? ReactFabric$3.default : ReactFabric$3; diff --git a/Libraries/Renderer/oss/ReactFabric-profiling.js b/Libraries/Renderer/oss/ReactFabric-profiling.js new file mode 100644 index 00000000000000..f1962978797bc2 --- /dev/null +++ b/Libraries/Renderer/oss/ReactFabric-profiling.js @@ -0,0 +1,5645 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @noflow + * @providesModule ReactFabric-profiling + * @preventMunge + * @generated + */ + +"use strict"; +require("InitializeCore"); +var invariant = require("fbjs/lib/invariant"), + ReactNativeViewConfigRegistry = require("ReactNativeViewConfigRegistry"), + UIManager = require("UIManager"), + React = require("react"), + emptyObject = require("fbjs/lib/emptyObject"), + deepDiffer = require("deepDiffer"), + flattenStyle = require("flattenStyle"), + TextInputState = require("TextInputState"), + FabricUIManager = require("FabricUIManager"), + ExceptionsManager = require("ExceptionsManager"); +function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) { + this._hasCaughtError = !1; + this._caughtError = null; + var funcArgs = Array.prototype.slice.call(arguments, 3); + try { + func.apply(context, funcArgs); + } catch (error) { + (this._caughtError = error), (this._hasCaughtError = !0); + } +} +var ReactErrorUtils = { + _caughtError: null, + _hasCaughtError: !1, + _rethrowError: null, + _hasRethrowError: !1, + invokeGuardedCallback: function(name, func, context, a, b, c, d, e, f) { + invokeGuardedCallback.apply(ReactErrorUtils, arguments); + }, + invokeGuardedCallbackAndCatchFirstError: function( + name, + func, + context, + a, + b, + c, + d, + e, + f + ) { + ReactErrorUtils.invokeGuardedCallback.apply(this, arguments); + if (ReactErrorUtils.hasCaughtError()) { + var error = ReactErrorUtils.clearCaughtError(); + ReactErrorUtils._hasRethrowError || + ((ReactErrorUtils._hasRethrowError = !0), + (ReactErrorUtils._rethrowError = error)); + } + }, + rethrowCaughtError: function() { + return rethrowCaughtError.apply(ReactErrorUtils, arguments); + }, + hasCaughtError: function() { + return ReactErrorUtils._hasCaughtError; + }, + clearCaughtError: function() { + if (ReactErrorUtils._hasCaughtError) { + var error = ReactErrorUtils._caughtError; + ReactErrorUtils._caughtError = null; + ReactErrorUtils._hasCaughtError = !1; + return error; + } + invariant( + !1, + "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue." + ); + } +}; +function rethrowCaughtError() { + if (ReactErrorUtils._hasRethrowError) { + var error = ReactErrorUtils._rethrowError; + ReactErrorUtils._rethrowError = null; + ReactErrorUtils._hasRethrowError = !1; + throw error; + } +} +var eventPluginOrder = null, + namesToPlugins = {}; +function recomputePluginOrdering() { + if (eventPluginOrder) + for (var pluginName in namesToPlugins) { + var pluginModule = namesToPlugins[pluginName], + pluginIndex = eventPluginOrder.indexOf(pluginName); + invariant( + -1 < pluginIndex, + "EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `%s`.", + pluginName + ); + if (!plugins[pluginIndex]) { + invariant( + pluginModule.extractEvents, + "EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `%s` does not.", + pluginName + ); + plugins[pluginIndex] = pluginModule; + pluginIndex = pluginModule.eventTypes; + for (var eventName in pluginIndex) { + var JSCompiler_inline_result = void 0; + var dispatchConfig = pluginIndex[eventName], + pluginModule$jscomp$0 = pluginModule, + eventName$jscomp$0 = eventName; + invariant( + !eventNameDispatchConfigs.hasOwnProperty(eventName$jscomp$0), + "EventPluginHub: More than one plugin attempted to publish the same event name, `%s`.", + eventName$jscomp$0 + ); + eventNameDispatchConfigs[eventName$jscomp$0] = dispatchConfig; + var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames; + if (phasedRegistrationNames) { + for (JSCompiler_inline_result in phasedRegistrationNames) + phasedRegistrationNames.hasOwnProperty( + JSCompiler_inline_result + ) && + publishRegistrationName( + phasedRegistrationNames[JSCompiler_inline_result], + pluginModule$jscomp$0, + eventName$jscomp$0 + ); + JSCompiler_inline_result = !0; + } else + dispatchConfig.registrationName + ? (publishRegistrationName( + dispatchConfig.registrationName, + pluginModule$jscomp$0, + eventName$jscomp$0 + ), + (JSCompiler_inline_result = !0)) + : (JSCompiler_inline_result = !1); + invariant( + JSCompiler_inline_result, + "EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.", + eventName, + pluginName + ); + } + } + } +} +function publishRegistrationName(registrationName, pluginModule) { + invariant( + !registrationNameModules[registrationName], + "EventPluginHub: More than one plugin attempted to publish the same registration name, `%s`.", + registrationName + ); + registrationNameModules[registrationName] = pluginModule; +} +var plugins = [], + eventNameDispatchConfigs = {}, + registrationNameModules = {}, + getFiberCurrentPropsFromNode = null, + getInstanceFromNode = null, + getNodeFromInstance = null; +function executeDispatch(event, simulated, listener, inst) { + simulated = event.type || "unknown-event"; + event.currentTarget = getNodeFromInstance(inst); + ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError( + simulated, + listener, + void 0, + event + ); + event.currentTarget = null; +} +function executeDirectDispatch(event) { + var dispatchListener = event._dispatchListeners, + dispatchInstance = event._dispatchInstances; + invariant( + !Array.isArray(dispatchListener), + "executeDirectDispatch(...): Invalid `event`." + ); + event.currentTarget = dispatchListener + ? getNodeFromInstance(dispatchInstance) + : null; + dispatchListener = dispatchListener ? dispatchListener(event) : null; + event.currentTarget = null; + event._dispatchListeners = null; + event._dispatchInstances = null; + return dispatchListener; +} +function accumulateInto(current, next) { + invariant( + null != next, + "accumulateInto(...): Accumulated items must not be null or undefined." + ); + if (null == current) return next; + if (Array.isArray(current)) { + if (Array.isArray(next)) return current.push.apply(current, next), current; + current.push(next); + return current; + } + return Array.isArray(next) ? [current].concat(next) : [current, next]; +} +function forEachAccumulated(arr, cb, scope) { + Array.isArray(arr) ? arr.forEach(cb, scope) : arr && cb.call(scope, arr); +} +var eventQueue = null; +function executeDispatchesAndReleaseTopLevel(e) { + if (e) { + var dispatchListeners = e._dispatchListeners, + dispatchInstances = e._dispatchInstances; + if (Array.isArray(dispatchListeners)) + for ( + var i = 0; + i < dispatchListeners.length && !e.isPropagationStopped(); + i++ + ) + executeDispatch(e, !1, dispatchListeners[i], dispatchInstances[i]); + else + dispatchListeners && + executeDispatch(e, !1, dispatchListeners, dispatchInstances); + e._dispatchListeners = null; + e._dispatchInstances = null; + e.isPersistent() || e.constructor.release(e); + } +} +var injection = { + injectEventPluginOrder: function(injectedEventPluginOrder) { + invariant( + !eventPluginOrder, + "EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React." + ); + eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder); + recomputePluginOrdering(); + }, + injectEventPluginsByName: function(injectedNamesToPlugins) { + var isOrderingDirty = !1, + pluginName; + for (pluginName in injectedNamesToPlugins) + if (injectedNamesToPlugins.hasOwnProperty(pluginName)) { + var pluginModule = injectedNamesToPlugins[pluginName]; + (namesToPlugins.hasOwnProperty(pluginName) && + namesToPlugins[pluginName] === pluginModule) || + (invariant( + !namesToPlugins[pluginName], + "EventPluginRegistry: Cannot inject two different event plugins using the same name, `%s`.", + pluginName + ), + (namesToPlugins[pluginName] = pluginModule), + (isOrderingDirty = !0)); + } + isOrderingDirty && recomputePluginOrdering(); + } +}; +function getListener(inst, registrationName) { + var listener = inst.stateNode; + if (!listener) return null; + var props = getFiberCurrentPropsFromNode(listener); + if (!props) return null; + listener = props[registrationName]; + a: switch (registrationName) { + case "onClick": + case "onClickCapture": + case "onDoubleClick": + case "onDoubleClickCapture": + case "onMouseDown": + case "onMouseDownCapture": + case "onMouseMove": + case "onMouseMoveCapture": + case "onMouseUp": + case "onMouseUpCapture": + (props = !props.disabled) || + ((inst = inst.type), + (props = !( + "button" === inst || + "input" === inst || + "select" === inst || + "textarea" === inst + ))); + inst = !props; + break a; + default: + inst = !1; + } + if (inst) return null; + invariant( + !listener || "function" === typeof listener, + "Expected `%s` listener to be a function, instead got a value of `%s` type.", + registrationName, + typeof listener + ); + return listener; +} +function getParent(inst) { + do inst = inst.return; + while (inst && 5 !== inst.tag); + return inst ? inst : null; +} +function traverseTwoPhase(inst, fn, arg) { + for (var path = []; inst; ) path.push(inst), (inst = getParent(inst)); + for (inst = path.length; 0 < inst--; ) fn(path[inst], "captured", arg); + for (inst = 0; inst < path.length; inst++) fn(path[inst], "bubbled", arg); +} +function accumulateDirectionalDispatches(inst, phase, event) { + if ( + (phase = getListener( + inst, + event.dispatchConfig.phasedRegistrationNames[phase] + )) + ) + (event._dispatchListeners = accumulateInto( + event._dispatchListeners, + phase + )), + (event._dispatchInstances = accumulateInto( + event._dispatchInstances, + inst + )); +} +function accumulateTwoPhaseDispatchesSingle(event) { + event && + event.dispatchConfig.phasedRegistrationNames && + traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event); +} +function accumulateTwoPhaseDispatchesSingleSkipTarget(event) { + if (event && event.dispatchConfig.phasedRegistrationNames) { + var targetInst = event._targetInst; + targetInst = targetInst ? getParent(targetInst) : null; + traverseTwoPhase(targetInst, accumulateDirectionalDispatches, event); + } +} +function accumulateDirectDispatchesSingle(event) { + if (event && event.dispatchConfig.registrationName) { + var inst = event._targetInst; + if (inst && event && event.dispatchConfig.registrationName) { + var listener = getListener(inst, event.dispatchConfig.registrationName); + listener && + ((event._dispatchListeners = accumulateInto( + event._dispatchListeners, + listener + )), + (event._dispatchInstances = accumulateInto( + event._dispatchInstances, + inst + ))); + } + } +} +var shouldBeReleasedProperties = "dispatchConfig _targetInst nativeEvent isDefaultPrevented isPropagationStopped _dispatchListeners _dispatchInstances".split( + " " +); +function functionThatReturnsTrue() { + return !0; +} +function functionThatReturnsFalse() { + return !1; +} +function SyntheticEvent( + dispatchConfig, + targetInst, + nativeEvent, + nativeEventTarget +) { + this.dispatchConfig = dispatchConfig; + this._targetInst = targetInst; + this.nativeEvent = nativeEvent; + dispatchConfig = this.constructor.Interface; + for (var propName in dispatchConfig) + dispatchConfig.hasOwnProperty(propName) && + ((targetInst = dispatchConfig[propName]) + ? (this[propName] = targetInst(nativeEvent)) + : "target" === propName + ? (this.target = nativeEventTarget) + : (this[propName] = nativeEvent[propName])); + this.isDefaultPrevented = (null != nativeEvent.defaultPrevented + ? nativeEvent.defaultPrevented + : !1 === nativeEvent.returnValue) + ? functionThatReturnsTrue + : functionThatReturnsFalse; + this.isPropagationStopped = functionThatReturnsFalse; + return this; +} +Object.assign(SyntheticEvent.prototype, { + preventDefault: function() { + this.defaultPrevented = !0; + var event = this.nativeEvent; + event && + (event.preventDefault + ? event.preventDefault() + : "unknown" !== typeof event.returnValue && (event.returnValue = !1), + (this.isDefaultPrevented = functionThatReturnsTrue)); + }, + stopPropagation: function() { + var event = this.nativeEvent; + event && + (event.stopPropagation + ? event.stopPropagation() + : "unknown" !== typeof event.cancelBubble && (event.cancelBubble = !0), + (this.isPropagationStopped = functionThatReturnsTrue)); + }, + persist: function() { + this.isPersistent = functionThatReturnsTrue; + }, + isPersistent: functionThatReturnsFalse, + destructor: function() { + var Interface = this.constructor.Interface, + propName; + for (propName in Interface) this[propName] = null; + for ( + Interface = 0; + Interface < shouldBeReleasedProperties.length; + Interface++ + ) + this[shouldBeReleasedProperties[Interface]] = null; + } +}); +SyntheticEvent.Interface = { + type: null, + target: null, + currentTarget: function() { + return null; + }, + eventPhase: null, + bubbles: null, + cancelable: null, + timeStamp: function(event) { + return event.timeStamp || Date.now(); + }, + defaultPrevented: null, + isTrusted: null +}; +SyntheticEvent.extend = function(Interface) { + function E() {} + function Class() { + return Super.apply(this, arguments); + } + var Super = this; + E.prototype = Super.prototype; + var prototype = new E(); + Object.assign(prototype, Class.prototype); + Class.prototype = prototype; + Class.prototype.constructor = Class; + Class.Interface = Object.assign({}, Super.Interface, Interface); + Class.extend = Super.extend; + addEventPoolingTo(Class); + return Class; +}; +addEventPoolingTo(SyntheticEvent); +function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) { + if (this.eventPool.length) { + var instance = this.eventPool.pop(); + this.call(instance, dispatchConfig, targetInst, nativeEvent, nativeInst); + return instance; + } + return new this(dispatchConfig, targetInst, nativeEvent, nativeInst); +} +function releasePooledEvent(event) { + invariant( + event instanceof this, + "Trying to release an event instance into a pool of a different type." + ); + event.destructor(); + 10 > this.eventPool.length && this.eventPool.push(event); +} +function addEventPoolingTo(EventConstructor) { + EventConstructor.eventPool = []; + EventConstructor.getPooled = getPooledEvent; + EventConstructor.release = releasePooledEvent; +} +var ResponderSyntheticEvent = SyntheticEvent.extend({ + touchHistory: function() { + return null; + } +}); +function isStartish(topLevelType) { + return "topTouchStart" === topLevelType; +} +function isMoveish(topLevelType) { + return "topTouchMove" === topLevelType; +} +var startDependencies = ["topTouchStart"], + moveDependencies = ["topTouchMove"], + endDependencies = ["topTouchCancel", "topTouchEnd"], + touchBank = [], + touchHistory = { + touchBank: touchBank, + numberActiveTouches: 0, + indexOfSingleActiveTouch: -1, + mostRecentTimeStamp: 0 + }; +function timestampForTouch(touch) { + return touch.timeStamp || touch.timestamp; +} +function getTouchIdentifier(_ref) { + _ref = _ref.identifier; + invariant(null != _ref, "Touch object is missing identifier."); + return _ref; +} +function recordTouchStart(touch) { + var identifier = getTouchIdentifier(touch), + touchRecord = touchBank[identifier]; + touchRecord + ? ((touchRecord.touchActive = !0), + (touchRecord.startPageX = touch.pageX), + (touchRecord.startPageY = touch.pageY), + (touchRecord.startTimeStamp = timestampForTouch(touch)), + (touchRecord.currentPageX = touch.pageX), + (touchRecord.currentPageY = touch.pageY), + (touchRecord.currentTimeStamp = timestampForTouch(touch)), + (touchRecord.previousPageX = touch.pageX), + (touchRecord.previousPageY = touch.pageY), + (touchRecord.previousTimeStamp = timestampForTouch(touch))) + : ((touchRecord = { + touchActive: !0, + startPageX: touch.pageX, + startPageY: touch.pageY, + startTimeStamp: timestampForTouch(touch), + currentPageX: touch.pageX, + currentPageY: touch.pageY, + currentTimeStamp: timestampForTouch(touch), + previousPageX: touch.pageX, + previousPageY: touch.pageY, + previousTimeStamp: timestampForTouch(touch) + }), + (touchBank[identifier] = touchRecord)); + touchHistory.mostRecentTimeStamp = timestampForTouch(touch); +} +function recordTouchMove(touch) { + var touchRecord = touchBank[getTouchIdentifier(touch)]; + touchRecord + ? ((touchRecord.touchActive = !0), + (touchRecord.previousPageX = touchRecord.currentPageX), + (touchRecord.previousPageY = touchRecord.currentPageY), + (touchRecord.previousTimeStamp = touchRecord.currentTimeStamp), + (touchRecord.currentPageX = touch.pageX), + (touchRecord.currentPageY = touch.pageY), + (touchRecord.currentTimeStamp = timestampForTouch(touch)), + (touchHistory.mostRecentTimeStamp = timestampForTouch(touch))) + : console.error( + "Cannot record touch move without a touch start.\nTouch Move: %s\n", + "Touch Bank: %s", + printTouch(touch), + printTouchBank() + ); +} +function recordTouchEnd(touch) { + var touchRecord = touchBank[getTouchIdentifier(touch)]; + touchRecord + ? ((touchRecord.touchActive = !1), + (touchRecord.previousPageX = touchRecord.currentPageX), + (touchRecord.previousPageY = touchRecord.currentPageY), + (touchRecord.previousTimeStamp = touchRecord.currentTimeStamp), + (touchRecord.currentPageX = touch.pageX), + (touchRecord.currentPageY = touch.pageY), + (touchRecord.currentTimeStamp = timestampForTouch(touch)), + (touchHistory.mostRecentTimeStamp = timestampForTouch(touch))) + : console.error( + "Cannot record touch end without a touch start.\nTouch End: %s\n", + "Touch Bank: %s", + printTouch(touch), + printTouchBank() + ); +} +function printTouch(touch) { + return JSON.stringify({ + identifier: touch.identifier, + pageX: touch.pageX, + pageY: touch.pageY, + timestamp: timestampForTouch(touch) + }); +} +function printTouchBank() { + var printed = JSON.stringify(touchBank.slice(0, 20)); + 20 < touchBank.length && + (printed += " (original size: " + touchBank.length + ")"); + return printed; +} +var ResponderTouchHistoryStore = { + recordTouchTrack: function(topLevelType, nativeEvent) { + if (isMoveish(topLevelType)) + nativeEvent.changedTouches.forEach(recordTouchMove); + else if (isStartish(topLevelType)) + nativeEvent.changedTouches.forEach(recordTouchStart), + (touchHistory.numberActiveTouches = nativeEvent.touches.length), + 1 === touchHistory.numberActiveTouches && + (touchHistory.indexOfSingleActiveTouch = + nativeEvent.touches[0].identifier); + else if ( + "topTouchEnd" === topLevelType || + "topTouchCancel" === topLevelType + ) + if ( + (nativeEvent.changedTouches.forEach(recordTouchEnd), + (touchHistory.numberActiveTouches = nativeEvent.touches.length), + 1 === touchHistory.numberActiveTouches) + ) + for (topLevelType = 0; topLevelType < touchBank.length; topLevelType++) + if ( + ((nativeEvent = touchBank[topLevelType]), + null != nativeEvent && nativeEvent.touchActive) + ) { + touchHistory.indexOfSingleActiveTouch = topLevelType; + break; + } + }, + touchHistory: touchHistory +}; +function accumulate(current, next) { + invariant( + null != next, + "accumulate(...): Accumulated items must be not be null or undefined." + ); + return null == current + ? next + : Array.isArray(current) + ? current.concat(next) + : Array.isArray(next) ? [current].concat(next) : [current, next]; +} +var responderInst = null, + trackedTouchCount = 0; +function changeResponder(nextResponderInst, blockHostResponder) { + var oldResponderInst = responderInst; + responderInst = nextResponderInst; + if (null !== ResponderEventPlugin.GlobalResponderHandler) + ResponderEventPlugin.GlobalResponderHandler.onChange( + oldResponderInst, + nextResponderInst, + blockHostResponder + ); +} +var eventTypes$1 = { + startShouldSetResponder: { + phasedRegistrationNames: { + bubbled: "onStartShouldSetResponder", + captured: "onStartShouldSetResponderCapture" + }, + dependencies: startDependencies + }, + scrollShouldSetResponder: { + phasedRegistrationNames: { + bubbled: "onScrollShouldSetResponder", + captured: "onScrollShouldSetResponderCapture" + }, + dependencies: ["topScroll"] + }, + selectionChangeShouldSetResponder: { + phasedRegistrationNames: { + bubbled: "onSelectionChangeShouldSetResponder", + captured: "onSelectionChangeShouldSetResponderCapture" + }, + dependencies: ["topSelectionChange"] + }, + moveShouldSetResponder: { + phasedRegistrationNames: { + bubbled: "onMoveShouldSetResponder", + captured: "onMoveShouldSetResponderCapture" + }, + dependencies: moveDependencies + }, + responderStart: { + registrationName: "onResponderStart", + dependencies: startDependencies + }, + responderMove: { + registrationName: "onResponderMove", + dependencies: moveDependencies + }, + responderEnd: { + registrationName: "onResponderEnd", + dependencies: endDependencies + }, + responderRelease: { + registrationName: "onResponderRelease", + dependencies: endDependencies + }, + responderTerminationRequest: { + registrationName: "onResponderTerminationRequest", + dependencies: [] + }, + responderGrant: { registrationName: "onResponderGrant", dependencies: [] }, + responderReject: { + registrationName: "onResponderReject", + dependencies: [] + }, + responderTerminate: { + registrationName: "onResponderTerminate", + dependencies: [] + } + }, + ResponderEventPlugin = { + _getResponder: function() { + return responderInst; + }, + eventTypes: eventTypes$1, + extractEvents: function( + topLevelType, + targetInst, + nativeEvent, + nativeEventTarget + ) { + if (isStartish(topLevelType)) trackedTouchCount += 1; + else if ( + "topTouchEnd" === topLevelType || + "topTouchCancel" === topLevelType + ) + if (0 <= trackedTouchCount) --trackedTouchCount; + else + return ( + console.error( + "Ended a touch event which was not counted in `trackedTouchCount`." + ), + null + ); + ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent); + if ( + targetInst && + (("topScroll" === topLevelType && !nativeEvent.responderIgnoreScroll) || + (0 < trackedTouchCount && "topSelectionChange" === topLevelType) || + isStartish(topLevelType) || + isMoveish(topLevelType)) + ) { + var JSCompiler_temp = isStartish(topLevelType) + ? eventTypes$1.startShouldSetResponder + : isMoveish(topLevelType) + ? eventTypes$1.moveShouldSetResponder + : "topSelectionChange" === topLevelType + ? eventTypes$1.selectionChangeShouldSetResponder + : eventTypes$1.scrollShouldSetResponder; + if (responderInst) + b: { + var JSCompiler_temp$jscomp$0 = responderInst; + for ( + var depthA = 0, tempA = JSCompiler_temp$jscomp$0; + tempA; + tempA = getParent(tempA) + ) + depthA++; + tempA = 0; + for (var tempB = targetInst; tempB; tempB = getParent(tempB)) + tempA++; + for (; 0 < depthA - tempA; ) + (JSCompiler_temp$jscomp$0 = getParent(JSCompiler_temp$jscomp$0)), + depthA--; + for (; 0 < tempA - depthA; ) + (targetInst = getParent(targetInst)), tempA--; + for (; depthA--; ) { + if ( + JSCompiler_temp$jscomp$0 === targetInst || + JSCompiler_temp$jscomp$0 === targetInst.alternate + ) + break b; + JSCompiler_temp$jscomp$0 = getParent(JSCompiler_temp$jscomp$0); + targetInst = getParent(targetInst); + } + JSCompiler_temp$jscomp$0 = null; + } + else JSCompiler_temp$jscomp$0 = targetInst; + targetInst = JSCompiler_temp$jscomp$0 === responderInst; + JSCompiler_temp$jscomp$0 = ResponderSyntheticEvent.getPooled( + JSCompiler_temp, + JSCompiler_temp$jscomp$0, + nativeEvent, + nativeEventTarget + ); + JSCompiler_temp$jscomp$0.touchHistory = + ResponderTouchHistoryStore.touchHistory; + targetInst + ? forEachAccumulated( + JSCompiler_temp$jscomp$0, + accumulateTwoPhaseDispatchesSingleSkipTarget + ) + : forEachAccumulated( + JSCompiler_temp$jscomp$0, + accumulateTwoPhaseDispatchesSingle + ); + b: { + JSCompiler_temp = JSCompiler_temp$jscomp$0._dispatchListeners; + targetInst = JSCompiler_temp$jscomp$0._dispatchInstances; + if (Array.isArray(JSCompiler_temp)) + for ( + depthA = 0; + depthA < JSCompiler_temp.length && + !JSCompiler_temp$jscomp$0.isPropagationStopped(); + depthA++ + ) { + if ( + JSCompiler_temp[depthA]( + JSCompiler_temp$jscomp$0, + targetInst[depthA] + ) + ) { + JSCompiler_temp = targetInst[depthA]; + break b; + } + } + else if ( + JSCompiler_temp && + JSCompiler_temp(JSCompiler_temp$jscomp$0, targetInst) + ) { + JSCompiler_temp = targetInst; + break b; + } + JSCompiler_temp = null; + } + JSCompiler_temp$jscomp$0._dispatchInstances = null; + JSCompiler_temp$jscomp$0._dispatchListeners = null; + JSCompiler_temp$jscomp$0.isPersistent() || + JSCompiler_temp$jscomp$0.constructor.release( + JSCompiler_temp$jscomp$0 + ); + JSCompiler_temp && JSCompiler_temp !== responderInst + ? ((JSCompiler_temp$jscomp$0 = void 0), + (targetInst = ResponderSyntheticEvent.getPooled( + eventTypes$1.responderGrant, + JSCompiler_temp, + nativeEvent, + nativeEventTarget + )), + (targetInst.touchHistory = ResponderTouchHistoryStore.touchHistory), + forEachAccumulated(targetInst, accumulateDirectDispatchesSingle), + (depthA = !0 === executeDirectDispatch(targetInst)), + responderInst + ? ((tempA = ResponderSyntheticEvent.getPooled( + eventTypes$1.responderTerminationRequest, + responderInst, + nativeEvent, + nativeEventTarget + )), + (tempA.touchHistory = ResponderTouchHistoryStore.touchHistory), + forEachAccumulated(tempA, accumulateDirectDispatchesSingle), + (tempB = + !tempA._dispatchListeners || executeDirectDispatch(tempA)), + tempA.isPersistent() || tempA.constructor.release(tempA), + tempB + ? ((tempA = ResponderSyntheticEvent.getPooled( + eventTypes$1.responderTerminate, + responderInst, + nativeEvent, + nativeEventTarget + )), + (tempA.touchHistory = + ResponderTouchHistoryStore.touchHistory), + forEachAccumulated(tempA, accumulateDirectDispatchesSingle), + (JSCompiler_temp$jscomp$0 = accumulate( + JSCompiler_temp$jscomp$0, + [targetInst, tempA] + )), + changeResponder(JSCompiler_temp, depthA)) + : ((JSCompiler_temp = ResponderSyntheticEvent.getPooled( + eventTypes$1.responderReject, + JSCompiler_temp, + nativeEvent, + nativeEventTarget + )), + (JSCompiler_temp.touchHistory = + ResponderTouchHistoryStore.touchHistory), + forEachAccumulated( + JSCompiler_temp, + accumulateDirectDispatchesSingle + ), + (JSCompiler_temp$jscomp$0 = accumulate( + JSCompiler_temp$jscomp$0, + JSCompiler_temp + )))) + : ((JSCompiler_temp$jscomp$0 = accumulate( + JSCompiler_temp$jscomp$0, + targetInst + )), + changeResponder(JSCompiler_temp, depthA)), + (JSCompiler_temp = JSCompiler_temp$jscomp$0)) + : (JSCompiler_temp = null); + } else JSCompiler_temp = null; + JSCompiler_temp$jscomp$0 = responderInst && isStartish(topLevelType); + targetInst = responderInst && isMoveish(topLevelType); + depthA = + responderInst && + ("topTouchEnd" === topLevelType || "topTouchCancel" === topLevelType); + if ( + (JSCompiler_temp$jscomp$0 = JSCompiler_temp$jscomp$0 + ? eventTypes$1.responderStart + : targetInst + ? eventTypes$1.responderMove + : depthA ? eventTypes$1.responderEnd : null) + ) + (JSCompiler_temp$jscomp$0 = ResponderSyntheticEvent.getPooled( + JSCompiler_temp$jscomp$0, + responderInst, + nativeEvent, + nativeEventTarget + )), + (JSCompiler_temp$jscomp$0.touchHistory = + ResponderTouchHistoryStore.touchHistory), + forEachAccumulated( + JSCompiler_temp$jscomp$0, + accumulateDirectDispatchesSingle + ), + (JSCompiler_temp = accumulate( + JSCompiler_temp, + JSCompiler_temp$jscomp$0 + )); + JSCompiler_temp$jscomp$0 = + responderInst && "topTouchCancel" === topLevelType; + if ( + (topLevelType = + responderInst && + !JSCompiler_temp$jscomp$0 && + ("topTouchEnd" === topLevelType || "topTouchCancel" === topLevelType)) + ) + a: { + if ((topLevelType = nativeEvent.touches) && 0 !== topLevelType.length) + for (targetInst = 0; targetInst < topLevelType.length; targetInst++) + if ( + ((depthA = topLevelType[targetInst].target), + null !== depthA && void 0 !== depthA && 0 !== depthA) + ) { + tempA = getInstanceFromNode(depthA); + b: { + for (depthA = responderInst; tempA; ) { + if (depthA === tempA || depthA === tempA.alternate) { + depthA = !0; + break b; + } + tempA = getParent(tempA); + } + depthA = !1; + } + if (depthA) { + topLevelType = !1; + break a; + } + } + topLevelType = !0; + } + if ( + (topLevelType = JSCompiler_temp$jscomp$0 + ? eventTypes$1.responderTerminate + : topLevelType ? eventTypes$1.responderRelease : null) + ) + (nativeEvent = ResponderSyntheticEvent.getPooled( + topLevelType, + responderInst, + nativeEvent, + nativeEventTarget + )), + (nativeEvent.touchHistory = ResponderTouchHistoryStore.touchHistory), + forEachAccumulated(nativeEvent, accumulateDirectDispatchesSingle), + (JSCompiler_temp = accumulate(JSCompiler_temp, nativeEvent)), + changeResponder(null); + return JSCompiler_temp; + }, + GlobalResponderHandler: null, + injection: { + injectGlobalResponderHandler: function(GlobalResponderHandler) { + ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler; + } + } + }, + customBubblingEventTypes$1 = + ReactNativeViewConfigRegistry.customBubblingEventTypes, + customDirectEventTypes$1 = + ReactNativeViewConfigRegistry.customDirectEventTypes, + ReactNativeBridgeEventPlugin = { + eventTypes: ReactNativeViewConfigRegistry.eventTypes, + extractEvents: function( + topLevelType, + targetInst, + nativeEvent, + nativeEventTarget + ) { + if (null == targetInst) return null; + var bubbleDispatchConfig = customBubblingEventTypes$1[topLevelType], + directDispatchConfig = customDirectEventTypes$1[topLevelType]; + invariant( + bubbleDispatchConfig || directDispatchConfig, + 'Unsupported top level event type "%s" dispatched', + topLevelType + ); + topLevelType = SyntheticEvent.getPooled( + bubbleDispatchConfig || directDispatchConfig, + targetInst, + nativeEvent, + nativeEventTarget + ); + if (bubbleDispatchConfig) + forEachAccumulated(topLevelType, accumulateTwoPhaseDispatchesSingle); + else if (directDispatchConfig) + forEachAccumulated(topLevelType, accumulateDirectDispatchesSingle); + else return null; + return topLevelType; + } + }; +injection.injectEventPluginOrder([ + "ResponderEventPlugin", + "ReactNativeBridgeEventPlugin" +]); +injection.injectEventPluginsByName({ + ResponderEventPlugin: ResponderEventPlugin, + ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin +}); +function getInstanceFromInstance(instanceHandle) { + return instanceHandle; +} +var Injected$jscomp$inline_574 = { + getClosestInstanceFromNode: getInstanceFromInstance, + getInstanceFromNode: getInstanceFromInstance, + getNodeFromInstance: function(inst) { + inst = inst.stateNode.canonical._nativeTag; + invariant(inst, "All native instances should have a tag."); + return inst; + }, + getFiberCurrentPropsFromNode: function(inst) { + return inst.canonical.currentProps; + } +}; +getFiberCurrentPropsFromNode = + Injected$jscomp$inline_574.getFiberCurrentPropsFromNode; +getInstanceFromNode = Injected$jscomp$inline_574.getInstanceFromNode; +getNodeFromInstance = Injected$jscomp$inline_574.getNodeFromInstance; +ResponderEventPlugin.injection.injectGlobalResponderHandler({ + onChange: function(from, to, blockNativeResponder) { + null !== to + ? UIManager.setJSResponder( + to.stateNode.canonical._nativeTag, + blockNativeResponder + ) + : UIManager.clearJSResponder(); + } +}); +var ReactCurrentOwner = + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, + hasSymbol = "function" === typeof Symbol && Symbol.for, + REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 60103, + REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 60106, + REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 60107, + REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for("react.strict_mode") : 60108, + REACT_PROFILER_TYPE = hasSymbol ? Symbol.for("react.profiler") : 60114, + 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, + REACT_TIMEOUT_TYPE = hasSymbol ? Symbol.for("react.timeout") : 60113, + MAYBE_ITERATOR_SYMBOL = "function" === typeof Symbol && Symbol.iterator; +function getIteratorFn(maybeIterable) { + if (null === maybeIterable || "undefined" === typeof maybeIterable) + return null; + maybeIterable = + (MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) || + maybeIterable["@@iterator"]; + return "function" === typeof maybeIterable ? maybeIterable : null; +} +function getComponentName(fiber) { + var type = fiber.type; + if ("function" === typeof type) return type.displayName || type.name; + if ("string" === typeof type) return type; + switch (type) { + case REACT_ASYNC_MODE_TYPE: + return "AsyncMode"; + case REACT_CONTEXT_TYPE: + return "Context.Consumer"; + case REACT_FRAGMENT_TYPE: + return "ReactFragment"; + case REACT_PORTAL_TYPE: + return "ReactPortal"; + case REACT_PROFILER_TYPE: + return "Profiler(" + fiber.pendingProps.id + ")"; + case REACT_PROVIDER_TYPE: + return "Context.Provider"; + case REACT_STRICT_MODE_TYPE: + return "StrictMode"; + case REACT_TIMEOUT_TYPE: + return "Timeout"; + } + if ("object" === typeof type && null !== type) + switch (type.$$typeof) { + case REACT_FORWARD_REF_TYPE: + return ( + (fiber = type.render.displayName || type.render.name || ""), + "" !== fiber ? "ForwardRef(" + fiber + ")" : "ForwardRef" + ); + } + return null; +} +function isFiberMountedImpl(fiber) { + var node = fiber; + if (fiber.alternate) for (; node.return; ) node = node.return; + else { + if (0 !== (node.effectTag & 2)) return 1; + for (; node.return; ) + if (((node = node.return), 0 !== (node.effectTag & 2))) return 1; + } + return 3 === node.tag ? 2 : 3; +} +function assertIsMounted(fiber) { + invariant( + 2 === isFiberMountedImpl(fiber), + "Unable to find node on an unmounted component." + ); +} +function findCurrentFiberUsingSlowPath(fiber) { + var alternate = fiber.alternate; + if (!alternate) + return ( + (alternate = isFiberMountedImpl(fiber)), + invariant( + 3 !== alternate, + "Unable to find node on an unmounted component." + ), + 1 === alternate ? null : fiber + ); + for (var a = fiber, b = alternate; ; ) { + var parentA = a.return, + parentB = parentA ? parentA.alternate : null; + if (!parentA || !parentB) break; + if (parentA.child === parentB.child) { + for (var child = parentA.child; child; ) { + if (child === a) return assertIsMounted(parentA), fiber; + if (child === b) return assertIsMounted(parentA), alternate; + child = child.sibling; + } + invariant(!1, "Unable to find node on an unmounted component."); + } + if (a.return !== b.return) (a = parentA), (b = parentB); + else { + child = !1; + for (var _child = parentA.child; _child; ) { + if (_child === a) { + child = !0; + a = parentA; + b = parentB; + break; + } + if (_child === b) { + child = !0; + b = parentA; + a = parentB; + break; + } + _child = _child.sibling; + } + if (!child) { + for (_child = parentB.child; _child; ) { + if (_child === a) { + child = !0; + a = parentB; + b = parentA; + break; + } + if (_child === b) { + child = !0; + b = parentB; + a = parentA; + break; + } + _child = _child.sibling; + } + invariant( + child, + "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue." + ); + } + } + invariant( + a.alternate === b, + "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." + ); + } + invariant(3 === a.tag, "Unable to find node on an unmounted component."); + return a.stateNode.current === a ? fiber : alternate; +} +function findCurrentHostFiber(parent) { + parent = findCurrentFiberUsingSlowPath(parent); + if (!parent) return null; + for (var node = parent; ; ) { + if (5 === node.tag || 6 === node.tag) return node; + if (node.child) (node.child.return = node), (node = node.child); + else { + if (node === parent) break; + for (; !node.sibling; ) { + if (!node.return || node.return === parent) return null; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + } + return null; +} +function findCurrentHostFiberWithNoPortals(parent) { + parent = findCurrentFiberUsingSlowPath(parent); + if (!parent) return null; + for (var node = parent; ; ) { + if (5 === node.tag || 6 === node.tag) return node; + if (node.child && 4 !== node.tag) + (node.child.return = node), (node = node.child); + else { + if (node === parent) break; + for (; !node.sibling; ) { + if (!node.return || node.return === parent) return null; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + } + return null; +} +function mountSafeCallback(context, callback) { + return function() { + if (callback) { + if ("boolean" === typeof context.__isMounted) { + if (!context.__isMounted) return; + } else if ( + "function" === typeof context.isMounted && + !context.isMounted() + ) + return; + return callback.apply(context, arguments); + } + }; +} +var emptyObject$1 = {}, + removedKeys = null, + removedKeyCount = 0; +function restoreDeletedValuesInNestedArray( + updatePayload, + node, + validAttributes +) { + if (Array.isArray(node)) + for (var i = node.length; i-- && 0 < removedKeyCount; ) + restoreDeletedValuesInNestedArray( + updatePayload, + node[i], + validAttributes + ); + else if (node && 0 < removedKeyCount) + for (i in removedKeys) + if (removedKeys[i]) { + var _nextProp = node[i]; + if (void 0 !== _nextProp) { + var attributeConfig = validAttributes[i]; + if (attributeConfig) { + "function" === typeof _nextProp && (_nextProp = !0); + "undefined" === typeof _nextProp && (_nextProp = null); + if ("object" !== typeof attributeConfig) + updatePayload[i] = _nextProp; + else if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) + (_nextProp = + "function" === typeof attributeConfig.process + ? attributeConfig.process(_nextProp) + : _nextProp), + (updatePayload[i] = _nextProp); + removedKeys[i] = !1; + removedKeyCount--; + } + } + } +} +function diffNestedProperty( + updatePayload, + prevProp, + nextProp, + validAttributes +) { + if (!updatePayload && prevProp === nextProp) return updatePayload; + if (!prevProp || !nextProp) + return nextProp + ? addNestedProperty(updatePayload, nextProp, validAttributes) + : prevProp + ? clearNestedProperty(updatePayload, prevProp, validAttributes) + : updatePayload; + if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) + return diffProperties(updatePayload, prevProp, nextProp, validAttributes); + if (Array.isArray(prevProp) && Array.isArray(nextProp)) { + var minLength = + prevProp.length < nextProp.length ? prevProp.length : nextProp.length, + i; + for (i = 0; i < minLength; i++) + updatePayload = diffNestedProperty( + updatePayload, + prevProp[i], + nextProp[i], + validAttributes + ); + for (; i < prevProp.length; i++) + updatePayload = clearNestedProperty( + updatePayload, + prevProp[i], + validAttributes + ); + for (; i < nextProp.length; i++) + updatePayload = addNestedProperty( + updatePayload, + nextProp[i], + validAttributes + ); + return updatePayload; + } + return Array.isArray(prevProp) + ? diffProperties( + updatePayload, + flattenStyle(prevProp), + nextProp, + validAttributes + ) + : diffProperties( + updatePayload, + prevProp, + flattenStyle(nextProp), + validAttributes + ); +} +function addNestedProperty(updatePayload, nextProp, validAttributes) { + if (!nextProp) return updatePayload; + if (!Array.isArray(nextProp)) + return diffProperties( + updatePayload, + emptyObject$1, + nextProp, + validAttributes + ); + for (var i = 0; i < nextProp.length; i++) + updatePayload = addNestedProperty( + updatePayload, + nextProp[i], + validAttributes + ); + return updatePayload; +} +function clearNestedProperty(updatePayload, prevProp, validAttributes) { + if (!prevProp) return updatePayload; + if (!Array.isArray(prevProp)) + return diffProperties( + updatePayload, + prevProp, + emptyObject$1, + validAttributes + ); + for (var i = 0; i < prevProp.length; i++) + updatePayload = clearNestedProperty( + updatePayload, + prevProp[i], + validAttributes + ); + return updatePayload; +} +function diffProperties(updatePayload, prevProps, nextProps, validAttributes) { + var attributeConfig, propKey; + for (propKey in nextProps) + if ((attributeConfig = validAttributes[propKey])) { + var prevProp = prevProps[propKey]; + var nextProp = nextProps[propKey]; + "function" === typeof nextProp && + ((nextProp = !0), "function" === typeof prevProp && (prevProp = !0)); + "undefined" === typeof nextProp && + ((nextProp = null), + "undefined" === typeof prevProp && (prevProp = null)); + removedKeys && (removedKeys[propKey] = !1); + if (updatePayload && void 0 !== updatePayload[propKey]) + if ("object" !== typeof attributeConfig) + updatePayload[propKey] = nextProp; + else { + if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) + (attributeConfig = + "function" === typeof attributeConfig.process + ? attributeConfig.process(nextProp) + : nextProp), + (updatePayload[propKey] = attributeConfig); + } + else if (prevProp !== nextProp) + if ("object" !== typeof attributeConfig) + ("object" !== typeof nextProp || + null === nextProp || + deepDiffer(prevProp, nextProp)) && + ((updatePayload || (updatePayload = {}))[propKey] = nextProp); + else if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) { + if ( + void 0 === prevProp || + ("function" === typeof attributeConfig.diff + ? attributeConfig.diff(prevProp, nextProp) + : "object" !== typeof nextProp || + null === nextProp || + deepDiffer(prevProp, nextProp)) + ) + (attributeConfig = + "function" === typeof attributeConfig.process + ? attributeConfig.process(nextProp) + : nextProp), + ((updatePayload || (updatePayload = {}))[ + propKey + ] = attributeConfig); + } else + (removedKeys = null), + (removedKeyCount = 0), + (updatePayload = diffNestedProperty( + updatePayload, + prevProp, + nextProp, + attributeConfig + )), + 0 < removedKeyCount && + updatePayload && + (restoreDeletedValuesInNestedArray( + updatePayload, + nextProp, + attributeConfig + ), + (removedKeys = null)); + } + for (var _propKey in prevProps) + void 0 === nextProps[_propKey] && + (!(attributeConfig = validAttributes[_propKey]) || + (updatePayload && void 0 !== updatePayload[_propKey]) || + ((prevProp = prevProps[_propKey]), + void 0 !== prevProp && + ("object" !== typeof attributeConfig || + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ? (((updatePayload || (updatePayload = {}))[_propKey] = null), + removedKeys || (removedKeys = {}), + removedKeys[_propKey] || + ((removedKeys[_propKey] = !0), removedKeyCount++)) + : (updatePayload = clearNestedProperty( + updatePayload, + prevProp, + attributeConfig + ))))); + return updatePayload; +} +var now$1 = + "object" === typeof performance && "function" === typeof performance.now + ? function() { + return performance.now(); + } + : function() { + return Date.now(); + }, + scheduledCallback = null, + frameDeadline = 0, + frameDeadlineObject = { + timeRemaining: function() { + return frameDeadline - now$1(); + }, + didTimeout: !1 + }; +function setTimeoutCallback() { + frameDeadline = now$1() + 5; + var callback = scheduledCallback; + scheduledCallback = null; + null !== callback && callback(frameDeadlineObject); +} +var restoreTarget = null, + restoreQueue = null; +function restoreStateOfTarget(target) { + if ((target = getInstanceFromNode(target))) { + invariant( + null, + "Fiber needs to be injected to handle a fiber target for controlled events. This error is likely caused by a bug in React. Please file an issue." + ); + var props = getFiberCurrentPropsFromNode(target.stateNode); + null.restoreControlledState(target.stateNode, target.type, props); + } +} +function _batchedUpdates(fn, bookkeeping) { + return fn(bookkeeping); +} +function _flushInteractiveUpdates() {} +var isBatching = !1; +function batchedUpdates(fn, bookkeeping) { + if (isBatching) return fn(bookkeeping); + isBatching = !0; + try { + return _batchedUpdates(fn, bookkeeping); + } finally { + if (((isBatching = !1), null !== restoreTarget || null !== restoreQueue)) + if ( + (_flushInteractiveUpdates(), + restoreTarget && + ((bookkeeping = restoreTarget), + (fn = restoreQueue), + (restoreQueue = restoreTarget = null), + restoreStateOfTarget(bookkeeping), + fn)) + ) + for (bookkeeping = 0; bookkeeping < fn.length; bookkeeping++) + restoreStateOfTarget(fn[bookkeeping]); + } +} +function dispatchEvent(target, topLevelType, nativeEvent) { + batchedUpdates(function() { + var events = nativeEvent.target; + for (var events$jscomp$0 = null, i = 0; i < plugins.length; i++) { + var possiblePlugin = plugins[i]; + possiblePlugin && + (possiblePlugin = possiblePlugin.extractEvents( + topLevelType, + target, + nativeEvent, + events + )) && + (events$jscomp$0 = accumulateInto(events$jscomp$0, possiblePlugin)); + } + events = events$jscomp$0; + null !== events && (eventQueue = accumulateInto(eventQueue, events)); + events = eventQueue; + eventQueue = null; + events && + (forEachAccumulated(events, executeDispatchesAndReleaseTopLevel), + invariant( + !eventQueue, + "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented." + ), + ReactErrorUtils.rethrowCaughtError()); + }); +} +function shim$1() { + invariant( + !1, + "The current renderer does not support hyration. This error is likely caused by a bug in React. Please file an issue." + ); +} +var nextReactTag = 2; +FabricUIManager.registerEventHandler && + FabricUIManager.registerEventHandler(dispatchEvent); +var ReactFabricHostComponent = (function() { + function ReactFabricHostComponent(tag, viewConfig, props) { + if (!(this instanceof ReactFabricHostComponent)) + throw new TypeError("Cannot call a class as a function"); + this._nativeTag = tag; + this.viewConfig = viewConfig; + this.currentProps = props; + } + ReactFabricHostComponent.prototype.blur = function() { + TextInputState.blurTextInput(this._nativeTag); + }; + ReactFabricHostComponent.prototype.focus = function() { + TextInputState.focusTextInput(this._nativeTag); + }; + ReactFabricHostComponent.prototype.measure = function(callback) { + UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); + }; + ReactFabricHostComponent.prototype.measureInWindow = function(callback) { + UIManager.measureInWindow( + this._nativeTag, + mountSafeCallback(this, callback) + ); + }; + ReactFabricHostComponent.prototype.measureLayout = function( + relativeToNativeNode, + onSuccess, + onFail + ) { + UIManager.measureLayout( + this._nativeTag, + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }; + ReactFabricHostComponent.prototype.setNativeProps = function(nativeProps) { + nativeProps = diffProperties( + null, + emptyObject$1, + nativeProps, + this.viewConfig.validAttributes + ); + null != nativeProps && + UIManager.updateView( + this._nativeTag, + this.viewConfig.uiViewClassName, + nativeProps + ); + }; + return ReactFabricHostComponent; +})(); +function createTextInstance( + text, + rootContainerInstance, + hostContext, + internalInstanceHandle +) { + invariant( + hostContext.isInAParentText, + "Text strings must be rendered within a component." + ); + hostContext = nextReactTag; + nextReactTag += 2; + return { + node: FabricUIManager.createNode( + hostContext, + "RCTRawText", + rootContainerInstance, + { text: text }, + internalInstanceHandle + ) + }; +} +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 valueStack = [], + index = -1; +function createCursor(defaultValue) { + return { current: defaultValue }; +} +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; +} +var contextStackCursor = createCursor(emptyObject), + didPerformWorkStackCursor = createCursor(!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 popTopLevelContextObject(fiber) { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} +function pushTopLevelContextObject(fiber, context, didChange) { + invariant( + contextStackCursor.current === emptyObject, + "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; + this.sibling = this.child = this.return = this.stateNode = this.type = null; + this.index = 0; + this.ref = null; + this.pendingProps = pendingProps; + this.memoizedState = this.updateQueue = this.memoizedProps = null; + this.mode = mode; + this.effectTag = 0; + this.lastEffect = this.firstEffect = this.nextEffect = null; + this.expirationTime = 0; + this.alternate = null; + this.treeBaseTime = this.selfBaseTime = this.actualStartTime = this.actualDuration = 0; +} +function createWorkInProgress(current, pendingProps, expirationTime) { + var workInProgress = current.alternate; + null === workInProgress + ? ((workInProgress = new FiberNode( + current.tag, + pendingProps, + current.key, + current.mode + )), + (workInProgress.type = current.type), + (workInProgress.stateNode = current.stateNode), + (workInProgress.alternate = current), + (current.alternate = workInProgress)) + : ((workInProgress.pendingProps = pendingProps), + (workInProgress.effectTag = 0), + (workInProgress.nextEffect = null), + (workInProgress.firstEffect = null), + (workInProgress.lastEffect = null), + (workInProgress.actualDuration = 0), + (workInProgress.actualStartTime = 0)); + workInProgress.expirationTime = expirationTime; + workInProgress.child = current.child; + workInProgress.memoizedProps = current.memoizedProps; + workInProgress.memoizedState = current.memoizedState; + workInProgress.updateQueue = current.updateQueue; + workInProgress.sibling = current.sibling; + workInProgress.index = current.index; + workInProgress.ref = current.ref; + workInProgress.selfBaseTime = current.selfBaseTime; + workInProgress.treeBaseTime = current.treeBaseTime; + return workInProgress; +} +function createFiberFromElement(element, mode, expirationTime) { + var type = element.type, + key = element.key; + element = element.props; + if ("function" === typeof type) + var fiberTag = type.prototype && type.prototype.isReactComponent ? 2 : 0; + else if ("string" === typeof type) fiberTag = 5; + else + switch (type) { + case REACT_FRAGMENT_TYPE: + return createFiberFromFragment( + element.children, + mode, + expirationTime, + key + ); + case REACT_ASYNC_MODE_TYPE: + fiberTag = 11; + mode |= 3; + break; + case REACT_STRICT_MODE_TYPE: + fiberTag = 11; + mode |= 2; + break; + case REACT_PROFILER_TYPE: + return ( + (type = new FiberNode(15, element, key, mode | 4)), + (type.type = REACT_PROFILER_TYPE), + (type.expirationTime = expirationTime), + type + ); + case REACT_TIMEOUT_TYPE: + fiberTag = 16; + mode |= 2; + break; + default: + a: { + switch ("object" === typeof type && null !== type + ? type.$$typeof + : null) { + case REACT_PROVIDER_TYPE: + fiberTag = 13; + break a; + case REACT_CONTEXT_TYPE: + fiberTag = 12; + break a; + case REACT_FORWARD_REF_TYPE: + fiberTag = 14; + break a; + default: + invariant( + !1, + "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", + null == type ? type : typeof type, + "" + ); + } + fiberTag = void 0; + } + } + mode = new FiberNode(fiberTag, element, key, mode); + mode.type = type; + mode.expirationTime = expirationTime; + return mode; +} +function createFiberFromFragment(elements, mode, expirationTime, key) { + elements = new FiberNode(10, elements, key, mode); + elements.expirationTime = expirationTime; + return elements; +} +function createFiberFromText(content, mode, expirationTime) { + content = new FiberNode(6, content, null, mode); + content.expirationTime = expirationTime; + return content; +} +function createFiberFromPortal(portal, mode, expirationTime) { + mode = new FiberNode( + 4, + null !== portal.children ? portal.children : [], + portal.key, + mode + ); + mode.expirationTime = expirationTime; + mode.stateNode = { + containerInfo: portal.containerInfo, + pendingChildren: null, + implementation: portal.implementation + }; + return mode; +} +function createFiberRoot(containerInfo, isAsync, hydrate) { + isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0); + containerInfo = { + current: isAsync, + containerInfo: containerInfo, + pendingChildren: null, + earliestPendingTime: 0, + latestPendingTime: 0, + earliestSuspendedTime: 0, + latestSuspendedTime: 0, + latestPingedTime: 0, + didError: !1, + pendingCommitExpirationTime: 0, + finishedWork: null, + context: null, + pendingContext: null, + hydrate: hydrate, + nextExpirationTimeToWorkOn: 0, + expirationTime: 0, + firstBatch: null, + nextScheduledRoot: null + }; + return (isAsync.stateNode = containerInfo); +} +var onCommitFiberRoot = null, + onCommitFiberUnmount = null; +function catchErrors(fn) { + return function(arg) { + try { + return fn(arg); + } catch (err) {} + }; +} +function injectInternals(internals) { + if ("undefined" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) return !1; + var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__; + if (hook.isDisabled || !hook.supportsFiber) return !0; + try { + var rendererID = hook.inject(internals); + onCommitFiberRoot = catchErrors(function(root) { + return hook.onCommitFiberRoot(rendererID, root); + }); + onCommitFiberUnmount = catchErrors(function(fiber) { + return hook.onCommitFiberUnmount(rendererID, fiber); + }); + } catch (err) {} + return !0; +} +function onCommitRoot(root) { + "function" === typeof onCommitFiberRoot && onCommitFiberRoot(root); +} +function onCommitUnmount(fiber) { + "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(fiber); +} +function markPendingPriorityLevel(root, expirationTime) { + root.didError = !1; + var earliestPendingTime = root.earliestPendingTime; + 0 === earliestPendingTime + ? (root.earliestPendingTime = root.latestPendingTime = expirationTime) + : earliestPendingTime > expirationTime + ? (root.earliestPendingTime = expirationTime) + : root.latestPendingTime < expirationTime && + (root.latestPendingTime = expirationTime); + findNextPendingPriorityLevel(root); +} +function findNextPendingPriorityLevel(root) { + var earliestSuspendedTime = root.earliestSuspendedTime, + earliestPendingTime = root.earliestPendingTime; + if (0 === earliestSuspendedTime) + var nextExpirationTimeToWorkOn = (earliestSuspendedTime = earliestPendingTime); + else + 0 !== earliestPendingTime + ? ((nextExpirationTimeToWorkOn = earliestPendingTime), + (earliestSuspendedTime = + earliestSuspendedTime < earliestPendingTime + ? earliestSuspendedTime + : earliestPendingTime)) + : (nextExpirationTimeToWorkOn = earliestSuspendedTime = + root.latestPingedTime); + root.didError && (earliestSuspendedTime = 1); + root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn; + root.expirationTime = earliestSuspendedTime; +} +var hasForceUpdate = !1; +function createUpdateQueue(baseState) { + return { + expirationTime: 0, + baseState: baseState, + firstUpdate: null, + lastUpdate: null, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; +} +function cloneUpdateQueue(currentQueue) { + return { + expirationTime: currentQueue.expirationTime, + baseState: currentQueue.baseState, + firstUpdate: currentQueue.firstUpdate, + lastUpdate: currentQueue.lastUpdate, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; +} +function createUpdate(expirationTime) { + return { + expirationTime: expirationTime, + tag: 0, + payload: null, + callback: null, + next: null, + nextEffect: null + }; +} +function appendUpdateToQueue(queue, update, expirationTime) { + null === queue.lastUpdate + ? (queue.firstUpdate = queue.lastUpdate = update) + : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); + if (0 === queue.expirationTime || queue.expirationTime > expirationTime) + queue.expirationTime = expirationTime; +} +function enqueueUpdate(fiber, update, expirationTime) { + var alternate = fiber.alternate; + if (null === alternate) { + var queue1 = fiber.updateQueue; + var queue2 = null; + null === queue1 && + (queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState)); + } else + (queue1 = fiber.updateQueue), + (queue2 = alternate.updateQueue), + null === queue1 + ? null === queue2 + ? ((queue1 = fiber.updateQueue = createUpdateQueue( + fiber.memoizedState + )), + (queue2 = alternate.updateQueue = createUpdateQueue( + alternate.memoizedState + ))) + : (queue1 = fiber.updateQueue = cloneUpdateQueue(queue2)) + : null === queue2 && + (queue2 = alternate.updateQueue = cloneUpdateQueue(queue1)); + null === queue2 || queue1 === queue2 + ? appendUpdateToQueue(queue1, update, expirationTime) + : null === queue1.lastUpdate || null === queue2.lastUpdate + ? (appendUpdateToQueue(queue1, update, expirationTime), + appendUpdateToQueue(queue2, update, expirationTime)) + : (appendUpdateToQueue(queue1, update, expirationTime), + (queue2.lastUpdate = update)); +} +function enqueueCapturedUpdate(workInProgress, update, renderExpirationTime) { + var workInProgressQueue = workInProgress.updateQueue; + workInProgressQueue = + null === workInProgressQueue + ? (workInProgress.updateQueue = createUpdateQueue( + workInProgress.memoizedState + )) + : ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue); + null === workInProgressQueue.lastCapturedUpdate + ? (workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update) + : ((workInProgressQueue.lastCapturedUpdate.next = update), + (workInProgressQueue.lastCapturedUpdate = update)); + if ( + 0 === workInProgressQueue.expirationTime || + workInProgressQueue.expirationTime > renderExpirationTime + ) + workInProgressQueue.expirationTime = renderExpirationTime; +} +function ensureWorkInProgressQueueIsAClone(workInProgress, queue) { + var current = workInProgress.alternate; + null !== current && + queue === current.updateQueue && + (queue = workInProgress.updateQueue = cloneUpdateQueue(queue)); + return queue; +} +function getStateFromUpdate( + workInProgress, + queue, + update, + prevState, + nextProps, + instance +) { + switch (update.tag) { + case 1: + return ( + (workInProgress = update.payload), + "function" === typeof workInProgress + ? workInProgress.call(instance, prevState, nextProps) + : workInProgress + ); + case 3: + workInProgress.effectTag = (workInProgress.effectTag & -1025) | 64; + case 0: + workInProgress = update.payload; + nextProps = + "function" === typeof workInProgress + ? workInProgress.call(instance, prevState, nextProps) + : workInProgress; + if (null === nextProps || void 0 === nextProps) break; + return Object.assign({}, prevState, nextProps); + case 2: + hasForceUpdate = !0; + } + return prevState; +} +function processUpdateQueue( + workInProgress, + queue, + props, + instance, + renderExpirationTime +) { + hasForceUpdate = !1; + if ( + !(0 === queue.expirationTime || queue.expirationTime > renderExpirationTime) + ) { + queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + for ( + var newBaseState = queue.baseState, + newFirstUpdate = null, + newExpirationTime = 0, + update = queue.firstUpdate, + resultState = newBaseState; + null !== update; + + ) { + var updateExpirationTime = update.expirationTime; + if (updateExpirationTime > renderExpirationTime) { + if ( + (null === newFirstUpdate && + ((newFirstUpdate = update), (newBaseState = resultState)), + 0 === newExpirationTime || newExpirationTime > updateExpirationTime) + ) + newExpirationTime = updateExpirationTime; + } else + (resultState = getStateFromUpdate( + workInProgress, + queue, + update, + resultState, + props, + instance + )), + null !== update.callback && + ((workInProgress.effectTag |= 32), + (update.nextEffect = null), + null === queue.lastEffect + ? (queue.firstEffect = queue.lastEffect = update) + : ((queue.lastEffect.nextEffect = update), + (queue.lastEffect = update))); + update = update.next; + } + updateExpirationTime = null; + for (update = queue.firstCapturedUpdate; null !== update; ) { + var _updateExpirationTime = update.expirationTime; + if (_updateExpirationTime > renderExpirationTime) { + if ( + (null === updateExpirationTime && + ((updateExpirationTime = update), + null === newFirstUpdate && (newBaseState = resultState)), + 0 === newExpirationTime || newExpirationTime > _updateExpirationTime) + ) + newExpirationTime = _updateExpirationTime; + } else + (resultState = getStateFromUpdate( + workInProgress, + queue, + update, + resultState, + props, + instance + )), + null !== update.callback && + ((workInProgress.effectTag |= 32), + (update.nextEffect = null), + null === queue.lastCapturedEffect + ? (queue.firstCapturedEffect = queue.lastCapturedEffect = update) + : ((queue.lastCapturedEffect.nextEffect = update), + (queue.lastCapturedEffect = update))); + update = update.next; + } + null === newFirstUpdate && (queue.lastUpdate = null); + null === updateExpirationTime + ? (queue.lastCapturedUpdate = null) + : (workInProgress.effectTag |= 32); + null === newFirstUpdate && + null === updateExpirationTime && + (newBaseState = resultState); + queue.baseState = newBaseState; + queue.firstUpdate = newFirstUpdate; + queue.firstCapturedUpdate = updateExpirationTime; + queue.expirationTime = newExpirationTime; + workInProgress.memoizedState = resultState; + } +} +function callCallback(callback, context) { + invariant( + "function" === typeof callback, + "Invalid argument passed as callback. Expected a function. Instead received: %s", + callback + ); + callback.call(context); +} +function commitUpdateQueue(finishedWork, finishedQueue, instance) { + null !== finishedQueue.firstCapturedUpdate && + (null !== finishedQueue.lastUpdate && + ((finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate), + (finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate)), + (finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null)); + finishedWork = finishedQueue.firstEffect; + for ( + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + null !== finishedWork; + + ) { + var _callback3 = finishedWork.callback; + null !== _callback3 && + ((finishedWork.callback = null), callCallback(_callback3, instance)); + finishedWork = finishedWork.nextEffect; + } + finishedWork = finishedQueue.firstCapturedEffect; + for ( + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; + null !== finishedWork; + + ) + (finishedQueue = finishedWork.callback), + null !== finishedQueue && + ((finishedWork.callback = null), callCallback(finishedQueue, instance)), + (finishedWork = finishedWork.nextEffect); +} +function createCapturedValue(value, source) { + return { + value: value, + source: source, + stack: getStackAddendumByWorkInProgressFiber(source) + }; +} +var providerCursor = createCursor(null), + valueCursor = createCursor(null), + changedBitsCursor = createCursor(0); +function pushProvider(providerFiber) { + var context = providerFiber.type._context; + push(changedBitsCursor, context._changedBits2, providerFiber); + push(valueCursor, context._currentValue2, providerFiber); + push(providerCursor, providerFiber, providerFiber); + context._currentValue2 = providerFiber.pendingProps.value; + context._changedBits2 = providerFiber.stateNode; +} +function popProvider(providerFiber) { + var changedBits = changedBitsCursor.current, + currentValue = valueCursor.current; + pop(providerCursor, providerFiber); + pop(valueCursor, providerFiber); + pop(changedBitsCursor, providerFiber); + providerFiber = providerFiber.type._context; + providerFiber._currentValue2 = currentValue; + providerFiber._changedBits2 = changedBits; +} +var NO_CONTEXT = {}, + contextStackCursor$1 = createCursor(NO_CONTEXT), + contextFiberStackCursor = createCursor(NO_CONTEXT), + rootInstanceStackCursor = createCursor(NO_CONTEXT); +function requiredContext(c) { + invariant( + c !== NO_CONTEXT, + "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." + ); + return c; +} +function pushHostContainer(fiber, nextRootInstance) { + push(rootInstanceStackCursor, nextRootInstance, fiber); + push(contextFiberStackCursor, fiber, fiber); + push(contextStackCursor$1, NO_CONTEXT, fiber); + pop(contextStackCursor$1, fiber); + push(contextStackCursor$1, { isInAParentText: !1 }, fiber); +} +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} +function popHostContext(fiber) { + contextFiberStackCursor.current === fiber && + (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); +} +var timerPausedAt = 0, + totalElapsedPauseTime = 0; +function recordElapsedActualRenderTime(fiber) { + fiber.actualDuration = now$1() - totalElapsedPauseTime - fiber.actualDuration; +} +function resumeActualRenderTimerIfPaused() { + 0 < timerPausedAt && + ((totalElapsedPauseTime += now$1() - timerPausedAt), (timerPausedAt = 0)); +} +var baseStartTime = -1, + hasOwnProperty = Object.prototype.hasOwnProperty; +function is(x, y) { + return x === y ? 0 !== x || 0 !== y || 1 / x === 1 / y : x !== x && y !== y; +} +function shallowEqual(objA, objB) { + if (is(objA, objB)) return !0; + if ( + "object" !== typeof objA || + null === objA || + "object" !== typeof objB || + null === objB + ) + return !1; + var keysA = Object.keys(objA), + keysB = Object.keys(objB); + if (keysA.length !== keysB.length) return !1; + for (keysB = 0; keysB < keysA.length; keysB++) + if ( + !hasOwnProperty.call(objB, keysA[keysB]) || + !is(objA[keysA[keysB]], objB[keysA[keysB]]) + ) + return !1; + return !0; +} +function applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + nextProps +) { + var prevState = workInProgress.memoizedState; + getDerivedStateFromProps = getDerivedStateFromProps(nextProps, prevState); + prevState = + null === getDerivedStateFromProps || void 0 === getDerivedStateFromProps + ? prevState + : Object.assign({}, prevState, getDerivedStateFromProps); + workInProgress.memoizedState = prevState; + workInProgress = workInProgress.updateQueue; + null !== workInProgress && + 0 === workInProgress.expirationTime && + (workInProgress.baseState = prevState); +} +var classComponentUpdater = { + isMounted: function(component) { + return (component = component._reactInternalFiber) + ? 2 === isFiberMountedImpl(component) + : !1; + }, + enqueueSetState: function(inst, payload, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.payload = payload; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + }, + enqueueReplaceState: function(inst, payload, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.tag = 1; + update.payload = payload; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + }, + enqueueForceUpdate: function(inst, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.tag = 2; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + } +}; +function checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext +) { + var instance = workInProgress.stateNode; + workInProgress = workInProgress.type; + return "function" === typeof instance.shouldComponentUpdate + ? instance.shouldComponentUpdate(newProps, newState, newContext) + : workInProgress.prototype && workInProgress.prototype.isPureReactComponent + ? !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) + : !0; +} +function callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext +) { + workInProgress = instance.state; + "function" === typeof instance.componentWillReceiveProps && + instance.componentWillReceiveProps(newProps, newContext); + "function" === typeof instance.UNSAFE_componentWillReceiveProps && + instance.UNSAFE_componentWillReceiveProps(newProps, newContext); + instance.state !== workInProgress && + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); +} +function mountClassInstance(workInProgress, renderExpirationTime) { + var ctor = workInProgress.type, + instance = workInProgress.stateNode, + props = workInProgress.pendingProps, + unmaskedContext = getUnmaskedContext(workInProgress); + instance.props = props; + instance.state = workInProgress.memoizedState; + instance.refs = emptyObject; + instance.context = getMaskedContext(workInProgress, unmaskedContext); + unmaskedContext = workInProgress.updateQueue; + null !== unmaskedContext && + (processUpdateQueue( + workInProgress, + unmaskedContext, + props, + instance, + renderExpirationTime + ), + (instance.state = workInProgress.memoizedState)); + unmaskedContext = workInProgress.type.getDerivedStateFromProps; + "function" === typeof unmaskedContext && + (applyDerivedStateFromProps(workInProgress, unmaskedContext, props), + (instance.state = workInProgress.memoizedState)); + "function" === typeof ctor.getDerivedStateFromProps || + "function" === typeof instance.getSnapshotBeforeUpdate || + ("function" !== typeof instance.UNSAFE_componentWillMount && + "function" !== typeof instance.componentWillMount) || + ((ctor = instance.state), + "function" === typeof instance.componentWillMount && + instance.componentWillMount(), + "function" === typeof instance.UNSAFE_componentWillMount && + instance.UNSAFE_componentWillMount(), + ctor !== instance.state && + classComponentUpdater.enqueueReplaceState(instance, instance.state, null), + (unmaskedContext = workInProgress.updateQueue), + null !== unmaskedContext && + (processUpdateQueue( + workInProgress, + unmaskedContext, + props, + instance, + renderExpirationTime + ), + (instance.state = workInProgress.memoizedState))); + "function" === typeof instance.componentDidMount && + (workInProgress.effectTag |= 4); +} +var isArray$1 = Array.isArray; +function coerceRef(returnFiber, current, element) { + returnFiber = element.ref; + if ( + null !== returnFiber && + "function" !== typeof returnFiber && + "object" !== typeof returnFiber + ) { + if (element._owner) { + element = element._owner; + var inst = void 0; + element && + (invariant( + 2 === element.tag, + "Stateless function components cannot have refs." + ), + (inst = element.stateNode)); + invariant( + inst, + "Missing owner for string ref %s. This error is likely caused by a bug in React. Please file an issue.", + returnFiber + ); + var stringRef = "" + returnFiber; + if ( + null !== current && + null !== current.ref && + "function" === typeof current.ref && + current.ref._stringRef === stringRef + ) + return current.ref; + current = function(value) { + var refs = inst.refs === emptyObject ? (inst.refs = {}) : inst.refs; + null === value ? delete refs[stringRef] : (refs[stringRef] = value); + }; + current._stringRef = stringRef; + return current; + } + invariant( + "string" === typeof returnFiber, + "Expected ref to be a function or a string." + ); + invariant( + element._owner, + "Element ref was specified as a string (%s) but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a functional component\n2. You may be adding a ref to a component that was not created inside a component's render method\n3. You have multiple copies of React loaded\nSee https://fb.me/react-refs-must-have-owner for more information.", + returnFiber + ); + } + return returnFiber; +} +function throwOnInvalidObjectType(returnFiber, newChild) { + "textarea" !== returnFiber.type && + invariant( + !1, + "Objects are not valid as a React child (found: %s).%s", + "[object Object]" === Object.prototype.toString.call(newChild) + ? "object with keys {" + Object.keys(newChild).join(", ") + "}" + : newChild, + "" + ); +} +function ChildReconciler(shouldTrackSideEffects) { + function deleteChild(returnFiber, childToDelete) { + if (shouldTrackSideEffects) { + var last = returnFiber.lastEffect; + null !== last + ? ((last.nextEffect = childToDelete), + (returnFiber.lastEffect = childToDelete)) + : (returnFiber.firstEffect = returnFiber.lastEffect = childToDelete); + childToDelete.nextEffect = null; + childToDelete.effectTag = 8; + } + } + function deleteRemainingChildren(returnFiber, currentFirstChild) { + if (!shouldTrackSideEffects) return null; + for (; null !== currentFirstChild; ) + deleteChild(returnFiber, currentFirstChild), + (currentFirstChild = currentFirstChild.sibling); + return null; + } + function mapRemainingChildren(returnFiber, currentFirstChild) { + for (returnFiber = new Map(); null !== currentFirstChild; ) + null !== currentFirstChild.key + ? returnFiber.set(currentFirstChild.key, currentFirstChild) + : returnFiber.set(currentFirstChild.index, currentFirstChild), + (currentFirstChild = currentFirstChild.sibling); + return returnFiber; + } + function useFiber(fiber, pendingProps, expirationTime) { + fiber = createWorkInProgress(fiber, pendingProps, expirationTime); + fiber.index = 0; + fiber.sibling = null; + return fiber; + } + function placeChild(newFiber, lastPlacedIndex, newIndex) { + newFiber.index = newIndex; + if (!shouldTrackSideEffects) return lastPlacedIndex; + newIndex = newFiber.alternate; + if (null !== newIndex) + return ( + (newIndex = newIndex.index), + newIndex < lastPlacedIndex + ? ((newFiber.effectTag = 2), lastPlacedIndex) + : newIndex + ); + newFiber.effectTag = 2; + return lastPlacedIndex; + } + function placeSingleChild(newFiber) { + shouldTrackSideEffects && + null === newFiber.alternate && + (newFiber.effectTag = 2); + return newFiber; + } + function updateTextNode(returnFiber, current, textContent, expirationTime) { + if (null === current || 6 !== current.tag) + return ( + (current = createFiberFromText( + textContent, + returnFiber.mode, + expirationTime + )), + (current.return = returnFiber), + current + ); + current = useFiber(current, textContent, expirationTime); + current.return = returnFiber; + return current; + } + function updateElement(returnFiber, current, element, expirationTime) { + if (null !== current && current.type === element.type) + return ( + (expirationTime = useFiber(current, element.props, expirationTime)), + (expirationTime.ref = coerceRef(returnFiber, current, element)), + (expirationTime.return = returnFiber), + expirationTime + ); + expirationTime = createFiberFromElement( + element, + returnFiber.mode, + expirationTime + ); + expirationTime.ref = coerceRef(returnFiber, current, element); + expirationTime.return = returnFiber; + return expirationTime; + } + function updatePortal(returnFiber, current, portal, expirationTime) { + if ( + null === current || + 4 !== current.tag || + current.stateNode.containerInfo !== portal.containerInfo || + current.stateNode.implementation !== portal.implementation + ) + return ( + (current = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime + )), + (current.return = returnFiber), + current + ); + current = useFiber(current, portal.children || [], expirationTime); + current.return = returnFiber; + return current; + } + function updateFragment(returnFiber, current, fragment, expirationTime, key) { + if (null === current || 10 !== current.tag) + return ( + (current = createFiberFromFragment( + fragment, + returnFiber.mode, + expirationTime, + key + )), + (current.return = returnFiber), + current + ); + current = useFiber(current, fragment, expirationTime); + current.return = returnFiber; + return current; + } + function createChild(returnFiber, newChild, expirationTime) { + if ("string" === typeof newChild || "number" === typeof newChild) + return ( + (newChild = createFiberFromText( + "" + newChild, + returnFiber.mode, + expirationTime + )), + (newChild.return = returnFiber), + newChild + ); + if ("object" === typeof newChild && null !== newChild) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + return ( + (expirationTime = createFiberFromElement( + newChild, + returnFiber.mode, + expirationTime + )), + (expirationTime.ref = coerceRef(returnFiber, null, newChild)), + (expirationTime.return = returnFiber), + expirationTime + ); + case REACT_PORTAL_TYPE: + return ( + (newChild = createFiberFromPortal( + newChild, + returnFiber.mode, + expirationTime + )), + (newChild.return = returnFiber), + newChild + ); + } + if (isArray$1(newChild) || getIteratorFn(newChild)) + return ( + (newChild = createFiberFromFragment( + newChild, + returnFiber.mode, + expirationTime, + null + )), + (newChild.return = returnFiber), + newChild + ); + throwOnInvalidObjectType(returnFiber, newChild); + } + return null; + } + function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { + var key = null !== oldFiber ? oldFiber.key : null; + if ("string" === typeof newChild || "number" === typeof newChild) + return null !== key + ? null + : updateTextNode(returnFiber, oldFiber, "" + newChild, expirationTime); + if ("object" === typeof newChild && null !== newChild) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + return newChild.key === key + ? newChild.type === REACT_FRAGMENT_TYPE + ? updateFragment( + returnFiber, + oldFiber, + newChild.props.children, + expirationTime, + key + ) + : updateElement(returnFiber, oldFiber, newChild, expirationTime) + : null; + case REACT_PORTAL_TYPE: + return newChild.key === key + ? updatePortal(returnFiber, oldFiber, newChild, expirationTime) + : null; + } + if (isArray$1(newChild) || getIteratorFn(newChild)) + return null !== key + ? null + : updateFragment( + returnFiber, + oldFiber, + newChild, + expirationTime, + null + ); + throwOnInvalidObjectType(returnFiber, newChild); + } + return null; + } + function updateFromMap( + existingChildren, + returnFiber, + newIdx, + newChild, + expirationTime + ) { + if ("string" === typeof newChild || "number" === typeof newChild) + return ( + (existingChildren = existingChildren.get(newIdx) || null), + updateTextNode( + returnFiber, + existingChildren, + "" + newChild, + expirationTime + ) + ); + if ("object" === typeof newChild && null !== newChild) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + return ( + (existingChildren = + existingChildren.get( + null === newChild.key ? newIdx : newChild.key + ) || null), + newChild.type === REACT_FRAGMENT_TYPE + ? updateFragment( + returnFiber, + existingChildren, + newChild.props.children, + expirationTime, + newChild.key + ) + : updateElement( + returnFiber, + existingChildren, + newChild, + expirationTime + ) + ); + case REACT_PORTAL_TYPE: + return ( + (existingChildren = + existingChildren.get( + null === newChild.key ? newIdx : newChild.key + ) || null), + updatePortal( + returnFiber, + existingChildren, + newChild, + expirationTime + ) + ); + } + if (isArray$1(newChild) || getIteratorFn(newChild)) + return ( + (existingChildren = existingChildren.get(newIdx) || null), + updateFragment( + returnFiber, + existingChildren, + newChild, + expirationTime, + null + ) + ); + throwOnInvalidObjectType(returnFiber, newChild); + } + return null; + } + function reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChildren, + expirationTime + ) { + for ( + var resultingFirstChild = null, + previousNewFiber = null, + oldFiber = currentFirstChild, + newIdx = (currentFirstChild = 0), + nextOldFiber = null; + null !== oldFiber && newIdx < newChildren.length; + newIdx++ + ) { + oldFiber.index > newIdx + ? ((nextOldFiber = oldFiber), (oldFiber = null)) + : (nextOldFiber = oldFiber.sibling); + var newFiber = updateSlot( + returnFiber, + oldFiber, + newChildren[newIdx], + expirationTime + ); + if (null === newFiber) { + null === oldFiber && (oldFiber = nextOldFiber); + break; + } + shouldTrackSideEffects && + oldFiber && + null === newFiber.alternate && + deleteChild(returnFiber, oldFiber); + currentFirstChild = placeChild(newFiber, currentFirstChild, newIdx); + null === previousNewFiber + ? (resultingFirstChild = newFiber) + : (previousNewFiber.sibling = newFiber); + previousNewFiber = newFiber; + oldFiber = nextOldFiber; + } + if (newIdx === newChildren.length) + return ( + deleteRemainingChildren(returnFiber, oldFiber), resultingFirstChild + ); + if (null === oldFiber) { + for (; newIdx < newChildren.length; newIdx++) + if ( + (oldFiber = createChild( + returnFiber, + newChildren[newIdx], + expirationTime + )) + ) + (currentFirstChild = placeChild(oldFiber, currentFirstChild, newIdx)), + null === previousNewFiber + ? (resultingFirstChild = oldFiber) + : (previousNewFiber.sibling = oldFiber), + (previousNewFiber = oldFiber); + return resultingFirstChild; + } + for ( + oldFiber = mapRemainingChildren(returnFiber, oldFiber); + newIdx < newChildren.length; + newIdx++ + ) + if ( + (nextOldFiber = updateFromMap( + oldFiber, + returnFiber, + newIdx, + newChildren[newIdx], + expirationTime + )) + ) + shouldTrackSideEffects && + null !== nextOldFiber.alternate && + oldFiber.delete( + null === nextOldFiber.key ? newIdx : nextOldFiber.key + ), + (currentFirstChild = placeChild( + nextOldFiber, + currentFirstChild, + newIdx + )), + null === previousNewFiber + ? (resultingFirstChild = nextOldFiber) + : (previousNewFiber.sibling = nextOldFiber), + (previousNewFiber = nextOldFiber); + shouldTrackSideEffects && + oldFiber.forEach(function(child) { + return deleteChild(returnFiber, child); + }); + return resultingFirstChild; + } + function reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChildrenIterable, + expirationTime + ) { + var iteratorFn = getIteratorFn(newChildrenIterable); + invariant( + "function" === typeof iteratorFn, + "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue." + ); + newChildrenIterable = iteratorFn.call(newChildrenIterable); + invariant( + null != newChildrenIterable, + "An iterable object provided no iterator." + ); + for ( + var previousNewFiber = (iteratorFn = null), + oldFiber = currentFirstChild, + newIdx = (currentFirstChild = 0), + nextOldFiber = null, + step = newChildrenIterable.next(); + null !== oldFiber && !step.done; + newIdx++, step = newChildrenIterable.next() + ) { + oldFiber.index > newIdx + ? ((nextOldFiber = oldFiber), (oldFiber = null)) + : (nextOldFiber = oldFiber.sibling); + var newFiber = updateSlot( + returnFiber, + oldFiber, + step.value, + expirationTime + ); + if (null === newFiber) { + oldFiber || (oldFiber = nextOldFiber); + break; + } + shouldTrackSideEffects && + oldFiber && + null === newFiber.alternate && + deleteChild(returnFiber, oldFiber); + currentFirstChild = placeChild(newFiber, currentFirstChild, newIdx); + null === previousNewFiber + ? (iteratorFn = newFiber) + : (previousNewFiber.sibling = newFiber); + previousNewFiber = newFiber; + oldFiber = nextOldFiber; + } + if (step.done) + return deleteRemainingChildren(returnFiber, oldFiber), iteratorFn; + if (null === oldFiber) { + for (; !step.done; newIdx++, step = newChildrenIterable.next()) + (step = createChild(returnFiber, step.value, expirationTime)), + null !== step && + ((currentFirstChild = placeChild(step, currentFirstChild, newIdx)), + null === previousNewFiber + ? (iteratorFn = step) + : (previousNewFiber.sibling = step), + (previousNewFiber = step)); + return iteratorFn; + } + for ( + oldFiber = mapRemainingChildren(returnFiber, oldFiber); + !step.done; + newIdx++, step = newChildrenIterable.next() + ) + (step = updateFromMap( + oldFiber, + returnFiber, + newIdx, + step.value, + expirationTime + )), + null !== step && + (shouldTrackSideEffects && + null !== step.alternate && + oldFiber.delete(null === step.key ? newIdx : step.key), + (currentFirstChild = placeChild(step, currentFirstChild, newIdx)), + null === previousNewFiber + ? (iteratorFn = step) + : (previousNewFiber.sibling = step), + (previousNewFiber = step)); + shouldTrackSideEffects && + oldFiber.forEach(function(child) { + return deleteChild(returnFiber, child); + }); + return iteratorFn; + } + return function(returnFiber, currentFirstChild, newChild, expirationTime) { + var isUnkeyedTopLevelFragment = + "object" === typeof newChild && + null !== newChild && + newChild.type === REACT_FRAGMENT_TYPE && + null === newChild.key; + isUnkeyedTopLevelFragment && (newChild = newChild.props.children); + var isObject = "object" === typeof newChild && null !== newChild; + if (isObject) + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + a: { + isObject = newChild.key; + for ( + isUnkeyedTopLevelFragment = currentFirstChild; + null !== isUnkeyedTopLevelFragment; + + ) { + if (isUnkeyedTopLevelFragment.key === isObject) + if ( + 10 === isUnkeyedTopLevelFragment.tag + ? newChild.type === REACT_FRAGMENT_TYPE + : isUnkeyedTopLevelFragment.type === newChild.type + ) { + deleteRemainingChildren( + returnFiber, + isUnkeyedTopLevelFragment.sibling + ); + currentFirstChild = useFiber( + isUnkeyedTopLevelFragment, + newChild.type === REACT_FRAGMENT_TYPE + ? newChild.props.children + : newChild.props, + expirationTime + ); + currentFirstChild.ref = coerceRef( + returnFiber, + isUnkeyedTopLevelFragment, + newChild + ); + currentFirstChild.return = returnFiber; + returnFiber = currentFirstChild; + break a; + } else { + deleteRemainingChildren( + returnFiber, + isUnkeyedTopLevelFragment + ); + break; + } + else deleteChild(returnFiber, isUnkeyedTopLevelFragment); + isUnkeyedTopLevelFragment = isUnkeyedTopLevelFragment.sibling; + } + newChild.type === REACT_FRAGMENT_TYPE + ? ((currentFirstChild = createFiberFromFragment( + newChild.props.children, + returnFiber.mode, + expirationTime, + newChild.key + )), + (currentFirstChild.return = returnFiber), + (returnFiber = currentFirstChild)) + : ((expirationTime = createFiberFromElement( + newChild, + returnFiber.mode, + expirationTime + )), + (expirationTime.ref = coerceRef( + returnFiber, + currentFirstChild, + newChild + )), + (expirationTime.return = returnFiber), + (returnFiber = expirationTime)); + } + return placeSingleChild(returnFiber); + case REACT_PORTAL_TYPE: + a: { + for ( + isUnkeyedTopLevelFragment = newChild.key; + null !== currentFirstChild; + + ) { + if (currentFirstChild.key === isUnkeyedTopLevelFragment) + if ( + 4 === currentFirstChild.tag && + currentFirstChild.stateNode.containerInfo === + newChild.containerInfo && + currentFirstChild.stateNode.implementation === + newChild.implementation + ) { + deleteRemainingChildren( + returnFiber, + currentFirstChild.sibling + ); + currentFirstChild = useFiber( + currentFirstChild, + newChild.children || [], + expirationTime + ); + currentFirstChild.return = returnFiber; + returnFiber = currentFirstChild; + break a; + } else { + deleteRemainingChildren(returnFiber, currentFirstChild); + break; + } + else deleteChild(returnFiber, currentFirstChild); + currentFirstChild = currentFirstChild.sibling; + } + currentFirstChild = createFiberFromPortal( + newChild, + returnFiber.mode, + expirationTime + ); + currentFirstChild.return = returnFiber; + returnFiber = currentFirstChild; + } + return placeSingleChild(returnFiber); + } + if ("string" === typeof newChild || "number" === typeof newChild) + return ( + (newChild = "" + newChild), + null !== currentFirstChild && 6 === currentFirstChild.tag + ? (deleteRemainingChildren(returnFiber, currentFirstChild.sibling), + (currentFirstChild = useFiber( + currentFirstChild, + newChild, + expirationTime + )), + (currentFirstChild.return = returnFiber), + (returnFiber = currentFirstChild)) + : (deleteRemainingChildren(returnFiber, currentFirstChild), + (currentFirstChild = createFiberFromText( + newChild, + returnFiber.mode, + expirationTime + )), + (currentFirstChild.return = returnFiber), + (returnFiber = currentFirstChild)), + placeSingleChild(returnFiber) + ); + if (isArray$1(newChild)) + return reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); + if (getIteratorFn(newChild)) + return reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); + isObject && throwOnInvalidObjectType(returnFiber, newChild); + if ("undefined" === typeof newChild && !isUnkeyedTopLevelFragment) + switch (returnFiber.tag) { + case 2: + case 1: + (expirationTime = returnFiber.type), + invariant( + !1, + "%s(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.", + expirationTime.displayName || expirationTime.name || "Component" + ); + } + return deleteRemainingChildren(returnFiber, currentFirstChild); + }; +} +var reconcileChildFibers = ChildReconciler(!0), + mountChildFibers = ChildReconciler(!1), + hydrationParentFiber = null, + nextHydratableInstance = null, + isHydrating = !1; +function tryHydrate(fiber, nextInstance) { + switch (fiber.tag) { + case 5: + return ( + (nextInstance = shim$1(nextInstance, fiber.type, fiber.pendingProps)), + null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 + ); + case 6: + return ( + (nextInstance = shim$1(nextInstance, fiber.pendingProps)), + null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 + ); + default: + return !1; + } +} +function tryToClaimNextHydratableInstance(fiber$jscomp$0) { + if (isHydrating) { + var nextInstance = nextHydratableInstance; + if (nextInstance) { + var firstAttemptedInstance = nextInstance; + if (!tryHydrate(fiber$jscomp$0, nextInstance)) { + nextInstance = shim$1(firstAttemptedInstance); + if (!nextInstance || !tryHydrate(fiber$jscomp$0, nextInstance)) { + fiber$jscomp$0.effectTag |= 2; + isHydrating = !1; + hydrationParentFiber = fiber$jscomp$0; + return; + } + var returnFiber = hydrationParentFiber, + fiber = new FiberNode(5, null, null, 0); + fiber.type = "DELETED"; + fiber.stateNode = firstAttemptedInstance; + fiber.return = returnFiber; + fiber.effectTag = 8; + null !== returnFiber.lastEffect + ? ((returnFiber.lastEffect.nextEffect = fiber), + (returnFiber.lastEffect = fiber)) + : (returnFiber.firstEffect = returnFiber.lastEffect = fiber); + } + hydrationParentFiber = fiber$jscomp$0; + nextHydratableInstance = shim$1(nextInstance); + } else + (fiber$jscomp$0.effectTag |= 2), + (isHydrating = !1), + (hydrationParentFiber = fiber$jscomp$0); + } +} +function reconcileChildren(current, workInProgress, nextChildren) { + reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + workInProgress.expirationTime + ); +} +function reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime +) { + workInProgress.child = + null === current + ? mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ) + : reconcileChildFibers( + workInProgress, + current.child, + nextChildren, + renderExpirationTime + ); +} +function markRef(current, workInProgress) { + var ref = workInProgress.ref; + if ( + (null === current && null !== ref) || + (null !== current && current.ref !== ref) + ) + workInProgress.effectTag |= 128; +} +function finishClassComponent( + current, + workInProgress, + shouldUpdate, + hasContext, + renderExpirationTime +) { + markRef(current, workInProgress); + var didCaptureError = 0 !== (workInProgress.effectTag & 64); + if (!shouldUpdate && !didCaptureError) + return ( + hasContext && invalidateContextProvider(workInProgress, !1), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + shouldUpdate = workInProgress.stateNode; + ReactCurrentOwner.current = workInProgress; + if (didCaptureError) { + var nextChildren = null; + baseStartTime = -1; + } else nextChildren = shouldUpdate.render(); + workInProgress.effectTag |= 1; + didCaptureError && + (reconcileChildrenAtExpirationTime( + current, + workInProgress, + null, + renderExpirationTime + ), + (workInProgress.child = null)); + reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime + ); + workInProgress.memoizedState = shouldUpdate.state; + workInProgress.memoizedProps = shouldUpdate.props; + hasContext && invalidateContextProvider(workInProgress, !0); + return workInProgress.child; +} +function pushHostRootContext(workInProgress) { + var root = workInProgress.stateNode; + root.pendingContext + ? pushTopLevelContextObject( + workInProgress, + root.pendingContext, + root.pendingContext !== root.context + ) + : root.context && + pushTopLevelContextObject(workInProgress, root.context, !1); + pushHostContainer(workInProgress, root.containerInfo); +} +function propagateContextChange( + workInProgress, + context, + changedBits, + renderExpirationTime +) { + var fiber = workInProgress.child; + null !== fiber && (fiber.return = workInProgress); + for (; null !== fiber; ) { + switch (fiber.tag) { + case 12: + var nextFiber = fiber.stateNode | 0; + if (fiber.type === context && 0 !== (nextFiber & changedBits)) { + for (nextFiber = fiber; null !== nextFiber; ) { + var alternate = nextFiber.alternate; + if ( + 0 === nextFiber.expirationTime || + nextFiber.expirationTime > renderExpirationTime + ) + (nextFiber.expirationTime = renderExpirationTime), + null !== alternate && + (0 === alternate.expirationTime || + alternate.expirationTime > renderExpirationTime) && + (alternate.expirationTime = renderExpirationTime); + else if ( + null !== alternate && + (0 === alternate.expirationTime || + alternate.expirationTime > renderExpirationTime) + ) + alternate.expirationTime = renderExpirationTime; + else break; + nextFiber = nextFiber.return; + } + nextFiber = null; + } else nextFiber = fiber.child; + break; + case 13: + nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + break; + default: + nextFiber = fiber.child; + } + if (null !== nextFiber) nextFiber.return = fiber; + else + for (nextFiber = fiber; null !== nextFiber; ) { + if (nextFiber === workInProgress) { + nextFiber = null; + break; + } + fiber = nextFiber.sibling; + if (null !== fiber) { + fiber.return = nextFiber.return; + nextFiber = fiber; + break; + } + nextFiber = nextFiber.return; + } + fiber = nextFiber; + } +} +function updateContextProvider(current, workInProgress, renderExpirationTime) { + var context = workInProgress.type._context, + newProps = workInProgress.pendingProps, + oldProps = workInProgress.memoizedProps, + canBailOnProps = !0; + if (didPerformWorkStackCursor.current) canBailOnProps = !1; + else if (oldProps === newProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + var newValue = newProps.value; + workInProgress.memoizedProps = newProps; + if (null === oldProps) newValue = 1073741823; + else if (oldProps.value === newProps.value) { + if (oldProps.children === newProps.children && canBailOnProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + newValue = 0; + } else { + var oldValue = oldProps.value; + if ( + (oldValue === newValue && + (0 !== oldValue || 1 / oldValue === 1 / newValue)) || + (oldValue !== oldValue && newValue !== newValue) + ) { + if (oldProps.children === newProps.children && canBailOnProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + newValue = 0; + } else if ( + ((newValue = + "function" === typeof context._calculateChangedBits + ? context._calculateChangedBits(oldValue, newValue) + : 1073741823), + (newValue |= 0), + 0 === newValue) + ) { + if (oldProps.children === newProps.children && canBailOnProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + } else + propagateContextChange( + workInProgress, + context, + newValue, + renderExpirationTime + ); + } + workInProgress.stateNode = newValue; + pushProvider(workInProgress); + reconcileChildren(current, workInProgress, newProps.children); + return workInProgress.child; +} +function bailoutOnAlreadyFinishedWork(current, workInProgress) { + baseStartTime = -1; + invariant( + null === current || workInProgress.child === current.child, + "Resuming work not yet implemented." + ); + if (null !== workInProgress.child) { + current = workInProgress.child; + var newChild = createWorkInProgress( + current, + current.pendingProps, + current.expirationTime + ); + workInProgress.child = newChild; + for (newChild.return = workInProgress; null !== current.sibling; ) + (current = current.sibling), + (newChild = newChild.sibling = createWorkInProgress( + current, + current.pendingProps, + current.expirationTime + )), + (newChild.return = workInProgress); + newChild.sibling = null; + } + return workInProgress.child; +} +function beginWork(current, workInProgress, renderExpirationTime) { + workInProgress.mode & 4 && + ((workInProgress.actualDuration = + now$1() - workInProgress.actualDuration - totalElapsedPauseTime), + (workInProgress.actualStartTime = now$1())); + if ( + 0 === workInProgress.expirationTime || + workInProgress.expirationTime > renderExpirationTime + ) { + baseStartTime = -1; + switch (workInProgress.tag) { + case 3: + pushHostRootContext(workInProgress); + break; + case 2: + pushContextProvider(workInProgress); + break; + case 4: + pushHostContainer( + workInProgress, + workInProgress.stateNode.containerInfo + ); + break; + case 13: + pushProvider(workInProgress); + } + return null; + } + switch (workInProgress.tag) { + case 0: + invariant( + null === current, + "An indeterminate component should never have mounted. This error is likely caused by a bug in React. Please file an issue." + ); + var fn = workInProgress.type, + props = workInProgress.pendingProps, + unmaskedContext = getUnmaskedContext(workInProgress); + unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + fn = fn(props, unmaskedContext); + workInProgress.effectTag |= 1; + "object" === typeof fn && + null !== fn && + "function" === typeof fn.render && + void 0 === fn.$$typeof + ? ((unmaskedContext = workInProgress.type), + (workInProgress.tag = 2), + (workInProgress.memoizedState = + null !== fn.state && void 0 !== fn.state ? fn.state : null), + (unmaskedContext = unmaskedContext.getDerivedStateFromProps), + "function" === typeof unmaskedContext && + applyDerivedStateFromProps(workInProgress, unmaskedContext, props), + (props = pushContextProvider(workInProgress)), + (fn.updater = classComponentUpdater), + (workInProgress.stateNode = fn), + (fn._reactInternalFiber = workInProgress), + mountClassInstance(workInProgress, renderExpirationTime), + (current = finishClassComponent( + current, + workInProgress, + !0, + props, + renderExpirationTime + ))) + : ((workInProgress.tag = 1), + reconcileChildren(current, workInProgress, fn), + (workInProgress.memoizedProps = props), + (current = workInProgress.child)); + return current; + case 1: + return ( + (props = workInProgress.type), + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime + ? ((fn = getUnmaskedContext(workInProgress)), + (fn = getMaskedContext(workInProgress, fn)), + (props = props(renderExpirationTime, fn)), + (workInProgress.effectTag |= 1), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 2: + props = pushContextProvider(workInProgress); + if (null === current) + if (null === workInProgress.stateNode) { + var props$jscomp$0 = workInProgress.pendingProps, + ctor = workInProgress.type; + fn = getUnmaskedContext(workInProgress); + var needsContext = + 2 === workInProgress.tag && + null != workInProgress.type.contextTypes; + unmaskedContext = needsContext + ? getMaskedContext(workInProgress, fn) + : emptyObject; + props$jscomp$0 = new ctor(props$jscomp$0, unmaskedContext); + workInProgress.memoizedState = + null !== props$jscomp$0.state && void 0 !== props$jscomp$0.state + ? props$jscomp$0.state + : null; + props$jscomp$0.updater = classComponentUpdater; + workInProgress.stateNode = props$jscomp$0; + props$jscomp$0._reactInternalFiber = workInProgress; + needsContext && + ((needsContext = workInProgress.stateNode), + (needsContext.__reactInternalMemoizedUnmaskedChildContext = fn), + (needsContext.__reactInternalMemoizedMaskedChildContext = unmaskedContext)); + mountClassInstance(workInProgress, renderExpirationTime); + fn = !0; + } else { + ctor = workInProgress.type; + fn = workInProgress.stateNode; + needsContext = workInProgress.memoizedProps; + unmaskedContext = workInProgress.pendingProps; + fn.props = needsContext; + var oldContext = fn.context; + props$jscomp$0 = getUnmaskedContext(workInProgress); + props$jscomp$0 = getMaskedContext(workInProgress, props$jscomp$0); + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + (ctor = + "function" === typeof getDerivedStateFromProps || + "function" === typeof fn.getSnapshotBeforeUpdate) || + ("function" !== typeof fn.UNSAFE_componentWillReceiveProps && + "function" !== typeof fn.componentWillReceiveProps) || + ((needsContext !== unmaskedContext || + oldContext !== props$jscomp$0) && + callComponentWillReceiveProps( + workInProgress, + fn, + unmaskedContext, + props$jscomp$0 + )); + hasForceUpdate = !1; + var oldState = workInProgress.memoizedState; + oldContext = fn.state = oldState; + var updateQueue = workInProgress.updateQueue; + null !== updateQueue && + (processUpdateQueue( + workInProgress, + updateQueue, + unmaskedContext, + fn, + renderExpirationTime + ), + (oldContext = workInProgress.memoizedState)); + needsContext !== unmaskedContext || + oldState !== oldContext || + didPerformWorkStackCursor.current || + hasForceUpdate + ? ("function" === typeof getDerivedStateFromProps && + (applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + unmaskedContext + ), + (oldContext = workInProgress.memoizedState)), + (needsContext = + hasForceUpdate || + checkShouldComponentUpdate( + workInProgress, + needsContext, + unmaskedContext, + oldState, + oldContext, + props$jscomp$0 + )) + ? (ctor || + ("function" !== typeof fn.UNSAFE_componentWillMount && + "function" !== typeof fn.componentWillMount) || + ("function" === typeof fn.componentWillMount && + fn.componentWillMount(), + "function" === typeof fn.UNSAFE_componentWillMount && + fn.UNSAFE_componentWillMount()), + "function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4)) + : ("function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4), + (workInProgress.memoizedProps = unmaskedContext), + (workInProgress.memoizedState = oldContext)), + (fn.props = unmaskedContext), + (fn.state = oldContext), + (fn.context = props$jscomp$0), + (fn = needsContext)) + : ("function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4), + (fn = !1)); + } + else + (ctor = workInProgress.type), + (fn = workInProgress.stateNode), + (unmaskedContext = workInProgress.memoizedProps), + (needsContext = workInProgress.pendingProps), + (fn.props = unmaskedContext), + (oldContext = fn.context), + (props$jscomp$0 = getUnmaskedContext(workInProgress)), + (props$jscomp$0 = getMaskedContext(workInProgress, props$jscomp$0)), + (getDerivedStateFromProps = ctor.getDerivedStateFromProps), + (ctor = + "function" === typeof getDerivedStateFromProps || + "function" === typeof fn.getSnapshotBeforeUpdate) || + ("function" !== typeof fn.UNSAFE_componentWillReceiveProps && + "function" !== typeof fn.componentWillReceiveProps) || + ((unmaskedContext !== needsContext || + oldContext !== props$jscomp$0) && + callComponentWillReceiveProps( + workInProgress, + fn, + needsContext, + props$jscomp$0 + )), + (hasForceUpdate = !1), + (oldContext = workInProgress.memoizedState), + (oldState = fn.state = oldContext), + (updateQueue = workInProgress.updateQueue), + null !== updateQueue && + (processUpdateQueue( + workInProgress, + updateQueue, + needsContext, + fn, + renderExpirationTime + ), + (oldState = workInProgress.memoizedState)), + unmaskedContext !== needsContext || + oldContext !== oldState || + didPerformWorkStackCursor.current || + hasForceUpdate + ? ("function" === typeof getDerivedStateFromProps && + (applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + needsContext + ), + (oldState = workInProgress.memoizedState)), + (getDerivedStateFromProps = + hasForceUpdate || + checkShouldComponentUpdate( + workInProgress, + unmaskedContext, + needsContext, + oldContext, + oldState, + props$jscomp$0 + )) + ? (ctor || + ("function" !== typeof fn.UNSAFE_componentWillUpdate && + "function" !== typeof fn.componentWillUpdate) || + ("function" === typeof fn.componentWillUpdate && + fn.componentWillUpdate( + needsContext, + oldState, + props$jscomp$0 + ), + "function" === typeof fn.UNSAFE_componentWillUpdate && + fn.UNSAFE_componentWillUpdate( + needsContext, + oldState, + props$jscomp$0 + )), + "function" === typeof fn.componentDidUpdate && + (workInProgress.effectTag |= 4), + "function" === typeof fn.getSnapshotBeforeUpdate && + (workInProgress.effectTag |= 256)) + : ("function" !== typeof fn.componentDidUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 4), + "function" !== typeof fn.getSnapshotBeforeUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 256), + (workInProgress.memoizedProps = needsContext), + (workInProgress.memoizedState = oldState)), + (fn.props = needsContext), + (fn.state = oldState), + (fn.context = props$jscomp$0), + (fn = getDerivedStateFromProps)) + : ("function" !== typeof fn.componentDidUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 4), + "function" !== typeof fn.getSnapshotBeforeUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 256), + (fn = !1)); + return finishClassComponent( + current, + workInProgress, + fn, + props, + renderExpirationTime + ); + case 3: + return ( + pushHostRootContext(workInProgress), + (props = workInProgress.updateQueue), + null !== props + ? ((fn = workInProgress.memoizedState), + (fn = null !== fn ? fn.element : null), + processUpdateQueue( + workInProgress, + props, + workInProgress.pendingProps, + null, + renderExpirationTime + ), + (renderExpirationTime = workInProgress.memoizedState.element), + renderExpirationTime === fn + ? (current = bailoutOnAlreadyFinishedWork( + current, + workInProgress + )) + : (reconcileChildren( + current, + workInProgress, + renderExpirationTime + ), + (current = workInProgress.child))) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 5: + return ( + requiredContext(rootInstanceStackCursor.current), + (renderExpirationTime = requiredContext(contextStackCursor$1.current)), + (props = workInProgress.type), + (props = + "AndroidTextInput" === props || + "RCTMultilineTextInputView" === props || + "RCTSinglelineTextInputView" === props || + "RCTText" === props || + "RCTVirtualText" === props), + (props = + renderExpirationTime.isInAParentText !== props + ? { isInAParentText: props } + : renderExpirationTime), + renderExpirationTime !== props && + (push(contextFiberStackCursor, workInProgress, workInProgress), + push(contextStackCursor$1, props, workInProgress)), + null === current && tryToClaimNextHydratableInstance(workInProgress), + (props = workInProgress.memoizedProps), + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || props !== renderExpirationTime + ? ((props = renderExpirationTime.children), + markRef(current, workInProgress), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 6: + return ( + null === current && tryToClaimNextHydratableInstance(workInProgress), + (workInProgress.memoizedProps = workInProgress.pendingProps), + null + ); + case 16: + return null; + case 4: + return ( + pushHostContainer( + workInProgress, + workInProgress.stateNode.containerInfo + ), + (props = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== props + ? (null === current + ? (workInProgress.child = reconcileChildFibers( + workInProgress, + null, + props, + renderExpirationTime + )) + : reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = props), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 14: + return ( + (props = workInProgress.type.render), + (renderExpirationTime = workInProgress.pendingProps), + (fn = workInProgress.ref), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime || + fn !== (null !== current ? current.ref : null) + ? ((props = props(renderExpirationTime, fn)), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 10: + return ( + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime + ? (reconcileChildren(current, workInProgress, renderExpirationTime), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 11: + return ( + (renderExpirationTime = workInProgress.pendingProps.children), + didPerformWorkStackCursor.current || + (null !== renderExpirationTime && + workInProgress.memoizedProps !== renderExpirationTime) + ? (reconcileChildren(current, workInProgress, renderExpirationTime), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 15: + return ( + (renderExpirationTime = workInProgress.pendingProps), + (workInProgress.effectTag |= 4), + workInProgress.memoizedProps === renderExpirationTime + ? (current = bailoutOnAlreadyFinishedWork(current, workInProgress)) + : (reconcileChildren( + current, + workInProgress, + renderExpirationTime.children + ), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)), + current + ); + case 13: + return updateContextProvider( + current, + workInProgress, + renderExpirationTime + ); + case 12: + a: if ( + ((fn = workInProgress.type), + (unmaskedContext = workInProgress.pendingProps), + (needsContext = workInProgress.memoizedProps), + (props = fn._currentValue2), + (props$jscomp$0 = fn._changedBits2), + didPerformWorkStackCursor.current || + 0 !== props$jscomp$0 || + needsContext !== unmaskedContext) + ) { + workInProgress.memoizedProps = unmaskedContext; + ctor = unmaskedContext.unstable_observedBits; + if (void 0 === ctor || null === ctor) ctor = 1073741823; + workInProgress.stateNode = ctor; + if (0 !== (props$jscomp$0 & ctor)) + propagateContextChange( + workInProgress, + fn, + props$jscomp$0, + renderExpirationTime + ); + else if (needsContext === unmaskedContext) { + current = bailoutOnAlreadyFinishedWork(current, workInProgress); + break a; + } + renderExpirationTime = unmaskedContext.children; + renderExpirationTime = renderExpirationTime(props); + workInProgress.effectTag |= 1; + reconcileChildren(current, workInProgress, renderExpirationTime); + current = workInProgress.child; + } else current = bailoutOnAlreadyFinishedWork(current, workInProgress); + return current; + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } +} +function appendAllChildren(parent, workInProgress) { + for (var node = workInProgress.child; null !== node; ) { + if (5 === node.tag || 6 === node.tag) + FabricUIManager.appendChild(parent.node, node.stateNode.node); + else if (4 !== node.tag && null !== node.child) { + node.child.return = node; + node = node.child; + continue; + } + if (node === workInProgress) break; + for (; null === node.sibling; ) { + if (null === node.return || node.return === workInProgress) return; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } +} +var updateHostContainer = void 0, + updateHostComponent$1 = void 0, + updateHostText$1 = void 0; +updateHostContainer = function(workInProgress) { + var portalOrRoot = workInProgress.stateNode; + if (null !== workInProgress.firstEffect) { + var container = portalOrRoot.containerInfo, + newChildSet = FabricUIManager.createChildSet(container); + a: for (var node = workInProgress.child; null !== node; ) { + if (5 === node.tag || 6 === node.tag) + FabricUIManager.appendChildToSet(newChildSet, node.stateNode.node); + else if (4 !== node.tag && null !== node.child) { + node.child.return = node; + node = node.child; + continue; + } + if (node === workInProgress) break a; + for (; null === node.sibling; ) { + if (null === node.return || node.return === workInProgress) break a; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + portalOrRoot.pendingChildren = newChildSet; + workInProgress.effectTag |= 4; + FabricUIManager.completeRoot(container, newChildSet); + } +}; +updateHostComponent$1 = function(current, workInProgress, updatePayload) { + var childrenUnchanged = null === workInProgress.firstEffect; + current = current.stateNode; + if (childrenUnchanged && null === updatePayload) + workInProgress.stateNode = current; + else { + var node = current.node; + updatePayload = { + node: childrenUnchanged + ? null !== updatePayload + ? FabricUIManager.cloneNodeWithNewProps( + node, + updatePayload, + workInProgress + ) + : FabricUIManager.cloneNode(node, workInProgress) + : null !== updatePayload + ? FabricUIManager.cloneNodeWithNewChildrenAndProps( + node, + updatePayload, + workInProgress + ) + : FabricUIManager.cloneNodeWithNewChildren(node, workInProgress), + canonical: current.canonical + }; + workInProgress.stateNode = updatePayload; + childrenUnchanged + ? (workInProgress.effectTag |= 4) + : appendAllChildren(updatePayload, workInProgress); + } +}; +updateHostText$1 = function(current, workInProgress, oldText, newText) { + oldText !== newText && + ((current = requiredContext(rootInstanceStackCursor.current)), + (oldText = requiredContext(contextStackCursor$1.current)), + (workInProgress.stateNode = createTextInstance( + newText, + current, + oldText, + workInProgress + )), + (workInProgress.effectTag |= 4)); +}; +function completeWork(current, workInProgress) { + var newProps = workInProgress.pendingProps; + workInProgress.mode & 4 && recordElapsedActualRenderTime(workInProgress); + switch (workInProgress.tag) { + case 1: + return null; + case 2: + return popContextProvider(workInProgress), null; + case 3: + popHostContainer(workInProgress); + popTopLevelContextObject(workInProgress); + newProps = workInProgress.stateNode; + newProps.pendingContext && + ((newProps.context = newProps.pendingContext), + (newProps.pendingContext = null)); + if (null === current || null === current.child) + workInProgress.effectTag &= -3; + updateHostContainer(workInProgress); + return null; + case 5: + popHostContext(workInProgress); + var rootContainerInstance = requiredContext( + rootInstanceStackCursor.current + ), + type = workInProgress.type; + if (null !== current && null != workInProgress.stateNode) { + var oldProps = current.memoizedProps, + instance = workInProgress.stateNode, + currentHostContext = requiredContext(contextStackCursor$1.current), + updatePayload = diffProperties( + null, + oldProps, + newProps, + instance.canonical.viewConfig.validAttributes + ); + instance.canonical.currentProps = newProps; + updateHostComponent$1( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ); + current.ref !== workInProgress.ref && (workInProgress.effectTag |= 128); + } else { + if (!newProps) + return ( + invariant( + null !== workInProgress.stateNode, + "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." + ), + null + ); + instance = requiredContext(contextStackCursor$1.current); + current = nextReactTag; + nextReactTag += 2; + oldProps = ReactNativeViewConfigRegistry.get(type); + invariant( + "RCTView" !== type || !instance.isInAParentText, + "Nesting of within is not currently supported." + ); + type = diffProperties( + null, + emptyObject$1, + newProps, + oldProps.validAttributes + ); + rootContainerInstance = FabricUIManager.createNode( + current, + oldProps.uiViewClassName, + rootContainerInstance, + type, + workInProgress + ); + newProps = new ReactFabricHostComponent(current, oldProps, newProps); + newProps = { node: rootContainerInstance, canonical: newProps }; + appendAllChildren(newProps, workInProgress); + workInProgress.stateNode = newProps; + null !== workInProgress.ref && (workInProgress.effectTag |= 128); + } + return null; + case 6: + if (current && null != workInProgress.stateNode) + updateHostText$1( + current, + workInProgress, + current.memoizedProps, + newProps + ); + else { + if ("string" !== typeof newProps) + return ( + invariant( + null !== workInProgress.stateNode, + "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." + ), + null + ); + rootContainerInstance = requiredContext( + rootInstanceStackCursor.current + ); + type = requiredContext(contextStackCursor$1.current); + workInProgress.stateNode = createTextInstance( + newProps, + rootContainerInstance, + type, + workInProgress + ); + } + return null; + case 14: + return null; + case 16: + return null; + case 10: + return null; + case 11: + return null; + case 15: + return null; + case 4: + return ( + popHostContainer(workInProgress), + updateHostContainer(workInProgress), + null + ); + case 13: + return popProvider(workInProgress), null; + case 12: + return null; + case 0: + invariant( + !1, + "An indeterminate component should have become determinate before completing. This error is likely caused by a bug in React. Please file an issue." + ); + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } +} +function logError(boundary, errorInfo) { + var source = errorInfo.source, + stack = errorInfo.stack; + null === stack && + null !== source && + (stack = getStackAddendumByWorkInProgressFiber(source)); + null !== source && getComponentName(source); + source = null !== stack ? stack : ""; + errorInfo = errorInfo.value; + null !== boundary && 2 === boundary.tag && getComponentName(boundary); + try { + if (errorInfo instanceof Error) { + var message = errorInfo.message, + name = errorInfo.name; + var errorToHandle = errorInfo; + try { + errorToHandle.message = + (message ? name + ": " + message : name) + + "\n\nThis error is located at:" + + source; + } catch (e) {} + } else + errorToHandle = + "string" === typeof errorInfo + ? Error(errorInfo + "\n\nThis error is located at:" + source) + : Error("Unspecified error at:" + source); + ExceptionsManager.handleException(errorToHandle, !1); + } catch (e) { + (e && e.suppressReactErrorLogging) || console.error(e); + } +} +function safelyDetachRef(current) { + var ref = current.ref; + if (null !== ref) + if ("function" === typeof ref) + try { + ref(null); + } catch (refError) { + captureCommitPhaseError(current, refError); + } + else ref.current = null; +} +function commitWork(current, finishedWork) { + switch (finishedWork.tag) { + case 2: + break; + case 5: + break; + case 6: + break; + case 3: + 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." + ); + } +} +function createRootErrorUpdate(fiber, errorInfo, expirationTime) { + expirationTime = createUpdate(expirationTime); + expirationTime.tag = 3; + expirationTime.payload = { element: null }; + var error = errorInfo.value; + expirationTime.callback = function() { + onUncaughtError(error); + logError(fiber, errorInfo); + }; + return expirationTime; +} +function createClassErrorUpdate(fiber, errorInfo, expirationTime) { + expirationTime = createUpdate(expirationTime); + expirationTime.tag = 3; + var inst = fiber.stateNode; + null !== inst && + "function" === typeof inst.componentDidCatch && + (expirationTime.callback = function() { + null === legacyErrorBoundariesThatAlreadyFailed + ? (legacyErrorBoundariesThatAlreadyFailed = new Set([this])) + : legacyErrorBoundariesThatAlreadyFailed.add(this); + var error = errorInfo.value, + stack = errorInfo.stack; + logError(fiber, errorInfo); + this.componentDidCatch(error, { + componentStack: null !== stack ? stack : "" + }); + }); + return expirationTime; +} +function unwindWork(workInProgress) { + workInProgress.mode & 4 && recordElapsedActualRenderTime(workInProgress); + switch (workInProgress.tag) { + case 2: + popContextProvider(workInProgress); + var effectTag = workInProgress.effectTag; + return effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null; + case 3: + return ( + popHostContainer(workInProgress), + popTopLevelContextObject(workInProgress), + (effectTag = workInProgress.effectTag), + effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null + ); + case 5: + return popHostContext(workInProgress), null; + case 16: + return ( + (effectTag = workInProgress.effectTag), + effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null + ); + case 4: + return popHostContainer(workInProgress), null; + case 13: + return popProvider(workInProgress), null; + default: + return null; + } +} +var originalStartTimeMs = now$1(), + mostRecentCurrentTime = 2, + mostRecentCurrentTimeMs = originalStartTimeMs, + lastUniqueAsyncExpiration = 0, + expirationContext = 0, + isWorking = !1, + nextUnitOfWork = null, + nextRoot = null, + nextRenderExpirationTime = 0, + nextLatestTimeoutMs = -1, + nextRenderDidError = !1, + nextEffect = null, + isCommitting$1 = !1, + legacyErrorBoundariesThatAlreadyFailed = null; +function resetStack() { + if (null !== nextUnitOfWork) + for ( + var interruptedWork = nextUnitOfWork.return; + null !== interruptedWork; + + ) { + var interruptedWork$jscomp$0 = interruptedWork; + interruptedWork$jscomp$0.mode & 4 && + (resumeActualRenderTimerIfPaused(), + recordElapsedActualRenderTime(interruptedWork$jscomp$0)); + switch (interruptedWork$jscomp$0.tag) { + case 2: + popContextProvider(interruptedWork$jscomp$0); + break; + case 3: + popHostContainer(interruptedWork$jscomp$0); + popTopLevelContextObject(interruptedWork$jscomp$0); + break; + case 5: + popHostContext(interruptedWork$jscomp$0); + break; + case 4: + popHostContainer(interruptedWork$jscomp$0); + break; + case 13: + popProvider(interruptedWork$jscomp$0); + } + interruptedWork = interruptedWork.return; + } + nextRoot = null; + nextRenderExpirationTime = 0; + nextLatestTimeoutMs = -1; + nextRenderDidError = !1; + nextUnitOfWork = null; +} +function completeUnitOfWork(workInProgress$jscomp$0) { + for (;;) { + var current = workInProgress$jscomp$0.alternate, + returnFiber = workInProgress$jscomp$0.return, + siblingFiber = workInProgress$jscomp$0.sibling; + if (0 === (workInProgress$jscomp$0.effectTag & 512)) { + current = completeWork( + current, + workInProgress$jscomp$0, + nextRenderExpirationTime + ); + var workInProgress = workInProgress$jscomp$0; + if ( + 1073741823 === nextRenderExpirationTime || + 1073741823 !== workInProgress.expirationTime + ) { + var newExpirationTime = 0; + switch (workInProgress.tag) { + case 3: + case 2: + var updateQueue = workInProgress.updateQueue; + null !== updateQueue && + (newExpirationTime = updateQueue.expirationTime); + } + if (workInProgress.mode & 4) { + updateQueue = workInProgress.selfBaseTime; + for (var child = workInProgress.child; null !== child; ) + (updateQueue += child.treeBaseTime), + 0 !== child.expirationTime && + (0 === newExpirationTime || + newExpirationTime > child.expirationTime) && + (newExpirationTime = child.expirationTime), + (child = child.sibling); + workInProgress.treeBaseTime = updateQueue; + } else + for (updateQueue = workInProgress.child; null !== updateQueue; ) + 0 !== updateQueue.expirationTime && + (0 === newExpirationTime || + newExpirationTime > updateQueue.expirationTime) && + (newExpirationTime = updateQueue.expirationTime), + (updateQueue = updateQueue.sibling); + workInProgress.expirationTime = newExpirationTime; + } + if (null !== current) return current; + null !== returnFiber && + 0 === (returnFiber.effectTag & 512) && + (null === returnFiber.firstEffect && + (returnFiber.firstEffect = workInProgress$jscomp$0.firstEffect), + null !== workInProgress$jscomp$0.lastEffect && + (null !== returnFiber.lastEffect && + (returnFiber.lastEffect.nextEffect = + workInProgress$jscomp$0.firstEffect), + (returnFiber.lastEffect = workInProgress$jscomp$0.lastEffect)), + 1 < workInProgress$jscomp$0.effectTag && + (null !== returnFiber.lastEffect + ? (returnFiber.lastEffect.nextEffect = workInProgress$jscomp$0) + : (returnFiber.firstEffect = workInProgress$jscomp$0), + (returnFiber.lastEffect = workInProgress$jscomp$0))); + } else { + workInProgress$jscomp$0 = unwindWork( + workInProgress$jscomp$0, + nextRenderExpirationTime + ); + if (null !== workInProgress$jscomp$0) + return ( + (workInProgress$jscomp$0.effectTag &= 511), workInProgress$jscomp$0 + ); + null !== returnFiber && + ((returnFiber.firstEffect = returnFiber.lastEffect = null), + (returnFiber.effectTag |= 512)); + } + if (null !== siblingFiber) return siblingFiber; + if (null !== returnFiber) workInProgress$jscomp$0 = returnFiber; + else break; + } + return null; +} +function performUnitOfWork(workInProgress) { + var current = workInProgress.alternate; + workInProgress.mode & 4 && (baseStartTime = now$1()); + current = beginWork(current, workInProgress, nextRenderExpirationTime); + workInProgress.mode & 4 && + (-1 !== baseStartTime && + (workInProgress.selfBaseTime = now$1() - baseStartTime), + (baseStartTime = -1)); + null === current && (current = completeUnitOfWork(workInProgress)); + ReactCurrentOwner.current = null; + return current; +} +function renderRoot(root$jscomp$0, isYieldy) { + invariant( + !isWorking, + "renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." + ); + isWorking = !0; + var expirationTime = root$jscomp$0.nextExpirationTimeToWorkOn; + if ( + expirationTime !== nextRenderExpirationTime || + root$jscomp$0 !== nextRoot || + null === nextUnitOfWork + ) + resetStack(), + (nextRoot = root$jscomp$0), + (nextRenderExpirationTime = expirationTime), + (nextLatestTimeoutMs = -1), + (nextRenderDidError = !1), + (nextUnitOfWork = createWorkInProgress( + nextRoot.current, + null, + nextRenderExpirationTime + )), + (root$jscomp$0.pendingCommitExpirationTime = 0); + var didFatal = !1; + do { + try { + if (isYieldy) { + for (; null !== nextUnitOfWork && !shouldYield(); ) + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + 0 === timerPausedAt && (timerPausedAt = now$1()); + } else + for (; null !== nextUnitOfWork; ) + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + } catch (thrownValue) { + if (((baseStartTime = -1), null === nextUnitOfWork)) + (didFatal = !0), onUncaughtError(thrownValue); + else { + invariant( + null !== nextUnitOfWork, + "Failed to replay rendering after an error. This is likely caused by a bug in React. Please file an issue with a reproducing case to help us find it." + ); + isYieldy = nextUnitOfWork; + var returnFiber = isYieldy.return; + if (null === returnFiber) { + didFatal = !0; + onUncaughtError(thrownValue); + break; + } + a: { + var root = root$jscomp$0, + returnFiber$jscomp$0 = returnFiber, + sourceFiber = isYieldy, + value = thrownValue; + returnFiber = nextRenderExpirationTime; + sourceFiber.effectTag |= 512; + sourceFiber.firstEffect = sourceFiber.lastEffect = null; + nextRenderDidError = !0; + if ( + (root.didError || 1 === returnFiber) && + (returnFiber === root.latestPendingTime || + returnFiber === root.latestSuspendedTime) + ) { + value = createCapturedValue(value, sourceFiber); + root = returnFiber$jscomp$0; + do { + switch (root.tag) { + case 3: + root.effectTag |= 1024; + value = createRootErrorUpdate(root, value, returnFiber); + enqueueCapturedUpdate(root, value, returnFiber); + break a; + case 2: + if ( + ((returnFiber$jscomp$0 = value), + (sourceFiber = root.stateNode), + 0 === (root.effectTag & 64) && + null !== sourceFiber && + "function" === typeof sourceFiber.componentDidCatch && + (null === legacyErrorBoundariesThatAlreadyFailed || + !legacyErrorBoundariesThatAlreadyFailed.has( + sourceFiber + ))) + ) { + root.effectTag |= 1024; + value = createClassErrorUpdate( + root, + returnFiber$jscomp$0, + returnFiber + ); + enqueueCapturedUpdate(root, value, returnFiber); + break a; + } + } + root = root.return; + } while (null !== root); + } + } + nextUnitOfWork = completeUnitOfWork(isYieldy); + } + } + break; + } while (1); + isWorking = !1; + didFatal + ? (root$jscomp$0.finishedWork = null) + : null === nextUnitOfWork + ? ((didFatal = root$jscomp$0.current.alternate), + invariant( + null !== didFatal, + "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue." + ), + 0 === (didFatal.effectTag & 512) + ? ((root$jscomp$0.pendingCommitExpirationTime = expirationTime), + (root$jscomp$0.finishedWork = didFatal)) + : (!nextRenderDidError || + (expirationTime !== root$jscomp$0.latestPendingTime && + expirationTime !== root$jscomp$0.latestSuspendedTime) + ? ((didFatal = root$jscomp$0.earliestPendingTime), + (isYieldy = root$jscomp$0.latestPendingTime), + didFatal === expirationTime + ? (root$jscomp$0.earliestPendingTime = + isYieldy === expirationTime + ? (root$jscomp$0.latestPendingTime = 0) + : isYieldy) + : isYieldy === expirationTime && + (root$jscomp$0.latestPendingTime = didFatal), + (didFatal = root$jscomp$0.latestSuspendedTime), + didFatal === expirationTime && + (root$jscomp$0.latestPingedTime = 0), + (isYieldy = root$jscomp$0.earliestSuspendedTime), + 0 === isYieldy + ? (root$jscomp$0.earliestSuspendedTime = root$jscomp$0.latestSuspendedTime = expirationTime) + : isYieldy > expirationTime + ? (root$jscomp$0.earliestSuspendedTime = expirationTime) + : didFatal < expirationTime && + (root$jscomp$0.latestSuspendedTime = expirationTime)) + : (root$jscomp$0.didError = !0), + findNextPendingPriorityLevel(root$jscomp$0), + onSuspend( + root$jscomp$0, + expirationTime, + root$jscomp$0.expirationTime, + nextLatestTimeoutMs + ))) + : (root$jscomp$0.finishedWork = null); +} +function captureCommitPhaseError(fiber, error) { + var JSCompiler_inline_result; + a: { + invariant( + !isWorking || isCommitting$1, + "dispatch: Cannot dispatch during the render phase." + ); + for ( + JSCompiler_inline_result = fiber.return; + null !== JSCompiler_inline_result; + + ) { + switch (JSCompiler_inline_result.tag) { + case 2: + var instance = JSCompiler_inline_result.stateNode; + if ( + "function" === + typeof JSCompiler_inline_result.type.getDerivedStateFromCatch || + ("function" === typeof instance.componentDidCatch && + (null === legacyErrorBoundariesThatAlreadyFailed || + !legacyErrorBoundariesThatAlreadyFailed.has(instance))) + ) { + fiber = createCapturedValue(error, fiber); + fiber = createClassErrorUpdate(JSCompiler_inline_result, fiber, 1); + enqueueUpdate(JSCompiler_inline_result, fiber, 1); + scheduleWork(JSCompiler_inline_result, 1); + JSCompiler_inline_result = void 0; + break a; + } + break; + case 3: + fiber = createCapturedValue(error, fiber); + fiber = createRootErrorUpdate(JSCompiler_inline_result, fiber, 1); + enqueueUpdate(JSCompiler_inline_result, fiber, 1); + scheduleWork(JSCompiler_inline_result, 1); + JSCompiler_inline_result = void 0; + break a; + } + JSCompiler_inline_result = JSCompiler_inline_result.return; + } + 3 === fiber.tag && + ((JSCompiler_inline_result = createCapturedValue(error, fiber)), + (JSCompiler_inline_result = createRootErrorUpdate( + fiber, + JSCompiler_inline_result, + 1 + )), + enqueueUpdate(fiber, JSCompiler_inline_result, 1), + scheduleWork(fiber, 1)); + JSCompiler_inline_result = void 0; + } + return JSCompiler_inline_result; +} +function computeExpirationForFiber(currentTime, fiber) { + currentTime = + 0 !== expirationContext + ? expirationContext + : isWorking + ? isCommitting$1 ? 1 : nextRenderExpirationTime + : fiber.mode & 1 + ? isBatchingInteractiveUpdates + ? 2 + 10 * ((((currentTime - 2 + 15) / 10) | 0) + 1) + : 2 + 25 * ((((currentTime - 2 + 500) / 25) | 0) + 1) + : 1; + isBatchingInteractiveUpdates && + (0 === lowestPendingInteractiveExpirationTime || + currentTime > lowestPendingInteractiveExpirationTime) && + (lowestPendingInteractiveExpirationTime = currentTime); + return currentTime; +} +function scheduleWork(fiber, expirationTime) { + for (; null !== fiber; ) { + if (0 === fiber.expirationTime || fiber.expirationTime > expirationTime) + fiber.expirationTime = expirationTime; + null !== fiber.alternate && + (0 === fiber.alternate.expirationTime || + fiber.alternate.expirationTime > expirationTime) && + (fiber.alternate.expirationTime = expirationTime); + if (null === fiber.return) + if (3 === fiber.tag) { + var root = fiber.stateNode; + !isWorking && + 0 !== nextRenderExpirationTime && + expirationTime < nextRenderExpirationTime && + resetStack(); + markPendingPriorityLevel(root, expirationTime); + (isWorking && !isCommitting$1 && nextRoot === root) || + requestWork(root, root.expirationTime); + nestedUpdateCount > NESTED_UPDATE_LIMIT && + invariant( + !1, + "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops." + ); + } else break; + fiber = fiber.return; + } +} +function recalculateCurrentTime() { + mostRecentCurrentTimeMs = now$1() - originalStartTimeMs; + return (mostRecentCurrentTime = ((mostRecentCurrentTimeMs / 10) | 0) + 2); +} +function syncUpdates(fn, a, b, c, d) { + var previousExpirationContext = expirationContext; + expirationContext = 1; + try { + return fn(a, b, c, d); + } finally { + expirationContext = previousExpirationContext; + } +} +var firstScheduledRoot = null, + lastScheduledRoot = null, + callbackExpirationTime = 0, + callbackID = void 0, + isRendering = !1, + nextFlushedRoot = null, + nextFlushedExpirationTime = 0, + lowestPendingInteractiveExpirationTime = 0, + deadlineDidExpire = !1, + hasUnhandledError = !1, + unhandledError = null, + deadline = null, + isBatchingUpdates = !1, + isUnbatchingUpdates = !1, + isBatchingInteractiveUpdates = !1, + completedBatches = null, + NESTED_UPDATE_LIMIT = 1e3, + nestedUpdateCount = 0, + timeHeuristicForUnitOfWork = 1; +function scheduleCallbackWithExpirationTime(expirationTime) { + if (0 !== callbackExpirationTime) { + if (expirationTime > callbackExpirationTime) return; + if (null !== callbackID) { + var callbackID$jscomp$0 = callbackID; + scheduledCallback = null; + clearTimeout(callbackID$jscomp$0); + } + } + callbackExpirationTime = expirationTime; + now$1(); + scheduledCallback = performAsyncWork; + callbackID = setTimeout(setTimeoutCallback, 1); +} +function onSuspend(root, suspendedExpirationTime, expirationTime, timeoutMs) { + 0 <= timeoutMs && + setTimeout(function() { + var latestSuspendedTime = root.latestSuspendedTime; + 0 !== latestSuspendedTime && + latestSuspendedTime <= suspendedExpirationTime && + ((latestSuspendedTime = root.latestPingedTime), + 0 === latestSuspendedTime || + latestSuspendedTime < suspendedExpirationTime) && + (root.latestPingedTime = suspendedExpirationTime); + findNextPendingPriorityLevel(root); + latestSuspendedTime = root.expirationTime; + 0 !== latestSuspendedTime && requestWork(root, latestSuspendedTime); + }, timeoutMs); + root.expirationTime = expirationTime; +} +function requestWork(root, expirationTime) { + if (null === root.nextScheduledRoot) + (root.expirationTime = expirationTime), + null === lastScheduledRoot + ? ((firstScheduledRoot = lastScheduledRoot = root), + (root.nextScheduledRoot = root)) + : ((lastScheduledRoot = lastScheduledRoot.nextScheduledRoot = root), + (lastScheduledRoot.nextScheduledRoot = firstScheduledRoot)); + else { + var remainingExpirationTime = root.expirationTime; + if ( + 0 === remainingExpirationTime || + expirationTime < remainingExpirationTime + ) + root.expirationTime = expirationTime; + } + isRendering || + (isBatchingUpdates + ? isUnbatchingUpdates && + ((nextFlushedRoot = root), + (nextFlushedExpirationTime = 1), + performWorkOnRoot(root, 1, !1)) + : 1 === expirationTime + ? performWork(1, null) + : scheduleCallbackWithExpirationTime(expirationTime)); +} +function findHighestPriorityRoot() { + var highestPriorityWork = 0, + highestPriorityRoot = null; + if (null !== lastScheduledRoot) + for ( + var previousScheduledRoot = lastScheduledRoot, root = firstScheduledRoot; + null !== root; + + ) { + var remainingExpirationTime = root.expirationTime; + if (0 === remainingExpirationTime) { + invariant( + null !== previousScheduledRoot && null !== lastScheduledRoot, + "Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue." + ); + if (root === root.nextScheduledRoot) { + firstScheduledRoot = lastScheduledRoot = root.nextScheduledRoot = null; + break; + } else if (root === firstScheduledRoot) + (firstScheduledRoot = remainingExpirationTime = + root.nextScheduledRoot), + (lastScheduledRoot.nextScheduledRoot = remainingExpirationTime), + (root.nextScheduledRoot = null); + else if (root === lastScheduledRoot) { + lastScheduledRoot = previousScheduledRoot; + lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; + root.nextScheduledRoot = null; + break; + } else + (previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot), + (root.nextScheduledRoot = null); + root = previousScheduledRoot.nextScheduledRoot; + } else { + if ( + 0 === highestPriorityWork || + remainingExpirationTime < highestPriorityWork + ) + (highestPriorityWork = remainingExpirationTime), + (highestPriorityRoot = root); + if (root === lastScheduledRoot) break; + previousScheduledRoot = root; + root = root.nextScheduledRoot; + } + } + previousScheduledRoot = nextFlushedRoot; + null !== previousScheduledRoot && + previousScheduledRoot === highestPriorityRoot && + 1 === highestPriorityWork + ? nestedUpdateCount++ + : (nestedUpdateCount = 0); + nextFlushedRoot = highestPriorityRoot; + nextFlushedExpirationTime = highestPriorityWork; +} +function performAsyncWork(dl) { + performWork(0, dl); +} +function performWork(minExpirationTime, dl) { + deadline = dl; + findHighestPriorityRoot(); + resumeActualRenderTimerIfPaused(); + if (null !== deadline) + for ( + ; + null !== nextFlushedRoot && + 0 !== nextFlushedExpirationTime && + (0 === minExpirationTime || + minExpirationTime >= nextFlushedExpirationTime) && + (!deadlineDidExpire || + recalculateCurrentTime() >= nextFlushedExpirationTime); + + ) + recalculateCurrentTime(), + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !0), + findHighestPriorityRoot(); + else + for ( + ; + null !== nextFlushedRoot && + 0 !== nextFlushedExpirationTime && + (0 === minExpirationTime || + minExpirationTime >= nextFlushedExpirationTime); + + ) + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !1), + findHighestPriorityRoot(); + null !== deadline && ((callbackExpirationTime = 0), (callbackID = null)); + 0 !== nextFlushedExpirationTime && + scheduleCallbackWithExpirationTime(nextFlushedExpirationTime); + deadline = null; + deadlineDidExpire = !1; + finishRendering(); +} +function finishRendering() { + nestedUpdateCount = 0; + if (null !== completedBatches) { + var batches = completedBatches; + completedBatches = null; + for (var i = 0; i < batches.length; i++) { + var batch = batches[i]; + try { + batch._onComplete(); + } catch (error) { + hasUnhandledError || + ((hasUnhandledError = !0), (unhandledError = error)); + } + } + } + if (hasUnhandledError) + throw ((batches = unhandledError), + (unhandledError = null), + (hasUnhandledError = !1), + batches); +} +function performWorkOnRoot(root, expirationTime, isYieldy) { + invariant( + !isRendering, + "performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." + ); + isRendering = !0; + isYieldy + ? ((isYieldy = root.finishedWork), + null !== isYieldy + ? completeRoot$1(root, isYieldy, expirationTime) + : ((root.finishedWork = null), + renderRoot(root, !0), + (isYieldy = root.finishedWork), + null !== isYieldy && + (shouldYield() + ? ((root.finishedWork = isYieldy), + 0 === timerPausedAt && (timerPausedAt = now$1())) + : completeRoot$1(root, isYieldy, expirationTime)))) + : ((isYieldy = root.finishedWork), + null !== isYieldy + ? completeRoot$1(root, isYieldy, expirationTime) + : ((root.finishedWork = null), + renderRoot(root, !1), + (isYieldy = root.finishedWork), + null !== isYieldy && completeRoot$1(root, isYieldy, expirationTime))); + isRendering = !1; +} +function completeRoot$1(root, finishedWork$jscomp$0, expirationTime) { + var firstBatch = root.firstBatch; + if ( + null !== firstBatch && + firstBatch._expirationTime <= expirationTime && + (null === completedBatches + ? (completedBatches = [firstBatch]) + : completedBatches.push(firstBatch), + firstBatch._defer) + ) { + root.finishedWork = finishedWork$jscomp$0; + root.expirationTime = 0; + return; + } + root.finishedWork = null; + isCommitting$1 = isWorking = !0; + invariant( + root.current !== finishedWork$jscomp$0, + "Cannot commit the same tree as before. This is probably a bug related to the return field. This error is likely caused by a bug in React. Please file an issue." + ); + expirationTime = root.pendingCommitExpirationTime; + invariant( + 0 !== expirationTime, + "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." + ); + root.pendingCommitExpirationTime = 0; + firstBatch = finishedWork$jscomp$0.expirationTime; + recalculateCurrentTime(); + root.didError = !1; + if (0 === firstBatch) + (root.earliestPendingTime = 0), + (root.latestPendingTime = 0), + (root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0); + else { + var latestPendingTime = root.latestPendingTime; + 0 !== latestPendingTime && + (latestPendingTime < firstBatch + ? (root.earliestPendingTime = root.latestPendingTime = 0) + : root.earliestPendingTime < firstBatch && + (root.earliestPendingTime = root.latestPendingTime)); + latestPendingTime = root.earliestSuspendedTime; + 0 === latestPendingTime + ? markPendingPriorityLevel(root, firstBatch) + : firstBatch > root.latestSuspendedTime + ? ((root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0), + markPendingPriorityLevel(root, firstBatch)) + : firstBatch < latestPendingTime && + markPendingPriorityLevel(root, firstBatch); + } + findNextPendingPriorityLevel(root); + ReactCurrentOwner.current = null; + 1 < finishedWork$jscomp$0.effectTag + ? null !== finishedWork$jscomp$0.lastEffect + ? ((finishedWork$jscomp$0.lastEffect.nextEffect = finishedWork$jscomp$0), + (firstBatch = finishedWork$jscomp$0.firstEffect)) + : (firstBatch = finishedWork$jscomp$0) + : (firstBatch = finishedWork$jscomp$0.firstEffect); + for (nextEffect = firstBatch; null !== nextEffect; ) { + latestPendingTime = !1; + var error = void 0; + try { + for (; null !== nextEffect; ) { + if (nextEffect.effectTag & 256) { + var current = nextEffect.alternate, + finishedWork = nextEffect; + switch (finishedWork.tag) { + case 2: + if (finishedWork.effectTag & 256 && null !== current) { + var prevProps = current.memoizedProps, + prevState = current.memoizedState, + instance = finishedWork.stateNode; + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + var snapshot = instance.getSnapshotBeforeUpdate( + prevProps, + prevState + ); + instance.__reactInternalSnapshotBeforeUpdate = snapshot; + } + 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." + ); + } + } + nextEffect = nextEffect.nextEffect; + } + } catch (e) { + (latestPendingTime = !0), (error = e); + } + latestPendingTime && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, error), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + now$1(); + for (nextEffect = firstBatch; null !== nextEffect; ) { + current = !1; + prevProps = void 0; + try { + for (; null !== nextEffect; ) { + var effectTag = nextEffect.effectTag; + if (effectTag & 128) { + var current$jscomp$0 = nextEffect.alternate; + if (null !== current$jscomp$0) { + var currentRef = current$jscomp$0.ref; + null !== currentRef && + ("function" === typeof currentRef + ? currentRef(null) + : (currentRef.current = null)); + } + } + switch (effectTag & 14) { + case 2: + nextEffect.effectTag &= -3; + break; + case 6: + nextEffect.effectTag &= -3; + commitWork(nextEffect.alternate, nextEffect); + break; + case 4: + commitWork(nextEffect.alternate, nextEffect); + break; + case 8: + prevState = nextEffect; + a: for (snapshot = instance = prevState; ; ) { + latestPendingTime = snapshot; + "function" === typeof onCommitUnmount && + onCommitUnmount(latestPendingTime); + switch (latestPendingTime.tag) { + case 2: + safelyDetachRef(latestPendingTime); + var instance$jscomp$0 = latestPendingTime.stateNode; + if ( + "function" === typeof instance$jscomp$0.componentWillUnmount + ) + try { + (instance$jscomp$0.props = + latestPendingTime.memoizedProps), + (instance$jscomp$0.state = + latestPendingTime.memoizedState), + instance$jscomp$0.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(latestPendingTime, unmountError); + } + break; + case 5: + safelyDetachRef(latestPendingTime); + break; + case 4: + FabricUIManager.createChildSet( + latestPendingTime.stateNode.containerInfo + ); + } + if (null !== snapshot.child) + (snapshot.child.return = snapshot), (snapshot = snapshot.child); + else { + if (snapshot === instance) break; + for (; null === snapshot.sibling; ) { + if (null === snapshot.return || snapshot.return === instance) + break a; + snapshot = snapshot.return; + } + snapshot.sibling.return = snapshot.return; + snapshot = snapshot.sibling; + } + } + prevState.return = null; + prevState.child = null; + prevState.alternate && + ((prevState.alternate.child = null), + (prevState.alternate.return = null)); + } + nextEffect = nextEffect.nextEffect; + } + } catch (e) { + (current = !0), (prevProps = e); + } + current && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, prevProps), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + root.current = finishedWork$jscomp$0; + for (nextEffect = firstBatch; null !== nextEffect; ) { + effectTag = !1; + current$jscomp$0 = void 0; + try { + for (currentRef = expirationTime; null !== nextEffect; ) { + var effectTag$jscomp$0 = nextEffect.effectTag; + if (effectTag$jscomp$0 & 36) { + var current$jscomp$1 = nextEffect.alternate; + instance$jscomp$0 = nextEffect; + firstBatch = currentRef; + switch (instance$jscomp$0.tag) { + case 2: + var instance$jscomp$1 = instance$jscomp$0.stateNode; + if (instance$jscomp$0.effectTag & 4) + if (null === current$jscomp$1) + (instance$jscomp$1.props = instance$jscomp$0.memoizedProps), + (instance$jscomp$1.state = instance$jscomp$0.memoizedState), + instance$jscomp$1.componentDidMount(); + else { + var prevProps$jscomp$0 = current$jscomp$1.memoizedProps, + prevState$jscomp$0 = current$jscomp$1.memoizedState; + instance$jscomp$1.props = instance$jscomp$0.memoizedProps; + instance$jscomp$1.state = instance$jscomp$0.memoizedState; + instance$jscomp$1.componentDidUpdate( + prevProps$jscomp$0, + prevState$jscomp$0, + instance$jscomp$1.__reactInternalSnapshotBeforeUpdate + ); + } + var updateQueue = instance$jscomp$0.updateQueue; + null !== updateQueue && + ((instance$jscomp$1.props = instance$jscomp$0.memoizedProps), + (instance$jscomp$1.state = instance$jscomp$0.memoizedState), + commitUpdateQueue( + instance$jscomp$0, + updateQueue, + instance$jscomp$1, + firstBatch + )); + break; + case 3: + var _updateQueue = instance$jscomp$0.updateQueue; + if (null !== _updateQueue) { + current = null; + if (null !== instance$jscomp$0.child) + switch (instance$jscomp$0.child.tag) { + case 5: + current = instance$jscomp$0.child.stateNode.canonical; + break; + case 2: + current = instance$jscomp$0.child.stateNode; + } + commitUpdateQueue( + instance$jscomp$0, + _updateQueue, + current, + firstBatch + ); + } + break; + case 5: + null === current$jscomp$1 && + instance$jscomp$0.effectTag & 4 && + invariant( + !1, + "The current renderer does not support mutation. This error is likely caused by a bug in React. Please file an issue." + ); + break; + case 6: + break; + case 4: + break; + case 15: + break; + case 16: + 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." + ); + } + } + if (effectTag$jscomp$0 & 128) { + instance$jscomp$0 = void 0; + var ref = nextEffect.ref; + if (null !== ref) { + var instance$jscomp$2 = nextEffect.stateNode; + switch (nextEffect.tag) { + case 5: + instance$jscomp$0 = instance$jscomp$2.canonical; + break; + default: + instance$jscomp$0 = instance$jscomp$2; + } + "function" === typeof ref + ? ref(instance$jscomp$0) + : (ref.current = instance$jscomp$0); + } + } + var next = nextEffect.nextEffect; + nextEffect.nextEffect = null; + nextEffect = next; + } + } catch (e) { + (effectTag = !0), (current$jscomp$0 = e); + } + effectTag && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, current$jscomp$0), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + totalElapsedPauseTime = 0; + isWorking = isCommitting$1 = !1; + "function" === typeof onCommitRoot && + onCommitRoot(finishedWork$jscomp$0.stateNode); + finishedWork$jscomp$0 = root.expirationTime; + 0 === finishedWork$jscomp$0 && + (legacyErrorBoundariesThatAlreadyFailed = null); + root.expirationTime = finishedWork$jscomp$0; + root.finishedWork = null; +} +function shouldYield() { + return null === deadline || + deadlineDidExpire || + deadline.timeRemaining() > timeHeuristicForUnitOfWork + ? !1 + : (deadlineDidExpire = !0); +} +function onUncaughtError(error) { + invariant( + null !== nextFlushedRoot, + "Should be working on a root. This error is likely caused by a bug in React. Please file an issue." + ); + nextFlushedRoot.expirationTime = 0; + hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error)); +} +function updateContainerAtExpirationTime( + element, + container, + parentComponent, + expirationTime, + callback +) { + var current = container.current; + if (parentComponent) { + parentComponent = parentComponent._reactInternalFiber; + var parentContext; + b: { + invariant( + 2 === isFiberMountedImpl(parentComponent) && 2 === parentComponent.tag, + "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." + ); + for (parentContext = parentComponent; 3 !== parentContext.tag; ) { + if (isContextProvider(parentContext)) { + parentContext = + parentContext.stateNode.__reactInternalMemoizedMergedChildContext; + break b; + } + parentContext = parentContext.return; + invariant( + parentContext, + "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." + ); + } + parentContext = parentContext.stateNode.context; + } + parentComponent = isContextProvider(parentComponent) + ? processChildContext(parentComponent, parentContext) + : parentContext; + } else parentComponent = emptyObject; + null === container.context + ? (container.context = parentComponent) + : (container.pendingContext = parentComponent); + container = callback; + callback = createUpdate(expirationTime); + callback.payload = { element: element }; + container = void 0 === container ? null : container; + null !== container && (callback.callback = container); + enqueueUpdate(current, callback, expirationTime); + scheduleWork(current, expirationTime); + return expirationTime; +} +function findHostInstance$1(component) { + var fiber = component._reactInternalFiber; + void 0 === fiber && + ("function" === typeof component.render + ? invariant(!1, "Unable to find node on an unmounted component.") + : invariant( + !1, + "Argument appears to not be a ReactComponent. Keys: %s", + Object.keys(component) + )); + component = findCurrentHostFiber(fiber); + return null === component ? null : component.stateNode; +} +function updateContainer(element, container, parentComponent, callback) { + var current = container.current, + currentTime = recalculateCurrentTime(); + current = computeExpirationForFiber(currentTime, current); + return updateContainerAtExpirationTime( + element, + container, + parentComponent, + current, + callback + ); +} +function getPublicRootInstance(container) { + container = container.current; + if (!container.child) return null; + switch (container.child.tag) { + case 5: + return container.child.stateNode.canonical; + default: + return container.child.stateNode; + } +} +function injectIntoDevTools(devToolsConfig) { + var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; + return injectInternals( + Object.assign({}, devToolsConfig, { + findHostInstanceByFiber: function(fiber) { + fiber = findCurrentHostFiber(fiber); + return null === fiber ? null : fiber.stateNode; + }, + findFiberByHostInstance: function(instance) { + return findFiberByHostInstance + ? findFiberByHostInstance(instance) + : null; + } + }) + ); +} +var ReactFabricRenderer = { + updateContainerAtExpirationTime: updateContainerAtExpirationTime, + createContainer: function(containerInfo, isAsync, hydrate) { + return createFiberRoot(containerInfo, isAsync, hydrate); + }, + updateContainer: updateContainer, + flushRoot: function(root, expirationTime) { + invariant( + !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); + performWork(1, null); + finishRendering(); + }, + requestWork: requestWork, + computeUniqueAsyncExpiration: function() { + var result = + 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); + result <= lastUniqueAsyncExpiration && + (result = lastUniqueAsyncExpiration + 1); + return (lastUniqueAsyncExpiration = result); + }, + batchedUpdates: function(fn, a) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + return fn(a); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + unbatchedUpdates: function(fn, a) { + if (isBatchingUpdates && !isUnbatchingUpdates) { + isUnbatchingUpdates = !0; + try { + return fn(a); + } finally { + isUnbatchingUpdates = !1; + } + } + return fn(a); + }, + deferredUpdates: function(fn) { + var previousExpirationContext = expirationContext; + expirationContext = + 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); + try { + return fn(); + } finally { + expirationContext = previousExpirationContext; + } + }, + syncUpdates: syncUpdates, + interactiveUpdates: function(fn, a, b) { + if (isBatchingInteractiveUpdates) return fn(a, b); + isBatchingUpdates || + isRendering || + 0 === lowestPendingInteractiveExpirationTime || + (performWork(lowestPendingInteractiveExpirationTime, null), + (lowestPendingInteractiveExpirationTime = 0)); + var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates, + previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = isBatchingInteractiveUpdates = !0; + try { + return fn(a, b); + } finally { + (isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates), + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + flushInteractiveUpdates: function() { + isRendering || + 0 === lowestPendingInteractiveExpirationTime || + (performWork(lowestPendingInteractiveExpirationTime, null), + (lowestPendingInteractiveExpirationTime = 0)); + }, + flushControlled: function(fn) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + syncUpdates(fn); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + flushSync: function(fn, a) { + invariant( + !isRendering, + "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." + ); + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + return syncUpdates(fn, a); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates), performWork(1, null); + } + }, + getPublicRootInstance: getPublicRootInstance, + findHostInstance: findHostInstance$1, + findHostInstanceWithNoPortals: function(fiber) { + fiber = findCurrentHostFiberWithNoPortals(fiber); + return null === fiber ? null : fiber.stateNode; + }, + injectIntoDevTools: injectIntoDevTools +}; +function createPortal(children, containerInfo, implementation) { + var key = + 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null; + return { + $$typeof: REACT_PORTAL_TYPE, + key: null == key ? null : "" + key, + children: children, + containerInfo: containerInfo, + implementation: implementation + }; +} +function _inherits(subClass, superClass) { + if ("function" !== typeof superClass && null !== superClass) + throw new TypeError( + "Super expression must either be null or a function, not " + + typeof superClass + ); + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: !1, + writable: !0, + configurable: !0 + } + }); + superClass && + (Object.setPrototypeOf + ? Object.setPrototypeOf(subClass, superClass) + : (subClass.__proto__ = superClass)); +} +var getInspectorDataForViewTag = void 0; +getInspectorDataForViewTag = function() { + invariant(!1, "getInspectorDataForViewTag() is not available in production"); +}; +function findNodeHandle(componentOrHandle) { + if (null == componentOrHandle) return null; + if ("number" === typeof componentOrHandle) return componentOrHandle; + if (componentOrHandle._nativeTag) return componentOrHandle._nativeTag; + if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) + return componentOrHandle.canonical._nativeTag; + componentOrHandle = findHostInstance$1(componentOrHandle); + return null == componentOrHandle + ? componentOrHandle + : componentOrHandle.canonical + ? componentOrHandle.canonical._nativeTag + : componentOrHandle._nativeTag; +} +_batchedUpdates = ReactFabricRenderer.batchedUpdates; +_flushInteractiveUpdates = ReactFabricRenderer.flushInteractiveUpdates; +var roots = new Map(), + ReactFabric = { + NativeComponent: (function(findNodeHandle, findHostInstance) { + return (function(_React$Component) { + function ReactNativeComponent() { + if (!(this instanceof ReactNativeComponent)) + throw new TypeError("Cannot call a class as a function"); + var call = _React$Component.apply(this, arguments); + if (!this) + throw new ReferenceError( + "this hasn't been initialised - super() hasn't been called" + ); + return !call || + ("object" !== typeof call && "function" !== typeof call) + ? this + : call; + } + _inherits(ReactNativeComponent, _React$Component); + ReactNativeComponent.prototype.blur = function() { + TextInputState.blurTextInput(findNodeHandle(this)); + }; + ReactNativeComponent.prototype.focus = function() { + TextInputState.focusTextInput(findNodeHandle(this)); + }; + ReactNativeComponent.prototype.measure = function(callback) { + UIManager.measure( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }; + ReactNativeComponent.prototype.measureInWindow = function(callback) { + UIManager.measureInWindow( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }; + ReactNativeComponent.prototype.measureLayout = function( + relativeToNativeNode, + onSuccess, + onFail + ) { + UIManager.measureLayout( + findNodeHandle(this), + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }; + ReactNativeComponent.prototype.setNativeProps = function(nativeProps) { + var maybeInstance = void 0; + try { + maybeInstance = findHostInstance(this); + } catch (error) {} + if (null != maybeInstance) { + var viewConfig = + maybeInstance.viewConfig || maybeInstance.canonical.viewConfig; + nativeProps = diffProperties( + null, + emptyObject$1, + nativeProps, + viewConfig.validAttributes + ); + null != nativeProps && + UIManager.updateView( + maybeInstance._nativeTag, + viewConfig.uiViewClassName, + nativeProps + ); + } + }; + return ReactNativeComponent; + })(React.Component); + })(findNodeHandle, findHostInstance$1), + findNodeHandle: findNodeHandle, + render: function(element, containerTag, callback) { + var root = roots.get(containerTag); + root || + ((root = createFiberRoot(containerTag, !1, !1)), + roots.set(containerTag, root)); + updateContainer(element, root, null, callback); + return getPublicRootInstance(root); + }, + unmountComponentAtNode: function(containerTag) { + var root = roots.get(containerTag); + root && + updateContainer(null, root, null, function() { + roots.delete(containerTag); + }); + }, + createPortal: function(children, containerTag) { + return createPortal( + children, + containerTag, + null, + 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : null + ); + }, + __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: { + NativeMethodsMixin: (function(findNodeHandle, findHostInstance) { + return { + measure: function(callback) { + UIManager.measure( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }, + measureInWindow: function(callback) { + UIManager.measureInWindow( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }, + measureLayout: function(relativeToNativeNode, onSuccess, onFail) { + UIManager.measureLayout( + findNodeHandle(this), + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }, + setNativeProps: function(nativeProps) { + var maybeInstance = void 0; + try { + maybeInstance = findHostInstance(this); + } catch (error) {} + if (null != maybeInstance) { + var viewConfig = maybeInstance.viewConfig; + nativeProps = diffProperties( + null, + emptyObject$1, + nativeProps, + viewConfig.validAttributes + ); + null != nativeProps && + UIManager.updateView( + maybeInstance._nativeTag, + viewConfig.uiViewClassName, + nativeProps + ); + } + }, + focus: function() { + TextInputState.focusTextInput(findNodeHandle(this)); + }, + blur: function() { + TextInputState.blurTextInput(findNodeHandle(this)); + } + }; + })(findNodeHandle, findHostInstance$1) + } + }; +injectIntoDevTools({ + findFiberByHostInstance: getInstanceFromInstance, + getInspectorDataForViewTag: getInspectorDataForViewTag, + bundleType: 0, + version: "16.4.1", + rendererPackageName: "react-native-renderer" +}); +var ReactFabric$2 = { default: ReactFabric }, + ReactFabric$3 = (ReactFabric$2 && ReactFabric) || ReactFabric$2; +module.exports = ReactFabric$3.default ? ReactFabric$3.default : ReactFabric$3; diff --git a/Libraries/Renderer/oss/ReactNativeRenderer-dev.js b/Libraries/Renderer/oss/ReactNativeRenderer-dev.js index f1a8809d897bd2..c18f1f137a6a00 100644 --- a/Libraries/Renderer/oss/ReactNativeRenderer-dev.js +++ b/Libraries/Renderer/oss/ReactNativeRenderer-dev.js @@ -19,19 +19,17 @@ if (__DEV__) { require("InitializeCore"); var invariant = require("fbjs/lib/invariant"); var warning = require("fbjs/lib/warning"); -var emptyFunction = require("fbjs/lib/emptyFunction"); var ReactNativeViewConfigRegistry = require("ReactNativeViewConfigRegistry"); var UIManager = require("UIManager"); var RCTEventEmitter = require("RCTEventEmitter"); 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 deepFreezeAndThrowOnMutationInDev = require("deepFreezeAndThrowOnMutationInDev"); var deepDiffer = require("deepDiffer"); var flattenStyle = require("flattenStyle"); var TextInputState = require("TextInputState"); +var checkPropTypes = require("prop-types/checkPropTypes"); +var ExceptionsManager = require("ExceptionsManager"); var invokeGuardedCallback = function(name, func, context, a, b, c, d, e, f) { this._hasCaughtError = false; @@ -1183,7 +1181,9 @@ var EventInterface = { type: null, target: null, // currentTarget is set when dispatching; no use in copying it here - currentTarget: emptyFunction.thatReturnsNull, + currentTarget: function() { + return null; + }, eventPhase: null, bubbles: null, cancelable: null, @@ -1194,6 +1194,14 @@ var EventInterface = { isTrusted: null }; +function functionThatReturnsTrue() { + return true; +} + +function functionThatReturnsFalse() { + return false; +} + /** * Synthetic events are dispatched by event plugins, typically in response to a * top-level event delegation handler. @@ -1254,11 +1262,11 @@ function SyntheticEvent( ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false; if (defaultPrevented) { - this.isDefaultPrevented = emptyFunction.thatReturnsTrue; + this.isDefaultPrevented = functionThatReturnsTrue; } else { - this.isDefaultPrevented = emptyFunction.thatReturnsFalse; + this.isDefaultPrevented = functionThatReturnsFalse; } - this.isPropagationStopped = emptyFunction.thatReturnsFalse; + this.isPropagationStopped = functionThatReturnsFalse; return this; } @@ -1275,7 +1283,7 @@ Object.assign(SyntheticEvent.prototype, { } else if (typeof event.returnValue !== "unknown") { event.returnValue = false; } - this.isDefaultPrevented = emptyFunction.thatReturnsTrue; + this.isDefaultPrevented = functionThatReturnsTrue; }, stopPropagation: function() { @@ -1295,7 +1303,7 @@ Object.assign(SyntheticEvent.prototype, { event.cancelBubble = true; } - this.isPropagationStopped = emptyFunction.thatReturnsTrue; + this.isPropagationStopped = functionThatReturnsTrue; }, /** @@ -1304,7 +1312,7 @@ Object.assign(SyntheticEvent.prototype, { * won't be added back into the pool. */ persist: function() { - this.isPersistent = emptyFunction.thatReturnsTrue; + this.isPersistent = functionThatReturnsTrue; }, /** @@ -1312,7 +1320,7 @@ Object.assign(SyntheticEvent.prototype, { * * @return {boolean} True if this should not be released, false otherwise. */ - isPersistent: emptyFunction.thatReturnsFalse, + isPersistent: functionThatReturnsFalse, /** * `PooledClass` looks for `destructor` on each instance it releases. @@ -1340,12 +1348,12 @@ Object.assign(SyntheticEvent.prototype, { Object.defineProperty( this, "preventDefault", - getPooledWarningPropertyDefinition("preventDefault", emptyFunction) + getPooledWarningPropertyDefinition("preventDefault", function() {}) ); Object.defineProperty( this, "stopPropagation", - getPooledWarningPropertyDefinition("stopPropagation", emptyFunction) + getPooledWarningPropertyDefinition("stopPropagation", function() {}) ); } } @@ -2371,6 +2379,32 @@ var ReactNativeBridgeEventPlugin = { } }; +var ReactNativeEventPluginOrder = [ + "ResponderEventPlugin", + "ReactNativeBridgeEventPlugin" +]; + +/** + * Make sure essential globals are available and are patched correctly. Please don't remove this + * line. Bundles created by react-packager `require` it before executing any application code. This + * ensures it exists in the dependency graph and can be `require`d. + * TODO: require this in packager, not in React #10932517 + */ +// Module provided by RN: +/** + * Inject module for resolving DOM hierarchy and plugin ordering. + */ +injection.injectEventPluginOrder(ReactNativeEventPluginOrder); + +/** + * Some important event plugins included by default (without having to require + * them). + */ +injection.injectEventPluginsByName({ + ResponderEventPlugin: ResponderEventPlugin, + ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin +}); + var instanceCache = {}; var instanceProps = {}; @@ -2384,12 +2418,7 @@ function uncacheFiberNode(tag) { } function getInstanceFromTag(tag) { - if (typeof tag === "number") { - return instanceCache[tag] || null; - } else { - // Fabric will invoke event emitters on a direct fiber reference - return tag; - } + return instanceCache[tag] || null; } function getTagFromInstance(inst) { @@ -2419,49 +2448,6 @@ var ReactNativeComponentTree = Object.freeze({ updateFiberProps: updateFiberProps }); -var ReactNativeEventPluginOrder = [ - "ResponderEventPlugin", - "ReactNativeBridgeEventPlugin" -]; - -// Module provided by RN: -var ReactNativeGlobalResponderHandler = { - onChange: function(from, to, blockNativeResponder) { - if (to !== null) { - var tag = to.stateNode._nativeTag; - UIManager.setJSResponder(tag, blockNativeResponder); - } else { - UIManager.clearJSResponder(); - } - } -}; - -/** - * Make sure essential globals are available and are patched correctly. Please don't remove this - * line. Bundles created by react-packager `require` it before executing any application code. This - * ensures it exists in the dependency graph and can be `require`d. - * TODO: require this in packager, not in React #10932517 - */ -// Module provided by RN: -/** - * Inject module for resolving DOM hierarchy and plugin ordering. - */ -injection.injectEventPluginOrder(ReactNativeEventPluginOrder); -injection$1.injectComponentTree(ReactNativeComponentTree); - -ResponderEventPlugin.injection.injectGlobalResponderHandler( - ReactNativeGlobalResponderHandler -); - -/** - * Some important event plugins included by default (without having to require - * them). - */ -injection.injectEventPluginsByName({ - ResponderEventPlugin: ResponderEventPlugin, - ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin -}); - // Use to restore controlled state after a change event has fired. var fiberHostComponent = null; @@ -2718,12 +2704,30 @@ var ReactNativeEventEmitter = Object.freeze({ receiveTouches: receiveTouches }); +// Module provided by RN: +var ReactNativeGlobalResponderHandler = { + onChange: function(from, to, blockNativeResponder) { + if (to !== null) { + var tag = to.stateNode._nativeTag; + UIManager.setJSResponder(tag, blockNativeResponder); + } else { + UIManager.clearJSResponder(); + } + } +}; + // Module provided by RN: /** * Register the event emitter with the native bridge */ RCTEventEmitter.register(ReactNativeEventEmitter); +injection$1.injectComponentTree(ReactNativeComponentTree); + +ResponderEventPlugin.injection.injectGlobalResponderHandler( + ReactNativeGlobalResponderHandler +); + /** * `ReactInstanceMap` maintains a mapping from a public facing stateful * instance (key) and the internal representation (value). This allows public @@ -2812,6 +2816,8 @@ function getComponentName(fiber) { return "Context.Provider"; case REACT_STRICT_MODE_TYPE: return "StrictMode"; + case REACT_TIMEOUT_TYPE: + return "Timeout"; } if (typeof type === "object" && type !== null) { switch (type.$$typeof) { @@ -3110,1057 +3116,1101 @@ function findCurrentHostFiberWithNoPortals(parent) { return null; } -var debugRenderPhaseSideEffects = false; -var debugRenderPhaseSideEffectsForStrictMode = false; -var enableGetDerivedStateFromCatch = false; -var enableSuspense = false; -var enableMutatingReconciler = true; -var enableNoopReconciler = false; -var enablePersistentReconciler = false; -var enableUserTimingAPI = true; -var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; -var warnAboutDeprecatedLifecycles = false; -var enableProfilerTimer = true; -var fireGetDerivedStateFromPropsOnStateUpdates = true; - -// Only used in www builds. - -// Max 31 bit integer. The max integer size in V8 for 32-bit systems. -// Math.pow(2, 30) - 1 -// 0b111111111111111111111111111111 -var MAX_SIGNED_31_BIT_INT = 1073741823; - -// TODO: Use an opaque type once ESLint et al support the syntax - -var NoWork = 0; -var Sync = 1; -var Never = MAX_SIGNED_31_BIT_INT; - -var UNIT_SIZE = 10; -var MAGIC_NUMBER_OFFSET = 2; +// Modules provided by RN: +var emptyObject$1 = {}; -// 1 unit of expiration time represents 10ms. -function msToExpirationTime(ms) { - // Always add an offset so that we don't clash with the magic number for NoWork. - return ((ms / UNIT_SIZE) | 0) + MAGIC_NUMBER_OFFSET; -} +/** + * Create a payload that contains all the updates between two sets of props. + * + * These helpers are all encapsulated into a single module, because they use + * mutation as a performance optimization which leads to subtle shared + * dependencies between the code paths. To avoid this mutable state leaking + * across modules, I've kept them isolated to this module. + */ -function expirationTimeToMs(expirationTime) { - return (expirationTime - MAGIC_NUMBER_OFFSET) * UNIT_SIZE; -} +// Tracks removed keys +var removedKeys = null; +var removedKeyCount = 0; -function ceiling(num, precision) { - return (((num / precision) | 0) + 1) * precision; +function defaultDiffer(prevProp, nextProp) { + if (typeof nextProp !== "object" || nextProp === null) { + // Scalars have already been checked for equality + return true; + } else { + // For objects and arrays, the default diffing algorithm is a deep compare + return deepDiffer(prevProp, nextProp); + } } -function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) { - return ( - MAGIC_NUMBER_OFFSET + - ceiling( - currentTime - MAGIC_NUMBER_OFFSET + expirationInMs / UNIT_SIZE, - bucketSizeMs / UNIT_SIZE - ) - ); -} +function restoreDeletedValuesInNestedArray( + updatePayload, + node, + validAttributes +) { + if (Array.isArray(node)) { + var i = node.length; + while (i-- && removedKeyCount > 0) { + restoreDeletedValuesInNestedArray( + updatePayload, + node[i], + validAttributes + ); + } + } else if (node && removedKeyCount > 0) { + var obj = node; + for (var propKey in removedKeys) { + if (!removedKeys[propKey]) { + continue; + } + var _nextProp = obj[propKey]; + if (_nextProp === undefined) { + continue; + } -var NoContext = 0; -var AsyncMode = 1; -var StrictMode = 2; -var ProfileMode = 4; + var attributeConfig = validAttributes[propKey]; + if (!attributeConfig) { + continue; // not a valid native prop + } -var hasBadMapPolyfill = void 0; + if (typeof _nextProp === "function") { + _nextProp = true; + } + if (typeof _nextProp === "undefined") { + _nextProp = null; + } -{ - hasBadMapPolyfill = false; - try { - var nonExtensibleObject = Object.preventExtensions({}); - var testMap = new Map([[nonExtensibleObject, null]]); - var testSet = new Set([nonExtensibleObject]); - // This is necessary for Rollup to not consider these unused. - // https://github.com/rollup/rollup/issues/1771 - // TODO: we can remove these if Rollup fixes the bug. - testMap.set(0, 0); - testSet.add(0); - } catch (e) { - // TODO: Consider warning about bad polyfills - hasBadMapPolyfill = true; + if (typeof attributeConfig !== "object") { + // case: !Object is the default case + updatePayload[propKey] = _nextProp; + } else if ( + typeof attributeConfig.diff === "function" || + typeof attributeConfig.process === "function" + ) { + // case: CustomAttributeConfiguration + var nextValue = + typeof attributeConfig.process === "function" + ? attributeConfig.process(_nextProp) + : _nextProp; + updatePayload[propKey] = nextValue; + } + removedKeys[propKey] = false; + removedKeyCount--; + } } } -// A Fiber is work on a Component that needs to be done or was done. There can -// be more than one per component. - -var debugCounter = void 0; - -{ - debugCounter = 1; -} - -function FiberNode(tag, pendingProps, key, mode) { - // Instance - this.tag = tag; - this.key = key; - this.type = null; - this.stateNode = null; - - // Fiber - this.return = null; - this.child = null; - this.sibling = null; - this.index = 0; - - this.ref = null; - - this.pendingProps = pendingProps; - this.memoizedProps = null; - this.updateQueue = null; - this.memoizedState = null; - - this.mode = mode; - - // Effects - this.effectTag = NoEffect; - this.nextEffect = null; - - this.firstEffect = null; - this.lastEffect = null; - - this.expirationTime = NoWork; - - this.alternate = null; +function diffNestedArrayProperty( + updatePayload, + prevArray, + nextArray, + validAttributes +) { + var minLength = + prevArray.length < nextArray.length ? prevArray.length : nextArray.length; + var i = void 0; + for (i = 0; i < minLength; i++) { + // Diff any items in the array in the forward direction. Repeated keys + // will be overwritten by later values. + updatePayload = diffNestedProperty( + updatePayload, + prevArray[i], + nextArray[i], + validAttributes + ); + } + for (; i < prevArray.length; i++) { + // Clear out all remaining properties. + updatePayload = clearNestedProperty( + updatePayload, + prevArray[i], + validAttributes + ); + } + for (; i < nextArray.length; i++) { + // Add all remaining properties. + updatePayload = addNestedProperty( + updatePayload, + nextArray[i], + validAttributes + ); + } + return updatePayload; +} - if (enableProfilerTimer) { - this.selfBaseTime = 0; - this.treeBaseTime = 0; +function diffNestedProperty( + updatePayload, + prevProp, + nextProp, + validAttributes +) { + if (!updatePayload && prevProp === nextProp) { + // If no properties have been added, then we can bail out quickly on object + // equality. + return updatePayload; } - { - this._debugID = debugCounter++; - this._debugSource = null; - this._debugOwner = null; - this._debugIsCurrentlyTiming = false; - if (!hasBadMapPolyfill && typeof Object.preventExtensions === "function") { - Object.preventExtensions(this); + if (!prevProp || !nextProp) { + if (nextProp) { + return addNestedProperty(updatePayload, nextProp, validAttributes); + } + if (prevProp) { + return clearNestedProperty(updatePayload, prevProp, validAttributes); } + return updatePayload; } -} - -// This is a constructor function, rather than a POJO constructor, still -// please ensure we do the following: -// 1) Nobody should add any instance methods on this. Instance methods can be -// more difficult to predict when they get optimized and they are almost -// never inlined properly in static compilers. -// 2) Nobody should rely on `instanceof Fiber` for type testing. We should -// always know when it is a fiber. -// 3) We might want to experiment with using numeric keys since they are easier -// to optimize in a non-JIT environment. -// 4) We can easily go from a constructor to a createFiber object literal if that -// is faster. -// 5) It should be easy to port this to a C struct and keep a C implementation -// compatible. -var createFiber = function(tag, pendingProps, key, mode) { - // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors - return new FiberNode(tag, pendingProps, key, mode); -}; -function shouldConstruct(Component) { - return !!(Component.prototype && Component.prototype.isReactComponent); -} + if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) { + // Both are leaves, we can diff the leaves. + return diffProperties(updatePayload, prevProp, nextProp, validAttributes); + } -// This is used to create an alternate fiber to do work on. -function createWorkInProgress(current, pendingProps, expirationTime) { - var workInProgress = current.alternate; - if (workInProgress === null) { - // We use a double buffering pooling technique because we know that we'll - // only ever need at most two versions of a tree. We pool the "other" unused - // node that we're free to reuse. This is lazily created to avoid allocating - // extra objects for things that are never updated. It also allow us to - // reclaim the extra memory if needed. - workInProgress = createFiber( - current.tag, - pendingProps, - current.key, - current.mode + if (Array.isArray(prevProp) && Array.isArray(nextProp)) { + // Both are arrays, we can diff the arrays. + return diffNestedArrayProperty( + updatePayload, + prevProp, + nextProp, + validAttributes ); - workInProgress.type = current.type; - workInProgress.stateNode = current.stateNode; + } - { - // DEV-only fields - workInProgress._debugID = current._debugID; - workInProgress._debugSource = current._debugSource; - workInProgress._debugOwner = current._debugOwner; - } + if (Array.isArray(prevProp)) { + return diffProperties( + updatePayload, + // $FlowFixMe - We know that this is always an object when the input is. + flattenStyle(prevProp), + // $FlowFixMe - We know that this isn't an array because of above flow. + nextProp, + validAttributes + ); + } - workInProgress.alternate = current; - current.alternate = workInProgress; - } else { - workInProgress.pendingProps = pendingProps; + return diffProperties( + updatePayload, + prevProp, + // $FlowFixMe - We know that this is always an object when the input is. + flattenStyle(nextProp), + validAttributes + ); +} - // We already have an alternate. - // Reset the effect tag. - workInProgress.effectTag = NoEffect; +/** + * addNestedProperty takes a single set of props and valid attribute + * attribute configurations. It processes each prop and adds it to the + * updatePayload. + */ +function addNestedProperty(updatePayload, nextProp, validAttributes) { + if (!nextProp) { + return updatePayload; + } - // The effect list is no longer valid. - workInProgress.nextEffect = null; - workInProgress.firstEffect = null; - workInProgress.lastEffect = null; + if (!Array.isArray(nextProp)) { + // Add each property of the leaf. + return addProperties(updatePayload, nextProp, validAttributes); } - workInProgress.expirationTime = expirationTime; + for (var i = 0; i < nextProp.length; i++) { + // Add all the properties of the array. + updatePayload = addNestedProperty( + updatePayload, + nextProp[i], + validAttributes + ); + } - workInProgress.child = current.child; - workInProgress.memoizedProps = current.memoizedProps; - workInProgress.memoizedState = current.memoizedState; - workInProgress.updateQueue = current.updateQueue; + return updatePayload; +} - // These will be overridden during the parent's reconciliation - workInProgress.sibling = current.sibling; - workInProgress.index = current.index; - workInProgress.ref = current.ref; +/** + * clearNestedProperty takes a single set of props and valid attributes. It + * adds a null sentinel to the updatePayload, for each prop key. + */ +function clearNestedProperty(updatePayload, prevProp, validAttributes) { + if (!prevProp) { + return updatePayload; + } - if (enableProfilerTimer) { - workInProgress.selfBaseTime = current.selfBaseTime; - workInProgress.treeBaseTime = current.treeBaseTime; + if (!Array.isArray(prevProp)) { + // Add each property of the leaf. + return clearProperties(updatePayload, prevProp, validAttributes); } - return workInProgress; + for (var i = 0; i < prevProp.length; i++) { + // Add all the properties of the array. + updatePayload = clearNestedProperty( + updatePayload, + prevProp[i], + validAttributes + ); + } + return updatePayload; } -function createHostRootFiber(isAsync) { - var mode = isAsync ? AsyncMode | StrictMode : NoContext; - return createFiber(HostRoot, null, null, mode); -} +/** + * diffProperties takes two sets of props and a set of valid attributes + * and write to updatePayload the values that changed or were deleted. + * If no updatePayload is provided, a new one is created and returned if + * anything changed. + */ +function diffProperties(updatePayload, prevProps, nextProps, validAttributes) { + var attributeConfig = void 0; + var nextProp = void 0; + var prevProp = void 0; -function createFiberFromElement(element, mode, expirationTime) { - var owner = null; - { - owner = element._owner; - } + for (var propKey in nextProps) { + attributeConfig = validAttributes[propKey]; + if (!attributeConfig) { + continue; // not a valid native prop + } - var fiber = void 0; - var type = element.type; - var key = element.key; - var pendingProps = element.props; + prevProp = prevProps[propKey]; + nextProp = nextProps[propKey]; - var fiberTag = void 0; - if (typeof type === "function") { - fiberTag = shouldConstruct(type) ? ClassComponent : IndeterminateComponent; - } else if (typeof type === "string") { - fiberTag = HostComponent; - } else { - switch (type) { - case REACT_FRAGMENT_TYPE: - return createFiberFromFragment( - pendingProps.children, - mode, - expirationTime, - key - ); - case REACT_ASYNC_MODE_TYPE: - fiberTag = Mode; - mode |= AsyncMode | StrictMode; - break; - case REACT_STRICT_MODE_TYPE: - fiberTag = Mode; - mode |= StrictMode; - break; - case REACT_PROFILER_TYPE: - return createFiberFromProfiler(pendingProps, mode, expirationTime, key); - case REACT_TIMEOUT_TYPE: - fiberTag = TimeoutComponent; - // Suspense does not require async, but its children should be strict - // mode compatible. - mode |= StrictMode; - break; - default: - fiberTag = getFiberTagFromObjectType(type, owner); - break; + // functions are converted to booleans as markers that the associated + // events should be sent from native. + if (typeof nextProp === "function") { + nextProp = true; + // If nextProp is not a function, then don't bother changing prevProp + // since nextProp will win and go into the updatePayload regardless. + if (typeof prevProp === "function") { + prevProp = true; + } } - } - fiber = createFiber(fiberTag, pendingProps, key, mode); - fiber.type = type; - fiber.expirationTime = expirationTime; + // An explicit value of undefined is treated as a null because it overrides + // any other preceding value. + if (typeof nextProp === "undefined") { + nextProp = null; + if (typeof prevProp === "undefined") { + prevProp = null; + } + } - { - fiber._debugSource = element._source; - fiber._debugOwner = element._owner; - } + if (removedKeys) { + removedKeys[propKey] = false; + } - return fiber; -} + if (updatePayload && updatePayload[propKey] !== undefined) { + // Something else already triggered an update to this key because another + // value diffed. Since we're now later in the nested arrays our value is + // more important so we need to calculate it and override the existing + // value. It doesn't matter if nothing changed, we'll set it anyway. -function getFiberTagFromObjectType(type, owner) { - var $$typeof = - typeof type === "object" && type !== null ? type.$$typeof : null; + // Pattern match on: attributeConfig + if (typeof attributeConfig !== "object") { + // case: !Object is the default case + updatePayload[propKey] = nextProp; + } else if ( + typeof attributeConfig.diff === "function" || + typeof attributeConfig.process === "function" + ) { + // case: CustomAttributeConfiguration + var nextValue = + typeof attributeConfig.process === "function" + ? attributeConfig.process(nextProp) + : nextProp; + updatePayload[propKey] = nextValue; + } + continue; + } - switch ($$typeof) { - case REACT_PROVIDER_TYPE: - return ContextProvider; - case REACT_CONTEXT_TYPE: - // This is a consumer - return ContextConsumer; - case REACT_FORWARD_REF_TYPE: - return ForwardRef; - default: { - var info = ""; - { - if ( - type === undefined || - (typeof type === "object" && - type !== null && - Object.keys(type).length === 0) - ) { - info += - " You likely forgot to export your component from the file " + - "it's defined in, or you might have mixed up default and " + - "named imports."; - } - var ownerName = owner ? getComponentName(owner) : null; - if (ownerName) { - info += "\n\nCheck the render method of `" + ownerName + "`."; - } + if (prevProp === nextProp) { + continue; // nothing changed + } + + // Pattern match on: attributeConfig + if (typeof attributeConfig !== "object") { + // case: !Object is the default case + if (defaultDiffer(prevProp, nextProp)) { + // a normal leaf has changed + (updatePayload || (updatePayload = {}))[propKey] = nextProp; } - invariant( - false, - "Element type is invalid: expected a string (for built-in " + - "components) or a class/function (for composite components) " + - "but got: %s.%s", - type == null ? type : typeof type, - info + } else if ( + typeof attributeConfig.diff === "function" || + typeof attributeConfig.process === "function" + ) { + // case: CustomAttributeConfiguration + var shouldUpdate = + prevProp === undefined || + (typeof attributeConfig.diff === "function" + ? attributeConfig.diff(prevProp, nextProp) + : defaultDiffer(prevProp, nextProp)); + if (shouldUpdate) { + var _nextValue = + typeof attributeConfig.process === "function" + ? attributeConfig.process(nextProp) + : nextProp; + (updatePayload || (updatePayload = {}))[propKey] = _nextValue; + } + } else { + // default: fallthrough case when nested properties are defined + removedKeys = null; + removedKeyCount = 0; + // We think that attributeConfig is not CustomAttributeConfiguration at + // this point so we assume it must be AttributeConfiguration. + updatePayload = diffNestedProperty( + updatePayload, + prevProp, + nextProp, + attributeConfig ); + if (removedKeyCount > 0 && updatePayload) { + restoreDeletedValuesInNestedArray( + updatePayload, + nextProp, + attributeConfig + ); + removedKeys = null; + } } } -} -function createFiberFromFragment(elements, mode, expirationTime, key) { - var fiber = createFiber(Fragment, elements, key, mode); - fiber.expirationTime = expirationTime; - return fiber; -} + // Also iterate through all the previous props to catch any that have been + // removed and make sure native gets the signal so it can reset them to the + // default. + for (var _propKey in prevProps) { + if (nextProps[_propKey] !== undefined) { + continue; // we've already covered this key in the previous pass + } + attributeConfig = validAttributes[_propKey]; + if (!attributeConfig) { + continue; // not a valid native prop + } -function createFiberFromProfiler(pendingProps, mode, expirationTime, key) { - { + if (updatePayload && updatePayload[_propKey] !== undefined) { + // This was already updated to a diff result earlier. + continue; + } + + prevProp = prevProps[_propKey]; + if (prevProp === undefined) { + continue; // was already empty anyway + } + // Pattern match on: attributeConfig if ( - typeof pendingProps.id !== "string" || - typeof pendingProps.onRender !== "function" + typeof attributeConfig !== "object" || + typeof attributeConfig.diff === "function" || + typeof attributeConfig.process === "function" ) { - invariant( - false, - 'Profiler must specify an "id" string and "onRender" function as props' + // case: CustomAttributeConfiguration | !Object + // Flag the leaf property for removal by sending a sentinel. + (updatePayload || (updatePayload = {}))[_propKey] = null; + if (!removedKeys) { + removedKeys = {}; + } + if (!removedKeys[_propKey]) { + removedKeys[_propKey] = true; + removedKeyCount++; + } + } else { + // default: + // This is a nested attribute configuration where all the properties + // were removed so we need to go through and clear out all of them. + updatePayload = clearNestedProperty( + updatePayload, + prevProp, + attributeConfig ); } } - - var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); - fiber.type = REACT_PROFILER_TYPE; - fiber.expirationTime = expirationTime; - fiber.stateNode = { - duration: 0, - startTime: 0 - }; - - return fiber; + return updatePayload; } -function createFiberFromText(content, mode, expirationTime) { - var fiber = createFiber(HostText, content, null, mode); - fiber.expirationTime = expirationTime; - return fiber; +/** + * addProperties adds all the valid props to the payload after being processed. + */ +function addProperties(updatePayload, props, validAttributes) { + // TODO: Fast path + return diffProperties(updatePayload, emptyObject$1, props, validAttributes); } -function createFiberFromHostInstanceForDeletion() { - var fiber = createFiber(HostComponent, null, null, NoContext); - fiber.type = "DELETED"; - return fiber; +/** + * clearProperties clears all the previous props by adding a null sentinel + * to the payload for each valid key. + */ +function clearProperties(updatePayload, prevProps, validAttributes) { + // TODO: Fast path + return diffProperties( + updatePayload, + prevProps, + emptyObject$1, + validAttributes + ); } -function createFiberFromPortal(portal, mode, expirationTime) { - var pendingProps = portal.children !== null ? portal.children : []; - var fiber = createFiber(HostPortal, pendingProps, portal.key, mode); - fiber.expirationTime = expirationTime; - fiber.stateNode = { - containerInfo: portal.containerInfo, - pendingChildren: null, // Used by persistent updates - implementation: portal.implementation - }; - 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; - if (enableProfilerTimer) { - target.selfBaseTime = source.selfBaseTime; - target.treeBaseTime = source.treeBaseTime; - } - target._debugID = source._debugID; - target._debugSource = source._debugSource; - target._debugOwner = source._debugOwner; - target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming; - return target; +function create(props, validAttributes) { + return addProperties( + null, // updatePayload + props, + validAttributes + ); } -// TODO: This should be lifted into the renderer. - -function createFiberRoot(containerInfo, isAsync, hydrate) { - // Cyclic construction. This cheats the type system right now because - // stateNode is any. - var uninitializedFiber = createHostRootFiber(isAsync); - var root = { - current: uninitializedFiber, - containerInfo: containerInfo, - pendingChildren: null, - - earliestPendingTime: NoWork, - latestPendingTime: NoWork, - earliestSuspendedTime: NoWork, - latestSuspendedTime: NoWork, - latestPingedTime: NoWork, - - pendingCommitExpirationTime: NoWork, - finishedWork: null, - context: null, - pendingContext: null, - hydrate: hydrate, - remainingExpirationTime: NoWork, - firstBatch: null, - nextScheduledRoot: null - }; - uninitializedFiber.stateNode = root; - return root; +function diff(prevProps, nextProps, validAttributes) { + return diffProperties( + null, // updatePayload + prevProps, + nextProps, + validAttributes + ); } -var onCommitFiberRoot = null; -var onCommitFiberUnmount = null; -var hasLoggedError = false; - -function catchErrors(fn) { - return function(arg) { - try { - return fn(arg); - } catch (err) { - if (true && !hasLoggedError) { - hasLoggedError = true; - warning(false, "React DevTools encountered an error: %s", err); +/** + * In the future, we should cleanup callbacks by cancelling them instead of + * using this. + */ +function mountSafeCallback(context, callback) { + return function() { + if (!callback) { + return undefined; + } + if (typeof context.__isMounted === "boolean") { + // TODO(gaearon): this is gross and should be removed. + // It is currently necessary because View uses createClass, + // and so any measure() calls on View (which are done by React + // DevTools) trigger the isMounted() deprecation warning. + if (!context.__isMounted) { + return undefined; + } + // The else branch is important so that we don't + // trigger the deprecation warning by calling isMounted. + } else if (typeof context.isMounted === "function") { + if (!context.isMounted()) { + return undefined; } } + return callback.apply(context, arguments); }; } -function injectInternals(internals) { - if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined") { - // No DevTools - return false; - } - var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__; - if (hook.isDisabled) { - // This isn't a real property on the hook, but it can be set to opt out - // of DevTools integration and associated warnings and logs. - // https://github.com/facebook/react/issues/3877 - return true; - } - if (!hook.supportsFiber) { - { - warning( - false, - "The installed version of React DevTools is too old and will not work " + - "with the current version of React. Please update React DevTools. " + - "https://fb.me/react-devtools" - ); - } - // DevTools exists, even though it doesn't support Fiber. - return true; - } - try { - var rendererID = hook.inject(internals); - // We have successfully injected, so now it is safe to set up hooks. - onCommitFiberRoot = catchErrors(function(root) { - return hook.onCommitFiberRoot(rendererID, root); - }); - onCommitFiberUnmount = catchErrors(function(fiber) { - return hook.onCommitFiberUnmount(rendererID, fiber); - }); - } catch (err) { - // Catch all errors because it is unsafe to throw during initialization. - { - warning(false, "React DevTools encountered an error: %s.", err); +function throwOnStylesProp(component, props) { + if (props.styles !== undefined) { + var owner = component._owner || null; + var name = component.constructor.displayName; + var msg = + "`styles` is not a supported property of `" + + name + + "`, did " + + "you mean `style` (singular)?"; + if (owner && owner.constructor && owner.constructor.displayName) { + msg += + "\n\nCheck the `" + + owner.constructor.displayName + + "` parent " + + " component."; } + throw new Error(msg); } - // DevTools exists - return true; } -function onCommitRoot(root) { - if (typeof onCommitFiberRoot === "function") { - onCommitFiberRoot(root); +function warnForStyleProps(props, validAttributes) { + for (var key in validAttributes.style) { + if (!(validAttributes[key] || props[key] === undefined)) { + console.error( + "You are setting the style `{ " + + key + + ": ... }` as a prop. You " + + "should nest it in a style object. " + + "E.g. `{ style: { " + + key + + ": ... } }`" + ); + } } } -function onCommitUnmount(fiber) { - if (typeof onCommitFiberUnmount === "function") { - onCommitFiberUnmount(fiber); +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); } } -var describeComponentFrame = function(name, source, ownerName) { - return ( - "\n in " + - (name || "Unknown") + - (source - ? " (at " + - source.fileName.replace(/^.*[\\\/]/, "") + - ":" + - source.lineNumber + - ")" - : ownerName ? " (created by " + ownerName + ")" : "") - ); -}; +// Modules provided by RN: +/** + * This component defines the same methods as NativeMethodsMixin but without the + * findNodeHandle wrapper. This wrapper is unnecessary for HostComponent views + * and would also result in a circular require.js dependency (since + * ReactNativeFiber depends on this component and NativeMethodsMixin depends on + * ReactNativeFiber). + */ -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 ""; +var ReactNativeFiberHostComponent = (function() { + function ReactNativeFiberHostComponent(tag, viewConfig) { + _classCallCheck(this, ReactNativeFiberHostComponent); + + this._nativeTag = tag; + this._children = []; + this.viewConfig = viewConfig; } -} -// 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; -} + ReactNativeFiberHostComponent.prototype.blur = function blur() { + TextInputState.blurTextInput(this._nativeTag); + }; -/** - * Forked from fbjs/warning: - * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js - * - * Only change is we use console.warn instead of console.error, - * and do nothing when 'console' is not supported. - * This really simplifies the code. - * --- - * Similar to invariant but only logs a warning if the condition is not met. - * This can be used to log issues in development environments in critical - * paths. Removing the logging code for production environments will keep the - * same logic and follow the same code paths. - */ + ReactNativeFiberHostComponent.prototype.focus = function focus() { + TextInputState.focusTextInput(this._nativeTag); + }; -var lowPriorityWarning = function() {}; + ReactNativeFiberHostComponent.prototype.measure = function measure(callback) { + UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); + }; -{ - var printWarning = function(format) { - for ( - var _len = arguments.length, - args = Array(_len > 1 ? _len - 1 : 0), - _key = 1; - _key < _len; - _key++ - ) { - args[_key - 1] = arguments[_key]; - } + ReactNativeFiberHostComponent.prototype.measureInWindow = function measureInWindow( + callback + ) { + UIManager.measureInWindow( + this._nativeTag, + mountSafeCallback(this, callback) + ); + }; - var argIndex = 0; - var message = - "Warning: " + - format.replace(/%s/g, function() { - return args[argIndex++]; - }); - if (typeof console !== "undefined") { - console.warn(message); - } - try { - // --- Welcome to debugging React --- - // This error was thrown as a convenience so that you can use this stack - // to find the callsite that caused this warning to fire. - throw new Error(message); - } catch (x) {} + ReactNativeFiberHostComponent.prototype.measureLayout = function measureLayout( + relativeToNativeNode, + onSuccess, + onFail /* currently unused */ + ) { + UIManager.measureLayout( + this._nativeTag, + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); }; - lowPriorityWarning = function(condition, format) { - if (format === undefined) { - throw new Error( - "`warning(condition, format, ...args)` requires a warning " + - "message argument" - ); + ReactNativeFiberHostComponent.prototype.setNativeProps = function setNativeProps( + nativeProps + ) { + { + warnForStyleProps(nativeProps, this.viewConfig.validAttributes); } - if (!condition) { - for ( - var _len2 = arguments.length, - args = Array(_len2 > 2 ? _len2 - 2 : 0), - _key2 = 2; - _key2 < _len2; - _key2++ - ) { - args[_key2 - 2] = arguments[_key2]; - } - printWarning.apply(undefined, [format].concat(args)); + var updatePayload = create(nativeProps, this.viewConfig.validAttributes); + + // Avoid the overhead of bridge calls if there's no update. + // This is an expensive no-op for Android, and causes an unnecessary + // view invalidation for certain components (eg RCTTextInput) on iOS. + if (updatePayload != null) { + UIManager.updateView( + this._nativeTag, + this.viewConfig.uiViewClassName, + updatePayload + ); } }; -} -var lowPriorityWarning$1 = lowPriorityWarning; + return ReactNativeFiberHostComponent; +})(); -var ReactStrictModeWarnings = { - discardPendingWarnings: function() {}, - flushPendingDeprecationWarnings: function() {}, - flushPendingUnsafeLifecycleWarnings: function() {}, - recordDeprecationWarnings: function(fiber, instance) {}, - recordUnsafeLifecycleWarnings: function(fiber, instance) {} -}; +var hasNativePerformanceNow = + typeof performance === "object" && typeof performance.now === "function"; -{ - var LIFECYCLE_SUGGESTIONS = { - UNSAFE_componentWillMount: "componentDidMount", - UNSAFE_componentWillReceiveProps: "static getDerivedStateFromProps", - UNSAFE_componentWillUpdate: "componentDidUpdate" - }; +var now$1 = hasNativePerformanceNow + ? function() { + return performance.now(); + } + : function() { + return Date.now(); + }; - var pendingComponentWillMountWarnings = []; - var pendingComponentWillReceivePropsWarnings = []; - var pendingComponentWillUpdateWarnings = []; - var pendingUnsafeLifecycleWarnings = new Map(); +var scheduledCallback = null; +var frameDeadline = 0; - // Tracks components we have already warned about. - var didWarnAboutDeprecatedLifecycles = new Set(); - var didWarnAboutUnsafeLifecycles = new Set(); +var frameDeadlineObject = { + timeRemaining: function() { + return frameDeadline - now$1(); + }, + didTimeout: false +}; - var setToSortedString = function(set) { - var array = []; - set.forEach(function(value) { - array.push(value); - }); - return array.sort().join(", "); - }; +function setTimeoutCallback() { + // TODO (bvaughn) Hard-coded 5ms unblocks initial async testing. + // React API probably changing to boolean rather than time remaining. + // Longer-term plan is to rewrite this using shared memory, + // And just return the value of the bit as the boolean. + frameDeadline = now$1() + 5; - ReactStrictModeWarnings.discardPendingWarnings = function() { - pendingComponentWillMountWarnings = []; - pendingComponentWillReceivePropsWarnings = []; - pendingComponentWillUpdateWarnings = []; - pendingUnsafeLifecycleWarnings = new Map(); - }; + var callback = scheduledCallback; + scheduledCallback = null; + if (callback !== null) { + callback(frameDeadlineObject); + } +} - ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function() { - pendingUnsafeLifecycleWarnings.forEach(function( - lifecycleWarningsMap, - strictRoot - ) { - var lifecyclesWarningMesages = []; +// RN has a poor polyfill for requestIdleCallback so we aren't using it. +// This implementation is only intended for short-term use anyway. +// We also don't implement cancel functionality b'c Fiber doesn't currently need it. +function scheduleDeferredCallback$1(callback, options) { + // We assume only one callback is scheduled at a time b'c that's how Fiber works. + scheduledCallback = callback; + var timeoutId = setTimeout(setTimeoutCallback, 1); + return timeoutId; // Timeouts are always numbers on RN +} - Object.keys(lifecycleWarningsMap).forEach(function(lifecycle) { - var lifecycleWarnings = lifecycleWarningsMap[lifecycle]; - if (lifecycleWarnings.length > 0) { - var componentNames = new Set(); - lifecycleWarnings.forEach(function(fiber) { - componentNames.add(getComponentName(fiber) || "Component"); - didWarnAboutUnsafeLifecycles.add(fiber.type); - }); +function cancelDeferredCallback$1(callbackID) { + scheduledCallback = null; + clearTimeout(callbackID); // Timeouts are always numbers on RN +} - var formatted = lifecycle.replace("UNSAFE_", ""); - var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle]; - var sortedComponentNames = setToSortedString(componentNames); +// Renderers that don't support persistence +// can re-export everything from this module. - lifecyclesWarningMesages.push( - formatted + - ": Please update the following components to use " + - (suggestion + " instead: " + sortedComponentNames) - ); - } - }); +function shim() { + invariant( + false, + "The current renderer does not support persistence. " + + "This error is likely caused by a bug in React. " + + "Please file an issue." + ); +} - if (lifecyclesWarningMesages.length > 0) { - var strictRootComponentStack = getStackAddendumByWorkInProgressFiber( - strictRoot - ); +// Persistence (when unsupported) +var supportsPersistence = false; +var cloneInstance = shim; +var createContainerChildSet = shim; +var appendChildToContainerChildSet = shim; +var finalizeContainerChildren = shim; +var replaceContainerChildren = shim; - warning( - false, - "Unsafe lifecycle methods were found within a strict-mode tree:%s" + - "\n\n%s" + - "\n\nLearn more about this warning here:" + - "\nhttps://fb.me/react-strict-mode-warnings", - strictRootComponentStack, - lifecyclesWarningMesages.join("\n\n") - ); - } - }); +// Renderers that don't support hydration +// can re-export everything from this module. - pendingUnsafeLifecycleWarnings = new Map(); - }; +function shim$1() { + invariant( + false, + "The current renderer does not support hyration. " + + "This error is likely caused by a bug in React. " + + "Please file an issue." + ); +} - var findStrictRoot = function(fiber) { - var maybeStrictRoot = null; +// Hydration (when unsupported) +var supportsHydration = false; +var canHydrateInstance = shim$1; +var canHydrateTextInstance = shim$1; +var getNextHydratableSibling = shim$1; +var getFirstHydratableChild = shim$1; +var hydrateInstance = shim$1; +var hydrateTextInstance = shim$1; +var didNotMatchHydratedContainerTextInstance = shim$1; +var didNotMatchHydratedTextInstance = shim$1; +var didNotHydrateContainerInstance = shim$1; +var didNotHydrateInstance = shim$1; +var didNotFindHydratableContainerInstance = shim$1; +var didNotFindHydratableContainerTextInstance = shim$1; +var didNotFindHydratableInstance = shim$1; +var didNotFindHydratableTextInstance = shim$1; - var node = fiber; - while (node !== null) { - if (node.mode & StrictMode) { - maybeStrictRoot = node; - } - node = node.return; - } +// Modules provided by RN: +// Unused - return maybeStrictRoot; - }; +// Counter for uniquely identifying views. +// % 10 === 1 means it is a rootTag. +// % 2 === 0 means it is a Fabric tag. +var nextReactTag = 3; +function allocateTag() { + var tag = nextReactTag; + if (tag % 10 === 1) { + tag += 2; + } + nextReactTag = tag + 2; + return tag; +} - ReactStrictModeWarnings.flushPendingDeprecationWarnings = function() { - if (pendingComponentWillMountWarnings.length > 0) { - var uniqueNames = new Set(); - pendingComponentWillMountWarnings.forEach(function(fiber) { - uniqueNames.add(getComponentName(fiber) || "Component"); - didWarnAboutDeprecatedLifecycles.add(fiber.type); - }); +function recursivelyUncacheFiberNode(node) { + if (typeof node === "number") { + // Leaf node (eg text) + uncacheFiberNode(node); + } else { + uncacheFiberNode(node._nativeTag); - var sortedNames = setToSortedString(uniqueNames); + node._children.forEach(recursivelyUncacheFiberNode); + } +} - lowPriorityWarning$1( - false, - "componentWillMount is deprecated and will be removed in the next major version. " + - "Use componentDidMount instead. As a temporary workaround, " + - "you can rename to UNSAFE_componentWillMount." + - "\n\nPlease update the following components: %s" + - "\n\nLearn more about this warning here:" + - "\nhttps://fb.me/react-async-component-lifecycle-hooks", - sortedNames - ); +function appendInitialChild(parentInstance, child) { + parentInstance._children.push(child); +} - pendingComponentWillMountWarnings = []; - } +function createInstance( + type, + props, + rootContainerInstance, + hostContext, + internalInstanceHandle +) { + var tag = allocateTag(); + var viewConfig = ReactNativeViewConfigRegistry.get(type); - if (pendingComponentWillReceivePropsWarnings.length > 0) { - var _uniqueNames = new Set(); - pendingComponentWillReceivePropsWarnings.forEach(function(fiber) { - _uniqueNames.add(getComponentName(fiber) || "Component"); - didWarnAboutDeprecatedLifecycles.add(fiber.type); - }); + { + for (var key in viewConfig.validAttributes) { + if (props.hasOwnProperty(key)) { + deepFreezeAndThrowOnMutationInDev(props[key]); + } + } + } - var _sortedNames = setToSortedString(_uniqueNames); + invariant( + type !== "RCTView" || !hostContext.isInAParentText, + "Nesting of within is not currently supported." + ); - lowPriorityWarning$1( - false, - "componentWillReceiveProps is deprecated and will be removed in the next major version. " + - "Use static getDerivedStateFromProps instead." + - "\n\nPlease update the following components: %s" + - "\n\nLearn more about this warning here:" + - "\nhttps://fb.me/react-async-component-lifecycle-hooks", - _sortedNames - ); + var updatePayload = create(props, viewConfig.validAttributes); - pendingComponentWillReceivePropsWarnings = []; - } + UIManager.createView( + tag, // reactTag + viewConfig.uiViewClassName, // viewName + rootContainerInstance, // rootTag + updatePayload // props + ); - if (pendingComponentWillUpdateWarnings.length > 0) { - var _uniqueNames2 = new Set(); - pendingComponentWillUpdateWarnings.forEach(function(fiber) { - _uniqueNames2.add(getComponentName(fiber) || "Component"); - didWarnAboutDeprecatedLifecycles.add(fiber.type); - }); + var component = new ReactNativeFiberHostComponent(tag, viewConfig); - var _sortedNames2 = setToSortedString(_uniqueNames2); + precacheFiberNode(internalInstanceHandle, tag); + updateFiberProps(tag, props); - lowPriorityWarning$1( - false, - "componentWillUpdate is deprecated and will be removed in the next major version. " + - "Use componentDidUpdate instead. As a temporary workaround, " + - "you can rename to UNSAFE_componentWillUpdate." + - "\n\nPlease update the following components: %s" + - "\n\nLearn more about this warning here:" + - "\nhttps://fb.me/react-async-component-lifecycle-hooks", - _sortedNames2 - ); + // Not sure how to avoid this cast. Flow is okay if the component is defined + // in the same file but if it's external it can't see the types. + return component; +} - pendingComponentWillUpdateWarnings = []; - } - }; +function createTextInstance( + text, + rootContainerInstance, + hostContext, + internalInstanceHandle +) { + invariant( + hostContext.isInAParentText, + "Text strings must be rendered within a component." + ); - ReactStrictModeWarnings.recordDeprecationWarnings = function( - fiber, - instance - ) { - // Dedup strategy: Warn once per component. - if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) { - return; - } + var tag = allocateTag(); - // Don't warn about react-lifecycles-compat polyfilled components. - if ( - typeof instance.componentWillMount === "function" && - instance.componentWillMount.__suppressDeprecationWarning !== true - ) { - pendingComponentWillMountWarnings.push(fiber); - } - if ( - typeof instance.componentWillReceiveProps === "function" && - instance.componentWillReceiveProps.__suppressDeprecationWarning !== true - ) { - pendingComponentWillReceivePropsWarnings.push(fiber); - } - if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true - ) { - pendingComponentWillUpdateWarnings.push(fiber); - } - }; + UIManager.createView( + tag, // reactTag + "RCTRawText", // viewName + rootContainerInstance, // rootTag + { text: text } // props + ); - ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function( - fiber, - instance - ) { - var strictRoot = findStrictRoot(fiber); - if (strictRoot === null) { - warning( - false, - "Expected to find a StrictMode component in a strict mode tree. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - return; - } + precacheFiberNode(internalInstanceHandle, tag); - // Dedup strategy: Warn once per component. - // This is difficult to track any other way since component names - // are often vague and are likely to collide between 3rd party libraries. - // An expand property is probably okay to use here since it's DEV-only, - // and will only be set in the event of serious warnings. - if (didWarnAboutUnsafeLifecycles.has(fiber.type)) { - return; - } + return tag; +} - var warningsForRoot = void 0; - if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) { - warningsForRoot = { - UNSAFE_componentWillMount: [], - UNSAFE_componentWillReceiveProps: [], - UNSAFE_componentWillUpdate: [] - }; +function finalizeInitialChildren( + parentInstance, + type, + props, + rootContainerInstance, + hostContext +) { + // Don't send a no-op message over the bridge. + if (parentInstance._children.length === 0) { + return false; + } - pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot); - } else { - warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot); - } + // Map from child objects to native tags. + // Either way we need to pass a copy of the Array to prevent it from being frozen. + var nativeTags = parentInstance._children.map(function(child) { + return typeof child === "number" + ? child // Leaf node (eg text) + : child._nativeTag; + }); - var unsafeLifecycles = []; - if ( - (typeof instance.componentWillMount === "function" && - instance.componentWillMount.__suppressDeprecationWarning !== true) || - typeof instance.UNSAFE_componentWillMount === "function" - ) { - unsafeLifecycles.push("UNSAFE_componentWillMount"); - } - if ( - (typeof instance.componentWillReceiveProps === "function" && - instance.componentWillReceiveProps.__suppressDeprecationWarning !== - true) || - typeof instance.UNSAFE_componentWillReceiveProps === "function" - ) { - unsafeLifecycles.push("UNSAFE_componentWillReceiveProps"); - } - if ( - (typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true) || - typeof instance.UNSAFE_componentWillUpdate === "function" - ) { - unsafeLifecycles.push("UNSAFE_componentWillUpdate"); - } + UIManager.setChildren( + parentInstance._nativeTag, // containerTag + nativeTags // reactTags + ); - if (unsafeLifecycles.length > 0) { - unsafeLifecycles.forEach(function(lifecycle) { - warningsForRoot[lifecycle].push(fiber); - }); - } - }; + return false; } -/** - * The "actual" render time is total time required to render the descendants of a Profiler component. - * This time is stored as a stack, since Profilers can be nested. - * This time is started during the "begin" phase and stopped during the "complete" phase. - * It is paused (and accumulated) in the event of an interruption or an aborted render. - */ +function getRootHostContext(rootContainerInstance) { + return { isInAParentText: false }; +} -function createProfilerTimer(now) { - var fiberStack = void 0; +function getChildHostContext(parentHostContext, type, rootContainerInstance) { + var prevIsInAParentText = parentHostContext.isInAParentText; + var isInAParentText = + type === "AndroidTextInput" || // Android + type === "RCTMultilineTextInputView" || // iOS + type === "RCTSinglelineTextInputView" || // iOS + type === "RCTText" || + type === "RCTVirtualText"; - { - fiberStack = []; + if (prevIsInAParentText !== isInAParentText) { + return { isInAParentText: isInAParentText }; + } else { + return parentHostContext; } +} - var timerPausedAt = 0; - var totalElapsedPauseTime = 0; - - function checkActualRenderTimeStackEmpty() { - { - !(fiberStack.length === 0) - ? warning( - false, - "Expected an empty stack. Something was not reset properly." - ) - : void 0; - } - } +function getPublicInstance(instance) { + return instance; +} - function markActualRenderTimeStarted(fiber) { - { - fiberStack.push(fiber); - } - fiber.stateNode.startTime = now() - totalElapsedPauseTime; - } +function prepareForCommit(containerInfo) { + // Noop +} - function pauseActualRenderTimerIfRunning() { - if (timerPausedAt === 0) { - timerPausedAt = now(); - } - } +function prepareUpdate( + instance, + type, + oldProps, + newProps, + rootContainerInstance, + hostContext +) { + return emptyObject; +} - function recordElapsedActualRenderTime(fiber) { - { - !(fiber === fiberStack.pop()) - ? warning(false, "Unexpected Fiber popped.") - : void 0; - } - fiber.stateNode.duration += - now() - totalElapsedPauseTime - fiber.stateNode.startTime; - } +function resetAfterCommit(containerInfo) { + // Noop +} - function resetActualRenderTimer() { - totalElapsedPauseTime = 0; - } +var now = now$1; +var isPrimaryRenderer = true; +var scheduleDeferredCallback = scheduleDeferredCallback$1; +var cancelDeferredCallback = cancelDeferredCallback$1; - function resumeActualRenderTimerIfPaused() { - if (timerPausedAt > 0) { - totalElapsedPauseTime += now() - timerPausedAt; - timerPausedAt = 0; - } - } +function shouldDeprioritizeSubtree(type, props) { + return false; +} - /** - * The "base" render time is the duration of the “begin” phase of work for a particular fiber. - * This time is measured and stored on each fiber. - * The time for all sibling fibers are accumulated and stored on their parent during the "complete" phase. - * If a fiber bails out (sCU false) then its "base" timer is cancelled and the fiber is not updated. - */ +function shouldSetTextContent(type, props) { + // TODO (bvaughn) Revisit this decision. + // Always returning false simplifies the createInstance() implementation, + // But creates an additional child Fiber for raw text children. + // No additional native views are created though. + // It's not clear to me which is better so I'm deferring for now. + // More context @ github.com/facebook/react/pull/8560#discussion_r92111303 + return false; +} - var baseStartTime = -1; +// ------------------- +// Mutation +// ------------------- - function recordElapsedBaseRenderTimeIfRunning(fiber) { - if (baseStartTime !== -1) { - fiber.selfBaseTime = now() - baseStartTime; - } - } +var supportsMutation = true; - function startBaseRenderTimer() { - { - if (baseStartTime !== -1) { - warning( - false, - "Cannot start base timer that is already running. " + - "This error is likely caused by a bug in React. " + - "Please file an issue." - ); - } - } - baseStartTime = now(); - } +function appendChild(parentInstance, child) { + var childTag = typeof child === "number" ? child : child._nativeTag; + var children = parentInstance._children; + var index = children.indexOf(child); - function stopBaseRenderTimerIfRunning() { - baseStartTime = -1; - } + if (index >= 0) { + children.splice(index, 1); + children.push(child); - if (enableProfilerTimer) { - return { - checkActualRenderTimeStackEmpty: checkActualRenderTimeStackEmpty, - markActualRenderTimeStarted: markActualRenderTimeStarted, - pauseActualRenderTimerIfRunning: pauseActualRenderTimerIfRunning, - recordElapsedActualRenderTime: recordElapsedActualRenderTime, - resetActualRenderTimer: resetActualRenderTimer, - resumeActualRenderTimerIfPaused: resumeActualRenderTimerIfPaused, - recordElapsedBaseRenderTimeIfRunning: recordElapsedBaseRenderTimeIfRunning, - startBaseRenderTimer: startBaseRenderTimer, - stopBaseRenderTimerIfRunning: stopBaseRenderTimerIfRunning - }; + UIManager.manageChildren( + parentInstance._nativeTag, // containerTag + [index], // moveFromIndices + [children.length - 1], // moveToIndices + [], // addChildReactTags + [], // addAtIndices + [] // removeAtIndices + ); } else { - return { - checkActualRenderTimeStackEmpty: function() {}, - markActualRenderTimeStarted: function(fiber) {}, - pauseActualRenderTimerIfRunning: function() {}, - recordElapsedActualRenderTime: function(fiber) {}, - resetActualRenderTimer: function() {}, - resumeActualRenderTimerIfPaused: function() {}, - recordElapsedBaseRenderTimeIfRunning: function(fiber) {}, - startBaseRenderTimer: function() {}, - stopBaseRenderTimerIfRunning: function() {} - }; + children.push(child); + + UIManager.manageChildren( + parentInstance._nativeTag, // containerTag + [], // moveFromIndices + [], // moveToIndices + [childTag], // addChildReactTags + [children.length - 1], // addAtIndices + [] // removeAtIndices + ); } } -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 appendChildToContainer(parentInstance, child) { + var childTag = typeof child === "number" ? child : child._nativeTag; + UIManager.setChildren( + parentInstance, // containerTag + [childTag] // reactTags + ); } -function getCurrentFiberStackAddendum$1() { - { - var fiber = ReactDebugCurrentFiber.current; - if (fiber === null) { +function commitTextUpdate(textInstance, oldText, newText) { + UIManager.updateView( + textInstance, // reactTag + "RCTRawText", // viewName + { text: newText } // props + ); +} + +function commitUpdate( + instance, + updatePayloadTODO, + type, + oldProps, + newProps, + internalInstanceHandle +) { + var viewConfig = instance.viewConfig; + + updateFiberProps(instance._nativeTag, newProps); + + var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); + + // Avoid the overhead of bridge calls if there's no update. + // This is an expensive no-op for Android, and causes an unnecessary + // view invalidation for certain components (eg RCTTextInput) on iOS. + if (updatePayload != null) { + UIManager.updateView( + instance._nativeTag, // reactTag + viewConfig.uiViewClassName, // viewName + updatePayload // props + ); + } +} + +function insertBefore(parentInstance, child, beforeChild) { + var children = parentInstance._children; + var index = children.indexOf(child); + + // Move existing child or add new child? + if (index >= 0) { + children.splice(index, 1); + var beforeChildIndex = children.indexOf(beforeChild); + children.splice(beforeChildIndex, 0, child); + + UIManager.manageChildren( + parentInstance._nativeTag, // containerID + [index], // moveFromIndices + [beforeChildIndex], // moveToIndices + [], // addChildReactTags + [], // addAtIndices + [] // removeAtIndices + ); + } else { + var _beforeChildIndex = children.indexOf(beforeChild); + children.splice(_beforeChildIndex, 0, child); + + var childTag = typeof child === "number" ? child : child._nativeTag; + + UIManager.manageChildren( + parentInstance._nativeTag, // containerID + [], // moveFromIndices + [], // moveToIndices + [childTag], // addChildReactTags + [_beforeChildIndex], // addAtIndices + [] // removeAtIndices + ); + } +} + +function insertInContainerBefore(parentInstance, child, beforeChild) { + // TODO (bvaughn): Remove this check when... + // We create a wrapper object for the container in ReactNative render() + // Or we refactor to remove wrapper objects entirely. + // For more info on pros/cons see PR #8560 description. + invariant( + typeof parentInstance !== "number", + "Container does not support insertBefore operation" + ); +} + +function removeChild(parentInstance, child) { + recursivelyUncacheFiberNode(child); + var children = parentInstance._children; + var index = children.indexOf(child); + + children.splice(index, 1); + + UIManager.manageChildren( + parentInstance._nativeTag, // containerID + [], // moveFromIndices + [], // moveToIndices + [], // addChildReactTags + [], // addAtIndices + [index] // removeAtIndices + ); +} + +function removeChildFromContainer(parentInstance, child) { + recursivelyUncacheFiberNode(child); + UIManager.manageChildren( + parentInstance, // containerID + [], // moveFromIndices + [], // moveToIndices + [], // addChildReactTags + [], // addAtIndices + [0] // removeAtIndices + ); +} + +function resetTextContent(instance) { + // Noop +} + +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, @@ -4177,7 +4227,7 @@ function resetCurrentFiber() { } function setCurrentFiber(fiber) { - ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackAddendum$1; + ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackAddendum; ReactDebugCurrentFiber.current = fiber; ReactDebugCurrentFiber.phase = null; } @@ -4193,9 +4243,21 @@ var ReactDebugCurrentFiber = { setCurrentFiber: setCurrentFiber, setCurrentPhase: setCurrentPhase, getCurrentFiberOwnerName: getCurrentFiberOwnerName, - getCurrentFiberStackAddendum: getCurrentFiberStackAddendum$1 + getCurrentFiberStackAddendum: getCurrentFiberStackAddendum }; +var debugRenderPhaseSideEffects = false; +var debugRenderPhaseSideEffectsForStrictMode = false; +var enableGetDerivedStateFromCatch = false; +var enableSuspense = false; +var enableUserTimingAPI = true; +var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; +var warnAboutDeprecatedLifecycles = false; +var warnAboutLegacyContextAPI = false; +var enableProfilerTimer = 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"; @@ -4651,9970 +4713,9647 @@ function stopCommitLifeCyclesTimer() { } } -// UpdateQueue is a linked list of prioritized updates. -// -// Like fibers, update queues come in pairs: a current queue, which represents -// the visible state of the screen, and a work-in-progress queue, which is -// can be mutated and processed asynchronously before it is committed — a form -// of double buffering. If a work-in-progress render is discarded before -// finishing, we create a new work-in-progress by cloning the current queue. -// -// Both queues share a persistent, singly-linked list structure. To schedule an -// update, we append it to the end of both queues. Each queue maintains a -// pointer to first update in the persistent list that hasn't been processed. -// The work-in-progress pointer always has a position equal to or greater than -// the current queue, since we always work on that one. The current queue's -// pointer is only updated during the commit phase, when we swap in the -// work-in-progress. -// -// For example: -// -// Current pointer: A - B - C - D - E - F -// Work-in-progress pointer: D - E - F -// ^ -// The work-in-progress queue has -// processed more updates than current. -// -// The reason we append to both queues is because otherwise we might drop -// updates without ever processing them. For example, if we only add updates to -// the work-in-progress queue, some updates could be lost whenever a work-in -// -progress render restarts by cloning from current. Similarly, if we only add -// updates to the current queue, the updates will be lost whenever an already -// in-progress queue commits and swaps with the current queue. However, by -// adding to both queues, we guarantee that the update will be part of the next -// work-in-progress. (And because the work-in-progress queue becomes the -// current queue once it commits, there's no danger of applying the same -// update twice.) -// -// Prioritization -// -------------- -// -// Updates are not sorted by priority, but by insertion; new updates are always -// appended to the end of the list. -// -// The priority is still important, though. When processing the update queue -// during the render phase, only the updates with sufficient priority are -// included in the result. If we skip an update because it has insufficient -// priority, it remains in the queue to be processed later, during a lower -// priority render. Crucially, all updates subsequent to a skipped update also -// remain in the queue *regardless of their priority*. That means high priority -// updates are sometimes processed twice, at two separate priorities. We also -// keep track of a base state, that represents the state before the first -// update in the queue is applied. -// -// For example: -// -// Given a base state of '', and the following queue of updates -// -// A1 - B2 - C1 - D2 -// -// where the number indicates the priority, and the update is applied to the -// previous state by appending a letter, React will process these updates as -// two separate renders, one per distinct priority level: -// -// First render, at priority 1: -// Base state: '' -// Updates: [A1, C1] -// Result state: 'AC' -// -// Second render, at priority 2: -// Base state: 'A' <- The base state does not include C1, -// because B2 was skipped. -// Updates: [B2, C1, D2] <- C1 was rebased on top of B2 -// Result state: 'ABCD' -// -// Because we process updates in insertion order, and rebase high priority -// updates when preceding updates are skipped, the final result is deterministic -// regardless of priority. Intermediate state may vary according to system -// resources, but the final state is always the same. - -var UpdateState = 0; -var ReplaceState = 1; -var ForceUpdate = 2; -var CaptureUpdate = 3; +var valueStack = []; -// Global state that is reset at the beginning of calling `processUpdateQueue`. -// It should only be read right after calling `processUpdateQueue`, via -// `checkHasForceUpdateAfterProcessing`. -var hasForceUpdate = false; +var fiberStack = void 0; -var didWarnUpdateInsideUpdate = void 0; -var currentlyProcessingQueue = void 0; -var resetCurrentlyProcessingQueue = void 0; { - didWarnUpdateInsideUpdate = false; - currentlyProcessingQueue = null; - resetCurrentlyProcessingQueue = function() { - currentlyProcessingQueue = null; - }; + fiberStack = []; } -function createUpdateQueue(baseState) { - var queue = { - expirationTime: NoWork, - baseState: baseState, - firstUpdate: null, - lastUpdate: null, - firstCapturedUpdate: null, - lastCapturedUpdate: null, - firstEffect: null, - lastEffect: null, - firstCapturedEffect: null, - lastCapturedEffect: null +var index = -1; + +function createCursor(defaultValue) { + return { + current: defaultValue }; - return queue; } -function cloneUpdateQueue(currentQueue) { - var queue = { - expirationTime: currentQueue.expirationTime, - baseState: currentQueue.baseState, - firstUpdate: currentQueue.firstUpdate, - lastUpdate: currentQueue.lastUpdate, - - // TODO: With resuming, if we bail out and resuse the child tree, we should - // keep these effects. - firstCapturedUpdate: null, - lastCapturedUpdate: null, +function pop(cursor, fiber) { + if (index < 0) { + { + warning(false, "Unexpected pop."); + } + return; + } - firstEffect: null, - lastEffect: null, + { + if (fiber !== fiberStack[index]) { + warning(false, "Unexpected Fiber popped."); + } + } - firstCapturedEffect: null, - lastCapturedEffect: null - }; - return queue; -} + cursor.current = valueStack[index]; -function createUpdate(expirationTime) { - return { - expirationTime: expirationTime, + valueStack[index] = null; - tag: UpdateState, - payload: null, - callback: null, + { + fiberStack[index] = null; + } - next: null, - nextEffect: null - }; + index--; } -function appendUpdateToQueue(queue, update, expirationTime) { - // Append the update to the end of the list. - if (queue.lastUpdate === null) { - // Queue is empty - queue.firstUpdate = queue.lastUpdate = update; - } else { - queue.lastUpdate.next = update; - queue.lastUpdate = update; - } - if ( - queue.expirationTime === NoWork || - queue.expirationTime > expirationTime - ) { - // The incoming update has the earliest expiration of any update in the - // queue. Update the queue's expiration time. - queue.expirationTime = expirationTime; - } -} +function push(cursor, value, fiber) { + index++; -function enqueueUpdate(fiber, update, expirationTime) { - // Update queues are created lazily. - var alternate = fiber.alternate; - var queue1 = void 0; - var queue2 = void 0; - if (alternate === null) { - // There's only one fiber. - queue1 = fiber.updateQueue; - queue2 = null; - if (queue1 === null) { - queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState); - } - } else { - // There are two owners. - queue1 = fiber.updateQueue; - queue2 = alternate.updateQueue; - if (queue1 === null) { - if (queue2 === null) { - // Neither fiber has an update queue. Create new ones. - queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState); - queue2 = alternate.updateQueue = createUpdateQueue( - alternate.memoizedState - ); - } else { - // Only one fiber has an update queue. Clone to create a new one. - queue1 = fiber.updateQueue = cloneUpdateQueue(queue2); - } - } else { - if (queue2 === null) { - // Only one fiber has an update queue. Clone to create a new one. - queue2 = alternate.updateQueue = cloneUpdateQueue(queue1); - } else { - // Both owners have an update queue. - } - } - } - if (queue2 === null || queue1 === queue2) { - // There's only a single queue. - appendUpdateToQueue(queue1, update, expirationTime); - } else { - // There are two queues. We need to append the update to both queues, - // while accounting for the persistent structure of the list — we don't - // want the same update to be added multiple times. - if (queue1.lastUpdate === null || queue2.lastUpdate === null) { - // One of the queues is not empty. We must add the update to both queues. - appendUpdateToQueue(queue1, update, expirationTime); - appendUpdateToQueue(queue2, update, expirationTime); - } else { - // Both queues are non-empty. The last update is the same in both lists, - // because of structural sharing. So, only append to one of the lists. - appendUpdateToQueue(queue1, update, expirationTime); - // But we still need to update the `lastUpdate` pointer of queue2. - queue2.lastUpdate = update; - } + valueStack[index] = cursor.current; + + { + fiberStack[index] = fiber; } + cursor.current = value; +} + +function checkThatStackIsEmpty() { { - if ( - fiber.tag === ClassComponent && - (currentlyProcessingQueue === queue1 || - (queue2 !== null && currentlyProcessingQueue === queue2)) && - !didWarnUpdateInsideUpdate - ) { + if (index !== -1) { warning( false, - "An update (setState, replaceState, or forceUpdate) was scheduled " + - "from inside an update function. Update functions should be pure, " + - "with zero side-effects. Consider using componentDidUpdate or a " + - "callback." + "Expected an empty stack. Something was not reset properly." ); - didWarnUpdateInsideUpdate = true; } } } -function enqueueCapturedUpdate(workInProgress, update, renderExpirationTime) { - // Captured updates go into a separate list, and only on the work-in- - // progress queue. - var workInProgressQueue = workInProgress.updateQueue; - if (workInProgressQueue === null) { - workInProgressQueue = workInProgress.updateQueue = createUpdateQueue( - workInProgress.memoizedState - ); - } else { - // TODO: I put this here rather than createWorkInProgress so that we don't - // clone the queue unnecessarily. There's probably a better way to - // structure this. - workInProgressQueue = ensureWorkInProgressQueueIsAClone( - workInProgress, - workInProgressQueue - ); +function resetStackAfterFatalErrorInDev() { + { + index = -1; + valueStack.length = 0; + fiberStack.length = 0; } +} - // Append the update to the end of the list. - if (workInProgressQueue.lastCapturedUpdate === null) { - // This is the first render phase update - workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update; - } else { - workInProgressQueue.lastCapturedUpdate.next = update; - workInProgressQueue.lastCapturedUpdate = update; - } - if ( - workInProgressQueue.expirationTime === NoWork || - workInProgressQueue.expirationTime > renderExpirationTime - ) { - // The incoming update has the earliest expiration of any update in the - // queue. Update the queue's expiration time. - workInProgressQueue.expirationTime = renderExpirationTime; - } +var warnedAboutMissingGetChildContext = void 0; + +{ + warnedAboutMissingGetChildContext = {}; } -function ensureWorkInProgressQueueIsAClone(workInProgress, queue) { - var current = workInProgress.alternate; - if (current !== null) { - // If the work-in-progress queue is equal to the current queue, - // we need to clone it first. - if (queue === current.updateQueue) { - queue = workInProgress.updateQueue = cloneUpdateQueue(queue); - } +// 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 queue; + return contextStackCursor.current; } -function getStateFromUpdate( - workInProgress, - queue, - update, - prevState, - nextProps, - instance -) { - switch (update.tag) { - case ReplaceState: { - var _payload = update.payload; - if (typeof _payload === "function") { - // Updater function - { - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - _payload.call(instance, prevState, nextProps); - } - } - return _payload.call(instance, prevState, nextProps); - } - // State object - return _payload; - } - case CaptureUpdate: { - workInProgress.effectTag = - (workInProgress.effectTag & ~ShouldCapture) | DidCapture; - } - // Intentional fallthrough - case UpdateState: { - var _payload2 = update.payload; - var partialState = void 0; - if (typeof _payload2 === "function") { - // Updater function - { - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - _payload2.call(instance, prevState, nextProps); - } - } - partialState = _payload2.call(instance, prevState, nextProps); - } else { - // Partial state object - partialState = _payload2; - } - if (partialState === null || partialState === undefined) { - // Null and undefined are treated as no-ops. - return prevState; - } - // Merge the partial state and the previous state. - return Object.assign({}, prevState, partialState); - } - case ForceUpdate: { - hasForceUpdate = true; - return prevState; - } - } - return prevState; +function cacheContext(workInProgress, unmaskedContext, maskedContext) { + var instance = workInProgress.stateNode; + instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; + instance.__reactInternalMemoizedMaskedChildContext = maskedContext; } -function processUpdateQueue( - workInProgress, - queue, - props, - instance, - renderExpirationTime -) { - hasForceUpdate = false; +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 ( - queue.expirationTime === NoWork || - queue.expirationTime > renderExpirationTime + instance && + instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext ) { - // Insufficient priority. Bailout. - return; + return instance.__reactInternalMemoizedMaskedChildContext; } - queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + var context = {}; + for (var key in contextTypes) { + context[key] = unmaskedContext[key]; + } { - currentlyProcessingQueue = queue; + var name = getComponentName(workInProgress) || "Unknown"; + checkPropTypes( + contextTypes, + context, + "context", + name, + ReactDebugCurrentFiber.getCurrentFiberStackAddendum + ); } - // These values may change as we process the queue. - var newBaseState = queue.baseState; - var newFirstUpdate = null; - var newExpirationTime = NoWork; + // 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); + } - // Iterate through the list of updates to compute the result. - var update = queue.firstUpdate; - var resultState = newBaseState; - while (update !== null) { - var updateExpirationTime = update.expirationTime; - if (updateExpirationTime > renderExpirationTime) { - // This update does not have sufficient priority. Skip it. - if (newFirstUpdate === null) { - // This is the first skipped update. It will be the first update in - // the new list. - newFirstUpdate = update; - // Since this is the first update that was skipped, the current result - // is the new base state. - newBaseState = resultState; - } - // Since this update will remain in the list, update the remaining - // expiration time. - if ( - newExpirationTime === NoWork || - newExpirationTime > updateExpirationTime - ) { - newExpirationTime = updateExpirationTime; - } - } else { - // This update does have sufficient priority. Process it and compute - // a new result. - resultState = getStateFromUpdate( - workInProgress, - queue, - update, - resultState, - props, - instance - ); - var _callback = update.callback; - if (_callback !== null) { - workInProgress.effectTag |= Callback; - // Set this to null, in case it was mutated during an aborted render. - update.nextEffect = null; - if (queue.lastEffect === null) { - queue.firstEffect = queue.lastEffect = update; - } else { - queue.lastEffect.nextEffect = update; - queue.lastEffect = update; - } - } - } - // Continue to the next update. - update = update.next; + 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; } - // Separately, iterate though the list of captured updates. - var newFirstCapturedUpdate = null; - update = queue.firstCapturedUpdate; - while (update !== null) { - var _updateExpirationTime = update.expirationTime; - if (_updateExpirationTime > renderExpirationTime) { - // This update does not have sufficient priority. Skip it. - if (newFirstCapturedUpdate === null) { - // This is the first skipped captured update. It will be the first - // update in the new list. - newFirstCapturedUpdate = update; - // If this is the first update that was skipped, the current result is - // the new base state. - if (newFirstUpdate === null) { - newBaseState = resultState; - } - } - // Since this update will remain in the list, update the remaining - // expiration time. - if ( - newExpirationTime === NoWork || - newExpirationTime > _updateExpirationTime - ) { - newExpirationTime = _updateExpirationTime; - } - } else { - // This update does have sufficient priority. Process it and compute - // a new result. - resultState = getStateFromUpdate( - workInProgress, - queue, - update, - resultState, - props, - instance - ); - var _callback2 = update.callback; - if (_callback2 !== null) { - workInProgress.effectTag |= Callback; - // Set this to null, in case it was mutated during an aborted render. - update.nextEffect = null; - if (queue.lastCapturedEffect === null) { - queue.firstCapturedEffect = queue.lastCapturedEffect = update; - } else { - queue.lastCapturedEffect.nextEffect = update; - queue.lastCapturedEffect = update; - } + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} + +function popTopLevelContextObject(fiber) { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} + +function pushTopLevelContextObject(fiber, context, didChange) { + invariant( + contextStackCursor.current === emptyObject, + "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 + ); } } - update = update.next; + return parentContext; } - if (newFirstUpdate === null) { - queue.lastUpdate = null; + var childContext = void 0; + { + ReactDebugCurrentFiber.setCurrentPhase("getChildContext"); } - if (newFirstCapturedUpdate === null) { - queue.lastCapturedUpdate = null; - } else { - workInProgress.effectTag |= Callback; + startPhaseTimer(fiber, "getChildContext"); + childContext = instance.getChildContext(); + stopPhaseTimer(); + { + ReactDebugCurrentFiber.setCurrentPhase(null); } - if (newFirstUpdate === null && newFirstCapturedUpdate === null) { - // We processed every update, without skipping. That means the new base - // state is the same as the result state. - newBaseState = resultState; + 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 + ); } - queue.baseState = newBaseState; - queue.firstUpdate = newFirstUpdate; - queue.firstCapturedUpdate = newFirstCapturedUpdate; - queue.expirationTime = newExpirationTime; + return Object.assign({}, parentContext, childContext); +} - workInProgress.memoizedState = resultState; +function pushContextProvider(workInProgress) { + if (!isContextProvider(workInProgress)) { + return false; + } - { - currentlyProcessingQueue = null; + 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 callCallback(callback, context) { +function findCurrentUnmaskedContext(fiber) { + // Currently this is only used with renderSubtreeIntoContainer; not sure if it + // makes sense elsewhere invariant( - typeof callback === "function", - "Invalid argument passed as callback. Expected a function. Instead " + - "received: %s", - callback + 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." ); - callback.call(context); + + 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; } -function resetHasForceUpdateBeforeProcessing() { - hasForceUpdate = false; +// Max 31 bit integer. The max integer size in V8 for 32-bit systems. +// Math.pow(2, 30) - 1 +// 0b111111111111111111111111111111 +var MAX_SIGNED_31_BIT_INT = 1073741823; + +var NoWork = 0; +var Sync = 1; +var Never = MAX_SIGNED_31_BIT_INT; + +var UNIT_SIZE = 10; +var MAGIC_NUMBER_OFFSET = 2; + +// 1 unit of expiration time represents 10ms. +function msToExpirationTime(ms) { + // Always add an offset so that we don't clash with the magic number for NoWork. + return ((ms / UNIT_SIZE) | 0) + MAGIC_NUMBER_OFFSET; } -function checkHasForceUpdateAfterProcessing() { - return hasForceUpdate; +function expirationTimeToMs(expirationTime) { + return (expirationTime - MAGIC_NUMBER_OFFSET) * UNIT_SIZE; } -function commitUpdateQueue( - finishedWork, - finishedQueue, - instance, - renderExpirationTime -) { - // If the finished render included captured updates, and there are still - // lower priority updates left over, we need to keep the captured updates - // in the queue so that they are rebased and not dropped once we process the - // queue again at the lower priority. - if (finishedQueue.firstCapturedUpdate !== null) { - // Join the captured update list to the end of the normal list. - if (finishedQueue.lastUpdate !== null) { - finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate; - finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate; - } - // Clear the list of captured updates. - finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null; - } +function ceiling(num, precision) { + return (((num / precision) | 0) + 1) * precision; +} - // Commit the effects - var effect = finishedQueue.firstEffect; - finishedQueue.firstEffect = finishedQueue.lastEffect = null; - while (effect !== null) { - var _callback3 = effect.callback; - if (_callback3 !== null) { - effect.callback = null; - callCallback(_callback3, instance); - } - effect = effect.nextEffect; - } +function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) { + return ( + MAGIC_NUMBER_OFFSET + + ceiling( + currentTime - MAGIC_NUMBER_OFFSET + expirationInMs / UNIT_SIZE, + bucketSizeMs / UNIT_SIZE + ) + ); +} - effect = finishedQueue.firstCapturedEffect; - finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; - while (effect !== null) { - var _callback4 = effect.callback; - if (_callback4 !== null) { - effect.callback = null; - callCallback(_callback4, instance); - } - effect = effect.nextEffect; +var NoContext = 0; +var AsyncMode = 1; +var StrictMode = 2; +var ProfileMode = 4; + +var hasBadMapPolyfill = void 0; + +{ + hasBadMapPolyfill = false; + try { + var nonExtensibleObject = Object.preventExtensions({}); + var testMap = new Map([[nonExtensibleObject, null]]); + var testSet = new Set([nonExtensibleObject]); + // This is necessary for Rollup to not consider these unused. + // https://github.com/rollup/rollup/issues/1771 + // TODO: we can remove these if Rollup fixes the bug. + testMap.set(0, 0); + testSet.add(0); + } catch (e) { + // TODO: Consider warning about bad polyfills + hasBadMapPolyfill = true; } } -var fakeInternalInstance = {}; -var isArray = Array.isArray; +// A Fiber is work on a Component that needs to be done or was done. There can +// be more than one per component. -var didWarnAboutStateAssignmentForComponent = void 0; -var didWarnAboutUninitializedState = void 0; -var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0; -var didWarnAboutLegacyLifecyclesAndDerivedState = void 0; -var didWarnAboutUndefinedDerivedState = void 0; -var warnOnUndefinedDerivedState = void 0; -var warnOnInvalidCallback = void 0; +var debugCounter = void 0; { - didWarnAboutStateAssignmentForComponent = new Set(); - didWarnAboutUninitializedState = new Set(); - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); - didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); - didWarnAboutUndefinedDerivedState = new Set(); - - var didWarnOnInvalidCallback = new Set(); + debugCounter = 1; +} - warnOnInvalidCallback = function(callback, callerName) { - if (callback === null || typeof callback === "function") { - return; - } - var key = callerName + "_" + callback; - if (!didWarnOnInvalidCallback.has(key)) { - didWarnOnInvalidCallback.add(key); - warning( - false, - "%s(...): Expected the last optional `callback` argument to be a " + - "function. Instead received: %s.", - callerName, - callback - ); - } - }; +function FiberNode(tag, pendingProps, key, mode) { + // Instance + this.tag = tag; + this.key = key; + this.type = null; + this.stateNode = null; - warnOnUndefinedDerivedState = function(workInProgress, partialState) { - if (partialState === undefined) { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutUndefinedDerivedState.has(componentName)) { - didWarnAboutUndefinedDerivedState.add(componentName); - warning( - false, - "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + - "You have returned undefined.", - componentName - ); - } - } - }; + // Fiber + this.return = null; + this.child = null; + this.sibling = null; + this.index = 0; - // This is so gross but it's at least non-critical and can be removed if - // it causes problems. This is meant to give a nicer error message for - // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component, - // ...)) which otherwise throws a "_processChildContext is not a function" - // exception. - Object.defineProperty(fakeInternalInstance, "_processChildContext", { - enumerable: false, - value: function() { - invariant( - false, - "_processChildContext is not available in React 16+. This likely " + - "means you have multiple copies of React and are attempting to nest " + - "a React 15 tree inside a React 16 tree using " + - "unstable_renderSubtreeIntoContainer, which isn't supported. Try " + - "to make sure you have only one copy of React (and ideally, switch " + - "to ReactDOM.createPortal)." - ); - } - }); - Object.freeze(fakeInternalInstance); -} + this.ref = null; -function applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - nextProps -) { - var prevState = workInProgress.memoizedState; + this.pendingProps = pendingProps; + this.memoizedProps = null; + this.updateQueue = null; + this.memoizedState = null; - { - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - // Invoke the function an extra time to help detect side-effects. - getDerivedStateFromProps(nextProps, prevState); - } - } + this.mode = mode; - var partialState = getDerivedStateFromProps(nextProps, prevState); + // Effects + this.effectTag = NoEffect; + this.nextEffect = null; - { - warnOnUndefinedDerivedState(workInProgress, partialState); + this.firstEffect = null; + this.lastEffect = null; + + this.expirationTime = NoWork; + + this.alternate = null; + + if (enableProfilerTimer) { + this.actualDuration = 0; + this.actualStartTime = 0; + this.selfBaseTime = 0; + this.treeBaseTime = 0; } - // Merge the partial state and the previous state. - var memoizedState = - partialState === null || partialState === undefined - ? prevState - : Object.assign({}, prevState, partialState); - workInProgress.memoizedState = memoizedState; - // Once the update queue is empty, persist the derived state onto the - // base state. - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null && updateQueue.expirationTime === NoWork) { - updateQueue.baseState = memoizedState; + { + this._debugID = debugCounter++; + this._debugSource = null; + this._debugOwner = null; + this._debugIsCurrentlyTiming = false; + if (!hasBadMapPolyfill && typeof Object.preventExtensions === "function") { + Object.preventExtensions(this); + } } } -var ReactFiberClassComponent = function( - legacyContext, - scheduleWork, - computeExpirationForFiber, - memoizeProps, - memoizeState, - recalculateCurrentTime -) { - var cacheContext = legacyContext.cacheContext, - getMaskedContext = legacyContext.getMaskedContext, - getUnmaskedContext = legacyContext.getUnmaskedContext, - isContextConsumer = legacyContext.isContextConsumer, - hasContextChanged = legacyContext.hasContextChanged; - - var classComponentUpdater = { - isMounted: isMounted, - enqueueSetState: function(inst, payload, callback) { - var fiber = get$1(inst); - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); - - var update = createUpdate(expirationTime); - update.payload = payload; - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "setState"); - } - update.callback = callback; - } +// This is a constructor function, rather than a POJO constructor, still +// please ensure we do the following: +// 1) Nobody should add any instance methods on this. Instance methods can be +// more difficult to predict when they get optimized and they are almost +// never inlined properly in static compilers. +// 2) Nobody should rely on `instanceof Fiber` for type testing. We should +// always know when it is a fiber. +// 3) We might want to experiment with using numeric keys since they are easier +// to optimize in a non-JIT environment. +// 4) We can easily go from a constructor to a createFiber object literal if that +// is faster. +// 5) It should be easy to port this to a C struct and keep a C implementation +// compatible. +var createFiber = function(tag, pendingProps, key, mode) { + // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors + return new FiberNode(tag, pendingProps, key, mode); +}; - enqueueUpdate(fiber, update, expirationTime); - scheduleWork(fiber, expirationTime); - }, - enqueueReplaceState: function(inst, payload, callback) { - var fiber = get$1(inst); - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); +function shouldConstruct(Component) { + return !!(Component.prototype && Component.prototype.isReactComponent); +} - var update = createUpdate(expirationTime); - update.tag = ReplaceState; - update.payload = payload; +// This is used to create an alternate fiber to do work on. +function createWorkInProgress(current, pendingProps, expirationTime) { + var workInProgress = current.alternate; + if (workInProgress === null) { + // We use a double buffering pooling technique because we know that we'll + // only ever need at most two versions of a tree. We pool the "other" unused + // node that we're free to reuse. This is lazily created to avoid allocating + // extra objects for things that are never updated. It also allow us to + // reclaim the extra memory if needed. + workInProgress = createFiber( + current.tag, + pendingProps, + current.key, + current.mode + ); + workInProgress.type = current.type; + workInProgress.stateNode = current.stateNode; - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "replaceState"); - } - update.callback = callback; - } + { + // DEV-only fields + workInProgress._debugID = current._debugID; + workInProgress._debugSource = current._debugSource; + workInProgress._debugOwner = current._debugOwner; + } - enqueueUpdate(fiber, update, expirationTime); - scheduleWork(fiber, expirationTime); - }, - enqueueForceUpdate: function(inst, callback) { - var fiber = get$1(inst); - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); + workInProgress.alternate = current; + current.alternate = workInProgress; + } else { + workInProgress.pendingProps = pendingProps; - var update = createUpdate(expirationTime); - update.tag = ForceUpdate; + // We already have an alternate. + // Reset the effect tag. + workInProgress.effectTag = NoEffect; - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "forceUpdate"); - } - update.callback = callback; - } + // The effect list is no longer valid. + workInProgress.nextEffect = null; + workInProgress.firstEffect = null; + workInProgress.lastEffect = null; - enqueueUpdate(fiber, update, expirationTime); - scheduleWork(fiber, expirationTime); + if (enableProfilerTimer) { + // We intentionally reset, rather than copy, actualDuration & actualStartTime. + // This prevents time from endlessly accumulating in new commits. + // This has the downside of resetting values for different priority renders, + // But works for yielding (the common case) and should support resuming. + workInProgress.actualDuration = 0; + workInProgress.actualStartTime = 0; } - }; - - function checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - newState, - newContext - ) { - var instance = workInProgress.stateNode; - var ctor = workInProgress.type; - if (typeof instance.shouldComponentUpdate === "function") { - startPhaseTimer(workInProgress, "shouldComponentUpdate"); - var shouldUpdate = instance.shouldComponentUpdate( - newProps, - newState, - newContext - ); - 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; - } + workInProgress.expirationTime = expirationTime; - return shouldUpdate; - } + workInProgress.child = current.child; + workInProgress.memoizedProps = current.memoizedProps; + workInProgress.memoizedState = current.memoizedState; + workInProgress.updateQueue = current.updateQueue; - if (ctor.prototype && ctor.prototype.isPureReactComponent) { - return ( - !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) - ); - } + // These will be overridden during the parent's reconciliation + workInProgress.sibling = current.sibling; + workInProgress.index = current.index; + workInProgress.ref = current.ref; - return true; + if (enableProfilerTimer) { + workInProgress.selfBaseTime = current.selfBaseTime; + workInProgress.treeBaseTime = current.treeBaseTime; } - function checkClassInstance(workInProgress) { - var instance = workInProgress.stateNode; - var type = workInProgress.type; - { - var name = getComponentName(workInProgress) || "Component"; - var renderPresent = instance.render; + return workInProgress; +} - if (!renderPresent) { - if (type.prototype && typeof type.prototype.render === "function") { - warning( - false, - "%s(...): No `render` method found on the returned component " + - "instance: did you accidentally return an object from the constructor?", - name - ); - } else { - warning( - false, - "%s(...): No `render` method found on the returned component " + - "instance: you may have forgotten to define `render`.", - name - ); - } - } +function createHostRootFiber(isAsync) { + var mode = isAsync ? AsyncMode | StrictMode : NoContext; + return createFiber(HostRoot, null, null, mode); +} - var noGetInitialStateOnES6 = - !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; - 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; - 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; - 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; - 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; - if ( - type.prototype && - type.prototype.isPureReactComponent && - typeof instance.shouldComponentUpdate !== "undefined" - ) { - warning( - false, - "%s has a method called shouldComponentUpdate(). " + - "shouldComponentUpdate should not be used when extending React.PureComponent. " + - "Please extend React.Component if shouldComponentUpdate is used.", - getComponentName(workInProgress) || "A pure component" - ); - } - 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; - 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; - var noComponentWillRecieveProps = - typeof instance.componentWillRecieveProps !== "function"; - !noComponentWillRecieveProps - ? warning( - false, - "%s has a method called " + - "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", - name - ) - : void 0; - 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; - 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; - 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; - - if ( - typeof instance.getSnapshotBeforeUpdate === "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; - } - } +function createFiberFromElement(element, mode, expirationTime) { + var owner = null; + { + owner = element._owner; } - function adoptClassInstance(workInProgress, instance) { - instance.updater = classComponentUpdater; - workInProgress.stateNode = instance; - // The instance needs access to the fiber so that it can schedule updates - set(instance, workInProgress); - { - instance._reactInternalInstance = fakeInternalInstance; + var fiber = void 0; + var type = element.type; + var key = element.key; + var pendingProps = element.props; + + var fiberTag = void 0; + if (typeof type === "function") { + fiberTag = shouldConstruct(type) ? ClassComponent : IndeterminateComponent; + } else if (typeof type === "string") { + fiberTag = HostComponent; + } else { + switch (type) { + case REACT_FRAGMENT_TYPE: + return createFiberFromFragment( + pendingProps.children, + mode, + expirationTime, + key + ); + case REACT_ASYNC_MODE_TYPE: + fiberTag = Mode; + mode |= AsyncMode | StrictMode; + break; + case REACT_STRICT_MODE_TYPE: + fiberTag = Mode; + mode |= StrictMode; + break; + case REACT_PROFILER_TYPE: + return createFiberFromProfiler(pendingProps, mode, expirationTime, key); + case REACT_TIMEOUT_TYPE: + fiberTag = TimeoutComponent; + // Suspense does not require async, but its children should be strict + // mode compatible. + mode |= StrictMode; + break; + default: + fiberTag = getFiberTagFromObjectType(type, owner); + break; } } - function constructClassInstance(workInProgress, props, renderExpirationTime) { - var ctor = workInProgress.type; - var unmaskedContext = getUnmaskedContext(workInProgress); - var needsContext = isContextConsumer(workInProgress); - var context = needsContext - ? getMaskedContext(workInProgress, unmaskedContext) - : emptyObject; + fiber = createFiber(fiberTag, pendingProps, key, mode); + fiber.type = type; + fiber.expirationTime = expirationTime; - // Instantiate twice to help detect side-effects. - { - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - new ctor(props, context); // eslint-disable-line no-new - } - } + { + fiber._debugSource = element._source; + fiber._debugOwner = element._owner; + } - var instance = new ctor(props, context); - var state = (workInProgress.memoizedState = - instance.state !== null && instance.state !== undefined - ? instance.state - : null); - adoptClassInstance(workInProgress, instance); + return fiber; +} - { - if ( - typeof ctor.getDerivedStateFromProps === "function" && - state === null - ) { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutUninitializedState.has(componentName)) { - didWarnAboutUninitializedState.add(componentName); - warning( - false, - "%s: Did not properly initialize state during construction. " + - "Expected state to be an object, but it was %s.", - componentName, - instance.state === null ? "null" : "undefined" - ); - } - } +function getFiberTagFromObjectType(type, owner) { + var $$typeof = + typeof type === "object" && type !== null ? type.$$typeof : null; - // 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"; - } + switch ($$typeof) { + case REACT_PROVIDER_TYPE: + return ContextProvider; + case REACT_CONTEXT_TYPE: + // This is a consumer + return ContextConsumer; + case REACT_FORWARD_REF_TYPE: + return ForwardRef; + default: { + var info = ""; + { if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true + type === undefined || + (typeof type === "object" && + type !== null && + Object.keys(type).length === 0) ) { - foundWillUpdateName = "componentWillUpdate"; - } else if (typeof instance.UNSAFE_componentWillUpdate === "function") { - foundWillUpdateName = "UNSAFE_componentWillUpdate"; + info += + " You likely forgot to export your component from the file " + + "it's defined in, or you might have mixed up default and " + + "named imports."; } - 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 : "" - ); - } + var ownerName = owner ? getComponentName(owner) : null; + if (ownerName) { + info += "\n\nCheck the render method of `" + ownerName + "`."; } } - } - - // Cache unmasked context so we can avoid recreating masked context unless necessary. - // ReactFiberContext usually updates this cache but can't for newly-created instances. - if (needsContext) { - cacheContext(workInProgress, unmaskedContext, context); - } - - return instance; - } - - function callComponentWillMount(workInProgress, instance) { - startPhaseTimer(workInProgress, "componentWillMount"); - var oldState = instance.state; - - if (typeof instance.componentWillMount === "function") { - instance.componentWillMount(); - } - if (typeof instance.UNSAFE_componentWillMount === "function") { - instance.UNSAFE_componentWillMount(); - } - - stopPhaseTimer(); - - if (oldState !== instance.state) { - { - warning( - false, - "%s.componentWillMount(): Assigning directly to this.state is " + - "deprecated (except inside a component's " + - "constructor). Use setState instead.", - getComponentName(workInProgress) || "Component" - ); - } - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); + invariant( + false, + "Element type is invalid: expected a string (for built-in " + + "components) or a class/function (for composite components) " + + "but got: %s.%s", + type == null ? type : typeof type, + info + ); } } +} - function callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newContext - ) { - var oldState = instance.state; - startPhaseTimer(workInProgress, "componentWillReceiveProps"); - if (typeof instance.componentWillReceiveProps === "function") { - instance.componentWillReceiveProps(newProps, newContext); - } - if (typeof instance.UNSAFE_componentWillReceiveProps === "function") { - instance.UNSAFE_componentWillReceiveProps(newProps, newContext); - } - stopPhaseTimer(); +function createFiberFromFragment(elements, mode, expirationTime, key) { + var fiber = createFiber(Fragment, elements, key, mode); + fiber.expirationTime = expirationTime; + return fiber; +} - if (instance.state !== oldState) { - { - var componentName = getComponentName(workInProgress) || "Component"; - if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { - didWarnAboutStateAssignmentForComponent.add(componentName); - warning( - false, - "%s.componentWillReceiveProps(): Assigning directly to " + - "this.state is deprecated (except inside a component's " + - "constructor). Use setState instead.", - componentName - ); - } - } - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); +function createFiberFromProfiler(pendingProps, mode, expirationTime, key) { + { + if ( + typeof pendingProps.id !== "string" || + typeof pendingProps.onRender !== "function" + ) { + invariant( + false, + 'Profiler must specify an "id" string and "onRender" function as props' + ); } } - // Invokes the mount life-cycles on a previously never rendered instance. - function mountClassInstance(workInProgress, renderExpirationTime) { - var ctor = workInProgress.type; + var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); + fiber.type = REACT_PROFILER_TYPE; + fiber.expirationTime = expirationTime; - { - checkClassInstance(workInProgress); - } + return fiber; +} - var instance = workInProgress.stateNode; - var props = workInProgress.pendingProps; - var unmaskedContext = getUnmaskedContext(workInProgress); +function createFiberFromText(content, mode, expirationTime) { + var fiber = createFiber(HostText, content, null, mode); + fiber.expirationTime = expirationTime; + return fiber; +} - instance.props = props; - instance.state = workInProgress.memoizedState; - instance.refs = emptyObject; - instance.context = getMaskedContext(workInProgress, unmaskedContext); +function createFiberFromHostInstanceForDeletion() { + var fiber = createFiber(HostComponent, null, null, NoContext); + fiber.type = "DELETED"; + return fiber; +} - { - if (workInProgress.mode & StrictMode) { - ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( - workInProgress, - instance - ); - } - - if (warnAboutDeprecatedLifecycles) { - ReactStrictModeWarnings.recordDeprecationWarnings( - workInProgress, - instance - ); - } - } - - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - props, - instance, - renderExpirationTime - ); - instance.state = workInProgress.memoizedState; - } +function createFiberFromPortal(portal, mode, expirationTime) { + var pendingProps = portal.children !== null ? portal.children : []; + var fiber = createFiber(HostPortal, pendingProps, portal.key, mode); + fiber.expirationTime = expirationTime; + fiber.stateNode = { + containerInfo: portal.containerInfo, + pendingChildren: null, // Used by persistent updates + implementation: portal.implementation + }; + return fiber; +} - var getDerivedStateFromProps = workInProgress.type.getDerivedStateFromProps; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - props - ); - instance.state = workInProgress.memoizedState; - } +// 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); + } - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - typeof ctor.getDerivedStateFromProps !== "function" && - typeof instance.getSnapshotBeforeUpdate !== "function" && - (typeof instance.UNSAFE_componentWillMount === "function" || - typeof instance.componentWillMount === "function") - ) { - callComponentWillMount(workInProgress, instance); - // If we had additional state updates during this life-cycle, let's - // process them now. - updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - props, - instance, - renderExpirationTime - ); - instance.state = workInProgress.memoizedState; - } - } + // 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. - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; - } + 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; + if (enableProfilerTimer) { + target.actualDuration = source.actualDuration; + target.actualStartTime = source.actualStartTime; + target.selfBaseTime = source.selfBaseTime; + target.treeBaseTime = source.treeBaseTime; } + target._debugID = source._debugID; + target._debugSource = source._debugSource; + target._debugOwner = source._debugOwner; + target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming; + return target; +} - function resumeMountClassInstance(workInProgress, renderExpirationTime) { - var ctor = workInProgress.type; - var instance = workInProgress.stateNode; - - var oldProps = workInProgress.memoizedProps; - var newProps = workInProgress.pendingProps; - instance.props = oldProps; +// TODO: This should be lifted into the renderer. - var oldContext = instance.context; - var newUnmaskedContext = getUnmaskedContext(workInProgress); - var newContext = getMaskedContext(workInProgress, newUnmaskedContext); +function createFiberRoot(containerInfo, isAsync, hydrate) { + // Cyclic construction. This cheats the type system right now because + // stateNode is any. + var uninitializedFiber = createHostRootFiber(isAsync); + var root = { + current: uninitializedFiber, + containerInfo: containerInfo, + pendingChildren: null, - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - var hasNewLifecycles = - typeof getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; + earliestPendingTime: NoWork, + latestPendingTime: NoWork, + earliestSuspendedTime: NoWork, + latestSuspendedTime: NoWork, + latestPingedTime: NoWork, - // 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. + didError: false, - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillReceiveProps === "function" || - typeof instance.componentWillReceiveProps === "function") - ) { - if (oldProps !== newProps || oldContext !== newContext) { - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newContext - ); - } - } + pendingCommitExpirationTime: NoWork, + finishedWork: null, + context: null, + pendingContext: null, + hydrate: hydrate, + nextExpirationTimeToWorkOn: NoWork, + expirationTime: NoWork, + firstBatch: null, + nextScheduledRoot: null + }; + uninitializedFiber.stateNode = root; + return root; +} - resetHasForceUpdateBeforeProcessing(); +var onCommitFiberRoot = null; +var onCommitFiberUnmount = null; +var hasLoggedError = false; - var oldState = workInProgress.memoizedState; - var newState = (instance.state = oldState); - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime - ); - newState = workInProgress.memoizedState; - } - if ( - oldProps === newProps && - oldState === newState && - !hasContextChanged() && - !checkHasForceUpdateAfterProcessing() - ) { - // 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. - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; +function catchErrors(fn) { + return function(arg) { + try { + return fn(arg); + } catch (err) { + if (true && !hasLoggedError) { + hasLoggedError = true; + warning(false, "React DevTools encountered an error: %s", err); } - return false; } + }; +} - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - newProps +function injectInternals(internals) { + if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined") { + // No DevTools + return false; + } + var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__; + if (hook.isDisabled) { + // This isn't a real property on the hook, but it can be set to opt out + // of DevTools integration and associated warnings and logs. + // https://github.com/facebook/react/issues/3877 + return true; + } + if (!hook.supportsFiber) { + { + warning( + false, + "The installed version of React DevTools is too old and will not work " + + "with the current version of React. Please update React DevTools. " + + "https://fb.me/react-devtools" ); - newState = workInProgress.memoizedState; } - - var shouldUpdate = - checkHasForceUpdateAfterProcessing() || - checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - newState, - newContext - ); - - if (shouldUpdate) { - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillMount === "function" || - typeof instance.componentWillMount === "function") - ) { - startPhaseTimer(workInProgress, "componentWillMount"); - if (typeof instance.componentWillMount === "function") { - instance.componentWillMount(); - } - if (typeof instance.UNSAFE_componentWillMount === "function") { - instance.UNSAFE_componentWillMount(); - } - stopPhaseTimer(); - } - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; - } - } 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. - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; - } - - // If shouldComponentUpdate returned false, we should still update the - // memoized state to indicate that this work can be reused. - workInProgress.memoizedProps = newProps; - workInProgress.memoizedState = newState; + // DevTools exists, even though it doesn't support Fiber. + return true; + } + try { + var rendererID = hook.inject(internals); + // We have successfully injected, so now it is safe to set up hooks. + onCommitFiberRoot = catchErrors(function(root) { + return hook.onCommitFiberRoot(rendererID, root); + }); + onCommitFiberUnmount = catchErrors(function(fiber) { + return hook.onCommitFiberUnmount(rendererID, fiber); + }); + } catch (err) { + // Catch all errors because it is unsafe to throw during initialization. + { + warning(false, "React DevTools encountered an error: %s.", err); } - - // Update the existing instance's state, props, and context pointers even - // if shouldComponentUpdate returns false. - instance.props = newProps; - instance.state = newState; - instance.context = newContext; - - return shouldUpdate; } + // DevTools exists + return true; +} - // Invokes the update life-cycles and returns false if it shouldn't rerender. - function updateClassInstance(current, workInProgress, renderExpirationTime) { - var ctor = workInProgress.type; - var instance = workInProgress.stateNode; - - var oldProps = workInProgress.memoizedProps; - var newProps = workInProgress.pendingProps; - instance.props = oldProps; +function onCommitRoot(root) { + if (typeof onCommitFiberRoot === "function") { + onCommitFiberRoot(root); + } +} - var oldContext = instance.context; - var newUnmaskedContext = getUnmaskedContext(workInProgress); - var newContext = getMaskedContext(workInProgress, newUnmaskedContext); +function onCommitUnmount(fiber) { + if (typeof onCommitFiberUnmount === "function") { + onCommitFiberUnmount(fiber); + } +} - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - var hasNewLifecycles = - typeof getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; +/** + * Forked from fbjs/warning: + * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js + * + * Only change is we use console.warn instead of console.error, + * and do nothing when 'console' is not supported. + * This really simplifies the code. + * --- + * Similar to invariant but only logs a warning if the condition is not met. + * This can be used to log issues in development environments in critical + * paths. Removing the logging code for production environments will keep the + * same logic and follow the same code paths. + */ - // 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. +var lowPriorityWarning = function() {}; - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillReceiveProps === "function" || - typeof instance.componentWillReceiveProps === "function") - ) { - if (oldProps !== newProps || oldContext !== newContext) { - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newContext - ); - } +{ + var printWarning = function(format) { + for ( + var _len = arguments.length, + args = Array(_len > 1 ? _len - 1 : 0), + _key = 1; + _key < _len; + _key++ + ) { + args[_key - 1] = arguments[_key]; } - resetHasForceUpdateBeforeProcessing(); + var argIndex = 0; + var message = + "Warning: " + + format.replace(/%s/g, function() { + return args[argIndex++]; + }); + if (typeof console !== "undefined") { + console.warn(message); + } + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) {} + }; - var oldState = workInProgress.memoizedState; - var newState = (instance.state = oldState); - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime + lowPriorityWarning = function(condition, format) { + if (format === undefined) { + throw new Error( + "`warning(condition, format, ...args)` requires a warning " + + "message argument" ); - newState = workInProgress.memoizedState; } - - if ( - oldProps === newProps && - oldState === newState && - !hasContextChanged() && - !checkHasForceUpdateAfterProcessing() - ) { - // 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. - if (typeof instance.componentDidUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Update; - } - } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Snapshot; - } + if (!condition) { + for ( + var _len2 = arguments.length, + args = Array(_len2 > 2 ? _len2 - 2 : 0), + _key2 = 2; + _key2 < _len2; + _key2++ + ) { + args[_key2 - 2] = arguments[_key2]; } - return false; - } - if (typeof getDerivedStateFromProps === "function") { - if (fireGetDerivedStateFromPropsOnStateUpdates || oldProps !== newProps) { - applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - newProps - ); - newState = workInProgress.memoizedState; - } + printWarning.apply(undefined, [format].concat(args)); } + }; +} - var shouldUpdate = - checkHasForceUpdateAfterProcessing() || - checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - newState, - newContext - ); +var lowPriorityWarning$1 = lowPriorityWarning; - if (shouldUpdate) { - // In order to support react-lifecycles-compat polyfilled components, - // Unsafe lifecycles should not be invoked for components using the new APIs. - if ( - !hasNewLifecycles && - (typeof instance.UNSAFE_componentWillUpdate === "function" || - typeof instance.componentWillUpdate === "function") - ) { - startPhaseTimer(workInProgress, "componentWillUpdate"); - if (typeof instance.componentWillUpdate === "function") { - instance.componentWillUpdate(newProps, newState, newContext); - } - if (typeof instance.UNSAFE_componentWillUpdate === "function") { - instance.UNSAFE_componentWillUpdate(newProps, newState, newContext); - } - stopPhaseTimer(); - } - 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. - if (typeof instance.componentDidUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Update; - } - } - if (typeof instance.getSnapshotBeforeUpdate === "function") { - if ( - oldProps !== current.memoizedProps || - oldState !== current.memoizedState - ) { - workInProgress.effectTag |= Snapshot; - } - } +var ReactStrictModeWarnings = { + discardPendingWarnings: function() {}, + flushPendingDeprecationWarnings: function() {}, + flushPendingUnsafeLifecycleWarnings: function() {}, + recordDeprecationWarnings: function(fiber, instance) {}, + recordUnsafeLifecycleWarnings: function(fiber, instance) {}, + recordLegacyContextWarning: function(fiber, instance) {}, + flushLegacyContextWarning: function() {} +}; - // If shouldComponentUpdate returned false, we should still update the - // memoized props/state to indicate that this work can be reused. - workInProgress.memoizedProps = newProps; - workInProgress.memoizedState = newState; - } +{ + var LIFECYCLE_SUGGESTIONS = { + UNSAFE_componentWillMount: "componentDidMount", + UNSAFE_componentWillReceiveProps: "static getDerivedStateFromProps", + UNSAFE_componentWillUpdate: "componentDidUpdate" + }; - // Update the existing instance's state, props, and context pointers even - // if shouldComponentUpdate returns false. - instance.props = newProps; - instance.state = newState; - instance.context = newContext; + var pendingComponentWillMountWarnings = []; + var pendingComponentWillReceivePropsWarnings = []; + var pendingComponentWillUpdateWarnings = []; + var pendingUnsafeLifecycleWarnings = new Map(); + var pendingLegacyContextWarning = new Map(); - return shouldUpdate; - } + // Tracks components we have already warned about. + var didWarnAboutDeprecatedLifecycles = new Set(); + var didWarnAboutUnsafeLifecycles = new Set(); + var didWarnAboutLegacyContext = new Set(); - return { - adoptClassInstance: adoptClassInstance, - constructClassInstance: constructClassInstance, - mountClassInstance: mountClassInstance, - resumeMountClassInstance: resumeMountClassInstance, - updateClassInstance: updateClassInstance + var setToSortedString = function(set) { + var array = []; + set.forEach(function(value) { + array.push(value); + }); + return array.sort().join(", "); }; -}; -var getCurrentFiberStackAddendum$2 = - ReactDebugCurrentFiber.getCurrentFiberStackAddendum; + ReactStrictModeWarnings.discardPendingWarnings = function() { + pendingComponentWillMountWarnings = []; + pendingComponentWillReceivePropsWarnings = []; + pendingComponentWillUpdateWarnings = []; + pendingUnsafeLifecycleWarnings = new Map(); + pendingLegacyContextWarning = new Map(); + }; -var didWarnAboutMaps = void 0; -var didWarnAboutStringRefInStrictMode = void 0; -var ownerHasKeyUseWarning = void 0; -var ownerHasFunctionTypeWarning = void 0; -var warnForMissingKey = function(child) {}; + ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function() { + pendingUnsafeLifecycleWarnings.forEach(function( + lifecycleWarningsMap, + strictRoot + ) { + var lifecyclesWarningMesages = []; -{ - didWarnAboutMaps = false; - didWarnAboutStringRefInStrictMode = {}; + Object.keys(lifecycleWarningsMap).forEach(function(lifecycle) { + var lifecycleWarnings = lifecycleWarningsMap[lifecycle]; + if (lifecycleWarnings.length > 0) { + var componentNames = new Set(); + lifecycleWarnings.forEach(function(fiber) { + componentNames.add(getComponentName(fiber) || "Component"); + didWarnAboutUnsafeLifecycles.add(fiber.type); + }); - /** - * Warn if there's no key explicitly set on dynamic arrays of children or - * object keys are not valid. This allows us to keep track of children between - * updates. - */ - ownerHasKeyUseWarning = {}; - ownerHasFunctionTypeWarning = {}; + var formatted = lifecycle.replace("UNSAFE_", ""); + var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle]; + var sortedComponentNames = setToSortedString(componentNames); - warnForMissingKey = function(child) { - if (child === null || typeof child !== "object") { - return; - } - if (!child._store || child._store.validated || child.key != null) { - return; - } - invariant( - typeof child._store === "object", - "React Component in warnForMissingKey should have a _store. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - child._store.validated = true; + lifecyclesWarningMesages.push( + formatted + + ": Please update the following components to use " + + (suggestion + " instead: " + sortedComponentNames) + ); + } + }); - var currentComponentErrorInfo = - "Each child in an array or iterator should have a unique " + - '"key" prop. See https://fb.me/react-warning-keys for ' + - "more information." + - (getCurrentFiberStackAddendum$2() || ""); - if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { - return; - } - ownerHasKeyUseWarning[currentComponentErrorInfo] = true; + if (lifecyclesWarningMesages.length > 0) { + var strictRootComponentStack = getStackAddendumByWorkInProgressFiber( + strictRoot + ); - warning( - false, - "Each child in an array or iterator should have a unique " + - '"key" prop. See https://fb.me/react-warning-keys for ' + - "more information.%s", - getCurrentFiberStackAddendum$2() - ); + warning( + false, + "Unsafe lifecycle methods were found within a strict-mode tree:%s" + + "\n\n%s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-strict-mode-warnings", + strictRootComponentStack, + lifecyclesWarningMesages.join("\n\n") + ); + } + }); + + pendingUnsafeLifecycleWarnings = new Map(); }; -} -var isArray$1 = Array.isArray; + var findStrictRoot = function(fiber) { + var maybeStrictRoot = null; -function coerceRef(returnFiber, current, element) { - var mixedRef = element.ref; - if ( - mixedRef !== null && - typeof mixedRef !== "function" && - typeof mixedRef !== "object" - ) { - { - if (returnFiber.mode & StrictMode) { - var componentName = getComponentName(returnFiber) || "Component"; - if (!didWarnAboutStringRefInStrictMode[componentName]) { - warning( - false, - 'A string ref, "%s", has been found within a strict mode tree. ' + - "String refs are a source of potential bugs and should be avoided. " + - "We recommend using createRef() instead." + - "\n%s" + - "\n\nLearn more about using refs safely here:" + - "\nhttps://fb.me/react-strict-mode-string-ref", - mixedRef, - getStackAddendumByWorkInProgressFiber(returnFiber) - ); - didWarnAboutStringRefInStrictMode[componentName] = true; - } + var node = fiber; + while (node !== null) { + if (node.mode & StrictMode) { + maybeStrictRoot = node; } + node = node.return; } - if (element._owner) { - var owner = element._owner; - var inst = void 0; - if (owner) { - var ownerFiber = owner; - invariant( - ownerFiber.tag === ClassComponent, - "Stateless function components cannot have refs." - ); - inst = ownerFiber.stateNode; - } - invariant( - inst, - "Missing owner for string ref %s. This error is likely caused by a " + - "bug in React. Please file an issue.", - mixedRef - ); - var stringRef = "" + mixedRef; - // Check if previous string ref matches new string ref - if ( - current !== null && - current.ref !== null && - current.ref._stringRef === stringRef - ) { - return current.ref; - } - var ref = function(value) { - var refs = inst.refs === emptyObject ? (inst.refs = {}) : inst.refs; - if (value === null) { - delete refs[stringRef]; - } else { - refs[stringRef] = value; - } - }; - ref._stringRef = stringRef; - return ref; - } else { - invariant( - typeof mixedRef === "string", - "Expected ref to be a function or a string." - ); - invariant( - element._owner, - "Element ref was specified as a string (%s) but no owner was set. This could happen for one of" + - " the following reasons:\n" + - "1. You may be adding a ref to a functional component\n" + - "2. You may be adding a ref to a component that was not created inside a component's render method\n" + - "3. You have multiple copies of React loaded\n" + - "See https://fb.me/react-refs-must-have-owner for more information.", - mixedRef + return maybeStrictRoot; + }; + + ReactStrictModeWarnings.flushPendingDeprecationWarnings = function() { + if (pendingComponentWillMountWarnings.length > 0) { + var uniqueNames = new Set(); + pendingComponentWillMountWarnings.forEach(function(fiber) { + uniqueNames.add(getComponentName(fiber) || "Component"); + didWarnAboutDeprecatedLifecycles.add(fiber.type); + }); + + var sortedNames = setToSortedString(uniqueNames); + + lowPriorityWarning$1( + false, + "componentWillMount is deprecated and will be removed in the next major version. " + + "Use componentDidMount instead. As a temporary workaround, " + + "you can rename to UNSAFE_componentWillMount." + + "\n\nPlease update the following components: %s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-async-component-lifecycle-hooks", + sortedNames ); + + pendingComponentWillMountWarnings = []; } - } - return mixedRef; -} -function throwOnInvalidObjectType(returnFiber, newChild) { - if (returnFiber.type !== "textarea") { - var addendum = ""; - { - addendum = - " If you meant to render a collection of children, use an array " + - "instead." + - (getCurrentFiberStackAddendum$2() || ""); + if (pendingComponentWillReceivePropsWarnings.length > 0) { + var _uniqueNames = new Set(); + pendingComponentWillReceivePropsWarnings.forEach(function(fiber) { + _uniqueNames.add(getComponentName(fiber) || "Component"); + didWarnAboutDeprecatedLifecycles.add(fiber.type); + }); + + var _sortedNames = setToSortedString(_uniqueNames); + + lowPriorityWarning$1( + false, + "componentWillReceiveProps is deprecated and will be removed in the next major version. " + + "Use static getDerivedStateFromProps instead." + + "\n\nPlease update the following components: %s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-async-component-lifecycle-hooks", + _sortedNames + ); + + pendingComponentWillReceivePropsWarnings = []; } - invariant( - false, - "Objects are not valid as a React child (found: %s).%s", - Object.prototype.toString.call(newChild) === "[object Object]" - ? "object with keys {" + Object.keys(newChild).join(", ") + "}" - : newChild, - addendum - ); - } -} -function warnOnFunctionType() { - var currentComponentErrorInfo = - "Functions are not valid as a React child. This may happen if " + - "you return a Component instead of from render. " + - "Or maybe you meant to call this function rather than return it." + - (getCurrentFiberStackAddendum$2() || ""); + if (pendingComponentWillUpdateWarnings.length > 0) { + var _uniqueNames2 = new Set(); + pendingComponentWillUpdateWarnings.forEach(function(fiber) { + _uniqueNames2.add(getComponentName(fiber) || "Component"); + didWarnAboutDeprecatedLifecycles.add(fiber.type); + }); - if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) { - return; - } - ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; + var _sortedNames2 = setToSortedString(_uniqueNames2); - warning( - false, - "Functions are not valid as a React child. This may happen if " + - "you return a Component instead of from render. " + - "Or maybe you meant to call this function rather than return it.%s", - getCurrentFiberStackAddendum$2() || "" - ); -} + lowPriorityWarning$1( + false, + "componentWillUpdate is deprecated and will be removed in the next major version. " + + "Use componentDidUpdate instead. As a temporary workaround, " + + "you can rename to UNSAFE_componentWillUpdate." + + "\n\nPlease update the following components: %s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-async-component-lifecycle-hooks", + _sortedNames2 + ); -// This wrapper function exists because I expect to clone the code in each path -// to be able to optimize each path individually by branching early. This needs -// a compiler or we can do it manually. Helpers that don't need this branching -// live outside of this function. -function ChildReconciler(shouldTrackSideEffects) { - function deleteChild(returnFiber, childToDelete) { - if (!shouldTrackSideEffects) { - // Noop. + pendingComponentWillUpdateWarnings = []; + } + }; + + ReactStrictModeWarnings.recordDeprecationWarnings = function( + fiber, + instance + ) { + // Dedup strategy: Warn once per component. + if (didWarnAboutDeprecatedLifecycles.has(fiber.type)) { return; } - // Deletions are added in reversed order so we add it to the front. - // At this point, the return fiber's effect list is empty except for - // deletions, so we can just append the deletion to the list. The remaining - // effects aren't added until the complete phase. Once we implement - // resuming, this may not be true. - var last = returnFiber.lastEffect; - if (last !== null) { - last.nextEffect = childToDelete; - returnFiber.lastEffect = childToDelete; - } else { - returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; + + // Don't warn about react-lifecycles-compat polyfilled components. + if ( + typeof instance.componentWillMount === "function" && + instance.componentWillMount.__suppressDeprecationWarning !== true + ) { + pendingComponentWillMountWarnings.push(fiber); } - childToDelete.nextEffect = null; - childToDelete.effectTag = Deletion; - } + if ( + typeof instance.componentWillReceiveProps === "function" && + instance.componentWillReceiveProps.__suppressDeprecationWarning !== true + ) { + pendingComponentWillReceivePropsWarnings.push(fiber); + } + if ( + typeof instance.componentWillUpdate === "function" && + instance.componentWillUpdate.__suppressDeprecationWarning !== true + ) { + pendingComponentWillUpdateWarnings.push(fiber); + } + }; - function deleteRemainingChildren(returnFiber, currentFirstChild) { - if (!shouldTrackSideEffects) { - // Noop. - return null; + ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function( + fiber, + instance + ) { + var strictRoot = findStrictRoot(fiber); + if (strictRoot === null) { + warning( + false, + "Expected to find a StrictMode component in a strict mode tree. " + + "This error is likely caused by a bug in React. Please file an issue." + ); + return; } - // TODO: For the shouldClone case, this could be micro-optimized a bit by - // assuming that after the first child we've already added everything. - var childToDelete = currentFirstChild; - while (childToDelete !== null) { - deleteChild(returnFiber, childToDelete); - childToDelete = childToDelete.sibling; + // Dedup strategy: Warn once per component. + // This is difficult to track any other way since component names + // are often vague and are likely to collide between 3rd party libraries. + // An expand property is probably okay to use here since it's DEV-only, + // and will only be set in the event of serious warnings. + if (didWarnAboutUnsafeLifecycles.has(fiber.type)) { + return; } - return null; - } - function mapRemainingChildren(returnFiber, currentFirstChild) { - // Add the remaining children to a temporary map so that we can find them by - // keys quickly. Implicit (null) keys get added to this set with their index - var existingChildren = new Map(); + var warningsForRoot = void 0; + if (!pendingUnsafeLifecycleWarnings.has(strictRoot)) { + warningsForRoot = { + UNSAFE_componentWillMount: [], + UNSAFE_componentWillReceiveProps: [], + UNSAFE_componentWillUpdate: [] + }; - var existingChild = currentFirstChild; - while (existingChild !== null) { - if (existingChild.key !== null) { - existingChildren.set(existingChild.key, existingChild); - } else { - existingChildren.set(existingChild.index, existingChild); - } - existingChild = existingChild.sibling; + pendingUnsafeLifecycleWarnings.set(strictRoot, warningsForRoot); + } else { + warningsForRoot = pendingUnsafeLifecycleWarnings.get(strictRoot); } - return existingChildren; - } - function useFiber(fiber, pendingProps, expirationTime) { - // We currently set sibling to null and index to 0 here because it is easy - // to forget to do before returning it. E.g. for the single child case. - var clone = createWorkInProgress(fiber, pendingProps, expirationTime); - clone.index = 0; - clone.sibling = null; - return clone; - } - - function placeChild(newFiber, lastPlacedIndex, newIndex) { - newFiber.index = newIndex; - if (!shouldTrackSideEffects) { - // Noop. - return lastPlacedIndex; + var unsafeLifecycles = []; + if ( + (typeof instance.componentWillMount === "function" && + instance.componentWillMount.__suppressDeprecationWarning !== true) || + typeof instance.UNSAFE_componentWillMount === "function" + ) { + unsafeLifecycles.push("UNSAFE_componentWillMount"); } - var current = newFiber.alternate; - if (current !== null) { - var oldIndex = current.index; - if (oldIndex < lastPlacedIndex) { - // This is a move. - newFiber.effectTag = Placement; - return lastPlacedIndex; - } else { - // This item can stay in place. - return oldIndex; - } - } else { - // This is an insertion. - newFiber.effectTag = Placement; - return lastPlacedIndex; + if ( + (typeof instance.componentWillReceiveProps === "function" && + instance.componentWillReceiveProps.__suppressDeprecationWarning !== + true) || + typeof instance.UNSAFE_componentWillReceiveProps === "function" + ) { + unsafeLifecycles.push("UNSAFE_componentWillReceiveProps"); + } + if ( + (typeof instance.componentWillUpdate === "function" && + instance.componentWillUpdate.__suppressDeprecationWarning !== true) || + typeof instance.UNSAFE_componentWillUpdate === "function" + ) { + unsafeLifecycles.push("UNSAFE_componentWillUpdate"); } - } - function placeSingleChild(newFiber) { - // This is simpler for the single child case. We only need to do a - // placement for inserting new children. - if (shouldTrackSideEffects && newFiber.alternate === null) { - newFiber.effectTag = Placement; + if (unsafeLifecycles.length > 0) { + unsafeLifecycles.forEach(function(lifecycle) { + warningsForRoot[lifecycle].push(fiber); + }); } - return newFiber; - } + }; - function updateTextNode(returnFiber, current, textContent, expirationTime) { - if (current === null || current.tag !== HostText) { - // Insert - var created = createFiberFromText( - textContent, - returnFiber.mode, - expirationTime + ReactStrictModeWarnings.recordLegacyContextWarning = function( + fiber, + instance + ) { + var strictRoot = findStrictRoot(fiber); + if (strictRoot === null) { + warning( + false, + "Expected to find a StrictMode component in a strict mode tree. " + + "This error is likely caused by a bug in React. Please file an issue." ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current, textContent, expirationTime); - existing.return = returnFiber; - return existing; + return; } - } - function updateElement(returnFiber, current, element, expirationTime) { - if (current !== null && current.type === element.type) { - // Move based on index - var existing = useFiber(current, element.props, expirationTime); - existing.ref = coerceRef(returnFiber, current, element); - existing.return = returnFiber; - { - existing._debugSource = element._source; - existing._debugOwner = element._owner; - } - return existing; - } else { - // Insert - var created = createFiberFromElement( - element, - returnFiber.mode, - expirationTime - ); - created.ref = coerceRef(returnFiber, current, element); - created.return = returnFiber; - return created; + // Dedup strategy: Warn once per component. + if (didWarnAboutLegacyContext.has(fiber.type)) { + return; } - } - function updatePortal(returnFiber, current, portal, expirationTime) { + var warningsForRoot = pendingLegacyContextWarning.get(strictRoot); + if ( - current === null || - current.tag !== HostPortal || - current.stateNode.containerInfo !== portal.containerInfo || - current.stateNode.implementation !== portal.implementation + fiber.type.contextTypes != null || + fiber.type.childContextTypes != null || + (instance !== null && typeof instance.getChildContext === "function") ) { - // Insert - var created = createFiberFromPortal( - portal, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current, portal.children || [], expirationTime); - existing.return = returnFiber; - return existing; + if (warningsForRoot === undefined) { + warningsForRoot = []; + pendingLegacyContextWarning.set(strictRoot, warningsForRoot); + } + warningsForRoot.push(fiber); } - } + }; - function updateFragment(returnFiber, current, fragment, expirationTime, key) { - if (current === null || current.tag !== Fragment) { - // Insert - var created = createFiberFromFragment( - fragment, - returnFiber.mode, - expirationTime, - key + ReactStrictModeWarnings.flushLegacyContextWarning = function() { + pendingLegacyContextWarning.forEach(function(fiberArray, strictRoot) { + var uniqueNames = new Set(); + fiberArray.forEach(function(fiber) { + uniqueNames.add(getComponentName(fiber) || "Component"); + didWarnAboutLegacyContext.add(fiber.type); + }); + + var sortedNames = setToSortedString(uniqueNames); + var strictRootComponentStack = getStackAddendumByWorkInProgressFiber( + strictRoot ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current, fragment, expirationTime); - existing.return = returnFiber; - return existing; - } - } - function createChild(returnFiber, newChild, expirationTime) { - if (typeof newChild === "string" || typeof newChild === "number") { - // Text nodes don't have keys. If the previous node is implicitly keyed - // we can continue to replace it without aborting even if it is not a text - // node. - var created = createFiberFromText( - "" + newChild, - returnFiber.mode, - expirationTime + warning( + false, + "Legacy context API has been detected within a strict-mode tree: %s" + + "\n\nPlease update the following components: %s" + + "\n\nLearn more about this warning here:" + + "\nhttps://fb.me/react-strict-mode-warnings", + strictRootComponentStack, + sortedNames ); - created.return = returnFiber; - return created; - } + }); + }; +} - if (typeof newChild === "object" && newChild !== null) { - switch (newChild.$$typeof) { - case REACT_ELEMENT_TYPE: { - var _created = createFiberFromElement( - newChild, - returnFiber.mode, - expirationTime - ); - _created.ref = coerceRef(returnFiber, null, newChild); - _created.return = returnFiber; - return _created; - } - case REACT_PORTAL_TYPE: { - var _created2 = createFiberFromPortal( - newChild, - returnFiber.mode, - expirationTime - ); - _created2.return = returnFiber; - return _created2; - } - } +// This lets us hook into Fiber to debug what it's doing. +// See https://github.com/facebook/react/pull/8033. +// This is not part of the public API, not even for React DevTools. +// You may only inject a debugTool if you work on React Fiber itself. +var ReactFiberInstrumentation = { + debugTool: null +}; - if (isArray$1(newChild) || getIteratorFn(newChild)) { - var _created3 = createFiberFromFragment( - newChild, - returnFiber.mode, - expirationTime, - null - ); - _created3.return = returnFiber; - return _created3; - } +var ReactFiberInstrumentation_1 = ReactFiberInstrumentation; - throwOnInvalidObjectType(returnFiber, newChild); +// TODO: Offscreen updates + +function markPendingPriorityLevel(root, expirationTime) { + // If there's a gap between completing a failed root and retrying it, + // additional updates may be scheduled. Clear `didError`, in case the update + // is sufficient to fix the error. + root.didError = false; + + // Update the latest and earliest pending times + var earliestPendingTime = root.earliestPendingTime; + if (earliestPendingTime === NoWork) { + // No other pending updates. + root.earliestPendingTime = root.latestPendingTime = expirationTime; + } else { + if (earliestPendingTime > expirationTime) { + // This is the earliest pending update. + root.earliestPendingTime = expirationTime; + } else { + var latestPendingTime = root.latestPendingTime; + if (latestPendingTime < expirationTime) { + // This is the latest pending update + root.latestPendingTime = expirationTime; + } } + } + findNextPendingPriorityLevel(root); +} - { - if (typeof newChild === "function") { - warnOnFunctionType(); +function markCommittedPriorityLevels(root, currentTime, earliestRemainingTime) { + root.didError = false; + + if (earliestRemainingTime === NoWork) { + // Fast path. There's no remaining work. Clear everything. + root.earliestPendingTime = NoWork; + root.latestPendingTime = NoWork; + root.earliestSuspendedTime = NoWork; + root.latestSuspendedTime = NoWork; + root.latestPingedTime = NoWork; + findNextPendingPriorityLevel(root); + return; + } + + // Let's see if the previous latest known pending level was just flushed. + var latestPendingTime = root.latestPendingTime; + if (latestPendingTime !== NoWork) { + if (latestPendingTime < earliestRemainingTime) { + // We've flushed all the known pending levels. + root.earliestPendingTime = root.latestPendingTime = NoWork; + } else { + var earliestPendingTime = root.earliestPendingTime; + if (earliestPendingTime < earliestRemainingTime) { + // We've flushed the earliest known pending level. Set this to the + // latest pending time. + root.earliestPendingTime = root.latestPendingTime; } } + } - return null; + // Now let's handle the earliest remaining level in the whole tree. We need to + // decide whether to treat it as a pending level or as suspended. Check + // it falls within the range of known suspended levels. + + var earliestSuspendedTime = root.earliestSuspendedTime; + if (earliestSuspendedTime === NoWork) { + // There's no suspended work. Treat the earliest remaining level as a + // pending level. + markPendingPriorityLevel(root, earliestRemainingTime); + findNextPendingPriorityLevel(root); + return; } - function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { - // Update the fiber if the keys match, otherwise return null. + var latestSuspendedTime = root.latestSuspendedTime; + if (earliestRemainingTime > latestSuspendedTime) { + // The earliest remaining level is later than all the suspended work. That + // means we've flushed all the suspended work. + root.earliestSuspendedTime = NoWork; + root.latestSuspendedTime = NoWork; + root.latestPingedTime = NoWork; - var key = oldFiber !== null ? oldFiber.key : null; + // There's no suspended work. Treat the earliest remaining level as a + // pending level. + markPendingPriorityLevel(root, earliestRemainingTime); + findNextPendingPriorityLevel(root); + return; + } - if (typeof newChild === "string" || typeof newChild === "number") { - // Text nodes don't have keys. If the previous node is implicitly keyed - // we can continue to replace it without aborting even if it is not a text - // node. - if (key !== null) { - return null; - } - return updateTextNode( - returnFiber, - oldFiber, - "" + newChild, - expirationTime - ); - } + if (earliestRemainingTime < earliestSuspendedTime) { + // The earliest remaining time is earlier than all the suspended work. + // Treat it as a pending update. + markPendingPriorityLevel(root, earliestRemainingTime); + findNextPendingPriorityLevel(root); + return; + } - if (typeof newChild === "object" && newChild !== null) { - switch (newChild.$$typeof) { - case REACT_ELEMENT_TYPE: { - if (newChild.key === key) { - if (newChild.type === REACT_FRAGMENT_TYPE) { - return updateFragment( - returnFiber, - oldFiber, - newChild.props.children, - expirationTime, - key - ); - } - return updateElement( - returnFiber, - oldFiber, - newChild, - expirationTime - ); - } else { - return null; + // The earliest remaining time falls within the range of known suspended + // levels. We should treat this as suspended work. + findNextPendingPriorityLevel(root); +} + +function hasLowerPriorityWork(root, renderExpirationTime) { + return ( + renderExpirationTime !== root.latestPendingTime && + renderExpirationTime !== root.latestSuspendedTime + ); +} + +function markSuspendedPriorityLevel(root, suspendedTime, didError) { + if (didError && !hasLowerPriorityWork(root, suspendedTime)) { + // TODO: When we add back resuming, we need to ensure the progressed work + // is thrown out and not reused during the restarted render. One way to + // invalidate the progressed work is to restart at expirationTime + 1. + root.didError = true; + findNextPendingPriorityLevel(root); + return; + } + + // First, check the known pending levels and update them if needed. + var earliestPendingTime = root.earliestPendingTime; + var latestPendingTime = root.latestPendingTime; + if (earliestPendingTime === suspendedTime) { + if (latestPendingTime === suspendedTime) { + // Both known pending levels were suspended. Clear them. + root.earliestPendingTime = root.latestPendingTime = NoWork; + } else { + // The earliest pending level was suspended. Clear by setting it to the + // latest pending level. + root.earliestPendingTime = latestPendingTime; + } + } else if (latestPendingTime === suspendedTime) { + // The latest pending level was suspended. Clear by setting it to the + // latest pending level. + root.latestPendingTime = earliestPendingTime; + } + + // Next, if we're working on the lowest known suspended level, clear the ping. + // TODO: What if a promise suspends and pings before the root completes? + var latestSuspendedTime = root.latestSuspendedTime; + if (latestSuspendedTime === suspendedTime) { + root.latestPingedTime = NoWork; + } + + // Finally, update the known suspended levels. + var earliestSuspendedTime = root.earliestSuspendedTime; + if (earliestSuspendedTime === NoWork) { + // No other suspended levels. + root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime; + } else { + if (earliestSuspendedTime > suspendedTime) { + // This is the earliest suspended level. + root.earliestSuspendedTime = suspendedTime; + } else if (latestSuspendedTime < suspendedTime) { + // This is the latest suspended level + root.latestSuspendedTime = suspendedTime; + } + } + findNextPendingPriorityLevel(root); +} + +function markPingedPriorityLevel(root, pingedTime) { + var latestSuspendedTime = root.latestSuspendedTime; + if (latestSuspendedTime !== NoWork && latestSuspendedTime <= pingedTime) { + var latestPingedTime = root.latestPingedTime; + if (latestPingedTime === NoWork || latestPingedTime < pingedTime) { + root.latestPingedTime = pingedTime; + } + } + findNextPendingPriorityLevel(root); +} + +function findNextPendingPriorityLevel(root) { + var earliestSuspendedTime = root.earliestSuspendedTime; + var earliestPendingTime = root.earliestPendingTime; + var nextExpirationTimeToWorkOn = void 0; + var expirationTime = void 0; + if (earliestSuspendedTime === NoWork) { + // Fast path. There's no suspended work. + nextExpirationTimeToWorkOn = expirationTime = earliestPendingTime; + } else if (earliestPendingTime !== NoWork) { + // Check if there's known pending work. + nextExpirationTimeToWorkOn = earliestPendingTime; + expirationTime = + earliestSuspendedTime < earliestPendingTime + ? earliestSuspendedTime + : earliestPendingTime; + } else { + // Finally, if a suspended level was pinged, work on that. Otherwise there's + // nothing to work on. + nextExpirationTimeToWorkOn = expirationTime = root.latestPingedTime; + } + + if (root.didError) { + // Revert to synchronous mode. + expirationTime = Sync; + } + + root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn; + root.expirationTime = expirationTime; +} + +// UpdateQueue is a linked list of prioritized updates. +// +// Like fibers, update queues come in pairs: a current queue, which represents +// the visible state of the screen, and a work-in-progress queue, which is +// can be mutated and processed asynchronously before it is committed — a form +// of double buffering. If a work-in-progress render is discarded before +// finishing, we create a new work-in-progress by cloning the current queue. +// +// Both queues share a persistent, singly-linked list structure. To schedule an +// update, we append it to the end of both queues. Each queue maintains a +// pointer to first update in the persistent list that hasn't been processed. +// The work-in-progress pointer always has a position equal to or greater than +// the current queue, since we always work on that one. The current queue's +// pointer is only updated during the commit phase, when we swap in the +// work-in-progress. +// +// For example: +// +// Current pointer: A - B - C - D - E - F +// Work-in-progress pointer: D - E - F +// ^ +// The work-in-progress queue has +// processed more updates than current. +// +// The reason we append to both queues is because otherwise we might drop +// updates without ever processing them. For example, if we only add updates to +// the work-in-progress queue, some updates could be lost whenever a work-in +// -progress render restarts by cloning from current. Similarly, if we only add +// updates to the current queue, the updates will be lost whenever an already +// in-progress queue commits and swaps with the current queue. However, by +// adding to both queues, we guarantee that the update will be part of the next +// work-in-progress. (And because the work-in-progress queue becomes the +// current queue once it commits, there's no danger of applying the same +// update twice.) +// +// Prioritization +// -------------- +// +// Updates are not sorted by priority, but by insertion; new updates are always +// appended to the end of the list. +// +// The priority is still important, though. When processing the update queue +// during the render phase, only the updates with sufficient priority are +// included in the result. If we skip an update because it has insufficient +// priority, it remains in the queue to be processed later, during a lower +// priority render. Crucially, all updates subsequent to a skipped update also +// remain in the queue *regardless of their priority*. That means high priority +// updates are sometimes processed twice, at two separate priorities. We also +// keep track of a base state, that represents the state before the first +// update in the queue is applied. +// +// For example: +// +// Given a base state of '', and the following queue of updates +// +// A1 - B2 - C1 - D2 +// +// where the number indicates the priority, and the update is applied to the +// previous state by appending a letter, React will process these updates as +// two separate renders, one per distinct priority level: +// +// First render, at priority 1: +// Base state: '' +// Updates: [A1, C1] +// Result state: 'AC' +// +// Second render, at priority 2: +// Base state: 'A' <- The base state does not include C1, +// because B2 was skipped. +// Updates: [B2, C1, D2] <- C1 was rebased on top of B2 +// Result state: 'ABCD' +// +// Because we process updates in insertion order, and rebase high priority +// updates when preceding updates are skipped, the final result is deterministic +// regardless of priority. Intermediate state may vary according to system +// resources, but the final state is always the same. + +var UpdateState = 0; +var ReplaceState = 1; +var ForceUpdate = 2; +var CaptureUpdate = 3; + +// Global state that is reset at the beginning of calling `processUpdateQueue`. +// It should only be read right after calling `processUpdateQueue`, via +// `checkHasForceUpdateAfterProcessing`. +var hasForceUpdate = false; + +var didWarnUpdateInsideUpdate = void 0; +var currentlyProcessingQueue = void 0; +var resetCurrentlyProcessingQueue = void 0; +{ + didWarnUpdateInsideUpdate = false; + currentlyProcessingQueue = null; + resetCurrentlyProcessingQueue = function() { + currentlyProcessingQueue = null; + }; +} + +function createUpdateQueue(baseState) { + var queue = { + expirationTime: NoWork, + baseState: baseState, + firstUpdate: null, + lastUpdate: null, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; + return queue; +} + +function cloneUpdateQueue(currentQueue) { + var queue = { + expirationTime: currentQueue.expirationTime, + baseState: currentQueue.baseState, + firstUpdate: currentQueue.firstUpdate, + lastUpdate: currentQueue.lastUpdate, + + // TODO: With resuming, if we bail out and resuse the child tree, we should + // keep these effects. + firstCapturedUpdate: null, + lastCapturedUpdate: null, + + firstEffect: null, + lastEffect: null, + + firstCapturedEffect: null, + lastCapturedEffect: null + }; + return queue; +} + +function createUpdate(expirationTime) { + return { + expirationTime: expirationTime, + + tag: UpdateState, + payload: null, + callback: null, + + next: null, + nextEffect: null + }; +} + +function appendUpdateToQueue(queue, update, expirationTime) { + // Append the update to the end of the list. + if (queue.lastUpdate === null) { + // Queue is empty + queue.firstUpdate = queue.lastUpdate = update; + } else { + queue.lastUpdate.next = update; + queue.lastUpdate = update; + } + if ( + queue.expirationTime === NoWork || + queue.expirationTime > expirationTime + ) { + // The incoming update has the earliest expiration of any update in the + // queue. Update the queue's expiration time. + queue.expirationTime = expirationTime; + } +} + +function enqueueUpdate(fiber, update, expirationTime) { + // Update queues are created lazily. + var alternate = fiber.alternate; + var queue1 = void 0; + var queue2 = void 0; + if (alternate === null) { + // There's only one fiber. + queue1 = fiber.updateQueue; + queue2 = null; + if (queue1 === null) { + queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState); + } + } else { + // There are two owners. + queue1 = fiber.updateQueue; + queue2 = alternate.updateQueue; + if (queue1 === null) { + if (queue2 === null) { + // Neither fiber has an update queue. Create new ones. + queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState); + queue2 = alternate.updateQueue = createUpdateQueue( + alternate.memoizedState + ); + } else { + // Only one fiber has an update queue. Clone to create a new one. + queue1 = fiber.updateQueue = cloneUpdateQueue(queue2); + } + } else { + if (queue2 === null) { + // Only one fiber has an update queue. Clone to create a new one. + queue2 = alternate.updateQueue = cloneUpdateQueue(queue1); + } else { + // Both owners have an update queue. + } + } + } + if (queue2 === null || queue1 === queue2) { + // There's only a single queue. + appendUpdateToQueue(queue1, update, expirationTime); + } else { + // There are two queues. We need to append the update to both queues, + // while accounting for the persistent structure of the list — we don't + // want the same update to be added multiple times. + if (queue1.lastUpdate === null || queue2.lastUpdate === null) { + // One of the queues is not empty. We must add the update to both queues. + appendUpdateToQueue(queue1, update, expirationTime); + appendUpdateToQueue(queue2, update, expirationTime); + } else { + // Both queues are non-empty. The last update is the same in both lists, + // because of structural sharing. So, only append to one of the lists. + appendUpdateToQueue(queue1, update, expirationTime); + // But we still need to update the `lastUpdate` pointer of queue2. + queue2.lastUpdate = update; + } + } + + { + if ( + fiber.tag === ClassComponent && + (currentlyProcessingQueue === queue1 || + (queue2 !== null && currentlyProcessingQueue === queue2)) && + !didWarnUpdateInsideUpdate + ) { + warning( + false, + "An update (setState, replaceState, or forceUpdate) was scheduled " + + "from inside an update function. Update functions should be pure, " + + "with zero side-effects. Consider using componentDidUpdate or a " + + "callback." + ); + didWarnUpdateInsideUpdate = true; + } + } +} + +function enqueueCapturedUpdate(workInProgress, update, renderExpirationTime) { + // Captured updates go into a separate list, and only on the work-in- + // progress queue. + var workInProgressQueue = workInProgress.updateQueue; + if (workInProgressQueue === null) { + workInProgressQueue = workInProgress.updateQueue = createUpdateQueue( + workInProgress.memoizedState + ); + } else { + // TODO: I put this here rather than createWorkInProgress so that we don't + // clone the queue unnecessarily. There's probably a better way to + // structure this. + workInProgressQueue = ensureWorkInProgressQueueIsAClone( + workInProgress, + workInProgressQueue + ); + } + + // Append the update to the end of the list. + if (workInProgressQueue.lastCapturedUpdate === null) { + // This is the first render phase update + workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update; + } else { + workInProgressQueue.lastCapturedUpdate.next = update; + workInProgressQueue.lastCapturedUpdate = update; + } + if ( + workInProgressQueue.expirationTime === NoWork || + workInProgressQueue.expirationTime > renderExpirationTime + ) { + // The incoming update has the earliest expiration of any update in the + // queue. Update the queue's expiration time. + workInProgressQueue.expirationTime = renderExpirationTime; + } +} + +function ensureWorkInProgressQueueIsAClone(workInProgress, queue) { + var current = workInProgress.alternate; + if (current !== null) { + // If the work-in-progress queue is equal to the current queue, + // we need to clone it first. + if (queue === current.updateQueue) { + queue = workInProgress.updateQueue = cloneUpdateQueue(queue); + } + } + return queue; +} + +function getStateFromUpdate( + workInProgress, + queue, + update, + prevState, + nextProps, + instance +) { + switch (update.tag) { + case ReplaceState: { + var _payload = update.payload; + if (typeof _payload === "function") { + // Updater function + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + _payload.call(instance, prevState, nextProps); } } - case REACT_PORTAL_TYPE: { - if (newChild.key === key) { - return updatePortal( - returnFiber, - oldFiber, - newChild, - expirationTime - ); - } else { - return null; + return _payload.call(instance, prevState, nextProps); + } + // State object + return _payload; + } + case CaptureUpdate: { + workInProgress.effectTag = + (workInProgress.effectTag & ~ShouldCapture) | DidCapture; + } + // Intentional fallthrough + case UpdateState: { + var _payload2 = update.payload; + var partialState = void 0; + if (typeof _payload2 === "function") { + // Updater function + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + _payload2.call(instance, prevState, nextProps); } } + partialState = _payload2.call(instance, prevState, nextProps); + } else { + // Partial state object + partialState = _payload2; + } + if (partialState === null || partialState === undefined) { + // Null and undefined are treated as no-ops. + return prevState; + } + // Merge the partial state and the previous state. + return Object.assign({}, prevState, partialState); + } + case ForceUpdate: { + hasForceUpdate = true; + return prevState; + } + } + return prevState; +} + +function processUpdateQueue( + workInProgress, + queue, + props, + instance, + renderExpirationTime +) { + hasForceUpdate = false; + + if ( + queue.expirationTime === NoWork || + queue.expirationTime > renderExpirationTime + ) { + // Insufficient priority. Bailout. + return; + } + + queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + + { + currentlyProcessingQueue = queue; + } + + // These values may change as we process the queue. + var newBaseState = queue.baseState; + var newFirstUpdate = null; + var newExpirationTime = NoWork; + + // Iterate through the list of updates to compute the result. + var update = queue.firstUpdate; + var resultState = newBaseState; + while (update !== null) { + var updateExpirationTime = update.expirationTime; + if (updateExpirationTime > renderExpirationTime) { + // This update does not have sufficient priority. Skip it. + if (newFirstUpdate === null) { + // This is the first skipped update. It will be the first update in + // the new list. + newFirstUpdate = update; + // Since this is the first update that was skipped, the current result + // is the new base state. + newBaseState = resultState; + } + // Since this update will remain in the list, update the remaining + // expiration time. + if ( + newExpirationTime === NoWork || + newExpirationTime > updateExpirationTime + ) { + newExpirationTime = updateExpirationTime; + } + } else { + // This update does have sufficient priority. Process it and compute + // a new result. + resultState = getStateFromUpdate( + workInProgress, + queue, + update, + resultState, + props, + instance + ); + var _callback = update.callback; + if (_callback !== null) { + workInProgress.effectTag |= Callback; + // Set this to null, in case it was mutated during an aborted render. + update.nextEffect = null; + if (queue.lastEffect === null) { + queue.firstEffect = queue.lastEffect = update; + } else { + queue.lastEffect.nextEffect = update; + queue.lastEffect = update; + } + } + } + // Continue to the next update. + update = update.next; + } + + // Separately, iterate though the list of captured updates. + var newFirstCapturedUpdate = null; + update = queue.firstCapturedUpdate; + while (update !== null) { + var _updateExpirationTime = update.expirationTime; + if (_updateExpirationTime > renderExpirationTime) { + // This update does not have sufficient priority. Skip it. + if (newFirstCapturedUpdate === null) { + // This is the first skipped captured update. It will be the first + // update in the new list. + newFirstCapturedUpdate = update; + // If this is the first update that was skipped, the current result is + // the new base state. + if (newFirstUpdate === null) { + newBaseState = resultState; + } + } + // Since this update will remain in the list, update the remaining + // expiration time. + if ( + newExpirationTime === NoWork || + newExpirationTime > _updateExpirationTime + ) { + newExpirationTime = _updateExpirationTime; + } + } else { + // This update does have sufficient priority. Process it and compute + // a new result. + resultState = getStateFromUpdate( + workInProgress, + queue, + update, + resultState, + props, + instance + ); + var _callback2 = update.callback; + if (_callback2 !== null) { + workInProgress.effectTag |= Callback; + // Set this to null, in case it was mutated during an aborted render. + update.nextEffect = null; + if (queue.lastCapturedEffect === null) { + queue.firstCapturedEffect = queue.lastCapturedEffect = update; + } else { + queue.lastCapturedEffect.nextEffect = update; + queue.lastCapturedEffect = update; + } } + } + update = update.next; + } + + if (newFirstUpdate === null) { + queue.lastUpdate = null; + } + if (newFirstCapturedUpdate === null) { + queue.lastCapturedUpdate = null; + } else { + workInProgress.effectTag |= Callback; + } + if (newFirstUpdate === null && newFirstCapturedUpdate === null) { + // We processed every update, without skipping. That means the new base + // state is the same as the result state. + newBaseState = resultState; + } - if (isArray$1(newChild) || getIteratorFn(newChild)) { - if (key !== null) { - return null; - } + queue.baseState = newBaseState; + queue.firstUpdate = newFirstUpdate; + queue.firstCapturedUpdate = newFirstCapturedUpdate; + queue.expirationTime = newExpirationTime; - return updateFragment( - returnFiber, - oldFiber, - newChild, - expirationTime, - null - ); - } + workInProgress.memoizedState = resultState; - throwOnInvalidObjectType(returnFiber, newChild); + { + currentlyProcessingQueue = null; + } +} + +function callCallback(callback, context) { + invariant( + typeof callback === "function", + "Invalid argument passed as callback. Expected a function. Instead " + + "received: %s", + callback + ); + callback.call(context); +} + +function resetHasForceUpdateBeforeProcessing() { + hasForceUpdate = false; +} + +function checkHasForceUpdateAfterProcessing() { + return hasForceUpdate; +} + +function commitUpdateQueue( + finishedWork, + finishedQueue, + instance, + renderExpirationTime +) { + // If the finished render included captured updates, and there are still + // lower priority updates left over, we need to keep the captured updates + // in the queue so that they are rebased and not dropped once we process the + // queue again at the lower priority. + if (finishedQueue.firstCapturedUpdate !== null) { + // Join the captured update list to the end of the normal list. + if (finishedQueue.lastUpdate !== null) { + finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate; + finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate; } + // Clear the list of captured updates. + finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null; + } - { - if (typeof newChild === "function") { - warnOnFunctionType(); - } + // Commit the effects + var effect = finishedQueue.firstEffect; + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + while (effect !== null) { + var _callback3 = effect.callback; + if (_callback3 !== null) { + effect.callback = null; + callCallback(_callback3, instance); } + effect = effect.nextEffect; + } - return null; + effect = finishedQueue.firstCapturedEffect; + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; + while (effect !== null) { + var _callback4 = effect.callback; + if (_callback4 !== null) { + effect.callback = null; + callCallback(_callback4, instance); + } + effect = effect.nextEffect; } +} - function updateFromMap( - existingChildren, - returnFiber, - newIdx, - newChild, - expirationTime - ) { - if (typeof newChild === "string" || typeof newChild === "number") { - // Text nodes don't have keys, so we neither have to check the old nor - // new node for the key. If both are text nodes, they match. - var matchedFiber = existingChildren.get(newIdx) || null; - return updateTextNode( - returnFiber, - matchedFiber, - "" + newChild, - expirationTime - ); +function createCapturedValue(value, source) { + // If the value is an error, call this function immediately after it is thrown + // so the stack is accurate. + return { + value: value, + source: source, + stack: getStackAddendumByWorkInProgressFiber(source) + }; +} + +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; + + if (isPrimaryRenderer) { + 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 === undefined || + 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; + } + } else { + push(changedBitsCursor, context._changedBits2, providerFiber); + push(valueCursor, context._currentValue2, providerFiber); + push(providerCursor, providerFiber, providerFiber); + + context._currentValue2 = providerFiber.pendingProps.value; + context._changedBits2 = providerFiber.stateNode; + { + !( + context._currentRenderer2 === undefined || + context._currentRenderer2 === null || + context._currentRenderer2 === rendererSigil + ) + ? warning( + false, + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." + ) + : void 0; + context._currentRenderer2 = rendererSigil; } + } +} - if (typeof newChild === "object" && newChild !== null) { - switch (newChild.$$typeof) { - case REACT_ELEMENT_TYPE: { - var _matchedFiber = - existingChildren.get( - newChild.key === null ? newIdx : newChild.key - ) || null; - if (newChild.type === REACT_FRAGMENT_TYPE) { - return updateFragment( - returnFiber, - _matchedFiber, - newChild.props.children, - expirationTime, - newChild.key - ); - } - return updateElement( - returnFiber, - _matchedFiber, - newChild, - expirationTime - ); - } - case REACT_PORTAL_TYPE: { - var _matchedFiber2 = - existingChildren.get( - newChild.key === null ? newIdx : newChild.key - ) || null; - return updatePortal( - returnFiber, - _matchedFiber2, - newChild, - expirationTime - ); - } - } +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; + if (isPrimaryRenderer) { + context._currentValue = currentValue; + context._changedBits = changedBits; + } else { + context._currentValue2 = currentValue; + context._changedBits2 = changedBits; + } +} + +function getContextCurrentValue(context) { + return isPrimaryRenderer ? context._currentValue : context._currentValue2; +} + +function getContextChangedBits(context) { + return isPrimaryRenderer ? context._changedBits : context._changedBits2; +} + +var NO_CONTEXT = {}; + +var contextStackCursor$1 = createCursor(NO_CONTEXT); +var contextFiberStackCursor = createCursor(NO_CONTEXT); +var rootInstanceStackCursor = createCursor(NO_CONTEXT); + +function requiredContext(c) { + invariant( + c !== NO_CONTEXT, + "Expected host context to exist. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + return c; +} + +function getRootHostContainer() { + var rootInstance = requiredContext(rootInstanceStackCursor.current); + return rootInstance; +} + +function pushHostContainer(fiber, nextRootInstance) { + // Push current root instance onto the stack; + // This allows us to reset root when portals are popped. + push(rootInstanceStackCursor, nextRootInstance, fiber); + // Track the context and the Fiber that provided it. + // This enables us to pop only Fibers that provide unique contexts. + push(contextFiberStackCursor, fiber, fiber); + + // Finally, we need to push the host context to the stack. + // However, we can't just call getRootHostContext() and push it because + // we'd have a different number of entries on the stack depending on + // whether getRootHostContext() throws somewhere in renderer code or not. + // So we push an empty value first. This lets us safely unwind on errors. + push(contextStackCursor$1, NO_CONTEXT, fiber); + var nextRootContext = getRootHostContext(nextRootInstance); + // Now that we know this function doesn't throw, replace it. + pop(contextStackCursor$1, fiber); + push(contextStackCursor$1, nextRootContext, fiber); +} + +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} + +function getHostContext() { + var context = requiredContext(contextStackCursor$1.current); + return context; +} + +function pushHostContext(fiber) { + var rootInstance = requiredContext(rootInstanceStackCursor.current); + var context = requiredContext(contextStackCursor$1.current); + var nextContext = getChildHostContext(context, fiber.type, rootInstance); + + // Don't push this Fiber's context unless it's unique. + if (context === nextContext) { + return; + } + + // Track the context and the Fiber that provided it. + // This enables us to pop only Fibers that provide unique contexts. + push(contextFiberStackCursor, fiber, fiber); + push(contextStackCursor$1, nextContext, fiber); +} + +function popHostContext(fiber) { + // Do not pop unless this Fiber provided the current context. + // pushHostContext() only pushes Fibers that provide unique contexts. + if (contextFiberStackCursor.current !== fiber) { + return; + } + + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); +} + +var commitTime = 0; + +function getCommitTime() { + return commitTime; +} + +function recordCommitTime() { + if (!enableProfilerTimer) { + return; + } + commitTime = now(); +} + +/** + * The "actual" render time is total time required to render the descendants of a Profiler component. + * This time is stored as a stack, since Profilers can be nested. + * This time is started during the "begin" phase and stopped during the "complete" phase. + * It is paused (and accumulated) in the event of an interruption or an aborted render. + */ + +var fiberStack$1 = void 0; + +{ + fiberStack$1 = []; +} + +var timerPausedAt = 0; +var totalElapsedPauseTime = 0; + +function checkActualRenderTimeStackEmpty() { + if (!enableProfilerTimer) { + return; + } + { + !(fiberStack$1.length === 0) + ? warning( + false, + "Expected an empty stack. Something was not reset properly." + ) + : void 0; + } +} + +function markActualRenderTimeStarted(fiber) { + if (!enableProfilerTimer) { + return; + } + { + fiberStack$1.push(fiber); + } + + fiber.actualDuration = now() - fiber.actualDuration - totalElapsedPauseTime; + fiber.actualStartTime = now(); +} + +function pauseActualRenderTimerIfRunning() { + if (!enableProfilerTimer) { + return; + } + if (timerPausedAt === 0) { + timerPausedAt = now(); + } +} + +function recordElapsedActualRenderTime(fiber) { + if (!enableProfilerTimer) { + return; + } + { + !(fiber === fiberStack$1.pop()) + ? warning(false, "Unexpected Fiber (%s) popped.", getComponentName(fiber)) + : void 0; + } - if (isArray$1(newChild) || getIteratorFn(newChild)) { - var _matchedFiber3 = existingChildren.get(newIdx) || null; - return updateFragment( - returnFiber, - _matchedFiber3, - newChild, - expirationTime, - null - ); - } + fiber.actualDuration = now() - totalElapsedPauseTime - fiber.actualDuration; +} - throwOnInvalidObjectType(returnFiber, newChild); - } +function resetActualRenderTimer() { + if (!enableProfilerTimer) { + return; + } + totalElapsedPauseTime = 0; +} - { - if (typeof newChild === "function") { - warnOnFunctionType(); - } - } +function resumeActualRenderTimerIfPaused() { + if (!enableProfilerTimer) { + return; + } + if (timerPausedAt > 0) { + totalElapsedPauseTime += now() - timerPausedAt; + timerPausedAt = 0; + } +} - return null; +/** + * The "base" render time is the duration of the “begin” phase of work for a particular fiber. + * This time is measured and stored on each fiber. + * The time for all sibling fibers are accumulated and stored on their parent during the "complete" phase. + * If a fiber bails out (sCU false) then its "base" timer is cancelled and the fiber is not updated. + */ + +var baseStartTime = -1; + +function recordElapsedBaseRenderTimeIfRunning(fiber) { + if (!enableProfilerTimer) { + return; } + if (baseStartTime !== -1) { + fiber.selfBaseTime = now() - baseStartTime; + } +} - /** - * Warns if there is a duplicate or missing key - */ - function warnOnInvalidKey(child, knownKeys) { - { - if (typeof child !== "object" || child === null) { - return knownKeys; - } - switch (child.$$typeof) { - case REACT_ELEMENT_TYPE: - case REACT_PORTAL_TYPE: - warnForMissingKey(child); - var key = child.key; - if (typeof key !== "string") { - break; - } - if (knownKeys === null) { - knownKeys = new Set(); - knownKeys.add(key); - break; - } - if (!knownKeys.has(key)) { - knownKeys.add(key); - break; - } - warning( - false, - "Encountered two children with the same key, `%s`. " + - "Keys should be unique so that components maintain their identity " + - "across updates. Non-unique keys may cause children to be " + - "duplicated and/or omitted — the behavior is unsupported and " + - "could change in a future version.%s", - key, - getCurrentFiberStackAddendum$2() - ); - break; - default: - break; - } +function startBaseRenderTimer() { + if (!enableProfilerTimer) { + return; + } + { + if (baseStartTime !== -1) { + warning( + false, + "Cannot start base timer that is already running. " + + "This error is likely caused by a bug in React. " + + "Please file an issue." + ); } - return knownKeys; } + baseStartTime = now(); +} - function reconcileChildrenArray( - returnFiber, - currentFirstChild, - newChildren, - expirationTime - ) { - // This algorithm can't optimize by searching from boths ends since we - // don't have backpointers on fibers. I'm trying to see how far we can get - // with that model. If it ends up not being worth the tradeoffs, we can - // add it later. +function stopBaseRenderTimerIfRunning() { + if (!enableProfilerTimer) { + return; + } + baseStartTime = -1; +} - // Even with a two ended optimization, we'd want to optimize for the case - // where there are few changes and brute force the comparison instead of - // going for the Map. It'd like to explore hitting that path first in - // forward-only mode and only go for the Map once we notice that we need - // lots of look ahead. This doesn't handle reversal as well as two ended - // search but that's unusual. Besides, for the two ended optimization to - // work on Iterables, we'd need to copy the whole set. +/*eslint-disable no-self-compare */ - // In this first iteration, we'll just live with hitting the bad case - // (adding everything to a Map) in for every insert/move. +var hasOwnProperty = Object.prototype.hasOwnProperty; - // If you change this code, also update reconcileChildrenIterator() which - // uses the same algorithm. +/** + * inlined Object.is polyfill to avoid requiring consumers ship their own + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + */ +function is(x, y) { + // SameValue algorithm + if (x === y) { + // Steps 1-5, 7-10 + // Steps 6.b-6.e: +0 != -0 + // Added the nonzero y check to make Flow happy, but it is redundant + return x !== 0 || y !== 0 || 1 / x === 1 / y; + } else { + // Step 6.a: NaN == NaN + return x !== x && y !== y; + } +} - { - // First, validate keys. - var knownKeys = null; - for (var i = 0; i < newChildren.length; i++) { - var child = newChildren[i]; - knownKeys = warnOnInvalidKey(child, knownKeys); - } - } +/** + * Performs equality by iterating through keys on an object and returning false + * when any key has values which are not strictly equal between the arguments. + * Returns true when the values of all keys are strictly equal. + */ +function shallowEqual(objA, objB) { + if (is(objA, objB)) { + return true; + } - var resultingFirstChild = null; - var previousNewFiber = null; + if ( + typeof objA !== "object" || + objA === null || + typeof objB !== "object" || + objB === null + ) { + return false; + } - var oldFiber = currentFirstChild; - var lastPlacedIndex = 0; - var newIdx = 0; - var nextOldFiber = null; - for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) { - if (oldFiber.index > newIdx) { - nextOldFiber = oldFiber; - oldFiber = null; - } else { - nextOldFiber = oldFiber.sibling; - } - var newFiber = updateSlot( - returnFiber, - oldFiber, - newChildren[newIdx], - expirationTime - ); - if (newFiber === null) { - // TODO: This breaks on empty slots like null children. That's - // unfortunate because it triggers the slow path all the time. We need - // a better way to communicate whether this was a miss or null, - // boolean, undefined, etc. - if (oldFiber === null) { - oldFiber = nextOldFiber; - } - break; - } - if (shouldTrackSideEffects) { - if (oldFiber && newFiber.alternate === null) { - // We matched the slot, but we didn't reuse the existing fiber, so we - // need to delete the existing child. - deleteChild(returnFiber, oldFiber); - } - } - lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - // TODO: Move out of the loop. This only happens for the first run. - resultingFirstChild = newFiber; - } else { - // TODO: Defer siblings if we're not at the right index for this slot. - // I.e. if we had null values before, then we want to defer this - // for each null value. However, we also don't want to call updateSlot - // with the previous one. - previousNewFiber.sibling = newFiber; - } - previousNewFiber = newFiber; - oldFiber = nextOldFiber; + var keysA = Object.keys(objA); + var keysB = Object.keys(objB); + + if (keysA.length !== keysB.length) { + return false; + } + + // Test for A's keys different from B. + for (var i = 0; i < keysA.length; i++) { + if ( + !hasOwnProperty.call(objB, keysA[i]) || + !is(objA[keysA[i]], objB[keysA[i]]) + ) { + return false; } + } - if (newIdx === newChildren.length) { - // We've reached the end of the new children. We can delete the rest. - deleteRemainingChildren(returnFiber, oldFiber); - return resultingFirstChild; + return true; +} + +var fakeInternalInstance = {}; +var isArray = Array.isArray; + +var didWarnAboutStateAssignmentForComponent = void 0; +var didWarnAboutUninitializedState = void 0; +var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = void 0; +var didWarnAboutLegacyLifecyclesAndDerivedState = void 0; +var didWarnAboutUndefinedDerivedState = void 0; +var warnOnUndefinedDerivedState = void 0; +var warnOnInvalidCallback = void 0; + +{ + didWarnAboutStateAssignmentForComponent = new Set(); + didWarnAboutUninitializedState = new Set(); + didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); + didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); + didWarnAboutUndefinedDerivedState = new Set(); + + var didWarnOnInvalidCallback = new Set(); + + warnOnInvalidCallback = function(callback, callerName) { + if (callback === null || typeof callback === "function") { + return; + } + var key = callerName + "_" + callback; + if (!didWarnOnInvalidCallback.has(key)) { + didWarnOnInvalidCallback.add(key); + warning( + false, + "%s(...): Expected the last optional `callback` argument to be a " + + "function. Instead received: %s.", + callerName, + callback + ); } + }; - if (oldFiber === null) { - // If we don't have any more existing children we can choose a fast path - // since the rest will all be insertions. - for (; newIdx < newChildren.length; newIdx++) { - var _newFiber = createChild( - returnFiber, - newChildren[newIdx], - expirationTime + warnOnUndefinedDerivedState = function(workInProgress, partialState) { + if (partialState === undefined) { + var componentName = getComponentName(workInProgress) || "Component"; + if (!didWarnAboutUndefinedDerivedState.has(componentName)) { + didWarnAboutUndefinedDerivedState.add(componentName); + warning( + false, + "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + + "You have returned undefined.", + componentName ); - if (!_newFiber) { - continue; - } - lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - // TODO: Move out of the loop. This only happens for the first run. - resultingFirstChild = _newFiber; - } else { - previousNewFiber.sibling = _newFiber; - } - previousNewFiber = _newFiber; } - return resultingFirstChild; } + }; - // Add all children to a key map for quick lookups. - var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - - // Keep scanning and use the map to restore deleted items as moves. - for (; newIdx < newChildren.length; newIdx++) { - var _newFiber2 = updateFromMap( - existingChildren, - returnFiber, - newIdx, - newChildren[newIdx], - expirationTime + // This is so gross but it's at least non-critical and can be removed if + // it causes problems. This is meant to give a nicer error message for + // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component, + // ...)) which otherwise throws a "_processChildContext is not a function" + // exception. + Object.defineProperty(fakeInternalInstance, "_processChildContext", { + enumerable: false, + value: function() { + invariant( + false, + "_processChildContext is not available in React 16+. This likely " + + "means you have multiple copies of React and are attempting to nest " + + "a React 15 tree inside a React 16 tree using " + + "unstable_renderSubtreeIntoContainer, which isn't supported. Try " + + "to make sure you have only one copy of React (and ideally, switch " + + "to ReactDOM.createPortal)." ); - if (_newFiber2) { - if (shouldTrackSideEffects) { - if (_newFiber2.alternate !== null) { - // The new fiber is a work in progress, but if there exists a - // current, that means that we reused the fiber. We need to delete - // it from the child list so that we don't add it to the deletion - // list. - existingChildren.delete( - _newFiber2.key === null ? newIdx : _newFiber2.key - ); - } - } - lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - resultingFirstChild = _newFiber2; - } else { - previousNewFiber.sibling = _newFiber2; - } - previousNewFiber = _newFiber2; - } } + }); + Object.freeze(fakeInternalInstance); +} - if (shouldTrackSideEffects) { - // Any existing children that weren't consumed above were deleted. We need - // to add them to the deletion list. - existingChildren.forEach(function(child) { - return deleteChild(returnFiber, child); - }); - } +function applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + nextProps +) { + var prevState = workInProgress.memoizedState; - return resultingFirstChild; + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + // Invoke the function an extra time to help detect side-effects. + getDerivedStateFromProps(nextProps, prevState); + } } - function reconcileChildrenIterator( - returnFiber, - currentFirstChild, - newChildrenIterable, - expirationTime - ) { - // This is the same implementation as reconcileChildrenArray(), - // but using the iterator instead. + var partialState = getDerivedStateFromProps(nextProps, prevState); - var iteratorFn = getIteratorFn(newChildrenIterable); - invariant( - typeof iteratorFn === "function", - "An object is not an iterable. This error is likely caused by a bug in " + - "React. Please file an issue." - ); + { + warnOnUndefinedDerivedState(workInProgress, partialState); + } + // Merge the partial state and the previous state. + var memoizedState = + partialState === null || partialState === undefined + ? prevState + : Object.assign({}, prevState, partialState); + workInProgress.memoizedState = memoizedState; - { - // Warn about using Maps as children - 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$2() - ) - : void 0; - didWarnAboutMaps = true; - } - } + // Once the update queue is empty, persist the derived state onto the + // base state. + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null && updateQueue.expirationTime === NoWork) { + updateQueue.baseState = memoizedState; + } +} - // First, validate keys. - // We'll get a different iterator later for the main pass. - var _newChildren = iteratorFn.call(newChildrenIterable); - if (_newChildren) { - var knownKeys = null; - var _step = _newChildren.next(); - for (; !_step.done; _step = _newChildren.next()) { - var child = _step.value; - knownKeys = warnOnInvalidKey(child, knownKeys); - } +var classComponentUpdater = { + isMounted: isMounted, + enqueueSetState: function(inst, payload, callback) { + var fiber = get$1(inst); + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); + + var update = createUpdate(expirationTime); + update.payload = payload; + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "setState"); } + update.callback = callback; } - var newChildren = iteratorFn.call(newChildrenIterable); - invariant(newChildren != null, "An iterable object provided no iterator."); - - var resultingFirstChild = null; - var previousNewFiber = null; + enqueueUpdate(fiber, update, expirationTime); + scheduleWork(fiber, expirationTime); + }, + enqueueReplaceState: function(inst, payload, callback) { + var fiber = get$1(inst); + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); - var oldFiber = currentFirstChild; - var lastPlacedIndex = 0; - var newIdx = 0; - var nextOldFiber = null; + var update = createUpdate(expirationTime); + update.tag = ReplaceState; + update.payload = payload; - var step = newChildren.next(); - for ( - ; - oldFiber !== null && !step.done; - newIdx++, step = newChildren.next() - ) { - if (oldFiber.index > newIdx) { - nextOldFiber = oldFiber; - oldFiber = null; - } else { - nextOldFiber = oldFiber.sibling; - } - var newFiber = updateSlot( - returnFiber, - oldFiber, - step.value, - expirationTime - ); - if (newFiber === null) { - // TODO: This breaks on empty slots like null children. That's - // unfortunate because it triggers the slow path all the time. We need - // a better way to communicate whether this was a miss or null, - // boolean, undefined, etc. - if (!oldFiber) { - oldFiber = nextOldFiber; - } - break; - } - if (shouldTrackSideEffects) { - if (oldFiber && newFiber.alternate === null) { - // We matched the slot, but we didn't reuse the existing fiber, so we - // need to delete the existing child. - deleteChild(returnFiber, oldFiber); - } - } - lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - // TODO: Move out of the loop. This only happens for the first run. - resultingFirstChild = newFiber; - } else { - // TODO: Defer siblings if we're not at the right index for this slot. - // I.e. if we had null values before, then we want to defer this - // for each null value. However, we also don't want to call updateSlot - // with the previous one. - previousNewFiber.sibling = newFiber; + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "replaceState"); } - previousNewFiber = newFiber; - oldFiber = nextOldFiber; + update.callback = callback; } - if (step.done) { - // We've reached the end of the new children. We can delete the rest. - deleteRemainingChildren(returnFiber, oldFiber); - return resultingFirstChild; - } + enqueueUpdate(fiber, update, expirationTime); + scheduleWork(fiber, expirationTime); + }, + enqueueForceUpdate: function(inst, callback) { + var fiber = get$1(inst); + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); - if (oldFiber === null) { - // If we don't have any more existing children we can choose a fast path - // since the rest will all be insertions. - for (; !step.done; newIdx++, step = newChildren.next()) { - var _newFiber3 = createChild(returnFiber, step.value, expirationTime); - if (_newFiber3 === null) { - continue; - } - lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - // TODO: Move out of the loop. This only happens for the first run. - resultingFirstChild = _newFiber3; - } else { - previousNewFiber.sibling = _newFiber3; - } - previousNewFiber = _newFiber3; + var update = createUpdate(expirationTime); + update.tag = ForceUpdate; + + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "forceUpdate"); } - return resultingFirstChild; + update.callback = callback; } - // Add all children to a key map for quick lookups. - var existingChildren = mapRemainingChildren(returnFiber, oldFiber); + enqueueUpdate(fiber, update, expirationTime); + scheduleWork(fiber, expirationTime); + } +}; - // Keep scanning and use the map to restore deleted items as moves. - for (; !step.done; newIdx++, step = newChildren.next()) { - var _newFiber4 = updateFromMap( - existingChildren, - returnFiber, - newIdx, - step.value, - expirationTime - ); - if (_newFiber4 !== null) { - if (shouldTrackSideEffects) { - if (_newFiber4.alternate !== null) { - // The new fiber is a work in progress, but if there exists a - // current, that means that we reused the fiber. We need to delete - // it from the child list so that we don't add it to the deletion - // list. - existingChildren.delete( - _newFiber4.key === null ? newIdx : _newFiber4.key - ); - } - } - lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - resultingFirstChild = _newFiber4; - } else { - previousNewFiber.sibling = _newFiber4; - } - previousNewFiber = _newFiber4; - } - } +function checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext +) { + var instance = workInProgress.stateNode; + var ctor = workInProgress.type; + if (typeof instance.shouldComponentUpdate === "function") { + startPhaseTimer(workInProgress, "shouldComponentUpdate"); + var shouldUpdate = instance.shouldComponentUpdate( + newProps, + newState, + newContext + ); + stopPhaseTimer(); - if (shouldTrackSideEffects) { - // Any existing children that weren't consumed above were deleted. We need - // to add them to the deletion list. - existingChildren.forEach(function(child) { - return deleteChild(returnFiber, child); - }); + { + !(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; } - return resultingFirstChild; + return shouldUpdate; } - function reconcileSingleTextNode( - returnFiber, - currentFirstChild, - textContent, - expirationTime - ) { - // There's no need to check for keys on text nodes since we don't have a - // way to define them. - if (currentFirstChild !== null && currentFirstChild.tag === HostText) { - // We already have an existing node so let's just update it and delete - // the rest. - deleteRemainingChildren(returnFiber, currentFirstChild.sibling); - var existing = useFiber(currentFirstChild, textContent, expirationTime); - existing.return = returnFiber; - return existing; - } - // The existing first child is not a text node so we need to create one - // and delete the existing ones. - deleteRemainingChildren(returnFiber, currentFirstChild); - var created = createFiberFromText( - textContent, - returnFiber.mode, - expirationTime + if (ctor.prototype && ctor.prototype.isPureReactComponent) { + return ( + !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) ); - created.return = returnFiber; - return created; } - function reconcileSingleElement( - returnFiber, - currentFirstChild, - element, - expirationTime - ) { - var key = element.key; - var child = currentFirstChild; - while (child !== null) { - // TODO: If key === null and child.key === null, then this only applies to - // the first item in the list. - if (child.key === key) { - if ( - child.tag === Fragment - ? element.type === REACT_FRAGMENT_TYPE - : child.type === element.type - ) { - deleteRemainingChildren(returnFiber, child.sibling); - var existing = useFiber( - child, - element.type === REACT_FRAGMENT_TYPE - ? element.props.children - : element.props, - expirationTime - ); - existing.ref = coerceRef(returnFiber, child, element); - existing.return = returnFiber; - { - existing._debugSource = element._source; - existing._debugOwner = element._owner; - } - return existing; - } else { - deleteRemainingChildren(returnFiber, child); - break; - } + return true; +} + +function checkClassInstance(workInProgress) { + var instance = workInProgress.stateNode; + var type = workInProgress.type; + { + var name = getComponentName(workInProgress) || "Component"; + var renderPresent = instance.render; + + if (!renderPresent) { + if (type.prototype && typeof type.prototype.render === "function") { + warning( + false, + "%s(...): No `render` method found on the returned component " + + "instance: did you accidentally return an object from the constructor?", + name + ); } else { - deleteChild(returnFiber, child); + warning( + false, + "%s(...): No `render` method found on the returned component " + + "instance: you may have forgotten to define `render`.", + name + ); } - child = child.sibling; } - if (element.type === REACT_FRAGMENT_TYPE) { - var created = createFiberFromFragment( - element.props.children, - returnFiber.mode, - expirationTime, - element.key + var noGetInitialStateOnES6 = + !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; + 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; + 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; + 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; + 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; + if ( + type.prototype && + type.prototype.isPureReactComponent && + typeof instance.shouldComponentUpdate !== "undefined" + ) { + warning( + false, + "%s has a method called shouldComponentUpdate(). " + + "shouldComponentUpdate should not be used when extending React.PureComponent. " + + "Please extend React.Component if shouldComponentUpdate is used.", + getComponentName(workInProgress) || "A pure component" ); - created.return = returnFiber; - return created; - } else { - var _created4 = createFiberFromElement( - element, - returnFiber.mode, - expirationTime + } + 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; + 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; + var noComponentWillRecieveProps = + typeof instance.componentWillRecieveProps !== "function"; + !noComponentWillRecieveProps + ? warning( + false, + "%s has a method called " + + "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", + name + ) + : void 0; + 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; + 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; + 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; + + if ( + typeof instance.getSnapshotBeforeUpdate === "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) ); - _created4.ref = coerceRef(returnFiber, currentFirstChild, element); - _created4.return = returnFiber; - return _created4; + } + + 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; } } +} - function reconcileSinglePortal( - returnFiber, - currentFirstChild, - portal, - expirationTime - ) { - var key = portal.key; - var child = currentFirstChild; - while (child !== null) { - // TODO: If key === null and child.key === null, then this only applies to - // the first item in the list. - if (child.key === key) { - if ( - child.tag === HostPortal && - child.stateNode.containerInfo === portal.containerInfo && - child.stateNode.implementation === portal.implementation - ) { - deleteRemainingChildren(returnFiber, child.sibling); - var existing = useFiber(child, portal.children || [], expirationTime); - existing.return = returnFiber; - return existing; - } else { - deleteRemainingChildren(returnFiber, child); - break; +function adoptClassInstance(workInProgress, instance) { + instance.updater = classComponentUpdater; + workInProgress.stateNode = instance; + // The instance needs access to the fiber so that it can schedule updates + set(instance, workInProgress); + { + instance._reactInternalInstance = fakeInternalInstance; + } +} + +function constructClassInstance(workInProgress, props, renderExpirationTime) { + var ctor = workInProgress.type; + var unmaskedContext = getUnmaskedContext(workInProgress); + var needsContext = isContextConsumer(workInProgress); + var context = needsContext + ? getMaskedContext(workInProgress, unmaskedContext) + : emptyObject; + + // Instantiate twice to help detect side-effects. + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + new ctor(props, context); // eslint-disable-line no-new + } + } + + var instance = new ctor(props, context); + var state = (workInProgress.memoizedState = + instance.state !== null && instance.state !== undefined + ? instance.state + : null); + adoptClassInstance(workInProgress, instance); + + { + if (typeof ctor.getDerivedStateFromProps === "function" && state === null) { + var componentName = getComponentName(workInProgress) || "Component"; + if (!didWarnAboutUninitializedState.has(componentName)) { + didWarnAboutUninitializedState.add(componentName); + warning( + false, + "%s: Did not properly initialize state during construction. " + + "Expected state to be an object, but it was %s.", + 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 : "" + ); } - } else { - deleteChild(returnFiber, child); } - child = child.sibling; } + } - var created = createFiberFromPortal( - portal, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; + // Cache unmasked context so we can avoid recreating masked context unless necessary. + // ReactFiberContext usually updates this cache but can't for newly-created instances. + if (needsContext) { + cacheContext(workInProgress, unmaskedContext, context); + } + + return instance; +} + +function callComponentWillMount(workInProgress, instance) { + startPhaseTimer(workInProgress, "componentWillMount"); + var oldState = instance.state; + + if (typeof instance.componentWillMount === "function") { + instance.componentWillMount(); + } + if (typeof instance.UNSAFE_componentWillMount === "function") { + instance.UNSAFE_componentWillMount(); } - // This API will tag the children with the side-effect of the reconciliation - // itself. They will be added to the side-effect list as we pass through the - // children and the parent. - function reconcileChildFibers( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ) { - // This function is not recursive. - // If the top level item is an array, we treat it as a set of children, - // not as a fragment. Nested arrays on the other hand will be treated as - // fragment nodes. Recursion happens at the normal flow. + stopPhaseTimer(); - // Handle top level unkeyed fragments as if they were arrays. - // This leads to an ambiguity between <>{[...]} and <>.... - // We treat the ambiguous cases above the same. - if ( - typeof newChild === "object" && - newChild !== null && - newChild.type === REACT_FRAGMENT_TYPE && - newChild.key === null - ) { - newChild = newChild.props.children; + if (oldState !== instance.state) { + { + warning( + false, + "%s.componentWillMount(): Assigning directly to this.state is " + + "deprecated (except inside a component's " + + "constructor). Use setState instead.", + getComponentName(workInProgress) || "Component" + ); } + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); + } +} - // Handle object types - var isObject = typeof newChild === "object" && newChild !== null; +function callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext +) { + var oldState = instance.state; + startPhaseTimer(workInProgress, "componentWillReceiveProps"); + if (typeof instance.componentWillReceiveProps === "function") { + instance.componentWillReceiveProps(newProps, newContext); + } + if (typeof instance.UNSAFE_componentWillReceiveProps === "function") { + instance.UNSAFE_componentWillReceiveProps(newProps, newContext); + } + stopPhaseTimer(); - if (isObject) { - switch (newChild.$$typeof) { - case REACT_ELEMENT_TYPE: - return placeSingleChild( - reconcileSingleElement( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ) - ); - case REACT_PORTAL_TYPE: - return placeSingleChild( - reconcileSinglePortal( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ) - ); + if (instance.state !== oldState) { + { + var componentName = getComponentName(workInProgress) || "Component"; + if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { + didWarnAboutStateAssignmentForComponent.add(componentName); + warning( + false, + "%s.componentWillReceiveProps(): Assigning directly to " + + "this.state is deprecated (except inside a component's " + + "constructor). Use setState instead.", + componentName + ); } } + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); + } +} - if (typeof newChild === "string" || typeof newChild === "number") { - return placeSingleChild( - reconcileSingleTextNode( - returnFiber, - currentFirstChild, - "" + newChild, - expirationTime - ) +// Invokes the mount life-cycles on a previously never rendered instance. +function mountClassInstance(workInProgress, renderExpirationTime) { + var ctor = workInProgress.type; + + { + checkClassInstance(workInProgress); + } + + var instance = workInProgress.stateNode; + var props = workInProgress.pendingProps; + var unmaskedContext = getUnmaskedContext(workInProgress); + + instance.props = props; + instance.state = workInProgress.memoizedState; + instance.refs = emptyObject; + instance.context = getMaskedContext(workInProgress, unmaskedContext); + + { + if (workInProgress.mode & StrictMode) { + ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( + workInProgress, + instance ); - } - if (isArray$1(newChild)) { - return reconcileChildrenArray( - returnFiber, - currentFirstChild, - newChild, - expirationTime + ReactStrictModeWarnings.recordLegacyContextWarning( + workInProgress, + instance ); } - if (getIteratorFn(newChild)) { - return reconcileChildrenIterator( - returnFiber, - currentFirstChild, - newChild, - expirationTime + if (warnAboutDeprecatedLifecycles) { + ReactStrictModeWarnings.recordDeprecationWarnings( + workInProgress, + instance ); } + } - if (isObject) { - throwOnInvalidObjectType(returnFiber, newChild); - } + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + props, + instance, + renderExpirationTime + ); + instance.state = workInProgress.memoizedState; + } - { - if (typeof newChild === "function") { - warnOnFunctionType(); - } - } - if (typeof newChild === "undefined") { - // If the new child is undefined, and the return fiber is a composite - // component, throw an error. If Fiber return types are disabled, - // we already threw above. - switch (returnFiber.tag) { - case ClassComponent: { - { - var instance = returnFiber.stateNode; - if (instance.render._isMockFunction) { - // We allow auto-mocks to proceed as if they're returning null. - break; - } - } - } - // Intentionally fall through to the next case, which handles both - // functions and classes - // eslint-disable-next-lined no-fallthrough - case FunctionalComponent: { - var Component = returnFiber.type; - invariant( - false, - "%s(...): Nothing was returned from render. This usually means a " + - "return statement is missing. Or, to render nothing, " + - "return null.", - Component.displayName || Component.name || "Component" - ); - } - } - } + var getDerivedStateFromProps = workInProgress.type.getDerivedStateFromProps; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps(workInProgress, getDerivedStateFromProps, props); + instance.state = workInProgress.memoizedState; + } - // Remaining cases are all treated as empty. - return deleteRemainingChildren(returnFiber, currentFirstChild); + // In order to support react-lifecycles-compat polyfilled components, + // Unsafe lifecycles should not be invoked for components using the new APIs. + if ( + typeof ctor.getDerivedStateFromProps !== "function" && + typeof instance.getSnapshotBeforeUpdate !== "function" && + (typeof instance.UNSAFE_componentWillMount === "function" || + typeof instance.componentWillMount === "function") + ) { + callComponentWillMount(workInProgress, instance); + // If we had additional state updates during this life-cycle, let's + // process them now. + updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + props, + instance, + renderExpirationTime + ); + instance.state = workInProgress.memoizedState; + } } - return reconcileChildFibers; + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; + } } -var reconcileChildFibers = ChildReconciler(true); -var mountChildFibers = ChildReconciler(false); +function resumeMountClassInstance(workInProgress, renderExpirationTime) { + var ctor = workInProgress.type; + var instance = workInProgress.stateNode; -function cloneChildFibers(current, workInProgress) { - invariant( - current === null || workInProgress.child === current.child, - "Resuming work not yet implemented." - ); + var oldProps = workInProgress.memoizedProps; + var newProps = workInProgress.pendingProps; + instance.props = oldProps; - if (workInProgress.child === null) { - return; - } + var oldContext = instance.context; + var newUnmaskedContext = getUnmaskedContext(workInProgress); + var newContext = getMaskedContext(workInProgress, newUnmaskedContext); - var currentChild = workInProgress.child; - var newChild = createWorkInProgress( - currentChild, - currentChild.pendingProps, - currentChild.expirationTime - ); - workInProgress.child = newChild; + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + var hasNewLifecycles = + typeof getDerivedStateFromProps === "function" || + typeof instance.getSnapshotBeforeUpdate === "function"; - newChild.return = workInProgress; - while (currentChild.sibling !== null) { - currentChild = currentChild.sibling; - newChild = newChild.sibling = createWorkInProgress( - currentChild, - currentChild.pendingProps, - currentChild.expirationTime - ); - newChild.return = workInProgress; + // 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. + if ( + !hasNewLifecycles && + (typeof instance.UNSAFE_componentWillReceiveProps === "function" || + typeof instance.componentWillReceiveProps === "function") + ) { + if (oldProps !== newProps || oldContext !== newContext) { + callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext + ); + } } - newChild.sibling = null; -} -var getCurrentFiberStackAddendum = - ReactDebugCurrentFiber.getCurrentFiberStackAddendum; + resetHasForceUpdateBeforeProcessing(); -var didWarnAboutBadClass = void 0; -var didWarnAboutGetDerivedStateOnFunctionalComponent = void 0; -var didWarnAboutStatelessRefs = void 0; + var oldState = workInProgress.memoizedState; + var newState = (instance.state = oldState); + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + newProps, + instance, + renderExpirationTime + ); + newState = workInProgress.memoizedState; + } + if ( + oldProps === newProps && + oldState === newState && + !hasContextChanged() && + !checkHasForceUpdateAfterProcessing() + ) { + // 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. + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; + } + return false; + } -{ - didWarnAboutBadClass = {}; - didWarnAboutGetDerivedStateOnFunctionalComponent = {}; - didWarnAboutStatelessRefs = {}; -} + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + newProps + ); + newState = workInProgress.memoizedState; + } -var ReactFiberBeginWork = function( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - scheduleWork, - computeExpirationForFiber, - profilerTimer, - recalculateCurrentTime -) { - var shouldSetTextContent = config.shouldSetTextContent, - shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree; - var pushHostContext = hostContext.pushHostContext, - pushHostContainer = hostContext.pushHostContainer; - var pushProvider = newContext.pushProvider, - getContextCurrentValue = newContext.getContextCurrentValue, - getContextChangedBits = newContext.getContextChangedBits; - var markActualRenderTimeStarted = profilerTimer.markActualRenderTimeStarted, - stopBaseRenderTimerIfRunning = profilerTimer.stopBaseRenderTimerIfRunning; - 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, - memoizeState, - recalculateCurrentTime - ), - adoptClassInstance = _ReactFiberClassCompo.adoptClassInstance, - constructClassInstance = _ReactFiberClassCompo.constructClassInstance, - mountClassInstance = _ReactFiberClassCompo.mountClassInstance, - resumeMountClassInstance = _ReactFiberClassCompo.resumeMountClassInstance, - updateClassInstance = _ReactFiberClassCompo.updateClassInstance; - - // TODO: Remove this and use reconcileChildrenAtExpirationTime directly. - - function reconcileChildren(current, workInProgress, nextChildren) { - reconcileChildrenAtExpirationTime( - current, + var shouldUpdate = + checkHasForceUpdateAfterProcessing() || + checkShouldComponentUpdate( workInProgress, - nextChildren, - workInProgress.expirationTime + oldProps, + newProps, + oldState, + newState, + newContext ); + + if (shouldUpdate) { + // In order to support react-lifecycles-compat polyfilled components, + // Unsafe lifecycles should not be invoked for components using the new APIs. + if ( + !hasNewLifecycles && + (typeof instance.UNSAFE_componentWillMount === "function" || + typeof instance.componentWillMount === "function") + ) { + startPhaseTimer(workInProgress, "componentWillMount"); + if (typeof instance.componentWillMount === "function") { + instance.componentWillMount(); + } + if (typeof instance.UNSAFE_componentWillMount === "function") { + instance.UNSAFE_componentWillMount(); + } + stopPhaseTimer(); + } + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; + } + } 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. + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; + } + + // If shouldComponentUpdate returned false, we should still update the + // memoized state to indicate that this work can be reused. + workInProgress.memoizedProps = newProps; + workInProgress.memoizedState = newState; } - function reconcileChildrenAtExpirationTime( - current, - workInProgress, - nextChildren, - renderExpirationTime - ) { - if (current === null) { - // If this is a fresh new component that hasn't been rendered yet, we - // won't update its child set by applying minimal side-effects. Instead, - // we will add them all to the child before it gets rendered. That means - // we can optimize this reconciliation pass by not tracking side-effects. - workInProgress.child = mountChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime - ); - } else { - // If the current child is the same as the work in progress, it means that - // we haven't yet started any work on these children. Therefore, we use - // the clone algorithm to create a copy of all the current children. + // Update the existing instance's state, props, and context pointers even + // if shouldComponentUpdate returns false. + instance.props = newProps; + instance.state = newState; + instance.context = newContext; + + return shouldUpdate; +} - // If we had any progressed work already, that is invalid at this point so - // let's throw it out. - workInProgress.child = reconcileChildFibers( +// Invokes the update life-cycles and returns false if it shouldn't rerender. +function updateClassInstance(current, workInProgress, renderExpirationTime) { + var ctor = workInProgress.type; + var instance = workInProgress.stateNode; + + var oldProps = workInProgress.memoizedProps; + var newProps = workInProgress.pendingProps; + instance.props = oldProps; + + var oldContext = instance.context; + var newUnmaskedContext = getUnmaskedContext(workInProgress); + var newContext = getMaskedContext(workInProgress, newUnmaskedContext); + + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + var hasNewLifecycles = + typeof 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. + if ( + !hasNewLifecycles && + (typeof instance.UNSAFE_componentWillReceiveProps === "function" || + typeof instance.componentWillReceiveProps === "function") + ) { + if (oldProps !== newProps || oldContext !== newContext) { + callComponentWillReceiveProps( workInProgress, - current.child, - nextChildren, - renderExpirationTime + instance, + newProps, + newContext ); } } - function updateForwardRef(current, workInProgress) { - var render = workInProgress.type.render; - var nextProps = workInProgress.pendingProps; - var ref = workInProgress.ref; - if (hasLegacyContextChanged()) { - // 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) { - var currentRef = current !== null ? current.ref : null; - if (ref === currentRef) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - } - - var nextChildren = void 0; - { - ReactCurrentOwner.current = workInProgress; - ReactDebugCurrentFiber.setCurrentPhase("render"); - nextChildren = render(nextProps, ref); - ReactDebugCurrentFiber.setCurrentPhase(null); - } + resetHasForceUpdateBeforeProcessing(); - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextProps); - return workInProgress.child; + var oldState = workInProgress.memoizedState; + var newState = (instance.state = oldState); + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + newProps, + instance, + renderExpirationTime + ); + newState = workInProgress.memoizedState; } - function updateFragment(current, workInProgress) { - var nextChildren = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { - // 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) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); + if ( + oldProps === newProps && + oldState === newState && + !hasContextChanged() && + !checkHasForceUpdateAfterProcessing() + ) { + // 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. + if (typeof instance.componentDidUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + workInProgress.effectTag |= Update; + } } - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextChildren); - return workInProgress.child; + if (typeof instance.getSnapshotBeforeUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + workInProgress.effectTag |= Snapshot; + } + } + return false; } - function updateMode(current, workInProgress) { - var nextChildren = workInProgress.pendingProps.children; - if (hasLegacyContextChanged()) { - // 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 ( - nextChildren === null || - workInProgress.memoizedProps === nextChildren - ) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextChildren); - return workInProgress.child; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + newProps + ); + newState = workInProgress.memoizedState; } - function updateProfiler(current, workInProgress) { - var nextProps = workInProgress.pendingProps; - if (enableProfilerTimer) { - // Start render timer here and push start time onto queue - markActualRenderTimeStarted(workInProgress); + var shouldUpdate = + checkHasForceUpdateAfterProcessing() || + checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext + ); - // Let the "complete" phase know to stop the timer, - // And the scheduler to record the measured time. + if (shouldUpdate) { + // In order to support react-lifecycles-compat polyfilled components, + // Unsafe lifecycles should not be invoked for components using the new APIs. + if ( + !hasNewLifecycles && + (typeof instance.UNSAFE_componentWillUpdate === "function" || + typeof instance.componentWillUpdate === "function") + ) { + startPhaseTimer(workInProgress, "componentWillUpdate"); + if (typeof instance.componentWillUpdate === "function") { + instance.componentWillUpdate(newProps, newState, newContext); + } + if (typeof instance.UNSAFE_componentWillUpdate === "function") { + instance.UNSAFE_componentWillUpdate(newProps, newState, newContext); + } + stopPhaseTimer(); + } + if (typeof instance.componentDidUpdate === "function") { workInProgress.effectTag |= Update; } - if (workInProgress.memoizedProps === nextProps) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); + if (typeof instance.getSnapshotBeforeUpdate === "function") { + workInProgress.effectTag |= Snapshot; } - var nextChildren = nextProps.children; - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextProps); - return workInProgress.child; - } - - function markRef(current, workInProgress) { - var ref = workInProgress.ref; - if ( - (current === null && ref !== null) || - (current !== null && current.ref !== ref) - ) { - // Schedule a Ref effect - workInProgress.effectTag |= Ref; + } 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. + if (typeof instance.componentDidUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + 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. + workInProgress.memoizedProps = newProps; + workInProgress.memoizedState = newState; } - function updateFunctionalComponent(current, workInProgress) { - var fn = workInProgress.type; - var nextProps = workInProgress.pendingProps; + // Update the existing instance's state, props, and context pointers even + // if shouldComponentUpdate returns false. + instance.props = newProps; + instance.state = newState; + instance.context = newContext; - if (hasLegacyContextChanged()) { - // 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) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - // TODO: consider bringing fn.shouldComponentUpdate() back. - // It used to be here. + return shouldUpdate; +} + +var getCurrentFiberStackAddendum$2 = + ReactDebugCurrentFiber.getCurrentFiberStackAddendum; + +var didWarnAboutMaps = void 0; +var didWarnAboutStringRefInStrictMode = void 0; +var ownerHasKeyUseWarning = void 0; +var ownerHasFunctionTypeWarning = void 0; +var warnForMissingKey = function(child) {}; + +{ + didWarnAboutMaps = false; + didWarnAboutStringRefInStrictMode = {}; + + /** + * Warn if there's no key explicitly set on dynamic arrays of children or + * object keys are not valid. This allows us to keep track of children between + * updates. + */ + ownerHasKeyUseWarning = {}; + ownerHasFunctionTypeWarning = {}; + + warnForMissingKey = function(child) { + if (child === null || typeof child !== "object") { + return; + } + if (!child._store || child._store.validated || child.key != null) { + return; + } + invariant( + typeof child._store === "object", + "React Component in warnForMissingKey should have a _store. " + + "This error is likely caused by a bug in React. Please file an issue." + ); + child._store.validated = true; + + var currentComponentErrorInfo = + "Each child in an array or iterator should have a unique " + + '"key" prop. See https://fb.me/react-warning-keys for ' + + "more information." + + (getCurrentFiberStackAddendum$2() || ""); + if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { + return; } + ownerHasKeyUseWarning[currentComponentErrorInfo] = true; - var unmaskedContext = getUnmaskedContext(workInProgress); - var context = getMaskedContext(workInProgress, unmaskedContext); + warning( + false, + "Each child in an array or iterator should have a unique " + + '"key" prop. See https://fb.me/react-warning-keys for ' + + "more information.%s", + getCurrentFiberStackAddendum$2() + ); + }; +} - var nextChildren = void 0; +var isArray$1 = Array.isArray; +function coerceRef(returnFiber, current, element) { + var mixedRef = element.ref; + if ( + mixedRef !== null && + typeof mixedRef !== "function" && + typeof mixedRef !== "object" + ) { { - ReactCurrentOwner.current = workInProgress; - ReactDebugCurrentFiber.setCurrentPhase("render"); - nextChildren = fn(nextProps, context); - ReactDebugCurrentFiber.setCurrentPhase(null); + if (returnFiber.mode & StrictMode) { + var componentName = getComponentName(returnFiber) || "Component"; + if (!didWarnAboutStringRefInStrictMode[componentName]) { + warning( + false, + 'A string ref, "%s", has been found within a strict mode tree. ' + + "String refs are a source of potential bugs and should be avoided. " + + "We recommend using createRef() instead." + + "\n%s" + + "\n\nLearn more about using refs safely here:" + + "\nhttps://fb.me/react-strict-mode-string-ref", + mixedRef, + getStackAddendumByWorkInProgressFiber(returnFiber) + ); + didWarnAboutStringRefInStrictMode[componentName] = true; + } + } } - // React DevTools reads this flag. - workInProgress.effectTag |= PerformedWork; - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextProps); - return workInProgress.child; - } - - function updateClassComponent(current, workInProgress, renderExpirationTime) { - // 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 shouldUpdate = void 0; - if (current === null) { - if (workInProgress.stateNode === null) { - // In the initial pass we might need to construct the instance. - constructClassInstance( - workInProgress, - workInProgress.pendingProps, - renderExpirationTime - ); - mountClassInstance(workInProgress, renderExpirationTime); - shouldUpdate = true; - } else { - // In a resume, we'll already have an instance we can reuse. - shouldUpdate = resumeMountClassInstance( - workInProgress, - renderExpirationTime + if (element._owner) { + var owner = element._owner; + var inst = void 0; + if (owner) { + var ownerFiber = owner; + invariant( + ownerFiber.tag === ClassComponent, + "Stateless function components cannot have refs." ); + inst = ownerFiber.stateNode; + } + invariant( + inst, + "Missing owner for string ref %s. This error is likely caused by a " + + "bug in React. Please file an issue.", + mixedRef + ); + var stringRef = "" + mixedRef; + // Check if previous string ref matches new string ref + if ( + current !== null && + current.ref !== null && + typeof current.ref === "function" && + current.ref._stringRef === stringRef + ) { + return current.ref; } + var ref = function(value) { + var refs = inst.refs === emptyObject ? (inst.refs = {}) : inst.refs; + if (value === null) { + delete refs[stringRef]; + } else { + refs[stringRef] = value; + } + }; + ref._stringRef = stringRef; + return ref; } else { - shouldUpdate = updateClassInstance( - current, - workInProgress, - renderExpirationTime + invariant( + typeof mixedRef === "string", + "Expected ref to be a function or a string." + ); + invariant( + element._owner, + "Element ref was specified as a string (%s) but no owner was set. This could happen for one of" + + " the following reasons:\n" + + "1. You may be adding a ref to a functional component\n" + + "2. You may be adding a ref to a component that was not created inside a component's render method\n" + + "3. You have multiple copies of React loaded\n" + + "See https://fb.me/react-refs-must-have-owner for more information.", + mixedRef ); } - return finishClassComponent( - current, - workInProgress, - shouldUpdate, - hasContext, - renderExpirationTime + } + return mixedRef; +} + +function throwOnInvalidObjectType(returnFiber, newChild) { + if (returnFiber.type !== "textarea") { + var addendum = ""; + { + addendum = + " If you meant to render a collection of children, use an array " + + "instead." + + (getCurrentFiberStackAddendum$2() || ""); + } + invariant( + false, + "Objects are not valid as a React child (found: %s).%s", + Object.prototype.toString.call(newChild) === "[object Object]" + ? "object with keys {" + Object.keys(newChild).join(", ") + "}" + : newChild, + addendum ); } +} - function finishClassComponent( - current, - workInProgress, - shouldUpdate, - hasContext, - renderExpirationTime - ) { - // Refs should update even if shouldComponentUpdate returns false - markRef(current, workInProgress); +function warnOnFunctionType() { + var currentComponentErrorInfo = + "Functions are not valid as a React child. This may happen if " + + "you return a Component instead of from render. " + + "Or maybe you meant to call this function rather than return it." + + (getCurrentFiberStackAddendum$2() || ""); - var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect; + if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) { + return; + } + ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; - if (!shouldUpdate && !didCaptureError) { - // Context providers should defer to sCU for rendering - if (hasContext) { - invalidateContextProvider(workInProgress, false); - } + warning( + false, + "Functions are not valid as a React child. This may happen if " + + "you return a Component instead of from render. " + + "Or maybe you meant to call this function rather than return it.%s", + getCurrentFiberStackAddendum$2() || "" + ); +} - return bailoutOnAlreadyFinishedWork(current, workInProgress); +// This wrapper function exists because I expect to clone the code in each path +// to be able to optimize each path individually by branching early. This needs +// a compiler or we can do it manually. Helpers that don't need this branching +// live outside of this function. +function ChildReconciler(shouldTrackSideEffects) { + function deleteChild(returnFiber, childToDelete) { + if (!shouldTrackSideEffects) { + // Noop. + return; } - - var ctor = workInProgress.type; - var instance = workInProgress.stateNode; - - // Rerender - ReactCurrentOwner.current = workInProgress; - var nextChildren = void 0; - if ( - didCaptureError && - (!enableGetDerivedStateFromCatch || - typeof ctor.getDerivedStateFromCatch !== "function") - ) { - // If we captured an error, but getDerivedStateFrom catch is not defined, - // unmount all the children. componentDidCatch will schedule an update to - // re-render a fallback. This is temporary until we migrate everyone to - // the new API. - // TODO: Warn in a future release. - nextChildren = null; - - if (enableProfilerTimer) { - stopBaseRenderTimerIfRunning(); - } + // Deletions are added in reversed order so we add it to the front. + // At this point, the return fiber's effect list is empty except for + // deletions, so we can just append the deletion to the list. The remaining + // effects aren't added until the complete phase. Once we implement + // resuming, this may not be true. + var last = returnFiber.lastEffect; + if (last !== null) { + last.nextEffect = childToDelete; + returnFiber.lastEffect = childToDelete; } else { - { - ReactDebugCurrentFiber.setCurrentPhase("render"); - nextChildren = instance.render(); - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - instance.render(); - } - ReactDebugCurrentFiber.setCurrentPhase(null); - } - } - - // React DevTools reads this flag. - workInProgress.effectTag |= PerformedWork; - if (didCaptureError) { - // If we're recovering from an error, reconcile twice: first to delete - // all the existing children. - reconcileChildrenAtExpirationTime( - current, - workInProgress, - null, - renderExpirationTime - ); - workInProgress.child = null; - // Now we can continue reconciling like normal. This has the effect of - // remounting all children regardless of whether their their - // identity matches. + returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; } - reconcileChildrenAtExpirationTime( - current, - workInProgress, - nextChildren, - renderExpirationTime - ); - // Memoize props and state using the values we just used to render. - // TODO: Restructure so we never read values from the instance. - memoizeState(workInProgress, instance.state); - memoizeProps(workInProgress, instance.props); + childToDelete.nextEffect = null; + childToDelete.effectTag = Deletion; + } - // The context might have changed so we need to recalculate it. - if (hasContext) { - invalidateContextProvider(workInProgress, true); + function deleteRemainingChildren(returnFiber, currentFirstChild) { + if (!shouldTrackSideEffects) { + // Noop. + return null; } - return workInProgress.child; - } - - function pushHostRootContext(workInProgress) { - var root = workInProgress.stateNode; - if (root.pendingContext) { - pushTopLevelContextObject( - workInProgress, - root.pendingContext, - root.pendingContext !== root.context - ); - } else if (root.context) { - // Should always be set - pushTopLevelContextObject(workInProgress, root.context, false); + // TODO: For the shouldClone case, this could be micro-optimized a bit by + // assuming that after the first child we've already added everything. + var childToDelete = currentFirstChild; + while (childToDelete !== null) { + deleteChild(returnFiber, childToDelete); + childToDelete = childToDelete.sibling; } - pushHostContainer(workInProgress, root.containerInfo); + return null; } - function updateHostRoot(current, workInProgress, renderExpirationTime) { - pushHostRootContext(workInProgress); - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - var nextProps = workInProgress.pendingProps; - var prevState = workInProgress.memoizedState; - var prevChildren = prevState !== null ? prevState.element : null; - processUpdateQueue( - workInProgress, - updateQueue, - nextProps, - null, - renderExpirationTime - ); - var nextState = workInProgress.memoizedState; - // Caution: React DevTools currently depends on this property - // being called "element". - var nextChildren = nextState.element; - - if (nextChildren === prevChildren) { - // If the state is the same as before, that's a bailout because we had - // no work that expires at this time. - resetHydrationState(); - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - var root = workInProgress.stateNode; - if ( - (current === null || current.child === null) && - root.hydrate && - enterHydrationState(workInProgress) - ) { - // If we don't have any current children this might be the first pass. - // We always try to hydrate. If this isn't a hydration pass there won't - // be any children to hydrate which is effectively the same thing as - // not hydrating. - - // This is a bit of a hack. We track the host root as a placement to - // know that we're currently in a mounting state. That way isMounted - // works as expected. We must reset this before committing. - // TODO: Delete this when we delete isMounted and findDOMNode. - workInProgress.effectTag |= Placement; + function mapRemainingChildren(returnFiber, currentFirstChild) { + // Add the remaining children to a temporary map so that we can find them by + // keys quickly. Implicit (null) keys get added to this set with their index + var existingChildren = new Map(); - // Ensure that children mount into this root without tracking - // side-effects. This ensures that we don't store Placement effects on - // nodes that will be hydrated. - workInProgress.child = mountChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime - ); + var existingChild = currentFirstChild; + while (existingChild !== null) { + if (existingChild.key !== null) { + existingChildren.set(existingChild.key, existingChild); } else { - // Otherwise reset hydration state in case we aborted and resumed another - // root. - resetHydrationState(); - reconcileChildren(current, workInProgress, nextChildren); + existingChildren.set(existingChild.index, existingChild); } - return workInProgress.child; + existingChild = existingChild.sibling; } - resetHydrationState(); - // If there is no update queue, that's a bailout because the root has no props. - return bailoutOnAlreadyFinishedWork(current, workInProgress); + return existingChildren; } - function updateHostComponent(current, workInProgress, renderExpirationTime) { - pushHostContext(workInProgress); + function useFiber(fiber, pendingProps, expirationTime) { + // We currently set sibling to null and index to 0 here because it is easy + // to forget to do before returning it. E.g. for the single child case. + var clone = createWorkInProgress(fiber, pendingProps, expirationTime); + clone.index = 0; + clone.sibling = null; + return clone; + } - if (current === null) { - tryToClaimNextHydratableInstance(workInProgress); + function placeChild(newFiber, lastPlacedIndex, newIndex) { + newFiber.index = newIndex; + if (!shouldTrackSideEffects) { + // Noop. + return lastPlacedIndex; } - - var type = workInProgress.type; - var memoizedProps = workInProgress.memoizedProps; - var nextProps = workInProgress.pendingProps; - var prevProps = current !== null ? current.memoizedProps : null; - - if (hasLegacyContextChanged()) { - // 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) { - var isHidden = - workInProgress.mode & AsyncMode && - shouldDeprioritizeSubtree(type, nextProps); - if (isHidden) { - // Before bailing out, make sure we've deprioritized a hidden component. - workInProgress.expirationTime = Never; - } - if (!isHidden || renderExpirationTime !== Never) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); + var current = newFiber.alternate; + if (current !== null) { + var oldIndex = current.index; + if (oldIndex < lastPlacedIndex) { + // This is a move. + newFiber.effectTag = Placement; + return lastPlacedIndex; + } else { + // This item can stay in place. + return oldIndex; } - // If we're rendering a hidden node at hidden priority, don't bailout. The - // parent is complete, but the children may not be. - } - - var nextChildren = nextProps.children; - var isDirectTextChild = shouldSetTextContent(type, nextProps); - - if (isDirectTextChild) { - // We special case a direct text child of a host node. This is a common - // case. We won't handle it as a reified child. We will instead handle - // this in the host environment that also have access to this prop. That - // avoids allocating another HostText fiber and traversing it. - nextChildren = null; - } else if (prevProps && shouldSetTextContent(type, prevProps)) { - // If we're switching from a direct text child to a normal child, or to - // empty, we need to schedule the text content to be reset. - workInProgress.effectTag |= ContentReset; + } else { + // This is an insertion. + newFiber.effectTag = Placement; + return lastPlacedIndex; } + } - markRef(current, workInProgress); - - // Check the host config to see if the children are offscreen/hidden. - if ( - renderExpirationTime !== Never && - workInProgress.mode & AsyncMode && - shouldDeprioritizeSubtree(type, nextProps) - ) { - // Down-prioritize the children. - workInProgress.expirationTime = Never; - // Bailout and come back to this fiber later. - workInProgress.memoizedProps = nextProps; - return null; + function placeSingleChild(newFiber) { + // This is simpler for the single child case. We only need to do a + // placement for inserting new children. + if (shouldTrackSideEffects && newFiber.alternate === null) { + newFiber.effectTag = Placement; } - - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextProps); - return workInProgress.child; + return newFiber; } - function updateHostText(current, workInProgress) { - if (current === null) { - tryToClaimNextHydratableInstance(workInProgress); + function updateTextNode(returnFiber, current, textContent, expirationTime) { + if (current === null || current.tag !== HostText) { + // Insert + var created = createFiberFromText( + textContent, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber(current, textContent, expirationTime); + existing.return = returnFiber; + return existing; } - var nextProps = workInProgress.pendingProps; - memoizeProps(workInProgress, nextProps); - // Nothing to do here. This is terminal. We'll do the completion step - // immediately after. - return null; } - function mountIndeterminateComponent( - current, - workInProgress, - renderExpirationTime - ) { - invariant( - current === null, - "An indeterminate component should never have mounted. This error is " + - "likely caused by a bug in React. Please file an issue." - ); - var fn = workInProgress.type; - var props = workInProgress.pendingProps; - var unmaskedContext = getUnmaskedContext(workInProgress); - var context = getMaskedContext(workInProgress, unmaskedContext); - - var value = void 0; - - { - if (fn.prototype && typeof fn.prototype.render === "function") { - var componentName = getComponentName(workInProgress) || "Unknown"; - - if (!didWarnAboutBadClass[componentName]) { - warning( - false, - "The <%s /> component appears to have a render method, but doesn't extend React.Component. " + - "This is likely to cause errors. Change %s to extend React.Component instead.", - componentName, - componentName - ); - didWarnAboutBadClass[componentName] = true; - } + function updateElement(returnFiber, current, element, expirationTime) { + if (current !== null && current.type === element.type) { + // Move based on index + var existing = useFiber(current, element.props, expirationTime); + existing.ref = coerceRef(returnFiber, current, element); + existing.return = returnFiber; + { + existing._debugSource = element._source; + existing._debugOwner = element._owner; } - ReactCurrentOwner.current = workInProgress; - value = fn(props, context); + return existing; + } else { + // Insert + var created = createFiberFromElement( + element, + returnFiber.mode, + expirationTime + ); + created.ref = coerceRef(returnFiber, current, element); + created.return = returnFiber; + return created; } - // React DevTools reads this flag. - workInProgress.effectTag |= PerformedWork; + } + function updatePortal(returnFiber, current, portal, expirationTime) { if ( - typeof value === "object" && - value !== null && - typeof value.render === "function" && - value.$$typeof === undefined + current === null || + current.tag !== HostPortal || + current.stateNode.containerInfo !== portal.containerInfo || + current.stateNode.implementation !== portal.implementation ) { - var Component = workInProgress.type; - - // Proceed under the assumption that this is a class instance - workInProgress.tag = ClassComponent; - - workInProgress.memoizedState = - value.state !== null && value.state !== undefined ? value.state : null; - - var getDerivedStateFromProps = Component.getDerivedStateFromProps; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - props - ); - } - - // 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); - adoptClassInstance(workInProgress, value); - mountClassInstance(workInProgress, renderExpirationTime); - return finishClassComponent( - current, - workInProgress, - true, - hasContext, - renderExpirationTime + // Insert + var created = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime ); + created.return = returnFiber; + return created; } else { - // Proceed under the assumption that this is a functional component - workInProgress.tag = FunctionalComponent; - { - 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; - } - if (workInProgress.ref !== null) { - var info = ""; - var ownerName = ReactDebugCurrentFiber.getCurrentFiberOwnerName(); - if (ownerName) { - info += "\n\nCheck the render method of `" + ownerName + "`."; - } - - var warningKey = ownerName || workInProgress._debugID || ""; - var debugSource = workInProgress._debugSource; - if (debugSource) { - warningKey = debugSource.fileName + ":" + debugSource.lineNumber; - } - if (!didWarnAboutStatelessRefs[warningKey]) { - didWarnAboutStatelessRefs[warningKey] = true; - warning( - false, - "Stateless function components cannot be given refs. " + - "Attempts to access this ref will fail.%s%s", - info, - ReactDebugCurrentFiber.getCurrentFiberStackAddendum() - ); - } - } - - if (typeof fn.getDerivedStateFromProps === "function") { - var _componentName = getComponentName(workInProgress) || "Unknown"; - - if ( - !didWarnAboutGetDerivedStateOnFunctionalComponent[_componentName] - ) { - warning( - false, - "%s: Stateless functional components do not support getDerivedStateFromProps.", - _componentName - ); - didWarnAboutGetDerivedStateOnFunctionalComponent[ - _componentName - ] = true; - } - } - } - reconcileChildren(current, workInProgress, value); - memoizeProps(workInProgress, props); - return workInProgress.child; + // Update + var existing = useFiber(current, portal.children || [], expirationTime); + existing.return = returnFiber; + return existing; } } - function updateTimeoutComponent( - current, - workInProgress, - renderExpirationTime - ) { - if (enableSuspense) { - var nextProps = workInProgress.pendingProps; - var prevProps = workInProgress.memoizedProps; - - var prevDidTimeout = workInProgress.memoizedState; - - // Check if we already attempted to render the normal state. If we did, - // and we timed out, render the placeholder state. - var alreadyCaptured = - (workInProgress.effectTag & DidCapture) === NoEffect; - var nextDidTimeout = !alreadyCaptured; - - if (hasLegacyContextChanged()) { - // 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 (nextProps === prevProps && nextDidTimeout === prevDidTimeout) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - - var render = nextProps.children; - var nextChildren = render(nextDidTimeout); - workInProgress.memoizedProps = nextProps; - workInProgress.memoizedState = nextDidTimeout; - reconcileChildren(current, workInProgress, nextChildren); - return workInProgress.child; + function updateFragment(returnFiber, current, fragment, expirationTime, key) { + if (current === null || current.tag !== Fragment) { + // Insert + var created = createFiberFromFragment( + fragment, + returnFiber.mode, + expirationTime, + key + ); + created.return = returnFiber; + return created; } else { - return null; + // Update + var existing = useFiber(current, fragment, expirationTime); + existing.return = returnFiber; + return existing; } } - function updatePortalComponent( - current, - workInProgress, - renderExpirationTime - ) { - pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo); - var nextChildren = workInProgress.pendingProps; - if (hasLegacyContextChanged()) { - // 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) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - - if (current === null) { - // Portals are special because we don't append the children during mount - // but at commit. Therefore we need to track insertions which the normal - // flow doesn't do during mount. This doesn't happen at the root because - // the root always starts with a "current" with a null child. - // TODO: Consider unifying this with how the root works. - workInProgress.child = reconcileChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime + function createChild(returnFiber, newChild, expirationTime) { + if (typeof newChild === "string" || typeof newChild === "number") { + // Text nodes don't have keys. If the previous node is implicitly keyed + // we can continue to replace it without aborting even if it is not a text + // node. + var created = createFiberFromText( + "" + newChild, + returnFiber.mode, + expirationTime ); - memoizeProps(workInProgress, nextChildren); - } else { - reconcileChildren(current, workInProgress, nextChildren); - memoizeProps(workInProgress, nextChildren); + created.return = returnFiber; + return created; } - return workInProgress.child; - } - function propagateContextChange( - workInProgress, - context, - changedBits, - 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. - switch (fiber.tag) { - case ContextConsumer: - // Check if the context matches. - var observedBits = fiber.stateNode | 0; - if (fiber.type === context && (observedBits & changedBits) !== 0) { - // Update the expiration time of all the ancestors, including - // the alternates. - var node = fiber; - while (node !== null) { - var alternate = node.alternate; - if ( - node.expirationTime === NoWork || - node.expirationTime > renderExpirationTime - ) { - node.expirationTime = renderExpirationTime; - if ( - alternate !== null && - (alternate.expirationTime === NoWork || - alternate.expirationTime > renderExpirationTime) - ) { - alternate.expirationTime = renderExpirationTime; - } - } else if ( - alternate !== null && - (alternate.expirationTime === NoWork || - alternate.expirationTime > renderExpirationTime) - ) { - alternate.expirationTime = renderExpirationTime; - } else { - // Neither alternate was updated, which means the rest of the - // ancestor path already has sufficient priority. - break; - } - node = node.return; - } - // Don't scan deeper than a matching consumer. When we render the - // consumer, we'll continue scanning from that point. This way the - // scanning work is time-sliced. - nextFiber = null; - } else { - // Traverse down. - nextFiber = fiber.child; - } - break; - case ContextProvider: - // Don't scan deeper if this is a matching provider - nextFiber = fiber.type === workInProgress.type ? null : fiber.child; - break; - default: - // Traverse down. - nextFiber = fiber.child; - break; - } - if (nextFiber !== null) { - // Set the return pointer of the child to the work-in-progress fiber. - nextFiber.return = fiber; - } else { - // No child. Traverse to next sibling. - nextFiber = fiber; - while (nextFiber !== null) { - if (nextFiber === workInProgress) { - // We're back to the root of this subtree. Exit. - nextFiber = null; - break; - } - var sibling = nextFiber.sibling; - if (sibling !== null) { - // Set the return pointer of the sibling to the work-in-progress fiber. - sibling.return = nextFiber.return; - nextFiber = sibling; - break; - } - // No more siblings. Traverse up. - nextFiber = nextFiber.return; + if (typeof newChild === "object" && newChild !== null) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: { + var _created = createFiberFromElement( + newChild, + returnFiber.mode, + expirationTime + ); + _created.ref = coerceRef(returnFiber, null, newChild); + _created.return = returnFiber; + return _created; + } + case REACT_PORTAL_TYPE: { + var _created2 = createFiberFromPortal( + newChild, + returnFiber.mode, + expirationTime + ); + _created2.return = returnFiber; + return _created2; } } - fiber = nextFiber; - } - } - function updateContextProvider( - current, - workInProgress, - renderExpirationTime - ) { - var providerType = workInProgress.type; - var context = providerType._context; + if (isArray$1(newChild) || getIteratorFn(newChild)) { + var _created3 = createFiberFromFragment( + newChild, + returnFiber.mode, + expirationTime, + null + ); + _created3.return = returnFiber; + return _created3; + } - var newProps = workInProgress.pendingProps; - var oldProps = workInProgress.memoizedProps; - var canBailOnProps = true; + throwOnInvalidObjectType(returnFiber, newChild); + } - if (hasLegacyContextChanged()) { - canBailOnProps = false; - // 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) { - workInProgress.stateNode = 0; - pushProvider(workInProgress); - return bailoutOnAlreadyFinishedWork(current, workInProgress); + { + if (typeof newChild === "function") { + warnOnFunctionType(); + } } - var newValue = newProps.value; - workInProgress.memoizedProps = newProps; + return null; + } - { - var providerPropTypes = workInProgress.type.propTypes; + function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { + // Update the fiber if the keys match, otherwise return null. - if (providerPropTypes) { - checkPropTypes( - providerPropTypes, - newProps, - "prop", - "Context.Provider", - getCurrentFiberStackAddendum - ); + var key = oldFiber !== null ? oldFiber.key : null; + + if (typeof newChild === "string" || typeof newChild === "number") { + // Text nodes don't have keys. If the previous node is implicitly keyed + // we can continue to replace it without aborting even if it is not a text + // node. + if (key !== null) { + return null; } + return updateTextNode( + returnFiber, + oldFiber, + "" + newChild, + expirationTime + ); } - var changedBits = void 0; - if (oldProps === null) { - // Initial render - changedBits = MAX_SIGNED_31_BIT_INT; - } else { - if (oldProps.value === newProps.value) { - // No change. Bailout early if children are the same. - if (oldProps.children === newProps.children && canBailOnProps) { - workInProgress.stateNode = 0; - pushProvider(workInProgress); - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - changedBits = 0; - } else { - var oldValue = oldProps.value; - // Use Object.is to compare the new context value to the old value. - // Inlined Object.is polyfill. - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is - if ( - (oldValue === newValue && - (oldValue !== 0 || 1 / oldValue === 1 / newValue)) || - (oldValue !== oldValue && newValue !== newValue) // eslint-disable-line no-self-compare - ) { - // No change. Bailout early if children are the same. - if (oldProps.children === newProps.children && canBailOnProps) { - workInProgress.stateNode = 0; - pushProvider(workInProgress); - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - changedBits = 0; - } else { - changedBits = - typeof context._calculateChangedBits === "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; - } - changedBits |= 0; - - if (changedBits === 0) { - // No change. Bailout early if children are the same. - if (oldProps.children === newProps.children && canBailOnProps) { - workInProgress.stateNode = 0; - pushProvider(workInProgress); - return bailoutOnAlreadyFinishedWork(current, workInProgress); + if (typeof newChild === "object" && newChild !== null) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: { + if (newChild.key === key) { + if (newChild.type === REACT_FRAGMENT_TYPE) { + return updateFragment( + returnFiber, + oldFiber, + newChild.props.children, + expirationTime, + key + ); } + return updateElement( + returnFiber, + oldFiber, + newChild, + expirationTime + ); } else { - propagateContextChange( - workInProgress, - context, - changedBits, - renderExpirationTime + return null; + } + } + case REACT_PORTAL_TYPE: { + if (newChild.key === key) { + return updatePortal( + returnFiber, + oldFiber, + newChild, + expirationTime ); + } else { + return null; } } } + + if (isArray$1(newChild) || getIteratorFn(newChild)) { + if (key !== null) { + return null; + } + + return updateFragment( + returnFiber, + oldFiber, + newChild, + expirationTime, + null + ); + } + + throwOnInvalidObjectType(returnFiber, newChild); } - workInProgress.stateNode = changedBits; - pushProvider(workInProgress); + { + if (typeof newChild === "function") { + warnOnFunctionType(); + } + } - var newChildren = newProps.children; - reconcileChildren(current, workInProgress, newChildren); - return workInProgress.child; + return null; } - function updateContextConsumer( - current, - workInProgress, - renderExpirationTime + function updateFromMap( + existingChildren, + returnFiber, + newIdx, + newChild, + expirationTime ) { - var context = workInProgress.type; - var newProps = workInProgress.pendingProps; - var oldProps = workInProgress.memoizedProps; - - var newValue = getContextCurrentValue(context); - var changedBits = getContextChangedBits(context); - - if (hasLegacyContextChanged()) { - // 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) { - return bailoutOnAlreadyFinishedWork(current, workInProgress); - } - workInProgress.memoizedProps = newProps; - - var observedBits = newProps.unstable_observedBits; - if (observedBits === undefined || observedBits === null) { - // Subscribe to all changes by default - observedBits = MAX_SIGNED_31_BIT_INT; - } - // Store the observedBits on the fiber's stateNode for quick access. - workInProgress.stateNode = observedBits; - - if ((changedBits & observedBits) !== 0) { - // Context change propagation stops at matching consumers, for time- - // slicing. Continue the propagation here. - propagateContextChange( - workInProgress, - context, - changedBits, - renderExpirationTime + if (typeof newChild === "string" || typeof newChild === "number") { + // Text nodes don't have keys, so we neither have to check the old nor + // new node for the key. If both are text nodes, they match. + var matchedFiber = existingChildren.get(newIdx) || null; + return updateTextNode( + returnFiber, + matchedFiber, + "" + newChild, + expirationTime ); - } else if (oldProps === newProps) { - // Skip over a memoized parent with a bitmask bailout even - // if we began working on it because of a deeper matching child. - 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; - } - - var newChildren = void 0; - { - ReactCurrentOwner.current = workInProgress; - ReactDebugCurrentFiber.setCurrentPhase("render"); - newChildren = render(newValue); - ReactDebugCurrentFiber.setCurrentPhase(null); } - // React DevTools reads this flag. - workInProgress.effectTag |= PerformedWork; - reconcileChildren(current, workInProgress, newChildren); - return workInProgress.child; - } - - /* - function reuseChildrenEffects(returnFiber : Fiber, firstChild : Fiber) { - let child = firstChild; - do { - // Ensure that the first and last effect of the parent corresponds - // to the children's first and last effect. - if (!returnFiber.firstEffect) { - returnFiber.firstEffect = child.firstEffect; - } - if (child.lastEffect) { - if (returnFiber.lastEffect) { - returnFiber.lastEffect.nextEffect = child.firstEffect; + if (typeof newChild === "object" && newChild !== null) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: { + var _matchedFiber = + existingChildren.get( + newChild.key === null ? newIdx : newChild.key + ) || null; + if (newChild.type === REACT_FRAGMENT_TYPE) { + return updateFragment( + returnFiber, + _matchedFiber, + newChild.props.children, + expirationTime, + newChild.key + ); + } + return updateElement( + returnFiber, + _matchedFiber, + newChild, + expirationTime + ); + } + case REACT_PORTAL_TYPE: { + var _matchedFiber2 = + existingChildren.get( + newChild.key === null ? newIdx : newChild.key + ) || null; + return updatePortal( + returnFiber, + _matchedFiber2, + newChild, + expirationTime + ); } - returnFiber.lastEffect = child.lastEffect; } - } while (child = child.sibling); - } - */ - function bailoutOnAlreadyFinishedWork(current, workInProgress) { - cancelWorkTimer(workInProgress); + if (isArray$1(newChild) || getIteratorFn(newChild)) { + var _matchedFiber3 = existingChildren.get(newIdx) || null; + return updateFragment( + returnFiber, + _matchedFiber3, + newChild, + expirationTime, + null + ); + } - if (enableProfilerTimer) { - // Don't update "base" render times for bailouts. - stopBaseRenderTimerIfRunning(); + throwOnInvalidObjectType(returnFiber, newChild); } - // TODO: We should ideally be able to bail out early if the children have no - // more work to do. However, since we don't have a separation of this - // Fiber's priority and its children yet - we don't know without doing lots - // of the same work we do anyway. Once we have that separation we can just - // bail out here if the children has no more work at this priority level. - // if (workInProgress.priorityOfChildren <= priorityLevel) { - // // If there are side-effects in these children that have not yet been - // // committed we need to ensure that they get properly transferred up. - // if (current && current.child !== workInProgress.child) { - // reuseChildrenEffects(workInProgress, child); - // } - // return null; - // } - - cloneChildFibers(current, workInProgress); - return workInProgress.child; - } - - function bailoutOnLowPriority(current, workInProgress) { - cancelWorkTimer(workInProgress); - - if (enableProfilerTimer) { - // Don't update "base" render times for bailouts. - stopBaseRenderTimerIfRunning(); + { + if (typeof newChild === "function") { + warnOnFunctionType(); + } } - // TODO: Handle HostComponent tags here as well and call pushHostContext()? - // See PR 8590 discussion for context - switch (workInProgress.tag) { - case HostRoot: - pushHostRootContext(workInProgress); - break; - case ClassComponent: - pushLegacyContextProvider(workInProgress); - break; - case HostPortal: - pushHostContainer( - workInProgress, - workInProgress.stateNode.containerInfo - ); - break; - case ContextProvider: - pushProvider(workInProgress); - break; - case Profiler: - if (enableProfilerTimer) { - markActualRenderTimeStarted(workInProgress); - } - break; - } - // TODO: What if this is currently in progress? - // How can that happen? How is this not being cloned? return null; } - // TODO: Delete memoizeProps/State and move to reconcile/bailout instead - function memoizeProps(workInProgress, nextProps) { - workInProgress.memoizedProps = nextProps; - } - - function memoizeState(workInProgress, nextState) { - workInProgress.memoizedState = nextState; - // Don't reset the updateQueue, in case there are pending updates. Resetting - // is handled by processUpdateQueue. + /** + * Warns if there is a duplicate or missing key + */ + function warnOnInvalidKey(child, knownKeys) { + { + if (typeof child !== "object" || child === null) { + return knownKeys; + } + switch (child.$$typeof) { + case REACT_ELEMENT_TYPE: + case REACT_PORTAL_TYPE: + warnForMissingKey(child); + var key = child.key; + if (typeof key !== "string") { + break; + } + if (knownKeys === null) { + knownKeys = new Set(); + knownKeys.add(key); + break; + } + if (!knownKeys.has(key)) { + knownKeys.add(key); + break; + } + warning( + false, + "Encountered two children with the same key, `%s`. " + + "Keys should be unique so that components maintain their identity " + + "across updates. Non-unique keys may cause children to be " + + "duplicated and/or omitted — the behavior is unsupported and " + + "could change in a future version.%s", + key, + getCurrentFiberStackAddendum$2() + ); + break; + default: + break; + } + } + return knownKeys; } - function beginWork(current, workInProgress, renderExpirationTime) { - if ( - workInProgress.expirationTime === NoWork || - workInProgress.expirationTime > renderExpirationTime - ) { - return bailoutOnLowPriority(current, workInProgress); - } + function reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChildren, + expirationTime + ) { + // This algorithm can't optimize by searching from boths ends since we + // don't have backpointers on fibers. I'm trying to see how far we can get + // with that model. If it ends up not being worth the tradeoffs, we can + // add it later. - switch (workInProgress.tag) { - case IndeterminateComponent: - return mountIndeterminateComponent( - current, - workInProgress, - renderExpirationTime - ); - case FunctionalComponent: - return updateFunctionalComponent(current, workInProgress); - case ClassComponent: - return updateClassComponent( - current, - workInProgress, - renderExpirationTime - ); - case HostRoot: - return updateHostRoot(current, workInProgress, renderExpirationTime); - case HostComponent: - return updateHostComponent( - current, - workInProgress, - renderExpirationTime - ); - case HostText: - return updateHostText(current, workInProgress); - case TimeoutComponent: - return updateTimeoutComponent( - current, - workInProgress, - renderExpirationTime - ); - case HostPortal: - return updatePortalComponent( - current, - workInProgress, - renderExpirationTime - ); - case ForwardRef: - return updateForwardRef(current, workInProgress); - case Fragment: - return updateFragment(current, workInProgress); - case Mode: - return updateMode(current, workInProgress); - case Profiler: - return updateProfiler(current, workInProgress); - case ContextProvider: - return updateContextProvider( - current, - workInProgress, - renderExpirationTime - ); - case ContextConsumer: - return updateContextConsumer( - current, - workInProgress, - renderExpirationTime - ); - default: - invariant( - false, - "Unknown unit of work tag. This error is likely caused by a bug in " + - "React. Please file an issue." - ); - } - } + // Even with a two ended optimization, we'd want to optimize for the case + // where there are few changes and brute force the comparison instead of + // going for the Map. It'd like to explore hitting that path first in + // forward-only mode and only go for the Map once we notice that we need + // lots of look ahead. This doesn't handle reversal as well as two ended + // search but that's unusual. Besides, for the two ended optimization to + // work on Iterables, we'd need to copy the whole set. - return { - beginWork: beginWork - }; -}; + // In this first iteration, we'll just live with hitting the bad case + // (adding everything to a Map) in for every insert/move. -var ReactFiberCompleteWork = function( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - profilerTimer -) { - var createInstance = config.createInstance, - createTextInstance = config.createTextInstance, - appendInitialChild = config.appendInitialChild, - finalizeInitialChildren = config.finalizeInitialChildren, - prepareUpdate = config.prepareUpdate, - mutation = config.mutation, - persistence = config.persistence; - var getRootHostContainer = hostContext.getRootHostContainer, - popHostContext = hostContext.popHostContext, - getHostContext = hostContext.getHostContext, - popHostContainer = hostContext.popHostContainer; - var recordElapsedActualRenderTime = - profilerTimer.recordElapsedActualRenderTime; - var popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject; - var popProvider = newContext.popProvider; - var prepareToHydrateHostInstance = - hydrationContext.prepareToHydrateHostInstance, - prepareToHydrateHostTextInstance = - hydrationContext.prepareToHydrateHostTextInstance, - popHydrationState = hydrationContext.popHydrationState; - - function markUpdate(workInProgress) { - // Tag the fiber with an update effect. This turns a Placement into - // a PlacementAndUpdate. - workInProgress.effectTag |= Update; - } + // If you change this code, also update reconcileChildrenIterator() which + // uses the same algorithm. - function markRef(workInProgress) { - workInProgress.effectTag |= Ref; - } + { + // First, validate keys. + var knownKeys = null; + for (var i = 0; i < newChildren.length; i++) { + var child = newChildren[i]; + knownKeys = warnOnInvalidKey(child, knownKeys); + } + } - function appendAllChildren(parent, workInProgress) { - // We only have the top Fiber that was created but we need recurse down its - // children to find all the terminal nodes. - var node = workInProgress.child; - while (node !== null) { - if (node.tag === HostComponent || node.tag === HostText) { - appendInitialChild(parent, node.stateNode); - } else if (node.tag === HostPortal) { - // If we have a portal child, then we don't want to traverse - // down its children. Instead, we'll get insertions from each child in - // the portal directly. - } else if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; + var resultingFirstChild = null; + var previousNewFiber = null; + + var oldFiber = currentFirstChild; + var lastPlacedIndex = 0; + var newIdx = 0; + var nextOldFiber = null; + for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) { + if (oldFiber.index > newIdx) { + nextOldFiber = oldFiber; + oldFiber = null; + } else { + nextOldFiber = oldFiber.sibling; } - if (node === workInProgress) { - return; + var newFiber = updateSlot( + returnFiber, + oldFiber, + newChildren[newIdx], + expirationTime + ); + if (newFiber === null) { + // TODO: This breaks on empty slots like null children. That's + // unfortunate because it triggers the slow path all the time. We need + // a better way to communicate whether this was a miss or null, + // boolean, undefined, etc. + if (oldFiber === null) { + oldFiber = nextOldFiber; + } + break; } - while (node.sibling === null) { - if (node.return === null || node.return === workInProgress) { - return; + if (shouldTrackSideEffects) { + if (oldFiber && newFiber.alternate === null) { + // We matched the slot, but we didn't reuse the existing fiber, so we + // need to delete the existing child. + deleteChild(returnFiber, oldFiber); } - node = node.return; } - node.sibling.return = node.return; - node = node.sibling; + lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + // TODO: Move out of the loop. This only happens for the first run. + resultingFirstChild = newFiber; + } else { + // TODO: Defer siblings if we're not at the right index for this slot. + // I.e. if we had null values before, then we want to defer this + // for each null value. However, we also don't want to call updateSlot + // with the previous one. + previousNewFiber.sibling = newFiber; + } + previousNewFiber = newFiber; + oldFiber = nextOldFiber; } - } - var updateHostContainer = void 0; - var updateHostComponent = void 0; - var updateHostText = void 0; - if (mutation) { - if (enableMutatingReconciler) { - // Mutation mode - updateHostContainer = function(workInProgress) { - // Noop - }; - updateHostComponent = function( - current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ) { - // TODO: Type this specific to this type of component. - workInProgress.updateQueue = updatePayload; - // If the update payload indicates that there is a change or if there - // is a new ref we mark this as an update. All the work is done in commitWork. - if (updatePayload) { - markUpdate(workInProgress); - } - }; - updateHostText = function(current, workInProgress, oldText, newText) { - // If the text differs, mark it as an update. All the work in done in commitWork. - if (oldText !== newText) { - markUpdate(workInProgress); - } - }; - } else { - invariant(false, "Mutating reconciler is disabled."); + if (newIdx === newChildren.length) { + // We've reached the end of the new children. We can delete the rest. + deleteRemainingChildren(returnFiber, oldFiber); + return resultingFirstChild; } - } else if (persistence) { - if (enablePersistentReconciler) { - // Persistent host tree mode - var cloneInstance = persistence.cloneInstance, - createContainerChildSet = persistence.createContainerChildSet, - appendChildToContainerChildSet = - persistence.appendChildToContainerChildSet, - finalizeContainerChildren = persistence.finalizeContainerChildren; - - // An unfortunate fork of appendAllChildren because we have two different parent types. - var appendAllChildrenToContainer = function( - containerChildSet, - workInProgress - ) { - // We only have the top Fiber that was created but we need recurse down its - // children to find all the terminal nodes. - var node = workInProgress.child; - while (node !== null) { - if (node.tag === HostComponent || node.tag === HostText) { - appendChildToContainerChildSet(containerChildSet, node.stateNode); - } else if (node.tag === HostPortal) { - // If we have a portal child, then we don't want to traverse - // down its children. Instead, we'll get insertions from each child in - // the portal directly. - } else if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; - } - if (node === workInProgress) { - return; - } - while (node.sibling === null) { - if (node.return === null || node.return === workInProgress) { - return; - } - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } - }; - updateHostContainer = function(workInProgress) { - var portalOrRoot = workInProgress.stateNode; - var childrenUnchanged = workInProgress.firstEffect === null; - if (childrenUnchanged) { - // No changes, just reuse the existing instance. - } else { - var container = portalOrRoot.containerInfo; - var newChildSet = createContainerChildSet(container); - // If children might have changed, we have to add them all to the set. - appendAllChildrenToContainer(newChildSet, workInProgress); - portalOrRoot.pendingChildren = newChildSet; - // Schedule an update on the container to swap out the container. - markUpdate(workInProgress); - finalizeContainerChildren(container, newChildSet); + if (oldFiber === null) { + // If we don't have any more existing children we can choose a fast path + // since the rest will all be insertions. + for (; newIdx < newChildren.length; newIdx++) { + var _newFiber = createChild( + returnFiber, + newChildren[newIdx], + expirationTime + ); + if (!_newFiber) { + continue; } - }; - updateHostComponent = function( - current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ) { - // If there are no effects associated with this node, then none of our children had any updates. - // This guarantees that we can reuse all of them. - var childrenUnchanged = workInProgress.firstEffect === null; - var currentInstance = current.stateNode; - if (childrenUnchanged && updatePayload === null) { - // No changes, just reuse the existing instance. - // Note that this might release a previous clone. - workInProgress.stateNode = currentInstance; + lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + // TODO: Move out of the loop. This only happens for the first run. + resultingFirstChild = _newFiber; } else { - var recyclableInstance = workInProgress.stateNode; - var newInstance = cloneInstance( - currentInstance, - updatePayload, - type, - oldProps, - newProps, - workInProgress, - childrenUnchanged, - recyclableInstance - ); - if ( - finalizeInitialChildren( - newInstance, - type, - newProps, - rootContainerInstance, - currentHostContext - ) - ) { - markUpdate(workInProgress); - } - workInProgress.stateNode = newInstance; - if (childrenUnchanged) { - // If there are no other effects in this tree, we need to flag this node as having one. - // Even though we're not going to use it for anything. - // Otherwise parents won't know that there are new children to propagate upwards. - markUpdate(workInProgress); - } else { - // If children might have changed, we have to add them all to the set. - appendAllChildren(newInstance, workInProgress); - } - } - }; - updateHostText = function(current, workInProgress, oldText, newText) { - if (oldText !== newText) { - // If the text content differs, we'll create a new text instance for it. - var rootContainerInstance = getRootHostContainer(); - var currentHostContext = getHostContext(); - workInProgress.stateNode = createTextInstance( - newText, - rootContainerInstance, - currentHostContext, - workInProgress - ); - // We'll have to mark it as having an effect, even though we won't use the effect for anything. - // This lets the parents know that at least one of their children has changed. - markUpdate(workInProgress); - } - }; - } else { - invariant(false, "Persistent reconciler is disabled."); - } - } else { - if (enableNoopReconciler) { - // No host operations - updateHostContainer = function(workInProgress) { - // Noop - }; - updateHostComponent = function( - current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ) { - // Noop - }; - updateHostText = function(current, workInProgress, oldText, newText) { - // Noop - }; - } else { - invariant(false, "Noop reconciler is disabled."); - } - } - - function completeWork(current, workInProgress, renderExpirationTime) { - var newProps = workInProgress.pendingProps; - switch (workInProgress.tag) { - case FunctionalComponent: - return null; - case ClassComponent: { - // We are leaving this subtree, so pop context if any. - popLegacyContextProvider(workInProgress); - return null; - } - case HostRoot: { - popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); - var fiberRoot = workInProgress.stateNode; - if (fiberRoot.pendingContext) { - fiberRoot.context = fiberRoot.pendingContext; - fiberRoot.pendingContext = null; - } - if (current === null || current.child === null) { - // If we hydrated, pop so that we can delete any remaining children - // that weren't hydrated. - popHydrationState(workInProgress); - // This resets the hacky state to fix isMounted before committing. - // TODO: Delete this when we delete isMounted and findDOMNode. - workInProgress.effectTag &= ~Placement; + previousNewFiber.sibling = _newFiber; } - updateHostContainer(workInProgress); - return null; + previousNewFiber = _newFiber; } - case HostComponent: { - popHostContext(workInProgress); - var rootContainerInstance = getRootHostContainer(); - var type = workInProgress.type; - if (current !== null && workInProgress.stateNode != null) { - // If we have an alternate, that means this is an update and we need to - // schedule a side-effect to do the updates. - var oldProps = current.memoizedProps; - // If we get updated because one of our children updated, we don't - // have newProps so we'll have to reuse them. - // TODO: Split the update API as separate for the props vs. children. - // Even better would be if children weren't special cased at all tho. - var instance = workInProgress.stateNode; - var currentHostContext = getHostContext(); - // TODO: Experiencing an error where oldProps is null. Suggests a host - // component is hitting the resume path. Figure out why. Possibly - // related to `hidden`. - var updatePayload = prepareUpdate( - instance, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ); - - updateHostComponent( - current, - workInProgress, - updatePayload, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ); - - if (current.ref !== workInProgress.ref) { - markRef(workInProgress); - } - } else { - if (!newProps) { - invariant( - workInProgress.stateNode !== null, - "We must have new props for new mounts. This error is likely " + - "caused by a bug in React. Please file an issue." - ); - // This can happen when we abort work. - return null; - } - - var _currentHostContext = getHostContext(); - // TODO: Move createInstance to beginWork and keep it on a context - // "stack" as the parent. Then append children as we go in beginWork - // or completeWork depending on we want to add then top->down or - // bottom->up. Top->down is faster in IE11. - var wasHydrated = popHydrationState(workInProgress); - if (wasHydrated) { - // TODO: Move this and createInstance step into the beginPhase - // to consolidate. - if ( - prepareToHydrateHostInstance( - workInProgress, - rootContainerInstance, - _currentHostContext - ) - ) { - // If changes to the hydrated node needs to be applied at the - // commit-phase we mark this as such. - markUpdate(workInProgress); - } - } else { - var _instance = createInstance( - type, - newProps, - rootContainerInstance, - _currentHostContext, - workInProgress - ); - - appendAllChildren(_instance, workInProgress); + return resultingFirstChild; + } - // Certain renderers require commit-time effects for initial mount. - // (eg DOM renderer supports auto-focus for certain elements). - // Make sure such renderers get scheduled for later work. - if ( - finalizeInitialChildren( - _instance, - type, - newProps, - rootContainerInstance, - _currentHostContext - ) - ) { - markUpdate(workInProgress); - } - workInProgress.stateNode = _instance; - } + // Add all children to a key map for quick lookups. + var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - if (workInProgress.ref !== null) { - // If there is a ref on a host node we need to schedule a callback - markRef(workInProgress); + // Keep scanning and use the map to restore deleted items as moves. + for (; newIdx < newChildren.length; newIdx++) { + var _newFiber2 = updateFromMap( + existingChildren, + returnFiber, + newIdx, + newChildren[newIdx], + expirationTime + ); + if (_newFiber2) { + if (shouldTrackSideEffects) { + if (_newFiber2.alternate !== null) { + // The new fiber is a work in progress, but if there exists a + // current, that means that we reused the fiber. We need to delete + // it from the child list so that we don't add it to the deletion + // list. + existingChildren.delete( + _newFiber2.key === null ? newIdx : _newFiber2.key + ); } } - return null; - } - case HostText: { - var newText = newProps; - if (current && workInProgress.stateNode != null) { - var oldText = current.memoizedProps; - // If we have an alternate, that means this is an update and we need - // to schedule a side-effect to do the updates. - updateHostText(current, workInProgress, oldText, newText); + lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + resultingFirstChild = _newFiber2; } else { - if (typeof newText !== "string") { - invariant( - workInProgress.stateNode !== null, - "We must have new props for new mounts. This error is likely " + - "caused by a bug in React. Please file an issue." - ); - // This can happen when we abort work. - return null; - } - var _rootContainerInstance = getRootHostContainer(); - var _currentHostContext2 = getHostContext(); - var _wasHydrated = popHydrationState(workInProgress); - if (_wasHydrated) { - if (prepareToHydrateHostTextInstance(workInProgress)) { - markUpdate(workInProgress); - } - } else { - workInProgress.stateNode = createTextInstance( - newText, - _rootContainerInstance, - _currentHostContext2, - workInProgress - ); - } + previousNewFiber.sibling = _newFiber2; } - return null; + previousNewFiber = _newFiber2; } - case ForwardRef: - return null; - case TimeoutComponent: - return null; - case Fragment: - return null; - case Mode: - return null; - case Profiler: - if (enableProfilerTimer) { - recordElapsedActualRenderTime(workInProgress); - } - return null; - case HostPortal: - popHostContainer(workInProgress); - updateHostContainer(workInProgress); - return null; - case ContextProvider: - // Pop provider fiber - popProvider(workInProgress); - return null; - case ContextConsumer: - return null; - // Error cases - case IndeterminateComponent: - invariant( - false, - "An indeterminate component should have become determinate before " + - "completing. This error is likely caused by a bug in React. Please " + - "file an issue." - ); - // eslint-disable-next-line no-fallthrough - default: - invariant( - false, - "Unknown unit of work tag. This error is likely caused by a bug in " + - "React. Please file an issue." - ); } - } - - return { - completeWork: completeWork - }; -}; - -function createCapturedValue(value, source) { - // If the value is an error, call this function immediately after it is thrown - // so the stack is accurate. - return { - value: value, - source: source, - stack: getStackAddendumByWorkInProgressFiber(source) - }; -} - -// Module provided by RN: -/** - * Intercept lifecycle errors and ensure they are shown with the correct stack - * trace within the native redbox component. - */ -function showErrorDialog(capturedError) { - var componentStack = capturedError.componentStack, - error = capturedError.error; - - var errorToHandle = void 0; - - // Typically Errors are thrown but eg strings or null can be thrown as well. - if (error instanceof Error) { - var message = error.message, - name = error.name; - - var summary = message ? name + ": " + message : name; - - errorToHandle = error; - - try { - errorToHandle.message = - summary + "\n\nThis error is located at:" + componentStack; - } catch (e) {} - } else if (typeof error === "string") { - errorToHandle = new Error( - error + "\n\nThis error is located at:" + componentStack - ); - } else { - errorToHandle = new Error("Unspecified error at:" + componentStack); - } - - ExceptionsManager.handleException(errorToHandle, false); - - // Return false here to prevent ReactFiberErrorLogger default behavior of - // logging error details to console.error. Calls to console.error are - // automatically routed to the native redbox controller, which we've already - // done above by calling ExceptionsManager. - return false; -} -function logCapturedError(capturedError) { - var logError = showErrorDialog(capturedError); + if (shouldTrackSideEffects) { + // Any existing children that weren't consumed above were deleted. We need + // to add them to the deletion list. + existingChildren.forEach(function(child) { + return deleteChild(returnFiber, child); + }); + } - // Allow injected showErrorDialog() to prevent default console.error logging. - // This enables renderers like ReactNative to better manage redbox behavior. - if (logError === false) { - return; + return resultingFirstChild; } - var error = capturedError.error; - var suppressLogging = error && error.suppressReactErrorLogging; - if (suppressLogging) { - return; - } + function reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChildrenIterable, + expirationTime + ) { + // This is the same implementation as reconcileChildrenArray(), + // but using the iterator instead. - { - var componentName = capturedError.componentName, - componentStack = capturedError.componentStack, - errorBoundaryName = capturedError.errorBoundaryName, - errorBoundaryFound = capturedError.errorBoundaryFound, - willRetry = capturedError.willRetry; + var iteratorFn = getIteratorFn(newChildrenIterable); + invariant( + typeof iteratorFn === "function", + "An object is not an iterable. This error is likely caused by a bug in " + + "React. Please file an issue." + ); - var componentNameMessage = componentName - ? "The above error occurred in the <" + componentName + "> component:" - : "The above error occurred in one of your React components:"; + { + // Warn about using Maps as children + if (newChildrenIterable.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$2() + ) + : void 0; + didWarnAboutMaps = true; + } - var errorBoundaryMessage = void 0; - // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow. - if (errorBoundaryFound && errorBoundaryName) { - if (willRetry) { - errorBoundaryMessage = - "React will try to recreate this component tree from scratch " + - ("using the error boundary you provided, " + errorBoundaryName + "."); - } else { - errorBoundaryMessage = - "This error was initially handled by the error boundary " + - errorBoundaryName + - ".\n" + - "Recreating the tree from scratch failed so React will unmount the tree."; + // First, validate keys. + // We'll get a different iterator later for the main pass. + var _newChildren = iteratorFn.call(newChildrenIterable); + if (_newChildren) { + var knownKeys = null; + var _step = _newChildren.next(); + for (; !_step.done; _step = _newChildren.next()) { + var child = _step.value; + knownKeys = warnOnInvalidKey(child, knownKeys); + } } - } else { - errorBoundaryMessage = - "Consider adding an error boundary to your tree to customize error handling behavior.\n" + - "Visit https://fb.me/react-error-boundaries to learn more about error boundaries."; } - var combinedMessage = - "" + - componentNameMessage + - componentStack + - "\n\n" + - ("" + errorBoundaryMessage); - - // In development, we provide our own message with just the component stack. - // We don't include the original error message and JS stack because the browser - // has already printed it. Even if the application swallows the error, it is still - // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils. - console.error(combinedMessage); - } -} -var invokeGuardedCallback$3 = ReactErrorUtils.invokeGuardedCallback; -var hasCaughtError$1 = ReactErrorUtils.hasCaughtError; -var clearCaughtError$1 = ReactErrorUtils.clearCaughtError; + var newChildren = iteratorFn.call(newChildrenIterable); + invariant(newChildren != null, "An iterable object provided no iterator."); -var didWarnAboutUndefinedSnapshotBeforeUpdate = null; -{ - didWarnAboutUndefinedSnapshotBeforeUpdate = new Set(); -} + var resultingFirstChild = null; + var previousNewFiber = null; -function logError(boundary, errorInfo) { - var source = errorInfo.source; - var stack = errorInfo.stack; - if (stack === null && source !== null) { - stack = getStackAddendumByWorkInProgressFiber(source); - } + var oldFiber = currentFirstChild; + var lastPlacedIndex = 0; + var newIdx = 0; + var nextOldFiber = null; - var capturedError = { - componentName: source !== null ? getComponentName(source) : null, - componentStack: stack !== null ? stack : "", - error: errorInfo.value, - errorBoundary: null, - errorBoundaryName: null, - errorBoundaryFound: false, - willRetry: false - }; + var step = newChildren.next(); + for ( + ; + oldFiber !== null && !step.done; + newIdx++, step = newChildren.next() + ) { + if (oldFiber.index > newIdx) { + nextOldFiber = oldFiber; + oldFiber = null; + } else { + nextOldFiber = oldFiber.sibling; + } + var newFiber = updateSlot( + returnFiber, + oldFiber, + step.value, + expirationTime + ); + if (newFiber === null) { + // TODO: This breaks on empty slots like null children. That's + // unfortunate because it triggers the slow path all the time. We need + // a better way to communicate whether this was a miss or null, + // boolean, undefined, etc. + if (!oldFiber) { + oldFiber = nextOldFiber; + } + break; + } + if (shouldTrackSideEffects) { + if (oldFiber && newFiber.alternate === null) { + // We matched the slot, but we didn't reuse the existing fiber, so we + // need to delete the existing child. + deleteChild(returnFiber, oldFiber); + } + } + lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + // TODO: Move out of the loop. This only happens for the first run. + resultingFirstChild = newFiber; + } else { + // TODO: Defer siblings if we're not at the right index for this slot. + // I.e. if we had null values before, then we want to defer this + // for each null value. However, we also don't want to call updateSlot + // with the previous one. + previousNewFiber.sibling = newFiber; + } + previousNewFiber = newFiber; + oldFiber = nextOldFiber; + } - if (boundary !== null && boundary.tag === ClassComponent) { - capturedError.errorBoundary = boundary.stateNode; - capturedError.errorBoundaryName = getComponentName(boundary); - capturedError.errorBoundaryFound = true; - capturedError.willRetry = true; - } + if (step.done) { + // We've reached the end of the new children. We can delete the rest. + deleteRemainingChildren(returnFiber, oldFiber); + return resultingFirstChild; + } - try { - logCapturedError(capturedError); - } catch (e) { - // Prevent cycle if logCapturedError() throws. - // A cycle may still occur if logCapturedError renders a component that throws. - var suppressLogging = e && e.suppressReactErrorLogging; - if (!suppressLogging) { - console.error(e); + if (oldFiber === null) { + // If we don't have any more existing children we can choose a fast path + // since the rest will all be insertions. + for (; !step.done; newIdx++, step = newChildren.next()) { + var _newFiber3 = createChild(returnFiber, step.value, expirationTime); + if (_newFiber3 === null) { + continue; + } + lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + // TODO: Move out of the loop. This only happens for the first run. + resultingFirstChild = _newFiber3; + } else { + previousNewFiber.sibling = _newFiber3; + } + previousNewFiber = _newFiber3; + } + return resultingFirstChild; } - } -} -var ReactFiberCommitWork = function( - config, - captureError, - scheduleWork, - computeExpirationForFiber, - markLegacyErrorBoundaryAsFailed, - recalculateCurrentTime -) { - var getPublicInstance = config.getPublicInstance, - mutation = config.mutation, - persistence = config.persistence; - - var callComponentWillUnmountWithTimer = function(current, instance) { - startPhaseTimer(current, "componentWillUnmount"); - instance.props = current.memoizedProps; - instance.state = current.memoizedState; - instance.componentWillUnmount(); - stopPhaseTimer(); - }; + // Add all children to a key map for quick lookups. + var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - // Capture errors so they don't interrupt unmounting. - function safelyCallComponentWillUnmount(current, instance) { - { - invokeGuardedCallback$3( - null, - callComponentWillUnmountWithTimer, - null, - current, - instance + // Keep scanning and use the map to restore deleted items as moves. + for (; !step.done; newIdx++, step = newChildren.next()) { + var _newFiber4 = updateFromMap( + existingChildren, + returnFiber, + newIdx, + step.value, + expirationTime ); - if (hasCaughtError$1()) { - var unmountError = clearCaughtError$1(); - captureError(current, unmountError); + if (_newFiber4 !== null) { + if (shouldTrackSideEffects) { + if (_newFiber4.alternate !== null) { + // The new fiber is a work in progress, but if there exists a + // current, that means that we reused the fiber. We need to delete + // it from the child list so that we don't add it to the deletion + // list. + existingChildren.delete( + _newFiber4.key === null ? newIdx : _newFiber4.key + ); + } + } + lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx); + if (previousNewFiber === null) { + resultingFirstChild = _newFiber4; + } else { + previousNewFiber.sibling = _newFiber4; + } + previousNewFiber = _newFiber4; } } + + if (shouldTrackSideEffects) { + // Any existing children that weren't consumed above were deleted. We need + // to add them to the deletion list. + existingChildren.forEach(function(child) { + return deleteChild(returnFiber, child); + }); + } + + return resultingFirstChild; } - function safelyDetachRef(current) { - var ref = current.ref; - if (ref !== null) { - if (typeof ref === "function") { - { - invokeGuardedCallback$3(null, ref, null, null); - if (hasCaughtError$1()) { - var refError = clearCaughtError$1(); - captureError(current, refError); + function reconcileSingleTextNode( + returnFiber, + currentFirstChild, + textContent, + expirationTime + ) { + // There's no need to check for keys on text nodes since we don't have a + // way to define them. + if (currentFirstChild !== null && currentFirstChild.tag === HostText) { + // We already have an existing node so let's just update it and delete + // the rest. + deleteRemainingChildren(returnFiber, currentFirstChild.sibling); + var existing = useFiber(currentFirstChild, textContent, expirationTime); + existing.return = returnFiber; + return existing; + } + // The existing first child is not a text node so we need to create one + // and delete the existing ones. + deleteRemainingChildren(returnFiber, currentFirstChild); + var created = createFiberFromText( + textContent, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; + } + + function reconcileSingleElement( + returnFiber, + currentFirstChild, + element, + expirationTime + ) { + var key = element.key; + var child = currentFirstChild; + while (child !== null) { + // TODO: If key === null and child.key === null, then this only applies to + // the first item in the list. + if (child.key === key) { + if ( + child.tag === Fragment + ? element.type === REACT_FRAGMENT_TYPE + : child.type === element.type + ) { + deleteRemainingChildren(returnFiber, child.sibling); + var existing = useFiber( + child, + element.type === REACT_FRAGMENT_TYPE + ? element.props.children + : element.props, + expirationTime + ); + existing.ref = coerceRef(returnFiber, child, element); + existing.return = returnFiber; + { + existing._debugSource = element._source; + existing._debugOwner = element._owner; } + return existing; + } else { + deleteRemainingChildren(returnFiber, child); + break; } } else { - ref.current = null; + deleteChild(returnFiber, child); } + child = child.sibling; + } + + if (element.type === REACT_FRAGMENT_TYPE) { + var created = createFiberFromFragment( + element.props.children, + returnFiber.mode, + expirationTime, + element.key + ); + created.return = returnFiber; + return created; + } else { + var _created4 = createFiberFromElement( + element, + returnFiber.mode, + expirationTime + ); + _created4.ref = coerceRef(returnFiber, currentFirstChild, element); + _created4.return = returnFiber; + return _created4; } } - 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(); - } + function reconcileSinglePortal( + returnFiber, + currentFirstChild, + portal, + expirationTime + ) { + var key = portal.key; + var child = currentFirstChild; + while (child !== null) { + // TODO: If key === null and child.key === null, then this only applies to + // the first item in the list. + if (child.key === key) { + if ( + child.tag === HostPortal && + child.stateNode.containerInfo === portal.containerInfo && + child.stateNode.implementation === portal.implementation + ) { + deleteRemainingChildren(returnFiber, child.sibling); + var existing = useFiber(child, portal.children || [], expirationTime); + existing.return = returnFiber; + return existing; + } else { + deleteRemainingChildren(returnFiber, child); + break; } - 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." - ); + } else { + deleteChild(returnFiber, child); } + child = child.sibling; } + + var created = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; } - function commitLifeCycles( - finishedRoot, - current, - finishedWork, - currentTime, - committedExpirationTime + // This API will tag the children with the side-effect of the reconciliation + // itself. They will be added to the side-effect list as we pass through the + // children and the parent. + function reconcileChildFibers( + returnFiber, + currentFirstChild, + newChild, + expirationTime ) { - switch (finishedWork.tag) { - case ClassComponent: { - var _instance2 = finishedWork.stateNode; - if (finishedWork.effectTag & Update) { - if (current === null) { - startPhaseTimer(finishedWork, "componentDidMount"); - _instance2.props = finishedWork.memoizedProps; - _instance2.state = finishedWork.memoizedState; - _instance2.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 - ); - stopPhaseTimer(); - } - } - var updateQueue = finishedWork.updateQueue; - if (updateQueue !== null) { - _instance2.props = finishedWork.memoizedProps; - _instance2.state = finishedWork.memoizedState; - commitUpdateQueue( - finishedWork, - updateQueue, - _instance2, - committedExpirationTime - ); - } - return; - } - case HostRoot: { - var _updateQueue = finishedWork.updateQueue; - if (_updateQueue !== null) { - var _instance3 = null; - if (finishedWork.child !== null) { - switch (finishedWork.child.tag) { - case HostComponent: - _instance3 = getPublicInstance(finishedWork.child.stateNode); - break; - case ClassComponent: - _instance3 = finishedWork.child.stateNode; - break; - } - } - commitUpdateQueue( - finishedWork, - _updateQueue, - _instance3, - committedExpirationTime - ); - } - return; - } - case HostComponent: { - var _instance4 = 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). - // These effects should only be committed when components are first mounted, - // aka when there is no current/alternate. - if (current === null && finishedWork.effectTag & Update) { - var type = finishedWork.type; - var props = finishedWork.memoizedProps; - commitMount(_instance4, type, props, finishedWork); - } + // This function is not recursive. + // If the top level item is an array, we treat it as a set of children, + // not as a fragment. Nested arrays on the other hand will be treated as + // fragment nodes. Recursion happens at the normal flow. - return; - } - case HostText: { - // We have no life-cycles associated with text. - return; - } - case HostPortal: { - // We have no life-cycles associated with portals. - return; - } - case Profiler: { - // We have no life-cycles associated with Profiler. - return; - } - case TimeoutComponent: { - // We have no life-cycles associated with Timeouts. - 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." - ); - } + // Handle top level unkeyed fragments as if they were arrays. + // This leads to an ambiguity between <>{[...]} and <>.... + // We treat the ambiguous cases above the same. + var isUnkeyedTopLevelFragment = + typeof newChild === "object" && + newChild !== null && + newChild.type === REACT_FRAGMENT_TYPE && + newChild.key === null; + if (isUnkeyedTopLevelFragment) { + newChild = newChild.props.children; } - } - function commitAttachRef(finishedWork) { - var ref = finishedWork.ref; - if (ref !== null) { - var _instance5 = finishedWork.stateNode; - var instanceToUse = void 0; - switch (finishedWork.tag) { - case HostComponent: - instanceToUse = getPublicInstance(_instance5); - break; - default: - 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) - ); - } - } + // Handle object types + var isObject = typeof newChild === "object" && newChild !== null; - ref.current = instanceToUse; + if (isObject) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + return placeSingleChild( + reconcileSingleElement( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ) + ); + case REACT_PORTAL_TYPE: + return placeSingleChild( + reconcileSinglePortal( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ) + ); } } - } - function commitDetachRef(current) { - var currentRef = current.ref; - if (currentRef !== null) { - if (typeof currentRef === "function") { - currentRef(null); - } else { - currentRef.current = null; - } + if (typeof newChild === "string" || typeof newChild === "number") { + return placeSingleChild( + reconcileSingleTextNode( + returnFiber, + currentFirstChild, + "" + newChild, + expirationTime + ) + ); } - } - // User-originating errors (lifecycles and refs) should not interrupt - // deletion, so don't let them throw. Host-originating errors should - // interrupt deletion, so it's okay - function commitUnmount(current) { - if (typeof onCommitUnmount === "function") { - onCommitUnmount(current); + if (isArray$1(newChild)) { + return reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); } - switch (current.tag) { - case ClassComponent: { - safelyDetachRef(current); - var _instance6 = current.stateNode; - if (typeof _instance6.componentWillUnmount === "function") { - safelyCallComponentWillUnmount(current, _instance6); - } - return; - } - case HostComponent: { - safelyDetachRef(current); - return; - } - case HostPortal: { - // TODO: this is recursive. - // We are also not using this parent because - // the portal will get pushed immediately. - if (enableMutatingReconciler && mutation) { - unmountHostComponents(current); - } else if (enablePersistentReconciler && persistence) { - emptyPortalContainer(current); - } - return; - } + if (getIteratorFn(newChild)) { + return reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); } - } - function commitNestedUnmounts(root) { - // While we're inside a removed host node we don't want to call - // removeChild on the inner nodes because they're removed by the top - // call anyway. We also want to call componentWillUnmount on all - // composites before this host node is removed from the tree. Therefore - var node = root; - while (true) { - commitUnmount(node); - // Visit children because they may contain more composite or host nodes. - // Skip portals because commitUnmount() currently visits them recursively. - if ( - node.child !== null && - // If we use mutation we drill down into portals using commitUnmount above. - // If we don't use mutation we drill down into portals here instead. - (!mutation || node.tag !== HostPortal) - ) { - node.child.return = node; - node = node.child; - continue; - } - if (node === root) { - return; + if (isObject) { + throwOnInvalidObjectType(returnFiber, newChild); + } + + { + if (typeof newChild === "function") { + warnOnFunctionType(); } - while (node.sibling === null) { - if (node.return === null || node.return === root) { - return; + } + if (typeof newChild === "undefined" && !isUnkeyedTopLevelFragment) { + // If the new child is undefined, and the return fiber is a composite + // component, throw an error. If Fiber return types are disabled, + // we already threw above. + switch (returnFiber.tag) { + case ClassComponent: { + { + var instance = returnFiber.stateNode; + if (instance.render._isMockFunction) { + // We allow auto-mocks to proceed as if they're returning null. + break; + } + } + } + // Intentionally fall through to the next case, which handles both + // functions and classes + // eslint-disable-next-lined no-fallthrough + case FunctionalComponent: { + var Component = returnFiber.type; + invariant( + false, + "%s(...): Nothing was returned from render. This usually means a " + + "return statement is missing. Or, to render nothing, " + + "return null.", + Component.displayName || Component.name || "Component" + ); } - node = node.return; } - node.sibling.return = node.return; - node = node.sibling; } - } - function detachFiber(current) { - // Cut off the return pointers to disconnect it from the tree. Ideally, we - // should clear the child pointer of the parent alternate to let this - // get GC:ed but we don't know which for sure which parent is the current - // one so we'll settle for GC:ing the subtree of this child. This child - // itself will be GC:ed when the parent updates the next time. - current.return = null; - current.child = null; - if (current.alternate) { - current.alternate.child = null; - current.alternate.return = null; - } + // Remaining cases are all treated as empty. + return deleteRemainingChildren(returnFiber, currentFirstChild); } - var emptyPortalContainer = void 0; - - if (!mutation) { - var commitContainer = void 0; - if (persistence) { - var replaceContainerChildren = persistence.replaceContainerChildren, - createContainerChildSet = persistence.createContainerChildSet; + return reconcileChildFibers; +} - emptyPortalContainer = function(current) { - var portal = current.stateNode; - var containerInfo = portal.containerInfo; +var reconcileChildFibers = ChildReconciler(true); +var mountChildFibers = ChildReconciler(false); - var emptyChildSet = createContainerChildSet(containerInfo); - replaceContainerChildren(containerInfo, emptyChildSet); - }; - commitContainer = function(finishedWork) { - switch (finishedWork.tag) { - case ClassComponent: { - return; - } - case HostComponent: { - return; - } - case HostText: { - return; - } - case HostRoot: - case HostPortal: { - var portalOrRoot = finishedWork.stateNode; - var containerInfo = portalOrRoot.containerInfo, - _pendingChildren = portalOrRoot.pendingChildren; +function cloneChildFibers(current, workInProgress) { + invariant( + current === null || workInProgress.child === current.child, + "Resuming work not yet implemented." + ); - replaceContainerChildren(containerInfo, _pendingChildren); - 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." - ); - } - } - }; - } else { - commitContainer = function(finishedWork) { - // Noop - }; - } - if (enablePersistentReconciler || enableNoopReconciler) { - return { - commitResetTextContent: function(finishedWork) {}, - commitPlacement: function(finishedWork) {}, - commitDeletion: function(current) { - // Detach refs and call componentWillUnmount() on the whole subtree. - commitNestedUnmounts(current); - detachFiber(current); - }, - commitWork: function(current, finishedWork) { - commitContainer(finishedWork); - }, - - commitLifeCycles: commitLifeCycles, - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, - commitAttachRef: commitAttachRef, - commitDetachRef: commitDetachRef - }; - } else if (persistence) { - invariant(false, "Persistent reconciler is disabled."); - } else { - invariant(false, "Noop reconciler is disabled."); - } + if (workInProgress.child === null) { + return; } - var commitMount = mutation.commitMount, - commitUpdate = mutation.commitUpdate, - resetTextContent = mutation.resetTextContent, - commitTextUpdate = mutation.commitTextUpdate, - appendChild = mutation.appendChild, - appendChildToContainer = mutation.appendChildToContainer, - insertBefore = mutation.insertBefore, - insertInContainerBefore = mutation.insertInContainerBefore, - removeChild = mutation.removeChild, - removeChildFromContainer = mutation.removeChildFromContainer; - function getHostParentFiber(fiber) { - var parent = fiber.return; - while (parent !== null) { - if (isHostParent(parent)) { - return parent; - } - parent = parent.return; - } - invariant( - false, - "Expected to find a host parent. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - } + var currentChild = workInProgress.child; + var newChild = createWorkInProgress( + currentChild, + currentChild.pendingProps, + currentChild.expirationTime + ); + workInProgress.child = newChild; - function isHostParent(fiber) { - return ( - fiber.tag === HostComponent || - fiber.tag === HostRoot || - fiber.tag === HostPortal + newChild.return = workInProgress; + while (currentChild.sibling !== null) { + currentChild = currentChild.sibling; + newChild = newChild.sibling = createWorkInProgress( + currentChild, + currentChild.pendingProps, + currentChild.expirationTime ); + newChild.return = workInProgress; } + newChild.sibling = null; +} - function getHostSibling(fiber) { - // We're going to search forward into the tree until we find a sibling host - // node. Unfortunately, if multiple insertions are done in a row we have to - // search past them. This leads to exponential search for the next sibling. - var node = fiber; - siblings: while (true) { - // If we didn't find anything, let's try the next sibling. - while (node.sibling === null) { - if (node.return === null || isHostParent(node.return)) { - // If we pop out of the root or hit the parent the fiber we are the - // last sibling. - return null; - } - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - while (node.tag !== HostComponent && node.tag !== HostText) { - // If it is not host node and, we might have a host node inside it. - // Try to search down until we find one. - if (node.effectTag & Placement) { - // If we don't have a child, try the siblings instead. - continue siblings; - } - // If we don't have a child, try the siblings instead. - // We also skip portals because they are not part of this host tree. - if (node.child === null || node.tag === HostPortal) { - continue siblings; - } else { - node.child.return = node; - node = node.child; - } - } - // Check if this host node is stable or about to be placed. - if (!(node.effectTag & Placement)) { - // Found it! - return node.stateNode; - } - } - } - - function commitPlacement(finishedWork) { - // Recursively insert all host nodes into the parent. - var parentFiber = getHostParentFiber(finishedWork); - var parent = void 0; - var isContainer = void 0; - switch (parentFiber.tag) { - case HostComponent: - parent = parentFiber.stateNode; - isContainer = false; - break; - case HostRoot: - parent = parentFiber.stateNode.containerInfo; - isContainer = true; - break; - case HostPortal: - parent = parentFiber.stateNode.containerInfo; - isContainer = true; - break; - default: - invariant( - false, - "Invalid host parent fiber. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - } - if (parentFiber.effectTag & ContentReset) { - // Reset the text content of the parent before doing any insertions - resetTextContent(parent); - // Clear ContentReset from the effect tag - parentFiber.effectTag &= ~ContentReset; - } +// The deepest Fiber on the stack involved in a hydration context. +// This may have been an insertion or a hydration. +var hydrationParentFiber = null; +var nextHydratableInstance = null; +var isHydrating = false; - var before = getHostSibling(finishedWork); - // We only have the top Fiber that was inserted but we need recurse down its - // children to find all the terminal nodes. - var node = finishedWork; - while (true) { - if (node.tag === HostComponent || node.tag === HostText) { - if (before) { - if (isContainer) { - insertInContainerBefore(parent, node.stateNode, before); - } else { - insertBefore(parent, node.stateNode, before); - } - } else { - if (isContainer) { - appendChildToContainer(parent, node.stateNode); - } else { - appendChild(parent, node.stateNode); - } - } - } else if (node.tag === HostPortal) { - // If the insertion itself is a portal, then we don't want to traverse - // down its children. Instead, we'll get insertions from each child in - // the portal directly. - } else if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; - } - if (node === finishedWork) { - return; - } - while (node.sibling === null) { - if (node.return === null || node.return === finishedWork) { - return; - } - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } +function enterHydrationState(fiber) { + if (!supportsHydration) { + return false; } - function unmountHostComponents(current) { - // We only have the top Fiber that was inserted but we need recurse down its - var node = current; - - // Each iteration, currentParent is populated with node's host parent if not - // currentParentIsValid. - var currentParentIsValid = false; - var currentParent = void 0; - var currentParentIsContainer = void 0; - - while (true) { - if (!currentParentIsValid) { - var parent = node.return; - findParent: while (true) { - invariant( - parent !== null, - "Expected to find a host parent. This error is likely caused by " + - "a bug in React. Please file an issue." - ); - switch (parent.tag) { - case HostComponent: - currentParent = parent.stateNode; - currentParentIsContainer = false; - break findParent; - case HostRoot: - currentParent = parent.stateNode.containerInfo; - currentParentIsContainer = true; - break findParent; - case HostPortal: - currentParent = parent.stateNode.containerInfo; - currentParentIsContainer = true; - break findParent; - } - parent = parent.return; - } - currentParentIsValid = true; - } + var parentInstance = fiber.stateNode.containerInfo; + nextHydratableInstance = getFirstHydratableChild(parentInstance); + hydrationParentFiber = fiber; + isHydrating = true; + return true; +} - if (node.tag === HostComponent || node.tag === HostText) { - commitNestedUnmounts(node); - // After all the children have unmounted, it is now safe to remove the - // node from the tree. - if (currentParentIsContainer) { - removeChildFromContainer(currentParent, node.stateNode); - } else { - removeChild(currentParent, node.stateNode); - } - // Don't visit children because we already visited them. - } else if (node.tag === HostPortal) { - // When we go into a portal, it becomes the parent to remove from. - // We will reassign it back when we pop the portal on the way up. - currentParent = node.stateNode.containerInfo; - // Visit children because portals might contain host components. - if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; - } - } else { - commitUnmount(node); - // Visit children because we may find more host components below. - if (node.child !== null) { - node.child.return = node; - node = node.child; - continue; - } - } - if (node === current) { - return; - } - while (node.sibling === null) { - if (node.return === null || node.return === current) { - return; - } - node = node.return; - if (node.tag === HostPortal) { - // When we go out of the portal, we need to restore the parent. - // Since we don't keep a stack of them, we will search for it. - currentParentIsValid = false; - } - } - node.sibling.return = node.return; - node = node.sibling; +function deleteHydratableInstance(returnFiber, instance) { + { + switch (returnFiber.tag) { + case HostRoot: + didNotHydrateContainerInstance( + returnFiber.stateNode.containerInfo, + instance + ); + break; + case HostComponent: + didNotHydrateInstance( + returnFiber.type, + returnFiber.memoizedProps, + returnFiber.stateNode, + instance + ); + break; } } - function commitDeletion(current) { - // Recursively delete all host nodes from the parent. - // Detach refs and call componentWillUnmount() on the whole subtree. - unmountHostComponents(current); - detachFiber(current); + var childToDelete = createFiberFromHostInstanceForDeletion(); + childToDelete.stateNode = instance; + childToDelete.return = returnFiber; + childToDelete.effectTag = Deletion; + + // This might seem like it belongs on progressedFirstDeletion. However, + // these children are not part of the reconciliation list of children. + // Even if we abort and rereconcile the children, that will try to hydrate + // again and the nodes are still in the host tree so these will be + // recreated. + if (returnFiber.lastEffect !== null) { + returnFiber.lastEffect.nextEffect = childToDelete; + returnFiber.lastEffect = childToDelete; + } else { + returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; } +} - function commitWork(current, finishedWork) { - switch (finishedWork.tag) { - case ClassComponent: { - return; +function insertNonHydratedInstance(returnFiber, fiber) { + fiber.effectTag |= Placement; + { + switch (returnFiber.tag) { + case HostRoot: { + var parentContainer = returnFiber.stateNode.containerInfo; + switch (fiber.tag) { + case HostComponent: + var type = fiber.type; + var props = fiber.pendingProps; + didNotFindHydratableContainerInstance(parentContainer, type, props); + break; + case HostText: + var text = fiber.pendingProps; + didNotFindHydratableContainerTextInstance(parentContainer, text); + break; + } + break; } case HostComponent: { - 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 - // as the newProps. The updatePayload will contain the real change in - // this case. - var oldProps = current !== null ? current.memoizedProps : newProps; - var type = finishedWork.type; - // TODO: Type the updateQueue to be specific to host components. - var updatePayload = finishedWork.updateQueue; - finishedWork.updateQueue = null; - if (updatePayload !== null) { - commitUpdate( - _instance7, - updatePayload, - type, - oldProps, - newProps, - finishedWork + var parentType = returnFiber.type; + var parentProps = returnFiber.memoizedProps; + var parentInstance = returnFiber.stateNode; + switch (fiber.tag) { + case HostComponent: + var _type = fiber.type; + var _props = fiber.pendingProps; + didNotFindHydratableInstance( + parentType, + parentProps, + parentInstance, + _type, + _props ); - } + break; + case HostText: + var _text = fiber.pendingProps; + didNotFindHydratableTextInstance( + parentType, + parentProps, + parentInstance, + _text + ); + break; } - return; - } - case HostText: { - invariant( - finishedWork.stateNode !== null, - "This should have a text node initialized. This error is likely " + - "caused by a bug in React. Please file an issue." - ); - var textInstance = finishedWork.stateNode; - var newText = finishedWork.memoizedProps; - // For hydration we reuse the update path but we treat the oldProps - // as the newProps. The updatePayload will contain the real change in - // this case. - var oldText = current !== null ? current.memoizedProps : newText; - commitTextUpdate(textInstance, oldText, newText); - return; + break; } - case HostRoot: { + default: return; - } - case Profiler: { - if (enableProfilerTimer) { - var onRender = finishedWork.memoizedProps.onRender; - onRender( - finishedWork.memoizedProps.id, - current === null ? "mount" : "update", - finishedWork.stateNode.duration, - finishedWork.treeBaseTime - ); + } + } +} - // Reset actualTime after successful commit. - // By default, we append to this time to account for errors and pauses. - finishedWork.stateNode.duration = 0; - } - return; - } - case TimeoutComponent: { - return; +function tryHydrate(fiber, nextInstance) { + switch (fiber.tag) { + case HostComponent: { + var type = fiber.type; + var props = fiber.pendingProps; + var instance = canHydrateInstance(nextInstance, type, props); + if (instance !== null) { + fiber.stateNode = instance; + return true; } - 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." - ); + return false; + } + case HostText: { + var text = fiber.pendingProps; + var textInstance = canHydrateTextInstance(nextInstance, text); + if (textInstance !== null) { + fiber.stateNode = textInstance; + return true; } + return false; } + default: + return false; } +} - function commitResetTextContent(current) { - resetTextContent(current.stateNode); +function tryToClaimNextHydratableInstance(fiber) { + if (!isHydrating) { + return; } - - if (enableMutatingReconciler) { - return { - commitBeforeMutationLifeCycles: commitBeforeMutationLifeCycles, - commitResetTextContent: commitResetTextContent, - commitPlacement: commitPlacement, - commitDeletion: commitDeletion, - commitWork: commitWork, - commitLifeCycles: commitLifeCycles, - commitAttachRef: commitAttachRef, - commitDetachRef: commitDetachRef - }; - } else { - invariant(false, "Mutating reconciler is disabled."); + var nextInstance = nextHydratableInstance; + if (!nextInstance) { + // Nothing to hydrate. Make it an insertion. + insertNonHydratedInstance(hydrationParentFiber, fiber); + isHydrating = false; + hydrationParentFiber = fiber; + return; } -}; + var firstAttemptedInstance = nextInstance; + if (!tryHydrate(fiber, nextInstance)) { + // If we can't hydrate this instance let's try the next one. + // We use this as a heuristic. It's based on intuition and not data so it + // might be flawed or unnecessary. + nextInstance = getNextHydratableSibling(firstAttemptedInstance); + if (!nextInstance || !tryHydrate(fiber, nextInstance)) { + // Nothing to hydrate. Make it an insertion. + insertNonHydratedInstance(hydrationParentFiber, fiber); + isHydrating = false; + hydrationParentFiber = fiber; + return; + } + // We matched the next one, we'll now assume that the first one was + // superfluous and we'll delete it. Since we can't eagerly delete it + // we'll have to schedule a deletion. To do that, this node needs a dummy + // fiber associated with it. + deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance); + } + hydrationParentFiber = fiber; + nextHydratableInstance = getFirstHydratableChild(nextInstance); +} -var ReactFiberUnwindWork = function( - config, - hostContext, - legacyContext, - newContext, - scheduleWork, - computeExpirationForFiber, - recalculateCurrentTime, - markLegacyErrorBoundaryAsFailed, - isAlreadyFailedLegacyErrorBoundary, - onUncaughtError, - profilerTimer, - suspendRoot, - retrySuspendedRoot +function prepareToHydrateHostInstance( + fiber, + rootContainerInstance, + hostContext ) { - var popHostContainer = hostContext.popHostContainer, - popHostContext = hostContext.popHostContext; - var popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject; - var popProvider = newContext.popProvider; - var resumeActualRenderTimerIfPaused = - profilerTimer.resumeActualRenderTimerIfPaused, - recordElapsedActualRenderTime = profilerTimer.recordElapsedActualRenderTime; - - function createRootErrorUpdate(fiber, errorInfo, expirationTime) { - var update = createUpdate(expirationTime); - // Unmount the root by rendering null. - update.tag = CaptureUpdate; - // Caution: React DevTools currently depends on this property - // being called "element". - update.payload = { element: null }; - var error = errorInfo.value; - update.callback = function() { - onUncaughtError(error); - logError(fiber, errorInfo); - }; - return update; + if (!supportsHydration) { + invariant( + false, + "Expected prepareToHydrateHostInstance() to never be called. " + + "This error is likely caused by a bug in React. Please file an issue." + ); } - function createClassErrorUpdate(fiber, errorInfo, expirationTime) { - var update = createUpdate(expirationTime); - update.tag = CaptureUpdate; - var getDerivedStateFromCatch = fiber.type.getDerivedStateFromCatch; - if ( - enableGetDerivedStateFromCatch && - typeof getDerivedStateFromCatch === "function" - ) { - var _error = errorInfo.value; - update.payload = function() { - return getDerivedStateFromCatch(_error); - }; - } - - var inst = fiber.stateNode; - if (inst !== null && typeof inst.componentDidCatch === "function") { - update.callback = function callback() { - if ( - !enableGetDerivedStateFromCatch || - getDerivedStateFromCatch !== "function" - ) { - // To preserve the preexisting retry behavior of error boundaries, - // we keep track of which ones already failed during this batch. - // This gets reset before we yield back to the browser. - // TODO: Warn in strict mode if getDerivedStateFromCatch is - // not defined. - markLegacyErrorBoundaryAsFailed(this); - } - var error = errorInfo.value; - var stack = errorInfo.stack; - logError(fiber, errorInfo); - this.componentDidCatch(error, { - componentStack: stack !== null ? stack : "" - }); - }; - } - return update; + var instance = fiber.stateNode; + var updatePayload = hydrateInstance( + instance, + fiber.type, + fiber.memoizedProps, + rootContainerInstance, + hostContext, + fiber + ); + // TODO: Type this specific to this type of component. + fiber.updateQueue = updatePayload; + // If the update payload indicates that there is a change or if there + // is a new ref we mark this as an update. + if (updatePayload !== null) { + return true; } + return false; +} - function schedulePing(finishedWork) { - // Once the promise resolves, we should try rendering the non- - // placeholder state again. - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, finishedWork); - var recoveryUpdate = createUpdate(expirationTime); - enqueueUpdate(finishedWork, recoveryUpdate, expirationTime); - scheduleWork(finishedWork, expirationTime); +function prepareToHydrateHostTextInstance(fiber) { + if (!supportsHydration) { + invariant( + false, + "Expected prepareToHydrateHostTextInstance() to never be called. " + + "This error is likely caused by a bug in React. Please file an issue." + ); } - function throwException( - root, - returnFiber, - sourceFiber, - value, - renderIsExpired, - renderExpirationTime, - currentTimeMs - ) { - // The source fiber did not complete. - sourceFiber.effectTag |= Incomplete; - // Its effect list is no longer valid. - sourceFiber.firstEffect = sourceFiber.lastEffect = null; - - if ( - enableSuspense && - value !== null && - typeof value === "object" && - typeof value.then === "function" - ) { - // This is a thenable. - var _thenable = value; - - var expirationTimeMs = expirationTimeToMs(renderExpirationTime); - var startTimeMs = expirationTimeMs - 5000; - var elapsedMs = currentTimeMs - startTimeMs; - if (elapsedMs < 0) { - elapsedMs = 0; - } - var remainingTimeMs = expirationTimeMs - currentTimeMs; - - // Find the earliest timeout of all the timeouts in the ancestor path. - // TODO: Alternatively, we could store the earliest timeout on the context - // stack, rather than searching on every suspend. - var _workInProgress = returnFiber; - var earliestTimeoutMs = -1; - searchForEarliestTimeout: do { - if (_workInProgress.tag === TimeoutComponent) { - var current = _workInProgress.alternate; - if (current !== null && current.memoizedState === true) { - // A parent Timeout already committed in a placeholder state. We - // need to handle this promise immediately. In other words, we - // should never suspend inside a tree that already expired. - earliestTimeoutMs = 0; - break searchForEarliestTimeout; + var textInstance = fiber.stateNode; + var textContent = fiber.memoizedProps; + var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber); + { + if (shouldUpdate) { + // We assume that prepareToHydrateHostTextInstance is called in a context where the + // hydration parent is the parent host component of this host text. + var returnFiber = hydrationParentFiber; + if (returnFiber !== null) { + switch (returnFiber.tag) { + case HostRoot: { + var parentContainer = returnFiber.stateNode.containerInfo; + didNotMatchHydratedContainerTextInstance( + parentContainer, + textInstance, + textContent + ); + break; } - var timeoutPropMs = _workInProgress.pendingProps.ms; - if (typeof timeoutPropMs === "number") { - if (timeoutPropMs <= 0) { - earliestTimeoutMs = 0; - break searchForEarliestTimeout; - } else if ( - earliestTimeoutMs === -1 || - timeoutPropMs < earliestTimeoutMs - ) { - earliestTimeoutMs = timeoutPropMs; - } - } else if (earliestTimeoutMs === -1) { - earliestTimeoutMs = remainingTimeMs; + case HostComponent: { + var parentType = returnFiber.type; + var parentProps = returnFiber.memoizedProps; + var parentInstance = returnFiber.stateNode; + didNotMatchHydratedTextInstance( + parentType, + parentProps, + parentInstance, + textInstance, + textContent + ); + break; } } - _workInProgress = _workInProgress.return; - } while (_workInProgress !== null); - - // Compute the remaining time until the timeout. - var msUntilTimeout = earliestTimeoutMs - elapsedMs; - - if (renderExpirationTime === Never || msUntilTimeout > 0) { - // There's still time remaining. - suspendRoot(root, _thenable, msUntilTimeout, renderExpirationTime); - var onResolveOrReject = function() { - retrySuspendedRoot(root, renderExpirationTime); - }; - _thenable.then(onResolveOrReject, onResolveOrReject); - return; - } else { - // No time remaining. Need to fallback to placeholder. - // Find the nearest timeout that can be retried. - _workInProgress = returnFiber; - do { - switch (_workInProgress.tag) { - case HostRoot: { - // The root expired, but no fallback was provided. Throw a - // helpful error. - var message = - renderExpirationTime === Sync - ? "A synchronous update was suspended, but no fallback UI " + - "was provided." - : "An update was suspended for longer than the timeout, " + - "but no fallback UI was provided."; - value = new Error(message); - break; - } - case TimeoutComponent: { - if ((_workInProgress.effectTag & DidCapture) === NoEffect) { - _workInProgress.effectTag |= ShouldCapture; - var _onResolveOrReject = schedulePing.bind( - null, - _workInProgress - ); - _thenable.then(_onResolveOrReject, _onResolveOrReject); - return; - } - // Already captured during this render. Continue to the next - // Timeout ancestor. - break; - } - } - _workInProgress = _workInProgress.return; - } while (_workInProgress !== null); } } + } + return shouldUpdate; +} - // We didn't find a boundary that could handle this type of exception. Start - // over and traverse parent path again, this time treating the exception - // as an error. - value = createCapturedValue(value, sourceFiber); - var workInProgress = returnFiber; - do { - switch (workInProgress.tag) { - case HostRoot: { - var _errorInfo = value; - workInProgress.effectTag |= ShouldCapture; - var update = createRootErrorUpdate( - workInProgress, - _errorInfo, - renderExpirationTime - ); - enqueueCapturedUpdate(workInProgress, update, renderExpirationTime); - return; - } - case ClassComponent: - // Capture and retry - var errorInfo = value; - var ctor = workInProgress.type; - var _instance = workInProgress.stateNode; - if ( - (workInProgress.effectTag & DidCapture) === NoEffect && - ((typeof ctor.getDerivedStateFromCatch === "function" && - enableGetDerivedStateFromCatch) || - (_instance !== null && - typeof _instance.componentDidCatch === "function" && - !isAlreadyFailedLegacyErrorBoundary(_instance))) - ) { - workInProgress.effectTag |= ShouldCapture; - // Schedule the error boundary to re-render using updated state - var _update = createClassErrorUpdate( - workInProgress, - errorInfo, - renderExpirationTime - ); - enqueueCapturedUpdate( - workInProgress, - _update, - renderExpirationTime - ); - return; - } - break; - default: - break; - } - workInProgress = workInProgress.return; - } while (workInProgress !== null); +function popToNextHostParent(fiber) { + var parent = fiber.return; + while ( + parent !== null && + parent.tag !== HostComponent && + parent.tag !== HostRoot + ) { + parent = parent.return; } + hydrationParentFiber = parent; +} - function unwindWork(workInProgress, renderIsExpired, renderExpirationTime) { - switch (workInProgress.tag) { - case ClassComponent: { - popLegacyContextProvider(workInProgress); - var effectTag = workInProgress.effectTag; - if (effectTag & ShouldCapture) { - workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture; - return workInProgress; - } - return null; - } - case HostRoot: { - popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); - var _effectTag = workInProgress.effectTag; - if (_effectTag & ShouldCapture) { - workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture; - return workInProgress; - } - return null; - } - case HostComponent: { - popHostContext(workInProgress); - return null; - } - case TimeoutComponent: { - var _effectTag2 = workInProgress.effectTag; - if (_effectTag2 & ShouldCapture) { - workInProgress.effectTag = - (_effectTag2 & ~ShouldCapture) | DidCapture; - return workInProgress; - } - return null; - } - case HostPortal: - popHostContainer(workInProgress); - return null; - case ContextProvider: - popProvider(workInProgress); - return null; - default: - return null; - } +function popHydrationState(fiber) { + if (!supportsHydration) { + return false; + } + if (fiber !== hydrationParentFiber) { + // We're deeper than the current hydration context, inside an inserted + // tree. + return false; + } + if (!isHydrating) { + // If we're not currently hydrating but we're in a hydration context, then + // we were an insertion and now need to pop up reenter hydration of our + // siblings. + popToNextHostParent(fiber); + isHydrating = true; + return false; } - 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; - case Profiler: - if (enableProfilerTimer) { - // Resume in case we're picking up on work that was paused. - resumeActualRenderTimerIfPaused(); - recordElapsedActualRenderTime(interruptedWork); - } - break; - default: - break; + var type = fiber.type; + + // If we have any remaining hydratable nodes, we need to delete them now. + // We only do this deeper than head and body since they tend to have random + // other nodes in them. We also ignore components with pure text content in + // side of them. + // TODO: Better heuristic. + if ( + fiber.tag !== HostComponent || + (type !== "head" && + type !== "body" && + !shouldSetTextContent(type, fiber.memoizedProps)) + ) { + var nextInstance = nextHydratableInstance; + while (nextInstance) { + deleteHydratableInstance(fiber, nextInstance); + nextInstance = getNextHydratableSibling(nextInstance); } } - return { - throwException: throwException, - unwindWork: unwindWork, - unwindInterruptedWork: unwindInterruptedWork, - createRootErrorUpdate: createRootErrorUpdate, - createClassErrorUpdate: createClassErrorUpdate - }; -}; + popToNextHostParent(fiber); + nextHydratableInstance = hydrationParentFiber + ? getNextHydratableSibling(fiber.stateNode) + : null; + return true; +} + +function resetHydrationState() { + if (!supportsHydration) { + return; + } + + hydrationParentFiber = null; + nextHydratableInstance = null; + isHydrating = false; +} + +var getCurrentFiberStackAddendum$1 = + ReactDebugCurrentFiber.getCurrentFiberStackAddendum; + +var didWarnAboutBadClass = void 0; +var didWarnAboutGetDerivedStateOnFunctionalComponent = void 0; +var didWarnAboutStatelessRefs = void 0; -var NO_CONTEXT = {}; +{ + didWarnAboutBadClass = {}; + didWarnAboutGetDerivedStateOnFunctionalComponent = {}; + didWarnAboutStatelessRefs = {}; +} -var ReactFiberHostContext = function(config, stack) { - var getChildHostContext = config.getChildHostContext, - getRootHostContext = config.getRootHostContext; - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; +// TODO: Remove this and use reconcileChildrenAtExpirationTime directly. +function reconcileChildren(current, workInProgress, nextChildren) { + reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + workInProgress.expirationTime + ); +} - var contextStackCursor = createCursor(NO_CONTEXT); - var contextFiberStackCursor = createCursor(NO_CONTEXT); - var rootInstanceStackCursor = createCursor(NO_CONTEXT); +function reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime +) { + if (current === null) { + // If this is a fresh new component that hasn't been rendered yet, we + // won't update its child set by applying minimal side-effects. Instead, + // we will add them all to the child before it gets rendered. That means + // we can optimize this reconciliation pass by not tracking side-effects. + workInProgress.child = mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ); + } else { + // If the current child is the same as the work in progress, it means that + // we haven't yet started any work on these children. Therefore, we use + // the clone algorithm to create a copy of all the current children. - function requiredContext(c) { - invariant( - c !== NO_CONTEXT, - "Expected host context to exist. This error is likely caused by a bug " + - "in React. Please file an issue." + // If we had any progressed work already, that is invalid at this point so + // let's throw it out. + workInProgress.child = reconcileChildFibers( + workInProgress, + current.child, + nextChildren, + renderExpirationTime ); - return c; } +} - function getRootHostContainer() { - var rootInstance = requiredContext(rootInstanceStackCursor.current); - return rootInstance; +function updateForwardRef(current, workInProgress) { + var render = workInProgress.type.render; + var nextProps = workInProgress.pendingProps; + var ref = workInProgress.ref; + 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) { + var currentRef = current !== null ? current.ref : null; + if (ref === currentRef) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } } - function pushHostContainer(fiber, nextRootInstance) { - // Push current root instance onto the stack; - // This allows us to reset root when portals are popped. - push(rootInstanceStackCursor, nextRootInstance, fiber); - // Track the context and the Fiber that provided it. - // This enables us to pop only Fibers that provide unique contexts. - push(contextFiberStackCursor, fiber, fiber); - - // Finally, we need to push the host context to the stack. - // However, we can't just call getRootHostContext() and push it because - // we'd have a different number of entries on the stack depending on - // whether getRootHostContext() throws somewhere in renderer code or not. - // So we push an empty value first. This lets us safely unwind on errors. - push(contextStackCursor, 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); + var nextChildren = void 0; + { + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase("render"); + nextChildren = render(nextProps, ref); + ReactDebugCurrentFiber.setCurrentPhase(null); } - function popHostContainer(fiber) { - pop(contextStackCursor, fiber); - pop(contextFiberStackCursor, fiber); - pop(rootInstanceStackCursor, fiber); - } + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextProps); + return workInProgress.child; +} - function getHostContext() { - var context = requiredContext(contextStackCursor.current); - return context; +function updateFragment(current, workInProgress) { + var nextChildren = workInProgress.pendingProps; + 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) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextChildren); + return workInProgress.child; +} - function pushHostContext(fiber) { - var rootInstance = requiredContext(rootInstanceStackCursor.current); - var context = requiredContext(contextStackCursor.current); - var nextContext = getChildHostContext(context, fiber.type, rootInstance); +function updateMode(current, workInProgress) { + var nextChildren = workInProgress.pendingProps.children; + 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 ( + nextChildren === null || + workInProgress.memoizedProps === nextChildren + ) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextChildren); + return workInProgress.child; +} - // Don't push this Fiber's context unless it's unique. - if (context === nextContext) { - return; - } +function updateProfiler(current, workInProgress) { + var nextProps = workInProgress.pendingProps; + if (enableProfilerTimer) { + workInProgress.effectTag |= Update; + } + if (workInProgress.memoizedProps === nextProps) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + var nextChildren = nextProps.children; + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextProps); + return workInProgress.child; +} - // Track the context and the Fiber that provided it. - // This enables us to pop only Fibers that provide unique contexts. - push(contextFiberStackCursor, fiber, fiber); - push(contextStackCursor, nextContext, fiber); +function markRef(current, workInProgress) { + var ref = workInProgress.ref; + if ( + (current === null && ref !== null) || + (current !== null && current.ref !== ref) + ) { + // Schedule a Ref effect + workInProgress.effectTag |= Ref; } +} - function popHostContext(fiber) { - // Do not pop unless this Fiber provided the current context. - // pushHostContext() only pushes Fibers that provide unique contexts. - if (contextFiberStackCursor.current !== fiber) { - return; - } +function updateFunctionalComponent(current, workInProgress) { + var fn = workInProgress.type; + var nextProps = workInProgress.pendingProps; - pop(contextStackCursor, fiber); - pop(contextFiberStackCursor, fiber); + 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) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + // TODO: consider bringing fn.shouldComponentUpdate() back. + // It used to be here. } - return { - getHostContext: getHostContext, - getRootHostContainer: getRootHostContainer, - popHostContainer: popHostContainer, - popHostContext: popHostContext, - pushHostContainer: pushHostContainer, - pushHostContext: pushHostContext - }; -}; - -var ReactFiberHydrationContext = function(config) { - var shouldSetTextContent = config.shouldSetTextContent, - hydration = config.hydration; + var unmaskedContext = getUnmaskedContext(workInProgress); + var context = getMaskedContext(workInProgress, unmaskedContext); - // If this doesn't have hydration mode. + var nextChildren = void 0; - if (!hydration) { - return { - enterHydrationState: function() { - return false; - }, - resetHydrationState: function() {}, - tryToClaimNextHydratableInstance: function() {}, - prepareToHydrateHostInstance: function() { - invariant( - false, - "Expected prepareToHydrateHostInstance() to never be called. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - }, - prepareToHydrateHostTextInstance: function() { - invariant( - false, - "Expected prepareToHydrateHostTextInstance() to never be called. " + - "This error is likely caused by a bug in React. Please file an issue." - ); - }, - popHydrationState: function(fiber) { - return false; - } - }; - } + { + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase("render"); + nextChildren = fn(nextProps, context); + ReactDebugCurrentFiber.setCurrentPhase(null); + } + // React DevTools reads this flag. + workInProgress.effectTag |= PerformedWork; + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextProps); + return workInProgress.child; +} + +function updateClassComponent(current, workInProgress, renderExpirationTime) { + // 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 = pushContextProvider(workInProgress); + var shouldUpdate = void 0; + if (current === null) { + if (workInProgress.stateNode === null) { + // In the initial pass we might need to construct the instance. + constructClassInstance( + workInProgress, + workInProgress.pendingProps, + renderExpirationTime + ); + mountClassInstance(workInProgress, renderExpirationTime); - var canHydrateInstance = hydration.canHydrateInstance, - canHydrateTextInstance = hydration.canHydrateTextInstance, - getNextHydratableSibling = hydration.getNextHydratableSibling, - getFirstHydratableChild = hydration.getFirstHydratableChild, - hydrateInstance = hydration.hydrateInstance, - hydrateTextInstance = hydration.hydrateTextInstance, - didNotMatchHydratedContainerTextInstance = - hydration.didNotMatchHydratedContainerTextInstance, - didNotMatchHydratedTextInstance = hydration.didNotMatchHydratedTextInstance, - didNotHydrateContainerInstance = hydration.didNotHydrateContainerInstance, - didNotHydrateInstance = hydration.didNotHydrateInstance, - didNotFindHydratableContainerInstance = - hydration.didNotFindHydratableContainerInstance, - didNotFindHydratableContainerTextInstance = - hydration.didNotFindHydratableContainerTextInstance, - didNotFindHydratableInstance = hydration.didNotFindHydratableInstance, - didNotFindHydratableTextInstance = - hydration.didNotFindHydratableTextInstance; - - // The deepest Fiber on the stack involved in a hydration context. - // This may have been an insertion or a hydration. - - var hydrationParentFiber = null; - var nextHydratableInstance = null; - var isHydrating = false; - - function enterHydrationState(fiber) { - var parentInstance = fiber.stateNode.containerInfo; - nextHydratableInstance = getFirstHydratableChild(parentInstance); - hydrationParentFiber = fiber; - isHydrating = true; - return true; + shouldUpdate = true; + } else { + // In a resume, we'll already have an instance we can reuse. + shouldUpdate = resumeMountClassInstance( + workInProgress, + renderExpirationTime + ); + } + } else { + shouldUpdate = updateClassInstance( + current, + workInProgress, + renderExpirationTime + ); } + return finishClassComponent( + current, + workInProgress, + shouldUpdate, + hasContext, + renderExpirationTime + ); +} - function deleteHydratableInstance(returnFiber, instance) { - { - switch (returnFiber.tag) { - case HostRoot: - didNotHydrateContainerInstance( - returnFiber.stateNode.containerInfo, - instance - ); - break; - case HostComponent: - didNotHydrateInstance( - returnFiber.type, - returnFiber.memoizedProps, - returnFiber.stateNode, - instance - ); - break; - } - } +function finishClassComponent( + current, + workInProgress, + shouldUpdate, + hasContext, + renderExpirationTime +) { + // Refs should update even if shouldComponentUpdate returns false + markRef(current, workInProgress); - var childToDelete = createFiberFromHostInstanceForDeletion(); - childToDelete.stateNode = instance; - childToDelete.return = returnFiber; - childToDelete.effectTag = Deletion; + var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect; - // This might seem like it belongs on progressedFirstDeletion. However, - // these children are not part of the reconciliation list of children. - // Even if we abort and rereconcile the children, that will try to hydrate - // again and the nodes are still in the host tree so these will be - // recreated. - if (returnFiber.lastEffect !== null) { - returnFiber.lastEffect.nextEffect = childToDelete; - returnFiber.lastEffect = childToDelete; - } else { - returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; + if (!shouldUpdate && !didCaptureError) { + // Context providers should defer to sCU for rendering + if (hasContext) { + invalidateContextProvider(workInProgress, false); } + + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - function insertNonHydratedInstance(returnFiber, fiber) { - fiber.effectTag |= Placement; + var ctor = workInProgress.type; + var instance = workInProgress.stateNode; + + // Rerender + ReactCurrentOwner.current = workInProgress; + var nextChildren = void 0; + if ( + didCaptureError && + (!enableGetDerivedStateFromCatch || + typeof ctor.getDerivedStateFromCatch !== "function") + ) { + // If we captured an error, but getDerivedStateFrom catch is not defined, + // unmount all the children. componentDidCatch will schedule an update to + // re-render a fallback. This is temporary until we migrate everyone to + // the new API. + // TODO: Warn in a future release. + nextChildren = null; + + if (enableProfilerTimer) { + stopBaseRenderTimerIfRunning(); + } + } else { { - switch (returnFiber.tag) { - case HostRoot: { - var parentContainer = returnFiber.stateNode.containerInfo; - switch (fiber.tag) { - case HostComponent: - var type = fiber.type; - var props = fiber.pendingProps; - didNotFindHydratableContainerInstance( - parentContainer, - type, - props - ); - break; - case HostText: - var text = fiber.pendingProps; - didNotFindHydratableContainerTextInstance(parentContainer, text); - break; - } - break; - } - case HostComponent: { - var parentType = returnFiber.type; - var parentProps = returnFiber.memoizedProps; - var parentInstance = returnFiber.stateNode; - switch (fiber.tag) { - case HostComponent: - var _type = fiber.type; - var _props = fiber.pendingProps; - didNotFindHydratableInstance( - parentType, - parentProps, - parentInstance, - _type, - _props - ); - break; - case HostText: - var _text = fiber.pendingProps; - didNotFindHydratableTextInstance( - parentType, - parentProps, - parentInstance, - _text - ); - break; - } - break; - } - default: - return; + ReactDebugCurrentFiber.setCurrentPhase("render"); + nextChildren = instance.render(); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + instance.render(); } + ReactDebugCurrentFiber.setCurrentPhase(null); } } - function tryHydrate(fiber, nextInstance) { - switch (fiber.tag) { - case HostComponent: { - var type = fiber.type; - var props = fiber.pendingProps; - var instance = canHydrateInstance(nextInstance, type, props); - if (instance !== null) { - fiber.stateNode = instance; - return true; - } - return false; - } - case HostText: { - var text = fiber.pendingProps; - var textInstance = canHydrateTextInstance(nextInstance, text); - if (textInstance !== null) { - fiber.stateNode = textInstance; - return true; - } - return false; - } - default: - return false; - } + // React DevTools reads this flag. + workInProgress.effectTag |= PerformedWork; + if (didCaptureError) { + // If we're recovering from an error, reconcile twice: first to delete + // all the existing children. + reconcileChildrenAtExpirationTime( + current, + workInProgress, + null, + renderExpirationTime + ); + workInProgress.child = null; + // Now we can continue reconciling like normal. This has the effect of + // remounting all children regardless of whether their their + // identity matches. } + reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime + ); + // Memoize props and state using the values we just used to render. + // TODO: Restructure so we never read values from the instance. + memoizeState(workInProgress, instance.state); + memoizeProps(workInProgress, instance.props); - function tryToClaimNextHydratableInstance(fiber) { - if (!isHydrating) { - return; - } - var nextInstance = nextHydratableInstance; - if (!nextInstance) { - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance(hydrationParentFiber, fiber); - isHydrating = false; - hydrationParentFiber = fiber; - return; - } - if (!tryHydrate(fiber, nextInstance)) { - // If we can't hydrate this instance let's try the next one. - // We use this as a heuristic. It's based on intuition and not data so it - // might be flawed or unnecessary. - nextInstance = getNextHydratableSibling(nextInstance); - if (!nextInstance || !tryHydrate(fiber, nextInstance)) { - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance(hydrationParentFiber, fiber); - isHydrating = false; - hydrationParentFiber = fiber; - return; - } - // We matched the next one, we'll now assume that the first one was - // superfluous and we'll delete it. Since we can't eagerly delete it - // we'll have to schedule a deletion. To do that, this node needs a dummy - // fiber associated with it. - deleteHydratableInstance(hydrationParentFiber, nextHydratableInstance); - } - hydrationParentFiber = fiber; - nextHydratableInstance = getFirstHydratableChild(nextInstance); + // The context might have changed so we need to recalculate it. + if (hasContext) { + invalidateContextProvider(workInProgress, true); } - function prepareToHydrateHostInstance( - fiber, - rootContainerInstance, - hostContext - ) { - var instance = fiber.stateNode; - var updatePayload = hydrateInstance( - instance, - fiber.type, - fiber.memoizedProps, - rootContainerInstance, - hostContext, - fiber + return workInProgress.child; +} + +function pushHostRootContext(workInProgress) { + var root = workInProgress.stateNode; + if (root.pendingContext) { + pushTopLevelContextObject( + workInProgress, + root.pendingContext, + root.pendingContext !== root.context ); - // TODO: Type this specific to this type of component. - fiber.updateQueue = updatePayload; - // If the update payload indicates that there is a change or if there - // is a new ref we mark this as an update. - if (updatePayload !== null) { - return true; - } - return false; + } else if (root.context) { + // Should always be set + pushTopLevelContextObject(workInProgress, root.context, false); } + pushHostContainer(workInProgress, root.containerInfo); +} - function prepareToHydrateHostTextInstance(fiber) { - var textInstance = fiber.stateNode; - var textContent = fiber.memoizedProps; - var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber); - { - if (shouldUpdate) { - // We assume that prepareToHydrateHostTextInstance is called in a context where the - // hydration parent is the parent host component of this host text. - var returnFiber = hydrationParentFiber; - if (returnFiber !== null) { - switch (returnFiber.tag) { - case HostRoot: { - var parentContainer = returnFiber.stateNode.containerInfo; - didNotMatchHydratedContainerTextInstance( - parentContainer, - textInstance, - textContent - ); - break; - } - case HostComponent: { - var parentType = returnFiber.type; - var parentProps = returnFiber.memoizedProps; - var parentInstance = returnFiber.stateNode; - didNotMatchHydratedTextInstance( - parentType, - parentProps, - parentInstance, - textInstance, - textContent - ); - break; - } - } - } - } - } - return shouldUpdate; - } +function updateHostRoot(current, workInProgress, renderExpirationTime) { + pushHostRootContext(workInProgress); + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + var nextProps = workInProgress.pendingProps; + var prevState = workInProgress.memoizedState; + var prevChildren = prevState !== null ? prevState.element : null; + processUpdateQueue( + workInProgress, + updateQueue, + nextProps, + null, + renderExpirationTime + ); + var nextState = workInProgress.memoizedState; + // Caution: React DevTools currently depends on this property + // being called "element". + var nextChildren = nextState.element; - function popToNextHostParent(fiber) { - var parent = fiber.return; - while ( - parent !== null && - parent.tag !== HostComponent && - parent.tag !== HostRoot + if (nextChildren === prevChildren) { + // If the state is the same as before, that's a bailout because we had + // no work that expires at this time. + resetHydrationState(); + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + var root = workInProgress.stateNode; + if ( + (current === null || current.child === null) && + root.hydrate && + enterHydrationState(workInProgress) ) { - parent = parent.return; + // If we don't have any current children this might be the first pass. + // We always try to hydrate. If this isn't a hydration pass there won't + // be any children to hydrate which is effectively the same thing as + // not hydrating. + + // This is a bit of a hack. We track the host root as a placement to + // know that we're currently in a mounting state. That way isMounted + // works as expected. We must reset this before committing. + // TODO: Delete this when we delete isMounted and findDOMNode. + workInProgress.effectTag |= Placement; + + // Ensure that children mount into this root without tracking + // side-effects. This ensures that we don't store Placement effects on + // nodes that will be hydrated. + workInProgress.child = mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ); + } else { + // Otherwise reset hydration state in case we aborted and resumed another + // root. + resetHydrationState(); + reconcileChildren(current, workInProgress, nextChildren); } - hydrationParentFiber = parent; + return workInProgress.child; } + resetHydrationState(); + // If there is no update queue, that's a bailout because the root has no props. + return bailoutOnAlreadyFinishedWork(current, workInProgress); +} - function popHydrationState(fiber) { - if (fiber !== hydrationParentFiber) { - // We're deeper than the current hydration context, inside an inserted - // tree. - return false; - } - if (!isHydrating) { - // If we're not currently hydrating but we're in a hydration context, then - // we were an insertion and now need to pop up reenter hydration of our - // siblings. - popToNextHostParent(fiber); - isHydrating = true; - return false; - } +function updateHostComponent(current, workInProgress, renderExpirationTime) { + pushHostContext(workInProgress); - var type = fiber.type; + if (current === null) { + tryToClaimNextHydratableInstance(workInProgress); + } - // If we have any remaining hydratable nodes, we need to delete them now. - // We only do this deeper than head and body since they tend to have random - // other nodes in them. We also ignore components with pure text content in - // side of them. - // TODO: Better heuristic. - if ( - fiber.tag !== HostComponent || - (type !== "head" && - type !== "body" && - !shouldSetTextContent(type, fiber.memoizedProps)) - ) { - var nextInstance = nextHydratableInstance; - while (nextInstance) { - deleteHydratableInstance(fiber, nextInstance); - nextInstance = getNextHydratableSibling(nextInstance); - } + var type = workInProgress.type; + var memoizedProps = workInProgress.memoizedProps; + var nextProps = workInProgress.pendingProps; + var prevProps = current !== null ? current.memoizedProps : null; + + 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) { + var isHidden = + workInProgress.mode & AsyncMode && + shouldDeprioritizeSubtree(type, nextProps); + if (isHidden) { + // Before bailing out, make sure we've deprioritized a hidden component. + workInProgress.expirationTime = Never; + } + if (!isHidden || renderExpirationTime !== Never) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } + // If we're rendering a hidden node at hidden priority, don't bailout. The + // parent is complete, but the children may not be. + } - popToNextHostParent(fiber); - nextHydratableInstance = hydrationParentFiber - ? getNextHydratableSibling(fiber.stateNode) - : null; - return true; + var nextChildren = nextProps.children; + var isDirectTextChild = shouldSetTextContent(type, nextProps); + + if (isDirectTextChild) { + // We special case a direct text child of a host node. This is a common + // case. We won't handle it as a reified child. We will instead handle + // this in the host environment that also have access to this prop. That + // avoids allocating another HostText fiber and traversing it. + nextChildren = null; + } else if (prevProps && shouldSetTextContent(type, prevProps)) { + // If we're switching from a direct text child to a normal child, or to + // empty, we need to schedule the text content to be reset. + workInProgress.effectTag |= ContentReset; } - function resetHydrationState() { - hydrationParentFiber = null; - nextHydratableInstance = null; - isHydrating = false; + markRef(current, workInProgress); + + // Check the host config to see if the children are offscreen/hidden. + if ( + renderExpirationTime !== Never && + workInProgress.mode & AsyncMode && + shouldDeprioritizeSubtree(type, nextProps) + ) { + // Down-prioritize the children. + workInProgress.expirationTime = Never; + // Bailout and come back to this fiber later. + workInProgress.memoizedProps = nextProps; + return null; } - return { - enterHydrationState: enterHydrationState, - resetHydrationState: resetHydrationState, - tryToClaimNextHydratableInstance: tryToClaimNextHydratableInstance, - prepareToHydrateHostInstance: prepareToHydrateHostInstance, - prepareToHydrateHostTextInstance: prepareToHydrateHostTextInstance, - popHydrationState: popHydrationState - }; -}; + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextProps); + return workInProgress.child; +} -// This lets us hook into Fiber to debug what it's doing. -// See https://github.com/facebook/react/pull/8033. -// This is not part of the public API, not even for React DevTools. -// You may only inject a debugTool if you work on React Fiber itself. -var ReactFiberInstrumentation = { - debugTool: null -}; +function updateHostText(current, workInProgress) { + if (current === null) { + tryToClaimNextHydratableInstance(workInProgress); + } + var nextProps = workInProgress.pendingProps; + memoizeProps(workInProgress, nextProps); + // Nothing to do here. This is terminal. We'll do the completion step + // immediately after. + return null; +} -var ReactFiberInstrumentation_1 = ReactFiberInstrumentation; +function mountIndeterminateComponent( + current, + workInProgress, + renderExpirationTime +) { + invariant( + current === null, + "An indeterminate component should never have mounted. This error is " + + "likely caused by a bug in React. Please file an issue." + ); + var fn = workInProgress.type; + var props = workInProgress.pendingProps; + var unmaskedContext = getUnmaskedContext(workInProgress); + var context = getMaskedContext(workInProgress, unmaskedContext); -// TODO: Offscreen updates + var value = void 0; -function markPendingPriorityLevel(root, expirationTime) { - if (enableSuspense) { - // Update the latest and earliest pending times - var earliestPendingTime = root.earliestPendingTime; - if (earliestPendingTime === NoWork) { - // No other pending updates. - root.earliestPendingTime = root.latestPendingTime = expirationTime; - } else { - if (earliestPendingTime > expirationTime) { - // This is the earliest pending update. - root.earliestPendingTime = expirationTime; - } else { - var latestPendingTime = root.latestPendingTime; - if (latestPendingTime < expirationTime) { - // This is the latest pending update - root.latestPendingTime = expirationTime; - } + { + if (fn.prototype && typeof fn.prototype.render === "function") { + var componentName = getComponentName(workInProgress) || "Unknown"; + + if (!didWarnAboutBadClass[componentName]) { + warning( + false, + "The <%s /> component appears to have a render method, but doesn't extend React.Component. " + + "This is likely to cause errors. Change %s to extend React.Component instead.", + componentName, + componentName + ); + didWarnAboutBadClass[componentName] = true; } } - } -} -function markCommittedPriorityLevels(root, currentTime, earliestRemainingTime) { - if (enableSuspense) { - if (earliestRemainingTime === NoWork) { - // Fast path. There's no remaining work. Clear everything. - root.earliestPendingTime = NoWork; - root.latestPendingTime = NoWork; - root.earliestSuspendedTime = NoWork; - root.latestSuspendedTime = NoWork; - root.latestPingedTime = NoWork; - return; + if (workInProgress.mode & StrictMode) { + ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null); } - // Let's see if the previous latest known pending level was just flushed. - var latestPendingTime = root.latestPendingTime; - if (latestPendingTime !== NoWork) { - if (latestPendingTime < earliestRemainingTime) { - // We've flushed all the known pending levels. - root.earliestPendingTime = root.latestPendingTime = NoWork; - } else { - var earliestPendingTime = root.earliestPendingTime; - if (earliestPendingTime < earliestRemainingTime) { - // We've flushed the earliest known pending level. Set this to the - // latest pending time. - root.earliestPendingTime = root.latestPendingTime; - } - } - } + ReactCurrentOwner.current = workInProgress; + value = fn(props, context); + } + // React DevTools reads this flag. + workInProgress.effectTag |= PerformedWork; - // Now let's handle the earliest remaining level in the whole tree. We need to - // decide whether to treat it as a pending level or as suspended. Check - // it falls within the range of known suspended levels. + if ( + typeof value === "object" && + value !== null && + typeof value.render === "function" && + value.$$typeof === undefined + ) { + var Component = workInProgress.type; - var earliestSuspendedTime = root.earliestSuspendedTime; - if (earliestSuspendedTime === NoWork) { - // There's no suspended work. Treat the earliest remaining level as a - // pending level. - markPendingPriorityLevel(root, earliestRemainingTime); - return; - } + // Proceed under the assumption that this is a class instance + workInProgress.tag = ClassComponent; - var latestSuspendedTime = root.latestSuspendedTime; - if (earliestRemainingTime > latestSuspendedTime) { - // The earliest remaining level is later than all the suspended work. That - // means we've flushed all the suspended work. - root.earliestSuspendedTime = NoWork; - root.latestSuspendedTime = NoWork; - root.latestPingedTime = NoWork; + workInProgress.memoizedState = + value.state !== null && value.state !== undefined ? value.state : null; - // There's no suspended work. Treat the earliest remaining level as a - // pending level. - markPendingPriorityLevel(root, earliestRemainingTime); - return; + var getDerivedStateFromProps = Component.getDerivedStateFromProps; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + props + ); } - if (earliestRemainingTime < earliestSuspendedTime) { - // The earliest remaining time is earlier than all the suspended work. - // Treat it as a pending update. - markPendingPriorityLevel(root, earliestRemainingTime); - return; - } + // 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 = pushContextProvider(workInProgress); + adoptClassInstance(workInProgress, value); + mountClassInstance(workInProgress, renderExpirationTime); + return finishClassComponent( + current, + workInProgress, + true, + hasContext, + renderExpirationTime + ); + } else { + // Proceed under the assumption that this is a functional component + workInProgress.tag = FunctionalComponent; + { + var _Component = workInProgress.type; - // The earliest remaining time falls within the range of known suspended - // levels. We should treat this as suspended work. - } -} + if (_Component) { + !!_Component.childContextTypes + ? warning( + false, + "%s(...): childContextTypes cannot be defined on a functional component.", + _Component.displayName || _Component.name || "Component" + ) + : void 0; + } + if (workInProgress.ref !== null) { + var info = ""; + var ownerName = ReactDebugCurrentFiber.getCurrentFiberOwnerName(); + if (ownerName) { + info += "\n\nCheck the render method of `" + ownerName + "`."; + } -function markSuspendedPriorityLevel(root, suspendedTime) { - if (enableSuspense) { - // First, check the known pending levels and update them if needed. - var earliestPendingTime = root.earliestPendingTime; - var latestPendingTime = root.latestPendingTime; - if (earliestPendingTime === suspendedTime) { - if (latestPendingTime === suspendedTime) { - // Both known pending levels were suspended. Clear them. - root.earliestPendingTime = root.latestPendingTime = NoWork; - } else { - // The earliest pending level was suspended. Clear by setting it to the - // latest pending level. - root.earliestPendingTime = latestPendingTime; + var warningKey = ownerName || workInProgress._debugID || ""; + var debugSource = workInProgress._debugSource; + if (debugSource) { + warningKey = debugSource.fileName + ":" + debugSource.lineNumber; + } + if (!didWarnAboutStatelessRefs[warningKey]) { + didWarnAboutStatelessRefs[warningKey] = true; + warning( + false, + "Stateless function components cannot be given refs. " + + "Attempts to access this ref will fail.%s%s", + info, + ReactDebugCurrentFiber.getCurrentFiberStackAddendum() + ); + } } - } else if (latestPendingTime === suspendedTime) { - // The latest pending level was suspended. Clear by setting it to the - // latest pending level. - root.latestPendingTime = earliestPendingTime; - } - // Next, if we're working on the lowest known suspended level, clear the ping. - // TODO: What if a promise suspends and pings before the root completes? - var latestSuspendedTime = root.latestSuspendedTime; - if (latestSuspendedTime === suspendedTime) { - root.latestPingedTime = NoWork; - } + if (typeof fn.getDerivedStateFromProps === "function") { + var _componentName = getComponentName(workInProgress) || "Unknown"; - // Finally, update the known suspended levels. - var earliestSuspendedTime = root.earliestSuspendedTime; - if (earliestSuspendedTime === NoWork) { - // No other suspended levels. - root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime; - } else { - if (earliestSuspendedTime > suspendedTime) { - // This is the earliest suspended level. - root.earliestSuspendedTime = suspendedTime; - } else if (latestSuspendedTime < suspendedTime) { - // This is the latest suspended level - root.latestSuspendedTime = suspendedTime; + if (!didWarnAboutGetDerivedStateOnFunctionalComponent[_componentName]) { + warning( + false, + "%s: Stateless functional components do not support getDerivedStateFromProps.", + _componentName + ); + didWarnAboutGetDerivedStateOnFunctionalComponent[ + _componentName + ] = true; + } } } + reconcileChildren(current, workInProgress, value); + memoizeProps(workInProgress, props); + return workInProgress.child; } } -function markPingedPriorityLevel(root, pingedTime) { +function updateTimeoutComponent(current, workInProgress, renderExpirationTime) { if (enableSuspense) { - var latestSuspendedTime = root.latestSuspendedTime; - if (latestSuspendedTime !== NoWork && latestSuspendedTime <= pingedTime) { - var latestPingedTime = root.latestPingedTime; - if (latestPingedTime === NoWork || latestPingedTime < pingedTime) { - root.latestPingedTime = pingedTime; - } - } - } -} + var nextProps = workInProgress.pendingProps; + var prevProps = workInProgress.memoizedProps; -function findNextPendingPriorityLevel(root) { - if (enableSuspense) { - var earliestSuspendedTime = root.earliestSuspendedTime; - var earliestPendingTime = root.earliestPendingTime; - if (earliestSuspendedTime === NoWork) { - // Fast path. There's no suspended work. - return earliestPendingTime; - } + var prevDidTimeout = workInProgress.memoizedState; - // First, check if there's known pending work. - if (earliestPendingTime !== NoWork) { - return earliestPendingTime; + // Check if we already attempted to render the normal state. If we did, + // and we timed out, render the placeholder state. + var alreadyCaptured = (workInProgress.effectTag & DidCapture) === NoEffect; + var nextDidTimeout = !alreadyCaptured; + + 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 (nextProps === prevProps && nextDidTimeout === prevDidTimeout) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } - // Finally, if a suspended level was pinged, work on that. Otherwise there's - // nothing to work on. - return root.latestPingedTime; + var render = nextProps.children; + var nextChildren = render(nextDidTimeout); + workInProgress.memoizedProps = nextProps; + workInProgress.memoizedState = nextDidTimeout; + reconcileChildren(current, workInProgress, nextChildren); + return workInProgress.child; } else { - return root.current.expirationTime; + return null; } } -var warnedAboutMissingGetChildContext = void 0; +function updatePortalComponent(current, workInProgress, renderExpirationTime) { + pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo); + var nextChildren = workInProgress.pendingProps; + 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) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } -{ - warnedAboutMissingGetChildContext = {}; + if (current === null) { + // Portals are special because we don't append the children during mount + // but at commit. Therefore we need to track insertions which the normal + // flow doesn't do during mount. This doesn't happen at the root because + // the root always starts with a "current" with a null child. + // TODO: Consider unifying this with how the root works. + workInProgress.child = reconcileChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ); + memoizeProps(workInProgress, nextChildren); + } else { + reconcileChildren(current, workInProgress, nextChildren); + memoizeProps(workInProgress, nextChildren); + } + return workInProgress.child; } -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; +function propagateContextChange( + workInProgress, + context, + changedBits, + 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. + switch (fiber.tag) { + case ContextConsumer: + // Check if the context matches. + var observedBits = fiber.stateNode | 0; + if (fiber.type === context && (observedBits & changedBits) !== 0) { + // Update the expiration time of all the ancestors, including + // the alternates. + var node = fiber; + while (node !== null) { + var alternate = node.alternate; + if ( + node.expirationTime === NoWork || + node.expirationTime > renderExpirationTime + ) { + node.expirationTime = renderExpirationTime; + if ( + alternate !== null && + (alternate.expirationTime === NoWork || + alternate.expirationTime > renderExpirationTime) + ) { + alternate.expirationTime = renderExpirationTime; + } + } else if ( + alternate !== null && + (alternate.expirationTime === NoWork || + alternate.expirationTime > renderExpirationTime) + ) { + alternate.expirationTime = renderExpirationTime; + } else { + // Neither alternate was updated, which means the rest of the + // ancestor path already has sufficient priority. + break; + } + node = node.return; + } + // Don't scan deeper than a matching consumer. When we render the + // consumer, we'll continue scanning from that point. This way the + // scanning work is time-sliced. + nextFiber = null; + } else { + // Traverse down. + nextFiber = fiber.child; + } + break; + case ContextProvider: + // Don't scan deeper if this is a matching provider + nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + break; + default: + // Traverse down. + nextFiber = fiber.child; + break; + } + if (nextFiber !== null) { + // Set the return pointer of the child to the work-in-progress fiber. + nextFiber.return = fiber; + } else { + // No child. Traverse to next sibling. + nextFiber = fiber; + while (nextFiber !== null) { + if (nextFiber === workInProgress) { + // We're back to the root of this subtree. Exit. + nextFiber = null; + break; + } + var sibling = nextFiber.sibling; + if (sibling !== null) { + // Set the return pointer of the sibling to the work-in-progress fiber. + sibling.return = nextFiber.return; + nextFiber = sibling; + break; + } + // No more siblings. Traverse up. + nextFiber = nextFiber.return; + } } - return contextStackCursor.current; + fiber = nextFiber; } +} - function cacheContext(workInProgress, unmaskedContext, maskedContext) { - var instance = workInProgress.stateNode; - instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; - instance.__reactInternalMemoizedMaskedChildContext = maskedContext; - } +function updateContextProvider(current, workInProgress, renderExpirationTime) { + var providerType = workInProgress.type; + var context = providerType._context; - function getMaskedContext(workInProgress, unmaskedContext) { - var type = workInProgress.type; - var contextTypes = type.contextTypes; - if (!contextTypes) { - return emptyObject; - } + var newProps = workInProgress.pendingProps; + var oldProps = workInProgress.memoizedProps; + var canBailOnProps = true; - // 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; - } + if (hasContextChanged()) { + canBailOnProps = false; + // 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) { + workInProgress.stateNode = 0; + pushProvider(workInProgress); + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } - var context = {}; - for (var key in contextTypes) { - context[key] = unmaskedContext[key]; - } + var newValue = newProps.value; + workInProgress.memoizedProps = newProps; - { - var name = getComponentName(workInProgress) || "Unknown"; + { + var providerPropTypes = workInProgress.type.propTypes; + + if (providerPropTypes) { checkPropTypes( - contextTypes, - context, - "context", - name, - ReactDebugCurrentFiber.getCurrentFiberStackAddendum + providerPropTypes, + newProps, + "prop", + "Context.Provider", + getCurrentFiberStackAddendum$1 ); } + } - // 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); - } + var changedBits = void 0; + if (oldProps === null) { + // Initial render + changedBits = MAX_SIGNED_31_BIT_INT; + } else { + if (oldProps.value === newProps.value) { + // No change. Bailout early if children are the same. + if (oldProps.children === newProps.children && canBailOnProps) { + workInProgress.stateNode = 0; + pushProvider(workInProgress); + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + changedBits = 0; + } else { + var oldValue = oldProps.value; + // Use Object.is to compare the new context value to the old value. + // Inlined Object.is polyfill. + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + if ( + (oldValue === newValue && + (oldValue !== 0 || 1 / oldValue === 1 / newValue)) || + (oldValue !== oldValue && newValue !== newValue) // eslint-disable-line no-self-compare + ) { + // No change. Bailout early if children are the same. + if (oldProps.children === newProps.children && canBailOnProps) { + workInProgress.stateNode = 0; + pushProvider(workInProgress); + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + changedBits = 0; + } else { + changedBits = + typeof context._calculateChangedBits === "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; + } + changedBits |= 0; - return context; + if (changedBits === 0) { + // No change. Bailout early if children are the same. + if (oldProps.children === newProps.children && canBailOnProps) { + workInProgress.stateNode = 0; + pushProvider(workInProgress); + return bailoutOnAlreadyFinishedWork(current, workInProgress); + } + } else { + propagateContextChange( + workInProgress, + context, + changedBits, + renderExpirationTime + ); + } + } + } } - function hasContextChanged() { - return didPerformWorkStackCursor.current; + workInProgress.stateNode = changedBits; + pushProvider(workInProgress); + + var newChildren = newProps.children; + reconcileChildren(current, workInProgress, newChildren); + return workInProgress.child; +} + +function updateContextConsumer(current, workInProgress, renderExpirationTime) { + var context = workInProgress.type; + var newProps = workInProgress.pendingProps; + var oldProps = workInProgress.memoizedProps; + + var newValue = getContextCurrentValue(context); + var changedBits = getContextChangedBits(context); + + 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) { + return bailoutOnAlreadyFinishedWork(current, workInProgress); } + workInProgress.memoizedProps = newProps; - function isContextConsumer(fiber) { - return fiber.tag === ClassComponent && fiber.type.contextTypes != null; + var observedBits = newProps.unstable_observedBits; + if (observedBits === undefined || observedBits === null) { + // Subscribe to all changes by default + observedBits = MAX_SIGNED_31_BIT_INT; } + // Store the observedBits on the fiber's stateNode for quick access. + workInProgress.stateNode = observedBits; - function isContextProvider(fiber) { - return fiber.tag === ClassComponent && fiber.type.childContextTypes != null; + if ((changedBits & observedBits) !== 0) { + // Context change propagation stops at matching consumers, for time- + // slicing. Continue the propagation here. + propagateContextChange( + workInProgress, + context, + changedBits, + renderExpirationTime + ); + } else if (oldProps === newProps) { + // Skip over a memoized parent with a bitmask bailout even + // if we began working on it because of a deeper matching child. + 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`). - function popContextProvider(fiber) { - if (!isContextProvider(fiber)) { - return; - } + 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; + } - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + var newChildren = void 0; + { + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase("render"); + newChildren = render(newValue); + ReactDebugCurrentFiber.setCurrentPhase(null); } - function popTopLevelContextObject(fiber) { - pop(didPerformWorkStackCursor, fiber); - pop(contextStackCursor, fiber); + // React DevTools reads this flag. + workInProgress.effectTag |= PerformedWork; + reconcileChildren(current, workInProgress, newChildren); + return workInProgress.child; +} + +/* + function reuseChildrenEffects(returnFiber : Fiber, firstChild : Fiber) { + let child = firstChild; + do { + // Ensure that the first and last effect of the parent corresponds + // to the children's first and last effect. + if (!returnFiber.firstEffect) { + returnFiber.firstEffect = child.firstEffect; + } + if (child.lastEffect) { + if (returnFiber.lastEffect) { + returnFiber.lastEffect.nextEffect = child.firstEffect; + } + returnFiber.lastEffect = child.lastEffect; + } + } while (child = child.sibling); } + */ - 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." - ); +function bailoutOnAlreadyFinishedWork(current, workInProgress) { + cancelWorkTimer(workInProgress); - push(contextStackCursor, context, fiber); - push(didPerformWorkStackCursor, didChange, fiber); + if (enableProfilerTimer) { + // Don't update "base" render times for bailouts. + stopBaseRenderTimerIfRunning(); } - function processChildContext(fiber, parentContext) { - var instance = fiber.stateNode; - var childContextTypes = fiber.type.childContextTypes; + // TODO: We should ideally be able to bail out early if the children have no + // more work to do. However, since we don't have a separation of this + // Fiber's priority and its children yet - we don't know without doing lots + // of the same work we do anyway. Once we have that separation we can just + // bail out here if the children has no more work at this priority level. + // if (workInProgress.priorityOfChildren <= priorityLevel) { + // // If there are side-effects in these children that have not yet been + // // committed we need to ensure that they get properly transferred up. + // if (current && current.child !== workInProgress.child) { + // reuseChildrenEffects(workInProgress, child); + // } + // return null; + // } - // 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; - } + cloneChildFibers(current, workInProgress); + return workInProgress.child; +} - 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 - ); - } +function bailoutOnLowPriority(current, workInProgress) { + cancelWorkTimer(workInProgress); - return Object.assign({}, parentContext, childContext); + if (enableProfilerTimer) { + // Don't update "base" render times for bailouts. + stopBaseRenderTimerIfRunning(); } - 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; + // TODO: Handle HostComponent tags here as well and call pushHostContext()? + // See PR 8590 discussion for context + switch (workInProgress.tag) { + case HostRoot: + pushHostRootContext(workInProgress); + break; + case ClassComponent: + pushContextProvider(workInProgress); + break; + case HostPortal: + pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo); + break; + case ContextProvider: + pushProvider(workInProgress); + break; } + // TODO: What if this is currently in progress? + // How can that happen? How is this not being cloned? + return null; +} - 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." - ); +// TODO: Delete memoizeProps/State and move to reconcile/bailout instead +function memoizeProps(workInProgress, nextProps) { + workInProgress.memoizedProps = nextProps; +} - 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 memoizeState(workInProgress, nextState) { + workInProgress.memoizedState = nextState; + // Don't reset the updateQueue, in case there are pending updates. Resetting + // is handled by processUpdateQueue. +} + +function beginWork(current, workInProgress, renderExpirationTime) { + if (enableProfilerTimer) { + if (workInProgress.mode & ProfileMode) { + markActualRenderTimeStarted(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." - ); + if ( + workInProgress.expirationTime === NoWork || + workInProgress.expirationTime > renderExpirationTime + ) { + return bailoutOnLowPriority(current, workInProgress); + } - var node = fiber; - while (node.tag !== HostRoot) { - if (isContextProvider(node)) { - return node.stateNode.__reactInternalMemoizedMergedChildContext; - } - var parent = node.return; + switch (workInProgress.tag) { + case IndeterminateComponent: + return mountIndeterminateComponent( + current, + workInProgress, + renderExpirationTime + ); + case FunctionalComponent: + return updateFunctionalComponent(current, workInProgress); + case ClassComponent: + return updateClassComponent( + current, + workInProgress, + renderExpirationTime + ); + case HostRoot: + return updateHostRoot(current, workInProgress, renderExpirationTime); + case HostComponent: + return updateHostComponent(current, workInProgress, renderExpirationTime); + case HostText: + return updateHostText(current, workInProgress); + case TimeoutComponent: + return updateTimeoutComponent( + current, + workInProgress, + renderExpirationTime + ); + case HostPortal: + return updatePortalComponent( + current, + workInProgress, + renderExpirationTime + ); + case ForwardRef: + return updateForwardRef(current, workInProgress); + case Fragment: + return updateFragment(current, workInProgress); + case Mode: + return updateMode(current, workInProgress); + case Profiler: + return updateProfiler(current, workInProgress); + case ContextProvider: + return updateContextProvider( + current, + workInProgress, + renderExpirationTime + ); + case ContextConsumer: + return updateContextConsumer( + current, + workInProgress, + renderExpirationTime + ); + default: invariant( - parent, - "Found unexpected detached subtree parent. " + - "This error is likely caused by a bug in React. Please file an issue." + false, + "Unknown unit of work tag. 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, isPrimaryRenderer) { - var createCursor = stack.createCursor, - push = stack.push, - pop = stack.pop; +function markUpdate(workInProgress) { + // Tag the fiber with an update effect. This turns a Placement into + // a PlacementAndUpdate. + workInProgress.effectTag |= Update; +} - var providerCursor = createCursor(null); - var valueCursor = createCursor(null); - var changedBitsCursor = createCursor(0); +function markRef$1(workInProgress) { + workInProgress.effectTag |= Ref; +} - var rendererSigil = void 0; - { - // Use this to detect multiple renderers using the same context - rendererSigil = {}; +function appendAllChildren(parent, workInProgress) { + // We only have the top Fiber that was created but we need recurse down its + // children to find all the terminal nodes. + var node = workInProgress.child; + while (node !== null) { + if (node.tag === HostComponent || node.tag === HostText) { + appendInitialChild(parent, node.stateNode); + } else if (node.tag === HostPortal) { + // If we have a portal child, then we don't want to traverse + // down its children. Instead, we'll get insertions from each child in + // the portal directly. + } else if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; + } + if (node === workInProgress) { + return; + } + while (node.sibling === null) { + if (node.return === null || node.return === workInProgress) { + return; + } + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; } +} - function pushProvider(providerFiber) { - var context = providerFiber.type._context; +var updateHostContainer = void 0; +var updateHostComponent$1 = void 0; +var updateHostText$1 = void 0; +if (supportsMutation) { + // Mutation mode - if (isPrimaryRenderer) { - push(changedBitsCursor, context._changedBits, providerFiber); - push(valueCursor, context._currentValue, providerFiber); - push(providerCursor, providerFiber, providerFiber); + updateHostContainer = function(workInProgress) { + // Noop + }; + updateHostComponent$1 = function( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ) { + // TODO: Type this specific to this type of component. + workInProgress.updateQueue = updatePayload; + // If the update payload indicates that there is a change or if there + // is a new ref we mark this as an update. All the work is done in commitWork. + if (updatePayload) { + markUpdate(workInProgress); + } + }; + updateHostText$1 = function(current, workInProgress, oldText, newText) { + // If the text differs, mark it as an update. All the work in done in commitWork. + if (oldText !== newText) { + markUpdate(workInProgress); + } + }; +} else if (supportsPersistence) { + // Persistent host tree mode - context._currentValue = providerFiber.pendingProps.value; - context._changedBits = providerFiber.stateNode; - { - !( - context._currentRenderer === undefined || - 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; + // An unfortunate fork of appendAllChildren because we have two different parent types. + var appendAllChildrenToContainer = function( + containerChildSet, + workInProgress + ) { + // We only have the top Fiber that was created but we need recurse down its + // children to find all the terminal nodes. + var node = workInProgress.child; + while (node !== null) { + if (node.tag === HostComponent || node.tag === HostText) { + appendChildToContainerChildSet(containerChildSet, node.stateNode); + } else if (node.tag === HostPortal) { + // If we have a portal child, then we don't want to traverse + // down its children. Instead, we'll get insertions from each child in + // the portal directly. + } else if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; + } + if (node === workInProgress) { + return; + } + while (node.sibling === null) { + if (node.return === null || node.return === workInProgress) { + return; + } + node = node.return; } + node.sibling.return = node.return; + node = node.sibling; + } + }; + updateHostContainer = function(workInProgress) { + var portalOrRoot = workInProgress.stateNode; + var childrenUnchanged = workInProgress.firstEffect === null; + if (childrenUnchanged) { + // No changes, just reuse the existing instance. } else { - push(changedBitsCursor, context._changedBits2, providerFiber); - push(valueCursor, context._currentValue2, providerFiber); - push(providerCursor, providerFiber, providerFiber); - - context._currentValue2 = providerFiber.pendingProps.value; - context._changedBits2 = providerFiber.stateNode; - { - !( - context._currentRenderer2 === undefined || - context._currentRenderer2 === null || - context._currentRenderer2 === rendererSigil + var container = portalOrRoot.containerInfo; + var newChildSet = createContainerChildSet(container); + // If children might have changed, we have to add them all to the set. + appendAllChildrenToContainer(newChildSet, workInProgress); + portalOrRoot.pendingChildren = newChildSet; + // Schedule an update on the container to swap out the container. + markUpdate(workInProgress); + finalizeContainerChildren(container, newChildSet); + } + }; + updateHostComponent$1 = function( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ) { + // If there are no effects associated with this node, then none of our children had any updates. + // This guarantees that we can reuse all of them. + var childrenUnchanged = workInProgress.firstEffect === null; + var currentInstance = current.stateNode; + if (childrenUnchanged && updatePayload === null) { + // No changes, just reuse the existing instance. + // Note that this might release a previous clone. + workInProgress.stateNode = currentInstance; + } else { + var recyclableInstance = workInProgress.stateNode; + var newInstance = cloneInstance( + currentInstance, + updatePayload, + type, + oldProps, + newProps, + workInProgress, + childrenUnchanged, + recyclableInstance + ); + if ( + finalizeInitialChildren( + newInstance, + type, + newProps, + rootContainerInstance, + currentHostContext ) - ? warning( - false, - "Detected multiple renderers concurrently rendering the " + - "same context provider. This is currently unsupported." - ) - : void 0; - context._currentRenderer2 = rendererSigil; + ) { + markUpdate(workInProgress); + } + workInProgress.stateNode = newInstance; + if (childrenUnchanged) { + // If there are no other effects in this tree, we need to flag this node as having one. + // Even though we're not going to use it for anything. + // Otherwise parents won't know that there are new children to propagate upwards. + markUpdate(workInProgress); + } else { + // If children might have changed, we have to add them all to the set. + appendAllChildren(newInstance, workInProgress); } } - } - - 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; - if (isPrimaryRenderer) { - context._currentValue = currentValue; - context._changedBits = changedBits; - } else { - context._currentValue2 = currentValue; - context._changedBits2 = changedBits; + }; + updateHostText$1 = function(current, workInProgress, oldText, newText) { + if (oldText !== newText) { + // If the text content differs, we'll create a new text instance for it. + var rootContainerInstance = getRootHostContainer(); + var currentHostContext = getHostContext(); + workInProgress.stateNode = createTextInstance( + newText, + rootContainerInstance, + currentHostContext, + workInProgress + ); + // We'll have to mark it as having an effect, even though we won't use the effect for anything. + // This lets the parents know that at least one of their children has changed. + markUpdate(workInProgress); } - } + }; +} else { + // No host operations + updateHostContainer = function(workInProgress) { + // Noop + }; + updateHostComponent$1 = function( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ) { + // Noop + }; + updateHostText$1 = function(current, workInProgress, oldText, newText) { + // Noop + }; +} - function getContextCurrentValue(context) { - return isPrimaryRenderer ? context._currentValue : context._currentValue2; - } +function completeWork(current, workInProgress, renderExpirationTime) { + var newProps = workInProgress.pendingProps; - function getContextChangedBits(context) { - return isPrimaryRenderer ? context._changedBits : context._changedBits2; + if (enableProfilerTimer) { + if (workInProgress.mode & ProfileMode) { + recordElapsedActualRenderTime(workInProgress); + } } - return { - pushProvider: pushProvider, - popProvider: popProvider, - getContextCurrentValue: getContextCurrentValue, - getContextChangedBits: getContextChangedBits - }; -}; - -var ReactFiberStack = function() { - var valueStack = []; + switch (workInProgress.tag) { + case FunctionalComponent: + return null; + case ClassComponent: { + // We are leaving this subtree, so pop context if any. + popContextProvider(workInProgress); + return null; + } + case HostRoot: { + popHostContainer(workInProgress); + popTopLevelContextObject(workInProgress); + var fiberRoot = workInProgress.stateNode; + if (fiberRoot.pendingContext) { + fiberRoot.context = fiberRoot.pendingContext; + fiberRoot.pendingContext = null; + } + if (current === null || current.child === null) { + // If we hydrated, pop so that we can delete any remaining children + // that weren't hydrated. + popHydrationState(workInProgress); + // This resets the hacky state to fix isMounted before committing. + // TODO: Delete this when we delete isMounted and findDOMNode. + workInProgress.effectTag &= ~Placement; + } + updateHostContainer(workInProgress); + return null; + } + case HostComponent: { + popHostContext(workInProgress); + var rootContainerInstance = getRootHostContainer(); + var type = workInProgress.type; + if (current !== null && workInProgress.stateNode != null) { + // If we have an alternate, that means this is an update and we need to + // schedule a side-effect to do the updates. + var oldProps = current.memoizedProps; + // If we get updated because one of our children updated, we don't + // have newProps so we'll have to reuse them. + // TODO: Split the update API as separate for the props vs. children. + // Even better would be if children weren't special cased at all tho. + var instance = workInProgress.stateNode; + var currentHostContext = getHostContext(); + // TODO: Experiencing an error where oldProps is null. Suggests a host + // component is hitting the resume path. Figure out why. Possibly + // related to `hidden`. + var updatePayload = prepareUpdate( + instance, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ); - var fiberStack = void 0; + updateHostComponent$1( + current, + workInProgress, + updatePayload, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ); - { - fiberStack = []; - } + if (current.ref !== workInProgress.ref) { + markRef$1(workInProgress); + } + } else { + if (!newProps) { + invariant( + workInProgress.stateNode !== null, + "We must have new props for new mounts. This error is likely " + + "caused by a bug in React. Please file an issue." + ); + // This can happen when we abort work. + return null; + } - var index = -1; + var _currentHostContext = getHostContext(); + // TODO: Move createInstance to beginWork and keep it on a context + // "stack" as the parent. Then append children as we go in beginWork + // or completeWork depending on we want to add then top->down or + // bottom->up. Top->down is faster in IE11. + var wasHydrated = popHydrationState(workInProgress); + if (wasHydrated) { + // TODO: Move this and createInstance step into the beginPhase + // to consolidate. + if ( + prepareToHydrateHostInstance( + workInProgress, + rootContainerInstance, + _currentHostContext + ) + ) { + // If changes to the hydrated node needs to be applied at the + // commit-phase we mark this as such. + markUpdate(workInProgress); + } + } else { + var _instance = createInstance( + type, + newProps, + rootContainerInstance, + _currentHostContext, + workInProgress + ); - function createCursor(defaultValue) { - return { - current: defaultValue - }; - } + appendAllChildren(_instance, workInProgress); - function isEmpty() { - return index === -1; - } + // Certain renderers require commit-time effects for initial mount. + // (eg DOM renderer supports auto-focus for certain elements). + // Make sure such renderers get scheduled for later work. + if ( + finalizeInitialChildren( + _instance, + type, + newProps, + rootContainerInstance, + _currentHostContext + ) + ) { + markUpdate(workInProgress); + } + workInProgress.stateNode = _instance; + } - function pop(cursor, fiber) { - if (index < 0) { - { - warning(false, "Unexpected pop."); + if (workInProgress.ref !== null) { + // If there is a ref on a host node we need to schedule a callback + markRef$1(workInProgress); + } } - return; + return null; } - - { - if (fiber !== fiberStack[index]) { - warning(false, "Unexpected Fiber popped."); + case HostText: { + var newText = newProps; + if (current && workInProgress.stateNode != null) { + var oldText = current.memoizedProps; + // If we have an alternate, that means this is an update and we need + // to schedule a side-effect to do the updates. + updateHostText$1(current, workInProgress, oldText, newText); + } else { + if (typeof newText !== "string") { + invariant( + workInProgress.stateNode !== null, + "We must have new props for new mounts. This error is likely " + + "caused by a bug in React. Please file an issue." + ); + // This can happen when we abort work. + return null; + } + var _rootContainerInstance = getRootHostContainer(); + var _currentHostContext2 = getHostContext(); + var _wasHydrated = popHydrationState(workInProgress); + if (_wasHydrated) { + if (prepareToHydrateHostTextInstance(workInProgress)) { + markUpdate(workInProgress); + } + } else { + workInProgress.stateNode = createTextInstance( + newText, + _rootContainerInstance, + _currentHostContext2, + workInProgress + ); + } } + return null; } + case ForwardRef: + return null; + case TimeoutComponent: + return null; + case Fragment: + return null; + case Mode: + return null; + case Profiler: + return null; + case HostPortal: + popHostContainer(workInProgress); + updateHostContainer(workInProgress); + return null; + case ContextProvider: + // Pop provider fiber + popProvider(workInProgress); + return null; + case ContextConsumer: + return null; + // Error cases + case IndeterminateComponent: + invariant( + false, + "An indeterminate component should have become determinate before " + + "completing. This error is likely caused by a bug in React. Please " + + "file an issue." + ); + // eslint-disable-next-line no-fallthrough + default: + invariant( + false, + "Unknown unit of work tag. This error is likely caused by a bug in " + + "React. Please file an issue." + ); + } +} - cursor.current = valueStack[index]; +// Module provided by RN: +/** + * Intercept lifecycle errors and ensure they are shown with the correct stack + * trace within the native redbox component. + */ +function showErrorDialog(capturedError) { + var componentStack = capturedError.componentStack, + error = capturedError.error; - valueStack[index] = null; + var errorToHandle = void 0; - { - fiberStack[index] = null; - } + // Typically Errors are thrown but eg strings or null can be thrown as well. + if (error instanceof Error) { + var message = error.message, + name = error.name; - index--; - } + var summary = message ? name + ": " + message : name; - function push(cursor, value, fiber) { - index++; + errorToHandle = error; - valueStack[index] = cursor.current; + try { + errorToHandle.message = + summary + "\n\nThis error is located at:" + componentStack; + } catch (e) {} + } else if (typeof error === "string") { + errorToHandle = new Error( + error + "\n\nThis error is located at:" + componentStack + ); + } else { + errorToHandle = new Error("Unspecified error at:" + componentStack); + } - { - fiberStack[index] = fiber; - } + ExceptionsManager.handleException(errorToHandle, false); - cursor.current = value; - } + // Return false here to prevent ReactFiberErrorLogger default behavior of + // logging error details to console.error. Calls to console.error are + // automatically routed to the native redbox controller, which we've already + // done above by calling ExceptionsManager. + return false; +} - function checkThatStackIsEmpty() { - { - if (index !== -1) { - warning( - false, - "Expected an empty stack. Something was not reset properly." - ); - } - } - } +function logCapturedError(capturedError) { + var logError = showErrorDialog(capturedError); - function resetStackAfterFatalErrorInDev() { - { - index = -1; - valueStack.length = 0; - fiberStack.length = 0; - } + // Allow injected showErrorDialog() to prevent default console.error logging. + // This enables renderers like ReactNative to better manage redbox behavior. + if (logError === false) { + return; } - 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; + var error = capturedError.error; + var suppressLogging = error && error.suppressReactErrorLogging; + if (suppressLogging) { + return; + } -var didWarnAboutStateTransition = void 0; -var didWarnSetStateChildContext = void 0; -var warnAboutUpdateOnUnmounted = void 0; -var warnAboutInvalidUpdates = void 0; + { + var componentName = capturedError.componentName, + componentStack = capturedError.componentStack, + errorBoundaryName = capturedError.errorBoundaryName, + errorBoundaryFound = capturedError.errorBoundaryFound, + willRetry = capturedError.willRetry; -{ - didWarnAboutStateTransition = false; - didWarnSetStateChildContext = false; - var didWarnStateUpdateForUnmountedComponent = {}; + var componentNameMessage = componentName + ? "The above error occurred in the <" + componentName + "> component:" + : "The above error occurred in one of your React components:"; - 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; + var errorBoundaryMessage = void 0; + // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow. + if (errorBoundaryFound && errorBoundaryName) { + if (willRetry) { + errorBoundaryMessage = + "React will try to recreate this component tree from scratch " + + ("using the error boundary you provided, " + errorBoundaryName + "."); + } else { + errorBoundaryMessage = + "This error was initially handled by the error boundary " + + errorBoundaryName + + ".\n" + + "Recreating the tree from scratch failed so React will unmount the tree."; + } + } else { + errorBoundaryMessage = + "Consider adding an error boundary to your tree to customize error handling behavior.\n" + + "Visit https://fb.me/react-error-boundaries to learn more about error boundaries."; } - 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) - ); - didWarnStateUpdateForUnmountedComponent[componentName] = true; - }; + var combinedMessage = + "" + + componentNameMessage + + componentStack + + "\n\n" + + ("" + errorBoundaryMessage); - warnAboutInvalidUpdates = function(instance) { - switch (ReactDebugCurrentFiber.phase) { - case "getChildContext": - if (didWarnSetStateChildContext) { - return; - } - warning( - false, - "setState(...): Cannot call setState() inside getChildContext()" - ); - didWarnSetStateChildContext = true; - break; - case "render": - if (didWarnAboutStateTransition) { - return; - } - warning( - false, - "Cannot update during an existing state transition (such as within " + - "`render` or another component's constructor). Render methods should " + - "be a pure function of props and state; constructor side-effects are " + - "an anti-pattern, but can be moved to `componentWillMount`." - ); - didWarnAboutStateTransition = true; - break; - } - }; + // In development, we provide our own message with just the component stack. + // We don't include the original error message and JS stack because the browser + // has already printed it. Even if the application swallows the error, it is still + // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils. + console.error(combinedMessage); + } } -var ReactFiberScheduler = function(config) { - var now = config.now, - scheduleDeferredCallback = config.scheduleDeferredCallback, - cancelDeferredCallback = config.cancelDeferredCallback, - prepareForCommit = config.prepareForCommit, - resetAfterCommit = config.resetAfterCommit; - - var stack = ReactFiberStack(); - var hostContext = ReactFiberHostContext(config, stack); - var legacyContext = ReactFiberLegacyContext(stack); - var newContext = ReactFiberNewContext(stack, config.isPrimaryRenderer); - var profilerTimer = createProfilerTimer(now); - var popHostContext = hostContext.popHostContext, - popHostContainer = hostContext.popHostContainer; - var popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popLegacyContextProvider = legacyContext.popContextProvider; - var popProvider = newContext.popProvider; - - var hydrationContext = ReactFiberHydrationContext(config); - - var _ReactFiberBeginWork = ReactFiberBeginWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - scheduleWork, - computeExpirationForFiber, - profilerTimer, - recalculateCurrentTime - ), - beginWork = _ReactFiberBeginWork.beginWork; - - var _ReactFiberCompleteWo = ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - profilerTimer - ), - completeWork = _ReactFiberCompleteWo.completeWork; - - var _ReactFiberUnwindWork = ReactFiberUnwindWork( - config, - hostContext, - legacyContext, - newContext, - scheduleWork, - computeExpirationForFiber, - recalculateCurrentTime, - markLegacyErrorBoundaryAsFailed, - isAlreadyFailedLegacyErrorBoundary, - onUncaughtError, - profilerTimer, - suspendRoot, - retrySuspendedRoot - ), - throwException = _ReactFiberUnwindWork.throwException, - unwindWork = _ReactFiberUnwindWork.unwindWork, - unwindInterruptedWork = _ReactFiberUnwindWork.unwindInterruptedWork, - createRootErrorUpdate = _ReactFiberUnwindWork.createRootErrorUpdate, - createClassErrorUpdate = _ReactFiberUnwindWork.createClassErrorUpdate; - - var _ReactFiberCommitWork = ReactFiberCommitWork( - config, - onCommitPhaseError, - scheduleWork, - computeExpirationForFiber, - markLegacyErrorBoundaryAsFailed, - recalculateCurrentTime - ), - commitBeforeMutationLifeCycles = - _ReactFiberCommitWork.commitBeforeMutationLifeCycles, - commitResetTextContent = _ReactFiberCommitWork.commitResetTextContent, - commitPlacement = _ReactFiberCommitWork.commitPlacement, - commitDeletion = _ReactFiberCommitWork.commitDeletion, - commitWork = _ReactFiberCommitWork.commitWork, - commitLifeCycles = _ReactFiberCommitWork.commitLifeCycles, - commitAttachRef = _ReactFiberCommitWork.commitAttachRef, - commitDetachRef = _ReactFiberCommitWork.commitDetachRef; - - var checkActualRenderTimeStackEmpty = - profilerTimer.checkActualRenderTimeStackEmpty, - pauseActualRenderTimerIfRunning = - profilerTimer.pauseActualRenderTimerIfRunning, - recordElapsedBaseRenderTimeIfRunning = - profilerTimer.recordElapsedBaseRenderTimeIfRunning, - resetActualRenderTimer = profilerTimer.resetActualRenderTimer, - resumeActualRenderTimerIfPaused = - profilerTimer.resumeActualRenderTimerIfPaused, - startBaseRenderTimer = profilerTimer.startBaseRenderTimer, - stopBaseRenderTimerIfRunning = profilerTimer.stopBaseRenderTimerIfRunning; - - // Represents the current time in ms. - - var originalStartTimeMs = now(); - var mostRecentCurrentTime = msToExpirationTime(0); - var mostRecentCurrentTimeMs = originalStartTimeMs; - - // Used to ensure computeUniqueAsyncExpiration is monotonically increases. - var lastUniqueAsyncExpiration = 0; - - // Represents the expiration time that incoming updates should use. (If this - // is NoWork, use the default strategy: async updates in async mode, sync - // updates in sync mode.) - var expirationContext = NoWork; - - var isWorking = false; - - // The next work in progress fiber that we're currently working on. - var nextUnitOfWork = null; - var nextRoot = null; - // The time at which we're currently rendering work. - var nextRenderExpirationTime = NoWork; - var nextLatestTimeoutMs = -1; - var nextRenderIsExpired = false; - - // The next fiber with an effect that we're currently committing. - var nextEffect = null; - - var isCommitting = false; - - var isRootReadyForCommit = false; - - var legacyErrorBoundariesThatAlreadyFailed = null; - - // Used for performance tracking. - var interruptedBy = null; - - 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, thrownValue, isAsync) { - if ( - thrownValue !== null && - typeof thrownValue === "object" && - typeof thrownValue.then === "function" - ) { - // Don't replay promises. Treat everything else like an error. - // TODO: Need to figure out a different strategy if/when we add - // support for catching other types. - return; - } - - // Restore the original state of the work-in-progress - if (stashedWorkInProgressProperties === null) { - // This should never happen. Don't throw because this code is DEV-only. - warning( - false, - "Could not replay rendering after an error. This is likely a bug in React. " + - "Please file an issue." - ); - return; - } - assignFiberPropertiesInDEV( - failedUnitOfWork, - stashedWorkInProgressProperties - ); +var invokeGuardedCallback$3 = ReactErrorUtils.invokeGuardedCallback; +var hasCaughtError$1 = ReactErrorUtils.hasCaughtError; +var clearCaughtError$1 = ReactErrorUtils.clearCaughtError; - switch (failedUnitOfWork.tag) { - case HostRoot: - popHostContainer(failedUnitOfWork); - popTopLevelLegacyContextObject(failedUnitOfWork); - break; - case HostComponent: - popHostContext(failedUnitOfWork); - break; - case ClassComponent: - popLegacyContextProvider(failedUnitOfWork); - break; - case HostPortal: - popHostContainer(failedUnitOfWork); - break; - case ContextProvider: - popProvider(failedUnitOfWork); - break; - } - // Replay the begin phase. - isReplayingFailedUnitOfWork = true; - originalReplayError = thrownValue; - invokeGuardedCallback$2(null, workLoop, null, isAsync); - isReplayingFailedUnitOfWork = false; - originalReplayError = null; - if (hasCaughtError()) { - clearCaughtError(); +var didWarnAboutUndefinedSnapshotBeforeUpdate = null; +{ + didWarnAboutUndefinedSnapshotBeforeUpdate = new Set(); +} - if (enableProfilerTimer) { - // Stop "base" render timer again (after the re-thrown error). - stopBaseRenderTimerIfRunning(); - } - } else { - // If the begin phase did not fail the second time, set this pointer - // back to the original value. - nextUnitOfWork = failedUnitOfWork; - } - }; - rethrowOriginalError = function() { - throw originalReplayError; - }; +function logError(boundary, errorInfo) { + var source = errorInfo.source; + var stack = errorInfo.stack; + if (stack === null && source !== null) { + stack = getStackAddendumByWorkInProgressFiber(source); } - function resetStack() { - if (nextUnitOfWork !== null) { - var interruptedWork = nextUnitOfWork.return; - while (interruptedWork !== null) { - unwindInterruptedWork(interruptedWork); - interruptedWork = interruptedWork.return; - } - } + var capturedError = { + componentName: source !== null ? getComponentName(source) : null, + componentStack: stack !== null ? stack : "", + error: errorInfo.value, + errorBoundary: null, + errorBoundaryName: null, + errorBoundaryFound: false, + willRetry: false + }; - { - ReactStrictModeWarnings.discardPendingWarnings(); - stack.checkThatStackIsEmpty(); + if (boundary !== null && boundary.tag === ClassComponent) { + capturedError.errorBoundary = boundary.stateNode; + capturedError.errorBoundaryName = getComponentName(boundary); + capturedError.errorBoundaryFound = true; + capturedError.willRetry = true; + } + + try { + logCapturedError(capturedError); + } catch (e) { + // Prevent cycle if logCapturedError() throws. + // A cycle may still occur if logCapturedError renders a component that throws. + var suppressLogging = e && e.suppressReactErrorLogging; + if (!suppressLogging) { + console.error(e); } + } +} - nextRoot = null; - nextRenderExpirationTime = NoWork; - nextLatestTimeoutMs = -1; - nextRenderIsExpired = false; - nextUnitOfWork = null; +var callComponentWillUnmountWithTimer = function(current, instance) { + startPhaseTimer(current, "componentWillUnmount"); + instance.props = current.memoizedProps; + instance.state = current.memoizedState; + instance.componentWillUnmount(); + stopPhaseTimer(); +}; - isRootReadyForCommit = false; +// Capture errors so they don't interrupt unmounting. +function safelyCallComponentWillUnmount(current, instance) { + { + invokeGuardedCallback$3( + null, + callComponentWillUnmountWithTimer, + null, + current, + instance + ); + if (hasCaughtError$1()) { + var unmountError = clearCaughtError$1(); + captureCommitPhaseError(current, unmountError); + } } +} - function commitAllHostEffects() { - while (nextEffect !== null) { +function safelyDetachRef(current) { + var ref = current.ref; + if (ref !== null) { + if (typeof ref === "function") { { - ReactDebugCurrentFiber.setCurrentFiber(nextEffect); - } - recordEffect(); - - var effectTag = nextEffect.effectTag; - - if (effectTag & ContentReset) { - commitResetTextContent(nextEffect); - } - - if (effectTag & Ref) { - var current = nextEffect.alternate; - if (current !== null) { - commitDetachRef(current); + invokeGuardedCallback$3(null, ref, null, null); + if (hasCaughtError$1()) { + var refError = clearCaughtError$1(); + captureCommitPhaseError(current, refError); } } + } else { + ref.current = null; + } + } +} - // The following switch statement is only concerned about placement, - // updates, and deletions. To avoid needing to add a case for every - // possible bitmap value, we remove the secondary effects from the - // effect tag and switch on that value. - var primaryEffectTag = effectTag & (Placement | Update | Deletion); - switch (primaryEffectTag) { - case Placement: { - commitPlacement(nextEffect); - // Clear the "placement" from effect tag so that we know that this is inserted, before - // any life-cycles like componentDidMount gets called. - // TODO: findDOMNode doesn't rely on this any more but isMounted - // does and isMounted is deprecated anyway so we should be able - // to kill this. - nextEffect.effectTag &= ~Placement; - break; - } - case PlacementAndUpdate: { - // Placement - commitPlacement(nextEffect); - // Clear the "placement" from effect tag so that we know that this is inserted, before - // any life-cycles like componentDidMount gets called. - nextEffect.effectTag &= ~Placement; - - // Update - var _current = nextEffect.alternate; - commitWork(_current, nextEffect); - break; - } - case Update: { - var _current2 = nextEffect.alternate; - commitWork(_current2, nextEffect); - break; - } - case Deletion: { - commitDeletion(nextEffect); - break; +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(); } } - nextEffect = nextEffect.nextEffect; + return; } - - { - ReactDebugCurrentFiber.resetCurrentFiber(); + 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." + ); } } +} - function commitBeforeMutationLifecycles() { - while (nextEffect !== null) { - var effectTag = nextEffect.effectTag; - - if (effectTag & Snapshot) { - recordEffect(); - var current = nextEffect.alternate; - commitBeforeMutationLifeCycles(current, nextEffect); +function commitLifeCycles( + finishedRoot, + current, + finishedWork, + currentTime, + committedExpirationTime +) { + switch (finishedWork.tag) { + case ClassComponent: { + var instance = finishedWork.stateNode; + if (finishedWork.effectTag & Update) { + if (current === null) { + startPhaseTimer(finishedWork, "componentDidMount"); + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + instance.componentDidMount(); + stopPhaseTimer(); + } else { + var prevProps = current.memoizedProps; + var prevState = current.memoizedState; + startPhaseTimer(finishedWork, "componentDidUpdate"); + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + instance.componentDidUpdate( + prevProps, + prevState, + instance.__reactInternalSnapshotBeforeUpdate + ); + stopPhaseTimer(); + } } - - // Don't cleanup effects yet; - // This will be done by commitAllLifeCycles() - nextEffect = nextEffect.nextEffect; - } - } - - function commitAllLifeCycles( - finishedRoot, - currentTime, - committedExpirationTime - ) { - { - ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings(); - - if (warnAboutDeprecatedLifecycles) { - ReactStrictModeWarnings.flushPendingDeprecationWarnings(); + var updateQueue = finishedWork.updateQueue; + if (updateQueue !== null) { + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + commitUpdateQueue( + finishedWork, + updateQueue, + instance, + committedExpirationTime + ); } + return; } - while (nextEffect !== null) { - var effectTag = nextEffect.effectTag; - - if (effectTag & (Update | Callback)) { - recordEffect(); - var current = nextEffect.alternate; - commitLifeCycles( - finishedRoot, - current, - nextEffect, - currentTime, + case HostRoot: { + var _updateQueue = finishedWork.updateQueue; + if (_updateQueue !== null) { + var _instance = null; + if (finishedWork.child !== null) { + switch (finishedWork.child.tag) { + case HostComponent: + _instance = getPublicInstance(finishedWork.child.stateNode); + break; + case ClassComponent: + _instance = finishedWork.child.stateNode; + break; + } + } + commitUpdateQueue( + finishedWork, + _updateQueue, + _instance, committedExpirationTime ); } + return; + } + case HostComponent: { + var _instance2 = finishedWork.stateNode; - if (effectTag & Ref) { - recordEffect(); - commitAttachRef(nextEffect); + // Renderers may schedule work to be done after host components are mounted + // (eg DOM renderer may schedule auto-focus for inputs and form controls). + // These effects should only be committed when components are first mounted, + // aka when there is no current/alternate. + if (current === null && finishedWork.effectTag & Update) { + var type = finishedWork.type; + var props = finishedWork.memoizedProps; } - var next = nextEffect.nextEffect; - // Ensure that we clean these up so that we don't accidentally keep them. - // I'm not actually sure this matters because we can't reset firstEffect - // and lastEffect since they're on every node, not just the effectful - // ones. So we have to clean everything as we reuse nodes anyway. - nextEffect.nextEffect = null; - // Ensure that we reset the effectTag here so that we can rely on effect - // tags to reason about the current life-cycle. - nextEffect = next; + return; + } + case HostText: { + // We have no life-cycles associated with text. + return; + } + case HostPortal: { + // We have no life-cycles associated with portals. + return; + } + case Profiler: { + // We have no life-cycles associated with Profiler. + return; + } + case TimeoutComponent: { + // We have no life-cycles associated with Timeouts. + 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." + ); } } +} - function isAlreadyFailedLegacyErrorBoundary(instance) { - return ( - legacyErrorBoundariesThatAlreadyFailed !== null && - legacyErrorBoundariesThatAlreadyFailed.has(instance) - ); - } - - function markLegacyErrorBoundaryAsFailed(instance) { - if (legacyErrorBoundariesThatAlreadyFailed === null) { - legacyErrorBoundariesThatAlreadyFailed = new Set([instance]); +function commitAttachRef(finishedWork) { + var ref = finishedWork.ref; + if (ref !== null) { + var instance = finishedWork.stateNode; + var instanceToUse = void 0; + switch (finishedWork.tag) { + case HostComponent: + instanceToUse = getPublicInstance(instance); + break; + default: + instanceToUse = instance; + } + if (typeof ref === "function") { + ref(instanceToUse); } else { - legacyErrorBoundariesThatAlreadyFailed.add(instance); + { + 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; } } +} - function commitRoot(finishedWork) { - isWorking = true; - isCommitting = true; - startCommitTimer(); - - var root = finishedWork.stateNode; - invariant( - root.current !== finishedWork, - "Cannot commit the same tree as before. This is probably a bug " + - "related to the return field. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - var committedExpirationTime = root.pendingCommitExpirationTime; - invariant( - committedExpirationTime !== NoWork, - "Cannot commit an incomplete root. This error is likely caused by a " + - "bug in React. Please file an issue." - ); - root.pendingCommitExpirationTime = NoWork; - - var currentTime = recalculateCurrentTime(); - - // Reset this to null before calling lifecycles - ReactCurrentOwner.current = null; - - var firstEffect = void 0; - if (finishedWork.effectTag > PerformedWork) { - // A fiber's effect list consists only of its children, not itself. So if - // the root has an effect, we need to add it to the end of the list. The - // resulting list is the set that would belong to the root's parent, if - // it had one; that is, all the effects in the tree including the root. - if (finishedWork.lastEffect !== null) { - finishedWork.lastEffect.nextEffect = finishedWork; - firstEffect = finishedWork.firstEffect; - } else { - firstEffect = finishedWork; - } +function commitDetachRef(current) { + var currentRef = current.ref; + if (currentRef !== null) { + if (typeof currentRef === "function") { + currentRef(null); } else { - // There is no effect on the root. - firstEffect = finishedWork.firstEffect; + currentRef.current = null; } + } +} - prepareForCommit(root.containerInfo); +// User-originating errors (lifecycles and refs) should not interrupt +// deletion, so don't let them throw. Host-originating errors should +// interrupt deletion, so it's okay +function commitUnmount(current) { + if (typeof onCommitUnmount === "function") { + onCommitUnmount(current); + } - // Invoke instances of getSnapshotBeforeUpdate before mutation. - nextEffect = firstEffect; - startCommitSnapshotEffectsTimer(); - while (nextEffect !== null) { - var didError = false; - var error = void 0; - { - invokeGuardedCallback$2(null, commitBeforeMutationLifecycles, null); - if (hasCaughtError()) { - didError = true; - error = clearCaughtError(); - } + switch (current.tag) { + case ClassComponent: { + safelyDetachRef(current); + var instance = current.stateNode; + if (typeof instance.componentWillUnmount === "function") { + safelyCallComponentWillUnmount(current, instance); } - 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; - } + return; + } + case HostComponent: { + safelyDetachRef(current); + return; + } + case HostPortal: { + // TODO: this is recursive. + // We are also not using this parent because + // the portal will get pushed immediately. + if (supportsMutation) { + unmountHostComponents(current); + } else if (supportsPersistence) { + emptyPortalContainer(current); } + return; } - 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; - } +function commitNestedUnmounts(root) { + // While we're inside a removed host node we don't want to call + // removeChild on the inner nodes because they're removed by the top + // call anyway. We also want to call componentWillUnmount on all + // composites before this host node is removed from the tree. Therefore + var node = root; + while (true) { + commitUnmount(node); + // Visit children because they may contain more composite or host nodes. + // Skip portals because commitUnmount() currently visits them recursively. + if ( + node.child !== null && + // If we use mutation we drill down into portals using commitUnmount above. + // If we don't use mutation we drill down into portals here instead. + (!supportsMutation || node.tag !== HostPortal) + ) { + node.child.return = node; + node = node.child; + continue; + } + if (node === root) { + return; + } + while (node.sibling === null) { + if (node.return === null || node.return === root) { + return; } + node = node.return; } - stopCommitHostEffectsTimer(); + node.sibling.return = node.return; + node = node.sibling; + } +} - resetAfterCommit(root.containerInfo); +function detachFiber(current) { + // Cut off the return pointers to disconnect it from the tree. Ideally, we + // should clear the child pointer of the parent alternate to let this + // get GC:ed but we don't know which for sure which parent is the current + // one so we'll settle for GC:ing the subtree of this child. This child + // itself will be GC:ed when the parent updates the next time. + current.return = null; + current.child = null; + if (current.alternate) { + current.alternate.child = null; + current.alternate.return = null; + } +} - // The work-in-progress tree is now the current tree. This must come after - // the first pass of the commit phase, so that the previous tree is still - // current during componentWillUnmount, but before the second pass, so that - // the finished work is current during componentDidMount/Update. - root.current = finishedWork; +function emptyPortalContainer(current) { + if (!supportsPersistence) { + return; + } - // In the second pass we'll perform all life-cycles and ref callbacks. - // Life-cycles happen as a separate pass so that all placements, updates, - // and deletions in the entire tree have already been invoked. - // This pass also triggers any renderer-specific initial effects. - nextEffect = firstEffect; - startCommitLifeCyclesTimer(); - while (nextEffect !== null) { - var _didError2 = false; - var _error2 = void 0; - { - invokeGuardedCallback$2( - null, - commitAllLifeCycles, - null, - root, - currentTime, - committedExpirationTime - ); - if (hasCaughtError()) { - _didError2 = true; - _error2 = clearCaughtError(); - } - } - if (_didError2) { - invariant( - nextEffect !== null, - "Should have next effect. This error is likely caused by a bug " + - "in React. Please file an issue." - ); - onCommitPhaseError(nextEffect, _error2); - if (nextEffect !== null) { - nextEffect = nextEffect.nextEffect; - } - } - } + var portal = current.stateNode; + var containerInfo = portal.containerInfo; - if (enableProfilerTimer) { - { - checkActualRenderTimeStackEmpty(); - } - resetActualRenderTimer(); - } + var emptyChildSet = createContainerChildSet(containerInfo); + replaceContainerChildren(containerInfo, emptyChildSet); +} - isCommitting = false; - isWorking = false; - stopCommitLifeCyclesTimer(); - stopCommitTimer(); - if (typeof onCommitRoot === "function") { - onCommitRoot(finishedWork.stateNode); +function commitContainer(finishedWork) { + if (!supportsPersistence) { + return; + } + + switch (finishedWork.tag) { + case ClassComponent: { + return; + } + case HostComponent: { + return; } - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork); + case HostText: { + return; } + case HostRoot: + case HostPortal: { + var portalOrRoot = finishedWork.stateNode; + var containerInfo = portalOrRoot.containerInfo, + _pendingChildren = portalOrRoot.pendingChildren; - markCommittedPriorityLevels(root, currentTime, root.current.expirationTime); - var remainingTime = findNextPendingPriorityLevel(root); - if (remainingTime === NoWork) { - // If there's no remaining work, we can clear the set of already failed - // error boundaries. - legacyErrorBoundariesThatAlreadyFailed = null; + replaceContainerChildren(containerInfo, _pendingChildren); + 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." + ); } - return remainingTime; } +} - function resetExpirationTime(workInProgress, renderTime) { - if (renderTime !== Never && workInProgress.expirationTime === Never) { - // The children of this component are hidden. Don't bubble their - // expiration times. - return; +function getHostParentFiber(fiber) { + var parent = fiber.return; + while (parent !== null) { + if (isHostParent(parent)) { + return parent; } + parent = parent.return; + } + invariant( + false, + "Expected to find a host parent. This error is likely caused by a bug " + + "in React. Please file an issue." + ); +} - // Check for pending updates. - var newExpirationTime = NoWork; - switch (workInProgress.tag) { - case HostRoot: - case ClassComponent: { - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - newExpirationTime = updateQueue.expirationTime; - } +function isHostParent(fiber) { + return ( + fiber.tag === HostComponent || + fiber.tag === HostRoot || + fiber.tag === HostPortal + ); +} + +function getHostSibling(fiber) { + // We're going to search forward into the tree until we find a sibling host + // node. Unfortunately, if multiple insertions are done in a row we have to + // search past them. This leads to exponential search for the next sibling. + var node = fiber; + siblings: while (true) { + // If we didn't find anything, let's try the next sibling. + while (node.sibling === null) { + if (node.return === null || isHostParent(node.return)) { + // If we pop out of the root or hit the parent the fiber we are the + // last sibling. + return null; } + node = node.return; } - - // TODO: Calls need to visit stateNode - - // Bubble up the earliest expiration time. - // (And "base" render timers if that feature flag is enabled) - if (enableProfilerTimer && workInProgress.mode & ProfileMode) { - var treeBaseTime = workInProgress.selfBaseTime; - var child = workInProgress.child; - while (child !== null) { - treeBaseTime += child.treeBaseTime; - if ( - child.expirationTime !== NoWork && - (newExpirationTime === NoWork || - newExpirationTime > child.expirationTime) - ) { - newExpirationTime = child.expirationTime; - } - child = child.sibling; + node.sibling.return = node.return; + node = node.sibling; + while (node.tag !== HostComponent && node.tag !== HostText) { + // If it is not host node and, we might have a host node inside it. + // Try to search down until we find one. + if (node.effectTag & Placement) { + // If we don't have a child, try the siblings instead. + continue siblings; } - workInProgress.treeBaseTime = treeBaseTime; - } else { - var _child = workInProgress.child; - while (_child !== null) { - if ( - _child.expirationTime !== NoWork && - (newExpirationTime === NoWork || - newExpirationTime > _child.expirationTime) - ) { - newExpirationTime = _child.expirationTime; - } - _child = _child.sibling; + // If we don't have a child, try the siblings instead. + // We also skip portals because they are not part of this host tree. + if (node.child === null || node.tag === HostPortal) { + continue siblings; + } else { + node.child.return = node; + node = node.child; } } - - workInProgress.expirationTime = newExpirationTime; + // Check if this host node is stable or about to be placed. + if (!(node.effectTag & Placement)) { + // Found it! + return node.stateNode; + } } +} - function completeUnitOfWork(workInProgress) { - // Attempt to complete the current unit of work, then move to the - // next sibling. If there are no more siblings, return to the - // parent fiber. - while (true) { - // The current, flushed, state of this fiber is the alternate. - // Ideally nothing should rely on this, but relying on it here - // means that we don't need an additional field on the work in - // progress. - var current = workInProgress.alternate; - { - ReactDebugCurrentFiber.setCurrentFiber(workInProgress); - } - - var returnFiber = workInProgress.return; - var siblingFiber = workInProgress.sibling; - - if ((workInProgress.effectTag & Incomplete) === NoEffect) { - // This fiber completed. - var next = completeWork( - current, - workInProgress, - nextRenderExpirationTime - ); - stopWorkTimer(workInProgress); - resetExpirationTime(workInProgress, nextRenderExpirationTime); - { - ReactDebugCurrentFiber.resetCurrentFiber(); - } - - if (next !== null) { - stopWorkTimer(workInProgress); - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCompleteWork( - workInProgress - ); - } - // If completing this work spawned new work, do that next. We'll come - // back here again. - return next; - } - - if ( - returnFiber !== null && - // Do not append effects to parents if a sibling failed to complete - (returnFiber.effectTag & Incomplete) === NoEffect - ) { - // Append all the effects of the subtree and this fiber onto the effect - // list of the parent. The completion order of the children affects the - // side-effect order. - if (returnFiber.firstEffect === null) { - returnFiber.firstEffect = workInProgress.firstEffect; - } - if (workInProgress.lastEffect !== null) { - if (returnFiber.lastEffect !== null) { - returnFiber.lastEffect.nextEffect = workInProgress.firstEffect; - } - returnFiber.lastEffect = workInProgress.lastEffect; - } - - // If this fiber had side-effects, we append it AFTER the children's - // side-effects. We can perform certain side-effects earlier if - // needed, by doing multiple passes over the effect list. We don't want - // to schedule our own side-effect on our own list because if end up - // reusing children we'll schedule this effect onto itself since we're - // at the end. - var effectTag = workInProgress.effectTag; - // Skip both NoWork and PerformedWork tags when creating the effect list. - // PerformedWork effect is read by React DevTools but shouldn't be committed. - if (effectTag > PerformedWork) { - if (returnFiber.lastEffect !== null) { - returnFiber.lastEffect.nextEffect = workInProgress; - } else { - returnFiber.firstEffect = workInProgress; - } - returnFiber.lastEffect = workInProgress; - } - } +function commitPlacement(finishedWork) { + if (!supportsMutation) { + return; + } - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); - } + // Recursively insert all host nodes into the parent. + var parentFiber = getHostParentFiber(finishedWork); + var parent = void 0; + var isContainer = void 0; + switch (parentFiber.tag) { + case HostComponent: + parent = parentFiber.stateNode; + isContainer = false; + break; + case HostRoot: + parent = parentFiber.stateNode.containerInfo; + isContainer = true; + break; + case HostPortal: + parent = parentFiber.stateNode.containerInfo; + isContainer = true; + break; + default: + invariant( + false, + "Invalid host parent fiber. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + } + if (parentFiber.effectTag & ContentReset) { + // Reset the text content of the parent before doing any insertions + parentFiber.effectTag &= ~ContentReset; + } - if (siblingFiber !== null) { - // If there is more work to do in this returnFiber, do that next. - return siblingFiber; - } else if (returnFiber !== null) { - // If there's no more work in this returnFiber. Complete the returnFiber. - workInProgress = returnFiber; - continue; + var before = getHostSibling(finishedWork); + // We only have the top Fiber that was inserted but we need recurse down its + // children to find all the terminal nodes. + var node = finishedWork; + while (true) { + if (node.tag === HostComponent || node.tag === HostText) { + if (before) { + if (isContainer) { + insertInContainerBefore(parent, node.stateNode, before); } else { - // We've reached the root. - isRootReadyForCommit = true; - return null; + insertBefore(parent, node.stateNode, before); } } else { - // This fiber did not complete because something threw. Pop values off - // the stack without entering the complete phase. If this is a boundary, - // capture values if possible. - var _next = unwindWork( - workInProgress, - nextRenderIsExpired, - nextRenderExpirationTime - ); - // Because this fiber did not complete, don't reset its expiration time. - if (workInProgress.effectTag & DidCapture) { - // Restarting an error boundary - stopFailedWorkTimer(workInProgress); - } else { - stopWorkTimer(workInProgress); - } - - { - ReactDebugCurrentFiber.resetCurrentFiber(); - } - - if (_next !== null) { - stopWorkTimer(workInProgress); - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCompleteWork( - workInProgress - ); - } - // If completing this work spawned new work, do that next. We'll come - // back here again. - // Since we're restarting, remove anything that is not a host effect - // from the effect tag. - _next.effectTag &= HostEffectMask; - return _next; - } - - if (returnFiber !== null) { - // Mark the parent fiber as incomplete and clear its effect list. - returnFiber.firstEffect = returnFiber.lastEffect = null; - returnFiber.effectTag |= Incomplete; - } - - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); - } - - if (siblingFiber !== null) { - // If there is more work to do in this returnFiber, do that next. - return siblingFiber; - } else if (returnFiber !== null) { - // If there's no more work in this returnFiber. Complete the returnFiber. - workInProgress = returnFiber; - continue; + if (isContainer) { + appendChildToContainer(parent, node.stateNode); } else { - return null; + appendChild(parent, node.stateNode); } } + } else if (node.tag === HostPortal) { + // If the insertion itself is a portal, then we don't want to traverse + // down its children. Instead, we'll get insertions from each child in + // the portal directly. + } else if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; } - - // Without this explicit null return Flow complains of invalid return type - // TODO Remove the above while(true) loop - // eslint-disable-next-line no-unreachable - return null; - } - - function performUnitOfWork(workInProgress) { - // The current, flushed, state of this fiber is the alternate. - // Ideally nothing should rely on this, but relying on it here - // means that we don't need an additional field on the work in - // progress. - var current = workInProgress.alternate; - - // See if beginning this work spawns more work. - startWorkTimer(workInProgress); - { - ReactDebugCurrentFiber.setCurrentFiber(workInProgress); + if (node === finishedWork) { + return; } - - if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { - stashedWorkInProgressProperties = assignFiberPropertiesInDEV( - stashedWorkInProgressProperties, - workInProgress - ); + while (node.sibling === null) { + if (node.return === null || node.return === finishedWork) { + return; + } + node = node.return; } + node.sibling.return = node.return; + node = node.sibling; + } +} - var next = void 0; - if (enableProfilerTimer) { - if (workInProgress.mode & ProfileMode) { - startBaseRenderTimer(); - } +function unmountHostComponents(current) { + // We only have the top Fiber that was inserted but we need recurse down its + var node = current; - next = beginWork(current, workInProgress, nextRenderExpirationTime); + // Each iteration, currentParent is populated with node's host parent if not + // currentParentIsValid. + var currentParentIsValid = false; + var currentParent = void 0; + var currentParentIsContainer = void 0; - if (workInProgress.mode & ProfileMode) { - // Update "base" time if the render wasn't bailed out on. - recordElapsedBaseRenderTimeIfRunning(workInProgress); - stopBaseRenderTimerIfRunning(); + while (true) { + if (!currentParentIsValid) { + var parent = node.return; + findParent: while (true) { + invariant( + parent !== null, + "Expected to find a host parent. This error is likely caused by " + + "a bug in React. Please file an issue." + ); + switch (parent.tag) { + case HostComponent: + currentParent = parent.stateNode; + currentParentIsContainer = false; + break findParent; + case HostRoot: + currentParent = parent.stateNode.containerInfo; + currentParentIsContainer = true; + break findParent; + case HostPortal: + currentParent = parent.stateNode.containerInfo; + currentParentIsContainer = true; + break findParent; + } + parent = parent.return; } - } else { - next = beginWork(current, workInProgress, nextRenderExpirationTime); + currentParentIsValid = true; } - { - 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 (node.tag === HostComponent || node.tag === HostText) { + commitNestedUnmounts(node); + // After all the children have unmounted, it is now safe to remove the + // node from the tree. + if (currentParentIsContainer) { + removeChildFromContainer(currentParent, node.stateNode); + } else { + removeChild(currentParent, node.stateNode); + } + // Don't visit children because we already visited them. + } else if (node.tag === HostPortal) { + // When we go into a portal, it becomes the parent to remove from. + // We will reassign it back when we pop the portal on the way up. + currentParent = node.stateNode.containerInfo; + // Visit children because portals might contain host components. + if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; + } + } else { + commitUnmount(node); + // Visit children because we may find more host components below. + if (node.child !== null) { + node.child.return = node; + node = node.child; + continue; } } - if (true && ReactFiberInstrumentation_1.debugTool) { - ReactFiberInstrumentation_1.debugTool.onBeginWork(workInProgress); + if (node === current) { + return; } - - if (next === null) { - // If this doesn't spawn new work, complete the current work. - next = completeUnitOfWork(workInProgress); + while (node.sibling === null) { + if (node.return === null || node.return === current) { + return; + } + node = node.return; + if (node.tag === HostPortal) { + // When we go out of the portal, we need to restore the parent. + // Since we don't keep a stack of them, we will search for it. + currentParentIsValid = false; + } } + node.sibling.return = node.return; + node = node.sibling; + } +} - ReactCurrentOwner.current = null; +function commitDeletion(current) { + if (supportsMutation) { + // Recursively delete all host nodes from the parent. + // Detach refs and call componentWillUnmount() on the whole subtree. + unmountHostComponents(current); + } else { + // Detach refs and call componentWillUnmount() on the whole subtree. + commitNestedUnmounts(current); + } + detachFiber(current); +} - return next; +function commitWork(current, finishedWork) { + if (!supportsMutation) { + commitContainer(finishedWork); + return; } - function workLoop(isAsync) { - if (!isAsync) { - // Flush all expired work. - while (nextUnitOfWork !== null) { - nextUnitOfWork = performUnitOfWork(nextUnitOfWork); - } - } else { - // Flush asynchronous work until the deadline runs out of time. - while (nextUnitOfWork !== null && !shouldYield()) { - nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + switch (finishedWork.tag) { + case ClassComponent: { + return; + } + case HostComponent: { + var instance = finishedWork.stateNode; + if (instance != null) { + // Commit the work prepared earlier. + var newProps = finishedWork.memoizedProps; + // For hydration we reuse the update path but we treat the oldProps + // as the newProps. The updatePayload will contain the real change in + // this case. + var oldProps = current !== null ? current.memoizedProps : newProps; + var type = finishedWork.type; + // TODO: Type the updateQueue to be specific to host components. + var updatePayload = finishedWork.updateQueue; + finishedWork.updateQueue = null; + if (updatePayload !== null) { + commitUpdate( + instance, + updatePayload, + type, + oldProps, + newProps, + finishedWork + ); + } } - + return; + } + case HostText: { + invariant( + finishedWork.stateNode !== null, + "This should have a text node initialized. This error is likely " + + "caused by a bug in React. Please file an issue." + ); + var textInstance = finishedWork.stateNode; + var newText = finishedWork.memoizedProps; + // For hydration we reuse the update path but we treat the oldProps + // as the newProps. The updatePayload will contain the real change in + // this case. + var oldText = current !== null ? current.memoizedProps : newText; + commitTextUpdate(textInstance, oldText, newText); + return; + } + case HostRoot: { + return; + } + case Profiler: { if (enableProfilerTimer) { - // If we didn't finish, pause the "actual" render timer. - // We'll restart it when we resume work. - pauseActualRenderTimerIfRunning(); + var onRender = finishedWork.memoizedProps.onRender; + onRender( + finishedWork.memoizedProps.id, + current === null ? "mount" : "update", + finishedWork.actualDuration, + finishedWork.treeBaseTime, + finishedWork.actualStartTime, + getCommitTime() + ); } + return; } - } - - function renderRoot(root, expirationTime, isAsync) { - invariant( - !isWorking, - "renderRoot was called recursively. This error is likely caused " + - "by a bug in React. Please file an issue." - ); - isWorking = true; - - // Check if we're starting from a fresh stack, or if we're resuming from - // previously yielded work. - if ( - expirationTime !== nextRenderExpirationTime || - root !== nextRoot || - nextUnitOfWork === null - ) { - // Reset the stack and start working from the root. - resetStack(); - nextRoot = root; - nextRenderExpirationTime = expirationTime; - nextLatestTimeoutMs = -1; - nextUnitOfWork = createWorkInProgress( - nextRoot.current, - null, - nextRenderExpirationTime + case TimeoutComponent: { + 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." ); - root.pendingCommitExpirationTime = NoWork; } + } +} - var didFatal = false; - - nextRenderIsExpired = - !isAsync || nextRenderExpirationTime <= mostRecentCurrentTime; - - startWorkLoopTimer(nextUnitOfWork); - - do { - try { - workLoop(isAsync); - } catch (thrownValue) { - if (enableProfilerTimer) { - // Stop "base" render timer in the event of an error. - stopBaseRenderTimerIfRunning(); - } - - if (nextUnitOfWork === null) { - // This is a fatal error. - didFatal = true; - onUncaughtError(thrownValue); - } else { - { - // Reset global debug state - // We assume this is defined in DEV - resetCurrentlyProcessingQueue(); - } - - var failedUnitOfWork = nextUnitOfWork; - if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { - replayUnitOfWork(failedUnitOfWork, thrownValue, isAsync); - } - - // TODO: we already know this isn't true in some cases. - // At least this shows a nicer error message until we figure out the cause. - // https://github.com/facebook/react/issues/12449#issuecomment-386727431 - invariant( - nextUnitOfWork !== null, - "Failed to replay rendering after an error. This " + - "is likely caused by a bug in React. Please file an issue " + - "with a reproducing case to help us find it." - ); +function commitResetTextContent(current) { + if (!supportsMutation) { + return; + } + resetTextContent(current.stateNode); +} - 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. - didFatal = true; - onUncaughtError(thrownValue); - break; - } - throwException( - root, - returnFiber, - sourceFiber, - thrownValue, - nextRenderIsExpired, - nextRenderExpirationTime, - mostRecentCurrentTimeMs - ); - nextUnitOfWork = completeUnitOfWork(sourceFiber); - } - } - break; - } while (true); +function createRootErrorUpdate(fiber, errorInfo, expirationTime) { + var update = createUpdate(expirationTime); + // Unmount the root by rendering null. + update.tag = CaptureUpdate; + // Caution: React DevTools currently depends on this property + // being called "element". + update.payload = { element: null }; + var error = errorInfo.value; + update.callback = function() { + onUncaughtError(error); + logError(fiber, errorInfo); + }; + return update; +} - // We're done performing work. Time to clean up. - var didCompleteRoot = false; - isWorking = false; +function createClassErrorUpdate(fiber, errorInfo, expirationTime) { + var update = createUpdate(expirationTime); + update.tag = CaptureUpdate; + var getDerivedStateFromCatch = fiber.type.getDerivedStateFromCatch; + if ( + enableGetDerivedStateFromCatch && + typeof getDerivedStateFromCatch === "function" + ) { + var error = errorInfo.value; + update.payload = function() { + return getDerivedStateFromCatch(error); + }; + } - // 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( - !nextRenderIsExpired, - "Expired work should have completed. This error is likely caused " + - "by a bug in React. Please file an issue." - ); - markSuspendedPriorityLevel(root, expirationTime); - if (nextLatestTimeoutMs >= 0) { - setTimeout(function() { - retrySuspendedRoot(root, expirationTime); - }, nextLatestTimeoutMs); - } - var firstUnblockedExpirationTime = findNextPendingPriorityLevel(root); - onBlock(firstUnblockedExpirationTime); - return null; - } - } 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; - } + var inst = fiber.stateNode; + if (inst !== null && typeof inst.componentDidCatch === "function") { + update.callback = function callback() { + if ( + !enableGetDerivedStateFromCatch || + getDerivedStateFromCatch !== "function" + ) { + // To preserve the preexisting retry behavior of error boundaries, + // we keep track of which ones already failed during this batch. + // This gets reset before we yield back to the browser. + // TODO: Warn in strict mode if getDerivedStateFromCatch is + // not defined. + markLegacyErrorBoundaryAsFailed(this); + } + var error = errorInfo.value; + var stack = errorInfo.stack; + logError(fiber, errorInfo); + this.componentDidCatch(error, { + componentStack: stack !== null ? stack : "" + }); + }; } + return update; +} - function dispatch(sourceFiber, value, expirationTime) { - invariant( - !isWorking || isCommitting, - "dispatch: Cannot dispatch during the render phase." - ); +function schedulePing(finishedWork) { + // Once the promise resolves, we should try rendering the non- + // placeholder state again. + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, finishedWork); + var recoveryUpdate = createUpdate(expirationTime); + enqueueUpdate(finishedWork, recoveryUpdate, expirationTime); + scheduleWork(finishedWork, expirationTime); +} + +function throwException( + root, + returnFiber, + sourceFiber, + value, + renderExpirationTime, + currentTimeMs +) { + // The source fiber did not complete. + sourceFiber.effectTag |= Incomplete; + // Its effect list is no longer valid. + sourceFiber.firstEffect = sourceFiber.lastEffect = null; - var fiber = sourceFiber.return; - while (fiber !== null) { - switch (fiber.tag) { - case ClassComponent: - var ctor = fiber.type; - var instance = fiber.stateNode; - if ( - typeof ctor.getDerivedStateFromCatch === "function" || - (typeof instance.componentDidCatch === "function" && - !isAlreadyFailedLegacyErrorBoundary(instance)) + if ( + enableSuspense && + value !== null && + typeof value === "object" && + typeof value.then === "function" + ) { + // This is a thenable. + var thenable = value; + + // TODO: Should use the earliest known expiration time + var expirationTimeMs = expirationTimeToMs(renderExpirationTime); + var startTimeMs = expirationTimeMs - 5000; + var elapsedMs = currentTimeMs - startTimeMs; + if (elapsedMs < 0) { + elapsedMs = 0; + } + var remainingTimeMs = expirationTimeMs - currentTimeMs; + + // Find the earliest timeout of all the timeouts in the ancestor path. + // TODO: Alternatively, we could store the earliest timeout on the context + // stack, rather than searching on every suspend. + var _workInProgress = returnFiber; + var earliestTimeoutMs = -1; + searchForEarliestTimeout: do { + if (_workInProgress.tag === TimeoutComponent) { + var current = _workInProgress.alternate; + if (current !== null && current.memoizedState === true) { + // A parent Timeout already committed in a placeholder state. We + // need to handle this promise immediately. In other words, we + // should never suspend inside a tree that already expired. + earliestTimeoutMs = 0; + break searchForEarliestTimeout; + } + var timeoutPropMs = _workInProgress.pendingProps.ms; + if (typeof timeoutPropMs === "number") { + if (timeoutPropMs <= 0) { + earliestTimeoutMs = 0; + break searchForEarliestTimeout; + } else if ( + earliestTimeoutMs === -1 || + timeoutPropMs < earliestTimeoutMs ) { - var errorInfo = createCapturedValue(value, sourceFiber); - var update = createClassErrorUpdate( - fiber, - errorInfo, - expirationTime - ); - enqueueUpdate(fiber, update, expirationTime); - scheduleWork(fiber, expirationTime); - return; + earliestTimeoutMs = timeoutPropMs; } - break; - case HostRoot: { - var _errorInfo = createCapturedValue(value, sourceFiber); - var _update = createRootErrorUpdate( - fiber, - _errorInfo, - expirationTime - ); - enqueueUpdate(fiber, _update, expirationTime); - scheduleWork(fiber, expirationTime); - return; + } else if (earliestTimeoutMs === -1) { + earliestTimeoutMs = remainingTimeMs; } } - fiber = fiber.return; - } + _workInProgress = _workInProgress.return; + } while (_workInProgress !== null); - if (sourceFiber.tag === HostRoot) { - // Error was thrown at the root. There is no parent, so the root - // itself should capture it. - var rootFiber = sourceFiber; - var _errorInfo2 = createCapturedValue(value, rootFiber); - var _update2 = createRootErrorUpdate( - rootFiber, - _errorInfo2, - expirationTime - ); - enqueueUpdate(rootFiber, _update2, expirationTime); - scheduleWork(rootFiber, expirationTime); - } - } + // Compute the remaining time until the timeout. + var msUntilTimeout = earliestTimeoutMs - elapsedMs; - function onCommitPhaseError(fiber, error) { - return dispatch(fiber, error, Sync); + if (renderExpirationTime === Never || msUntilTimeout > 0) { + // There's still time remaining. + markTimeout(root, thenable, msUntilTimeout, renderExpirationTime); + var onResolveOrReject = function() { + retrySuspendedRoot(root, renderExpirationTime); + }; + thenable.then(onResolveOrReject, onResolveOrReject); + return; + } else { + // No time remaining. Need to fallback to placeholder. + // Find the nearest timeout that can be retried. + _workInProgress = returnFiber; + do { + switch (_workInProgress.tag) { + case HostRoot: { + // The root expired, but no fallback was provided. Throw a + // helpful error. + var message = + renderExpirationTime === Sync + ? "A synchronous update was suspended, but no fallback UI " + + "was provided." + : "An update was suspended for longer than the timeout, " + + "but no fallback UI was provided."; + value = new Error(message); + break; + } + case TimeoutComponent: { + if ((_workInProgress.effectTag & DidCapture) === NoEffect) { + _workInProgress.effectTag |= ShouldCapture; + var _onResolveOrReject = schedulePing.bind(null, _workInProgress); + thenable.then(_onResolveOrReject, _onResolveOrReject); + return; + } + // Already captured during this render. Continue to the next + // Timeout ancestor. + break; + } + } + _workInProgress = _workInProgress.return; + } while (_workInProgress !== null); + } + } else { + // This is an error. + markError(root); + if ( + // Retry (at the same priority) one more time before handling the error. + // The retry will flush synchronously. (Unless we're already rendering + // synchronously, in which case move to the next check.) + (!root.didError && renderExpirationTime !== Sync) || + // There's lower priority work. If so, it may have the effect of fixing + // the exception that was just thrown. + hasLowerPriorityWork(root, renderExpirationTime) + ) { + return; + } } - function computeAsyncExpiration(currentTime) { - // Given the current clock time, returns an expiration time. We use rounding - // to batch like updates together. - // Should complete within ~1000ms. 1200ms max. - var expirationMs = 5000; - var bucketSizeMs = 250; - return computeExpirationBucket(currentTime, expirationMs, bucketSizeMs); - } + // We didn't find a boundary that could handle this type of exception. Start + // over and traverse parent path again, this time treating the exception + // as an error. + value = createCapturedValue(value, sourceFiber); + var workInProgress = returnFiber; + do { + switch (workInProgress.tag) { + case HostRoot: { + var _errorInfo = value; + workInProgress.effectTag |= ShouldCapture; + var update = createRootErrorUpdate( + workInProgress, + _errorInfo, + renderExpirationTime + ); + enqueueCapturedUpdate(workInProgress, update, renderExpirationTime); + return; + } + case ClassComponent: + // Capture and retry + var errorInfo = value; + var ctor = workInProgress.type; + var instance = workInProgress.stateNode; + if ( + (workInProgress.effectTag & DidCapture) === NoEffect && + ((typeof ctor.getDerivedStateFromCatch === "function" && + enableGetDerivedStateFromCatch) || + (instance !== null && + typeof instance.componentDidCatch === "function" && + !isAlreadyFailedLegacyErrorBoundary(instance))) + ) { + workInProgress.effectTag |= ShouldCapture; + // Schedule the error boundary to re-render using updated state + var _update = createClassErrorUpdate( + workInProgress, + errorInfo, + renderExpirationTime + ); + enqueueCapturedUpdate(workInProgress, _update, renderExpirationTime); + return; + } + break; + default: + break; + } + workInProgress = workInProgress.return; + } while (workInProgress !== null); +} - function computeInteractiveExpiration(currentTime) { - var expirationMs = void 0; - // We intentionally set a higher expiration time for interactive updates in - // dev than in production. - // If the main thread is being blocked so long that you hit the expiration, - // it's a problem that could be solved with better scheduling. - // People will be more likely to notice this and fix it with the long - // expiration time in development. - // In production we opt for better UX at the risk of masking scheduling - // problems, by expiring fast. - { - // Should complete within ~500ms. 600ms max. - expirationMs = 500; +function unwindWork(workInProgress, renderExpirationTime) { + if (enableProfilerTimer) { + if (workInProgress.mode & ProfileMode) { + recordElapsedActualRenderTime(workInProgress); } - var bucketSizeMs = 100; - return computeExpirationBucket(currentTime, expirationMs, bucketSizeMs); } - // Creates a unique async expiration time. - function computeUniqueAsyncExpiration() { - var currentTime = recalculateCurrentTime(); - var result = computeAsyncExpiration(currentTime); - if (result <= lastUniqueAsyncExpiration) { - // Since we assume the current time monotonically increases, we only hit - // this branch when computeUniqueAsyncExpiration is fired multiple times - // within a 200ms window (or whatever the async bucket size is). - result = lastUniqueAsyncExpiration + 1; - } - lastUniqueAsyncExpiration = result; - return lastUniqueAsyncExpiration; - } - - function computeExpirationForFiber(currentTime, fiber) { - var expirationTime = void 0; - if (expirationContext !== NoWork) { - // An explicit expiration context was set; - expirationTime = expirationContext; - } else if (isWorking) { - if (isCommitting) { - // Updates that occur during the commit phase should have sync priority - // by default. - expirationTime = Sync; - } else { - // Updates during the render phase should expire at the same time as - // the work that is being rendered. - expirationTime = nextRenderExpirationTime; + switch (workInProgress.tag) { + case ClassComponent: { + popContextProvider(workInProgress); + var effectTag = workInProgress.effectTag; + if (effectTag & ShouldCapture) { + workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture; + return workInProgress; } - } else { - // No explicit expiration context was set, and we're not currently - // performing work. Calculate a new expiration time. - if (fiber.mode & AsyncMode) { - if (isBatchingInteractiveUpdates) { - // This is an interactive update - expirationTime = computeInteractiveExpiration(currentTime); - } else { - // This is an async update - expirationTime = computeAsyncExpiration(currentTime); - } - } else { - // This is a sync update - expirationTime = Sync; + return null; + } + case HostRoot: { + popHostContainer(workInProgress); + popTopLevelContextObject(workInProgress); + var _effectTag = workInProgress.effectTag; + if (_effectTag & ShouldCapture) { + workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture; + return workInProgress; } + return null; } - if (isBatchingInteractiveUpdates) { - // This is an interactive update. Keep track of the lowest pending - // interactive expiration time. This allows us to synchronously flush - // all interactive updates when needed. - if ( - lowestPendingInteractiveExpirationTime === NoWork || - expirationTime > lowestPendingInteractiveExpirationTime - ) { - lowestPendingInteractiveExpirationTime = expirationTime; + case HostComponent: { + popHostContext(workInProgress); + return null; + } + case TimeoutComponent: { + var _effectTag2 = workInProgress.effectTag; + if (_effectTag2 & ShouldCapture) { + workInProgress.effectTag = (_effectTag2 & ~ShouldCapture) | DidCapture; + return workInProgress; } + return null; } - return expirationTime; + case HostPortal: + popHostContainer(workInProgress); + return null; + case ContextProvider: + popProvider(workInProgress); + return null; + default: + return null; } +} - // TODO: Rename this to scheduleTimeout or something - function suspendRoot(root, thenable, timeoutMs, suspendedTime) { - // Schedule the timeout. - if (timeoutMs >= 0 && nextLatestTimeoutMs < timeoutMs) { - nextLatestTimeoutMs = timeoutMs; +function unwindInterruptedWork(interruptedWork) { + if (enableProfilerTimer) { + if (interruptedWork.mode & ProfileMode) { + // Resume in case we're picking up on work that was paused. + resumeActualRenderTimerIfPaused(); + recordElapsedActualRenderTime(interruptedWork); } } - function retrySuspendedRoot(root, suspendedTime) { - markPingedPriorityLevel(root, suspendedTime); - var retryTime = findNextPendingPriorityLevel(root); - if (retryTime !== NoWork) { - requestRetry(root, retryTime); + switch (interruptedWork.tag) { + case ClassComponent: { + popContextProvider(interruptedWork); + break; + } + case HostRoot: { + popHostContainer(interruptedWork); + popTopLevelContextObject(interruptedWork); + break; + } + case HostComponent: { + popHostContext(interruptedWork); + break; } + case HostPortal: + popHostContainer(interruptedWork); + break; + case ContextProvider: + popProvider(interruptedWork); + break; + default: + break; } +} + +var invokeGuardedCallback$2 = ReactErrorUtils.invokeGuardedCallback; +var hasCaughtError = ReactErrorUtils.hasCaughtError; +var clearCaughtError = ReactErrorUtils.clearCaughtError; - function scheduleWork(fiber, expirationTime) { - recordScheduleUpdate(); +var didWarnAboutStateTransition = void 0; +var didWarnSetStateChildContext = void 0; +var warnAboutUpdateOnUnmounted = void 0; +var warnAboutInvalidUpdates = void 0; - { - if (fiber.tag === ClassComponent) { - var instance = fiber.stateNode; - warnAboutInvalidUpdates(instance); - } +{ + didWarnAboutStateTransition = false; + didWarnSetStateChildContext = false; + 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) + ); + didWarnStateUpdateForUnmountedComponent[componentName] = true; + }; - var node = fiber; - while (node !== null) { - // Walk the parent path to the root and update each node's - // expiration time. - if ( - node.expirationTime === NoWork || - node.expirationTime > expirationTime - ) { - node.expirationTime = expirationTime; - } - if (node.alternate !== null) { - if ( - node.alternate.expirationTime === NoWork || - node.alternate.expirationTime > expirationTime - ) { - node.alternate.expirationTime = expirationTime; + warnAboutInvalidUpdates = function(instance) { + switch (ReactDebugCurrentFiber.phase) { + case "getChildContext": + if (didWarnSetStateChildContext) { + return; } - } - if (node.return === null) { - if (node.tag === HostRoot) { - var root = node.stateNode; - if ( - !isWorking && - nextRenderExpirationTime !== NoWork && - expirationTime < nextRenderExpirationTime - ) { - // This is an interruption. (Used for performance tracking.) - interruptedBy = fiber; - resetStack(); - } - markPendingPriorityLevel(root, expirationTime); - var nextExpirationTimeToWorkOn = findNextPendingPriorityLevel(root); - 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 - ) { - requestWork(root, nextExpirationTimeToWorkOn); - } - if (nestedUpdateCount > NESTED_UPDATE_LIMIT) { - invariant( - false, - "Maximum update depth exceeded. This can happen when a " + - "component repeatedly calls setState inside " + - "componentWillUpdate or componentDidUpdate. React limits " + - "the number of nested updates to prevent infinite loops." - ); - } - } else { - { - if (fiber.tag === ClassComponent) { - warnAboutUpdateOnUnmounted(fiber); - } - } + warning( + false, + "setState(...): Cannot call setState() inside getChildContext()" + ); + didWarnSetStateChildContext = true; + break; + case "render": + if (didWarnAboutStateTransition) { return; } - } - node = node.return; - } - } - - function recalculateCurrentTime() { - // Subtract initial time so it fits inside 32bits - mostRecentCurrentTimeMs = now() - originalStartTimeMs; - mostRecentCurrentTime = msToExpirationTime(mostRecentCurrentTimeMs); - return mostRecentCurrentTime; - } - - function deferredUpdates(fn) { - var previousExpirationContext = expirationContext; - var currentTime = recalculateCurrentTime(); - expirationContext = computeAsyncExpiration(currentTime); - try { - return fn(); - } finally { - expirationContext = previousExpirationContext; - } - } - function syncUpdates(fn, a, b, c, d) { - var previousExpirationContext = expirationContext; - expirationContext = Sync; - try { - return fn(a, b, c, d); - } finally { - expirationContext = previousExpirationContext; + warning( + false, + "Cannot update during an existing state transition (such as within " + + "`render` or another component's constructor). Render methods should " + + "be a pure function of props and state; constructor side-effects are " + + "an anti-pattern, but can be moved to `componentWillMount`." + ); + didWarnAboutStateTransition = true; + break; } - } - - // TODO: Everything below this is written as if it has been lifted to the - // renderers. I'll do this in a follow-up. + }; +} - // Linked-list of roots - var firstScheduledRoot = null; - var lastScheduledRoot = null; +// Represents the current time in ms. +var originalStartTimeMs = now(); +var mostRecentCurrentTime = msToExpirationTime(0); +var mostRecentCurrentTimeMs = originalStartTimeMs; - var callbackExpirationTime = NoWork; - var callbackID = -1; - var isRendering = false; - var nextFlushedRoot = null; - var nextFlushedExpirationTime = NoWork; - var lowestPendingInteractiveExpirationTime = NoWork; - var deadlineDidExpire = false; - var hasUnhandledError = false; - var unhandledError = null; - var deadline = null; +// Used to ensure computeUniqueAsyncExpiration is monotonically increases. +var lastUniqueAsyncExpiration = 0; - var isBatchingUpdates = false; - var isUnbatchingUpdates = false; - var isBatchingInteractiveUpdates = false; +// Represents the expiration time that incoming updates should use. (If this +// is NoWork, use the default strategy: async updates in async mode, sync +// updates in sync mode.) +var expirationContext = NoWork; - var completedBatches = null; +var isWorking = false; - // Use these to prevent an infinite loop of nested updates - var NESTED_UPDATE_LIMIT = 1000; - var nestedUpdateCount = 0; +// The next work in progress fiber that we're currently working on. +var nextUnitOfWork = null; +var nextRoot = null; +// The time at which we're currently rendering work. +var nextRenderExpirationTime = NoWork; +var nextLatestTimeoutMs = -1; +var nextRenderDidError = false; - var timeHeuristicForUnitOfWork = 1; +// The next fiber with an effect that we're currently committing. +var nextEffect = null; - function scheduleCallbackWithExpiration(expirationTime) { - if (callbackExpirationTime !== NoWork) { - // A callback is already scheduled. Check its expiration time (timeout). - if (expirationTime > callbackExpirationTime) { - // Existing callback has sufficient timeout. Exit. - return; - } else { - // Existing callback has insufficient timeout. Cancel and schedule a - // new one. - cancelDeferredCallback(callbackID); - } - // The request callback timer is already running. Don't start a new one. - } else { - startRequestCallbackTimer(); - } +var isCommitting$1 = false; - // Compute a timeout for the given expiration time. - var currentMs = now() - originalStartTimeMs; - var expirationMs = expirationTimeToMs(expirationTime); - var timeout = expirationMs - currentMs; +var legacyErrorBoundariesThatAlreadyFailed = null; - callbackExpirationTime = expirationTime; - callbackID = scheduleDeferredCallback(performAsyncWork, { - timeout: timeout - }); - } +// Used for performance tracking. +var interruptedBy = null; - function requestRetry(root, expirationTime) { +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, thrownValue, isYieldy) { if ( - root.remainingExpirationTime === NoWork || - root.remainingExpirationTime < expirationTime + thrownValue !== null && + typeof thrownValue === "object" && + typeof thrownValue.then === "function" ) { - // For a retry, only update the remaining expiration time if it has a - // *lower priority* than the existing value. This is because, on a retry, - // we should attempt to coalesce as much as possible. - requestWork(root, expirationTime); - } - } - - // requestWork is called by the scheduler whenever a root receives an update. - // It's up to the renderer to call renderRoot at some point in the future. - function requestWork(root, expirationTime) { - addRootToSchedule(root, expirationTime); - - if (isRendering) { - // Prevent reentrancy. Remaining work will be scheduled at the end of - // the currently rendering batch. + // Don't replay promises. Treat everything else like an error. + // TODO: Need to figure out a different strategy if/when we add + // support for catching other types. return; } - if (isBatchingUpdates) { - // Flush work at the end of the batch. - if (isUnbatchingUpdates) { - // ...unless we're inside unbatchedUpdates, in which case we should - // flush it now. - nextFlushedRoot = root; - nextFlushedExpirationTime = Sync; - performWorkOnRoot(root, Sync, false); - } + // Restore the original state of the work-in-progress + if (stashedWorkInProgressProperties === null) { + // This should never happen. Don't throw because this code is DEV-only. + warning( + false, + "Could not replay rendering after an error. This is likely a bug in React. " + + "Please file an issue." + ); return; } + assignFiberPropertiesInDEV( + failedUnitOfWork, + stashedWorkInProgressProperties + ); - // TODO: Get rid of Sync and use current time? - if (expirationTime === Sync) { - performSyncWork(); - } else { - scheduleCallbackWithExpiration(expirationTime); - } - } - - function addRootToSchedule(root, expirationTime) { - // Add the root to the schedule. - // Check if this root is already part of the schedule. - if (root.nextScheduledRoot === null) { - // This root is not already scheduled. Add it. - root.remainingExpirationTime = expirationTime; - if (lastScheduledRoot === null) { - firstScheduledRoot = lastScheduledRoot = root; - root.nextScheduledRoot = root; - } else { - lastScheduledRoot.nextScheduledRoot = root; - lastScheduledRoot = root; - lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; - } - } else { - // This root is already scheduled, but its priority may have increased. - var remainingExpirationTime = root.remainingExpirationTime; - if ( - remainingExpirationTime === NoWork || - expirationTime < remainingExpirationTime - ) { - // Update the priority. - root.remainingExpirationTime = expirationTime; - } + switch (failedUnitOfWork.tag) { + case HostRoot: + popHostContainer(failedUnitOfWork); + popTopLevelContextObject(failedUnitOfWork); + break; + case HostComponent: + popHostContext(failedUnitOfWork); + break; + case ClassComponent: + popContextProvider(failedUnitOfWork); + break; + case HostPortal: + popHostContainer(failedUnitOfWork); + break; + case ContextProvider: + popProvider(failedUnitOfWork); + break; } - } - - function findHighestPriorityRoot() { - var highestPriorityWork = NoWork; - var highestPriorityRoot = null; - if (lastScheduledRoot !== null) { - var previousScheduledRoot = lastScheduledRoot; - var root = firstScheduledRoot; - while (root !== null) { - var remainingExpirationTime = root.remainingExpirationTime; - if (remainingExpirationTime === NoWork) { - // This root no longer has work. Remove it from the scheduler. + // Replay the begin phase. + isReplayingFailedUnitOfWork = true; + originalReplayError = thrownValue; + invokeGuardedCallback$2(null, workLoop, null, isYieldy); + isReplayingFailedUnitOfWork = false; + originalReplayError = null; + if (hasCaughtError()) { + clearCaughtError(); - // TODO: This check is redudant, but Flow is confused by the branch - // below where we set lastScheduledRoot to null, even though we break - // from the loop right after. - invariant( - previousScheduledRoot !== null && lastScheduledRoot !== null, - "Should have a previous and last root. This error is likely " + - "caused by a bug in React. Please file an issue." - ); - if (root === root.nextScheduledRoot) { - // This is the only root in the list. - root.nextScheduledRoot = null; - firstScheduledRoot = lastScheduledRoot = null; - break; - } else if (root === firstScheduledRoot) { - // This is the first root in the list. - var next = root.nextScheduledRoot; - firstScheduledRoot = next; - lastScheduledRoot.nextScheduledRoot = next; - root.nextScheduledRoot = null; - } else if (root === lastScheduledRoot) { - // This is the last root in the list. - lastScheduledRoot = previousScheduledRoot; - lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; - root.nextScheduledRoot = null; - break; - } else { - previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot; - root.nextScheduledRoot = null; - } - root = previousScheduledRoot.nextScheduledRoot; - } else { - if ( - highestPriorityWork === NoWork || - remainingExpirationTime < highestPriorityWork - ) { - // Update the priority, if it's higher - highestPriorityWork = remainingExpirationTime; - highestPriorityRoot = root; - } - if (root === lastScheduledRoot) { - break; - } - previousScheduledRoot = root; - root = root.nextScheduledRoot; + if (enableProfilerTimer) { + if (failedUnitOfWork.mode & ProfileMode) { + recordElapsedActualRenderTime(failedUnitOfWork); } + + // Stop "base" render timer again (after the re-thrown error). + stopBaseRenderTimerIfRunning(); } + } else { + // If the begin phase did not fail the second time, set this pointer + // back to the original value. + nextUnitOfWork = failedUnitOfWork; } + }; + rethrowOriginalError = function() { + throw originalReplayError; + }; +} - // If the next root is the same as the previous root, this is a nested - // update. To prevent an infinite loop, increment the nested update count. - var previousFlushedRoot = nextFlushedRoot; - if ( - previousFlushedRoot !== null && - previousFlushedRoot === highestPriorityRoot && - highestPriorityWork === Sync - ) { - nestedUpdateCount++; - } else { - // Reset whenever we switch roots. - nestedUpdateCount = 0; +function resetStack() { + if (nextUnitOfWork !== null) { + var interruptedWork = nextUnitOfWork.return; + while (interruptedWork !== null) { + unwindInterruptedWork(interruptedWork); + interruptedWork = interruptedWork.return; } - nextFlushedRoot = highestPriorityRoot; - nextFlushedExpirationTime = highestPriorityWork; } - function performAsyncWork(dl) { - performWork(NoWork, true, dl); + { + ReactStrictModeWarnings.discardPendingWarnings(); + checkThatStackIsEmpty(); } - function performSyncWork() { - performWork(Sync, false, null); - } + nextRoot = null; + nextRenderExpirationTime = NoWork; + nextLatestTimeoutMs = -1; + nextRenderDidError = false; + nextUnitOfWork = null; +} - function performWork(minExpirationTime, isAsync, dl) { - deadline = dl; +function commitAllHostEffects() { + while (nextEffect !== null) { + { + ReactDebugCurrentFiber.setCurrentFiber(nextEffect); + } + recordEffect(); - // Keep working on roots until there's no more work, or until the we reach - // the deadline. - findHighestPriorityRoot(); + var effectTag = nextEffect.effectTag; - if (enableProfilerTimer) { - resumeActualRenderTimerIfPaused(); + if (effectTag & ContentReset) { + commitResetTextContent(nextEffect); } - if (enableUserTimingAPI && deadline !== null) { - var didExpire = nextFlushedExpirationTime < recalculateCurrentTime(); - var timeout = expirationTimeToMs(nextFlushedExpirationTime); - stopRequestCallbackTimer(didExpire, timeout); + if (effectTag & Ref) { + var current = nextEffect.alternate; + if (current !== null) { + commitDetachRef(current); + } } - if (isAsync) { - while ( - nextFlushedRoot !== null && - nextFlushedExpirationTime !== NoWork && - (minExpirationTime === NoWork || - minExpirationTime >= nextFlushedExpirationTime) && - (!deadlineDidExpire || - recalculateCurrentTime() >= nextFlushedExpirationTime) - ) { - recalculateCurrentTime(); - performWorkOnRoot( - nextFlushedRoot, - nextFlushedExpirationTime, - !deadlineDidExpire - ); - findHighestPriorityRoot(); + // The following switch statement is only concerned about placement, + // updates, and deletions. To avoid needing to add a case for every + // possible bitmap value, we remove the secondary effects from the + // effect tag and switch on that value. + var primaryEffectTag = effectTag & (Placement | Update | Deletion); + switch (primaryEffectTag) { + case Placement: { + commitPlacement(nextEffect); + // Clear the "placement" from effect tag so that we know that this is inserted, before + // any life-cycles like componentDidMount gets called. + // TODO: findDOMNode doesn't rely on this any more but isMounted + // does and isMounted is deprecated anyway so we should be able + // to kill this. + nextEffect.effectTag &= ~Placement; + break; } - } else { - while ( - nextFlushedRoot !== null && - nextFlushedExpirationTime !== NoWork && - (minExpirationTime === NoWork || - minExpirationTime >= nextFlushedExpirationTime) - ) { - performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false); - findHighestPriorityRoot(); + case PlacementAndUpdate: { + // Placement + commitPlacement(nextEffect); + // Clear the "placement" from effect tag so that we know that this is inserted, before + // any life-cycles like componentDidMount gets called. + nextEffect.effectTag &= ~Placement; + + // Update + var _current = nextEffect.alternate; + commitWork(_current, nextEffect); + break; + } + case Update: { + var _current2 = nextEffect.alternate; + commitWork(_current2, nextEffect); + break; + } + case Deletion: { + commitDeletion(nextEffect); + break; } } + nextEffect = nextEffect.nextEffect; + } - // We're done flushing work. Either we ran out of time in this callback, - // or there's no more work left with sufficient priority. - - // If we're inside a callback, set this to false since we just completed it. - if (deadline !== null) { - callbackExpirationTime = NoWork; - callbackID = -1; - } - // If there's work left over, schedule a new callback. - if (nextFlushedExpirationTime !== NoWork) { - scheduleCallbackWithExpiration(nextFlushedExpirationTime); - } + { + ReactDebugCurrentFiber.resetCurrentFiber(); + } +} - // Clean-up. - deadline = null; - deadlineDidExpire = false; +function commitBeforeMutationLifecycles() { + while (nextEffect !== null) { + var effectTag = nextEffect.effectTag; - finishRendering(); - } + if (effectTag & Snapshot) { + recordEffect(); + var current = nextEffect.alternate; + commitBeforeMutationLifeCycles(current, nextEffect); + } - function flushRoot(root, expirationTime) { - invariant( - !isRendering, - "work.commit(): Cannot commit while already rendering. This likely " + - "means you attempted to commit from inside a lifecycle method." - ); - // 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(); + // Don't cleanup effects yet; + // This will be done by commitAllLifeCycles() + nextEffect = nextEffect.nextEffect; } +} - function finishRendering() { - nestedUpdateCount = 0; +function commitAllLifeCycles( + finishedRoot, + currentTime, + committedExpirationTime +) { + { + ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings(); - if (completedBatches !== null) { - var batches = completedBatches; - completedBatches = null; - for (var i = 0; i < batches.length; i++) { - var batch = batches[i]; - try { - batch._onComplete(); - } catch (error) { - if (!hasUnhandledError) { - hasUnhandledError = true; - unhandledError = error; - } - } - } + if (warnAboutDeprecatedLifecycles) { + ReactStrictModeWarnings.flushPendingDeprecationWarnings(); } - if (hasUnhandledError) { - var error = unhandledError; - unhandledError = null; - hasUnhandledError = false; - throw error; + if (warnAboutLegacyContextAPI) { + ReactStrictModeWarnings.flushLegacyContextWarning(); } } + while (nextEffect !== null) { + var effectTag = nextEffect.effectTag; - function performWorkOnRoot(root, expirationTime, isAsync) { - invariant( - !isRendering, - "performWorkOnRoot was called recursively. This error is likely caused " + - "by a bug in React. Please file an issue." - ); - - isRendering = true; + if (effectTag & (Update | Callback)) { + recordEffect(); + var current = nextEffect.alternate; + commitLifeCycles( + finishedRoot, + current, + nextEffect, + currentTime, + committedExpirationTime + ); + } - // Check if this is async work or sync/expired work. - if (!isAsync) { - // Flush sync work. - var finishedWork = root.finishedWork; - if (finishedWork !== null) { - // This root is already complete. We can commit it. - completeRoot(root, finishedWork, expirationTime); - } else { - root.finishedWork = null; - finishedWork = renderRoot(root, expirationTime, false); - if (finishedWork !== null) { - // We've completed the root. Commit it. - completeRoot(root, finishedWork, expirationTime); - } - } - } else { - // Flush async work. - var _finishedWork = root.finishedWork; - if (_finishedWork !== null) { - // This root is already complete. We can commit it. - completeRoot(root, _finishedWork, expirationTime); - } else { - root.finishedWork = null; - _finishedWork = renderRoot(root, expirationTime, true); - if (_finishedWork !== null) { - // We've completed the root. Check the deadline one more time - // before committing. - if (!shouldYield()) { - // Still time left. Commit the root. - completeRoot(root, _finishedWork, expirationTime); - } else { - // There's no time left. Mark this root as complete. We'll come - // back and commit it later. - root.finishedWork = _finishedWork; - - if (enableProfilerTimer) { - // If we didn't finish, pause the "actual" render timer. - // We'll restart it when we resume work. - pauseActualRenderTimerIfRunning(); - } - } - } - } + if (effectTag & Ref) { + recordEffect(); + commitAttachRef(nextEffect); } - isRendering = false; + var next = nextEffect.nextEffect; + // Ensure that we clean these up so that we don't accidentally keep them. + // I'm not actually sure this matters because we can't reset firstEffect + // and lastEffect since they're on every node, not just the effectful + // ones. So we have to clean everything as we reuse nodes anyway. + nextEffect.nextEffect = null; + // Ensure that we reset the effectTag here so that we can rely on effect + // tags to reason about the current life-cycle. + nextEffect = next; } +} - function completeRoot(root, finishedWork, expirationTime) { - // Check if there's a batch that matches this expiration time. - var firstBatch = root.firstBatch; - if (firstBatch !== null && firstBatch._expirationTime <= expirationTime) { - if (completedBatches === null) { - completedBatches = [firstBatch]; - } else { - completedBatches.push(firstBatch); - } - if (firstBatch._defer) { - // This root is blocked from committing by a batch. Unschedule it until - // we receive another update. - root.finishedWork = finishedWork; - root.remainingExpirationTime = NoWork; - return; - } - } +function isAlreadyFailedLegacyErrorBoundary(instance) { + return ( + legacyErrorBoundariesThatAlreadyFailed !== null && + legacyErrorBoundariesThatAlreadyFailed.has(instance) + ); +} - // Commit the root. - root.finishedWork = null; - root.remainingExpirationTime = commitRoot(finishedWork); +function markLegacyErrorBoundaryAsFailed(instance) { + if (legacyErrorBoundariesThatAlreadyFailed === null) { + legacyErrorBoundariesThatAlreadyFailed = new Set([instance]); + } else { + legacyErrorBoundariesThatAlreadyFailed.add(instance); } +} - // When working on async work, the reconciler asks the renderer if it should - // yield execution. For DOM, we implement this with requestIdleCallback. - function shouldYield() { - if (deadline === null) { - return false; - } - if (deadline.timeRemaining() > timeHeuristicForUnitOfWork) { - // Disregard deadline.didTimeout. Only expired work should be flushed - // during a timeout. This path is only hit for non-expired work. - return false; - } - deadlineDidExpire = true; - return true; - } +function commitRoot(root, finishedWork) { + isWorking = true; + isCommitting$1 = true; + startCommitTimer(); - function onUncaughtError(error) { - invariant( - nextFlushedRoot !== null, - "Should be working on a root. This error is likely caused by a bug in " + - "React. Please file an issue." - ); - // Unschedule this root so we don't work on it again until there's - // another update. - nextFlushedRoot.remainingExpirationTime = NoWork; - if (!hasUnhandledError) { - hasUnhandledError = true; - unhandledError = error; + invariant( + root.current !== finishedWork, + "Cannot commit the same tree as before. This is probably a bug " + + "related to the return field. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + var committedExpirationTime = root.pendingCommitExpirationTime; + invariant( + committedExpirationTime !== NoWork, + "Cannot commit an incomplete root. This error is likely caused by a " + + "bug in React. Please file an issue." + ); + root.pendingCommitExpirationTime = NoWork; + + // Update the pending priority levels to account for the work that we are + // about to commit. This needs to happen before calling the lifecycles, since + // they may schedule additional updates. + var earliestRemainingTime = finishedWork.expirationTime; + var currentTime = recalculateCurrentTime(); + markCommittedPriorityLevels(root, currentTime, earliestRemainingTime); + + // Reset this to null before calling lifecycles + ReactCurrentOwner.current = null; + + var firstEffect = void 0; + if (finishedWork.effectTag > PerformedWork) { + // A fiber's effect list consists only of its children, not itself. So if + // the root has an effect, we need to add it to the end of the list. The + // resulting list is the set that would belong to the root's parent, if + // it had one; that is, all the effects in the tree including the root. + if (finishedWork.lastEffect !== null) { + finishedWork.lastEffect.nextEffect = finishedWork; + firstEffect = finishedWork.firstEffect; + } else { + firstEffect = finishedWork; } + } else { + // There is no effect on the root. + firstEffect = finishedWork.firstEffect; } - function onBlock(remainingExpirationTime) { - invariant( - nextFlushedRoot !== null, - "Should be working on a root. This error is likely caused by a bug in " + - "React. Please file an issue." - ); - // This root was blocked. Unschedule it until there's another update. - nextFlushedRoot.remainingExpirationTime = remainingExpirationTime; - } + prepareForCommit(root.containerInfo); - // TODO: Batching should be implemented at the renderer level, not inside - // the reconciler. - function batchedUpdates(fn, a) { - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = true; - try { - return fn(a); - } finally { - isBatchingUpdates = previousIsBatchingUpdates; - if (!isBatchingUpdates && !isRendering) { - performSyncWork(); + // Invoke instances of getSnapshotBeforeUpdate before mutation. + nextEffect = firstEffect; + startCommitSnapshotEffectsTimer(); + while (nextEffect !== null) { + var didError = false; + var error = void 0; + { + invokeGuardedCallback$2(null, commitBeforeMutationLifecycles, null); + if (hasCaughtError()) { + didError = true; + error = clearCaughtError(); } } - } - - // TODO: Batching should be implemented at the renderer level, not inside - // the reconciler. - function unbatchedUpdates(fn, a) { - if (isBatchingUpdates && !isUnbatchingUpdates) { - isUnbatchingUpdates = true; - try { - return fn(a); - } finally { - isUnbatchingUpdates = false; + if (didError) { + invariant( + nextEffect !== null, + "Should have next effect. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + captureCommitPhaseError(nextEffect, error); + // Clean-up + if (nextEffect !== null) { + nextEffect = nextEffect.nextEffect; } } - return fn(a); } + stopCommitSnapshotEffectsTimer(); - // TODO: Batching should be implemented at the renderer level, not within - // the reconciler. - function flushSync(fn, a) { - invariant( - !isRendering, - "flushSync was called from inside a lifecycle method. It cannot be " + - "called when React is already rendering." - ); - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = true; - try { - return syncUpdates(fn, a); - } finally { - isBatchingUpdates = previousIsBatchingUpdates; - performSyncWork(); + if (enableProfilerTimer) { + // Mark the current commit time to be shared by all Profilers in this batch. + // This enables them to be grouped later. + recordCommitTime(); + } + + // 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." + ); + captureCommitPhaseError(nextEffect, _error); + // Clean-up + if (nextEffect !== null) { + nextEffect = nextEffect.nextEffect; + } } } + stopCommitHostEffectsTimer(); + + resetAfterCommit(root.containerInfo); - function interactiveUpdates(fn, a, b) { - if (isBatchingInteractiveUpdates) { - return fn(a, b); + // The work-in-progress tree is now the current tree. This must come after + // the first pass of the commit phase, so that the previous tree is still + // current during componentWillUnmount, but before the second pass, so that + // the finished work is current during componentDidMount/Update. + root.current = finishedWork; + + // In the second pass we'll perform all life-cycles and ref callbacks. + // Life-cycles happen as a separate pass so that all placements, updates, + // and deletions in the entire tree have already been invoked. + // This pass also triggers any renderer-specific initial effects. + nextEffect = firstEffect; + startCommitLifeCyclesTimer(); + while (nextEffect !== null) { + var _didError2 = false; + var _error2 = void 0; + { + invokeGuardedCallback$2( + null, + commitAllLifeCycles, + null, + root, + currentTime, + committedExpirationTime + ); + if (hasCaughtError()) { + _didError2 = true; + _error2 = clearCaughtError(); + } } - // If there are any pending interactive updates, synchronously flush them. - // This needs to happen before we read any handlers, because the effect of - // the previous event may influence which handlers are called during - // this event. - if ( - !isBatchingUpdates && - !isRendering && - lowestPendingInteractiveExpirationTime !== NoWork - ) { - // Synchronously flush pending interactive updates. - performWork(lowestPendingInteractiveExpirationTime, false, null); - lowestPendingInteractiveExpirationTime = NoWork; - } - var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates; - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingInteractiveUpdates = true; - isBatchingUpdates = true; - try { - return fn(a, b); - } finally { - isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates; - isBatchingUpdates = previousIsBatchingUpdates; - if (!isBatchingUpdates && !isRendering) { - performSyncWork(); + if (_didError2) { + invariant( + nextEffect !== null, + "Should have next effect. This error is likely caused by a bug " + + "in React. Please file an issue." + ); + captureCommitPhaseError(nextEffect, _error2); + if (nextEffect !== null) { + nextEffect = nextEffect.nextEffect; } } } - function flushInteractiveUpdates() { - if (!isRendering && lowestPendingInteractiveExpirationTime !== NoWork) { - // Synchronously flush pending interactive updates. - performWork(lowestPendingInteractiveExpirationTime, false, null); - lowestPendingInteractiveExpirationTime = NoWork; + if (enableProfilerTimer) { + { + checkActualRenderTimeStackEmpty(); } + resetActualRenderTimer(); } - function flushControlled(fn) { - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = true; - try { - syncUpdates(fn); - } finally { - isBatchingUpdates = previousIsBatchingUpdates; - if (!isBatchingUpdates && !isRendering) { - performWork(Sync, false, null); - } - } + isCommitting$1 = false; + isWorking = false; + stopCommitLifeCyclesTimer(); + stopCommitTimer(); + if (typeof onCommitRoot === "function") { + onCommitRoot(finishedWork.stateNode); + } + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCommitWork(finishedWork); } - return { - recalculateCurrentTime: recalculateCurrentTime, - computeExpirationForFiber: computeExpirationForFiber, - scheduleWork: scheduleWork, - requestWork: requestWork, - flushRoot: flushRoot, - batchedUpdates: batchedUpdates, - unbatchedUpdates: unbatchedUpdates, - flushSync: flushSync, - flushControlled: flushControlled, - deferredUpdates: deferredUpdates, - syncUpdates: syncUpdates, - interactiveUpdates: interactiveUpdates, - flushInteractiveUpdates: flushInteractiveUpdates, - computeUniqueAsyncExpiration: computeUniqueAsyncExpiration, - legacyContext: legacyContext - }; -}; - -var didWarnAboutNestedUpdates = void 0; - -{ - didWarnAboutNestedUpdates = false; + var expirationTime = root.expirationTime; + if (expirationTime === NoWork) { + // If there's no remaining work, we can clear the set of already failed + // error boundaries. + legacyErrorBoundariesThatAlreadyFailed = null; + } + onCommit(root, expirationTime); } -// 0 is PROD, 1 is DEV. -// Might add PROFILE later. +function resetExpirationTime(workInProgress, renderTime) { + if (renderTime !== Never && workInProgress.expirationTime === Never) { + // The children of this component are hidden. Don't bubble their + // expiration times. + return; + } -var ReactFiberReconciler$1 = function(config) { - var getPublicInstance = config.getPublicInstance; - - var _ReactFiberScheduler = ReactFiberScheduler(config), - computeUniqueAsyncExpiration = - _ReactFiberScheduler.computeUniqueAsyncExpiration, - recalculateCurrentTime = _ReactFiberScheduler.recalculateCurrentTime, - computeExpirationForFiber = _ReactFiberScheduler.computeExpirationForFiber, - scheduleWork = _ReactFiberScheduler.scheduleWork, - requestWork = _ReactFiberScheduler.requestWork, - flushRoot = _ReactFiberScheduler.flushRoot, - batchedUpdates = _ReactFiberScheduler.batchedUpdates, - unbatchedUpdates = _ReactFiberScheduler.unbatchedUpdates, - flushSync = _ReactFiberScheduler.flushSync, - flushControlled = _ReactFiberScheduler.flushControlled, - 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$1(parentComponent); - var parentContext = findCurrentUnmaskedContext(fiber); - return isContextProvider(fiber) - ? processChildContext(fiber, parentContext) - : parentContext; - } - - function scheduleRootUpdate(current, element, expirationTime, callback) { - { - if ( - ReactDebugCurrentFiber.phase === "render" && - ReactDebugCurrentFiber.current !== null && - !didWarnAboutNestedUpdates - ) { - didWarnAboutNestedUpdates = true; - warning( - false, - "Render methods should be a pure function of props and state; " + - "triggering nested component updates from render is not allowed. " + - "If necessary, trigger nested updates in componentDidUpdate.\n\n" + - "Check the render method of %s.", - getComponentName(ReactDebugCurrentFiber.current) || "Unknown" - ); + // Check for pending updates. + var newExpirationTime = NoWork; + switch (workInProgress.tag) { + case HostRoot: + case ClassComponent: { + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + newExpirationTime = updateQueue.expirationTime; } } - - var update = createUpdate(expirationTime); - // Caution: React DevTools currently depends on this property - // being called "element". - update.payload = { element: element }; - - callback = callback === undefined ? null : callback; - if (callback !== null) { - !(typeof callback === "function") - ? warning( - false, - "render(...): Expected the last optional `callback` argument to be a " + - "function. Instead received: %s.", - callback - ) - : void 0; - update.callback = callback; - } - enqueueUpdate(current, update, expirationTime); - - scheduleWork(current, expirationTime); - return expirationTime; } - function updateContainerAtExpirationTime( - element, - container, - parentComponent, - expirationTime, - callback - ) { - // TODO: If this is a nested container, this won't be the root. - var current = container.current; + // TODO: Calls need to visit stateNode - { - if (ReactFiberInstrumentation_1.debugTool) { - if (current.alternate === null) { - ReactFiberInstrumentation_1.debugTool.onMountContainer(container); - } else if (element === null) { - ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container); - } else { - ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container); - } + // Bubble up the earliest expiration time. + // (And "base" render timers if that feature flag is enabled) + if (enableProfilerTimer && workInProgress.mode & ProfileMode) { + var treeBaseTime = workInProgress.selfBaseTime; + var child = workInProgress.child; + while (child !== null) { + treeBaseTime += child.treeBaseTime; + if ( + child.expirationTime !== NoWork && + (newExpirationTime === NoWork || + newExpirationTime > child.expirationTime) + ) { + newExpirationTime = child.expirationTime; } + child = child.sibling; } - - var context = getContextForSubtree(parentComponent); - if (container.context === null) { - container.context = context; - } else { - container.pendingContext = context; - } - - return scheduleRootUpdate(current, element, expirationTime, callback); - } - - function findHostInstance(component) { - var fiber = get$1(component); - if (fiber === undefined) { - if (typeof component.render === "function") { - invariant(false, "Unable to find node on an unmounted component."); - } else { - invariant( - false, - "Argument appears to not be a ReactComponent. Keys: %s", - Object.keys(component) - ); + workInProgress.treeBaseTime = treeBaseTime; + } else { + var _child = workInProgress.child; + while (_child !== null) { + if ( + _child.expirationTime !== NoWork && + (newExpirationTime === NoWork || + newExpirationTime > _child.expirationTime) + ) { + newExpirationTime = _child.expirationTime; } + _child = _child.sibling; } - var hostFiber = findCurrentHostFiber(fiber); - if (hostFiber === null) { - return null; - } - return hostFiber.stateNode; } - return { - createContainer: function(containerInfo, isAsync, hydrate) { - return createFiberRoot(containerInfo, isAsync, hydrate); - }, - updateContainer: function(element, container, parentComponent, callback) { - var current = container.current; - var currentTime = recalculateCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, current); - return updateContainerAtExpirationTime( - element, - container, - parentComponent, - expirationTime, - callback - ); - }, - updateContainerAtExpirationTime: function( - element, - container, - parentComponent, - expirationTime, - callback - ) { - return updateContainerAtExpirationTime( - element, - container, - parentComponent, - expirationTime, - callback - ); - }, - - flushRoot: flushRoot, - - requestWork: requestWork, + workInProgress.expirationTime = newExpirationTime; +} - computeUniqueAsyncExpiration: computeUniqueAsyncExpiration, +function completeUnitOfWork(workInProgress) { + // Attempt to complete the current unit of work, then move to the + // next sibling. If there are no more siblings, return to the + // parent fiber. + while (true) { + // The current, flushed, state of this fiber is the alternate. + // Ideally nothing should rely on this, but relying on it here + // means that we don't need an additional field on the work in + // progress. + var current = workInProgress.alternate; + { + ReactDebugCurrentFiber.setCurrentFiber(workInProgress); + } - batchedUpdates: batchedUpdates, + var returnFiber = workInProgress.return; + var siblingFiber = workInProgress.sibling; - unbatchedUpdates: unbatchedUpdates, + if ((workInProgress.effectTag & Incomplete) === NoEffect) { + // This fiber completed. + var next = completeWork( + current, + workInProgress, + nextRenderExpirationTime + ); + stopWorkTimer(workInProgress); + resetExpirationTime(workInProgress, nextRenderExpirationTime); + { + ReactDebugCurrentFiber.resetCurrentFiber(); + } - deferredUpdates: deferredUpdates, + if (next !== null) { + stopWorkTimer(workInProgress); + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); + } + // If completing this work spawned new work, do that next. We'll come + // back here again. + return next; + } - syncUpdates: syncUpdates, + if ( + returnFiber !== null && + // Do not append effects to parents if a sibling failed to complete + (returnFiber.effectTag & Incomplete) === NoEffect + ) { + // Append all the effects of the subtree and this fiber onto the effect + // list of the parent. The completion order of the children affects the + // side-effect order. + if (returnFiber.firstEffect === null) { + returnFiber.firstEffect = workInProgress.firstEffect; + } + if (workInProgress.lastEffect !== null) { + if (returnFiber.lastEffect !== null) { + returnFiber.lastEffect.nextEffect = workInProgress.firstEffect; + } + returnFiber.lastEffect = workInProgress.lastEffect; + } - interactiveUpdates: interactiveUpdates, + // If this fiber had side-effects, we append it AFTER the children's + // side-effects. We can perform certain side-effects earlier if + // needed, by doing multiple passes over the effect list. We don't want + // to schedule our own side-effect on our own list because if end up + // reusing children we'll schedule this effect onto itself since we're + // at the end. + var effectTag = workInProgress.effectTag; + // Skip both NoWork and PerformedWork tags when creating the effect list. + // PerformedWork effect is read by React DevTools but shouldn't be committed. + if (effectTag > PerformedWork) { + if (returnFiber.lastEffect !== null) { + returnFiber.lastEffect.nextEffect = workInProgress; + } else { + returnFiber.firstEffect = workInProgress; + } + returnFiber.lastEffect = workInProgress; + } + } - flushInteractiveUpdates: flushInteractiveUpdates, + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); + } - flushControlled: flushControlled, + if (siblingFiber !== null) { + // If there is more work to do in this returnFiber, do that next. + return siblingFiber; + } else if (returnFiber !== null) { + // If there's no more work in this returnFiber. Complete the returnFiber. + workInProgress = returnFiber; + continue; + } else { + // We've reached the root. + return null; + } + } else { + // This fiber did not complete because something threw. Pop values off + // the stack without entering the complete phase. If this is a boundary, + // capture values if possible. + var _next = unwindWork(workInProgress, nextRenderExpirationTime); + // Because this fiber did not complete, don't reset its expiration time. + if (workInProgress.effectTag & DidCapture) { + // Restarting an error boundary + stopFailedWorkTimer(workInProgress); + } else { + stopWorkTimer(workInProgress); + } - flushSync: flushSync, + { + ReactDebugCurrentFiber.resetCurrentFiber(); + } - getPublicRootInstance: function(container) { - var containerFiber = container.current; - if (!containerFiber.child) { - return null; + if (_next !== null) { + stopWorkTimer(workInProgress); + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); + } + // If completing this work spawned new work, do that next. We'll come + // back here again. + // Since we're restarting, remove anything that is not a host effect + // from the effect tag. + _next.effectTag &= HostEffectMask; + return _next; } - switch (containerFiber.child.tag) { - case HostComponent: - return getPublicInstance(containerFiber.child.stateNode); - default: - return containerFiber.child.stateNode; + + if (returnFiber !== null) { + // Mark the parent fiber as incomplete and clear its effect list. + returnFiber.firstEffect = returnFiber.lastEffect = null; + returnFiber.effectTag |= Incomplete; } - }, - findHostInstance: findHostInstance, + if (true && ReactFiberInstrumentation_1.debugTool) { + ReactFiberInstrumentation_1.debugTool.onCompleteWork(workInProgress); + } - findHostInstanceWithNoPortals: function(fiber) { - var hostFiber = findCurrentHostFiberWithNoPortals(fiber); - if (hostFiber === null) { + if (siblingFiber !== null) { + // If there is more work to do in this returnFiber, do that next. + return siblingFiber; + } else if (returnFiber !== null) { + // If there's no more work in this returnFiber. Complete the returnFiber. + workInProgress = returnFiber; + continue; + } else { return null; } - return hostFiber.stateNode; - }, - injectIntoDevTools: function(devToolsConfig) { - var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; - - return injectInternals( - Object.assign({}, devToolsConfig, { - findHostInstanceByFiber: function(fiber) { - var hostFiber = findCurrentHostFiber(fiber); - if (hostFiber === null) { - return null; - } - return hostFiber.stateNode; - }, - findFiberByHostInstance: function(instance) { - if (!findFiberByHostInstance) { - // Might not be implemented by the renderer. - return null; - } - return findFiberByHostInstance(instance); - } - }) - ); } - }; -}; + } -var ReactFiberReconciler$2 = Object.freeze({ - default: ReactFiberReconciler$1 -}); + // Without this explicit null return Flow complains of invalid return type + // TODO Remove the above while(true) loop + // eslint-disable-next-line no-unreachable + return null; +} -var ReactFiberReconciler$3 = - (ReactFiberReconciler$2 && ReactFiberReconciler$1) || ReactFiberReconciler$2; +function performUnitOfWork(workInProgress) { + // The current, flushed, state of this fiber is the alternate. + // Ideally nothing should rely on this, but relying on it here + // means that we don't need an additional field on the work in + // progress. + var current = workInProgress.alternate; -// TODO: bundle Flow types with the package. + // See if beginning this work spawns more work. + startWorkTimer(workInProgress); + { + ReactDebugCurrentFiber.setCurrentFiber(workInProgress); + } -// TODO: decide on the top-level export form. -// This is hacky but makes it work with both Rollup and Jest. -var reactReconciler = ReactFiberReconciler$3.default - ? ReactFiberReconciler$3.default - : ReactFiberReconciler$3; + if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { + stashedWorkInProgressProperties = assignFiberPropertiesInDEV( + stashedWorkInProgressProperties, + workInProgress + ); + } -function createPortal( - children, - containerInfo, - // TODO: figure out the API for cross-renderer implementation. - implementation -) { - var key = - arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + var next = void 0; + if (enableProfilerTimer) { + if (workInProgress.mode & ProfileMode) { + startBaseRenderTimer(); + } - return { - // This tag allow us to uniquely identify this as a React Portal - $$typeof: REACT_PORTAL_TYPE, - key: key == null ? null : "" + key, - children: children, - containerInfo: containerInfo, - implementation: implementation - }; -} + next = beginWork(current, workInProgress, nextRenderExpirationTime); -// TODO: this is special because it gets imported during build. + if (workInProgress.mode & ProfileMode) { + // Update "base" time if the render wasn't bailed out on. + recordElapsedBaseRenderTimeIfRunning(workInProgress); + stopBaseRenderTimerIfRunning(); + } + } else { + next = beginWork(current, workInProgress, nextRenderExpirationTime); + } -var ReactVersion = "16.3.2"; + { + 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); + } -// Modules provided by RN: -var emptyObject$1 = {}; + if (next === null) { + // If this doesn't spawn new work, complete the current work. + next = completeUnitOfWork(workInProgress); + } -/** - * Create a payload that contains all the updates between two sets of props. - * - * These helpers are all encapsulated into a single module, because they use - * mutation as a performance optimization which leads to subtle shared - * dependencies between the code paths. To avoid this mutable state leaking - * across modules, I've kept them isolated to this module. - */ + ReactCurrentOwner.current = null; -// Tracks removed keys -var removedKeys = null; -var removedKeyCount = 0; + return next; +} -function defaultDiffer(prevProp, nextProp) { - if (typeof nextProp !== "object" || nextProp === null) { - // Scalars have already been checked for equality - return true; +function workLoop(isYieldy) { + if (!isYieldy) { + // Flush work without yielding + while (nextUnitOfWork !== null) { + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + } } else { - // For objects and arrays, the default diffing algorithm is a deep compare - return deepDiffer(prevProp, nextProp); + // Flush asynchronous work until the deadline runs out of time. + while (nextUnitOfWork !== null && !shouldYield()) { + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + } + + if (enableProfilerTimer) { + // If we didn't finish, pause the "actual" render timer. + // We'll restart it when we resume work. + pauseActualRenderTimerIfRunning(); + } } } -function restoreDeletedValuesInNestedArray( - updatePayload, - node, - validAttributes -) { - if (Array.isArray(node)) { - var i = node.length; - while (i-- && removedKeyCount > 0) { - restoreDeletedValuesInNestedArray( - updatePayload, - node[i], - validAttributes - ); - } - } else if (node && removedKeyCount > 0) { - var obj = node; - for (var propKey in removedKeys) { - if (!removedKeys[propKey]) { - continue; - } - var _nextProp = obj[propKey]; - if (_nextProp === undefined) { - continue; - } +function renderRoot(root, isYieldy) { + invariant( + !isWorking, + "renderRoot was called recursively. This error is likely caused " + + "by a bug in React. Please file an issue." + ); + isWorking = true; - var attributeConfig = validAttributes[propKey]; - if (!attributeConfig) { - continue; // not a valid native prop - } + var expirationTime = root.nextExpirationTimeToWorkOn; - if (typeof _nextProp === "function") { - _nextProp = true; - } - if (typeof _nextProp === "undefined") { - _nextProp = null; + // Check if we're starting from a fresh stack, or if we're resuming from + // previously yielded work. + if ( + expirationTime !== nextRenderExpirationTime || + root !== nextRoot || + nextUnitOfWork === null + ) { + // Reset the stack and start working from the root. + resetStack(); + nextRoot = root; + nextRenderExpirationTime = expirationTime; + nextLatestTimeoutMs = -1; + nextRenderDidError = false; + nextUnitOfWork = createWorkInProgress( + nextRoot.current, + null, + nextRenderExpirationTime + ); + root.pendingCommitExpirationTime = NoWork; + } + + var didFatal = false; + + startWorkLoopTimer(nextUnitOfWork); + + do { + try { + workLoop(isYieldy); + } catch (thrownValue) { + if (enableProfilerTimer) { + // Stop "base" render timer in the event of an error. + stopBaseRenderTimerIfRunning(); } - if (typeof attributeConfig !== "object") { - // case: !Object is the default case - updatePayload[propKey] = _nextProp; - } else if ( - typeof attributeConfig.diff === "function" || - typeof attributeConfig.process === "function" - ) { - // case: CustomAttributeConfiguration - var nextValue = - typeof attributeConfig.process === "function" - ? attributeConfig.process(_nextProp) - : _nextProp; - updatePayload[propKey] = nextValue; + if (nextUnitOfWork === null) { + // This is a fatal error. + didFatal = true; + onUncaughtError(thrownValue); + } else { + { + // Reset global debug state + // We assume this is defined in DEV + resetCurrentlyProcessingQueue(); + } + + var failedUnitOfWork = nextUnitOfWork; + if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) { + replayUnitOfWork(failedUnitOfWork, thrownValue, isYieldy); + } + + // TODO: we already know this isn't true in some cases. + // At least this shows a nicer error message until we figure out the cause. + // https://github.com/facebook/react/issues/12449#issuecomment-386727431 + invariant( + nextUnitOfWork !== null, + "Failed to replay rendering after an error. This " + + "is likely caused by a bug in React. Please file an issue " + + "with a reproducing case to help us find it." + ); + + 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. + didFatal = true; + onUncaughtError(thrownValue); + break; + } + throwException( + root, + returnFiber, + sourceFiber, + thrownValue, + nextRenderExpirationTime, + mostRecentCurrentTimeMs + ); + nextUnitOfWork = completeUnitOfWork(sourceFiber); } - removedKeys[propKey] = false; - removedKeyCount--; } - } -} - -function diffNestedArrayProperty( - updatePayload, - prevArray, - nextArray, - validAttributes -) { - var minLength = - prevArray.length < nextArray.length ? prevArray.length : nextArray.length; - var i = void 0; - for (i = 0; i < minLength; i++) { - // Diff any items in the array in the forward direction. Repeated keys - // will be overwritten by later values. - updatePayload = diffNestedProperty( - updatePayload, - prevArray[i], - nextArray[i], - validAttributes - ); - } - for (; i < prevArray.length; i++) { - // Clear out all remaining properties. - updatePayload = clearNestedProperty( - updatePayload, - prevArray[i], - validAttributes - ); - } - for (; i < nextArray.length; i++) { - // Add all remaining properties. - updatePayload = addNestedProperty( - updatePayload, - nextArray[i], - validAttributes - ); - } - return updatePayload; -} + break; + } while (true); -function diffNestedProperty( - updatePayload, - prevProp, - nextProp, - validAttributes -) { - if (!updatePayload && prevProp === nextProp) { - // If no properties have been added, then we can bail out quickly on object - // equality. - return updatePayload; - } + // We're done performing work. Time to clean up. + isWorking = false; - if (!prevProp || !nextProp) { - if (nextProp) { - return addNestedProperty(updatePayload, nextProp, validAttributes); + // Yield back to main thread. + if (didFatal) { + var didCompleteRoot = false; + stopWorkLoopTimer(interruptedBy, didCompleteRoot); + interruptedBy = null; + // There was a fatal error. + { + resetStackAfterFatalErrorInDev(); } - if (prevProp) { - return clearNestedProperty(updatePayload, prevProp, validAttributes); + onFatal(root); + } else if (nextUnitOfWork === null) { + // We reached the root. + var rootWorkInProgress = root.current.alternate; + invariant( + rootWorkInProgress !== null, + "Finished root should have a work-in-progress. This error is likely " + + "caused by a bug in React. Please file an issue." + ); + if ((rootWorkInProgress.effectTag & Incomplete) === NoEffect) { + var _didCompleteRoot = true; + stopWorkLoopTimer(interruptedBy, _didCompleteRoot); + interruptedBy = null; + // The root successfully completed. + onComplete(root, rootWorkInProgress, expirationTime); + } else { + // The root did not complete. + var _didCompleteRoot2 = false; + stopWorkLoopTimer(interruptedBy, _didCompleteRoot2); + interruptedBy = null; + markSuspendedPriorityLevel(root, expirationTime, nextRenderDidError); + var suspendedExpirationTime = expirationTime; + var newExpirationTime = root.expirationTime; + onSuspend( + root, + suspendedExpirationTime, + newExpirationTime, + nextLatestTimeoutMs + ); } - return updatePayload; + } else { + var _didCompleteRoot3 = false; + stopWorkLoopTimer(interruptedBy, _didCompleteRoot3); + interruptedBy = null; + onYield(root); } +} - if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) { - // Both are leaves, we can diff the leaves. - return diffProperties(updatePayload, prevProp, nextProp, validAttributes); - } +function dispatch(sourceFiber, value, expirationTime) { + invariant( + !isWorking || isCommitting$1, + "dispatch: Cannot dispatch during the render phase." + ); - if (Array.isArray(prevProp) && Array.isArray(nextProp)) { - // Both are arrays, we can diff the arrays. - return diffNestedArrayProperty( - updatePayload, - prevProp, - nextProp, - validAttributes - ); + var fiber = sourceFiber.return; + while (fiber !== null) { + switch (fiber.tag) { + case ClassComponent: + var ctor = fiber.type; + var instance = fiber.stateNode; + if ( + typeof ctor.getDerivedStateFromCatch === "function" || + (typeof instance.componentDidCatch === "function" && + !isAlreadyFailedLegacyErrorBoundary(instance)) + ) { + var errorInfo = createCapturedValue(value, sourceFiber); + var update = createClassErrorUpdate(fiber, errorInfo, expirationTime); + enqueueUpdate(fiber, update, expirationTime); + scheduleWork(fiber, expirationTime); + return; + } + break; + case HostRoot: { + var _errorInfo = createCapturedValue(value, sourceFiber); + var _update = createRootErrorUpdate(fiber, _errorInfo, expirationTime); + enqueueUpdate(fiber, _update, expirationTime); + scheduleWork(fiber, expirationTime); + return; + } + } + fiber = fiber.return; } - if (Array.isArray(prevProp)) { - return diffProperties( - updatePayload, - // $FlowFixMe - We know that this is always an object when the input is. - flattenStyle(prevProp), - // $FlowFixMe - We know that this isn't an array because of above flow. - nextProp, - validAttributes + if (sourceFiber.tag === HostRoot) { + // Error was thrown at the root. There is no parent, so the root + // itself should capture it. + var rootFiber = sourceFiber; + var _errorInfo2 = createCapturedValue(value, rootFiber); + var _update2 = createRootErrorUpdate( + rootFiber, + _errorInfo2, + expirationTime ); + enqueueUpdate(rootFiber, _update2, expirationTime); + scheduleWork(rootFiber, expirationTime); } +} - return diffProperties( - updatePayload, - prevProp, - // $FlowFixMe - We know that this is always an object when the input is. - flattenStyle(nextProp), - validAttributes - ); +function captureCommitPhaseError(fiber, error) { + return dispatch(fiber, error, Sync); } -/** - * addNestedProperty takes a single set of props and valid attribute - * attribute configurations. It processes each prop and adds it to the - * updatePayload. - */ -function addNestedProperty(updatePayload, nextProp, validAttributes) { - if (!nextProp) { - return updatePayload; - } +function computeAsyncExpiration(currentTime) { + // Given the current clock time, returns an expiration time. We use rounding + // to batch like updates together. + // Should complete within ~5000ms. 5250ms max. + var expirationMs = 5000; + var bucketSizeMs = 250; + return computeExpirationBucket(currentTime, expirationMs, bucketSizeMs); +} - if (!Array.isArray(nextProp)) { - // Add each property of the leaf. - return addProperties(updatePayload, nextProp, validAttributes); +function computeInteractiveExpiration(currentTime) { + var expirationMs = void 0; + // We intentionally set a higher expiration time for interactive updates in + // dev than in production. + // If the main thread is being blocked so long that you hit the expiration, + // it's a problem that could be solved with better scheduling. + // People will be more likely to notice this and fix it with the long + // expiration time in development. + // In production we opt for better UX at the risk of masking scheduling + // problems, by expiring fast. + { + // Should complete within ~500ms. 600ms max. + expirationMs = 500; + } + var bucketSizeMs = 100; + return computeExpirationBucket(currentTime, expirationMs, bucketSizeMs); +} + +// Creates a unique async expiration time. +function computeUniqueAsyncExpiration() { + var currentTime = recalculateCurrentTime(); + var result = computeAsyncExpiration(currentTime); + if (result <= lastUniqueAsyncExpiration) { + // Since we assume the current time monotonically increases, we only hit + // this branch when computeUniqueAsyncExpiration is fired multiple times + // within a 200ms window (or whatever the async bucket size is). + result = lastUniqueAsyncExpiration + 1; + } + lastUniqueAsyncExpiration = result; + return lastUniqueAsyncExpiration; +} + +function computeExpirationForFiber(currentTime, fiber) { + var expirationTime = void 0; + if (expirationContext !== NoWork) { + // An explicit expiration context was set; + expirationTime = expirationContext; + } else if (isWorking) { + if (isCommitting$1) { + // Updates that occur during the commit phase should have sync priority + // by default. + expirationTime = Sync; + } else { + // Updates during the render phase should expire at the same time as + // the work that is being rendered. + expirationTime = nextRenderExpirationTime; + } + } else { + // No explicit expiration context was set, and we're not currently + // performing work. Calculate a new expiration time. + if (fiber.mode & AsyncMode) { + if (isBatchingInteractiveUpdates) { + // This is an interactive update + expirationTime = computeInteractiveExpiration(currentTime); + } else { + // This is an async update + expirationTime = computeAsyncExpiration(currentTime); + } + } else { + // This is a sync update + expirationTime = Sync; + } } - - for (var i = 0; i < nextProp.length; i++) { - // Add all the properties of the array. - updatePayload = addNestedProperty( - updatePayload, - nextProp[i], - validAttributes - ); + if (isBatchingInteractiveUpdates) { + // This is an interactive update. Keep track of the lowest pending + // interactive expiration time. This allows us to synchronously flush + // all interactive updates when needed. + if ( + lowestPendingInteractiveExpirationTime === NoWork || + expirationTime > lowestPendingInteractiveExpirationTime + ) { + lowestPendingInteractiveExpirationTime = expirationTime; + } } - - return updatePayload; + return expirationTime; } -/** - * clearNestedProperty takes a single set of props and valid attributes. It - * adds a null sentinel to the updatePayload, for each prop key. - */ -function clearNestedProperty(updatePayload, prevProp, validAttributes) { - if (!prevProp) { - return updatePayload; +function markTimeout(root, thenable, timeoutMs, suspendedTime) { + // Schedule the timeout. + if (timeoutMs >= 0 && nextLatestTimeoutMs < timeoutMs) { + nextLatestTimeoutMs = timeoutMs; } +} - if (!Array.isArray(prevProp)) { - // Add each property of the leaf. - return clearProperties(updatePayload, prevProp, validAttributes); - } +function markError(root) { + nextRenderDidError = true; +} - for (var i = 0; i < prevProp.length; i++) { - // Add all the properties of the array. - updatePayload = clearNestedProperty( - updatePayload, - prevProp[i], - validAttributes - ); +function retrySuspendedRoot(root, suspendedTime) { + markPingedPriorityLevel(root, suspendedTime); + var retryTime = root.expirationTime; + if (retryTime !== NoWork) { + requestWork(root, retryTime); } - return updatePayload; } -/** - * diffProperties takes two sets of props and a set of valid attributes - * and write to updatePayload the values that changed or were deleted. - * If no updatePayload is provided, a new one is created and returned if - * anything changed. - */ -function diffProperties(updatePayload, prevProps, nextProps, validAttributes) { - var attributeConfig = void 0; - var nextProp = void 0; - var prevProp = void 0; +function scheduleWork(fiber, expirationTime) { + recordScheduleUpdate(); - for (var propKey in nextProps) { - attributeConfig = validAttributes[propKey]; - if (!attributeConfig) { - continue; // not a valid native prop + { + if (fiber.tag === ClassComponent) { + var instance = fiber.stateNode; + warnAboutInvalidUpdates(instance); } + } - prevProp = prevProps[propKey]; - nextProp = nextProps[propKey]; - - // functions are converted to booleans as markers that the associated - // events should be sent from native. - if (typeof nextProp === "function") { - nextProp = true; - // If nextProp is not a function, then don't bother changing prevProp - // since nextProp will win and go into the updatePayload regardless. - if (typeof prevProp === "function") { - prevProp = true; + var node = fiber; + while (node !== null) { + // Walk the parent path to the root and update each node's + // expiration time. + if ( + node.expirationTime === NoWork || + node.expirationTime > expirationTime + ) { + node.expirationTime = expirationTime; + } + if (node.alternate !== null) { + if ( + node.alternate.expirationTime === NoWork || + node.alternate.expirationTime > expirationTime + ) { + node.alternate.expirationTime = expirationTime; } } - - // An explicit value of undefined is treated as a null because it overrides - // any other preceding value. - if (typeof nextProp === "undefined") { - nextProp = null; - if (typeof prevProp === "undefined") { - prevProp = null; + if (node.return === null) { + if (node.tag === HostRoot) { + var root = node.stateNode; + if ( + !isWorking && + nextRenderExpirationTime !== NoWork && + expirationTime < nextRenderExpirationTime + ) { + // This is an interruption. (Used for performance tracking.) + interruptedBy = fiber; + resetStack(); + } + markPendingPriorityLevel(root, expirationTime); + 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$1 || + // ...unless this is a different root than the one we're rendering. + nextRoot !== root + ) { + var rootExpirationTime = root.expirationTime; + requestWork(root, rootExpirationTime); + } + if (nestedUpdateCount > NESTED_UPDATE_LIMIT) { + invariant( + false, + "Maximum update depth exceeded. This can happen when a " + + "component repeatedly calls setState inside " + + "componentWillUpdate or componentDidUpdate. React limits " + + "the number of nested updates to prevent infinite loops." + ); + } + } else { + { + if (fiber.tag === ClassComponent) { + warnAboutUpdateOnUnmounted(fiber); + } + } + return; } } + node = node.return; + } +} - if (removedKeys) { - removedKeys[propKey] = false; - } +function recalculateCurrentTime() { + // Subtract initial time so it fits inside 32bits + mostRecentCurrentTimeMs = now() - originalStartTimeMs; + mostRecentCurrentTime = msToExpirationTime(mostRecentCurrentTimeMs); + return mostRecentCurrentTime; +} - if (updatePayload && updatePayload[propKey] !== undefined) { - // Something else already triggered an update to this key because another - // value diffed. Since we're now later in the nested arrays our value is - // more important so we need to calculate it and override the existing - // value. It doesn't matter if nothing changed, we'll set it anyway. +function deferredUpdates(fn) { + var previousExpirationContext = expirationContext; + var currentTime = recalculateCurrentTime(); + expirationContext = computeAsyncExpiration(currentTime); + try { + return fn(); + } finally { + expirationContext = previousExpirationContext; + } +} +function syncUpdates(fn, a, b, c, d) { + var previousExpirationContext = expirationContext; + expirationContext = Sync; + try { + return fn(a, b, c, d); + } finally { + expirationContext = previousExpirationContext; + } +} - // Pattern match on: attributeConfig - if (typeof attributeConfig !== "object") { - // case: !Object is the default case - updatePayload[propKey] = nextProp; - } else if ( - typeof attributeConfig.diff === "function" || - typeof attributeConfig.process === "function" - ) { - // case: CustomAttributeConfiguration - var nextValue = - typeof attributeConfig.process === "function" - ? attributeConfig.process(nextProp) - : nextProp; - updatePayload[propKey] = nextValue; - } - continue; - } +// TODO: Everything below this is written as if it has been lifted to the +// renderers. I'll do this in a follow-up. - if (prevProp === nextProp) { - continue; // nothing changed - } +// Linked-list of roots +var firstScheduledRoot = null; +var lastScheduledRoot = null; - // Pattern match on: attributeConfig - if (typeof attributeConfig !== "object") { - // case: !Object is the default case - if (defaultDiffer(prevProp, nextProp)) { - // a normal leaf has changed - (updatePayload || (updatePayload = {}))[propKey] = nextProp; - } - } else if ( - typeof attributeConfig.diff === "function" || - typeof attributeConfig.process === "function" - ) { - // case: CustomAttributeConfiguration - var shouldUpdate = - prevProp === undefined || - (typeof attributeConfig.diff === "function" - ? attributeConfig.diff(prevProp, nextProp) - : defaultDiffer(prevProp, nextProp)); - if (shouldUpdate) { - var _nextValue = - typeof attributeConfig.process === "function" - ? attributeConfig.process(nextProp) - : nextProp; - (updatePayload || (updatePayload = {}))[propKey] = _nextValue; - } - } else { - // default: fallthrough case when nested properties are defined - removedKeys = null; - removedKeyCount = 0; - // We think that attributeConfig is not CustomAttributeConfiguration at - // this point so we assume it must be AttributeConfiguration. - updatePayload = diffNestedProperty( - updatePayload, - prevProp, - nextProp, - attributeConfig - ); - if (removedKeyCount > 0 && updatePayload) { - restoreDeletedValuesInNestedArray( - updatePayload, - nextProp, - attributeConfig - ); - removedKeys = null; - } - } - } +var callbackExpirationTime = NoWork; +var callbackID = void 0; +var isRendering = false; +var nextFlushedRoot = null; +var nextFlushedExpirationTime = NoWork; +var lowestPendingInteractiveExpirationTime = NoWork; +var deadlineDidExpire = false; +var hasUnhandledError = false; +var unhandledError = null; +var deadline = null; - // Also iterate through all the previous props to catch any that have been - // removed and make sure native gets the signal so it can reset them to the - // default. - for (var _propKey in prevProps) { - if (nextProps[_propKey] !== undefined) { - continue; // we've already covered this key in the previous pass - } - attributeConfig = validAttributes[_propKey]; - if (!attributeConfig) { - continue; // not a valid native prop - } +var isBatchingUpdates = false; +var isUnbatchingUpdates = false; +var isBatchingInteractiveUpdates = false; - if (updatePayload && updatePayload[_propKey] !== undefined) { - // This was already updated to a diff result earlier. - continue; - } +var completedBatches = null; - prevProp = prevProps[_propKey]; - if (prevProp === undefined) { - continue; // was already empty anyway - } - // Pattern match on: attributeConfig - if ( - typeof attributeConfig !== "object" || - typeof attributeConfig.diff === "function" || - typeof attributeConfig.process === "function" - ) { - // case: CustomAttributeConfiguration | !Object - // Flag the leaf property for removal by sending a sentinel. - (updatePayload || (updatePayload = {}))[_propKey] = null; - if (!removedKeys) { - removedKeys = {}; - } - if (!removedKeys[_propKey]) { - removedKeys[_propKey] = true; - removedKeyCount++; +// Use these to prevent an infinite loop of nested updates +var NESTED_UPDATE_LIMIT = 1000; +var nestedUpdateCount = 0; + +var timeHeuristicForUnitOfWork = 1; + +function scheduleCallbackWithExpirationTime(expirationTime) { + if (callbackExpirationTime !== NoWork) { + // A callback is already scheduled. Check its expiration time (timeout). + if (expirationTime > callbackExpirationTime) { + // Existing callback has sufficient timeout. Exit. + return; + } else { + if (callbackID !== null) { + // Existing callback has insufficient timeout. Cancel and schedule a + // new one. + cancelDeferredCallback(callbackID); } - } else { - // default: - // This is a nested attribute configuration where all the properties - // were removed so we need to go through and clear out all of them. - updatePayload = clearNestedProperty( - updatePayload, - prevProp, - attributeConfig - ); } + // The request callback timer is already running. Don't start a new one. + } else { + startRequestCallbackTimer(); } - return updatePayload; + + callbackExpirationTime = expirationTime; + var currentMs = now() - originalStartTimeMs; + var expirationTimeMs = expirationTimeToMs(expirationTime); + var timeout = expirationTimeMs - currentMs; + callbackID = scheduleDeferredCallback(performAsyncWork, { timeout: timeout }); } -/** - * addProperties adds all the valid props to the payload after being processed. - */ -function addProperties(updatePayload, props, validAttributes) { - // TODO: Fast path - return diffProperties(updatePayload, emptyObject$1, props, validAttributes); +// For every call to renderRoot, one of onFatal, onComplete, onSuspend, and +// onYield is called upon exiting. We use these in lieu of returning a tuple. +// I've also chosen not to inline them into renderRoot because these will +// eventually be lifted into the renderer. +function onFatal(root) { + root.finishedWork = null; } -/** - * clearProperties clears all the previous props by adding a null sentinel - * to the payload for each valid key. - */ -function clearProperties(updatePayload, prevProps, validAttributes) { - // TODO: Fast path - return diffProperties( - updatePayload, - prevProps, - emptyObject$1, - validAttributes - ); +function onComplete(root, finishedWork, expirationTime) { + root.pendingCommitExpirationTime = expirationTime; + root.finishedWork = finishedWork; } -function create(props, validAttributes) { - return addProperties( - null, // updatePayload - props, - validAttributes - ); +function onSuspend(root, suspendedExpirationTime, expirationTime, timeoutMs) { + if (timeoutMs >= 0) { + var suspendedRoot = root; + setTimeout(function() { + retrySuspendedRoot(suspendedRoot, suspendedExpirationTime); + }, timeoutMs); + } + root.expirationTime = expirationTime; } -function diff(prevProps, nextProps, validAttributes) { - return diffProperties( - null, // updatePayload - prevProps, - nextProps, - validAttributes - ); +function onYield(root) { + root.finishedWork = null; } -/** - * In the future, we should cleanup callbacks by cancelling them instead of - * using this. - */ -function mountSafeCallback(context, callback) { - return function() { - if (!callback) { - return undefined; - } - if (typeof context.__isMounted === "boolean") { - // TODO(gaearon): this is gross and should be removed. - // It is currently necessary because View uses createClass, - // and so any measure() calls on View (which are done by React - // DevTools) trigger the isMounted() deprecation warning. - if (!context.__isMounted) { - return undefined; - } - // The else branch is important so that we don't - // trigger the deprecation warning by calling isMounted. - } else if (typeof context.isMounted === "function") { - if (!context.isMounted()) { - return undefined; - } - } - return callback.apply(context, arguments); - }; +function onCommit(root, expirationTime) { + root.expirationTime = expirationTime; + root.finishedWork = null; } -function throwOnStylesProp(component, props) { - if (props.styles !== undefined) { - var owner = component._owner || null; - var name = component.constructor.displayName; - var msg = - "`styles` is not a supported property of `" + - name + - "`, did " + - "you mean `style` (singular)?"; - if (owner && owner.constructor && owner.constructor.displayName) { - msg += - "\n\nCheck the `" + - owner.constructor.displayName + - "` parent " + - " component."; - } - throw new Error(msg); +// requestWork is called by the scheduler whenever a root receives an update. +// It's up to the renderer to call renderRoot at some point in the future. +function requestWork(root, expirationTime) { + addRootToSchedule(root, expirationTime); + + if (isRendering) { + // Prevent reentrancy. Remaining work will be scheduled at the end of + // the currently rendering batch. + return; } -} -function warnForStyleProps(props, validAttributes) { - for (var key in validAttributes.style) { - if (!(validAttributes[key] || props[key] === undefined)) { - console.error( - "You are setting the style `{ " + - key + - ": ... }` as a prop. You " + - "should nest it in a style object. " + - "E.g. `{ style: { " + - key + - ": ... } }`" - ); + if (isBatchingUpdates) { + // Flush work at the end of the batch. + if (isUnbatchingUpdates) { + // ...unless we're inside unbatchedUpdates, in which case we should + // flush it now. + nextFlushedRoot = root; + nextFlushedExpirationTime = Sync; + performWorkOnRoot(root, Sync, false); } + return; + } + + // TODO: Get rid of Sync and use current time? + if (expirationTime === Sync) { + performSyncWork(); + } else { + scheduleCallbackWithExpirationTime(expirationTime); } } -function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); +function addRootToSchedule(root, expirationTime) { + // Add the root to the schedule. + // Check if this root is already part of the schedule. + if (root.nextScheduledRoot === null) { + // This root is not already scheduled. Add it. + root.expirationTime = expirationTime; + if (lastScheduledRoot === null) { + firstScheduledRoot = lastScheduledRoot = root; + root.nextScheduledRoot = root; + } else { + lastScheduledRoot.nextScheduledRoot = root; + lastScheduledRoot = root; + lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; + } + } else { + // This root is already scheduled, but its priority may have increased. + var remainingExpirationTime = root.expirationTime; + if ( + remainingExpirationTime === NoWork || + expirationTime < remainingExpirationTime + ) { + // Update the priority. + root.expirationTime = expirationTime; + } } } -// Modules provided by RN: -/** - * This component defines the same methods as NativeMethodsMixin but without the - * findNodeHandle wrapper. This wrapper is unnecessary for HostComponent views - * and would also result in a circular require.js dependency (since - * ReactNativeFiber depends on this component and NativeMethodsMixin depends on - * ReactNativeFiber). - */ +function findHighestPriorityRoot() { + var highestPriorityWork = NoWork; + var highestPriorityRoot = null; + if (lastScheduledRoot !== null) { + var previousScheduledRoot = lastScheduledRoot; + var root = firstScheduledRoot; + while (root !== null) { + var remainingExpirationTime = root.expirationTime; + if (remainingExpirationTime === NoWork) { + // This root no longer has work. Remove it from the scheduler. -var ReactNativeFiberHostComponent = (function() { - function ReactNativeFiberHostComponent(tag, viewConfig) { - _classCallCheck(this, ReactNativeFiberHostComponent); + // TODO: This check is redudant, but Flow is confused by the branch + // below where we set lastScheduledRoot to null, even though we break + // from the loop right after. + invariant( + previousScheduledRoot !== null && lastScheduledRoot !== null, + "Should have a previous and last root. This error is likely " + + "caused by a bug in React. Please file an issue." + ); + if (root === root.nextScheduledRoot) { + // This is the only root in the list. + root.nextScheduledRoot = null; + firstScheduledRoot = lastScheduledRoot = null; + break; + } else if (root === firstScheduledRoot) { + // This is the first root in the list. + var next = root.nextScheduledRoot; + firstScheduledRoot = next; + lastScheduledRoot.nextScheduledRoot = next; + root.nextScheduledRoot = null; + } else if (root === lastScheduledRoot) { + // This is the last root in the list. + lastScheduledRoot = previousScheduledRoot; + lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; + root.nextScheduledRoot = null; + break; + } else { + previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot; + root.nextScheduledRoot = null; + } + root = previousScheduledRoot.nextScheduledRoot; + } else { + if ( + highestPriorityWork === NoWork || + remainingExpirationTime < highestPriorityWork + ) { + // Update the priority, if it's higher + highestPriorityWork = remainingExpirationTime; + highestPriorityRoot = root; + } + if (root === lastScheduledRoot) { + break; + } + previousScheduledRoot = root; + root = root.nextScheduledRoot; + } + } + } - this._nativeTag = tag; - this._children = []; - this.viewConfig = viewConfig; + // If the next root is the same as the previous root, this is a nested + // update. To prevent an infinite loop, increment the nested update count. + var previousFlushedRoot = nextFlushedRoot; + if ( + previousFlushedRoot !== null && + previousFlushedRoot === highestPriorityRoot && + highestPriorityWork === Sync + ) { + nestedUpdateCount++; + } else { + // Reset whenever we switch roots. + nestedUpdateCount = 0; } + nextFlushedRoot = highestPriorityRoot; + nextFlushedExpirationTime = highestPriorityWork; +} - ReactNativeFiberHostComponent.prototype.blur = function blur() { - TextInputState.blurTextInput(this._nativeTag); - }; +function performAsyncWork(dl) { + performWork(NoWork, dl); +} - ReactNativeFiberHostComponent.prototype.focus = function focus() { - TextInputState.focusTextInput(this._nativeTag); - }; +function performSyncWork() { + performWork(Sync, null); +} - ReactNativeFiberHostComponent.prototype.measure = function measure(callback) { - UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); - }; +function performWork(minExpirationTime, dl) { + deadline = dl; - ReactNativeFiberHostComponent.prototype.measureInWindow = function measureInWindow( - callback - ) { - UIManager.measureInWindow( - this._nativeTag, - mountSafeCallback(this, callback) - ); - }; + // Keep working on roots until there's no more work, or until the we reach + // the deadline. + findHighestPriorityRoot(); - ReactNativeFiberHostComponent.prototype.measureLayout = function measureLayout( - relativeToNativeNode, - onSuccess, - onFail /* currently unused */ - ) { - UIManager.measureLayout( - this._nativeTag, - relativeToNativeNode, - mountSafeCallback(this, onFail), - mountSafeCallback(this, onSuccess) - ); - }; + if (enableProfilerTimer) { + resumeActualRenderTimerIfPaused(); + } - ReactNativeFiberHostComponent.prototype.setNativeProps = function setNativeProps( - nativeProps - ) { - { - warnForStyleProps(nativeProps, this.viewConfig.validAttributes); + if (enableUserTimingAPI && deadline !== null) { + var didExpire = nextFlushedExpirationTime < recalculateCurrentTime(); + var timeout = expirationTimeToMs(nextFlushedExpirationTime); + stopRequestCallbackTimer(didExpire, timeout); + } + + if (deadline !== null) { + while ( + nextFlushedRoot !== null && + nextFlushedExpirationTime !== NoWork && + (minExpirationTime === NoWork || + minExpirationTime >= nextFlushedExpirationTime) && + (!deadlineDidExpire || + recalculateCurrentTime() >= nextFlushedExpirationTime) + ) { + recalculateCurrentTime(); + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, true); + findHighestPriorityRoot(); + } + } else { + while ( + nextFlushedRoot !== null && + nextFlushedExpirationTime !== NoWork && + (minExpirationTime === NoWork || + minExpirationTime >= nextFlushedExpirationTime) + ) { + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false); + findHighestPriorityRoot(); } + } - var updatePayload = create(nativeProps, this.viewConfig.validAttributes); + // We're done flushing work. Either we ran out of time in this callback, + // or there's no more work left with sufficient priority. - // Avoid the overhead of bridge calls if there's no update. - // This is an expensive no-op for Android, and causes an unnecessary - // view invalidation for certain components (eg RCTTextInput) on iOS. - if (updatePayload != null) { - UIManager.updateView( - this._nativeTag, - this.viewConfig.uiViewClassName, - updatePayload - ); - } - }; + // If we're inside a callback, set this to false since we just completed it. + if (deadline !== null) { + callbackExpirationTime = NoWork; + callbackID = null; + } + // If there's work left over, schedule a new callback. + if (nextFlushedExpirationTime !== NoWork) { + scheduleCallbackWithExpirationTime(nextFlushedExpirationTime); + } - return ReactNativeFiberHostComponent; -})(); + // Clean-up. + deadline = null; + deadlineDidExpire = false; -var hasNativePerformanceNow = - typeof performance === "object" && typeof performance.now === "function"; + finishRendering(); +} -var now = hasNativePerformanceNow - ? function() { - return performance.now(); +function flushRoot(root, expirationTime) { + invariant( + !isRendering, + "work.commit(): Cannot commit while already rendering. This likely " + + "means you attempted to commit from inside a lifecycle method." + ); + // 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(); +} + +function finishRendering() { + nestedUpdateCount = 0; + + if (completedBatches !== null) { + var batches = completedBatches; + completedBatches = null; + for (var i = 0; i < batches.length; i++) { + var batch = batches[i]; + try { + batch._onComplete(); + } catch (error) { + if (!hasUnhandledError) { + hasUnhandledError = true; + unhandledError = error; + } + } } - : function() { - return Date.now(); - }; + } -var scheduledCallback = null; -var frameDeadline = 0; + if (hasUnhandledError) { + var error = unhandledError; + unhandledError = null; + hasUnhandledError = false; + throw error; + } +} -var frameDeadlineObject = { - timeRemaining: function() { - return frameDeadline - now(); - }, - didTimeout: false -}; +function performWorkOnRoot(root, expirationTime, isYieldy) { + invariant( + !isRendering, + "performWorkOnRoot was called recursively. This error is likely caused " + + "by a bug in React. Please file an issue." + ); + + isRendering = true; + + // Check if this is async work or sync/expired work. + if (!isYieldy) { + // Flush work without yielding. + var finishedWork = root.finishedWork; + if (finishedWork !== null) { + // This root is already complete. We can commit it. + completeRoot(root, finishedWork, expirationTime); + } else { + root.finishedWork = null; + renderRoot(root, false); + finishedWork = root.finishedWork; + if (finishedWork !== null) { + // We've completed the root. Commit it. + completeRoot(root, finishedWork, expirationTime); + } + } + } else { + // Flush async work. + var _finishedWork = root.finishedWork; + if (_finishedWork !== null) { + // This root is already complete. We can commit it. + completeRoot(root, _finishedWork, expirationTime); + } else { + root.finishedWork = null; + renderRoot(root, true); + _finishedWork = root.finishedWork; + if (_finishedWork !== null) { + // We've completed the root. Check the deadline one more time + // before committing. + if (!shouldYield()) { + // Still time left. Commit the root. + completeRoot(root, _finishedWork, expirationTime); + } else { + // There's no time left. Mark this root as complete. We'll come + // back and commit it later. + root.finishedWork = _finishedWork; + + if (enableProfilerTimer) { + // If we didn't finish, pause the "actual" render timer. + // We'll restart it when we resume work. + pauseActualRenderTimerIfRunning(); + } + } + } + } + } -function setTimeoutCallback() { - // TODO (bvaughn) Hard-coded 5ms unblocks initial async testing. - // React API probably changing to boolean rather than time remaining. - // Longer-term plan is to rewrite this using shared memory, - // And just return the value of the bit as the boolean. - frameDeadline = now() + 5; + isRendering = false; +} - var callback = scheduledCallback; - scheduledCallback = null; - if (callback !== null) { - callback(frameDeadlineObject); +function completeRoot(root, finishedWork, expirationTime) { + // Check if there's a batch that matches this expiration time. + var firstBatch = root.firstBatch; + if (firstBatch !== null && firstBatch._expirationTime <= expirationTime) { + if (completedBatches === null) { + completedBatches = [firstBatch]; + } else { + completedBatches.push(firstBatch); + } + if (firstBatch._defer) { + // This root is blocked from committing by a batch. Unschedule it until + // we receive another update. + root.finishedWork = finishedWork; + root.expirationTime = NoWork; + return; + } } + + // Commit the root. + root.finishedWork = null; + commitRoot(root, finishedWork); } -// RN has a poor polyfill for requestIdleCallback so we aren't using it. -// This implementation is only intended for short-term use anyway. -// We also don't implement cancel functionality b'c Fiber doesn't currently need it. -function scheduleDeferredCallback(callback) { - // We assume only one callback is scheduled at a time b'c that's how Fiber works. - scheduledCallback = callback; - return setTimeout(setTimeoutCallback, 1); +// When working on async work, the reconciler asks the renderer if it should +// yield execution. For DOM, we implement this with requestIdleCallback. +function shouldYield() { + if (deadline === null || deadlineDidExpire) { + return false; + } + if (deadline.timeRemaining() > timeHeuristicForUnitOfWork) { + // Disregard deadline.didTimeout. Only expired work should be flushed + // during a timeout. This path is only hit for non-expired work. + return false; + } + deadlineDidExpire = true; + return true; } -function cancelDeferredCallback(callbackID) { - scheduledCallback = null; - clearTimeout(callbackID); +function onUncaughtError(error) { + invariant( + nextFlushedRoot !== null, + "Should be working on a root. This error is likely caused by a bug in " + + "React. Please file an issue." + ); + // Unschedule this root so we don't work on it again until there's + // another update. + nextFlushedRoot.expirationTime = NoWork; + if (!hasUnhandledError) { + hasUnhandledError = true; + unhandledError = error; + } } -// Modules provided by RN: -// Counter for uniquely identifying views. -// % 10 === 1 means it is a rootTag. -// % 2 === 0 means it is a Fabric tag. -var nextReactTag = 3; -function allocateTag() { - var tag = nextReactTag; - if (tag % 10 === 1) { - tag += 2; +// TODO: Batching should be implemented at the renderer level, not inside +// the reconciler. +function batchedUpdates$1(fn, a) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = true; + try { + return fn(a); + } finally { + isBatchingUpdates = previousIsBatchingUpdates; + if (!isBatchingUpdates && !isRendering) { + performSyncWork(); + } } - nextReactTag = tag + 2; - return tag; } -function recursivelyUncacheFiberNode(node) { - if (typeof node === "number") { - // Leaf node (eg text) - uncacheFiberNode(node); - } else { - uncacheFiberNode(node._nativeTag); +// TODO: Batching should be implemented at the renderer level, not inside +// the reconciler. +function unbatchedUpdates(fn, a) { + if (isBatchingUpdates && !isUnbatchingUpdates) { + isUnbatchingUpdates = true; + try { + return fn(a); + } finally { + isUnbatchingUpdates = false; + } + } + return fn(a); +} - node._children.forEach(recursivelyUncacheFiberNode); +// TODO: Batching should be implemented at the renderer level, not within +// the reconciler. +function flushSync(fn, a) { + invariant( + !isRendering, + "flushSync was called from inside a lifecycle method. It cannot be " + + "called when React is already rendering." + ); + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = true; + try { + return syncUpdates(fn, a); + } finally { + isBatchingUpdates = previousIsBatchingUpdates; + performSyncWork(); } } -var ReactNativeHostConfig = { - appendInitialChild: function(parentInstance, child) { - parentInstance._children.push(child); - }, - createInstance: function( - type, - props, - rootContainerInstance, - hostContext, - internalInstanceHandle +function interactiveUpdates$1(fn, a, b) { + if (isBatchingInteractiveUpdates) { + return fn(a, b); + } + // If there are any pending interactive updates, synchronously flush them. + // This needs to happen before we read any handlers, because the effect of + // the previous event may influence which handlers are called during + // this event. + if ( + !isBatchingUpdates && + !isRendering && + lowestPendingInteractiveExpirationTime !== NoWork ) { - var tag = allocateTag(); - var viewConfig = ReactNativeViewConfigRegistry.get(type); + // Synchronously flush pending interactive updates. + performWork(lowestPendingInteractiveExpirationTime, null); + lowestPendingInteractiveExpirationTime = NoWork; + } + var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates; + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingInteractiveUpdates = true; + isBatchingUpdates = true; + try { + return fn(a, b); + } finally { + isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates; + isBatchingUpdates = previousIsBatchingUpdates; + if (!isBatchingUpdates && !isRendering) { + performSyncWork(); + } + } +} - { - for (var key in viewConfig.validAttributes) { - if (props.hasOwnProperty(key)) { - deepFreezeAndThrowOnMutationInDev(props[key]); - } - } +function flushInteractiveUpdates$1() { + if (!isRendering && lowestPendingInteractiveExpirationTime !== NoWork) { + // Synchronously flush pending interactive updates. + performWork(lowestPendingInteractiveExpirationTime, null); + lowestPendingInteractiveExpirationTime = NoWork; + } +} + +function flushControlled(fn) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = true; + try { + syncUpdates(fn); + } finally { + isBatchingUpdates = previousIsBatchingUpdates; + if (!isBatchingUpdates && !isRendering) { + performWork(Sync, null); } + } +} - invariant( - type !== "RCTView" || !hostContext.isInAParentText, - "Nesting of within is not currently supported." - ); +// 0 is PROD, 1 is DEV. +// Might add PROFILE later. - var updatePayload = create(props, viewConfig.validAttributes); +var didWarnAboutNestedUpdates = void 0; - UIManager.createView( - tag, // reactTag - viewConfig.uiViewClassName, // viewName - rootContainerInstance, // rootTag - updatePayload // props - ); +{ + didWarnAboutNestedUpdates = false; +} - var component = new ReactNativeFiberHostComponent(tag, viewConfig); +function getContextForSubtree(parentComponent) { + if (!parentComponent) { + return emptyObject; + } - precacheFiberNode(internalInstanceHandle, tag); - updateFiberProps(tag, props); + var fiber = get$1(parentComponent); + var parentContext = findCurrentUnmaskedContext(fiber); + return isContextProvider(fiber) + ? processChildContext(fiber, parentContext) + : parentContext; +} - // Not sure how to avoid this cast. Flow is okay if the component is defined - // in the same file but if it's external it can't see the types. - return component; - }, - createTextInstance: function( - text, - rootContainerInstance, - hostContext, - internalInstanceHandle - ) { - invariant( - hostContext.isInAParentText, - "Text strings must be rendered within a component." - ); +function scheduleRootUpdate(current, element, expirationTime, callback) { + { + if ( + ReactDebugCurrentFiber.phase === "render" && + ReactDebugCurrentFiber.current !== null && + !didWarnAboutNestedUpdates + ) { + didWarnAboutNestedUpdates = true; + warning( + false, + "Render methods should be a pure function of props and state; " + + "triggering nested component updates from render is not allowed. " + + "If necessary, trigger nested updates in componentDidUpdate.\n\n" + + "Check the render method of %s.", + getComponentName(ReactDebugCurrentFiber.current) || "Unknown" + ); + } + } - var tag = allocateTag(); + var update = createUpdate(expirationTime); + // Caution: React DevTools currently depends on this property + // being called "element". + update.payload = { element: element }; - UIManager.createView( - tag, // reactTag - "RCTRawText", // viewName - rootContainerInstance, // rootTag - { text: text } // props - ); + callback = callback === undefined ? null : callback; + if (callback !== null) { + !(typeof callback === "function") + ? warning( + false, + "render(...): Expected the last optional `callback` argument to be a " + + "function. Instead received: %s.", + callback + ) + : void 0; + update.callback = callback; + } + enqueueUpdate(current, update, expirationTime); - precacheFiberNode(internalInstanceHandle, tag); + scheduleWork(current, expirationTime); + return expirationTime; +} - return tag; - }, - finalizeInitialChildren: function( - parentInstance, - type, - props, - rootContainerInstance - ) { - // Don't send a no-op message over the bridge. - if (parentInstance._children.length === 0) { - return false; +function updateContainerAtExpirationTime( + element, + container, + parentComponent, + expirationTime, + callback +) { + // TODO: If this is a nested container, this won't be the root. + var current = container.current; + + { + if (ReactFiberInstrumentation_1.debugTool) { + if (current.alternate === null) { + ReactFiberInstrumentation_1.debugTool.onMountContainer(container); + } else if (element === null) { + ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container); + } else { + ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container); + } } + } - // Map from child objects to native tags. - // Either way we need to pass a copy of the Array to prevent it from being frozen. - var nativeTags = parentInstance._children.map(function(child) { - return typeof child === "number" - ? child // Leaf node (eg text) - : child._nativeTag; - }); + var context = getContextForSubtree(parentComponent); + if (container.context === null) { + container.context = context; + } else { + container.pendingContext = context; + } - UIManager.setChildren( - parentInstance._nativeTag, // containerTag - nativeTags // reactTags - ); + return scheduleRootUpdate(current, element, expirationTime, callback); +} - return false; - }, - getRootHostContext: function(rootContainerInstance) { - return { isInAParentText: false }; - }, - getChildHostContext: function(parentHostContext, type) { - var prevIsInAParentText = parentHostContext.isInAParentText; - var isInAParentText = - type === "AndroidTextInput" || // Android - type === "RCTMultilineTextInputView" || // iOS - type === "RCTSinglelineTextInputView" || // iOS - type === "RCTText" || - type === "RCTVirtualText"; - - if (prevIsInAParentText !== isInAParentText) { - return { isInAParentText: isInAParentText }; +function findHostInstance$1(component) { + var fiber = get$1(component); + if (fiber === undefined) { + if (typeof component.render === "function") { + invariant(false, "Unable to find node on an unmounted component."); } else { - return parentHostContext; + invariant( + false, + "Argument appears to not be a ReactComponent. Keys: %s", + Object.keys(component) + ); } - }, - getPublicInstance: function(instance) { - return instance; - }, + } + var hostFiber = findCurrentHostFiber(fiber); + if (hostFiber === null) { + return null; + } + return hostFiber.stateNode; +} - now: now, +function createContainer(containerInfo, isAsync, hydrate) { + return createFiberRoot(containerInfo, isAsync, hydrate); +} - isPrimaryRenderer: true, +function updateContainer(element, container, parentComponent, callback) { + var current = container.current; + var currentTime = recalculateCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, current); + return updateContainerAtExpirationTime( + element, + container, + parentComponent, + expirationTime, + callback + ); +} - prepareForCommit: function() { - // Noop - }, - prepareUpdate: function( - instance, - type, - oldProps, - newProps, - rootContainerInstance, - hostContext - ) { - return emptyObject; - }, - resetAfterCommit: function() { - // Noop - }, +function getPublicRootInstance(container) { + var containerFiber = container.current; + if (!containerFiber.child) { + return null; + } + switch (containerFiber.child.tag) { + case HostComponent: + return getPublicInstance(containerFiber.child.stateNode); + default: + return containerFiber.child.stateNode; + } +} - scheduleDeferredCallback: scheduleDeferredCallback, - cancelDeferredCallback: cancelDeferredCallback, +function findHostInstanceWithNoPortals(fiber) { + var hostFiber = findCurrentHostFiberWithNoPortals(fiber); + if (hostFiber === null) { + return null; + } + return hostFiber.stateNode; +} - shouldDeprioritizeSubtree: function(type, props) { - return false; - }, - shouldSetTextContent: function(type, props) { - // TODO (bvaughn) Revisit this decision. - // Always returning false simplifies the createInstance() implementation, - // But creates an additional child Fiber for raw text children. - // No additional native views are created though. - // It's not clear to me which is better so I'm deferring for now. - // More context @ github.com/facebook/react/pull/8560#discussion_r92111303 - return false; - }, +function injectIntoDevTools(devToolsConfig) { + var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; - mutation: { - appendChild: function(parentInstance, child) { - var childTag = typeof child === "number" ? child : child._nativeTag; - var children = parentInstance._children; - var index = children.indexOf(child); - - if (index >= 0) { - children.splice(index, 1); - children.push(child); - - UIManager.manageChildren( - parentInstance._nativeTag, // containerTag - [index], // moveFromIndices - [children.length - 1], // moveToIndices - [], // addChildReactTags - [], // addAtIndices - [] // removeAtIndices - ); - } else { - children.push(child); - - UIManager.manageChildren( - parentInstance._nativeTag, // containerTag - [], // moveFromIndices - [], // moveToIndices - [childTag], // addChildReactTags - [children.length - 1], // addAtIndices - [] // removeAtIndices - ); + return injectInternals( + Object.assign({}, devToolsConfig, { + findHostInstanceByFiber: function(fiber) { + var hostFiber = findCurrentHostFiber(fiber); + if (hostFiber === null) { + return null; + } + return hostFiber.stateNode; + }, + findFiberByHostInstance: function(instance) { + if (!findFiberByHostInstance) { + // Might not be implemented by the renderer. + return null; + } + return findFiberByHostInstance(instance); } - }, - appendChildToContainer: function(parentInstance, child) { - var childTag = typeof child === "number" ? child : child._nativeTag; - UIManager.setChildren( - parentInstance, // containerTag - [childTag] // reactTags - ); - }, - commitTextUpdate: function(textInstance, oldText, newText) { - UIManager.updateView( - textInstance, // reactTag - "RCTRawText", // viewName - { text: newText } // props - ); - }, - commitMount: function(instance, type, newProps, internalInstanceHandle) { - // Noop - }, - commitUpdate: function( - instance, - updatePayloadTODO, - type, - oldProps, - newProps, - internalInstanceHandle - ) { - var viewConfig = instance.viewConfig; + }) + ); +} - updateFiberProps(instance._nativeTag, newProps); +// This file intentionally does *not* have the Flow annotation. +// Don't add it. See `./inline-typed.js` for an explanation. + +var ReactNativeFiberRenderer = Object.freeze({ + updateContainerAtExpirationTime: updateContainerAtExpirationTime, + createContainer: createContainer, + updateContainer: updateContainer, + flushRoot: flushRoot, + requestWork: requestWork, + computeUniqueAsyncExpiration: computeUniqueAsyncExpiration, + batchedUpdates: batchedUpdates$1, + unbatchedUpdates: unbatchedUpdates, + deferredUpdates: deferredUpdates, + syncUpdates: syncUpdates, + interactiveUpdates: interactiveUpdates$1, + flushInteractiveUpdates: flushInteractiveUpdates$1, + flushControlled: flushControlled, + flushSync: flushSync, + getPublicRootInstance: getPublicRootInstance, + findHostInstance: findHostInstance$1, + findHostInstanceWithNoPortals: findHostInstanceWithNoPortals, + injectIntoDevTools: injectIntoDevTools +}); - var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); +function createPortal( + children, + containerInfo, + // TODO: figure out the API for cross-renderer implementation. + implementation +) { + var key = + arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; - // Avoid the overhead of bridge calls if there's no update. - // This is an expensive no-op for Android, and causes an unnecessary - // view invalidation for certain components (eg RCTTextInput) on iOS. - if (updatePayload != null) { - UIManager.updateView( - instance._nativeTag, // reactTag - viewConfig.uiViewClassName, // viewName - updatePayload // props - ); - } - }, - insertBefore: function(parentInstance, child, beforeChild) { - var children = parentInstance._children; - var index = children.indexOf(child); - - // Move existing child or add new child? - if (index >= 0) { - children.splice(index, 1); - var beforeChildIndex = children.indexOf(beforeChild); - children.splice(beforeChildIndex, 0, child); - - UIManager.manageChildren( - parentInstance._nativeTag, // containerID - [index], // moveFromIndices - [beforeChildIndex], // moveToIndices - [], // addChildReactTags - [], // addAtIndices - [] // removeAtIndices - ); - } else { - var _beforeChildIndex = children.indexOf(beforeChild); - children.splice(_beforeChildIndex, 0, child); - - var childTag = typeof child === "number" ? child : child._nativeTag; - - UIManager.manageChildren( - parentInstance._nativeTag, // containerID - [], // moveFromIndices - [], // moveToIndices - [childTag], // addChildReactTags - [_beforeChildIndex], // addAtIndices - [] // removeAtIndices - ); - } - }, - insertInContainerBefore: function(parentInstance, child, beforeChild) { - // TODO (bvaughn): Remove this check when... - // We create a wrapper object for the container in ReactNative render() - // Or we refactor to remove wrapper objects entirely. - // For more info on pros/cons see PR #8560 description. - invariant( - typeof parentInstance !== "number", - "Container does not support insertBefore operation" - ); - }, - removeChild: function(parentInstance, child) { - recursivelyUncacheFiberNode(child); - var children = parentInstance._children; - var index = children.indexOf(child); - - children.splice(index, 1); - - UIManager.manageChildren( - parentInstance._nativeTag, // containerID - [], // moveFromIndices - [], // moveToIndices - [], // addChildReactTags - [], // addAtIndices - [index] // removeAtIndices - ); - }, - removeChildFromContainer: function(parentInstance, child) { - recursivelyUncacheFiberNode(child); - UIManager.manageChildren( - parentInstance, // containerID - [], // moveFromIndices - [], // moveToIndices - [], // addChildReactTags - [], // addAtIndices - [0] // removeAtIndices - ); - }, - resetTextContent: function(instance) { - // Noop - } - } -}; + return { + // This tag allow us to uniquely identify this as a React Portal + $$typeof: REACT_PORTAL_TYPE, + key: key == null ? null : "" + key, + children: children, + containerInfo: containerInfo, + implementation: implementation + }; +} + +// TODO: this is special because it gets imported during build. + +var ReactVersion = "16.4.1"; // Modules provided by RN: var NativeMethodsMixin = function(findNodeHandle, findHostInstance) { @@ -15112,9 +14851,7 @@ var getInspectorDataForViewTag = void 0; } // Module provided by RN: -var ReactNativeFiberRenderer = reactReconciler(ReactNativeHostConfig); - -var findHostInstance = ReactNativeFiberRenderer.findHostInstance; +var findHostInstance = findHostInstance$1; function findNodeHandle(componentOrHandle) { { @@ -15182,22 +14919,18 @@ var ReactNativeRenderer = { if (!root) { // TODO (bvaughn): If we decide to keep the wrapper component, // We could create a wrapper for containerTag as well to reduce special casing. - root = ReactNativeFiberRenderer.createContainer( - containerTag, - false, - false - ); + root = createContainer(containerTag, false, false); roots.set(containerTag, root); } - ReactNativeFiberRenderer.updateContainer(element, root, null, callback); + updateContainer(element, root, null, callback); - return ReactNativeFiberRenderer.getPublicRootInstance(root); + return getPublicRootInstance(root); }, unmountComponentAtNode: function(containerTag) { var root = roots.get(containerTag); if (root) { // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred? - ReactNativeFiberRenderer.updateContainer(null, root, null, function() { + updateContainer(null, root, null, function() { roots.delete(containerTag); }); } @@ -15220,13 +14953,11 @@ var ReactNativeRenderer = { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: { // Used as a mixin in many createClass-based components NativeMethodsMixin: NativeMethodsMixin(findNodeHandle, findHostInstance), - // Used by react-native-github/Libraries/ components - ReactNativeComponentTree: ReactNativeComponentTree, // ScrollResponder computeComponentStackForErrorReporting: computeComponentStackForErrorReporting } }; -ReactNativeFiberRenderer.injectIntoDevTools({ +injectIntoDevTools({ findFiberByHostInstance: getInstanceFromTag, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 1, diff --git a/Libraries/Renderer/oss/ReactNativeRenderer-prod.js b/Libraries/Renderer/oss/ReactNativeRenderer-prod.js index 52c14c46bfc33e..24da20e3ba4278 100644 --- a/Libraries/Renderer/oss/ReactNativeRenderer-prod.js +++ b/Libraries/Renderer/oss/ReactNativeRenderer-prod.js @@ -13,17 +13,15 @@ "use strict"; require("InitializeCore"); var invariant = require("fbjs/lib/invariant"), - emptyFunction = require("fbjs/lib/emptyFunction"), ReactNativeViewConfigRegistry = require("ReactNativeViewConfigRegistry"), UIManager = require("UIManager"), RCTEventEmitter = require("RCTEventEmitter"), React = require("react"), emptyObject = require("fbjs/lib/emptyObject"), - shallowEqual = require("fbjs/lib/shallowEqual"), - ExceptionsManager = require("ExceptionsManager"), deepDiffer = require("deepDiffer"), flattenStyle = require("flattenStyle"), - TextInputState = require("TextInputState"); + TextInputState = require("TextInputState"), + ExceptionsManager = require("ExceptionsManager"); function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) { this._hasCaughtError = !1; this._caughtError = null; @@ -350,21 +348,14 @@ function accumulateDirectDispatchesSingle(event) { } } var shouldBeReleasedProperties = "dispatchConfig _targetInst nativeEvent isDefaultPrevented isPropagationStopped _dispatchListeners _dispatchInstances".split( - " " - ), - EventInterface = { - type: null, - target: null, - currentTarget: emptyFunction.thatReturnsNull, - eventPhase: null, - bubbles: null, - cancelable: null, - timeStamp: function(event) { - return event.timeStamp || Date.now(); - }, - defaultPrevented: null, - isTrusted: null - }; + " " +); +function functionThatReturnsTrue() { + return !0; +} +function functionThatReturnsFalse() { + return !1; +} function SyntheticEvent( dispatchConfig, targetInst, @@ -385,9 +376,9 @@ function SyntheticEvent( this.isDefaultPrevented = (null != nativeEvent.defaultPrevented ? nativeEvent.defaultPrevented : !1 === nativeEvent.returnValue) - ? emptyFunction.thatReturnsTrue - : emptyFunction.thatReturnsFalse; - this.isPropagationStopped = emptyFunction.thatReturnsFalse; + ? functionThatReturnsTrue + : functionThatReturnsFalse; + this.isPropagationStopped = functionThatReturnsFalse; return this; } Object.assign(SyntheticEvent.prototype, { @@ -398,7 +389,7 @@ Object.assign(SyntheticEvent.prototype, { (event.preventDefault ? event.preventDefault() : "unknown" !== typeof event.returnValue && (event.returnValue = !1), - (this.isDefaultPrevented = emptyFunction.thatReturnsTrue)); + (this.isDefaultPrevented = functionThatReturnsTrue)); }, stopPropagation: function() { var event = this.nativeEvent; @@ -406,12 +397,12 @@ Object.assign(SyntheticEvent.prototype, { (event.stopPropagation ? event.stopPropagation() : "unknown" !== typeof event.cancelBubble && (event.cancelBubble = !0), - (this.isPropagationStopped = emptyFunction.thatReturnsTrue)); + (this.isPropagationStopped = functionThatReturnsTrue)); }, persist: function() { - this.isPersistent = emptyFunction.thatReturnsTrue; + this.isPersistent = functionThatReturnsTrue; }, - isPersistent: emptyFunction.thatReturnsFalse, + isPersistent: functionThatReturnsFalse, destructor: function() { var Interface = this.constructor.Interface, propName; @@ -424,7 +415,21 @@ Object.assign(SyntheticEvent.prototype, { this[shouldBeReleasedProperties[Interface]] = null; } }); -SyntheticEvent.Interface = EventInterface; +SyntheticEvent.Interface = { + type: null, + target: null, + currentTarget: function() { + return null; + }, + eventPhase: null, + bubbles: null, + cancelable: null, + timeStamp: function(event) { + return event.timeStamp || Date.now(); + }, + defaultPrevented: null, + isTrusted: null +}; SyntheticEvent.extend = function(Interface) { function E() {} function Class() { @@ -984,56 +989,45 @@ var eventTypes$1 = { else return null; return topLevelType; } - }, - instanceCache = {}, - instanceProps = {}; -function uncacheFiberNode(tag) { - delete instanceCache[tag]; - delete instanceProps[tag]; -} -function getInstanceFromTag(tag) { - return "number" === typeof tag ? instanceCache[tag] || null : tag; -} -var ReactNativeComponentTree = Object.freeze({ - precacheFiberNode: function(hostInst, tag) { - instanceCache[tag] = hostInst; - }, - uncacheFiberNode: uncacheFiberNode, - getClosestInstanceFromNode: getInstanceFromTag, - getInstanceFromNode: getInstanceFromTag, - getNodeFromInstance: function(inst) { - var tag = inst.stateNode._nativeTag; - void 0 === tag && (tag = inst.stateNode.canonical._nativeTag); - invariant(tag, "All native instances should have a tag."); - return tag; - }, - getFiberCurrentPropsFromNode: function(stateNode) { - return instanceProps[stateNode._nativeTag] || null; - }, - updateFiberProps: function(tag, props) { - instanceProps[tag] = props; - } -}); + }; injection.injectEventPluginOrder([ "ResponderEventPlugin", "ReactNativeBridgeEventPlugin" ]); -getFiberCurrentPropsFromNode = - ReactNativeComponentTree.getFiberCurrentPropsFromNode; -getInstanceFromNode = ReactNativeComponentTree.getInstanceFromNode; -getNodeFromInstance = ReactNativeComponentTree.getNodeFromInstance; -ResponderEventPlugin.injection.injectGlobalResponderHandler({ - onChange: function(from, to, blockNativeResponder) { - null !== to - ? UIManager.setJSResponder(to.stateNode._nativeTag, blockNativeResponder) - : UIManager.clearJSResponder(); - } -}); injection.injectEventPluginsByName({ ResponderEventPlugin: ResponderEventPlugin, ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin }); -var restoreTarget = null, +var instanceCache = {}, + instanceProps = {}; +function uncacheFiberNode(tag) { + delete instanceCache[tag]; + delete instanceProps[tag]; +} +function getInstanceFromTag(tag) { + return instanceCache[tag] || null; +} +var ReactNativeComponentTree = { + precacheFiberNode: function(hostInst, tag) { + instanceCache[tag] = hostInst; + }, + uncacheFiberNode: uncacheFiberNode, + getClosestInstanceFromNode: getInstanceFromTag, + getInstanceFromNode: getInstanceFromTag, + getNodeFromInstance: function(inst) { + var tag = inst.stateNode._nativeTag; + void 0 === tag && (tag = inst.stateNode.canonical._nativeTag); + invariant(tag, "All native instances should have a tag."); + return tag; + }, + getFiberCurrentPropsFromNode: function(stateNode) { + return instanceProps[stateNode._nativeTag] || null; + }, + updateFiberProps: function(tag, props) { + instanceProps[tag] = props; + } + }, + restoreTarget = null, restoreQueue = null; function restoreStateOfTarget(target) { if ((target = getInstanceFromNode(target))) { @@ -1100,7 +1094,7 @@ function _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam) { ReactErrorUtils.rethrowCaughtError()); }); } -var ReactNativeEventEmitter = Object.freeze({ +RCTEventEmitter.register({ getListener: getListener, registrationNames: registrationNameModules, _receiveRootNodeIDEvent: _receiveRootNodeIDEvent, @@ -1140,7 +1134,17 @@ var ReactNativeEventEmitter = Object.freeze({ } } }); -RCTEventEmitter.register(ReactNativeEventEmitter); +getFiberCurrentPropsFromNode = + ReactNativeComponentTree.getFiberCurrentPropsFromNode; +getInstanceFromNode = ReactNativeComponentTree.getInstanceFromNode; +getNodeFromInstance = ReactNativeComponentTree.getNodeFromInstance; +ResponderEventPlugin.injection.injectGlobalResponderHandler({ + onChange: function(from, to, blockNativeResponder) { + null !== to + ? UIManager.setJSResponder(to.stateNode._nativeTag, blockNativeResponder) + : UIManager.clearJSResponder(); + } +}); var ReactCurrentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, hasSymbol = "function" === typeof Symbol && Symbol.for, @@ -1182,6 +1186,8 @@ function getComponentName(fiber) { return "Context.Provider"; case REACT_STRICT_MODE_TYPE: return "StrictMode"; + case REACT_TIMEOUT_TYPE: + return "Timeout"; } if ("object" === typeof type && null !== type) switch (type.$$typeof) { @@ -1203,11 +1209,6 @@ function isFiberMountedImpl(fiber) { } return 3 === node.tag ? 2 : 3; } -function isMounted(component) { - return (component = component._reactInternalFiber) - ? 2 === isFiberMountedImpl(component) - : !1; -} function assertIsMounted(fiber) { invariant( 2 === isFiberMountedImpl(fiber), @@ -1322,170 +1323,343 @@ function findCurrentHostFiberWithNoPortals(parent) { } return null; } -function FiberNode(tag, pendingProps, key, mode) { - this.tag = tag; - this.key = key; - this.sibling = this.child = this.return = this.stateNode = this.type = null; - this.index = 0; - this.ref = null; - this.pendingProps = pendingProps; - this.memoizedState = this.updateQueue = this.memoizedProps = null; - this.mode = mode; - this.effectTag = 0; - this.lastEffect = this.firstEffect = this.nextEffect = null; - this.expirationTime = 0; - this.alternate = null; -} -function createWorkInProgress(current, pendingProps, expirationTime) { - var workInProgress = current.alternate; - null === workInProgress - ? ((workInProgress = new FiberNode( - current.tag, - pendingProps, - current.key, - current.mode - )), - (workInProgress.type = current.type), - (workInProgress.stateNode = current.stateNode), - (workInProgress.alternate = current), - (current.alternate = workInProgress)) - : ((workInProgress.pendingProps = pendingProps), - (workInProgress.effectTag = 0), - (workInProgress.nextEffect = null), - (workInProgress.firstEffect = null), - (workInProgress.lastEffect = null)); - workInProgress.expirationTime = expirationTime; - workInProgress.child = current.child; - workInProgress.memoizedProps = current.memoizedProps; - workInProgress.memoizedState = current.memoizedState; - workInProgress.updateQueue = current.updateQueue; - workInProgress.sibling = current.sibling; - workInProgress.index = current.index; - workInProgress.ref = current.ref; - return workInProgress; -} -function createFiberFromElement(element, mode, expirationTime) { - var type = element.type, - key = element.key; - element = element.props; - if ("function" === typeof type) - var fiberTag = type.prototype && type.prototype.isReactComponent ? 2 : 0; - else if ("string" === typeof type) fiberTag = 5; - else - switch (type) { - case REACT_FRAGMENT_TYPE: - return createFiberFromFragment( - element.children, - mode, - expirationTime, - key - ); - case REACT_ASYNC_MODE_TYPE: - fiberTag = 11; - mode |= 3; - break; - case REACT_STRICT_MODE_TYPE: - fiberTag = 11; - mode |= 2; - break; - case REACT_PROFILER_TYPE: - return ( - (type = new FiberNode(15, element, key, mode | 4)), - (type.type = REACT_PROFILER_TYPE), - (type.expirationTime = expirationTime), - (type.stateNode = { duration: 0, startTime: 0 }), - type - ); - case REACT_TIMEOUT_TYPE: - fiberTag = 16; - mode |= 2; - break; - default: - a: { - switch ("object" === typeof type && null !== type - ? type.$$typeof - : null) { - case REACT_PROVIDER_TYPE: - fiberTag = 13; - break a; - case REACT_CONTEXT_TYPE: - fiberTag = 12; - break a; - case REACT_FORWARD_REF_TYPE: - fiberTag = 14; - break a; - default: - invariant( - !1, - "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", - null == type ? type : typeof type, - "" - ); +var emptyObject$1 = {}, + removedKeys = null, + removedKeyCount = 0; +function restoreDeletedValuesInNestedArray( + updatePayload, + node, + validAttributes +) { + if (Array.isArray(node)) + for (var i = node.length; i-- && 0 < removedKeyCount; ) + restoreDeletedValuesInNestedArray( + updatePayload, + node[i], + validAttributes + ); + else if (node && 0 < removedKeyCount) + for (i in removedKeys) + if (removedKeys[i]) { + var _nextProp = node[i]; + if (void 0 !== _nextProp) { + var attributeConfig = validAttributes[i]; + if (attributeConfig) { + "function" === typeof _nextProp && (_nextProp = !0); + "undefined" === typeof _nextProp && (_nextProp = null); + if ("object" !== typeof attributeConfig) + updatePayload[i] = _nextProp; + else if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) + (_nextProp = + "function" === typeof attributeConfig.process + ? attributeConfig.process(_nextProp) + : _nextProp), + (updatePayload[i] = _nextProp); + removedKeys[i] = !1; + removedKeyCount--; } - fiberTag = void 0; } - } - mode = new FiberNode(fiberTag, element, key, mode); - mode.type = type; - mode.expirationTime = expirationTime; - return mode; -} -function createFiberFromFragment(elements, mode, expirationTime, key) { - elements = new FiberNode(10, elements, key, mode); - elements.expirationTime = expirationTime; - return elements; -} -function createFiberFromText(content, mode, expirationTime) { - content = new FiberNode(6, content, null, mode); - content.expirationTime = expirationTime; - return content; -} -function createFiberFromPortal(portal, mode, expirationTime) { - mode = new FiberNode( - 4, - null !== portal.children ? portal.children : [], - portal.key, - mode - ); - mode.expirationTime = expirationTime; - mode.stateNode = { - containerInfo: portal.containerInfo, - pendingChildren: null, - implementation: portal.implementation - }; - return mode; -} -var onCommitFiberRoot = null, - onCommitFiberUnmount = null; -function catchErrors(fn) { - return function(arg) { - try { - return fn(arg); - } catch (err) {} - }; -} -function injectInternals(internals) { - if ("undefined" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) return !1; - var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__; - if (hook.isDisabled || !hook.supportsFiber) return !0; - try { - var rendererID = hook.inject(internals); - onCommitFiberRoot = catchErrors(function(root) { - return hook.onCommitFiberRoot(rendererID, root); - }); - onCommitFiberUnmount = catchErrors(function(fiber) { - return hook.onCommitFiberUnmount(rendererID, fiber); - }); - } catch (err) {} - return !0; -} -function onCommitRoot(root) { - "function" === typeof onCommitFiberRoot && onCommitFiberRoot(root); -} -function onCommitUnmount(fiber) { - "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(fiber); + } } -function getStackAddendumByWorkInProgressFiber(workInProgress) { +function diffNestedProperty( + updatePayload, + prevProp, + nextProp, + validAttributes +) { + if (!updatePayload && prevProp === nextProp) return updatePayload; + if (!prevProp || !nextProp) + return nextProp + ? addNestedProperty(updatePayload, nextProp, validAttributes) + : prevProp + ? clearNestedProperty(updatePayload, prevProp, validAttributes) + : updatePayload; + if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) + return diffProperties(updatePayload, prevProp, nextProp, validAttributes); + if (Array.isArray(prevProp) && Array.isArray(nextProp)) { + var minLength = + prevProp.length < nextProp.length ? prevProp.length : nextProp.length, + i; + for (i = 0; i < minLength; i++) + updatePayload = diffNestedProperty( + updatePayload, + prevProp[i], + nextProp[i], + validAttributes + ); + for (; i < prevProp.length; i++) + updatePayload = clearNestedProperty( + updatePayload, + prevProp[i], + validAttributes + ); + for (; i < nextProp.length; i++) + updatePayload = addNestedProperty( + updatePayload, + nextProp[i], + validAttributes + ); + return updatePayload; + } + return Array.isArray(prevProp) + ? diffProperties( + updatePayload, + flattenStyle(prevProp), + nextProp, + validAttributes + ) + : diffProperties( + updatePayload, + prevProp, + flattenStyle(nextProp), + validAttributes + ); +} +function addNestedProperty(updatePayload, nextProp, validAttributes) { + if (!nextProp) return updatePayload; + if (!Array.isArray(nextProp)) + return diffProperties( + updatePayload, + emptyObject$1, + nextProp, + validAttributes + ); + for (var i = 0; i < nextProp.length; i++) + updatePayload = addNestedProperty( + updatePayload, + nextProp[i], + validAttributes + ); + return updatePayload; +} +function clearNestedProperty(updatePayload, prevProp, validAttributes) { + if (!prevProp) return updatePayload; + if (!Array.isArray(prevProp)) + return diffProperties( + updatePayload, + prevProp, + emptyObject$1, + validAttributes + ); + for (var i = 0; i < prevProp.length; i++) + updatePayload = clearNestedProperty( + updatePayload, + prevProp[i], + validAttributes + ); + return updatePayload; +} +function diffProperties(updatePayload, prevProps, nextProps, validAttributes) { + var attributeConfig, propKey; + for (propKey in nextProps) + if ((attributeConfig = validAttributes[propKey])) { + var prevProp = prevProps[propKey]; + var nextProp = nextProps[propKey]; + "function" === typeof nextProp && + ((nextProp = !0), "function" === typeof prevProp && (prevProp = !0)); + "undefined" === typeof nextProp && + ((nextProp = null), + "undefined" === typeof prevProp && (prevProp = null)); + removedKeys && (removedKeys[propKey] = !1); + if (updatePayload && void 0 !== updatePayload[propKey]) + if ("object" !== typeof attributeConfig) + updatePayload[propKey] = nextProp; + else { + if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) + (attributeConfig = + "function" === typeof attributeConfig.process + ? attributeConfig.process(nextProp) + : nextProp), + (updatePayload[propKey] = attributeConfig); + } + else if (prevProp !== nextProp) + if ("object" !== typeof attributeConfig) + ("object" !== typeof nextProp || + null === nextProp || + deepDiffer(prevProp, nextProp)) && + ((updatePayload || (updatePayload = {}))[propKey] = nextProp); + else if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) { + if ( + void 0 === prevProp || + ("function" === typeof attributeConfig.diff + ? attributeConfig.diff(prevProp, nextProp) + : "object" !== typeof nextProp || + null === nextProp || + deepDiffer(prevProp, nextProp)) + ) + (attributeConfig = + "function" === typeof attributeConfig.process + ? attributeConfig.process(nextProp) + : nextProp), + ((updatePayload || (updatePayload = {}))[ + propKey + ] = attributeConfig); + } else + (removedKeys = null), + (removedKeyCount = 0), + (updatePayload = diffNestedProperty( + updatePayload, + prevProp, + nextProp, + attributeConfig + )), + 0 < removedKeyCount && + updatePayload && + (restoreDeletedValuesInNestedArray( + updatePayload, + nextProp, + attributeConfig + ), + (removedKeys = null)); + } + for (var _propKey in prevProps) + void 0 === nextProps[_propKey] && + (!(attributeConfig = validAttributes[_propKey]) || + (updatePayload && void 0 !== updatePayload[_propKey]) || + ((prevProp = prevProps[_propKey]), + void 0 !== prevProp && + ("object" !== typeof attributeConfig || + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ? (((updatePayload || (updatePayload = {}))[_propKey] = null), + removedKeys || (removedKeys = {}), + removedKeys[_propKey] || + ((removedKeys[_propKey] = !0), removedKeyCount++)) + : (updatePayload = clearNestedProperty( + updatePayload, + prevProp, + attributeConfig + ))))); + return updatePayload; +} +function mountSafeCallback(context, callback) { + return function() { + if (callback) { + if ("boolean" === typeof context.__isMounted) { + if (!context.__isMounted) return; + } else if ( + "function" === typeof context.isMounted && + !context.isMounted() + ) + return; + return callback.apply(context, arguments); + } + }; +} +var ReactNativeFiberHostComponent = (function() { + function ReactNativeFiberHostComponent(tag, viewConfig) { + if (!(this instanceof ReactNativeFiberHostComponent)) + throw new TypeError("Cannot call a class as a function"); + this._nativeTag = tag; + this._children = []; + this.viewConfig = viewConfig; + } + ReactNativeFiberHostComponent.prototype.blur = function() { + TextInputState.blurTextInput(this._nativeTag); + }; + ReactNativeFiberHostComponent.prototype.focus = function() { + TextInputState.focusTextInput(this._nativeTag); + }; + ReactNativeFiberHostComponent.prototype.measure = function(callback) { + UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); + }; + ReactNativeFiberHostComponent.prototype.measureInWindow = function( + callback + ) { + UIManager.measureInWindow( + this._nativeTag, + mountSafeCallback(this, callback) + ); + }; + ReactNativeFiberHostComponent.prototype.measureLayout = function( + relativeToNativeNode, + onSuccess, + onFail + ) { + UIManager.measureLayout( + this._nativeTag, + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }; + ReactNativeFiberHostComponent.prototype.setNativeProps = function( + nativeProps + ) { + nativeProps = diffProperties( + null, + emptyObject$1, + nativeProps, + this.viewConfig.validAttributes + ); + null != nativeProps && + UIManager.updateView( + this._nativeTag, + this.viewConfig.uiViewClassName, + nativeProps + ); + }; + return ReactNativeFiberHostComponent; + })(), + now$1 = + "object" === typeof performance && "function" === typeof performance.now + ? function() { + return performance.now(); + } + : function() { + return Date.now(); + }, + scheduledCallback = null, + frameDeadline = 0, + frameDeadlineObject = { + timeRemaining: function() { + return frameDeadline - now$1(); + }, + didTimeout: !1 + }; +function setTimeoutCallback() { + frameDeadline = now$1() + 5; + var callback = scheduledCallback; + scheduledCallback = null; + null !== callback && callback(frameDeadlineObject); +} +function shim$1() { + invariant( + !1, + "The current renderer does not support hyration. This error is likely caused by a bug in React. Please file an issue." + ); +} +var nextReactTag = 3; +function allocateTag() { + var tag = nextReactTag; + 1 === tag % 10 && (tag += 2); + nextReactTag = tag + 2; + return tag; +} +function recursivelyUncacheFiberNode(node) { + "number" === typeof node + ? uncacheFiberNode(node) + : (uncacheFiberNode(node._nativeTag), + node._children.forEach(recursivelyUncacheFiberNode)); +} +function finalizeInitialChildren(parentInstance) { + if (0 === parentInstance._children.length) return !1; + var nativeTags = parentInstance._children.map(function(child) { + return "number" === typeof child ? child : child._nativeTag; + }); + UIManager.setChildren(parentInstance._nativeTag, nativeTags); + return !1; +} +function getStackAddendumByWorkInProgressFiber(workInProgress) { var info = ""; do { a: switch (workInProgress.tag) { @@ -1518,20 +1692,325 @@ function getStackAddendumByWorkInProgressFiber(workInProgress) { } while (workInProgress); return info; } -function createProfilerTimer() { - return { - checkActualRenderTimeStackEmpty: function() {}, - markActualRenderTimeStarted: function() {}, - pauseActualRenderTimerIfRunning: function() {}, - recordElapsedActualRenderTime: function() {}, - resetActualRenderTimer: function() {}, - resumeActualRenderTimerIfPaused: function() {}, - recordElapsedBaseRenderTimeIfRunning: function() {}, - startBaseRenderTimer: function() {}, - stopBaseRenderTimerIfRunning: function() {} +new Set(); +var valueStack = [], + index = -1; +function createCursor(defaultValue) { + return { current: defaultValue }; +} +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; +} +var contextStackCursor = createCursor(emptyObject), + didPerformWorkStackCursor = createCursor(!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 popTopLevelContextObject(fiber) { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} +function pushTopLevelContextObject(fiber, context, didChange) { + invariant( + contextStackCursor.current === emptyObject, + "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; + this.sibling = this.child = this.return = this.stateNode = this.type = null; + this.index = 0; + this.ref = null; + this.pendingProps = pendingProps; + this.memoizedState = this.updateQueue = this.memoizedProps = null; + this.mode = mode; + this.effectTag = 0; + this.lastEffect = this.firstEffect = this.nextEffect = null; + this.expirationTime = 0; + this.alternate = null; +} +function createWorkInProgress(current, pendingProps, expirationTime) { + var workInProgress = current.alternate; + null === workInProgress + ? ((workInProgress = new FiberNode( + current.tag, + pendingProps, + current.key, + current.mode + )), + (workInProgress.type = current.type), + (workInProgress.stateNode = current.stateNode), + (workInProgress.alternate = current), + (current.alternate = workInProgress)) + : ((workInProgress.pendingProps = pendingProps), + (workInProgress.effectTag = 0), + (workInProgress.nextEffect = null), + (workInProgress.firstEffect = null), + (workInProgress.lastEffect = null)); + workInProgress.expirationTime = expirationTime; + workInProgress.child = current.child; + workInProgress.memoizedProps = current.memoizedProps; + workInProgress.memoizedState = current.memoizedState; + workInProgress.updateQueue = current.updateQueue; + workInProgress.sibling = current.sibling; + workInProgress.index = current.index; + workInProgress.ref = current.ref; + return workInProgress; +} +function createFiberFromElement(element, mode, expirationTime) { + var type = element.type, + key = element.key; + element = element.props; + if ("function" === typeof type) + var fiberTag = type.prototype && type.prototype.isReactComponent ? 2 : 0; + else if ("string" === typeof type) fiberTag = 5; + else + switch (type) { + case REACT_FRAGMENT_TYPE: + return createFiberFromFragment( + element.children, + mode, + expirationTime, + key + ); + case REACT_ASYNC_MODE_TYPE: + fiberTag = 11; + mode |= 3; + break; + case REACT_STRICT_MODE_TYPE: + fiberTag = 11; + mode |= 2; + break; + case REACT_PROFILER_TYPE: + return ( + (type = new FiberNode(15, element, key, mode | 4)), + (type.type = REACT_PROFILER_TYPE), + (type.expirationTime = expirationTime), + type + ); + case REACT_TIMEOUT_TYPE: + fiberTag = 16; + mode |= 2; + break; + default: + a: { + switch ("object" === typeof type && null !== type + ? type.$$typeof + : null) { + case REACT_PROVIDER_TYPE: + fiberTag = 13; + break a; + case REACT_CONTEXT_TYPE: + fiberTag = 12; + break a; + case REACT_FORWARD_REF_TYPE: + fiberTag = 14; + break a; + default: + invariant( + !1, + "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", + null == type ? type : typeof type, + "" + ); + } + fiberTag = void 0; + } + } + mode = new FiberNode(fiberTag, element, key, mode); + mode.type = type; + mode.expirationTime = expirationTime; + return mode; +} +function createFiberFromFragment(elements, mode, expirationTime, key) { + elements = new FiberNode(10, elements, key, mode); + elements.expirationTime = expirationTime; + return elements; +} +function createFiberFromText(content, mode, expirationTime) { + content = new FiberNode(6, content, null, mode); + content.expirationTime = expirationTime; + return content; +} +function createFiberFromPortal(portal, mode, expirationTime) { + mode = new FiberNode( + 4, + null !== portal.children ? portal.children : [], + portal.key, + mode + ); + mode.expirationTime = expirationTime; + mode.stateNode = { + containerInfo: portal.containerInfo, + pendingChildren: null, + implementation: portal.implementation }; + return mode; +} +function createFiberRoot(containerInfo, isAsync, hydrate) { + isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0); + containerInfo = { + current: isAsync, + containerInfo: containerInfo, + pendingChildren: null, + earliestPendingTime: 0, + latestPendingTime: 0, + earliestSuspendedTime: 0, + latestSuspendedTime: 0, + latestPingedTime: 0, + didError: !1, + pendingCommitExpirationTime: 0, + finishedWork: null, + context: null, + pendingContext: null, + hydrate: hydrate, + nextExpirationTimeToWorkOn: 0, + expirationTime: 0, + firstBatch: null, + nextScheduledRoot: null + }; + return (isAsync.stateNode = containerInfo); +} +var onCommitFiberRoot = null, + onCommitFiberUnmount = null; +function catchErrors(fn) { + return function(arg) { + try { + return fn(arg); + } catch (err) {} + }; +} +function injectInternals(internals) { + if ("undefined" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) return !1; + var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__; + if (hook.isDisabled || !hook.supportsFiber) return !0; + try { + var rendererID = hook.inject(internals); + onCommitFiberRoot = catchErrors(function(root) { + return hook.onCommitFiberRoot(rendererID, root); + }); + onCommitFiberUnmount = catchErrors(function(fiber) { + return hook.onCommitFiberUnmount(rendererID, fiber); + }); + } catch (err) {} + return !0; +} +function onCommitRoot(root) { + "function" === typeof onCommitFiberRoot && onCommitFiberRoot(root); +} +function onCommitUnmount(fiber) { + "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(fiber); +} +function markPendingPriorityLevel(root, expirationTime) { + root.didError = !1; + var earliestPendingTime = root.earliestPendingTime; + 0 === earliestPendingTime + ? (root.earliestPendingTime = root.latestPendingTime = expirationTime) + : earliestPendingTime > expirationTime + ? (root.earliestPendingTime = expirationTime) + : root.latestPendingTime < expirationTime && + (root.latestPendingTime = expirationTime); + findNextPendingPriorityLevel(root); +} +function findNextPendingPriorityLevel(root) { + var earliestSuspendedTime = root.earliestSuspendedTime, + earliestPendingTime = root.earliestPendingTime; + if (0 === earliestSuspendedTime) + var nextExpirationTimeToWorkOn = (earliestSuspendedTime = earliestPendingTime); + else + 0 !== earliestPendingTime + ? ((nextExpirationTimeToWorkOn = earliestPendingTime), + (earliestSuspendedTime = + earliestSuspendedTime < earliestPendingTime + ? earliestSuspendedTime + : earliestPendingTime)) + : (nextExpirationTimeToWorkOn = earliestSuspendedTime = + root.latestPingedTime); + root.didError && (earliestSuspendedTime = 1); + root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn; + root.expirationTime = earliestSuspendedTime; } -new Set(); var hasForceUpdate = !1; function createUpdateQueue(baseState) { return { @@ -1784,10 +2263,89 @@ function commitUpdateQueue(finishedWork, finishedQueue, instance) { null !== finishedWork; ) - (finishedQueue = finishedWork.callback), - null !== finishedQueue && - ((finishedWork.callback = null), callCallback(finishedQueue, instance)), - (finishedWork = finishedWork.nextEffect); + (finishedQueue = finishedWork.callback), + null !== finishedQueue && + ((finishedWork.callback = null), callCallback(finishedQueue, instance)), + (finishedWork = finishedWork.nextEffect); +} +function createCapturedValue(value, source) { + return { + value: value, + source: source, + stack: getStackAddendumByWorkInProgressFiber(source) + }; +} +var providerCursor = createCursor(null), + valueCursor = createCursor(null), + changedBitsCursor = createCursor(0); +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; +} +function popProvider(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; +} +var NO_CONTEXT = {}, + contextStackCursor$1 = createCursor(NO_CONTEXT), + contextFiberStackCursor = createCursor(NO_CONTEXT), + rootInstanceStackCursor = createCursor(NO_CONTEXT); +function requiredContext(c) { + invariant( + c !== NO_CONTEXT, + "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." + ); + return c; +} +function pushHostContainer(fiber, nextRootInstance) { + push(rootInstanceStackCursor, nextRootInstance, fiber); + push(contextFiberStackCursor, fiber, fiber); + push(contextStackCursor$1, NO_CONTEXT, fiber); + pop(contextStackCursor$1, fiber); + push(contextStackCursor$1, { isInAParentText: !1 }, fiber); +} +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} +function popHostContext(fiber) { + contextFiberStackCursor.current === fiber && + (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); +} +var hasOwnProperty = Object.prototype.hasOwnProperty; +function is(x, y) { + return x === y ? 0 !== x || 0 !== y || 1 / x === 1 / y : x !== x && y !== y; +} +function shallowEqual(objA, objB) { + if (is(objA, objB)) return !0; + if ( + "object" !== typeof objA || + null === objA || + "object" !== typeof objB || + null === objB + ) + return !1; + var keysA = Object.keys(objA), + keysB = Object.keys(objB); + if (keysA.length !== keysB.length) return !1; + for (keysB = 0; keysB < keysA.length; keysB++) + if ( + !hasOwnProperty.call(objB, keysA[keysB]) || + !is(objA[keysA[keysB]], objB[keysA[keysB]]) + ) + return !1; + return !0; } function applyDerivedStateFromProps( workInProgress, @@ -1806,351 +2364,120 @@ function applyDerivedStateFromProps( 0 === workInProgress.expirationTime && (workInProgress.baseState = prevState); } -function ReactFiberClassComponent( - legacyContext, - scheduleWork, - computeExpirationForFiber, - memoizeProps, - memoizeState, - recalculateCurrentTime -) { - function checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - newState, - newContext - ) { - var instance = workInProgress.stateNode; - workInProgress = workInProgress.type; - return "function" === typeof instance.shouldComponentUpdate - ? instance.shouldComponentUpdate(newProps, newState, newContext) - : workInProgress.prototype && - workInProgress.prototype.isPureReactComponent - ? !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) - : !0; - } - function adoptClassInstance(workInProgress, instance) { - instance.updater = classComponentUpdater; - workInProgress.stateNode = instance; - instance._reactInternalFiber = workInProgress; - } - function callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newContext - ) { - workInProgress = instance.state; - "function" === typeof instance.componentWillReceiveProps && - instance.componentWillReceiveProps(newProps, newContext); - "function" === typeof instance.UNSAFE_componentWillReceiveProps && - instance.UNSAFE_componentWillReceiveProps(newProps, newContext); - instance.state !== workInProgress && - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); +var classComponentUpdater = { + isMounted: function(component) { + return (component = component._reactInternalFiber) + ? 2 === isFiberMountedImpl(component) + : !1; + }, + enqueueSetState: function(inst, payload, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.payload = payload; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + }, + enqueueReplaceState: function(inst, payload, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.tag = 1; + update.payload = payload; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + }, + enqueueForceUpdate: function(inst, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.tag = 2; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); } - var cacheContext = legacyContext.cacheContext, - getMaskedContext = legacyContext.getMaskedContext, - getUnmaskedContext = legacyContext.getUnmaskedContext, - isContextConsumer = legacyContext.isContextConsumer, - hasContextChanged = legacyContext.hasContextChanged, - classComponentUpdater = { - isMounted: isMounted, - enqueueSetState: function(inst, payload, callback) { - inst = inst._reactInternalFiber; - var currentTime = recalculateCurrentTime(); - currentTime = computeExpirationForFiber(currentTime, inst); - var update = createUpdate(currentTime); - update.payload = payload; - void 0 !== callback && - null !== callback && - (update.callback = callback); - enqueueUpdate(inst, update, currentTime); - scheduleWork(inst, currentTime); - }, - enqueueReplaceState: function(inst, payload, callback) { - inst = inst._reactInternalFiber; - var currentTime = recalculateCurrentTime(); - currentTime = computeExpirationForFiber(currentTime, inst); - var update = createUpdate(currentTime); - update.tag = 1; - update.payload = payload; - void 0 !== callback && - null !== callback && - (update.callback = callback); - enqueueUpdate(inst, update, currentTime); - scheduleWork(inst, currentTime); - }, - enqueueForceUpdate: function(inst, callback) { - inst = inst._reactInternalFiber; - var currentTime = recalculateCurrentTime(); - currentTime = computeExpirationForFiber(currentTime, inst); - var update = createUpdate(currentTime); - update.tag = 2; - void 0 !== callback && - null !== callback && - (update.callback = callback); - enqueueUpdate(inst, update, currentTime); - scheduleWork(inst, currentTime); - } - }; - return { - adoptClassInstance: adoptClassInstance, - constructClassInstance: function(workInProgress, props) { - var ctor = workInProgress.type, - unmaskedContext = getUnmaskedContext(workInProgress), - needsContext = isContextConsumer(workInProgress), - context = needsContext - ? getMaskedContext(workInProgress, unmaskedContext) - : emptyObject; - props = new ctor(props, context); - workInProgress.memoizedState = - null !== props.state && void 0 !== props.state ? props.state : null; - adoptClassInstance(workInProgress, props); - needsContext && cacheContext(workInProgress, unmaskedContext, context); - return props; - }, - mountClassInstance: function(workInProgress, renderExpirationTime) { - var ctor = workInProgress.type, - instance = workInProgress.stateNode, - props = workInProgress.pendingProps, - unmaskedContext = getUnmaskedContext(workInProgress); - instance.props = props; - instance.state = workInProgress.memoizedState; - instance.refs = emptyObject; - instance.context = getMaskedContext(workInProgress, unmaskedContext); - unmaskedContext = workInProgress.updateQueue; - null !== unmaskedContext && - (processUpdateQueue( - workInProgress, - unmaskedContext, - props, - instance, - renderExpirationTime - ), - (instance.state = workInProgress.memoizedState)); - unmaskedContext = workInProgress.type.getDerivedStateFromProps; - "function" === typeof unmaskedContext && - (applyDerivedStateFromProps(workInProgress, unmaskedContext, props), - (instance.state = workInProgress.memoizedState)); - "function" === typeof ctor.getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate || - ("function" !== typeof instance.UNSAFE_componentWillMount && - "function" !== typeof instance.componentWillMount) || - ((ctor = instance.state), - "function" === typeof instance.componentWillMount && - instance.componentWillMount(), - "function" === typeof instance.UNSAFE_componentWillMount && - instance.UNSAFE_componentWillMount(), - ctor !== instance.state && - classComponentUpdater.enqueueReplaceState( - instance, - instance.state, - null - ), - (unmaskedContext = workInProgress.updateQueue), - null !== unmaskedContext && - (processUpdateQueue( - workInProgress, - unmaskedContext, - props, - instance, - renderExpirationTime - ), - (instance.state = workInProgress.memoizedState))); - "function" === typeof instance.componentDidMount && - (workInProgress.effectTag |= 4); - }, - resumeMountClassInstance: function(workInProgress, renderExpirationTime) { - var ctor = workInProgress.type, - instance = workInProgress.stateNode, - oldProps = workInProgress.memoizedProps, - newProps = workInProgress.pendingProps; - instance.props = oldProps; - var oldContext = instance.context, - newUnmaskedContext = getUnmaskedContext(workInProgress); - newUnmaskedContext = getMaskedContext(workInProgress, newUnmaskedContext); - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - (ctor = - "function" === typeof getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate) || - ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && - "function" !== typeof instance.componentWillReceiveProps) || - ((oldProps !== newProps || oldContext !== newUnmaskedContext) && - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newUnmaskedContext - )); - hasForceUpdate = !1; - var oldState = workInProgress.memoizedState; - oldContext = instance.state = oldState; - var updateQueue = workInProgress.updateQueue; - null !== updateQueue && - (processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime - ), - (oldContext = workInProgress.memoizedState)); - if ( - oldProps === newProps && - oldState === oldContext && - !hasContextChanged() && - !hasForceUpdate - ) - return ( - "function" === typeof instance.componentDidMount && - (workInProgress.effectTag |= 4), - !1 - ); - "function" === typeof getDerivedStateFromProps && - (applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - newProps - ), - (oldContext = workInProgress.memoizedState)); - (renderExpirationTime = - hasForceUpdate || - checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldState, - oldContext, - 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 && - (workInProgress.effectTag |= 4)) - : ("function" === typeof instance.componentDidMount && - (workInProgress.effectTag |= 4), - (workInProgress.memoizedProps = newProps), - (workInProgress.memoizedState = oldContext)); - instance.props = newProps; - instance.state = oldContext; - instance.context = newUnmaskedContext; - return renderExpirationTime; - }, - updateClassInstance: function( - current, +}; +function checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext +) { + var instance = workInProgress.stateNode; + workInProgress = workInProgress.type; + return "function" === typeof instance.shouldComponentUpdate + ? instance.shouldComponentUpdate(newProps, newState, newContext) + : workInProgress.prototype && workInProgress.prototype.isPureReactComponent + ? !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) + : !0; +} +function callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext +) { + workInProgress = instance.state; + "function" === typeof instance.componentWillReceiveProps && + instance.componentWillReceiveProps(newProps, newContext); + "function" === typeof instance.UNSAFE_componentWillReceiveProps && + instance.UNSAFE_componentWillReceiveProps(newProps, newContext); + instance.state !== workInProgress && + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); +} +function mountClassInstance(workInProgress, renderExpirationTime) { + var ctor = workInProgress.type, + instance = workInProgress.stateNode, + props = workInProgress.pendingProps, + unmaskedContext = getUnmaskedContext(workInProgress); + instance.props = props; + instance.state = workInProgress.memoizedState; + instance.refs = emptyObject; + instance.context = getMaskedContext(workInProgress, unmaskedContext); + unmaskedContext = workInProgress.updateQueue; + null !== unmaskedContext && + (processUpdateQueue( workInProgress, + unmaskedContext, + props, + instance, renderExpirationTime - ) { - var ctor = workInProgress.type, - instance = workInProgress.stateNode, - oldProps = workInProgress.memoizedProps, - newProps = workInProgress.pendingProps; - instance.props = oldProps; - var oldContext = instance.context, - newUnmaskedContext = getUnmaskedContext(workInProgress); - newUnmaskedContext = getMaskedContext(workInProgress, newUnmaskedContext); - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - (ctor = - "function" === typeof getDerivedStateFromProps || - "function" === typeof instance.getSnapshotBeforeUpdate) || - ("function" !== typeof instance.UNSAFE_componentWillReceiveProps && - "function" !== typeof instance.componentWillReceiveProps) || - ((oldProps !== newProps || oldContext !== newUnmaskedContext) && - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - newUnmaskedContext - )); - hasForceUpdate = !1; - oldContext = workInProgress.memoizedState; - var newState = (instance.state = oldContext), - updateQueue = workInProgress.updateQueue; - null !== updateQueue && - (processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime - ), - (newState = workInProgress.memoizedState)); - if ( - oldProps === newProps && - oldContext === newState && - !hasContextChanged() && - !hasForceUpdate - ) - return ( - "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 |= 256), - !1 - ); - "function" === typeof getDerivedStateFromProps && - (applyDerivedStateFromProps( - workInProgress, - getDerivedStateFromProps, - newProps - ), - (newState = workInProgress.memoizedState)); - (renderExpirationTime = - hasForceUpdate || - checkShouldComponentUpdate( - workInProgress, - oldProps, - newProps, - oldContext, - newState, - newUnmaskedContext - )) - ? (ctor || - ("function" !== typeof instance.UNSAFE_componentWillUpdate && - "function" !== typeof instance.componentWillUpdate) || - ("function" === typeof instance.componentWillUpdate && - instance.componentWillUpdate( - newProps, - newState, - newUnmaskedContext - ), - "function" === typeof instance.UNSAFE_componentWillUpdate && - instance.UNSAFE_componentWillUpdate( - newProps, - newState, - newUnmaskedContext - )), - "function" === typeof instance.componentDidUpdate && - (workInProgress.effectTag |= 4), - "function" === typeof instance.getSnapshotBeforeUpdate && - (workInProgress.effectTag |= 256)) - : ("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 |= 256), - (workInProgress.memoizedProps = newProps), - (workInProgress.memoizedState = newState)); - instance.props = newProps; - instance.state = newState; - instance.context = newUnmaskedContext; - return renderExpirationTime; - } - }; + ), + (instance.state = workInProgress.memoizedState)); + unmaskedContext = workInProgress.type.getDerivedStateFromProps; + "function" === typeof unmaskedContext && + (applyDerivedStateFromProps(workInProgress, unmaskedContext, props), + (instance.state = workInProgress.memoizedState)); + "function" === typeof ctor.getDerivedStateFromProps || + "function" === typeof instance.getSnapshotBeforeUpdate || + ("function" !== typeof instance.UNSAFE_componentWillMount && + "function" !== typeof instance.componentWillMount) || + ((ctor = instance.state), + "function" === typeof instance.componentWillMount && + instance.componentWillMount(), + "function" === typeof instance.UNSAFE_componentWillMount && + instance.UNSAFE_componentWillMount(), + ctor !== instance.state && + classComponentUpdater.enqueueReplaceState(instance, instance.state, null), + (unmaskedContext = workInProgress.updateQueue), + null !== unmaskedContext && + (processUpdateQueue( + workInProgress, + unmaskedContext, + props, + instance, + renderExpirationTime + ), + (instance.state = workInProgress.memoizedState))); + "function" === typeof instance.componentDidMount && + (workInProgress.effectTag |= 4); } var isArray$1 = Array.isArray; function coerceRef(returnFiber, current, element) { @@ -2178,6 +2505,7 @@ function coerceRef(returnFiber, current, element) { if ( null !== current && null !== current.ref && + "function" === typeof current.ref && current.ref._stringRef === stringRef ) return current.ref; @@ -2673,27 +3001,35 @@ function ChildReconciler(shouldTrackSideEffects) { return iteratorFn; } return function(returnFiber, currentFirstChild, newChild, expirationTime) { - "object" === typeof newChild && + var isUnkeyedTopLevelFragment = + "object" === typeof newChild && null !== newChild && newChild.type === REACT_FRAGMENT_TYPE && - null === newChild.key && - (newChild = newChild.props.children); + null === newChild.key; + isUnkeyedTopLevelFragment && (newChild = newChild.props.children); var isObject = "object" === typeof newChild && null !== newChild; if (isObject) switch (newChild.$$typeof) { case REACT_ELEMENT_TYPE: a: { - var key = newChild.key; - for (isObject = currentFirstChild; null !== isObject; ) { - if (isObject.key === key) + isObject = newChild.key; + for ( + isUnkeyedTopLevelFragment = currentFirstChild; + null !== isUnkeyedTopLevelFragment; + + ) { + if (isUnkeyedTopLevelFragment.key === isObject) if ( - 10 === isObject.tag + 10 === isUnkeyedTopLevelFragment.tag ? newChild.type === REACT_FRAGMENT_TYPE - : isObject.type === newChild.type + : isUnkeyedTopLevelFragment.type === newChild.type ) { - deleteRemainingChildren(returnFiber, isObject.sibling); + deleteRemainingChildren( + returnFiber, + isUnkeyedTopLevelFragment.sibling + ); currentFirstChild = useFiber( - isObject, + isUnkeyedTopLevelFragment, newChild.type === REACT_FRAGMENT_TYPE ? newChild.props.children : newChild.props, @@ -2701,18 +3037,21 @@ function ChildReconciler(shouldTrackSideEffects) { ); currentFirstChild.ref = coerceRef( returnFiber, - isObject, + isUnkeyedTopLevelFragment, newChild ); currentFirstChild.return = returnFiber; returnFiber = currentFirstChild; break a; } else { - deleteRemainingChildren(returnFiber, isObject); + deleteRemainingChildren( + returnFiber, + isUnkeyedTopLevelFragment + ); break; } - else deleteChild(returnFiber, isObject); - isObject = isObject.sibling; + else deleteChild(returnFiber, isUnkeyedTopLevelFragment); + isUnkeyedTopLevelFragment = isUnkeyedTopLevelFragment.sibling; } newChild.type === REACT_FRAGMENT_TYPE ? ((currentFirstChild = createFiberFromFragment( @@ -2739,8 +3078,12 @@ function ChildReconciler(shouldTrackSideEffects) { return placeSingleChild(returnFiber); case REACT_PORTAL_TYPE: a: { - for (isObject = newChild.key; null !== currentFirstChild; ) { - if (currentFirstChild.key === isObject) + for ( + isUnkeyedTopLevelFragment = newChild.key; + null !== currentFirstChild; + + ) { + if (currentFirstChild.key === isUnkeyedTopLevelFragment) if ( 4 === currentFirstChild.tag && currentFirstChild.stateNode.containerInfo === @@ -2814,7 +3157,7 @@ function ChildReconciler(shouldTrackSideEffects) { expirationTime ); isObject && throwOnInvalidObjectType(returnFiber, newChild); - if ("undefined" === typeof newChild) + if ("undefined" === typeof newChild && !isUnkeyedTopLevelFragment) switch (returnFiber.tag) { case 2: case 1: @@ -2829,184 +3172,234 @@ function ChildReconciler(shouldTrackSideEffects) { }; } var reconcileChildFibers = ChildReconciler(!0), - mountChildFibers = ChildReconciler(!1); -function ReactFiberBeginWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext, - scheduleWork, - computeExpirationForFiber, - profilerTimer, - recalculateCurrentTime -) { - function reconcileChildren(current, workInProgress, nextChildren) { - reconcileChildrenAtExpirationTime( - current, - workInProgress, - nextChildren, - workInProgress.expirationTime - ); - } - function reconcileChildrenAtExpirationTime( - current, - workInProgress, - nextChildren, - renderExpirationTime - ) { - workInProgress.child = - null === current - ? mountChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime - ) - : reconcileChildFibers( - workInProgress, - current.child, - nextChildren, - renderExpirationTime - ); + mountChildFibers = ChildReconciler(!1), + hydrationParentFiber = null, + nextHydratableInstance = null, + isHydrating = !1; +function tryHydrate(fiber, nextInstance) { + switch (fiber.tag) { + case 5: + return ( + (nextInstance = shim$1(nextInstance, fiber.type, fiber.pendingProps)), + null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 + ); + case 6: + return ( + (nextInstance = shim$1(nextInstance, fiber.pendingProps)), + null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 + ); + default: + return !1; } - function markRef(current, workInProgress) { - var ref = workInProgress.ref; - if ( - (null === current && null !== ref) || - (null !== current && current.ref !== ref) - ) - workInProgress.effectTag |= 128; +} +function tryToClaimNextHydratableInstance(fiber$jscomp$0) { + if (isHydrating) { + var nextInstance = nextHydratableInstance; + if (nextInstance) { + var firstAttemptedInstance = nextInstance; + if (!tryHydrate(fiber$jscomp$0, nextInstance)) { + nextInstance = shim$1(firstAttemptedInstance); + if (!nextInstance || !tryHydrate(fiber$jscomp$0, nextInstance)) { + fiber$jscomp$0.effectTag |= 2; + isHydrating = !1; + hydrationParentFiber = fiber$jscomp$0; + return; + } + var returnFiber = hydrationParentFiber, + fiber = new FiberNode(5, null, null, 0); + fiber.type = "DELETED"; + fiber.stateNode = firstAttemptedInstance; + fiber.return = returnFiber; + fiber.effectTag = 8; + null !== returnFiber.lastEffect + ? ((returnFiber.lastEffect.nextEffect = fiber), + (returnFiber.lastEffect = fiber)) + : (returnFiber.firstEffect = returnFiber.lastEffect = fiber); + } + hydrationParentFiber = fiber$jscomp$0; + nextHydratableInstance = shim$1(nextInstance); + } else + (fiber$jscomp$0.effectTag |= 2), + (isHydrating = !1), + (hydrationParentFiber = fiber$jscomp$0); } - function finishClassComponent( +} +function reconcileChildren(current, workInProgress, nextChildren) { + reconcileChildrenAtExpirationTime( current, workInProgress, - shouldUpdate, - hasContext, - renderExpirationTime - ) { - markRef(current, workInProgress); - var didCaptureError = 0 !== (workInProgress.effectTag & 64); - if (!shouldUpdate && !didCaptureError) - return ( - hasContext && invalidateContextProvider(workInProgress, !1), - bailoutOnAlreadyFinishedWork(current, workInProgress) - ); - shouldUpdate = workInProgress.stateNode; - ReactCurrentOwner.current = workInProgress; - var nextChildren = didCaptureError ? null : shouldUpdate.render(); - workInProgress.effectTag |= 1; - didCaptureError && - (reconcileChildrenAtExpirationTime( - current, - workInProgress, - null, - renderExpirationTime - ), - (workInProgress.child = null)); - reconcileChildrenAtExpirationTime( + nextChildren, + workInProgress.expirationTime + ); +} +function reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime +) { + workInProgress.child = + null === current + ? mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ) + : reconcileChildFibers( + workInProgress, + current.child, + nextChildren, + renderExpirationTime + ); +} +function markRef(current, workInProgress) { + var ref = workInProgress.ref; + if ( + (null === current && null !== ref) || + (null !== current && current.ref !== ref) + ) + workInProgress.effectTag |= 128; +} +function finishClassComponent( + current, + workInProgress, + shouldUpdate, + hasContext, + renderExpirationTime +) { + markRef(current, workInProgress); + var didCaptureError = 0 !== (workInProgress.effectTag & 64); + if (!shouldUpdate && !didCaptureError) + return ( + hasContext && invalidateContextProvider(workInProgress, !1), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + shouldUpdate = workInProgress.stateNode; + ReactCurrentOwner.current = workInProgress; + var nextChildren = didCaptureError ? null : shouldUpdate.render(); + workInProgress.effectTag |= 1; + didCaptureError && + (reconcileChildrenAtExpirationTime( current, workInProgress, - nextChildren, + null, renderExpirationTime - ); - workInProgress.memoizedState = shouldUpdate.state; - workInProgress.memoizedProps = shouldUpdate.props; - hasContext && invalidateContextProvider(workInProgress, !0); - return workInProgress.child; - } - function pushHostRootContext(workInProgress) { - var root = workInProgress.stateNode; - root.pendingContext - ? pushTopLevelContextObject( - workInProgress, - root.pendingContext, - root.pendingContext !== root.context - ) - : root.context && - pushTopLevelContextObject(workInProgress, root.context, !1); - pushHostContainer(workInProgress, root.containerInfo); - } - function propagateContextChange( + ), + (workInProgress.child = null)); + reconcileChildrenAtExpirationTime( + current, workInProgress, - context, - changedBits, + nextChildren, renderExpirationTime - ) { - var fiber = workInProgress.child; - null !== fiber && (fiber.return = workInProgress); - for (; null !== fiber; ) { - switch (fiber.tag) { - case 12: - var nextFiber = fiber.stateNode | 0; - if (fiber.type === context && 0 !== (nextFiber & changedBits)) { - for (nextFiber = fiber; null !== nextFiber; ) { - var alternate = nextFiber.alternate; - if ( - 0 === nextFiber.expirationTime || - nextFiber.expirationTime > renderExpirationTime - ) - (nextFiber.expirationTime = renderExpirationTime), - null !== alternate && - (0 === alternate.expirationTime || - alternate.expirationTime > renderExpirationTime) && - (alternate.expirationTime = renderExpirationTime); - else if ( + ); + workInProgress.memoizedState = shouldUpdate.state; + workInProgress.memoizedProps = shouldUpdate.props; + hasContext && invalidateContextProvider(workInProgress, !0); + return workInProgress.child; +} +function pushHostRootContext(workInProgress) { + var root = workInProgress.stateNode; + root.pendingContext + ? pushTopLevelContextObject( + workInProgress, + root.pendingContext, + root.pendingContext !== root.context + ) + : root.context && + pushTopLevelContextObject(workInProgress, root.context, !1); + pushHostContainer(workInProgress, root.containerInfo); +} +function propagateContextChange( + workInProgress, + context, + changedBits, + renderExpirationTime +) { + var fiber = workInProgress.child; + null !== fiber && (fiber.return = workInProgress); + for (; null !== fiber; ) { + switch (fiber.tag) { + case 12: + var nextFiber = fiber.stateNode | 0; + if (fiber.type === context && 0 !== (nextFiber & changedBits)) { + for (nextFiber = fiber; null !== nextFiber; ) { + var alternate = nextFiber.alternate; + if ( + 0 === nextFiber.expirationTime || + nextFiber.expirationTime > renderExpirationTime + ) + (nextFiber.expirationTime = renderExpirationTime), null !== alternate && - (0 === alternate.expirationTime || - alternate.expirationTime > renderExpirationTime) - ) - alternate.expirationTime = renderExpirationTime; - else break; - nextFiber = nextFiber.return; - } - nextFiber = null; - } else nextFiber = fiber.child; + (0 === alternate.expirationTime || + alternate.expirationTime > renderExpirationTime) && + (alternate.expirationTime = renderExpirationTime); + else if ( + null !== alternate && + (0 === alternate.expirationTime || + alternate.expirationTime > renderExpirationTime) + ) + alternate.expirationTime = renderExpirationTime; + else break; + nextFiber = nextFiber.return; + } + nextFiber = null; + } else nextFiber = fiber.child; + break; + case 13: + nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + break; + default: + nextFiber = fiber.child; + } + if (null !== nextFiber) nextFiber.return = fiber; + else + for (nextFiber = fiber; null !== nextFiber; ) { + if (nextFiber === workInProgress) { + nextFiber = null; break; - case 13: - nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + } + fiber = nextFiber.sibling; + if (null !== fiber) { + fiber.return = nextFiber.return; + nextFiber = fiber; break; - default: - nextFiber = fiber.child; - } - if (null !== nextFiber) nextFiber.return = fiber; - else - for (nextFiber = fiber; null !== nextFiber; ) { - if (nextFiber === workInProgress) { - nextFiber = null; - break; - } - fiber = nextFiber.sibling; - if (null !== fiber) { - fiber.return = nextFiber.return; - nextFiber = fiber; - break; - } - nextFiber = nextFiber.return; } - fiber = nextFiber; - } + nextFiber = nextFiber.return; + } + fiber = nextFiber; } - function updateContextProvider( - current, - workInProgress, - renderExpirationTime - ) { - var context = workInProgress.type._context, - newProps = workInProgress.pendingProps, - oldProps = workInProgress.memoizedProps, - canBailOnProps = !0; - if (hasLegacyContextChanged()) canBailOnProps = !1; - else if (oldProps === newProps) +} +function updateContextProvider(current, workInProgress, renderExpirationTime) { + var context = workInProgress.type._context, + newProps = workInProgress.pendingProps, + oldProps = workInProgress.memoizedProps, + canBailOnProps = !0; + if (didPerformWorkStackCursor.current) canBailOnProps = !1; + else if (oldProps === newProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + var newValue = newProps.value; + workInProgress.memoizedProps = newProps; + if (null === oldProps) newValue = 1073741823; + else if (oldProps.value === newProps.value) { + if (oldProps.children === newProps.children && canBailOnProps) return ( (workInProgress.stateNode = 0), pushProvider(workInProgress), bailoutOnAlreadyFinishedWork(current, workInProgress) ); - var newValue = newProps.value; - workInProgress.memoizedProps = newProps; - if (null === oldProps) newValue = 1073741823; - else if (oldProps.value === newProps.value) { + newValue = 0; + } else { + var oldValue = oldProps.value; + if ( + (oldValue === newValue && + (0 !== oldValue || 1 / oldValue === 1 / newValue)) || + (oldValue !== oldValue && newValue !== newValue) + ) { if (oldProps.children === newProps.children && canBailOnProps) return ( (workInProgress.stateNode = 0), @@ -3014,684 +3407,710 @@ function ReactFiberBeginWork( bailoutOnAlreadyFinishedWork(current, workInProgress) ); newValue = 0; - } else { - var oldValue = oldProps.value; - if ( - (oldValue === newValue && - (0 !== oldValue || 1 / oldValue === 1 / newValue)) || - (oldValue !== oldValue && newValue !== newValue) - ) { - if (oldProps.children === newProps.children && canBailOnProps) - return ( - (workInProgress.stateNode = 0), - pushProvider(workInProgress), - bailoutOnAlreadyFinishedWork(current, workInProgress) - ); - newValue = 0; - } else if ( - ((newValue = - "function" === typeof context._calculateChangedBits - ? context._calculateChangedBits(oldValue, newValue) - : 1073741823), - (newValue |= 0), - 0 === newValue) - ) { - if (oldProps.children === newProps.children && canBailOnProps) - return ( - (workInProgress.stateNode = 0), - pushProvider(workInProgress), - bailoutOnAlreadyFinishedWork(current, workInProgress) - ); - } else - propagateContextChange( + } else if ( + ((newValue = + "function" === typeof context._calculateChangedBits + ? context._calculateChangedBits(oldValue, newValue) + : 1073741823), + (newValue |= 0), + 0 === newValue) + ) { + if (oldProps.children === newProps.children && canBailOnProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + } else + propagateContextChange( + workInProgress, + context, + newValue, + renderExpirationTime + ); + } + workInProgress.stateNode = newValue; + pushProvider(workInProgress); + reconcileChildren(current, workInProgress, newProps.children); + return workInProgress.child; +} +function bailoutOnAlreadyFinishedWork(current, workInProgress) { + invariant( + null === current || workInProgress.child === current.child, + "Resuming work not yet implemented." + ); + if (null !== workInProgress.child) { + current = workInProgress.child; + var newChild = createWorkInProgress( + current, + current.pendingProps, + current.expirationTime + ); + workInProgress.child = newChild; + for (newChild.return = workInProgress; null !== current.sibling; ) + (current = current.sibling), + (newChild = newChild.sibling = createWorkInProgress( + current, + current.pendingProps, + current.expirationTime + )), + (newChild.return = workInProgress); + newChild.sibling = null; + } + return workInProgress.child; +} +function beginWork(current, workInProgress, renderExpirationTime) { + if ( + 0 === workInProgress.expirationTime || + workInProgress.expirationTime > renderExpirationTime + ) { + switch (workInProgress.tag) { + case 3: + pushHostRootContext(workInProgress); + break; + case 2: + pushContextProvider(workInProgress); + break; + case 4: + pushHostContainer( workInProgress, - context, - newValue, - renderExpirationTime + workInProgress.stateNode.containerInfo ); + break; + case 13: + pushProvider(workInProgress); } - workInProgress.stateNode = newValue; - pushProvider(workInProgress); - reconcileChildren(current, workInProgress, newProps.children); - return workInProgress.child; + return null; } - function bailoutOnAlreadyFinishedWork(current, workInProgress) { - invariant( - null === current || workInProgress.child === current.child, - "Resuming work not yet implemented." - ); - if (null !== workInProgress.child) { - current = workInProgress.child; - var newChild = createWorkInProgress( - current, - current.pendingProps, - current.expirationTime + switch (workInProgress.tag) { + case 0: + invariant( + null === current, + "An indeterminate component should never have mounted. This error is likely caused by a bug in React. Please file an issue." ); - workInProgress.child = newChild; - for (newChild.return = workInProgress; null !== current.sibling; ) - (current = current.sibling), - (newChild = newChild.sibling = createWorkInProgress( + var fn = workInProgress.type, + props = workInProgress.pendingProps, + unmaskedContext = getUnmaskedContext(workInProgress); + unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + fn = fn(props, unmaskedContext); + workInProgress.effectTag |= 1; + "object" === typeof fn && + null !== fn && + "function" === typeof fn.render && + void 0 === fn.$$typeof + ? ((unmaskedContext = workInProgress.type), + (workInProgress.tag = 2), + (workInProgress.memoizedState = + null !== fn.state && void 0 !== fn.state ? fn.state : null), + (unmaskedContext = unmaskedContext.getDerivedStateFromProps), + "function" === typeof unmaskedContext && + applyDerivedStateFromProps(workInProgress, unmaskedContext, props), + (props = pushContextProvider(workInProgress)), + (fn.updater = classComponentUpdater), + (workInProgress.stateNode = fn), + (fn._reactInternalFiber = workInProgress), + mountClassInstance(workInProgress, renderExpirationTime), + (current = finishClassComponent( current, - current.pendingProps, - current.expirationTime - )), - (newChild.return = workInProgress); - newChild.sibling = null; - } - return workInProgress.child; - } - var shouldSetTextContent = config.shouldSetTextContent, - shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree, - pushHostContext = hostContext.pushHostContext, - pushHostContainer = hostContext.pushHostContainer, - pushProvider = newContext.pushProvider, - getContextCurrentValue = newContext.getContextCurrentValue, - getContextChangedBits = newContext.getContextChangedBits, - 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) { - workInProgress.memoizedProps = nextProps; - }, - function(workInProgress, nextState) { - workInProgress.memoizedState = nextState; - }, - recalculateCurrentTime - ); - var adoptClassInstance = config.adoptClassInstance, - constructClassInstance = config.constructClassInstance, - mountClassInstance = config.mountClassInstance, - resumeMountClassInstance = config.resumeMountClassInstance, - updateClassInstance = config.updateClassInstance; - return { - beginWork: function(current, workInProgress, renderExpirationTime) { - if ( - 0 === workInProgress.expirationTime || - workInProgress.expirationTime > renderExpirationTime - ) { - switch (workInProgress.tag) { - case 3: - pushHostRootContext(workInProgress); - break; - case 2: - pushLegacyContextProvider(workInProgress); - break; - case 4: - pushHostContainer( + workInProgress, + !0, + props, + renderExpirationTime + ))) + : ((workInProgress.tag = 1), + reconcileChildren(current, workInProgress, fn), + (workInProgress.memoizedProps = props), + (current = workInProgress.child)); + return current; + case 1: + return ( + (props = workInProgress.type), + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime + ? ((fn = getUnmaskedContext(workInProgress)), + (fn = getMaskedContext(workInProgress, fn)), + (props = props(renderExpirationTime, fn)), + (workInProgress.effectTag |= 1), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 2: + props = pushContextProvider(workInProgress); + if (null === current) + if (null === workInProgress.stateNode) { + var props$jscomp$0 = workInProgress.pendingProps, + ctor = workInProgress.type; + fn = getUnmaskedContext(workInProgress); + var needsContext = + 2 === workInProgress.tag && + null != workInProgress.type.contextTypes; + unmaskedContext = needsContext + ? getMaskedContext(workInProgress, fn) + : emptyObject; + props$jscomp$0 = new ctor(props$jscomp$0, unmaskedContext); + workInProgress.memoizedState = + null !== props$jscomp$0.state && void 0 !== props$jscomp$0.state + ? props$jscomp$0.state + : null; + props$jscomp$0.updater = classComponentUpdater; + workInProgress.stateNode = props$jscomp$0; + props$jscomp$0._reactInternalFiber = workInProgress; + needsContext && + ((needsContext = workInProgress.stateNode), + (needsContext.__reactInternalMemoizedUnmaskedChildContext = fn), + (needsContext.__reactInternalMemoizedMaskedChildContext = unmaskedContext)); + mountClassInstance(workInProgress, renderExpirationTime); + fn = !0; + } else { + ctor = workInProgress.type; + fn = workInProgress.stateNode; + needsContext = workInProgress.memoizedProps; + unmaskedContext = workInProgress.pendingProps; + fn.props = needsContext; + var oldContext = fn.context; + props$jscomp$0 = getUnmaskedContext(workInProgress); + props$jscomp$0 = getMaskedContext(workInProgress, props$jscomp$0); + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + (ctor = + "function" === typeof getDerivedStateFromProps || + "function" === typeof fn.getSnapshotBeforeUpdate) || + ("function" !== typeof fn.UNSAFE_componentWillReceiveProps && + "function" !== typeof fn.componentWillReceiveProps) || + ((needsContext !== unmaskedContext || + oldContext !== props$jscomp$0) && + callComponentWillReceiveProps( + workInProgress, + fn, + unmaskedContext, + props$jscomp$0 + )); + hasForceUpdate = !1; + var oldState = workInProgress.memoizedState; + oldContext = fn.state = oldState; + var updateQueue = workInProgress.updateQueue; + null !== updateQueue && + (processUpdateQueue( workInProgress, - workInProgress.stateNode.containerInfo - ); - break; - case 13: - pushProvider(workInProgress); - } - return null; - } - switch (workInProgress.tag) { - case 0: - invariant( - null === current, - "An indeterminate component should never have mounted. This error is likely caused by a bug in React. Please file an issue." - ); - var fn = workInProgress.type, - props = workInProgress.pendingProps, - unmaskedContext = getUnmaskedContext(workInProgress); - unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); - fn = fn(props, unmaskedContext); - workInProgress.effectTag |= 1; - "object" === typeof fn && - null !== fn && - "function" === typeof fn.render && - void 0 === fn.$$typeof - ? ((unmaskedContext = workInProgress.type), - (workInProgress.tag = 2), - (workInProgress.memoizedState = - null !== fn.state && void 0 !== fn.state ? fn.state : null), - (unmaskedContext = unmaskedContext.getDerivedStateFromProps), - "function" === typeof unmaskedContext && - applyDerivedStateFromProps( + updateQueue, + unmaskedContext, + fn, + renderExpirationTime + ), + (oldContext = workInProgress.memoizedState)); + needsContext !== unmaskedContext || + oldState !== oldContext || + didPerformWorkStackCursor.current || + hasForceUpdate + ? ("function" === typeof getDerivedStateFromProps && + (applyDerivedStateFromProps( workInProgress, - unmaskedContext, - props + getDerivedStateFromProps, + unmaskedContext ), - (props = pushLegacyContextProvider(workInProgress)), - adoptClassInstance(workInProgress, fn), - mountClassInstance(workInProgress, renderExpirationTime), - (current = finishClassComponent( - current, - workInProgress, - !0, - props, - renderExpirationTime - ))) - : ((workInProgress.tag = 1), - reconcileChildren(current, workInProgress, fn), - (workInProgress.memoizedProps = props), - (current = workInProgress.child)); - return current; - case 1: - return ( - (props = workInProgress.type), - (renderExpirationTime = workInProgress.pendingProps), - hasLegacyContextChanged() || - workInProgress.memoizedProps !== renderExpirationTime - ? ((fn = getUnmaskedContext(workInProgress)), - (fn = getMaskedContext(workInProgress, fn)), - (props = props(renderExpirationTime, fn)), - (workInProgress.effectTag |= 1), - reconcileChildren(current, workInProgress, props), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 2: - return ( - (props = pushLegacyContextProvider(workInProgress)), - null === current - ? null === workInProgress.stateNode - ? (constructClassInstance( - workInProgress, - workInProgress.pendingProps, - renderExpirationTime - ), - mountClassInstance(workInProgress, renderExpirationTime), - (fn = !0)) - : (fn = resumeMountClassInstance( - workInProgress, - renderExpirationTime - )) - : (fn = updateClassInstance( - current, + (oldContext = workInProgress.memoizedState)), + (needsContext = + hasForceUpdate || + checkShouldComponentUpdate( workInProgress, - renderExpirationTime - )), - finishClassComponent( - current, + needsContext, + unmaskedContext, + oldState, + oldContext, + props$jscomp$0 + )) + ? (ctor || + ("function" !== typeof fn.UNSAFE_componentWillMount && + "function" !== typeof fn.componentWillMount) || + ("function" === typeof fn.componentWillMount && + fn.componentWillMount(), + "function" === typeof fn.UNSAFE_componentWillMount && + fn.UNSAFE_componentWillMount()), + "function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4)) + : ("function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4), + (workInProgress.memoizedProps = unmaskedContext), + (workInProgress.memoizedState = oldContext)), + (fn.props = unmaskedContext), + (fn.state = oldContext), + (fn.context = props$jscomp$0), + (fn = needsContext)) + : ("function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4), + (fn = !1)); + } + else + (ctor = workInProgress.type), + (fn = workInProgress.stateNode), + (unmaskedContext = workInProgress.memoizedProps), + (needsContext = workInProgress.pendingProps), + (fn.props = unmaskedContext), + (oldContext = fn.context), + (props$jscomp$0 = getUnmaskedContext(workInProgress)), + (props$jscomp$0 = getMaskedContext(workInProgress, props$jscomp$0)), + (getDerivedStateFromProps = ctor.getDerivedStateFromProps), + (ctor = + "function" === typeof getDerivedStateFromProps || + "function" === typeof fn.getSnapshotBeforeUpdate) || + ("function" !== typeof fn.UNSAFE_componentWillReceiveProps && + "function" !== typeof fn.componentWillReceiveProps) || + ((unmaskedContext !== needsContext || + oldContext !== props$jscomp$0) && + callComponentWillReceiveProps( + workInProgress, + fn, + needsContext, + props$jscomp$0 + )), + (hasForceUpdate = !1), + (oldContext = workInProgress.memoizedState), + (oldState = fn.state = oldContext), + (updateQueue = workInProgress.updateQueue), + null !== updateQueue && + (processUpdateQueue( workInProgress, + updateQueue, + needsContext, fn, - props, renderExpirationTime - ) - ); - case 3: - return ( - pushHostRootContext(workInProgress), - (props = workInProgress.updateQueue), - null !== props - ? ((fn = workInProgress.memoizedState), - (fn = null !== fn ? fn.element : null), - processUpdateQueue( + ), + (oldState = workInProgress.memoizedState)), + unmaskedContext !== needsContext || + oldContext !== oldState || + didPerformWorkStackCursor.current || + hasForceUpdate + ? ("function" === typeof getDerivedStateFromProps && + (applyDerivedStateFromProps( workInProgress, - props, - workInProgress.pendingProps, - null, - renderExpirationTime + getDerivedStateFromProps, + needsContext ), - (props = workInProgress.memoizedState.element), - props === fn - ? (resetHydrationState(), - (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - ))) - : ((fn = workInProgress.stateNode), - (null === current || null === current.child) && - fn.hydrate && - enterHydrationState(workInProgress) - ? ((workInProgress.effectTag |= 2), - (workInProgress.child = mountChildFibers( - workInProgress, - null, - props, - renderExpirationTime - ))) - : (resetHydrationState(), - reconcileChildren(current, workInProgress, props)), - (current = workInProgress.child))) - : (resetHydrationState(), - (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - ))), - current - ); - case 5: - a: { - pushHostContext(workInProgress); - null === current && - tryToClaimNextHydratableInstance(workInProgress); - props = workInProgress.type; - var memoizedProps = workInProgress.memoizedProps; - fn = workInProgress.pendingProps; - unmaskedContext = null !== current ? current.memoizedProps : null; - if (!hasLegacyContextChanged() && memoizedProps === fn) { - if ( - (memoizedProps = - workInProgress.mode & 1 && - shouldDeprioritizeSubtree(props, fn)) - ) - workInProgress.expirationTime = 1073741823; - if (!memoizedProps || 1073741823 !== renderExpirationTime) { - current = bailoutOnAlreadyFinishedWork(current, workInProgress); - break a; - } - } - memoizedProps = fn.children; - shouldSetTextContent(props, fn) - ? (memoizedProps = null) - : unmaskedContext && - shouldSetTextContent(props, unmaskedContext) && - (workInProgress.effectTag |= 16); - markRef(current, workInProgress); - 1073741823 !== renderExpirationTime && - workInProgress.mode & 1 && - shouldDeprioritizeSubtree(props, fn) - ? ((workInProgress.expirationTime = 1073741823), - (workInProgress.memoizedProps = fn), - (current = null)) - : (reconcileChildren(current, workInProgress, memoizedProps), - (workInProgress.memoizedProps = fn), - (current = workInProgress.child)); - } - return current; - case 6: - return ( - null === current && - tryToClaimNextHydratableInstance(workInProgress), - (workInProgress.memoizedProps = workInProgress.pendingProps), - null - ); - case 16: - return null; - case 4: - return ( - pushHostContainer( + (oldState = workInProgress.memoizedState)), + (getDerivedStateFromProps = + hasForceUpdate || + checkShouldComponentUpdate( + workInProgress, + unmaskedContext, + needsContext, + oldContext, + oldState, + props$jscomp$0 + )) + ? (ctor || + ("function" !== typeof fn.UNSAFE_componentWillUpdate && + "function" !== typeof fn.componentWillUpdate) || + ("function" === typeof fn.componentWillUpdate && + fn.componentWillUpdate( + needsContext, + oldState, + props$jscomp$0 + ), + "function" === typeof fn.UNSAFE_componentWillUpdate && + fn.UNSAFE_componentWillUpdate( + needsContext, + oldState, + props$jscomp$0 + )), + "function" === typeof fn.componentDidUpdate && + (workInProgress.effectTag |= 4), + "function" === typeof fn.getSnapshotBeforeUpdate && + (workInProgress.effectTag |= 256)) + : ("function" !== typeof fn.componentDidUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 4), + "function" !== typeof fn.getSnapshotBeforeUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 256), + (workInProgress.memoizedProps = needsContext), + (workInProgress.memoizedState = oldState)), + (fn.props = needsContext), + (fn.state = oldState), + (fn.context = props$jscomp$0), + (fn = getDerivedStateFromProps)) + : ("function" !== typeof fn.componentDidUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 4), + "function" !== typeof fn.getSnapshotBeforeUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 256), + (fn = !1)); + return finishClassComponent( + current, + workInProgress, + fn, + props, + renderExpirationTime + ); + case 3: + return ( + pushHostRootContext(workInProgress), + (props = workInProgress.updateQueue), + null !== props + ? ((fn = workInProgress.memoizedState), + (fn = null !== fn ? fn.element : null), + processUpdateQueue( workInProgress, - workInProgress.stateNode.containerInfo + props, + workInProgress.pendingProps, + null, + renderExpirationTime ), - (props = workInProgress.pendingProps), - hasLegacyContextChanged() || workInProgress.memoizedProps !== props - ? (null === current - ? (workInProgress.child = reconcileChildFibers( - workInProgress, - null, - props, - renderExpirationTime - )) - : reconcileChildren(current, workInProgress, props), - (workInProgress.memoizedProps = props), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 14: - return ( - (props = workInProgress.type.render), - (renderExpirationTime = workInProgress.pendingProps), - (fn = workInProgress.ref), - hasLegacyContextChanged() || - workInProgress.memoizedProps !== renderExpirationTime || - fn !== (null !== current ? current.ref : null) - ? ((props = props(renderExpirationTime, fn)), - reconcileChildren(current, workInProgress, props), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( + (renderExpirationTime = workInProgress.memoizedState.element), + renderExpirationTime === fn + ? (current = bailoutOnAlreadyFinishedWork( current, workInProgress - )), - current - ); - case 10: - return ( - (renderExpirationTime = workInProgress.pendingProps), - hasLegacyContextChanged() || - workInProgress.memoizedProps !== renderExpirationTime - ? (reconcileChildren( + )) + : (reconcileChildren( current, workInProgress, renderExpirationTime ), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 11: - return ( - (renderExpirationTime = workInProgress.pendingProps.children), - hasLegacyContextChanged() || - (null !== renderExpirationTime && - workInProgress.memoizedProps !== renderExpirationTime) - ? (reconcileChildren( - current, + (current = workInProgress.child))) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 5: + return ( + requiredContext(rootInstanceStackCursor.current), + (renderExpirationTime = requiredContext(contextStackCursor$1.current)), + (props = workInProgress.type), + (props = + "AndroidTextInput" === props || + "RCTMultilineTextInputView" === props || + "RCTSinglelineTextInputView" === props || + "RCTText" === props || + "RCTVirtualText" === props), + (props = + renderExpirationTime.isInAParentText !== props + ? { isInAParentText: props } + : renderExpirationTime), + renderExpirationTime !== props && + (push(contextFiberStackCursor, workInProgress, workInProgress), + push(contextStackCursor$1, props, workInProgress)), + null === current && tryToClaimNextHydratableInstance(workInProgress), + (props = workInProgress.memoizedProps), + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || props !== renderExpirationTime + ? ((props = renderExpirationTime.children), + markRef(current, workInProgress), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 6: + return ( + null === current && tryToClaimNextHydratableInstance(workInProgress), + (workInProgress.memoizedProps = workInProgress.pendingProps), + null + ); + case 16: + return null; + case 4: + return ( + pushHostContainer( + workInProgress, + workInProgress.stateNode.containerInfo + ), + (props = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== props + ? (null === current + ? (workInProgress.child = reconcileChildFibers( workInProgress, + null, + props, renderExpirationTime - ), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)) - : (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress - )), - current - ); - case 15: - return ( - (renderExpirationTime = workInProgress.pendingProps), - workInProgress.memoizedProps === renderExpirationTime - ? (current = bailoutOnAlreadyFinishedWork( - current, - workInProgress )) - : (reconcileChildren( - current, - workInProgress, - renderExpirationTime.children - ), - (workInProgress.memoizedProps = renderExpirationTime), - (current = workInProgress.child)), - current - ); - case 13: - return updateContextProvider( - current, + : reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = props), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 14: + return ( + (props = workInProgress.type.render), + (renderExpirationTime = workInProgress.pendingProps), + (fn = workInProgress.ref), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime || + fn !== (null !== current ? current.ref : null) + ? ((props = props(renderExpirationTime, fn)), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 10: + return ( + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime + ? (reconcileChildren(current, workInProgress, renderExpirationTime), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 11: + return ( + (renderExpirationTime = workInProgress.pendingProps.children), + didPerformWorkStackCursor.current || + (null !== renderExpirationTime && + workInProgress.memoizedProps !== renderExpirationTime) + ? (reconcileChildren(current, workInProgress, renderExpirationTime), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 15: + return ( + (renderExpirationTime = workInProgress.pendingProps), + workInProgress.memoizedProps === renderExpirationTime + ? (current = bailoutOnAlreadyFinishedWork(current, workInProgress)) + : (reconcileChildren( + current, + workInProgress, + renderExpirationTime.children + ), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)), + current + ); + case 13: + return updateContextProvider( + current, + workInProgress, + renderExpirationTime + ); + case 12: + a: if ( + ((fn = workInProgress.type), + (unmaskedContext = workInProgress.pendingProps), + (needsContext = workInProgress.memoizedProps), + (props = fn._currentValue), + (props$jscomp$0 = fn._changedBits), + didPerformWorkStackCursor.current || + 0 !== props$jscomp$0 || + needsContext !== unmaskedContext) + ) { + workInProgress.memoizedProps = unmaskedContext; + ctor = unmaskedContext.unstable_observedBits; + if (void 0 === ctor || null === ctor) ctor = 1073741823; + workInProgress.stateNode = ctor; + if (0 !== (props$jscomp$0 & ctor)) + propagateContextChange( workInProgress, + fn, + props$jscomp$0, renderExpirationTime ); - case 12: - a: { - fn = workInProgress.type; - unmaskedContext = workInProgress.pendingProps; - memoizedProps = workInProgress.memoizedProps; - props = getContextCurrentValue(fn); - var changedBits = getContextChangedBits(fn); - if ( - hasLegacyContextChanged() || - 0 !== changedBits || - memoizedProps !== 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 (memoizedProps === unmaskedContext) { - current = bailoutOnAlreadyFinishedWork(current, workInProgress); - break a; - } - renderExpirationTime = unmaskedContext.children; - renderExpirationTime = renderExpirationTime(props); - workInProgress.effectTag |= 1; - reconcileChildren(current, workInProgress, renderExpirationTime); - current = workInProgress.child; - } else - current = bailoutOnAlreadyFinishedWork(current, workInProgress); - } - return current; - default: - invariant( - !1, - "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." - ); - } - } - }; + else if (needsContext === unmaskedContext) { + current = bailoutOnAlreadyFinishedWork(current, workInProgress); + break a; + } + renderExpirationTime = unmaskedContext.children; + renderExpirationTime = renderExpirationTime(props); + workInProgress.effectTag |= 1; + reconcileChildren(current, workInProgress, renderExpirationTime); + current = workInProgress.child; + } else current = bailoutOnAlreadyFinishedWork(current, workInProgress); + return current; + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } } -function ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - newContext, - hydrationContext -) { - function markUpdate(workInProgress) { +var updateHostContainer = void 0, + updateHostComponent$1 = void 0, + updateHostText$1 = void 0; +updateHostContainer = function() {}; +updateHostComponent$1 = function(current, workInProgress, updatePayload) { + if ((workInProgress.updateQueue = updatePayload)) workInProgress.effectTag |= 4; - } - var createInstance = config.createInstance, - createTextInstance = config.createTextInstance, - appendInitialChild = config.appendInitialChild, - finalizeInitialChildren = config.finalizeInitialChildren, - prepareUpdate = config.prepareUpdate, - persistence = config.persistence, - getRootHostContainer = hostContext.getRootHostContainer, - popHostContext = hostContext.popHostContext, - getHostContext = hostContext.getHostContext, - popHostContainer = hostContext.popHostContainer, - popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popProvider = newContext.popProvider, - prepareToHydrateHostInstance = - hydrationContext.prepareToHydrateHostInstance, - prepareToHydrateHostTextInstance = - hydrationContext.prepareToHydrateHostTextInstance, - popHydrationState = hydrationContext.popHydrationState, - updateHostContainer = void 0, - updateHostComponent = void 0, - updateHostText = void 0; - config.mutation - ? ((updateHostContainer = function() {}), - (updateHostComponent = function(current, workInProgress, updatePayload) { - (workInProgress.updateQueue = updatePayload) && - markUpdate(workInProgress); - }), - (updateHostText = function(current, workInProgress, oldText, newText) { - oldText !== newText && markUpdate(workInProgress); - })) - : persistence - ? invariant(!1, "Persistent reconciler is disabled.") - : invariant(!1, "Noop reconciler is disabled."); - return { - completeWork: function(current, workInProgress) { - var newProps = workInProgress.pendingProps; - switch (workInProgress.tag) { - case 1: - return null; - case 2: - return popLegacyContextProvider(workInProgress), null; - case 3: - popHostContainer(workInProgress); - popTopLevelLegacyContextObject(workInProgress); - newProps = workInProgress.stateNode; - newProps.pendingContext && - ((newProps.context = newProps.pendingContext), - (newProps.pendingContext = null)); - if (null === current || null === current.child) - popHydrationState(workInProgress), (workInProgress.effectTag &= -3); - updateHostContainer(workInProgress); - return null; - case 5: - popHostContext(workInProgress); - var rootContainerInstance = getRootHostContainer(), - type = workInProgress.type; - if (null !== current && null != workInProgress.stateNode) { - var oldProps = current.memoizedProps, - instance = workInProgress.stateNode, - currentHostContext = getHostContext(); - instance = prepareUpdate( - instance, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ); - updateHostComponent( - current, - workInProgress, - instance, - type, - oldProps, - newProps, - rootContainerInstance, - currentHostContext - ); - current.ref !== workInProgress.ref && - (workInProgress.effectTag |= 128); - } else { - if (!newProps) - return ( - invariant( - null !== workInProgress.stateNode, - "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." - ), - null - ); - current = getHostContext(); - if (popHydrationState(workInProgress)) - prepareToHydrateHostInstance( - workInProgress, - rootContainerInstance, - current - ) && markUpdate(workInProgress); - else { - oldProps = createInstance( - type, - newProps, - rootContainerInstance, - current, - workInProgress - ); - a: for ( - currentHostContext = workInProgress.child; - null !== currentHostContext; - - ) { - if ( - 5 === currentHostContext.tag || - 6 === currentHostContext.tag - ) - appendInitialChild(oldProps, currentHostContext.stateNode); - else if ( - 4 !== currentHostContext.tag && - null !== currentHostContext.child - ) { - currentHostContext.child.return = currentHostContext; - currentHostContext = currentHostContext.child; - continue; - } - if (currentHostContext === workInProgress) break; - for (; null === currentHostContext.sibling; ) { - if ( - null === currentHostContext.return || - currentHostContext.return === workInProgress - ) - break a; - currentHostContext = currentHostContext.return; - } - currentHostContext.sibling.return = currentHostContext.return; - currentHostContext = currentHostContext.sibling; - } - finalizeInitialChildren( - oldProps, - type, - newProps, - rootContainerInstance, - current - ) && markUpdate(workInProgress); - workInProgress.stateNode = oldProps; - } - null !== workInProgress.ref && (workInProgress.effectTag |= 128); - } - return null; - case 6: - if (current && null != workInProgress.stateNode) - updateHostText( - current, - workInProgress, - current.memoizedProps, - newProps - ); - else { - if ("string" !== typeof newProps) - return ( - invariant( - null !== workInProgress.stateNode, - "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." - ), - null - ); - rootContainerInstance = getRootHostContainer(); - type = getHostContext(); - popHydrationState(workInProgress) - ? prepareToHydrateHostTextInstance(workInProgress) && - markUpdate(workInProgress) - : (workInProgress.stateNode = createTextInstance( - newProps, - rootContainerInstance, - type, - workInProgress - )); +}; +updateHostText$1 = function(current, workInProgress, oldText, newText) { + oldText !== newText && (workInProgress.effectTag |= 4); +}; +function completeWork(current, workInProgress) { + var newProps = workInProgress.pendingProps; + switch (workInProgress.tag) { + case 1: + return null; + case 2: + return popContextProvider(workInProgress), null; + case 3: + popHostContainer(workInProgress); + popTopLevelContextObject(workInProgress); + newProps = workInProgress.stateNode; + newProps.pendingContext && + ((newProps.context = newProps.pendingContext), + (newProps.pendingContext = null)); + if (null === current || null === current.child) + workInProgress.effectTag &= -3; + updateHostContainer(workInProgress); + return null; + case 5: + popHostContext(workInProgress); + var rootContainerInstance = requiredContext( + rootInstanceStackCursor.current + ), + type = workInProgress.type; + if (null !== current && null != workInProgress.stateNode) { + var oldProps = current.memoizedProps, + currentHostContext = requiredContext(contextStackCursor$1.current); + updateHostComponent$1( + current, + workInProgress, + emptyObject, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ); + current.ref !== workInProgress.ref && (workInProgress.effectTag |= 128); + } else { + if (!newProps) + return ( + invariant( + null !== workInProgress.stateNode, + "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." + ), + null + ); + current = requiredContext(contextStackCursor$1.current); + oldProps = allocateTag(); + currentHostContext = ReactNativeViewConfigRegistry.get(type); + invariant( + "RCTView" !== type || !current.isInAParentText, + "Nesting of within is not currently supported." + ); + var updatePayload = diffProperties( + null, + emptyObject$1, + newProps, + currentHostContext.validAttributes + ); + UIManager.createView( + oldProps, + currentHostContext.uiViewClassName, + rootContainerInstance, + updatePayload + ); + currentHostContext = new ReactNativeFiberHostComponent( + oldProps, + currentHostContext + ); + instanceCache[oldProps] = workInProgress; + instanceProps[oldProps] = newProps; + a: for (oldProps = workInProgress.child; null !== oldProps; ) { + if (5 === oldProps.tag || 6 === oldProps.tag) + currentHostContext._children.push(oldProps.stateNode); + else if (4 !== oldProps.tag && null !== oldProps.child) { + oldProps.child.return = oldProps; + oldProps = oldProps.child; + continue; } - return null; - case 14: - return null; - case 16: - return null; - case 10: - return null; - case 11: - return null; - case 15: - return null; - case 4: + if (oldProps === workInProgress) break; + for (; null === oldProps.sibling; ) { + if (null === oldProps.return || oldProps.return === workInProgress) + break a; + oldProps = oldProps.return; + } + oldProps.sibling.return = oldProps.return; + oldProps = oldProps.sibling; + } + finalizeInitialChildren( + currentHostContext, + type, + newProps, + rootContainerInstance, + current + ) && (workInProgress.effectTag |= 4); + workInProgress.stateNode = currentHostContext; + null !== workInProgress.ref && (workInProgress.effectTag |= 128); + } + return null; + case 6: + if (current && null != workInProgress.stateNode) + updateHostText$1( + current, + workInProgress, + current.memoizedProps, + newProps + ); + else { + if ("string" !== typeof newProps) return ( - popHostContainer(workInProgress), - updateHostContainer(workInProgress), + invariant( + null !== workInProgress.stateNode, + "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." + ), null ); - case 13: - return popProvider(workInProgress), null; - case 12: - return null; - case 0: - invariant( - !1, - "An indeterminate component should have become determinate before completing. This error is likely caused by a bug in React. Please file an issue." - ); - default: - invariant( - !1, - "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." - ); + rootContainerInstance = requiredContext( + rootInstanceStackCursor.current + ); + type = requiredContext(contextStackCursor$1.current); + invariant( + type.isInAParentText, + "Text strings must be rendered within a component." + ); + type = allocateTag(); + UIManager.createView(type, "RCTRawText", rootContainerInstance, { + text: newProps + }); + instanceCache[type] = workInProgress; + workInProgress.stateNode = type; } - } - }; -} -function createCapturedValue(value, source) { - return { - value: value, - source: source, - stack: getStackAddendumByWorkInProgressFiber(source) - }; + return null; + case 14: + return null; + case 16: + return null; + case 10: + return null; + case 11: + return null; + case 15: + return null; + case 4: + return ( + popHostContainer(workInProgress), + updateHostContainer(workInProgress), + null + ); + case 13: + return popProvider(workInProgress), null; + case 12: + return null; + case 0: + invariant( + !1, + "An indeterminate component should have become determinate before completing. This error is likely caused by a bug in React. Please file an issue." + ); + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } } function logError(boundary, errorInfo) { var source = errorInfo.source, @@ -3704,2544 +4123,1510 @@ function logError(boundary, errorInfo) { errorInfo = errorInfo.value; null !== boundary && 2 === boundary.tag && getComponentName(boundary); try { - if (errorInfo instanceof Error) { - var message = errorInfo.message, - name = errorInfo.name; - var errorToHandle = errorInfo; - try { - errorToHandle.message = - (message ? name + ": " + message : name) + - "\n\nThis error is located at:" + - source; - } catch (e) {} - } else - errorToHandle = - "string" === typeof errorInfo - ? Error(errorInfo + "\n\nThis error is located at:" + source) - : Error("Unspecified error at:" + source); - ExceptionsManager.handleException(errorToHandle, !1); - } catch (e) { - (e && e.suppressReactErrorLogging) || console.error(e); - } -} -function ReactFiberCommitWork(config, captureError) { - function safelyDetachRef(current) { - var ref = current.ref; - if (null !== ref) - if ("function" === typeof ref) - try { - ref(null); - } catch (refError) { - captureError(current, refError); - } - else ref.current = null; - } - function commitUnmount(current) { - "function" === typeof onCommitUnmount && onCommitUnmount(current); - switch (current.tag) { - case 2: - safelyDetachRef(current); - var _instance6 = current.stateNode; - if ("function" === typeof _instance6.componentWillUnmount) - try { - (_instance6.props = current.memoizedProps), - (_instance6.state = current.memoizedState), - _instance6.componentWillUnmount(); - } catch (unmountError) { - captureError(current, unmountError); - } - break; - case 5: - safelyDetachRef(current); - break; - case 4: - mutation && unmountHostComponents(current); - } - } - function isHostParent(fiber) { - return 5 === fiber.tag || 3 === fiber.tag || 4 === fiber.tag; - } - function unmountHostComponents(current) { - for ( - var node = current, - currentParentIsValid = !1, - currentParent = void 0, - currentParentIsContainer = void 0; - ; - - ) { - if (!currentParentIsValid) { - currentParentIsValid = node.return; - a: for (;;) { - invariant( - null !== currentParentIsValid, - "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." - ); - switch (currentParentIsValid.tag) { - case 5: - currentParent = currentParentIsValid.stateNode; - currentParentIsContainer = !1; - break a; - case 3: - currentParent = currentParentIsValid.stateNode.containerInfo; - currentParentIsContainer = !0; - break a; - case 4: - currentParent = currentParentIsValid.stateNode.containerInfo; - currentParentIsContainer = !0; - break a; - } - currentParentIsValid = currentParentIsValid.return; - } - currentParentIsValid = !0; - } - if (5 === node.tag || 6 === node.tag) { - a: for (var root = node, node$jscomp$0 = root; ; ) - if ( - (commitUnmount(node$jscomp$0), - null === node$jscomp$0.child || - (mutation && 4 === node$jscomp$0.tag)) - ) { - if (node$jscomp$0 === root) break; - for (; null === node$jscomp$0.sibling; ) { - if ( - null === node$jscomp$0.return || - node$jscomp$0.return === root - ) - break a; - node$jscomp$0 = node$jscomp$0.return; - } - node$jscomp$0.sibling.return = node$jscomp$0.return; - node$jscomp$0 = node$jscomp$0.sibling; - } else - (node$jscomp$0.child.return = node$jscomp$0), - (node$jscomp$0 = node$jscomp$0.child); - currentParentIsContainer - ? removeChildFromContainer(currentParent, node.stateNode) - : removeChild(currentParent, node.stateNode); - } else if ( - (4 === node.tag - ? (currentParent = node.stateNode.containerInfo) - : commitUnmount(node), - null !== node.child) - ) { - node.child.return = node; - node = node.child; - continue; - } - if (node === current) break; - for (; null === node.sibling; ) { - if (null === node.return || node.return === current) return; - node = node.return; - 4 === node.tag && (currentParentIsValid = !1); - } - node.sibling.return = node.return; - node = node.sibling; - } - } - var getPublicInstance = config.getPublicInstance, - mutation = config.mutation; - config = config.persistence; - mutation || - (config - ? invariant(!1, "Persistent reconciler is disabled.") - : invariant(!1, "Noop reconciler is disabled.")); - var commitMount = mutation.commitMount, - commitUpdate = mutation.commitUpdate, - resetTextContent = mutation.resetTextContent, - commitTextUpdate = mutation.commitTextUpdate, - appendChild = mutation.appendChild, - appendChildToContainer = mutation.appendChildToContainer, - insertBefore = mutation.insertBefore, - insertInContainerBefore = mutation.insertInContainerBefore, - removeChild = mutation.removeChild, - removeChildFromContainer = mutation.removeChildFromContainer; - return { - commitBeforeMutationLifeCycles: function(current, finishedWork) { - switch (finishedWork.tag) { - case 2: - if (finishedWork.effectTag & 256 && 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); - }, - commitPlacement: function(finishedWork) { - a: { - for (var parent = finishedWork.return; null !== parent; ) { - if (isHostParent(parent)) { - var parentFiber = parent; - break a; - } - parent = parent.return; - } - invariant( - !1, - "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." - ); - parentFiber = void 0; - } - var isContainer = (parent = void 0); - switch (parentFiber.tag) { - case 5: - parent = parentFiber.stateNode; - isContainer = !1; - break; - case 3: - parent = parentFiber.stateNode.containerInfo; - isContainer = !0; - break; - case 4: - parent = parentFiber.stateNode.containerInfo; - isContainer = !0; - break; - default: - invariant( - !1, - "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue." - ); - } - parentFiber.effectTag & 16 && - (resetTextContent(parent), (parentFiber.effectTag &= -17)); - a: b: for (parentFiber = finishedWork; ; ) { - for (; null === parentFiber.sibling; ) { - if (null === parentFiber.return || isHostParent(parentFiber.return)) { - parentFiber = null; - break a; - } - parentFiber = parentFiber.return; - } - parentFiber.sibling.return = parentFiber.return; - for ( - parentFiber = parentFiber.sibling; - 5 !== parentFiber.tag && 6 !== parentFiber.tag; - - ) { - if (parentFiber.effectTag & 2) continue b; - if (null === parentFiber.child || 4 === parentFiber.tag) continue b; - else - (parentFiber.child.return = parentFiber), - (parentFiber = parentFiber.child); - } - if (!(parentFiber.effectTag & 2)) { - parentFiber = parentFiber.stateNode; - break a; - } - } - for (var node = finishedWork; ; ) { - if (5 === node.tag || 6 === node.tag) - parentFiber - ? isContainer - ? insertInContainerBefore(parent, node.stateNode, parentFiber) - : insertBefore(parent, node.stateNode, parentFiber) - : isContainer - ? appendChildToContainer(parent, node.stateNode) - : appendChild(parent, node.stateNode); - else if (4 !== node.tag && null !== node.child) { - node.child.return = node; - node = node.child; - continue; - } - if (node === finishedWork) break; - for (; null === node.sibling; ) { - if (null === node.return || node.return === finishedWork) return; - node = node.return; - } - node.sibling.return = node.return; - node = node.sibling; - } - }, - commitDeletion: function(current) { - unmountHostComponents(current); - current.return = null; - current.child = null; - current.alternate && - ((current.alternate.child = null), (current.alternate.return = null)); - }, - commitWork: function(current, finishedWork) { - switch (finishedWork.tag) { - case 2: - break; - case 5: - var _instance7 = finishedWork.stateNode; - if (null != _instance7) { - var newProps = finishedWork.memoizedProps; - current = null !== current ? current.memoizedProps : newProps; - var type = finishedWork.type, - updatePayload = finishedWork.updateQueue; - finishedWork.updateQueue = null; - null !== updatePayload && - commitUpdate( - _instance7, - updatePayload, - type, - current, - newProps, - finishedWork - ); - } - break; - case 6: - invariant( - null !== finishedWork.stateNode, - "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue." - ); - _instance7 = finishedWork.memoizedProps; - commitTextUpdate( - finishedWork.stateNode, - null !== current ? current.memoizedProps : _instance7, - _instance7 - ); - break; - case 3: - break; - case 15: - break; - case 16: - 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." - ); - } - }, - commitLifeCycles: function( - finishedRoot, - current, - finishedWork, - currentTime, - committedExpirationTime - ) { - switch (finishedWork.tag) { - case 2: - finishedRoot = finishedWork.stateNode; - finishedWork.effectTag & 4 && - (null === current - ? ((finishedRoot.props = finishedWork.memoizedProps), - (finishedRoot.state = finishedWork.memoizedState), - finishedRoot.componentDidMount()) - : ((currentTime = current.memoizedProps), - (current = current.memoizedState), - (finishedRoot.props = finishedWork.memoizedProps), - (finishedRoot.state = finishedWork.memoizedState), - finishedRoot.componentDidUpdate( - currentTime, - current, - finishedRoot.__reactInternalSnapshotBeforeUpdate - ))); - current = finishedWork.updateQueue; - null !== current && - ((finishedRoot.props = finishedWork.memoizedProps), - (finishedRoot.state = finishedWork.memoizedState), - commitUpdateQueue( - finishedWork, - current, - finishedRoot, - committedExpirationTime - )); - break; - case 3: - current = finishedWork.updateQueue; - if (null !== current) { - finishedRoot = null; - if (null !== finishedWork.child) - switch (finishedWork.child.tag) { - case 5: - finishedRoot = getPublicInstance( - finishedWork.child.stateNode - ); - break; - case 2: - finishedRoot = finishedWork.child.stateNode; - } - commitUpdateQueue( - finishedWork, - current, - finishedRoot, - committedExpirationTime - ); - } - break; - case 5: - committedExpirationTime = finishedWork.stateNode; - null === current && - finishedWork.effectTag & 4 && - commitMount( - committedExpirationTime, - finishedWork.type, - finishedWork.memoizedProps, - finishedWork - ); - break; - case 6: - break; - case 4: - break; - case 15: - break; - case 16: - 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." - ); - } - }, - commitAttachRef: function(finishedWork) { - var ref = finishedWork.ref; - if (null !== ref) { - var _instance5 = finishedWork.stateNode; - switch (finishedWork.tag) { - case 5: - finishedWork = getPublicInstance(_instance5); - break; - default: - finishedWork = _instance5; - } - "function" === typeof ref - ? ref(finishedWork) - : (ref.current = finishedWork); - } - }, - commitDetachRef: function(current) { - current = current.ref; - null !== current && - ("function" === typeof current - ? current(null) - : (current.current = null)); - } - }; -} -function ReactFiberUnwindWork( - config, - hostContext, - legacyContext, - newContext, - scheduleWork, - computeExpirationForFiber, - recalculateCurrentTime, - markLegacyErrorBoundaryAsFailed, - isAlreadyFailedLegacyErrorBoundary, - onUncaughtError -) { - function createRootErrorUpdate(fiber, errorInfo, expirationTime) { - expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; - expirationTime.payload = { element: null }; - var error = errorInfo.value; - expirationTime.callback = function() { - onUncaughtError(error); - logError(fiber, errorInfo); - }; - return expirationTime; - } - function createClassErrorUpdate(fiber, errorInfo, expirationTime) { - expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; - var inst = fiber.stateNode; - null !== inst && - "function" === typeof inst.componentDidCatch && - (expirationTime.callback = function() { - markLegacyErrorBoundaryAsFailed(this); - var error = errorInfo.value, - stack = errorInfo.stack; - logError(fiber, errorInfo); - this.componentDidCatch(error, { - componentStack: null !== stack ? stack : "" - }); - }); - return expirationTime; - } - var popHostContainer = hostContext.popHostContainer, - popHostContext = hostContext.popHostContext, - popLegacyContextProvider = legacyContext.popContextProvider, - popTopLevelLegacyContextObject = legacyContext.popTopLevelContextObject, - popProvider = newContext.popProvider; - return { - throwException: function( - root, - returnFiber, - sourceFiber, - value, - renderIsExpired, - renderExpirationTime - ) { - sourceFiber.effectTag |= 512; - sourceFiber.firstEffect = sourceFiber.lastEffect = null; - value = createCapturedValue(value, sourceFiber); - root = returnFiber; - do { - switch (root.tag) { - case 3: - root.effectTag |= 1024; - value = createRootErrorUpdate(root, value, renderExpirationTime); - enqueueCapturedUpdate(root, value, renderExpirationTime); - return; - case 2: - if ( - ((returnFiber = value), - (sourceFiber = root.stateNode), - 0 === (root.effectTag & 64) && - null !== sourceFiber && - "function" === typeof sourceFiber.componentDidCatch && - !isAlreadyFailedLegacyErrorBoundary(sourceFiber)) - ) { - root.effectTag |= 1024; - value = createClassErrorUpdate( - root, - returnFiber, - renderExpirationTime - ); - enqueueCapturedUpdate(root, value, renderExpirationTime); - return; - } - } - root = root.return; - } while (null !== root); - }, - unwindWork: function(workInProgress) { - switch (workInProgress.tag) { - case 2: - popLegacyContextProvider(workInProgress); - var effectTag = workInProgress.effectTag; - return effectTag & 1024 - ? ((workInProgress.effectTag = (effectTag & -1025) | 64), - workInProgress) - : null; - case 3: - return ( - popHostContainer(workInProgress), - popTopLevelLegacyContextObject(workInProgress), - (effectTag = workInProgress.effectTag), - effectTag & 1024 - ? ((workInProgress.effectTag = (effectTag & -1025) | 64), - workInProgress) - : null - ); - case 5: - return popHostContext(workInProgress), null; - case 16: - return ( - (effectTag = workInProgress.effectTag), - effectTag & 1024 - ? ((workInProgress.effectTag = (effectTag & -1025) | 64), - workInProgress) - : null - ); - case 4: - return popHostContainer(workInProgress), null; - case 13: - return popProvider(workInProgress), null; - 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); + if (errorInfo instanceof Error) { + var message = errorInfo.message, + name = errorInfo.name; + var errorToHandle = errorInfo; + try { + errorToHandle.message = + (message ? name + ": " + message : name) + + "\n\nThis error is located at:" + + source; + } catch (e) {} + } else + errorToHandle = + "string" === typeof errorInfo + ? Error(errorInfo + "\n\nThis error is located at:" + source) + : Error("Unspecified error at:" + source); + ExceptionsManager.handleException(errorToHandle, !1); + } catch (e) { + (e && e.suppressReactErrorLogging) || console.error(e); + } +} +function safelyDetachRef(current) { + var ref = current.ref; + if (null !== ref) + if ("function" === typeof ref) + try { + ref(null); + } catch (refError) { + captureCommitPhaseError(current, refError); } - }, - createRootErrorUpdate: createRootErrorUpdate, - createClassErrorUpdate: createClassErrorUpdate - }; + else ref.current = null; +} +function commitUnmount(current) { + "function" === typeof onCommitUnmount && onCommitUnmount(current); + switch (current.tag) { + case 2: + safelyDetachRef(current); + var instance = current.stateNode; + if ("function" === typeof instance.componentWillUnmount) + try { + (instance.props = current.memoizedProps), + (instance.state = current.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current, unmountError); + } + break; + case 5: + safelyDetachRef(current); + break; + case 4: + unmountHostComponents(current); + } +} +function isHostParent(fiber) { + return 5 === fiber.tag || 3 === fiber.tag || 4 === fiber.tag; } -var NO_CONTEXT = {}; -function ReactFiberHostContext(config, stack) { - function requiredContext(c) { +function commitPlacement(finishedWork) { + a: { + for (var parent = finishedWork.return; null !== parent; ) { + if (isHostParent(parent)) { + var parentFiber = parent; + break a; + } + parent = parent.return; + } invariant( - c !== NO_CONTEXT, - "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." + !1, + "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." ); - return c; + parentFiber = void 0; } - 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); - return { - getHostContext: function() { - return requiredContext(contextStackCursor.current); - }, - getRootHostContainer: function() { - return requiredContext(rootInstanceStackCursor.current); - }, - popHostContainer: function(fiber) { - pop(contextStackCursor, fiber); - pop(contextFiberStackCursor, fiber); - pop(rootInstanceStackCursor, fiber); - }, - popHostContext: function(fiber) { - contextFiberStackCursor.current === fiber && - (pop(contextStackCursor, fiber), pop(contextFiberStackCursor, fiber)); - }, - pushHostContainer: function(fiber, nextRootInstance) { - push(rootInstanceStackCursor, nextRootInstance, fiber); - push(contextFiberStackCursor, fiber, fiber); - push(contextStackCursor, NO_CONTEXT, fiber); - nextRootInstance = getRootHostContext(nextRootInstance); - pop(contextStackCursor, fiber); - push(contextStackCursor, nextRootInstance, fiber); - }, - pushHostContext: function(fiber) { - var rootInstance = requiredContext(rootInstanceStackCursor.current), - context = requiredContext(contextStackCursor.current); - rootInstance = getChildHostContext(context, fiber.type, rootInstance); - context !== rootInstance && - (push(contextFiberStackCursor, fiber, fiber), - push(contextStackCursor, rootInstance, fiber)); - } - }; -} -function ReactFiberHydrationContext(config) { - function deleteHydratableInstance(returnFiber, instance) { - var fiber = new FiberNode(5, null, null, 0); - fiber.type = "DELETED"; - fiber.stateNode = instance; - fiber.return = returnFiber; - fiber.effectTag = 8; - null !== returnFiber.lastEffect - ? ((returnFiber.lastEffect.nextEffect = fiber), - (returnFiber.lastEffect = fiber)) - : (returnFiber.firstEffect = returnFiber.lastEffect = fiber); + var isContainer = (parent = void 0); + switch (parentFiber.tag) { + case 5: + parent = parentFiber.stateNode; + isContainer = !1; + break; + case 3: + parent = parentFiber.stateNode.containerInfo; + isContainer = !0; + break; + case 4: + parent = parentFiber.stateNode.containerInfo; + isContainer = !0; + break; + default: + invariant( + !1, + "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue." + ); } - function tryHydrate(fiber, nextInstance) { - switch (fiber.tag) { - case 5: - return ( - (nextInstance = canHydrateInstance( - nextInstance, - fiber.type, - fiber.pendingProps - )), - null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 - ); - case 6: - return ( - (nextInstance = canHydrateTextInstance( - nextInstance, - fiber.pendingProps - )), - null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 - ); - default: - return !1; + parentFiber.effectTag & 16 && (parentFiber.effectTag &= -17); + a: b: for (parentFiber = finishedWork; ; ) { + for (; null === parentFiber.sibling; ) { + if (null === parentFiber.return || isHostParent(parentFiber.return)) { + parentFiber = null; + break a; + } + parentFiber = parentFiber.return; } - } - function popToNextHostParent(fiber) { + parentFiber.sibling.return = parentFiber.return; for ( - fiber = fiber.return; - null !== fiber && 5 !== fiber.tag && 3 !== fiber.tag; + parentFiber = parentFiber.sibling; + 5 !== parentFiber.tag && 6 !== parentFiber.tag; - ) - fiber = fiber.return; - hydrationParentFiber = fiber; + ) { + if (parentFiber.effectTag & 2) continue b; + if (null === parentFiber.child || 4 === parentFiber.tag) continue b; + else + (parentFiber.child.return = parentFiber), + (parentFiber = parentFiber.child); + } + if (!(parentFiber.effectTag & 2)) { + parentFiber = parentFiber.stateNode; + break a; + } } - var shouldSetTextContent = config.shouldSetTextContent; - config = config.hydration; - if (!config) - return { - enterHydrationState: function() { - return !1; - }, - resetHydrationState: function() {}, - tryToClaimNextHydratableInstance: function() {}, - prepareToHydrateHostInstance: function() { - invariant( - !1, - "Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue." - ); - }, - prepareToHydrateHostTextInstance: function() { + for (var node = finishedWork; ; ) { + if (5 === node.tag || 6 === node.tag) + if (parentFiber) + if (isContainer) + invariant( + "number" !== typeof parent, + "Container does not support insertBefore operation" + ); + else { + var parentInstance = parent, + child = node.stateNode, + beforeChild = parentFiber, + children = parentInstance._children, + index = children.indexOf(child); + 0 <= index + ? (children.splice(index, 1), + (beforeChild = children.indexOf(beforeChild)), + children.splice(beforeChild, 0, child), + UIManager.manageChildren( + parentInstance._nativeTag, + [index], + [beforeChild], + [], + [], + [] + )) + : ((index = children.indexOf(beforeChild)), + children.splice(index, 0, child), + UIManager.manageChildren( + parentInstance._nativeTag, + [], + [], + ["number" === typeof child ? child : child._nativeTag], + [index], + [] + )); + } + else + isContainer + ? ((parentInstance = node.stateNode), + UIManager.setChildren(parent, [ + "number" === typeof parentInstance + ? parentInstance + : parentInstance._nativeTag + ])) + : ((parentInstance = parent), + (child = node.stateNode), + (children = "number" === typeof child ? child : child._nativeTag), + (index = parentInstance._children), + (beforeChild = index.indexOf(child)), + 0 <= beforeChild + ? (index.splice(beforeChild, 1), + index.push(child), + UIManager.manageChildren( + parentInstance._nativeTag, + [beforeChild], + [index.length - 1], + [], + [], + [] + )) + : (index.push(child), + UIManager.manageChildren( + parentInstance._nativeTag, + [], + [], + [children], + [index.length - 1], + [] + ))); + else if (4 !== node.tag && null !== node.child) { + node.child.return = node; + node = node.child; + continue; + } + if (node === finishedWork) break; + for (; null === node.sibling; ) { + if (null === node.return || node.return === finishedWork) return; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } +} +function unmountHostComponents(current) { + for ( + var node = current, + currentParentIsValid = !1, + currentParent = void 0, + currentParentIsContainer = void 0; + ; + + ) { + if (!currentParentIsValid) { + currentParentIsValid = node.return; + a: for (;;) { invariant( - !1, - "Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue." + null !== currentParentIsValid, + "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." ); - }, - popHydrationState: function() { - return !1; + switch (currentParentIsValid.tag) { + case 5: + currentParent = currentParentIsValid.stateNode; + currentParentIsContainer = !1; + break a; + case 3: + currentParent = currentParentIsValid.stateNode.containerInfo; + currentParentIsContainer = !0; + break a; + case 4: + currentParent = currentParentIsValid.stateNode.containerInfo; + currentParentIsContainer = !0; + break a; + } + currentParentIsValid = currentParentIsValid.return; } - }; - var canHydrateInstance = config.canHydrateInstance, - canHydrateTextInstance = config.canHydrateTextInstance, - getNextHydratableSibling = config.getNextHydratableSibling, - getFirstHydratableChild = config.getFirstHydratableChild, - hydrateInstance = config.hydrateInstance, - hydrateTextInstance = config.hydrateTextInstance, - hydrationParentFiber = null, - nextHydratableInstance = null, - isHydrating = !1; - return { - enterHydrationState: function(fiber) { - nextHydratableInstance = getFirstHydratableChild( - fiber.stateNode.containerInfo - ); - hydrationParentFiber = fiber; - return (isHydrating = !0); - }, - resetHydrationState: function() { - nextHydratableInstance = hydrationParentFiber = null; - isHydrating = !1; - }, - tryToClaimNextHydratableInstance: function(fiber) { - if (isHydrating) { - var nextInstance = nextHydratableInstance; - if (nextInstance) { - if (!tryHydrate(fiber, nextInstance)) { - nextInstance = getNextHydratableSibling(nextInstance); - if (!nextInstance || !tryHydrate(fiber, nextInstance)) { - fiber.effectTag |= 2; - isHydrating = !1; - hydrationParentFiber = fiber; - return; - } - deleteHydratableInstance( - hydrationParentFiber, - nextHydratableInstance - ); + currentParentIsValid = !0; + } + if (5 === node.tag || 6 === node.tag) { + a: for (var root = node, node$jscomp$0 = root; ; ) + if ( + (commitUnmount(node$jscomp$0), + null !== node$jscomp$0.child && 4 !== node$jscomp$0.tag) + ) + (node$jscomp$0.child.return = node$jscomp$0), + (node$jscomp$0 = node$jscomp$0.child); + else { + if (node$jscomp$0 === root) break; + for (; null === node$jscomp$0.sibling; ) { + if (null === node$jscomp$0.return || node$jscomp$0.return === root) + break a; + node$jscomp$0 = node$jscomp$0.return; } - hydrationParentFiber = fiber; - nextHydratableInstance = getFirstHydratableChild(nextInstance); - } else - (fiber.effectTag |= 2), - (isHydrating = !1), - (hydrationParentFiber = fiber); + node$jscomp$0.sibling.return = node$jscomp$0.return; + node$jscomp$0 = node$jscomp$0.sibling; + } + if (currentParentIsContainer) + (root = currentParent), + recursivelyUncacheFiberNode(node.stateNode), + UIManager.manageChildren(root, [], [], [], [], [0]); + else { + root = currentParent; + var child = node.stateNode; + recursivelyUncacheFiberNode(child); + node$jscomp$0 = root._children; + child = node$jscomp$0.indexOf(child); + node$jscomp$0.splice(child, 1); + UIManager.manageChildren(root._nativeTag, [], [], [], [], [child]); } - }, - prepareToHydrateHostInstance: function( - fiber, - rootContainerInstance, - hostContext + } else if ( + (4 === node.tag + ? (currentParent = node.stateNode.containerInfo) + : commitUnmount(node), + null !== node.child) ) { - rootContainerInstance = hydrateInstance( - fiber.stateNode, - fiber.type, - fiber.memoizedProps, - rootContainerInstance, - hostContext, - fiber - ); - fiber.updateQueue = rootContainerInstance; - return null !== rootContainerInstance ? !0 : !1; - }, - prepareToHydrateHostTextInstance: function(fiber) { - return hydrateTextInstance(fiber.stateNode, fiber.memoizedProps, fiber); - }, - popHydrationState: function(fiber) { - if (fiber !== hydrationParentFiber) return !1; - if (!isHydrating) - return popToNextHostParent(fiber), (isHydrating = !0), !1; - var type = fiber.type; - if ( - 5 !== fiber.tag || - ("head" !== type && - "body" !== type && - !shouldSetTextContent(type, fiber.memoizedProps)) - ) - for (type = nextHydratableInstance; type; ) - deleteHydratableInstance(fiber, type), - (type = getNextHydratableSibling(type)); - popToNextHostParent(fiber); - nextHydratableInstance = hydrationParentFiber - ? getNextHydratableSibling(fiber.stateNode) - : null; - return !0; + node.child.return = node; + node = node.child; + continue; } - }; -} -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); + if (node === current) break; + for (; null === node.sibling; ) { + if (null === node.return || node.return === current) return; + node = node.return; + 4 === node.tag && (currentParentIsValid = !1); + } + node.sibling.return = node.return; + node = node.sibling; } - 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) { +} +function commitWork(current, finishedWork) { + switch (finishedWork.tag) { + case 2: + break; + case 5: + var instance = finishedWork.stateNode; + if (null != instance) { + var newProps = finishedWork.memoizedProps; + current = null !== current ? current.memoizedProps : newProps; + var updatePayload = finishedWork.updateQueue; + finishedWork.updateQueue = null; + null !== updatePayload && + ((finishedWork = instance.viewConfig), + (instanceProps[instance._nativeTag] = newProps), + (newProps = diffProperties( + null, + current, + newProps, + finishedWork.validAttributes + )), + null != newProps && + UIManager.updateView( + instance._nativeTag, + finishedWork.uiViewClassName, + newProps + )); + } + break; + case 6: 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 + null !== finishedWork.stateNode, + "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue." ); - return !0; - }, - invalidateContextProvider: function(workInProgress, didChange) { - var instance = workInProgress.stateNode; + UIManager.updateView(finishedWork.stateNode, "RCTRawText", { + text: finishedWork.memoizedProps + }); + break; + case 3: + break; + case 15: + break; + case 16: + break; + default: invariant( - instance, - "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." + !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." ); - 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, isPrimaryRenderer) { - 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; - isPrimaryRenderer - ? (push(changedBitsCursor, context._changedBits, providerFiber), - push(valueCursor, context._currentValue, providerFiber), - push(providerCursor, providerFiber, providerFiber), - (context._currentValue = providerFiber.pendingProps.value), - (context._changedBits = providerFiber.stateNode)) - : (push(changedBitsCursor, context._changedBits2, providerFiber), - push(valueCursor, context._currentValue2, providerFiber), - push(providerCursor, providerFiber, providerFiber), - (context._currentValue2 = providerFiber.pendingProps.value), - (context._changedBits2 = 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; - isPrimaryRenderer - ? ((providerFiber._currentValue = currentValue), - (providerFiber._changedBits = changedBits)) - : ((providerFiber._currentValue2 = currentValue), - (providerFiber._changedBits2 = changedBits)); - }, - getContextCurrentValue: function(context) { - return isPrimaryRenderer ? context._currentValue : context._currentValue2; - }, - getContextChangedBits: function(context) { - return isPrimaryRenderer ? context._changedBits : context._changedBits2; - } +function createRootErrorUpdate(fiber, errorInfo, expirationTime) { + expirationTime = createUpdate(expirationTime); + expirationTime.tag = 3; + expirationTime.payload = { element: null }; + var error = errorInfo.value; + expirationTime.callback = function() { + onUncaughtError(error); + logError(fiber, errorInfo); }; + return expirationTime; } -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 createClassErrorUpdate(fiber, errorInfo, expirationTime) { + expirationTime = createUpdate(expirationTime); + expirationTime.tag = 3; + var inst = fiber.stateNode; + null !== inst && + "function" === typeof inst.componentDidCatch && + (expirationTime.callback = function() { + null === legacyErrorBoundariesThatAlreadyFailed + ? (legacyErrorBoundariesThatAlreadyFailed = new Set([this])) + : legacyErrorBoundariesThatAlreadyFailed.add(this); + var error = errorInfo.value, + stack = errorInfo.stack; + logError(fiber, errorInfo); + this.componentDidCatch(error, { + componentStack: null !== stack ? stack : "" + }); + }); + return expirationTime; } -function ReactFiberScheduler(config) { - function resetStack() { - if (null !== nextUnitOfWork) - for ( - var interruptedWork = nextUnitOfWork.return; - null !== interruptedWork; - - ) - unwindInterruptedWork(interruptedWork), - (interruptedWork = interruptedWork.return); - nextRoot = null; - nextRenderExpirationTime = 0; - nextLatestTimeoutMs = -1; - nextRenderIsExpired = !1; - nextUnitOfWork = null; - isRootReadyForCommit = !1; - } - function isAlreadyFailedLegacyErrorBoundary(instance) { - return ( - null !== legacyErrorBoundariesThatAlreadyFailed && - legacyErrorBoundariesThatAlreadyFailed.has(instance) - ); - } - function markLegacyErrorBoundaryAsFailed(instance) { - null === legacyErrorBoundariesThatAlreadyFailed - ? (legacyErrorBoundariesThatAlreadyFailed = new Set([instance])) - : legacyErrorBoundariesThatAlreadyFailed.add(instance); +function unwindWork(workInProgress) { + switch (workInProgress.tag) { + case 2: + popContextProvider(workInProgress); + var effectTag = workInProgress.effectTag; + return effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null; + case 3: + return ( + popHostContainer(workInProgress), + popTopLevelContextObject(workInProgress), + (effectTag = workInProgress.effectTag), + effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null + ); + case 5: + return popHostContext(workInProgress), null; + case 16: + return ( + (effectTag = workInProgress.effectTag), + effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null + ); + case 4: + return popHostContainer(workInProgress), null; + case 13: + return popProvider(workInProgress), null; + default: + return null; } - function completeUnitOfWork(workInProgress$jscomp$0) { - for (;;) { - var current = workInProgress$jscomp$0.alternate, - returnFiber = workInProgress$jscomp$0.return, - siblingFiber = workInProgress$jscomp$0.sibling; - if (0 === (workInProgress$jscomp$0.effectTag & 512)) { - current = completeWork( - current, - workInProgress$jscomp$0, - nextRenderExpirationTime - ); - var workInProgress = workInProgress$jscomp$0; - if ( - 1073741823 === nextRenderExpirationTime || - 1073741823 !== workInProgress.expirationTime - ) { - var newExpirationTime = 0; - switch (workInProgress.tag) { - case 3: - case 2: - var updateQueue = workInProgress.updateQueue; - null !== updateQueue && - (newExpirationTime = updateQueue.expirationTime); - } - for (updateQueue = workInProgress.child; null !== updateQueue; ) - 0 !== updateQueue.expirationTime && - (0 === newExpirationTime || - newExpirationTime > updateQueue.expirationTime) && - (newExpirationTime = updateQueue.expirationTime), - (updateQueue = updateQueue.sibling); - workInProgress.expirationTime = newExpirationTime; - } - if (null !== current) return current; - null !== returnFiber && - 0 === (returnFiber.effectTag & 512) && - (null === returnFiber.firstEffect && - (returnFiber.firstEffect = workInProgress$jscomp$0.firstEffect), - null !== workInProgress$jscomp$0.lastEffect && - (null !== returnFiber.lastEffect && - (returnFiber.lastEffect.nextEffect = - workInProgress$jscomp$0.firstEffect), - (returnFiber.lastEffect = workInProgress$jscomp$0.lastEffect)), - 1 < workInProgress$jscomp$0.effectTag && - (null !== returnFiber.lastEffect - ? (returnFiber.lastEffect.nextEffect = workInProgress$jscomp$0) - : (returnFiber.firstEffect = workInProgress$jscomp$0), - (returnFiber.lastEffect = workInProgress$jscomp$0))); - if (null !== siblingFiber) return siblingFiber; - if (null !== returnFiber) workInProgress$jscomp$0 = returnFiber; - else { - isRootReadyForCommit = !0; +} +var originalStartTimeMs = now$1(), + mostRecentCurrentTime = 2, + mostRecentCurrentTimeMs = originalStartTimeMs, + lastUniqueAsyncExpiration = 0, + expirationContext = 0, + isWorking = !1, + nextUnitOfWork = null, + nextRoot = null, + nextRenderExpirationTime = 0, + nextLatestTimeoutMs = -1, + nextRenderDidError = !1, + nextEffect = null, + isCommitting$1 = !1, + legacyErrorBoundariesThatAlreadyFailed = null; +function resetStack() { + if (null !== nextUnitOfWork) + for ( + var interruptedWork = nextUnitOfWork.return; + null !== interruptedWork; + + ) { + var interruptedWork$jscomp$0 = interruptedWork; + switch (interruptedWork$jscomp$0.tag) { + case 2: + popContextProvider(interruptedWork$jscomp$0); break; - } - } else { - workInProgress$jscomp$0 = unwindWork( - workInProgress$jscomp$0, - nextRenderIsExpired, - nextRenderExpirationTime - ); - if (null !== workInProgress$jscomp$0) - return ( - (workInProgress$jscomp$0.effectTag &= 511), workInProgress$jscomp$0 - ); - null !== returnFiber && - ((returnFiber.firstEffect = returnFiber.lastEffect = null), - (returnFiber.effectTag |= 512)); - if (null !== siblingFiber) return siblingFiber; - if (null !== returnFiber) workInProgress$jscomp$0 = returnFiber; - else break; + case 3: + popHostContainer(interruptedWork$jscomp$0); + popTopLevelContextObject(interruptedWork$jscomp$0); + break; + case 5: + popHostContext(interruptedWork$jscomp$0); + break; + case 4: + popHostContainer(interruptedWork$jscomp$0); + break; + case 13: + popProvider(interruptedWork$jscomp$0); } + interruptedWork = interruptedWork.return; } - return null; - } - function performUnitOfWork(workInProgress) { - var next = beginWork( - workInProgress.alternate, - workInProgress, - nextRenderExpirationTime - ); - null === next && (next = completeUnitOfWork(workInProgress)); - ReactCurrentOwner.current = null; - return next; - } - function renderRoot(root, expirationTime, isAsync) { - invariant( - !isWorking, - "renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." - ); - isWorking = !0; - if ( - expirationTime !== nextRenderExpirationTime || - root !== nextRoot || - null === nextUnitOfWork - ) - resetStack(), - (nextRoot = root), - (nextRenderExpirationTime = expirationTime), - (nextLatestTimeoutMs = -1), - (nextUnitOfWork = createWorkInProgress( - nextRoot.current, - null, - nextRenderExpirationTime - )), - (root.pendingCommitExpirationTime = 0); - var didFatal = !1; - nextRenderIsExpired = - !isAsync || nextRenderExpirationTime <= mostRecentCurrentTime; - do { - try { - if (isAsync) - for (; null !== nextUnitOfWork && !shouldYield(); ) - nextUnitOfWork = performUnitOfWork(nextUnitOfWork); - else - for (; null !== nextUnitOfWork; ) - nextUnitOfWork = performUnitOfWork(nextUnitOfWork); - } catch (thrownValue) { - if (null === nextUnitOfWork) - (didFatal = !0), onUncaughtError(thrownValue); - else { - invariant( - null !== nextUnitOfWork, - "Failed to replay rendering after an error. This is likely caused by a bug in React. Please file an issue with a reproducing case to help us find it." - ); - isAsync = nextUnitOfWork; - var returnFiber = isAsync.return; - if (null === returnFiber) { - didFatal = !0; - onUncaughtError(thrownValue); - break; - } - throwException( - root, - returnFiber, - isAsync, - thrownValue, - nextRenderIsExpired, - nextRenderExpirationTime, - mostRecentCurrentTimeMs - ); - nextUnitOfWork = completeUnitOfWork(isAsync); + nextRoot = null; + nextRenderExpirationTime = 0; + nextLatestTimeoutMs = -1; + nextRenderDidError = !1; + nextUnitOfWork = null; +} +function completeUnitOfWork(workInProgress$jscomp$0) { + for (;;) { + var current = workInProgress$jscomp$0.alternate, + returnFiber = workInProgress$jscomp$0.return, + siblingFiber = workInProgress$jscomp$0.sibling; + if (0 === (workInProgress$jscomp$0.effectTag & 512)) { + current = completeWork( + current, + workInProgress$jscomp$0, + nextRenderExpirationTime + ); + var workInProgress = workInProgress$jscomp$0; + if ( + 1073741823 === nextRenderExpirationTime || + 1073741823 !== workInProgress.expirationTime + ) { + var newExpirationTime = 0; + switch (workInProgress.tag) { + case 3: + case 2: + var updateQueue = workInProgress.updateQueue; + null !== updateQueue && + (newExpirationTime = updateQueue.expirationTime); } + for (updateQueue = workInProgress.child; null !== updateQueue; ) + 0 !== updateQueue.expirationTime && + (0 === newExpirationTime || + newExpirationTime > updateQueue.expirationTime) && + (newExpirationTime = updateQueue.expirationTime), + (updateQueue = updateQueue.sibling); + workInProgress.expirationTime = newExpirationTime; } - break; - } while (1); - isWorking = !1; - if (didFatal) return null; - if (null === nextUnitOfWork) { - if (isRootReadyForCommit) + if (null !== current) return current; + null !== returnFiber && + 0 === (returnFiber.effectTag & 512) && + (null === returnFiber.firstEffect && + (returnFiber.firstEffect = workInProgress$jscomp$0.firstEffect), + null !== workInProgress$jscomp$0.lastEffect && + (null !== returnFiber.lastEffect && + (returnFiber.lastEffect.nextEffect = + workInProgress$jscomp$0.firstEffect), + (returnFiber.lastEffect = workInProgress$jscomp$0.lastEffect)), + 1 < workInProgress$jscomp$0.effectTag && + (null !== returnFiber.lastEffect + ? (returnFiber.lastEffect.nextEffect = workInProgress$jscomp$0) + : (returnFiber.firstEffect = workInProgress$jscomp$0), + (returnFiber.lastEffect = workInProgress$jscomp$0))); + } else { + workInProgress$jscomp$0 = unwindWork( + workInProgress$jscomp$0, + nextRenderExpirationTime + ); + if (null !== workInProgress$jscomp$0) return ( - (root.pendingCommitExpirationTime = expirationTime), - root.current.alternate + (workInProgress$jscomp$0.effectTag &= 511), workInProgress$jscomp$0 ); - invariant( - !nextRenderIsExpired, - "Expired work should have completed. This error is likely caused by a bug in React. Please file an issue." - ); - 0 <= nextLatestTimeoutMs && - setTimeout(function() { - retrySuspendedRoot(root, expirationTime); - }, nextLatestTimeoutMs); - onBlock(root.current.expirationTime); + null !== returnFiber && + ((returnFiber.firstEffect = returnFiber.lastEffect = null), + (returnFiber.effectTag |= 512)); } - return null; + if (null !== siblingFiber) return siblingFiber; + if (null !== returnFiber) workInProgress$jscomp$0 = returnFiber; + else break; } - function onCommitPhaseError(fiber, error) { - var JSCompiler_inline_result; - a: { - invariant( - !isWorking || isCommitting, - "dispatch: Cannot dispatch during the render phase." - ); - for ( - JSCompiler_inline_result = fiber.return; - null !== JSCompiler_inline_result; + return null; +} +function performUnitOfWork(workInProgress) { + var next = beginWork( + workInProgress.alternate, + workInProgress, + nextRenderExpirationTime + ); + null === next && (next = completeUnitOfWork(workInProgress)); + ReactCurrentOwner.current = null; + return next; +} +function renderRoot(root$jscomp$0, isYieldy) { + invariant( + !isWorking, + "renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." + ); + isWorking = !0; + var expirationTime = root$jscomp$0.nextExpirationTimeToWorkOn; + if ( + expirationTime !== nextRenderExpirationTime || + root$jscomp$0 !== nextRoot || + null === nextUnitOfWork + ) + resetStack(), + (nextRoot = root$jscomp$0), + (nextRenderExpirationTime = expirationTime), + (nextLatestTimeoutMs = -1), + (nextRenderDidError = !1), + (nextUnitOfWork = createWorkInProgress( + nextRoot.current, + null, + nextRenderExpirationTime + )), + (root$jscomp$0.pendingCommitExpirationTime = 0); + var didFatal = !1; + do { + try { + if (isYieldy) + for (; null !== nextUnitOfWork && !shouldYield(); ) + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + else + for (; null !== nextUnitOfWork; ) + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + } catch (thrownValue) { + if (null === nextUnitOfWork) + (didFatal = !0), onUncaughtError(thrownValue); + else { + invariant( + null !== nextUnitOfWork, + "Failed to replay rendering after an error. This is likely caused by a bug in React. Please file an issue with a reproducing case to help us find it." + ); + isYieldy = nextUnitOfWork; + var returnFiber = isYieldy.return; + if (null === returnFiber) { + didFatal = !0; + onUncaughtError(thrownValue); + break; + } + a: { + var root = root$jscomp$0, + returnFiber$jscomp$0 = returnFiber, + sourceFiber = isYieldy, + value = thrownValue; + returnFiber = nextRenderExpirationTime; + sourceFiber.effectTag |= 512; + sourceFiber.firstEffect = sourceFiber.lastEffect = null; + nextRenderDidError = !0; + if ( + (root.didError || 1 === returnFiber) && + (returnFiber === root.latestPendingTime || + returnFiber === root.latestSuspendedTime) + ) { + value = createCapturedValue(value, sourceFiber); + root = returnFiber$jscomp$0; + do { + switch (root.tag) { + case 3: + root.effectTag |= 1024; + value = createRootErrorUpdate(root, value, returnFiber); + enqueueCapturedUpdate(root, value, returnFiber); + break a; + case 2: + if ( + ((returnFiber$jscomp$0 = value), + (sourceFiber = root.stateNode), + 0 === (root.effectTag & 64) && + null !== sourceFiber && + "function" === typeof sourceFiber.componentDidCatch && + (null === legacyErrorBoundariesThatAlreadyFailed || + !legacyErrorBoundariesThatAlreadyFailed.has( + sourceFiber + ))) + ) { + root.effectTag |= 1024; + value = createClassErrorUpdate( + root, + returnFiber$jscomp$0, + returnFiber + ); + enqueueCapturedUpdate(root, value, returnFiber); + break a; + } + } + root = root.return; + } while (null !== root); + } + } + nextUnitOfWork = completeUnitOfWork(isYieldy); + } + } + break; + } while (1); + isWorking = !1; + didFatal + ? (root$jscomp$0.finishedWork = null) + : null === nextUnitOfWork + ? ((didFatal = root$jscomp$0.current.alternate), + invariant( + null !== didFatal, + "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue." + ), + 0 === (didFatal.effectTag & 512) + ? ((root$jscomp$0.pendingCommitExpirationTime = expirationTime), + (root$jscomp$0.finishedWork = didFatal)) + : (!nextRenderDidError || + (expirationTime !== root$jscomp$0.latestPendingTime && + expirationTime !== root$jscomp$0.latestSuspendedTime) + ? ((didFatal = root$jscomp$0.earliestPendingTime), + (isYieldy = root$jscomp$0.latestPendingTime), + didFatal === expirationTime + ? (root$jscomp$0.earliestPendingTime = + isYieldy === expirationTime + ? (root$jscomp$0.latestPendingTime = 0) + : isYieldy) + : isYieldy === expirationTime && + (root$jscomp$0.latestPendingTime = didFatal), + (didFatal = root$jscomp$0.latestSuspendedTime), + didFatal === expirationTime && + (root$jscomp$0.latestPingedTime = 0), + (isYieldy = root$jscomp$0.earliestSuspendedTime), + 0 === isYieldy + ? (root$jscomp$0.earliestSuspendedTime = root$jscomp$0.latestSuspendedTime = expirationTime) + : isYieldy > expirationTime + ? (root$jscomp$0.earliestSuspendedTime = expirationTime) + : didFatal < expirationTime && + (root$jscomp$0.latestSuspendedTime = expirationTime)) + : (root$jscomp$0.didError = !0), + findNextPendingPriorityLevel(root$jscomp$0), + onSuspend( + root$jscomp$0, + expirationTime, + root$jscomp$0.expirationTime, + nextLatestTimeoutMs + ))) + : (root$jscomp$0.finishedWork = null); +} +function captureCommitPhaseError(fiber, error) { + var JSCompiler_inline_result; + a: { + invariant( + !isWorking || isCommitting$1, + "dispatch: Cannot dispatch during the render phase." + ); + for ( + JSCompiler_inline_result = fiber.return; + null !== JSCompiler_inline_result; - ) { - switch (JSCompiler_inline_result.tag) { - case 2: - var instance = JSCompiler_inline_result.stateNode; - if ( - "function" === - typeof JSCompiler_inline_result.type.getDerivedStateFromCatch || - ("function" === typeof instance.componentDidCatch && - !isAlreadyFailedLegacyErrorBoundary(instance)) - ) { - fiber = createCapturedValue(error, fiber); - fiber = createClassErrorUpdate( - JSCompiler_inline_result, - fiber, - 1 - ); - enqueueUpdate(JSCompiler_inline_result, fiber, 1); - scheduleWork(JSCompiler_inline_result, 1); - JSCompiler_inline_result = void 0; - break a; - } - break; - case 3: + ) { + switch (JSCompiler_inline_result.tag) { + case 2: + var instance = JSCompiler_inline_result.stateNode; + if ( + "function" === + typeof JSCompiler_inline_result.type.getDerivedStateFromCatch || + ("function" === typeof instance.componentDidCatch && + (null === legacyErrorBoundariesThatAlreadyFailed || + !legacyErrorBoundariesThatAlreadyFailed.has(instance))) + ) { fiber = createCapturedValue(error, fiber); - fiber = createRootErrorUpdate(JSCompiler_inline_result, fiber, 1); + fiber = createClassErrorUpdate(JSCompiler_inline_result, fiber, 1); enqueueUpdate(JSCompiler_inline_result, fiber, 1); scheduleWork(JSCompiler_inline_result, 1); JSCompiler_inline_result = void 0; break a; - } - JSCompiler_inline_result = JSCompiler_inline_result.return; + } + break; + case 3: + fiber = createCapturedValue(error, fiber); + fiber = createRootErrorUpdate(JSCompiler_inline_result, fiber, 1); + enqueueUpdate(JSCompiler_inline_result, fiber, 1); + scheduleWork(JSCompiler_inline_result, 1); + JSCompiler_inline_result = void 0; + break a; } - 3 === fiber.tag && - ((JSCompiler_inline_result = createCapturedValue(error, fiber)), - (JSCompiler_inline_result = createRootErrorUpdate( - fiber, - JSCompiler_inline_result, - 1 - )), - enqueueUpdate(fiber, JSCompiler_inline_result, 1), - scheduleWork(fiber, 1)); - JSCompiler_inline_result = void 0; - } - return JSCompiler_inline_result; - } - function computeExpirationForFiber(currentTime, fiber) { - currentTime = - 0 !== expirationContext - ? expirationContext - : isWorking - ? isCommitting ? 1 : nextRenderExpirationTime - : fiber.mode & 1 - ? isBatchingInteractiveUpdates - ? 2 + 10 * ((((currentTime - 2 + 15) / 10) | 0) + 1) - : 2 + 25 * ((((currentTime - 2 + 500) / 25) | 0) + 1) - : 1; - isBatchingInteractiveUpdates && - (0 === lowestPendingInteractiveExpirationTime || - currentTime > lowestPendingInteractiveExpirationTime) && - (lowestPendingInteractiveExpirationTime = currentTime); - return currentTime; - } - function retrySuspendedRoot(root) { - var retryTime = root.current.expirationTime; - 0 !== retryTime && - (0 === root.remainingExpirationTime || - root.remainingExpirationTime < retryTime) && - requestWork(root, retryTime); - } - function scheduleWork(fiber, expirationTime) { - for (; null !== fiber; ) { - if (0 === fiber.expirationTime || fiber.expirationTime > expirationTime) - fiber.expirationTime = expirationTime; - null !== fiber.alternate && - (0 === fiber.alternate.expirationTime || - fiber.alternate.expirationTime > expirationTime) && - (fiber.alternate.expirationTime = expirationTime); - if (null === fiber.return) - if (3 === fiber.tag) { - var root = fiber.stateNode; - !isWorking && - 0 !== nextRenderExpirationTime && - expirationTime < nextRenderExpirationTime && - resetStack(); - var nextExpirationTimeToWorkOn = root.current.expirationTime; - (isWorking && !isCommitting && nextRoot === root) || - requestWork(root, nextExpirationTimeToWorkOn); - nestedUpdateCount > NESTED_UPDATE_LIMIT && - invariant( - !1, - "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops." - ); - } else break; - fiber = fiber.return; - } - } - function recalculateCurrentTime() { - mostRecentCurrentTimeMs = now() - originalStartTimeMs; - return (mostRecentCurrentTime = ((mostRecentCurrentTimeMs / 10) | 0) + 2); - } - function syncUpdates(fn, a, b, c, d) { - var previousExpirationContext = expirationContext; - expirationContext = 1; - try { - return fn(a, b, c, d); - } finally { - expirationContext = previousExpirationContext; - } - } - function scheduleCallbackWithExpiration(expirationTime) { - if (0 !== callbackExpirationTime) { - if (expirationTime > callbackExpirationTime) return; - cancelDeferredCallback(callbackID); - } - var currentMs = now() - originalStartTimeMs; - callbackExpirationTime = expirationTime; - callbackID = scheduleDeferredCallback(performAsyncWork, { - timeout: 10 * (expirationTime - 2) - currentMs - }); - } - function requestWork(root, expirationTime) { - if (null === root.nextScheduledRoot) - (root.remainingExpirationTime = expirationTime), - null === lastScheduledRoot - ? ((firstScheduledRoot = lastScheduledRoot = root), - (root.nextScheduledRoot = root)) - : ((lastScheduledRoot = lastScheduledRoot.nextScheduledRoot = root), - (lastScheduledRoot.nextScheduledRoot = firstScheduledRoot)); - else { - var remainingExpirationTime = root.remainingExpirationTime; - if ( - 0 === remainingExpirationTime || - expirationTime < remainingExpirationTime - ) - root.remainingExpirationTime = expirationTime; + JSCompiler_inline_result = JSCompiler_inline_result.return; } - isRendering || - (isBatchingUpdates - ? isUnbatchingUpdates && - ((nextFlushedRoot = root), - (nextFlushedExpirationTime = 1), - performWorkOnRoot(root, 1, !1)) - : 1 === expirationTime - ? performSyncWork() - : scheduleCallbackWithExpiration(expirationTime)); + 3 === fiber.tag && + ((JSCompiler_inline_result = createCapturedValue(error, fiber)), + (JSCompiler_inline_result = createRootErrorUpdate( + fiber, + JSCompiler_inline_result, + 1 + )), + enqueueUpdate(fiber, JSCompiler_inline_result, 1), + scheduleWork(fiber, 1)); + JSCompiler_inline_result = void 0; } - function findHighestPriorityRoot() { - var highestPriorityWork = 0, - highestPriorityRoot = null; - if (null !== lastScheduledRoot) - for ( - var previousScheduledRoot = lastScheduledRoot, - root = firstScheduledRoot; - null !== root; - - ) { - var remainingExpirationTime = root.remainingExpirationTime; - if (0 === remainingExpirationTime) { + return JSCompiler_inline_result; +} +function computeExpirationForFiber(currentTime, fiber) { + currentTime = + 0 !== expirationContext + ? expirationContext + : isWorking + ? isCommitting$1 ? 1 : nextRenderExpirationTime + : fiber.mode & 1 + ? isBatchingInteractiveUpdates + ? 2 + 10 * ((((currentTime - 2 + 15) / 10) | 0) + 1) + : 2 + 25 * ((((currentTime - 2 + 500) / 25) | 0) + 1) + : 1; + isBatchingInteractiveUpdates && + (0 === lowestPendingInteractiveExpirationTime || + currentTime > lowestPendingInteractiveExpirationTime) && + (lowestPendingInteractiveExpirationTime = currentTime); + return currentTime; +} +function scheduleWork(fiber, expirationTime) { + for (; null !== fiber; ) { + if (0 === fiber.expirationTime || fiber.expirationTime > expirationTime) + fiber.expirationTime = expirationTime; + null !== fiber.alternate && + (0 === fiber.alternate.expirationTime || + fiber.alternate.expirationTime > expirationTime) && + (fiber.alternate.expirationTime = expirationTime); + if (null === fiber.return) + if (3 === fiber.tag) { + var root = fiber.stateNode; + !isWorking && + 0 !== nextRenderExpirationTime && + expirationTime < nextRenderExpirationTime && + resetStack(); + markPendingPriorityLevel(root, expirationTime); + (isWorking && !isCommitting$1 && nextRoot === root) || + requestWork(root, root.expirationTime); + nestedUpdateCount > NESTED_UPDATE_LIMIT && invariant( - null !== previousScheduledRoot && null !== lastScheduledRoot, - "Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue." + !1, + "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops." ); - if (root === root.nextScheduledRoot) { - firstScheduledRoot = lastScheduledRoot = root.nextScheduledRoot = null; - break; - } else if (root === firstScheduledRoot) - (firstScheduledRoot = remainingExpirationTime = - root.nextScheduledRoot), - (lastScheduledRoot.nextScheduledRoot = remainingExpirationTime), - (root.nextScheduledRoot = null); - else if (root === lastScheduledRoot) { - lastScheduledRoot = previousScheduledRoot; - lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; - root.nextScheduledRoot = null; - break; - } else - (previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot), - (root.nextScheduledRoot = null); - root = previousScheduledRoot.nextScheduledRoot; - } else { - if ( - 0 === highestPriorityWork || - remainingExpirationTime < highestPriorityWork - ) - (highestPriorityWork = remainingExpirationTime), - (highestPriorityRoot = root); - if (root === lastScheduledRoot) break; - previousScheduledRoot = root; - root = root.nextScheduledRoot; - } - } - previousScheduledRoot = nextFlushedRoot; - null !== previousScheduledRoot && - previousScheduledRoot === highestPriorityRoot && - 1 === highestPriorityWork - ? nestedUpdateCount++ - : (nestedUpdateCount = 0); - nextFlushedRoot = highestPriorityRoot; - nextFlushedExpirationTime = highestPriorityWork; - } - function performAsyncWork(dl) { - performWork(0, !0, dl); + } else break; + fiber = fiber.return; } - function performSyncWork() { - performWork(1, !1, null); - } - function performWork(minExpirationTime, isAsync, dl) { - deadline = dl; - findHighestPriorityRoot(); - if (isAsync) - for ( - ; - null !== nextFlushedRoot && - 0 !== nextFlushedExpirationTime && - (0 === minExpirationTime || - minExpirationTime >= nextFlushedExpirationTime) && - (!deadlineDidExpire || - recalculateCurrentTime() >= nextFlushedExpirationTime); - - ) - recalculateCurrentTime(), - performWorkOnRoot( - nextFlushedRoot, - nextFlushedExpirationTime, - !deadlineDidExpire - ), - findHighestPriorityRoot(); - else - for ( - ; - null !== nextFlushedRoot && - 0 !== nextFlushedExpirationTime && - (0 === minExpirationTime || - minExpirationTime >= nextFlushedExpirationTime); - - ) - performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !1), - findHighestPriorityRoot(); - null !== deadline && ((callbackExpirationTime = 0), (callbackID = -1)); - 0 !== nextFlushedExpirationTime && - scheduleCallbackWithExpiration(nextFlushedExpirationTime); - deadline = null; - deadlineDidExpire = !1; - finishRendering(); +} +function recalculateCurrentTime() { + mostRecentCurrentTimeMs = now$1() - originalStartTimeMs; + return (mostRecentCurrentTime = ((mostRecentCurrentTimeMs / 10) | 0) + 2); +} +function syncUpdates(fn, a, b, c, d) { + var previousExpirationContext = expirationContext; + expirationContext = 1; + try { + return fn(a, b, c, d); + } finally { + expirationContext = previousExpirationContext; } - function finishRendering() { - nestedUpdateCount = 0; - if (null !== completedBatches) { - var batches = completedBatches; - completedBatches = null; - for (var i = 0; i < batches.length; i++) { - var batch = batches[i]; - try { - batch._onComplete(); - } catch (error) { - hasUnhandledError || - ((hasUnhandledError = !0), (unhandledError = error)); - } - } +} +var firstScheduledRoot = null, + lastScheduledRoot = null, + callbackExpirationTime = 0, + callbackID = void 0, + isRendering = !1, + nextFlushedRoot = null, + nextFlushedExpirationTime = 0, + lowestPendingInteractiveExpirationTime = 0, + deadlineDidExpire = !1, + hasUnhandledError = !1, + unhandledError = null, + deadline = null, + isBatchingUpdates = !1, + isUnbatchingUpdates = !1, + isBatchingInteractiveUpdates = !1, + completedBatches = null, + NESTED_UPDATE_LIMIT = 1e3, + nestedUpdateCount = 0, + timeHeuristicForUnitOfWork = 1; +function scheduleCallbackWithExpirationTime(expirationTime) { + if (0 !== callbackExpirationTime) { + if (expirationTime > callbackExpirationTime) return; + if (null !== callbackID) { + var callbackID$jscomp$0 = callbackID; + scheduledCallback = null; + clearTimeout(callbackID$jscomp$0); } - if (hasUnhandledError) - throw ((batches = unhandledError), - (unhandledError = null), - (hasUnhandledError = !1), - batches); - } - function performWorkOnRoot(root, expirationTime, isAsync) { - invariant( - !isRendering, - "performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." - ); - isRendering = !0; - isAsync - ? ((isAsync = root.finishedWork), - null !== isAsync - ? completeRoot(root, isAsync, expirationTime) - : ((root.finishedWork = null), - (isAsync = renderRoot(root, expirationTime, !0)), - null !== isAsync && - (shouldYield() - ? (root.finishedWork = isAsync) - : completeRoot(root, isAsync, expirationTime)))) - : ((isAsync = root.finishedWork), - null !== isAsync - ? completeRoot(root, isAsync, expirationTime) - : ((root.finishedWork = null), - (isAsync = renderRoot(root, expirationTime, !1)), - null !== isAsync && completeRoot(root, isAsync, expirationTime))); - isRendering = !1; } - function completeRoot(root, finishedWork, expirationTime) { - var firstBatch = root.firstBatch; + callbackExpirationTime = expirationTime; + now$1(); + scheduledCallback = performAsyncWork; + callbackID = setTimeout(setTimeoutCallback, 1); +} +function onSuspend(root, suspendedExpirationTime, expirationTime, timeoutMs) { + 0 <= timeoutMs && + setTimeout(function() { + var latestSuspendedTime = root.latestSuspendedTime; + 0 !== latestSuspendedTime && + latestSuspendedTime <= suspendedExpirationTime && + ((latestSuspendedTime = root.latestPingedTime), + 0 === latestSuspendedTime || + latestSuspendedTime < suspendedExpirationTime) && + (root.latestPingedTime = suspendedExpirationTime); + findNextPendingPriorityLevel(root); + latestSuspendedTime = root.expirationTime; + 0 !== latestSuspendedTime && requestWork(root, latestSuspendedTime); + }, timeoutMs); + root.expirationTime = expirationTime; +} +function requestWork(root, expirationTime) { + if (null === root.nextScheduledRoot) + (root.expirationTime = expirationTime), + null === lastScheduledRoot + ? ((firstScheduledRoot = lastScheduledRoot = root), + (root.nextScheduledRoot = root)) + : ((lastScheduledRoot = lastScheduledRoot.nextScheduledRoot = root), + (lastScheduledRoot.nextScheduledRoot = firstScheduledRoot)); + else { + var remainingExpirationTime = root.expirationTime; if ( - null !== firstBatch && - firstBatch._expirationTime <= expirationTime && - (null === completedBatches - ? (completedBatches = [firstBatch]) - : completedBatches.push(firstBatch), - firstBatch._defer) - ) { - root.finishedWork = finishedWork; - root.remainingExpirationTime = 0; - return; - } - root.finishedWork = null; - isCommitting = isWorking = !0; - expirationTime = finishedWork.stateNode; - invariant( - expirationTime.current !== finishedWork, - "Cannot commit the same tree as before. This is probably a bug related to the return field. This error is likely caused by a bug in React. Please file an issue." - ); - firstBatch = expirationTime.pendingCommitExpirationTime; - invariant( - 0 !== firstBatch, - "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." - ); - expirationTime.pendingCommitExpirationTime = 0; - var currentTime = recalculateCurrentTime(); - ReactCurrentOwner.current = null; - if (1 < finishedWork.effectTag) - if (null !== finishedWork.lastEffect) { - finishedWork.lastEffect.nextEffect = finishedWork; - var firstEffect = finishedWork.firstEffect; - } else firstEffect = finishedWork; - else firstEffect = finishedWork.firstEffect; - prepareForCommit(expirationTime.containerInfo); - for (nextEffect = firstEffect; null !== nextEffect; ) { - var didError = !1, - error = void 0; - try { - for (; null !== nextEffect; ) - nextEffect.effectTag & 256 && - 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; - effectTag & 16 && commitResetTextContent(nextEffect); - if (effectTag & 128) { - var current = nextEffect.alternate; - null !== current && commitDetachRef(current); - } - switch (effectTag & 14) { - case 2: - commitPlacement(nextEffect); - nextEffect.effectTag &= -3; - break; - case 6: - commitPlacement(nextEffect); - nextEffect.effectTag &= -3; - commitWork(nextEffect.alternate, nextEffect); - break; - case 4: - commitWork(nextEffect.alternate, nextEffect); - break; - case 8: - commitDeletion(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)); - } - resetAfterCommit(expirationTime.containerInfo); - expirationTime.current = finishedWork; - for (nextEffect = firstEffect; null !== nextEffect; ) { - effectTag = !1; - current = void 0; - try { - for ( - firstEffect = expirationTime, - didError = currentTime, - error = firstBatch; - null !== nextEffect; + 0 === remainingExpirationTime || + expirationTime < remainingExpirationTime + ) + root.expirationTime = expirationTime; + } + isRendering || + (isBatchingUpdates + ? isUnbatchingUpdates && + ((nextFlushedRoot = root), + (nextFlushedExpirationTime = 1), + performWorkOnRoot(root, 1, !1)) + : 1 === expirationTime + ? performWork(1, null) + : scheduleCallbackWithExpirationTime(expirationTime)); +} +function findHighestPriorityRoot() { + var highestPriorityWork = 0, + highestPriorityRoot = null; + if (null !== lastScheduledRoot) + for ( + var previousScheduledRoot = lastScheduledRoot, root = firstScheduledRoot; + null !== root; - ) { - var effectTag$jscomp$0 = nextEffect.effectTag; - effectTag$jscomp$0 & 36 && - commitLifeCycles( - firstEffect, - nextEffect.alternate, - nextEffect, - didError, - error - ); - effectTag$jscomp$0 & 128 && commitAttachRef(nextEffect); - var next = nextEffect.nextEffect; - nextEffect.nextEffect = null; - nextEffect = next; - } - } catch (e) { - (effectTag = !0), (current = e); + ) { + var remainingExpirationTime = root.expirationTime; + if (0 === remainingExpirationTime) { + invariant( + null !== previousScheduledRoot && null !== lastScheduledRoot, + "Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue." + ); + if (root === root.nextScheduledRoot) { + firstScheduledRoot = lastScheduledRoot = root.nextScheduledRoot = null; + break; + } else if (root === firstScheduledRoot) + (firstScheduledRoot = remainingExpirationTime = + root.nextScheduledRoot), + (lastScheduledRoot.nextScheduledRoot = remainingExpirationTime), + (root.nextScheduledRoot = null); + else if (root === lastScheduledRoot) { + lastScheduledRoot = previousScheduledRoot; + lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; + root.nextScheduledRoot = null; + break; + } else + (previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot), + (root.nextScheduledRoot = null); + root = previousScheduledRoot.nextScheduledRoot; + } else { + if ( + 0 === highestPriorityWork || + remainingExpirationTime < highestPriorityWork + ) + (highestPriorityWork = remainingExpirationTime), + (highestPriorityRoot = root); + if (root === lastScheduledRoot) break; + previousScheduledRoot = root; + root = root.nextScheduledRoot; } - effectTag && - (invariant( - null !== nextEffect, - "Should have next effect. This error is likely caused by a bug in React. Please file an issue." - ), - onCommitPhaseError(nextEffect, current), - null !== nextEffect && (nextEffect = nextEffect.nextEffect)); } - isWorking = isCommitting = !1; - "function" === typeof onCommitRoot && onCommitRoot(finishedWork.stateNode); - finishedWork = expirationTime.current.expirationTime; - 0 === finishedWork && (legacyErrorBoundariesThatAlreadyFailed = null); - root.remainingExpirationTime = finishedWork; - } - function shouldYield() { - return null === deadline || - deadline.timeRemaining() > timeHeuristicForUnitOfWork - ? !1 - : (deadlineDidExpire = !0); - } - function onUncaughtError(error) { - invariant( - null !== nextFlushedRoot, - "Should be working on a root. This error is likely caused by a bug in React. Please file an issue." - ); - nextFlushedRoot.remainingExpirationTime = 0; - hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error)); - } - function onBlock(remainingExpirationTime) { - invariant( - null !== nextFlushedRoot, - "Should be working on a root. This error is likely caused by a bug in React. Please file an issue." - ); - nextFlushedRoot.remainingExpirationTime = remainingExpirationTime; - } - var now = config.now, - scheduleDeferredCallback = config.scheduleDeferredCallback, - cancelDeferredCallback = config.cancelDeferredCallback, - prepareForCommit = config.prepareForCommit, - resetAfterCommit = config.resetAfterCommit, - stack = ReactFiberStack(), - hostContext = ReactFiberHostContext(config, stack), - legacyContext = ReactFiberLegacyContext(stack); - stack = ReactFiberNewContext(stack, config.isPrimaryRenderer); - var profilerTimer = createProfilerTimer(now), - hydrationContext = ReactFiberHydrationContext(config), - beginWork = ReactFiberBeginWork( - config, - hostContext, - legacyContext, - stack, - hydrationContext, - scheduleWork, - computeExpirationForFiber, - profilerTimer, - recalculateCurrentTime - ).beginWork, - completeWork = ReactFiberCompleteWork( - config, - hostContext, - legacyContext, - stack, - hydrationContext, - profilerTimer - ).completeWork; - hostContext = ReactFiberUnwindWork( - config, - hostContext, - legacyContext, - stack, - scheduleWork, - computeExpirationForFiber, - recalculateCurrentTime, - markLegacyErrorBoundaryAsFailed, - isAlreadyFailedLegacyErrorBoundary, - onUncaughtError, - profilerTimer, - function(root, thenable, timeoutMs) { - 0 <= timeoutMs && - nextLatestTimeoutMs < timeoutMs && - (nextLatestTimeoutMs = timeoutMs); - }, - retrySuspendedRoot - ); - var throwException = hostContext.throwException, - unwindWork = hostContext.unwindWork, - unwindInterruptedWork = hostContext.unwindInterruptedWork, - createRootErrorUpdate = hostContext.createRootErrorUpdate, - createClassErrorUpdate = hostContext.createClassErrorUpdate; - config = ReactFiberCommitWork( - config, - onCommitPhaseError, - scheduleWork, - computeExpirationForFiber, - markLegacyErrorBoundaryAsFailed, - recalculateCurrentTime - ); - var commitBeforeMutationLifeCycles = config.commitBeforeMutationLifeCycles, - commitResetTextContent = config.commitResetTextContent, - commitPlacement = config.commitPlacement, - commitDeletion = config.commitDeletion, - commitWork = config.commitWork, - commitLifeCycles = config.commitLifeCycles, - commitAttachRef = config.commitAttachRef, - commitDetachRef = config.commitDetachRef, - originalStartTimeMs = now(), - mostRecentCurrentTime = 2, - mostRecentCurrentTimeMs = originalStartTimeMs, - lastUniqueAsyncExpiration = 0, - expirationContext = 0, - isWorking = !1, - nextUnitOfWork = null, - nextRoot = null, - nextRenderExpirationTime = 0, - nextLatestTimeoutMs = -1, - nextRenderIsExpired = !1, - nextEffect = null, - isCommitting = !1, - isRootReadyForCommit = !1, - legacyErrorBoundariesThatAlreadyFailed = null, - firstScheduledRoot = null, - lastScheduledRoot = null, - callbackExpirationTime = 0, - callbackID = -1, - isRendering = !1, - nextFlushedRoot = null, - nextFlushedExpirationTime = 0, - lowestPendingInteractiveExpirationTime = 0, - deadlineDidExpire = !1, - hasUnhandledError = !1, - unhandledError = null, - deadline = null, - isBatchingUpdates = !1, - isUnbatchingUpdates = !1, - isBatchingInteractiveUpdates = !1, - completedBatches = null, - NESTED_UPDATE_LIMIT = 1e3, - nestedUpdateCount = 0, - timeHeuristicForUnitOfWork = 1; - return { - recalculateCurrentTime: recalculateCurrentTime, - computeExpirationForFiber: computeExpirationForFiber, - scheduleWork: scheduleWork, - requestWork: requestWork, - flushRoot: function(root, expirationTime) { - invariant( - !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) { - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = !0; - try { - return fn(a); - } finally { - (isBatchingUpdates = previousIsBatchingUpdates) || - isRendering || - performSyncWork(); - } - }, - unbatchedUpdates: function(fn, a) { - if (isBatchingUpdates && !isUnbatchingUpdates) { - isUnbatchingUpdates = !0; - try { - return fn(a); - } finally { - isUnbatchingUpdates = !1; - } - } - return fn(a); - }, - flushSync: function(fn, a) { - invariant( - !isRendering, - "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." - ); - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = !0; - try { - return syncUpdates(fn, a); - } finally { - (isBatchingUpdates = previousIsBatchingUpdates), performSyncWork(); - } - }, - flushControlled: function(fn) { - var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = !0; - try { - syncUpdates(fn); - } finally { - (isBatchingUpdates = previousIsBatchingUpdates) || - isRendering || - performWork(1, !1, null); - } - }, - deferredUpdates: function(fn) { - var previousExpirationContext = expirationContext; - expirationContext = - 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); - try { - return fn(); - } finally { - expirationContext = previousExpirationContext; - } - }, - syncUpdates: syncUpdates, - interactiveUpdates: function(fn, a, b) { - if (isBatchingInteractiveUpdates) return fn(a, b); - isBatchingUpdates || - isRendering || - 0 === lowestPendingInteractiveExpirationTime || - (performWork(lowestPendingInteractiveExpirationTime, !1, null), - (lowestPendingInteractiveExpirationTime = 0)); - var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates, - previousIsBatchingUpdates = isBatchingUpdates; - isBatchingUpdates = isBatchingInteractiveUpdates = !0; - try { - return fn(a, b); - } finally { - (isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates), - (isBatchingUpdates = previousIsBatchingUpdates) || - isRendering || - performSyncWork(); - } - }, - flushInteractiveUpdates: function() { - isRendering || - 0 === lowestPendingInteractiveExpirationTime || - (performWork(lowestPendingInteractiveExpirationTime, !1, null), - (lowestPendingInteractiveExpirationTime = 0)); - }, - computeUniqueAsyncExpiration: function() { - var result = - 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); - result <= lastUniqueAsyncExpiration && - (result = lastUniqueAsyncExpiration + 1); - return (lastUniqueAsyncExpiration = result); - }, - legacyContext: legacyContext - }; + previousScheduledRoot = nextFlushedRoot; + null !== previousScheduledRoot && + previousScheduledRoot === highestPriorityRoot && + 1 === highestPriorityWork + ? nestedUpdateCount++ + : (nestedUpdateCount = 0); + nextFlushedRoot = highestPriorityRoot; + nextFlushedExpirationTime = highestPriorityWork; } -function ReactFiberReconciler$1(config) { - function updateContainerAtExpirationTime( - element, - container, - parentComponent, - expirationTime, - callback - ) { - var current = container.current; - if (parentComponent) { - parentComponent = parentComponent._reactInternalFiber; - var parentContext = findCurrentUnmaskedContext(parentComponent); - parentComponent = isContextProvider(parentComponent) - ? processChildContext(parentComponent, parentContext) - : parentContext; - } else parentComponent = emptyObject; - null === container.context - ? (container.context = parentComponent) - : (container.pendingContext = parentComponent); - container = callback; - callback = createUpdate(expirationTime); - callback.payload = { element: element }; - container = void 0 === container ? null : container; - null !== container && (callback.callback = container); - enqueueUpdate(current, callback, expirationTime); - scheduleWork(current, expirationTime); - return expirationTime; - } - var getPublicInstance = config.getPublicInstance; - 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; - return { - createContainer: function(containerInfo, isAsync, hydrate) { - isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0); - containerInfo = { - current: isAsync, - containerInfo: containerInfo, - pendingChildren: null, - earliestPendingTime: 0, - latestPendingTime: 0, - earliestSuspendedTime: 0, - latestSuspendedTime: 0, - latestPingedTime: 0, - pendingCommitExpirationTime: 0, - finishedWork: null, - context: null, - pendingContext: null, - hydrate: hydrate, - remainingExpirationTime: 0, - firstBatch: null, - nextScheduledRoot: null - }; - return (isAsync.stateNode = containerInfo); - }, - updateContainer: function(element, container, parentComponent, callback) { - var current = container.current, - currentTime = recalculateCurrentTime(); - current = computeExpirationForFiber(currentTime, current); - return updateContainerAtExpirationTime( - element, - container, - parentComponent, - current, - callback - ); - }, - updateContainerAtExpirationTime: function( - element, - container, - parentComponent, - expirationTime, - callback - ) { - return updateContainerAtExpirationTime( - element, - container, - parentComponent, - expirationTime, - callback - ); - }, - flushRoot: config.flushRoot, - requestWork: config.requestWork, - computeUniqueAsyncExpiration: config.computeUniqueAsyncExpiration, - batchedUpdates: config.batchedUpdates, - unbatchedUpdates: config.unbatchedUpdates, - deferredUpdates: config.deferredUpdates, - syncUpdates: config.syncUpdates, - interactiveUpdates: config.interactiveUpdates, - flushInteractiveUpdates: config.flushInteractiveUpdates, - flushControlled: config.flushControlled, - flushSync: config.flushSync, - getPublicRootInstance: function(container) { - container = container.current; - if (!container.child) return null; - switch (container.child.tag) { - case 5: - return getPublicInstance(container.child.stateNode); - default: - return container.child.stateNode; +function performAsyncWork(dl) { + performWork(0, dl); +} +function performWork(minExpirationTime, dl) { + deadline = dl; + findHighestPriorityRoot(); + if (null !== deadline) + for ( + ; + null !== nextFlushedRoot && + 0 !== nextFlushedExpirationTime && + (0 === minExpirationTime || + minExpirationTime >= nextFlushedExpirationTime) && + (!deadlineDidExpire || + recalculateCurrentTime() >= nextFlushedExpirationTime); + + ) + recalculateCurrentTime(), + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !0), + findHighestPriorityRoot(); + else + for ( + ; + null !== nextFlushedRoot && + 0 !== nextFlushedExpirationTime && + (0 === minExpirationTime || + minExpirationTime >= nextFlushedExpirationTime); + + ) + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !1), + findHighestPriorityRoot(); + null !== deadline && ((callbackExpirationTime = 0), (callbackID = null)); + 0 !== nextFlushedExpirationTime && + scheduleCallbackWithExpirationTime(nextFlushedExpirationTime); + deadline = null; + deadlineDidExpire = !1; + finishRendering(); +} +function finishRendering() { + nestedUpdateCount = 0; + if (null !== completedBatches) { + var batches = completedBatches; + completedBatches = null; + for (var i = 0; i < batches.length; i++) { + var batch = batches[i]; + try { + batch._onComplete(); + } catch (error) { + hasUnhandledError || + ((hasUnhandledError = !0), (unhandledError = error)); } - }, - findHostInstance: function(component) { - var fiber = component._reactInternalFiber; - void 0 === fiber && - ("function" === typeof component.render - ? invariant(!1, "Unable to find node on an unmounted component.") - : invariant( - !1, - "Argument appears to not be a ReactComponent. Keys: %s", - Object.keys(component) - )); - component = findCurrentHostFiber(fiber); - return null === component ? null : component.stateNode; - }, - findHostInstanceWithNoPortals: function(fiber) { - fiber = findCurrentHostFiberWithNoPortals(fiber); - return null === fiber ? null : fiber.stateNode; - }, - injectIntoDevTools: function(devToolsConfig) { - var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; - return injectInternals( - Object.assign({}, devToolsConfig, { - findHostInstanceByFiber: function(fiber) { - fiber = findCurrentHostFiber(fiber); - return null === fiber ? null : fiber.stateNode; - }, - findFiberByHostInstance: function(instance) { - return findFiberByHostInstance - ? findFiberByHostInstance(instance) - : null; - } - }) - ); } - }; + } + if (hasUnhandledError) + throw ((batches = unhandledError), + (unhandledError = null), + (hasUnhandledError = !1), + batches); } -var ReactFiberReconciler$2 = Object.freeze({ default: ReactFiberReconciler$1 }), - ReactFiberReconciler$3 = - (ReactFiberReconciler$2 && ReactFiberReconciler$1) || - ReactFiberReconciler$2, - reactReconciler = ReactFiberReconciler$3.default - ? ReactFiberReconciler$3.default - : ReactFiberReconciler$3; -function createPortal(children, containerInfo, implementation) { - var key = - 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null; - return { - $$typeof: REACT_PORTAL_TYPE, - key: null == key ? null : "" + key, - children: children, - containerInfo: containerInfo, - implementation: implementation - }; +function performWorkOnRoot(root, expirationTime, isYieldy) { + invariant( + !isRendering, + "performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." + ); + isRendering = !0; + isYieldy + ? ((isYieldy = root.finishedWork), + null !== isYieldy + ? completeRoot(root, isYieldy, expirationTime) + : ((root.finishedWork = null), + renderRoot(root, !0), + (isYieldy = root.finishedWork), + null !== isYieldy && + (shouldYield() + ? (root.finishedWork = isYieldy) + : completeRoot(root, isYieldy, expirationTime)))) + : ((isYieldy = root.finishedWork), + null !== isYieldy + ? completeRoot(root, isYieldy, expirationTime) + : ((root.finishedWork = null), + renderRoot(root, !1), + (isYieldy = root.finishedWork), + null !== isYieldy && completeRoot(root, isYieldy, expirationTime))); + isRendering = !1; } -var emptyObject$1 = {}, - removedKeys = null, - removedKeyCount = 0; -function restoreDeletedValuesInNestedArray( - updatePayload, - node, - validAttributes -) { - if (Array.isArray(node)) - for (var i = node.length; i-- && 0 < removedKeyCount; ) - restoreDeletedValuesInNestedArray( - updatePayload, - node[i], - validAttributes - ); - else if (node && 0 < removedKeyCount) - for (i in removedKeys) - if (removedKeys[i]) { - var _nextProp = node[i]; - if (void 0 !== _nextProp) { - var attributeConfig = validAttributes[i]; - if (attributeConfig) { - "function" === typeof _nextProp && (_nextProp = !0); - "undefined" === typeof _nextProp && (_nextProp = null); - if ("object" !== typeof attributeConfig) - updatePayload[i] = _nextProp; - else if ( - "function" === typeof attributeConfig.diff || - "function" === typeof attributeConfig.process - ) - (_nextProp = - "function" === typeof attributeConfig.process - ? attributeConfig.process(_nextProp) - : _nextProp), - (updatePayload[i] = _nextProp); - removedKeys[i] = !1; - removedKeyCount--; +function completeRoot(root, finishedWork$jscomp$0, expirationTime) { + var firstBatch = root.firstBatch; + if ( + null !== firstBatch && + firstBatch._expirationTime <= expirationTime && + (null === completedBatches + ? (completedBatches = [firstBatch]) + : completedBatches.push(firstBatch), + firstBatch._defer) + ) { + root.finishedWork = finishedWork$jscomp$0; + root.expirationTime = 0; + return; + } + root.finishedWork = null; + isCommitting$1 = isWorking = !0; + invariant( + root.current !== finishedWork$jscomp$0, + "Cannot commit the same tree as before. This is probably a bug related to the return field. This error is likely caused by a bug in React. Please file an issue." + ); + expirationTime = root.pendingCommitExpirationTime; + invariant( + 0 !== expirationTime, + "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." + ); + root.pendingCommitExpirationTime = 0; + firstBatch = finishedWork$jscomp$0.expirationTime; + recalculateCurrentTime(); + root.didError = !1; + if (0 === firstBatch) + (root.earliestPendingTime = 0), + (root.latestPendingTime = 0), + (root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0); + else { + var latestPendingTime = root.latestPendingTime; + 0 !== latestPendingTime && + (latestPendingTime < firstBatch + ? (root.earliestPendingTime = root.latestPendingTime = 0) + : root.earliestPendingTime < firstBatch && + (root.earliestPendingTime = root.latestPendingTime)); + latestPendingTime = root.earliestSuspendedTime; + 0 === latestPendingTime + ? markPendingPriorityLevel(root, firstBatch) + : firstBatch > root.latestSuspendedTime + ? ((root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0), + markPendingPriorityLevel(root, firstBatch)) + : firstBatch < latestPendingTime && + markPendingPriorityLevel(root, firstBatch); + } + findNextPendingPriorityLevel(root); + ReactCurrentOwner.current = null; + 1 < finishedWork$jscomp$0.effectTag + ? null !== finishedWork$jscomp$0.lastEffect + ? ((finishedWork$jscomp$0.lastEffect.nextEffect = finishedWork$jscomp$0), + (firstBatch = finishedWork$jscomp$0.firstEffect)) + : (firstBatch = finishedWork$jscomp$0) + : (firstBatch = finishedWork$jscomp$0.firstEffect); + for (nextEffect = firstBatch; null !== nextEffect; ) { + latestPendingTime = !1; + var error = void 0; + try { + for (; null !== nextEffect; ) { + if (nextEffect.effectTag & 256) { + var current = nextEffect.alternate, + finishedWork = nextEffect; + switch (finishedWork.tag) { + case 2: + if (finishedWork.effectTag & 256 && null !== current) { + var prevProps = current.memoizedProps, + prevState = current.memoizedState, + instance = finishedWork.stateNode; + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + var snapshot = instance.getSnapshotBeforeUpdate( + prevProps, + prevState + ); + instance.__reactInternalSnapshotBeforeUpdate = snapshot; + } + 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." + ); } } + nextEffect = nextEffect.nextEffect; } -} -function diffNestedProperty( - updatePayload, - prevProp, - nextProp, - validAttributes -) { - if (!updatePayload && prevProp === nextProp) return updatePayload; - if (!prevProp || !nextProp) - return nextProp - ? addNestedProperty(updatePayload, nextProp, validAttributes) - : prevProp - ? clearNestedProperty(updatePayload, prevProp, validAttributes) - : updatePayload; - if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) - return diffProperties(updatePayload, prevProp, nextProp, validAttributes); - if (Array.isArray(prevProp) && Array.isArray(nextProp)) { - var minLength = - prevProp.length < nextProp.length ? prevProp.length : nextProp.length, - i; - for (i = 0; i < minLength; i++) - updatePayload = diffNestedProperty( - updatePayload, - prevProp[i], - nextProp[i], - validAttributes - ); - for (; i < prevProp.length; i++) - updatePayload = clearNestedProperty( - updatePayload, - prevProp[i], - validAttributes - ); - for (; i < nextProp.length; i++) - updatePayload = addNestedProperty( - updatePayload, - nextProp[i], - validAttributes - ); - return updatePayload; + } catch (e) { + (latestPendingTime = !0), (error = e); + } + latestPendingTime && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, error), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); } - return Array.isArray(prevProp) - ? diffProperties( - updatePayload, - flattenStyle(prevProp), - nextProp, - validAttributes - ) - : diffProperties( - updatePayload, - prevProp, - flattenStyle(nextProp), - validAttributes - ); -} -function addNestedProperty(updatePayload, nextProp, validAttributes) { - if (!nextProp) return updatePayload; - if (!Array.isArray(nextProp)) - return diffProperties( - updatePayload, - emptyObject$1, - nextProp, - validAttributes - ); - for (var i = 0; i < nextProp.length; i++) - updatePayload = addNestedProperty( - updatePayload, - nextProp[i], - validAttributes - ); - return updatePayload; -} -function clearNestedProperty(updatePayload, prevProp, validAttributes) { - if (!prevProp) return updatePayload; - if (!Array.isArray(prevProp)) - return diffProperties( - updatePayload, - prevProp, - emptyObject$1, - validAttributes - ); - for (var i = 0; i < prevProp.length; i++) - updatePayload = clearNestedProperty( - updatePayload, - prevProp[i], - validAttributes - ); - return updatePayload; -} -function diffProperties(updatePayload, prevProps, nextProps, validAttributes) { - var attributeConfig, propKey; - for (propKey in nextProps) - if ((attributeConfig = validAttributes[propKey])) { - var prevProp = prevProps[propKey]; - var nextProp = nextProps[propKey]; - "function" === typeof nextProp && - ((nextProp = !0), "function" === typeof prevProp && (prevProp = !0)); - "undefined" === typeof nextProp && - ((nextProp = null), - "undefined" === typeof prevProp && (prevProp = null)); - removedKeys && (removedKeys[propKey] = !1); - if (updatePayload && void 0 !== updatePayload[propKey]) - if ("object" !== typeof attributeConfig) - updatePayload[propKey] = nextProp; - else { - if ( - "function" === typeof attributeConfig.diff || - "function" === typeof attributeConfig.process - ) - (attributeConfig = - "function" === typeof attributeConfig.process - ? attributeConfig.process(nextProp) - : nextProp), - (updatePayload[propKey] = attributeConfig); + for (nextEffect = firstBatch; null !== nextEffect; ) { + current = !1; + prevProps = void 0; + try { + for (; null !== nextEffect; ) { + var effectTag = nextEffect.effectTag; + if (effectTag & 128) { + var current$jscomp$0 = nextEffect.alternate; + if (null !== current$jscomp$0) { + var currentRef = current$jscomp$0.ref; + null !== currentRef && + ("function" === typeof currentRef + ? currentRef(null) + : (currentRef.current = null)); + } } - else if (prevProp !== nextProp) - if ("object" !== typeof attributeConfig) - ("object" !== typeof nextProp || - null === nextProp || - deepDiffer(prevProp, nextProp)) && - ((updatePayload || (updatePayload = {}))[propKey] = nextProp); - else if ( - "function" === typeof attributeConfig.diff || - "function" === typeof attributeConfig.process - ) { - if ( - void 0 === prevProp || - ("function" === typeof attributeConfig.diff - ? attributeConfig.diff(prevProp, nextProp) - : "object" !== typeof nextProp || - null === nextProp || - deepDiffer(prevProp, nextProp)) - ) - (attributeConfig = - "function" === typeof attributeConfig.process - ? attributeConfig.process(nextProp) - : nextProp), - ((updatePayload || (updatePayload = {}))[ - propKey - ] = attributeConfig); - } else - (removedKeys = null), - (removedKeyCount = 0), - (updatePayload = diffNestedProperty( - updatePayload, - prevProp, - nextProp, - attributeConfig - )), - 0 < removedKeyCount && - updatePayload && - (restoreDeletedValuesInNestedArray( - updatePayload, - nextProp, - attributeConfig - ), - (removedKeys = null)); + switch (effectTag & 14) { + case 2: + commitPlacement(nextEffect); + nextEffect.effectTag &= -3; + break; + case 6: + commitPlacement(nextEffect); + nextEffect.effectTag &= -3; + commitWork(nextEffect.alternate, nextEffect); + break; + case 4: + commitWork(nextEffect.alternate, nextEffect); + break; + case 8: + (prevState = nextEffect), + unmountHostComponents(prevState), + (prevState.return = null), + (prevState.child = null), + prevState.alternate && + ((prevState.alternate.child = null), + (prevState.alternate.return = null)); + } + nextEffect = nextEffect.nextEffect; + } + } catch (e) { + (current = !0), (prevProps = e); + } + current && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, prevProps), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + root.current = finishedWork$jscomp$0; + for (nextEffect = firstBatch; null !== nextEffect; ) { + effectTag = !1; + current$jscomp$0 = void 0; + try { + for (currentRef = expirationTime; null !== nextEffect; ) { + var effectTag$jscomp$0 = nextEffect.effectTag; + if (effectTag$jscomp$0 & 36) { + var current$jscomp$1 = nextEffect.alternate; + current = nextEffect; + prevProps = currentRef; + switch (current.tag) { + case 2: + var instance$jscomp$0 = current.stateNode; + if (current.effectTag & 4) + if (null === current$jscomp$1) + (instance$jscomp$0.props = current.memoizedProps), + (instance$jscomp$0.state = current.memoizedState), + instance$jscomp$0.componentDidMount(); + else { + var prevProps$jscomp$0 = current$jscomp$1.memoizedProps, + prevState$jscomp$0 = current$jscomp$1.memoizedState; + instance$jscomp$0.props = current.memoizedProps; + instance$jscomp$0.state = current.memoizedState; + instance$jscomp$0.componentDidUpdate( + prevProps$jscomp$0, + prevState$jscomp$0, + instance$jscomp$0.__reactInternalSnapshotBeforeUpdate + ); + } + var updateQueue = current.updateQueue; + null !== updateQueue && + ((instance$jscomp$0.props = current.memoizedProps), + (instance$jscomp$0.state = current.memoizedState), + commitUpdateQueue( + current, + updateQueue, + instance$jscomp$0, + prevProps + )); + break; + case 3: + var _updateQueue = current.updateQueue; + if (null !== _updateQueue) { + prevState = null; + if (null !== current.child) + switch (current.child.tag) { + case 5: + prevState = current.child.stateNode; + break; + case 2: + prevState = current.child.stateNode; + } + commitUpdateQueue(current, _updateQueue, prevState, prevProps); + } + break; + case 5: + break; + case 6: + break; + case 4: + break; + case 15: + break; + case 16: + 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." + ); + } + } + if (effectTag$jscomp$0 & 128) { + current = void 0; + var ref = nextEffect.ref; + if (null !== ref) { + var instance$jscomp$1 = nextEffect.stateNode; + switch (nextEffect.tag) { + case 5: + current = instance$jscomp$1; + break; + default: + current = instance$jscomp$1; + } + "function" === typeof ref ? ref(current) : (ref.current = current); + } + } + var next = nextEffect.nextEffect; + nextEffect.nextEffect = null; + nextEffect = next; + } + } catch (e) { + (effectTag = !0), (current$jscomp$0 = e); } - for (var _propKey in prevProps) - void 0 === nextProps[_propKey] && - (!(attributeConfig = validAttributes[_propKey]) || - (updatePayload && void 0 !== updatePayload[_propKey]) || - ((prevProp = prevProps[_propKey]), - void 0 !== prevProp && - ("object" !== typeof attributeConfig || - "function" === typeof attributeConfig.diff || - "function" === typeof attributeConfig.process - ? (((updatePayload || (updatePayload = {}))[_propKey] = null), - removedKeys || (removedKeys = {}), - removedKeys[_propKey] || - ((removedKeys[_propKey] = !0), removedKeyCount++)) - : (updatePayload = clearNestedProperty( - updatePayload, - prevProp, - attributeConfig - ))))); - return updatePayload; + effectTag && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, current$jscomp$0), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + isWorking = isCommitting$1 = !1; + "function" === typeof onCommitRoot && + onCommitRoot(finishedWork$jscomp$0.stateNode); + finishedWork$jscomp$0 = root.expirationTime; + 0 === finishedWork$jscomp$0 && + (legacyErrorBoundariesThatAlreadyFailed = null); + root.expirationTime = finishedWork$jscomp$0; + root.finishedWork = null; } -function mountSafeCallback(context, callback) { - return function() { - if (callback) { - if ("boolean" === typeof context.__isMounted) { - if (!context.__isMounted) return; - } else if ( - "function" === typeof context.isMounted && - !context.isMounted() - ) - return; - return callback.apply(context, arguments); - } - }; +function shouldYield() { + return null === deadline || + deadlineDidExpire || + deadline.timeRemaining() > timeHeuristicForUnitOfWork + ? !1 + : (deadlineDidExpire = !0); } -var ReactNativeFiberHostComponent = (function() { - function ReactNativeFiberHostComponent(tag, viewConfig) { - if (!(this instanceof ReactNativeFiberHostComponent)) - throw new TypeError("Cannot call a class as a function"); - this._nativeTag = tag; - this._children = []; - this.viewConfig = viewConfig; - } - ReactNativeFiberHostComponent.prototype.blur = function() { - TextInputState.blurTextInput(this._nativeTag); - }; - ReactNativeFiberHostComponent.prototype.focus = function() { - TextInputState.focusTextInput(this._nativeTag); - }; - ReactNativeFiberHostComponent.prototype.measure = function(callback) { - UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); - }; - ReactNativeFiberHostComponent.prototype.measureInWindow = function( - callback - ) { - UIManager.measureInWindow( - this._nativeTag, - mountSafeCallback(this, callback) - ); - }; - ReactNativeFiberHostComponent.prototype.measureLayout = function( - relativeToNativeNode, - onSuccess, - onFail - ) { - UIManager.measureLayout( - this._nativeTag, - relativeToNativeNode, - mountSafeCallback(this, onFail), - mountSafeCallback(this, onSuccess) - ); - }; - ReactNativeFiberHostComponent.prototype.setNativeProps = function( - nativeProps - ) { - nativeProps = diffProperties( - null, - emptyObject$1, - nativeProps, - this.viewConfig.validAttributes +function onUncaughtError(error) { + invariant( + null !== nextFlushedRoot, + "Should be working on a root. This error is likely caused by a bug in React. Please file an issue." + ); + nextFlushedRoot.expirationTime = 0; + hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error)); +} +function updateContainerAtExpirationTime( + element, + container, + parentComponent, + expirationTime, + callback +) { + var current = container.current; + if (parentComponent) { + parentComponent = parentComponent._reactInternalFiber; + var parentContext; + b: { + invariant( + 2 === isFiberMountedImpl(parentComponent) && 2 === parentComponent.tag, + "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." ); - null != nativeProps && - UIManager.updateView( - this._nativeTag, - this.viewConfig.uiViewClassName, - nativeProps - ); - }; - return ReactNativeFiberHostComponent; - })(), - now = - "object" === typeof performance && "function" === typeof performance.now - ? function() { - return performance.now(); + for (parentContext = parentComponent; 3 !== parentContext.tag; ) { + if (isContextProvider(parentContext)) { + parentContext = + parentContext.stateNode.__reactInternalMemoizedMergedChildContext; + break b; } - : function() { - return Date.now(); - }, - scheduledCallback = null, - frameDeadline = 0, - frameDeadlineObject = { - timeRemaining: function() { - return frameDeadline - now(); - }, - didTimeout: !1 - }; -function setTimeoutCallback() { - frameDeadline = now() + 5; - var callback = scheduledCallback; - scheduledCallback = null; - null !== callback && callback(frameDeadlineObject); + 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; + } else parentComponent = emptyObject; + null === container.context + ? (container.context = parentComponent) + : (container.pendingContext = parentComponent); + container = callback; + callback = createUpdate(expirationTime); + callback.payload = { element: element }; + container = void 0 === container ? null : container; + null !== container && (callback.callback = container); + enqueueUpdate(current, callback, expirationTime); + scheduleWork(current, expirationTime); + return expirationTime; } -var nextReactTag = 3; -function allocateTag() { - var tag = nextReactTag; - 1 === tag % 10 && (tag += 2); - nextReactTag = tag + 2; - return tag; +function findHostInstance$1(component) { + var fiber = component._reactInternalFiber; + void 0 === fiber && + ("function" === typeof component.render + ? invariant(!1, "Unable to find node on an unmounted component.") + : invariant( + !1, + "Argument appears to not be a ReactComponent. Keys: %s", + Object.keys(component) + )); + component = findCurrentHostFiber(fiber); + return null === component ? null : component.stateNode; } -function recursivelyUncacheFiberNode(node) { - "number" === typeof node - ? uncacheFiberNode(node) - : (uncacheFiberNode(node._nativeTag), - node._children.forEach(recursivelyUncacheFiberNode)); +function updateContainer(element, container, parentComponent, callback) { + var current = container.current, + currentTime = recalculateCurrentTime(); + current = computeExpirationForFiber(currentTime, current); + return updateContainerAtExpirationTime( + element, + container, + parentComponent, + current, + callback + ); } -var ReactNativeHostConfig = { - appendInitialChild: function(parentInstance, child) { - parentInstance._children.push(child); - }, - createInstance: function( - type, - props, - rootContainerInstance, - hostContext, - internalInstanceHandle - ) { - var tag = allocateTag(), - viewConfig = ReactNativeViewConfigRegistry.get(type); - invariant( - "RCTView" !== type || !hostContext.isInAParentText, - "Nesting of within is not currently supported." - ); - type = diffProperties( - null, - emptyObject$1, - props, - viewConfig.validAttributes - ); - UIManager.createView( - tag, - viewConfig.uiViewClassName, - rootContainerInstance, - type - ); - rootContainerInstance = new ReactNativeFiberHostComponent(tag, viewConfig); - instanceCache[tag] = internalInstanceHandle; - instanceProps[tag] = props; - return rootContainerInstance; +function getPublicRootInstance(container) { + container = container.current; + if (!container.child) return null; + switch (container.child.tag) { + case 5: + return container.child.stateNode; + default: + return container.child.stateNode; + } +} +function injectIntoDevTools(devToolsConfig) { + var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; + return injectInternals( + Object.assign({}, devToolsConfig, { + findHostInstanceByFiber: function(fiber) { + fiber = findCurrentHostFiber(fiber); + return null === fiber ? null : fiber.stateNode; + }, + findFiberByHostInstance: function(instance) { + return findFiberByHostInstance + ? findFiberByHostInstance(instance) + : null; + } + }) + ); +} +var ReactNativeFiberRenderer = { + updateContainerAtExpirationTime: updateContainerAtExpirationTime, + createContainer: function(containerInfo, isAsync, hydrate) { + return createFiberRoot(containerInfo, isAsync, hydrate); }, - createTextInstance: function( - text, - rootContainerInstance, - hostContext, - internalInstanceHandle - ) { + updateContainer: updateContainer, + flushRoot: function(root, expirationTime) { invariant( - hostContext.isInAParentText, - "Text strings must be rendered within a component." + !isRendering, + "work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method." ); - hostContext = allocateTag(); - UIManager.createView(hostContext, "RCTRawText", rootContainerInstance, { - text: text - }); - instanceCache[hostContext] = internalInstanceHandle; - return hostContext; + nextFlushedRoot = root; + nextFlushedExpirationTime = expirationTime; + performWorkOnRoot(root, expirationTime, !1); + performWork(1, null); + finishRendering(); }, - finalizeInitialChildren: function(parentInstance) { - if (0 === parentInstance._children.length) return !1; - var nativeTags = parentInstance._children.map(function(child) { - return "number" === typeof child ? child : child._nativeTag; - }); - UIManager.setChildren(parentInstance._nativeTag, nativeTags); - return !1; + requestWork: requestWork, + computeUniqueAsyncExpiration: function() { + var result = + 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); + result <= lastUniqueAsyncExpiration && + (result = lastUniqueAsyncExpiration + 1); + return (lastUniqueAsyncExpiration = result); }, - getRootHostContext: function() { - return { isInAParentText: !1 }; + batchedUpdates: function(fn, a) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + return fn(a); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } }, - getChildHostContext: function(parentHostContext, type) { - type = - "AndroidTextInput" === type || - "RCTMultilineTextInputView" === type || - "RCTSinglelineTextInputView" === type || - "RCTText" === type || - "RCTVirtualText" === type; - return parentHostContext.isInAParentText !== type - ? { isInAParentText: type } - : parentHostContext; + unbatchedUpdates: function(fn, a) { + if (isBatchingUpdates && !isUnbatchingUpdates) { + isUnbatchingUpdates = !0; + try { + return fn(a); + } finally { + isUnbatchingUpdates = !1; + } + } + return fn(a); }, - getPublicInstance: function(instance) { - return instance; + deferredUpdates: function(fn) { + var previousExpirationContext = expirationContext; + expirationContext = + 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); + try { + return fn(); + } finally { + expirationContext = previousExpirationContext; + } }, - now: now, - isPrimaryRenderer: !0, - prepareForCommit: function() {}, - prepareUpdate: function() { - return emptyObject; + syncUpdates: syncUpdates, + interactiveUpdates: function(fn, a, b) { + if (isBatchingInteractiveUpdates) return fn(a, b); + isBatchingUpdates || + isRendering || + 0 === lowestPendingInteractiveExpirationTime || + (performWork(lowestPendingInteractiveExpirationTime, null), + (lowestPendingInteractiveExpirationTime = 0)); + var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates, + previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = isBatchingInteractiveUpdates = !0; + try { + return fn(a, b); + } finally { + (isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates), + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } }, - resetAfterCommit: function() {}, - scheduleDeferredCallback: function(callback) { - scheduledCallback = callback; - return setTimeout(setTimeoutCallback, 1); + flushInteractiveUpdates: function() { + isRendering || + 0 === lowestPendingInteractiveExpirationTime || + (performWork(lowestPendingInteractiveExpirationTime, null), + (lowestPendingInteractiveExpirationTime = 0)); }, - cancelDeferredCallback: function(callbackID) { - scheduledCallback = null; - clearTimeout(callbackID); + flushControlled: function(fn) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + syncUpdates(fn); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } }, - shouldDeprioritizeSubtree: function() { - return !1; + flushSync: function(fn, a) { + invariant( + !isRendering, + "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." + ); + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + return syncUpdates(fn, a); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates), performWork(1, null); + } }, - shouldSetTextContent: function() { - return !1; + getPublicRootInstance: getPublicRootInstance, + findHostInstance: findHostInstance$1, + findHostInstanceWithNoPortals: function(fiber) { + fiber = findCurrentHostFiberWithNoPortals(fiber); + return null === fiber ? null : fiber.stateNode; }, - mutation: { - appendChild: function(parentInstance, child) { - var childTag = "number" === typeof child ? child : child._nativeTag, - children = parentInstance._children, - index = children.indexOf(child); - 0 <= index - ? (children.splice(index, 1), - children.push(child), - UIManager.manageChildren( - parentInstance._nativeTag, - [index], - [children.length - 1], - [], - [], - [] - )) - : (children.push(child), - UIManager.manageChildren( - parentInstance._nativeTag, - [], - [], - [childTag], - [children.length - 1], - [] - )); - }, - appendChildToContainer: function(parentInstance, child) { - UIManager.setChildren(parentInstance, [ - "number" === typeof child ? child : child._nativeTag - ]); - }, - commitTextUpdate: function(textInstance, oldText, newText) { - UIManager.updateView(textInstance, "RCTRawText", { text: newText }); - }, - commitMount: function() {}, - commitUpdate: function( - instance, - updatePayloadTODO, - type, - oldProps, - newProps - ) { - updatePayloadTODO = instance.viewConfig; - instanceProps[instance._nativeTag] = newProps; - oldProps = diffProperties( - null, - oldProps, - newProps, - updatePayloadTODO.validAttributes - ); - null != oldProps && - UIManager.updateView( - instance._nativeTag, - updatePayloadTODO.uiViewClassName, - oldProps - ); - }, - insertBefore: function(parentInstance, child, beforeChild) { - var children = parentInstance._children, - index = children.indexOf(child); - 0 <= index - ? (children.splice(index, 1), - (beforeChild = children.indexOf(beforeChild)), - children.splice(beforeChild, 0, child), - UIManager.manageChildren( - parentInstance._nativeTag, - [index], - [beforeChild], - [], - [], - [] - )) - : ((index = children.indexOf(beforeChild)), - children.splice(index, 0, child), - UIManager.manageChildren( - parentInstance._nativeTag, - [], - [], - ["number" === typeof child ? child : child._nativeTag], - [index], - [] - )); - }, - insertInContainerBefore: function(parentInstance) { - invariant( - "number" !== typeof parentInstance, - "Container does not support insertBefore operation" - ); - }, - removeChild: function(parentInstance, child) { - recursivelyUncacheFiberNode(child); - var children = parentInstance._children; - child = children.indexOf(child); - children.splice(child, 1); - UIManager.manageChildren( - parentInstance._nativeTag, - [], - [], - [], - [], - [child] - ); - }, - removeChildFromContainer: function(parentInstance, child) { - recursivelyUncacheFiberNode(child); - UIManager.manageChildren(parentInstance, [], [], [], [], [0]); - }, - resetTextContent: function() {} - } + injectIntoDevTools: injectIntoDevTools }; +function createPortal(children, containerInfo, implementation) { + var key = + 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null; + return { + $$typeof: REACT_PORTAL_TYPE, + key: null == key ? null : "" + key, + children: children, + containerInfo: containerInfo, + implementation: implementation + }; +} function _inherits(subClass, superClass) { if ("function" !== typeof superClass && null !== superClass) throw new TypeError( @@ -6265,15 +5650,13 @@ var getInspectorDataForViewTag = void 0; getInspectorDataForViewTag = function() { invariant(!1, "getInspectorDataForViewTag() is not available in production"); }; -var ReactNativeFiberRenderer = reactReconciler(ReactNativeHostConfig), - findHostInstance = ReactNativeFiberRenderer.findHostInstance; function findNodeHandle(componentOrHandle) { if (null == componentOrHandle) return null; if ("number" === typeof componentOrHandle) return componentOrHandle; if (componentOrHandle._nativeTag) return componentOrHandle._nativeTag; if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) return componentOrHandle.canonical._nativeTag; - componentOrHandle = findHostInstance(componentOrHandle); + componentOrHandle = findHostInstance$1(componentOrHandle); return null == componentOrHandle ? componentOrHandle : componentOrHandle.canonical @@ -6354,24 +5737,20 @@ var roots = new Map(), }; return ReactNativeComponent; })(React.Component); - })(findNodeHandle, findHostInstance), + })(findNodeHandle, findHostInstance$1), findNodeHandle: findNodeHandle, render: function(element, containerTag, callback) { var root = roots.get(containerTag); root || - ((root = ReactNativeFiberRenderer.createContainer( - containerTag, - !1, - !1 - )), + ((root = createFiberRoot(containerTag, !1, !1)), roots.set(containerTag, root)); - ReactNativeFiberRenderer.updateContainer(element, root, null, callback); - return ReactNativeFiberRenderer.getPublicRootInstance(root); + updateContainer(element, root, null, callback); + return getPublicRootInstance(root); }, unmountComponentAtNode: function(containerTag) { var root = roots.get(containerTag); root && - ReactNativeFiberRenderer.updateContainer(null, root, null, function() { + updateContainer(null, root, null, function() { roots.delete(containerTag); }); }, @@ -6439,8 +5818,7 @@ var roots = new Map(), TextInputState.blurTextInput(findNodeHandle(this)); } }; - })(findNodeHandle, findHostInstance), - ReactNativeComponentTree: ReactNativeComponentTree, + })(findNodeHandle, findHostInstance$1), computeComponentStackForErrorReporting: function(reactTag) { return (reactTag = getInstanceFromTag(reactTag)) ? getStackAddendumByWorkInProgressFiber(reactTag) @@ -6448,14 +5826,14 @@ var roots = new Map(), } } }; -ReactNativeFiberRenderer.injectIntoDevTools({ +injectIntoDevTools({ findFiberByHostInstance: getInstanceFromTag, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 0, - version: "16.3.2", + version: "16.4.1", rendererPackageName: "react-native-renderer" }); -var ReactNativeRenderer$2 = Object.freeze({ default: ReactNativeRenderer }), +var ReactNativeRenderer$2 = { default: ReactNativeRenderer }, ReactNativeRenderer$3 = (ReactNativeRenderer$2 && ReactNativeRenderer) || ReactNativeRenderer$2; module.exports = ReactNativeRenderer$3.default diff --git a/Libraries/Renderer/oss/ReactNativeRenderer-profiling.js b/Libraries/Renderer/oss/ReactNativeRenderer-profiling.js new file mode 100644 index 00000000000000..1e2d9749c9e59a --- /dev/null +++ b/Libraries/Renderer/oss/ReactNativeRenderer-profiling.js @@ -0,0 +1,5899 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @noflow + * @providesModule ReactNativeRenderer-profiling + * @preventMunge + * @generated + */ + +"use strict"; +require("InitializeCore"); +var invariant = require("fbjs/lib/invariant"), + ReactNativeViewConfigRegistry = require("ReactNativeViewConfigRegistry"), + UIManager = require("UIManager"), + RCTEventEmitter = require("RCTEventEmitter"), + React = require("react"), + emptyObject = require("fbjs/lib/emptyObject"), + deepDiffer = require("deepDiffer"), + flattenStyle = require("flattenStyle"), + TextInputState = require("TextInputState"), + ExceptionsManager = require("ExceptionsManager"); +function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) { + this._hasCaughtError = !1; + this._caughtError = null; + var funcArgs = Array.prototype.slice.call(arguments, 3); + try { + func.apply(context, funcArgs); + } catch (error) { + (this._caughtError = error), (this._hasCaughtError = !0); + } +} +var ReactErrorUtils = { + _caughtError: null, + _hasCaughtError: !1, + _rethrowError: null, + _hasRethrowError: !1, + invokeGuardedCallback: function(name, func, context, a, b, c, d, e, f) { + invokeGuardedCallback.apply(ReactErrorUtils, arguments); + }, + invokeGuardedCallbackAndCatchFirstError: function( + name, + func, + context, + a, + b, + c, + d, + e, + f + ) { + ReactErrorUtils.invokeGuardedCallback.apply(this, arguments); + if (ReactErrorUtils.hasCaughtError()) { + var error = ReactErrorUtils.clearCaughtError(); + ReactErrorUtils._hasRethrowError || + ((ReactErrorUtils._hasRethrowError = !0), + (ReactErrorUtils._rethrowError = error)); + } + }, + rethrowCaughtError: function() { + return rethrowCaughtError.apply(ReactErrorUtils, arguments); + }, + hasCaughtError: function() { + return ReactErrorUtils._hasCaughtError; + }, + clearCaughtError: function() { + if (ReactErrorUtils._hasCaughtError) { + var error = ReactErrorUtils._caughtError; + ReactErrorUtils._caughtError = null; + ReactErrorUtils._hasCaughtError = !1; + return error; + } + invariant( + !1, + "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue." + ); + } +}; +function rethrowCaughtError() { + if (ReactErrorUtils._hasRethrowError) { + var error = ReactErrorUtils._rethrowError; + ReactErrorUtils._rethrowError = null; + ReactErrorUtils._hasRethrowError = !1; + throw error; + } +} +var eventPluginOrder = null, + namesToPlugins = {}; +function recomputePluginOrdering() { + if (eventPluginOrder) + for (var pluginName in namesToPlugins) { + var pluginModule = namesToPlugins[pluginName], + pluginIndex = eventPluginOrder.indexOf(pluginName); + invariant( + -1 < pluginIndex, + "EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `%s`.", + pluginName + ); + if (!plugins[pluginIndex]) { + invariant( + pluginModule.extractEvents, + "EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `%s` does not.", + pluginName + ); + plugins[pluginIndex] = pluginModule; + pluginIndex = pluginModule.eventTypes; + for (var eventName in pluginIndex) { + var JSCompiler_inline_result = void 0; + var dispatchConfig = pluginIndex[eventName], + pluginModule$jscomp$0 = pluginModule, + eventName$jscomp$0 = eventName; + invariant( + !eventNameDispatchConfigs.hasOwnProperty(eventName$jscomp$0), + "EventPluginHub: More than one plugin attempted to publish the same event name, `%s`.", + eventName$jscomp$0 + ); + eventNameDispatchConfigs[eventName$jscomp$0] = dispatchConfig; + var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames; + if (phasedRegistrationNames) { + for (JSCompiler_inline_result in phasedRegistrationNames) + phasedRegistrationNames.hasOwnProperty( + JSCompiler_inline_result + ) && + publishRegistrationName( + phasedRegistrationNames[JSCompiler_inline_result], + pluginModule$jscomp$0, + eventName$jscomp$0 + ); + JSCompiler_inline_result = !0; + } else + dispatchConfig.registrationName + ? (publishRegistrationName( + dispatchConfig.registrationName, + pluginModule$jscomp$0, + eventName$jscomp$0 + ), + (JSCompiler_inline_result = !0)) + : (JSCompiler_inline_result = !1); + invariant( + JSCompiler_inline_result, + "EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.", + eventName, + pluginName + ); + } + } + } +} +function publishRegistrationName(registrationName, pluginModule) { + invariant( + !registrationNameModules[registrationName], + "EventPluginHub: More than one plugin attempted to publish the same registration name, `%s`.", + registrationName + ); + registrationNameModules[registrationName] = pluginModule; +} +var plugins = [], + eventNameDispatchConfigs = {}, + registrationNameModules = {}, + getFiberCurrentPropsFromNode = null, + getInstanceFromNode = null, + getNodeFromInstance = null; +function executeDispatch(event, simulated, listener, inst) { + simulated = event.type || "unknown-event"; + event.currentTarget = getNodeFromInstance(inst); + ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError( + simulated, + listener, + void 0, + event + ); + event.currentTarget = null; +} +function executeDirectDispatch(event) { + var dispatchListener = event._dispatchListeners, + dispatchInstance = event._dispatchInstances; + invariant( + !Array.isArray(dispatchListener), + "executeDirectDispatch(...): Invalid `event`." + ); + event.currentTarget = dispatchListener + ? getNodeFromInstance(dispatchInstance) + : null; + dispatchListener = dispatchListener ? dispatchListener(event) : null; + event.currentTarget = null; + event._dispatchListeners = null; + event._dispatchInstances = null; + return dispatchListener; +} +function accumulateInto(current, next) { + invariant( + null != next, + "accumulateInto(...): Accumulated items must not be null or undefined." + ); + if (null == current) return next; + if (Array.isArray(current)) { + if (Array.isArray(next)) return current.push.apply(current, next), current; + current.push(next); + return current; + } + return Array.isArray(next) ? [current].concat(next) : [current, next]; +} +function forEachAccumulated(arr, cb, scope) { + Array.isArray(arr) ? arr.forEach(cb, scope) : arr && cb.call(scope, arr); +} +var eventQueue = null; +function executeDispatchesAndReleaseTopLevel(e) { + if (e) { + var dispatchListeners = e._dispatchListeners, + dispatchInstances = e._dispatchInstances; + if (Array.isArray(dispatchListeners)) + for ( + var i = 0; + i < dispatchListeners.length && !e.isPropagationStopped(); + i++ + ) + executeDispatch(e, !1, dispatchListeners[i], dispatchInstances[i]); + else + dispatchListeners && + executeDispatch(e, !1, dispatchListeners, dispatchInstances); + e._dispatchListeners = null; + e._dispatchInstances = null; + e.isPersistent() || e.constructor.release(e); + } +} +var injection = { + injectEventPluginOrder: function(injectedEventPluginOrder) { + invariant( + !eventPluginOrder, + "EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React." + ); + eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder); + recomputePluginOrdering(); + }, + injectEventPluginsByName: function(injectedNamesToPlugins) { + var isOrderingDirty = !1, + pluginName; + for (pluginName in injectedNamesToPlugins) + if (injectedNamesToPlugins.hasOwnProperty(pluginName)) { + var pluginModule = injectedNamesToPlugins[pluginName]; + (namesToPlugins.hasOwnProperty(pluginName) && + namesToPlugins[pluginName] === pluginModule) || + (invariant( + !namesToPlugins[pluginName], + "EventPluginRegistry: Cannot inject two different event plugins using the same name, `%s`.", + pluginName + ), + (namesToPlugins[pluginName] = pluginModule), + (isOrderingDirty = !0)); + } + isOrderingDirty && recomputePluginOrdering(); + } +}; +function getListener(inst, registrationName) { + var listener = inst.stateNode; + if (!listener) return null; + var props = getFiberCurrentPropsFromNode(listener); + if (!props) return null; + listener = props[registrationName]; + a: switch (registrationName) { + case "onClick": + case "onClickCapture": + case "onDoubleClick": + case "onDoubleClickCapture": + case "onMouseDown": + case "onMouseDownCapture": + case "onMouseMove": + case "onMouseMoveCapture": + case "onMouseUp": + case "onMouseUpCapture": + (props = !props.disabled) || + ((inst = inst.type), + (props = !( + "button" === inst || + "input" === inst || + "select" === inst || + "textarea" === inst + ))); + inst = !props; + break a; + default: + inst = !1; + } + if (inst) return null; + invariant( + !listener || "function" === typeof listener, + "Expected `%s` listener to be a function, instead got a value of `%s` type.", + registrationName, + typeof listener + ); + return listener; +} +function getParent(inst) { + do inst = inst.return; + while (inst && 5 !== inst.tag); + return inst ? inst : null; +} +function traverseTwoPhase(inst, fn, arg) { + for (var path = []; inst; ) path.push(inst), (inst = getParent(inst)); + for (inst = path.length; 0 < inst--; ) fn(path[inst], "captured", arg); + for (inst = 0; inst < path.length; inst++) fn(path[inst], "bubbled", arg); +} +function accumulateDirectionalDispatches(inst, phase, event) { + if ( + (phase = getListener( + inst, + event.dispatchConfig.phasedRegistrationNames[phase] + )) + ) + (event._dispatchListeners = accumulateInto( + event._dispatchListeners, + phase + )), + (event._dispatchInstances = accumulateInto( + event._dispatchInstances, + inst + )); +} +function accumulateTwoPhaseDispatchesSingle(event) { + event && + event.dispatchConfig.phasedRegistrationNames && + traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event); +} +function accumulateTwoPhaseDispatchesSingleSkipTarget(event) { + if (event && event.dispatchConfig.phasedRegistrationNames) { + var targetInst = event._targetInst; + targetInst = targetInst ? getParent(targetInst) : null; + traverseTwoPhase(targetInst, accumulateDirectionalDispatches, event); + } +} +function accumulateDirectDispatchesSingle(event) { + if (event && event.dispatchConfig.registrationName) { + var inst = event._targetInst; + if (inst && event && event.dispatchConfig.registrationName) { + var listener = getListener(inst, event.dispatchConfig.registrationName); + listener && + ((event._dispatchListeners = accumulateInto( + event._dispatchListeners, + listener + )), + (event._dispatchInstances = accumulateInto( + event._dispatchInstances, + inst + ))); + } + } +} +var shouldBeReleasedProperties = "dispatchConfig _targetInst nativeEvent isDefaultPrevented isPropagationStopped _dispatchListeners _dispatchInstances".split( + " " +); +function functionThatReturnsTrue() { + return !0; +} +function functionThatReturnsFalse() { + return !1; +} +function SyntheticEvent( + dispatchConfig, + targetInst, + nativeEvent, + nativeEventTarget +) { + this.dispatchConfig = dispatchConfig; + this._targetInst = targetInst; + this.nativeEvent = nativeEvent; + dispatchConfig = this.constructor.Interface; + for (var propName in dispatchConfig) + dispatchConfig.hasOwnProperty(propName) && + ((targetInst = dispatchConfig[propName]) + ? (this[propName] = targetInst(nativeEvent)) + : "target" === propName + ? (this.target = nativeEventTarget) + : (this[propName] = nativeEvent[propName])); + this.isDefaultPrevented = (null != nativeEvent.defaultPrevented + ? nativeEvent.defaultPrevented + : !1 === nativeEvent.returnValue) + ? functionThatReturnsTrue + : functionThatReturnsFalse; + this.isPropagationStopped = functionThatReturnsFalse; + return this; +} +Object.assign(SyntheticEvent.prototype, { + preventDefault: function() { + this.defaultPrevented = !0; + var event = this.nativeEvent; + event && + (event.preventDefault + ? event.preventDefault() + : "unknown" !== typeof event.returnValue && (event.returnValue = !1), + (this.isDefaultPrevented = functionThatReturnsTrue)); + }, + stopPropagation: function() { + var event = this.nativeEvent; + event && + (event.stopPropagation + ? event.stopPropagation() + : "unknown" !== typeof event.cancelBubble && (event.cancelBubble = !0), + (this.isPropagationStopped = functionThatReturnsTrue)); + }, + persist: function() { + this.isPersistent = functionThatReturnsTrue; + }, + isPersistent: functionThatReturnsFalse, + destructor: function() { + var Interface = this.constructor.Interface, + propName; + for (propName in Interface) this[propName] = null; + for ( + Interface = 0; + Interface < shouldBeReleasedProperties.length; + Interface++ + ) + this[shouldBeReleasedProperties[Interface]] = null; + } +}); +SyntheticEvent.Interface = { + type: null, + target: null, + currentTarget: function() { + return null; + }, + eventPhase: null, + bubbles: null, + cancelable: null, + timeStamp: function(event) { + return event.timeStamp || Date.now(); + }, + defaultPrevented: null, + isTrusted: null +}; +SyntheticEvent.extend = function(Interface) { + function E() {} + function Class() { + return Super.apply(this, arguments); + } + var Super = this; + E.prototype = Super.prototype; + var prototype = new E(); + Object.assign(prototype, Class.prototype); + Class.prototype = prototype; + Class.prototype.constructor = Class; + Class.Interface = Object.assign({}, Super.Interface, Interface); + Class.extend = Super.extend; + addEventPoolingTo(Class); + return Class; +}; +addEventPoolingTo(SyntheticEvent); +function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) { + if (this.eventPool.length) { + var instance = this.eventPool.pop(); + this.call(instance, dispatchConfig, targetInst, nativeEvent, nativeInst); + return instance; + } + return new this(dispatchConfig, targetInst, nativeEvent, nativeInst); +} +function releasePooledEvent(event) { + invariant( + event instanceof this, + "Trying to release an event instance into a pool of a different type." + ); + event.destructor(); + 10 > this.eventPool.length && this.eventPool.push(event); +} +function addEventPoolingTo(EventConstructor) { + EventConstructor.eventPool = []; + EventConstructor.getPooled = getPooledEvent; + EventConstructor.release = releasePooledEvent; +} +var ResponderSyntheticEvent = SyntheticEvent.extend({ + touchHistory: function() { + return null; + } +}); +function isStartish(topLevelType) { + return "topTouchStart" === topLevelType; +} +function isMoveish(topLevelType) { + return "topTouchMove" === topLevelType; +} +var startDependencies = ["topTouchStart"], + moveDependencies = ["topTouchMove"], + endDependencies = ["topTouchCancel", "topTouchEnd"], + touchBank = [], + touchHistory = { + touchBank: touchBank, + numberActiveTouches: 0, + indexOfSingleActiveTouch: -1, + mostRecentTimeStamp: 0 + }; +function timestampForTouch(touch) { + return touch.timeStamp || touch.timestamp; +} +function getTouchIdentifier(_ref) { + _ref = _ref.identifier; + invariant(null != _ref, "Touch object is missing identifier."); + return _ref; +} +function recordTouchStart(touch) { + var identifier = getTouchIdentifier(touch), + touchRecord = touchBank[identifier]; + touchRecord + ? ((touchRecord.touchActive = !0), + (touchRecord.startPageX = touch.pageX), + (touchRecord.startPageY = touch.pageY), + (touchRecord.startTimeStamp = timestampForTouch(touch)), + (touchRecord.currentPageX = touch.pageX), + (touchRecord.currentPageY = touch.pageY), + (touchRecord.currentTimeStamp = timestampForTouch(touch)), + (touchRecord.previousPageX = touch.pageX), + (touchRecord.previousPageY = touch.pageY), + (touchRecord.previousTimeStamp = timestampForTouch(touch))) + : ((touchRecord = { + touchActive: !0, + startPageX: touch.pageX, + startPageY: touch.pageY, + startTimeStamp: timestampForTouch(touch), + currentPageX: touch.pageX, + currentPageY: touch.pageY, + currentTimeStamp: timestampForTouch(touch), + previousPageX: touch.pageX, + previousPageY: touch.pageY, + previousTimeStamp: timestampForTouch(touch) + }), + (touchBank[identifier] = touchRecord)); + touchHistory.mostRecentTimeStamp = timestampForTouch(touch); +} +function recordTouchMove(touch) { + var touchRecord = touchBank[getTouchIdentifier(touch)]; + touchRecord + ? ((touchRecord.touchActive = !0), + (touchRecord.previousPageX = touchRecord.currentPageX), + (touchRecord.previousPageY = touchRecord.currentPageY), + (touchRecord.previousTimeStamp = touchRecord.currentTimeStamp), + (touchRecord.currentPageX = touch.pageX), + (touchRecord.currentPageY = touch.pageY), + (touchRecord.currentTimeStamp = timestampForTouch(touch)), + (touchHistory.mostRecentTimeStamp = timestampForTouch(touch))) + : console.error( + "Cannot record touch move without a touch start.\nTouch Move: %s\n", + "Touch Bank: %s", + printTouch(touch), + printTouchBank() + ); +} +function recordTouchEnd(touch) { + var touchRecord = touchBank[getTouchIdentifier(touch)]; + touchRecord + ? ((touchRecord.touchActive = !1), + (touchRecord.previousPageX = touchRecord.currentPageX), + (touchRecord.previousPageY = touchRecord.currentPageY), + (touchRecord.previousTimeStamp = touchRecord.currentTimeStamp), + (touchRecord.currentPageX = touch.pageX), + (touchRecord.currentPageY = touch.pageY), + (touchRecord.currentTimeStamp = timestampForTouch(touch)), + (touchHistory.mostRecentTimeStamp = timestampForTouch(touch))) + : console.error( + "Cannot record touch end without a touch start.\nTouch End: %s\n", + "Touch Bank: %s", + printTouch(touch), + printTouchBank() + ); +} +function printTouch(touch) { + return JSON.stringify({ + identifier: touch.identifier, + pageX: touch.pageX, + pageY: touch.pageY, + timestamp: timestampForTouch(touch) + }); +} +function printTouchBank() { + var printed = JSON.stringify(touchBank.slice(0, 20)); + 20 < touchBank.length && + (printed += " (original size: " + touchBank.length + ")"); + return printed; +} +var ResponderTouchHistoryStore = { + recordTouchTrack: function(topLevelType, nativeEvent) { + if (isMoveish(topLevelType)) + nativeEvent.changedTouches.forEach(recordTouchMove); + else if (isStartish(topLevelType)) + nativeEvent.changedTouches.forEach(recordTouchStart), + (touchHistory.numberActiveTouches = nativeEvent.touches.length), + 1 === touchHistory.numberActiveTouches && + (touchHistory.indexOfSingleActiveTouch = + nativeEvent.touches[0].identifier); + else if ( + "topTouchEnd" === topLevelType || + "topTouchCancel" === topLevelType + ) + if ( + (nativeEvent.changedTouches.forEach(recordTouchEnd), + (touchHistory.numberActiveTouches = nativeEvent.touches.length), + 1 === touchHistory.numberActiveTouches) + ) + for (topLevelType = 0; topLevelType < touchBank.length; topLevelType++) + if ( + ((nativeEvent = touchBank[topLevelType]), + null != nativeEvent && nativeEvent.touchActive) + ) { + touchHistory.indexOfSingleActiveTouch = topLevelType; + break; + } + }, + touchHistory: touchHistory +}; +function accumulate(current, next) { + invariant( + null != next, + "accumulate(...): Accumulated items must be not be null or undefined." + ); + return null == current + ? next + : Array.isArray(current) + ? current.concat(next) + : Array.isArray(next) ? [current].concat(next) : [current, next]; +} +var responderInst = null, + trackedTouchCount = 0; +function changeResponder(nextResponderInst, blockHostResponder) { + var oldResponderInst = responderInst; + responderInst = nextResponderInst; + if (null !== ResponderEventPlugin.GlobalResponderHandler) + ResponderEventPlugin.GlobalResponderHandler.onChange( + oldResponderInst, + nextResponderInst, + blockHostResponder + ); +} +var eventTypes$1 = { + startShouldSetResponder: { + phasedRegistrationNames: { + bubbled: "onStartShouldSetResponder", + captured: "onStartShouldSetResponderCapture" + }, + dependencies: startDependencies + }, + scrollShouldSetResponder: { + phasedRegistrationNames: { + bubbled: "onScrollShouldSetResponder", + captured: "onScrollShouldSetResponderCapture" + }, + dependencies: ["topScroll"] + }, + selectionChangeShouldSetResponder: { + phasedRegistrationNames: { + bubbled: "onSelectionChangeShouldSetResponder", + captured: "onSelectionChangeShouldSetResponderCapture" + }, + dependencies: ["topSelectionChange"] + }, + moveShouldSetResponder: { + phasedRegistrationNames: { + bubbled: "onMoveShouldSetResponder", + captured: "onMoveShouldSetResponderCapture" + }, + dependencies: moveDependencies + }, + responderStart: { + registrationName: "onResponderStart", + dependencies: startDependencies + }, + responderMove: { + registrationName: "onResponderMove", + dependencies: moveDependencies + }, + responderEnd: { + registrationName: "onResponderEnd", + dependencies: endDependencies + }, + responderRelease: { + registrationName: "onResponderRelease", + dependencies: endDependencies + }, + responderTerminationRequest: { + registrationName: "onResponderTerminationRequest", + dependencies: [] + }, + responderGrant: { registrationName: "onResponderGrant", dependencies: [] }, + responderReject: { + registrationName: "onResponderReject", + dependencies: [] + }, + responderTerminate: { + registrationName: "onResponderTerminate", + dependencies: [] + } + }, + ResponderEventPlugin = { + _getResponder: function() { + return responderInst; + }, + eventTypes: eventTypes$1, + extractEvents: function( + topLevelType, + targetInst, + nativeEvent, + nativeEventTarget + ) { + if (isStartish(topLevelType)) trackedTouchCount += 1; + else if ( + "topTouchEnd" === topLevelType || + "topTouchCancel" === topLevelType + ) + if (0 <= trackedTouchCount) --trackedTouchCount; + else + return ( + console.error( + "Ended a touch event which was not counted in `trackedTouchCount`." + ), + null + ); + ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent); + if ( + targetInst && + (("topScroll" === topLevelType && !nativeEvent.responderIgnoreScroll) || + (0 < trackedTouchCount && "topSelectionChange" === topLevelType) || + isStartish(topLevelType) || + isMoveish(topLevelType)) + ) { + var JSCompiler_temp = isStartish(topLevelType) + ? eventTypes$1.startShouldSetResponder + : isMoveish(topLevelType) + ? eventTypes$1.moveShouldSetResponder + : "topSelectionChange" === topLevelType + ? eventTypes$1.selectionChangeShouldSetResponder + : eventTypes$1.scrollShouldSetResponder; + if (responderInst) + b: { + var JSCompiler_temp$jscomp$0 = responderInst; + for ( + var depthA = 0, tempA = JSCompiler_temp$jscomp$0; + tempA; + tempA = getParent(tempA) + ) + depthA++; + tempA = 0; + for (var tempB = targetInst; tempB; tempB = getParent(tempB)) + tempA++; + for (; 0 < depthA - tempA; ) + (JSCompiler_temp$jscomp$0 = getParent(JSCompiler_temp$jscomp$0)), + depthA--; + for (; 0 < tempA - depthA; ) + (targetInst = getParent(targetInst)), tempA--; + for (; depthA--; ) { + if ( + JSCompiler_temp$jscomp$0 === targetInst || + JSCompiler_temp$jscomp$0 === targetInst.alternate + ) + break b; + JSCompiler_temp$jscomp$0 = getParent(JSCompiler_temp$jscomp$0); + targetInst = getParent(targetInst); + } + JSCompiler_temp$jscomp$0 = null; + } + else JSCompiler_temp$jscomp$0 = targetInst; + targetInst = JSCompiler_temp$jscomp$0 === responderInst; + JSCompiler_temp$jscomp$0 = ResponderSyntheticEvent.getPooled( + JSCompiler_temp, + JSCompiler_temp$jscomp$0, + nativeEvent, + nativeEventTarget + ); + JSCompiler_temp$jscomp$0.touchHistory = + ResponderTouchHistoryStore.touchHistory; + targetInst + ? forEachAccumulated( + JSCompiler_temp$jscomp$0, + accumulateTwoPhaseDispatchesSingleSkipTarget + ) + : forEachAccumulated( + JSCompiler_temp$jscomp$0, + accumulateTwoPhaseDispatchesSingle + ); + b: { + JSCompiler_temp = JSCompiler_temp$jscomp$0._dispatchListeners; + targetInst = JSCompiler_temp$jscomp$0._dispatchInstances; + if (Array.isArray(JSCompiler_temp)) + for ( + depthA = 0; + depthA < JSCompiler_temp.length && + !JSCompiler_temp$jscomp$0.isPropagationStopped(); + depthA++ + ) { + if ( + JSCompiler_temp[depthA]( + JSCompiler_temp$jscomp$0, + targetInst[depthA] + ) + ) { + JSCompiler_temp = targetInst[depthA]; + break b; + } + } + else if ( + JSCompiler_temp && + JSCompiler_temp(JSCompiler_temp$jscomp$0, targetInst) + ) { + JSCompiler_temp = targetInst; + break b; + } + JSCompiler_temp = null; + } + JSCompiler_temp$jscomp$0._dispatchInstances = null; + JSCompiler_temp$jscomp$0._dispatchListeners = null; + JSCompiler_temp$jscomp$0.isPersistent() || + JSCompiler_temp$jscomp$0.constructor.release( + JSCompiler_temp$jscomp$0 + ); + JSCompiler_temp && JSCompiler_temp !== responderInst + ? ((JSCompiler_temp$jscomp$0 = void 0), + (targetInst = ResponderSyntheticEvent.getPooled( + eventTypes$1.responderGrant, + JSCompiler_temp, + nativeEvent, + nativeEventTarget + )), + (targetInst.touchHistory = ResponderTouchHistoryStore.touchHistory), + forEachAccumulated(targetInst, accumulateDirectDispatchesSingle), + (depthA = !0 === executeDirectDispatch(targetInst)), + responderInst + ? ((tempA = ResponderSyntheticEvent.getPooled( + eventTypes$1.responderTerminationRequest, + responderInst, + nativeEvent, + nativeEventTarget + )), + (tempA.touchHistory = ResponderTouchHistoryStore.touchHistory), + forEachAccumulated(tempA, accumulateDirectDispatchesSingle), + (tempB = + !tempA._dispatchListeners || executeDirectDispatch(tempA)), + tempA.isPersistent() || tempA.constructor.release(tempA), + tempB + ? ((tempA = ResponderSyntheticEvent.getPooled( + eventTypes$1.responderTerminate, + responderInst, + nativeEvent, + nativeEventTarget + )), + (tempA.touchHistory = + ResponderTouchHistoryStore.touchHistory), + forEachAccumulated(tempA, accumulateDirectDispatchesSingle), + (JSCompiler_temp$jscomp$0 = accumulate( + JSCompiler_temp$jscomp$0, + [targetInst, tempA] + )), + changeResponder(JSCompiler_temp, depthA)) + : ((JSCompiler_temp = ResponderSyntheticEvent.getPooled( + eventTypes$1.responderReject, + JSCompiler_temp, + nativeEvent, + nativeEventTarget + )), + (JSCompiler_temp.touchHistory = + ResponderTouchHistoryStore.touchHistory), + forEachAccumulated( + JSCompiler_temp, + accumulateDirectDispatchesSingle + ), + (JSCompiler_temp$jscomp$0 = accumulate( + JSCompiler_temp$jscomp$0, + JSCompiler_temp + )))) + : ((JSCompiler_temp$jscomp$0 = accumulate( + JSCompiler_temp$jscomp$0, + targetInst + )), + changeResponder(JSCompiler_temp, depthA)), + (JSCompiler_temp = JSCompiler_temp$jscomp$0)) + : (JSCompiler_temp = null); + } else JSCompiler_temp = null; + JSCompiler_temp$jscomp$0 = responderInst && isStartish(topLevelType); + targetInst = responderInst && isMoveish(topLevelType); + depthA = + responderInst && + ("topTouchEnd" === topLevelType || "topTouchCancel" === topLevelType); + if ( + (JSCompiler_temp$jscomp$0 = JSCompiler_temp$jscomp$0 + ? eventTypes$1.responderStart + : targetInst + ? eventTypes$1.responderMove + : depthA ? eventTypes$1.responderEnd : null) + ) + (JSCompiler_temp$jscomp$0 = ResponderSyntheticEvent.getPooled( + JSCompiler_temp$jscomp$0, + responderInst, + nativeEvent, + nativeEventTarget + )), + (JSCompiler_temp$jscomp$0.touchHistory = + ResponderTouchHistoryStore.touchHistory), + forEachAccumulated( + JSCompiler_temp$jscomp$0, + accumulateDirectDispatchesSingle + ), + (JSCompiler_temp = accumulate( + JSCompiler_temp, + JSCompiler_temp$jscomp$0 + )); + JSCompiler_temp$jscomp$0 = + responderInst && "topTouchCancel" === topLevelType; + if ( + (topLevelType = + responderInst && + !JSCompiler_temp$jscomp$0 && + ("topTouchEnd" === topLevelType || "topTouchCancel" === topLevelType)) + ) + a: { + if ((topLevelType = nativeEvent.touches) && 0 !== topLevelType.length) + for (targetInst = 0; targetInst < topLevelType.length; targetInst++) + if ( + ((depthA = topLevelType[targetInst].target), + null !== depthA && void 0 !== depthA && 0 !== depthA) + ) { + tempA = getInstanceFromNode(depthA); + b: { + for (depthA = responderInst; tempA; ) { + if (depthA === tempA || depthA === tempA.alternate) { + depthA = !0; + break b; + } + tempA = getParent(tempA); + } + depthA = !1; + } + if (depthA) { + topLevelType = !1; + break a; + } + } + topLevelType = !0; + } + if ( + (topLevelType = JSCompiler_temp$jscomp$0 + ? eventTypes$1.responderTerminate + : topLevelType ? eventTypes$1.responderRelease : null) + ) + (nativeEvent = ResponderSyntheticEvent.getPooled( + topLevelType, + responderInst, + nativeEvent, + nativeEventTarget + )), + (nativeEvent.touchHistory = ResponderTouchHistoryStore.touchHistory), + forEachAccumulated(nativeEvent, accumulateDirectDispatchesSingle), + (JSCompiler_temp = accumulate(JSCompiler_temp, nativeEvent)), + changeResponder(null); + return JSCompiler_temp; + }, + GlobalResponderHandler: null, + injection: { + injectGlobalResponderHandler: function(GlobalResponderHandler) { + ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler; + } + } + }, + customBubblingEventTypes$1 = + ReactNativeViewConfigRegistry.customBubblingEventTypes, + customDirectEventTypes$1 = + ReactNativeViewConfigRegistry.customDirectEventTypes, + ReactNativeBridgeEventPlugin = { + eventTypes: ReactNativeViewConfigRegistry.eventTypes, + extractEvents: function( + topLevelType, + targetInst, + nativeEvent, + nativeEventTarget + ) { + if (null == targetInst) return null; + var bubbleDispatchConfig = customBubblingEventTypes$1[topLevelType], + directDispatchConfig = customDirectEventTypes$1[topLevelType]; + invariant( + bubbleDispatchConfig || directDispatchConfig, + 'Unsupported top level event type "%s" dispatched', + topLevelType + ); + topLevelType = SyntheticEvent.getPooled( + bubbleDispatchConfig || directDispatchConfig, + targetInst, + nativeEvent, + nativeEventTarget + ); + if (bubbleDispatchConfig) + forEachAccumulated(topLevelType, accumulateTwoPhaseDispatchesSingle); + else if (directDispatchConfig) + forEachAccumulated(topLevelType, accumulateDirectDispatchesSingle); + else return null; + return topLevelType; + } + }; +injection.injectEventPluginOrder([ + "ResponderEventPlugin", + "ReactNativeBridgeEventPlugin" +]); +injection.injectEventPluginsByName({ + ResponderEventPlugin: ResponderEventPlugin, + ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin +}); +var instanceCache = {}, + instanceProps = {}; +function uncacheFiberNode(tag) { + delete instanceCache[tag]; + delete instanceProps[tag]; +} +function getInstanceFromTag(tag) { + return instanceCache[tag] || null; +} +var ReactNativeComponentTree = { + precacheFiberNode: function(hostInst, tag) { + instanceCache[tag] = hostInst; + }, + uncacheFiberNode: uncacheFiberNode, + getClosestInstanceFromNode: getInstanceFromTag, + getInstanceFromNode: getInstanceFromTag, + getNodeFromInstance: function(inst) { + var tag = inst.stateNode._nativeTag; + void 0 === tag && (tag = inst.stateNode.canonical._nativeTag); + invariant(tag, "All native instances should have a tag."); + return tag; + }, + getFiberCurrentPropsFromNode: function(stateNode) { + return instanceProps[stateNode._nativeTag] || null; + }, + updateFiberProps: function(tag, props) { + instanceProps[tag] = props; + } + }, + restoreTarget = null, + restoreQueue = null; +function restoreStateOfTarget(target) { + if ((target = getInstanceFromNode(target))) { + invariant( + null, + "Fiber needs to be injected to handle a fiber target for controlled events. This error is likely caused by a bug in React. Please file an issue." + ); + var props = getFiberCurrentPropsFromNode(target.stateNode); + null.restoreControlledState(target.stateNode, target.type, props); + } +} +function _batchedUpdates(fn, bookkeeping) { + return fn(bookkeeping); +} +function _flushInteractiveUpdates() {} +var isBatching = !1; +function batchedUpdates(fn, bookkeeping) { + if (isBatching) return fn(bookkeeping); + isBatching = !0; + try { + return _batchedUpdates(fn, bookkeeping); + } finally { + if (((isBatching = !1), null !== restoreTarget || null !== restoreQueue)) + if ( + (_flushInteractiveUpdates(), + restoreTarget && + ((bookkeeping = restoreTarget), + (fn = restoreQueue), + (restoreQueue = restoreTarget = null), + restoreStateOfTarget(bookkeeping), + fn)) + ) + for (bookkeeping = 0; bookkeeping < fn.length; bookkeeping++) + restoreStateOfTarget(fn[bookkeeping]); + } +} +var EMPTY_NATIVE_EVENT = {}; +function _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam) { + var nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT, + inst = getInstanceFromTag(rootNodeID); + batchedUpdates(function() { + var events = nativeEvent.target; + for (var events$jscomp$0 = null, i = 0; i < plugins.length; i++) { + var possiblePlugin = plugins[i]; + possiblePlugin && + (possiblePlugin = possiblePlugin.extractEvents( + topLevelType, + inst, + nativeEvent, + events + )) && + (events$jscomp$0 = accumulateInto(events$jscomp$0, possiblePlugin)); + } + events = events$jscomp$0; + null !== events && (eventQueue = accumulateInto(eventQueue, events)); + events = eventQueue; + eventQueue = null; + events && + (forEachAccumulated(events, executeDispatchesAndReleaseTopLevel), + invariant( + !eventQueue, + "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented." + ), + ReactErrorUtils.rethrowCaughtError()); + }); +} +RCTEventEmitter.register({ + getListener: getListener, + registrationNames: registrationNameModules, + _receiveRootNodeIDEvent: _receiveRootNodeIDEvent, + receiveEvent: function(rootNodeID, topLevelType, nativeEventParam) { + _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam); + }, + receiveTouches: function(eventTopLevelType, touches, changedIndices) { + if ( + "topTouchEnd" === eventTopLevelType || + "topTouchCancel" === eventTopLevelType + ) { + var JSCompiler_temp = []; + for (var i = 0; i < changedIndices.length; i++) { + var index = changedIndices[i]; + JSCompiler_temp.push(touches[index]); + touches[index] = null; + } + for (i = changedIndices = 0; i < touches.length; i++) + (index = touches[i]), + null !== index && (touches[changedIndices++] = index); + touches.length = changedIndices; + } else + for (JSCompiler_temp = [], i = 0; i < changedIndices.length; i++) + JSCompiler_temp.push(touches[changedIndices[i]]); + for ( + changedIndices = 0; + changedIndices < JSCompiler_temp.length; + changedIndices++ + ) { + i = JSCompiler_temp[changedIndices]; + i.changedTouches = JSCompiler_temp; + i.touches = touches; + index = null; + var target = i.target; + null === target || void 0 === target || 1 > target || (index = target); + _receiveRootNodeIDEvent(index, eventTopLevelType, i); + } + } +}); +getFiberCurrentPropsFromNode = + ReactNativeComponentTree.getFiberCurrentPropsFromNode; +getInstanceFromNode = ReactNativeComponentTree.getInstanceFromNode; +getNodeFromInstance = ReactNativeComponentTree.getNodeFromInstance; +ResponderEventPlugin.injection.injectGlobalResponderHandler({ + onChange: function(from, to, blockNativeResponder) { + null !== to + ? UIManager.setJSResponder(to.stateNode._nativeTag, blockNativeResponder) + : UIManager.clearJSResponder(); + } +}); +var ReactCurrentOwner = + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, + hasSymbol = "function" === typeof Symbol && Symbol.for, + REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 60103, + REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 60106, + REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 60107, + REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for("react.strict_mode") : 60108, + REACT_PROFILER_TYPE = hasSymbol ? Symbol.for("react.profiler") : 60114, + 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, + REACT_TIMEOUT_TYPE = hasSymbol ? Symbol.for("react.timeout") : 60113, + MAYBE_ITERATOR_SYMBOL = "function" === typeof Symbol && Symbol.iterator; +function getIteratorFn(maybeIterable) { + if (null === maybeIterable || "undefined" === typeof maybeIterable) + return null; + maybeIterable = + (MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) || + maybeIterable["@@iterator"]; + return "function" === typeof maybeIterable ? maybeIterable : null; +} +function getComponentName(fiber) { + var type = fiber.type; + if ("function" === typeof type) return type.displayName || type.name; + if ("string" === typeof type) return type; + switch (type) { + case REACT_ASYNC_MODE_TYPE: + return "AsyncMode"; + case REACT_CONTEXT_TYPE: + return "Context.Consumer"; + case REACT_FRAGMENT_TYPE: + return "ReactFragment"; + case REACT_PORTAL_TYPE: + return "ReactPortal"; + case REACT_PROFILER_TYPE: + return "Profiler(" + fiber.pendingProps.id + ")"; + case REACT_PROVIDER_TYPE: + return "Context.Provider"; + case REACT_STRICT_MODE_TYPE: + return "StrictMode"; + case REACT_TIMEOUT_TYPE: + return "Timeout"; + } + if ("object" === typeof type && null !== type) + switch (type.$$typeof) { + case REACT_FORWARD_REF_TYPE: + return ( + (fiber = type.render.displayName || type.render.name || ""), + "" !== fiber ? "ForwardRef(" + fiber + ")" : "ForwardRef" + ); + } + return null; +} +function isFiberMountedImpl(fiber) { + var node = fiber; + if (fiber.alternate) for (; node.return; ) node = node.return; + else { + if (0 !== (node.effectTag & 2)) return 1; + for (; node.return; ) + if (((node = node.return), 0 !== (node.effectTag & 2))) return 1; + } + return 3 === node.tag ? 2 : 3; +} +function assertIsMounted(fiber) { + invariant( + 2 === isFiberMountedImpl(fiber), + "Unable to find node on an unmounted component." + ); +} +function findCurrentFiberUsingSlowPath(fiber) { + var alternate = fiber.alternate; + if (!alternate) + return ( + (alternate = isFiberMountedImpl(fiber)), + invariant( + 3 !== alternate, + "Unable to find node on an unmounted component." + ), + 1 === alternate ? null : fiber + ); + for (var a = fiber, b = alternate; ; ) { + var parentA = a.return, + parentB = parentA ? parentA.alternate : null; + if (!parentA || !parentB) break; + if (parentA.child === parentB.child) { + for (var child = parentA.child; child; ) { + if (child === a) return assertIsMounted(parentA), fiber; + if (child === b) return assertIsMounted(parentA), alternate; + child = child.sibling; + } + invariant(!1, "Unable to find node on an unmounted component."); + } + if (a.return !== b.return) (a = parentA), (b = parentB); + else { + child = !1; + for (var _child = parentA.child; _child; ) { + if (_child === a) { + child = !0; + a = parentA; + b = parentB; + break; + } + if (_child === b) { + child = !0; + b = parentA; + a = parentB; + break; + } + _child = _child.sibling; + } + if (!child) { + for (_child = parentB.child; _child; ) { + if (_child === a) { + child = !0; + a = parentB; + b = parentA; + break; + } + if (_child === b) { + child = !0; + b = parentB; + a = parentA; + break; + } + _child = _child.sibling; + } + invariant( + child, + "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue." + ); + } + } + invariant( + a.alternate === b, + "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." + ); + } + invariant(3 === a.tag, "Unable to find node on an unmounted component."); + return a.stateNode.current === a ? fiber : alternate; +} +function findCurrentHostFiber(parent) { + parent = findCurrentFiberUsingSlowPath(parent); + if (!parent) return null; + for (var node = parent; ; ) { + if (5 === node.tag || 6 === node.tag) return node; + if (node.child) (node.child.return = node), (node = node.child); + else { + if (node === parent) break; + for (; !node.sibling; ) { + if (!node.return || node.return === parent) return null; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + } + return null; +} +function findCurrentHostFiberWithNoPortals(parent) { + parent = findCurrentFiberUsingSlowPath(parent); + if (!parent) return null; + for (var node = parent; ; ) { + if (5 === node.tag || 6 === node.tag) return node; + if (node.child && 4 !== node.tag) + (node.child.return = node), (node = node.child); + else { + if (node === parent) break; + for (; !node.sibling; ) { + if (!node.return || node.return === parent) return null; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + } + return null; +} +var emptyObject$1 = {}, + removedKeys = null, + removedKeyCount = 0; +function restoreDeletedValuesInNestedArray( + updatePayload, + node, + validAttributes +) { + if (Array.isArray(node)) + for (var i = node.length; i-- && 0 < removedKeyCount; ) + restoreDeletedValuesInNestedArray( + updatePayload, + node[i], + validAttributes + ); + else if (node && 0 < removedKeyCount) + for (i in removedKeys) + if (removedKeys[i]) { + var _nextProp = node[i]; + if (void 0 !== _nextProp) { + var attributeConfig = validAttributes[i]; + if (attributeConfig) { + "function" === typeof _nextProp && (_nextProp = !0); + "undefined" === typeof _nextProp && (_nextProp = null); + if ("object" !== typeof attributeConfig) + updatePayload[i] = _nextProp; + else if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) + (_nextProp = + "function" === typeof attributeConfig.process + ? attributeConfig.process(_nextProp) + : _nextProp), + (updatePayload[i] = _nextProp); + removedKeys[i] = !1; + removedKeyCount--; + } + } + } +} +function diffNestedProperty( + updatePayload, + prevProp, + nextProp, + validAttributes +) { + if (!updatePayload && prevProp === nextProp) return updatePayload; + if (!prevProp || !nextProp) + return nextProp + ? addNestedProperty(updatePayload, nextProp, validAttributes) + : prevProp + ? clearNestedProperty(updatePayload, prevProp, validAttributes) + : updatePayload; + if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) + return diffProperties(updatePayload, prevProp, nextProp, validAttributes); + if (Array.isArray(prevProp) && Array.isArray(nextProp)) { + var minLength = + prevProp.length < nextProp.length ? prevProp.length : nextProp.length, + i; + for (i = 0; i < minLength; i++) + updatePayload = diffNestedProperty( + updatePayload, + prevProp[i], + nextProp[i], + validAttributes + ); + for (; i < prevProp.length; i++) + updatePayload = clearNestedProperty( + updatePayload, + prevProp[i], + validAttributes + ); + for (; i < nextProp.length; i++) + updatePayload = addNestedProperty( + updatePayload, + nextProp[i], + validAttributes + ); + return updatePayload; + } + return Array.isArray(prevProp) + ? diffProperties( + updatePayload, + flattenStyle(prevProp), + nextProp, + validAttributes + ) + : diffProperties( + updatePayload, + prevProp, + flattenStyle(nextProp), + validAttributes + ); +} +function addNestedProperty(updatePayload, nextProp, validAttributes) { + if (!nextProp) return updatePayload; + if (!Array.isArray(nextProp)) + return diffProperties( + updatePayload, + emptyObject$1, + nextProp, + validAttributes + ); + for (var i = 0; i < nextProp.length; i++) + updatePayload = addNestedProperty( + updatePayload, + nextProp[i], + validAttributes + ); + return updatePayload; +} +function clearNestedProperty(updatePayload, prevProp, validAttributes) { + if (!prevProp) return updatePayload; + if (!Array.isArray(prevProp)) + return diffProperties( + updatePayload, + prevProp, + emptyObject$1, + validAttributes + ); + for (var i = 0; i < prevProp.length; i++) + updatePayload = clearNestedProperty( + updatePayload, + prevProp[i], + validAttributes + ); + return updatePayload; +} +function diffProperties(updatePayload, prevProps, nextProps, validAttributes) { + var attributeConfig, propKey; + for (propKey in nextProps) + if ((attributeConfig = validAttributes[propKey])) { + var prevProp = prevProps[propKey]; + var nextProp = nextProps[propKey]; + "function" === typeof nextProp && + ((nextProp = !0), "function" === typeof prevProp && (prevProp = !0)); + "undefined" === typeof nextProp && + ((nextProp = null), + "undefined" === typeof prevProp && (prevProp = null)); + removedKeys && (removedKeys[propKey] = !1); + if (updatePayload && void 0 !== updatePayload[propKey]) + if ("object" !== typeof attributeConfig) + updatePayload[propKey] = nextProp; + else { + if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) + (attributeConfig = + "function" === typeof attributeConfig.process + ? attributeConfig.process(nextProp) + : nextProp), + (updatePayload[propKey] = attributeConfig); + } + else if (prevProp !== nextProp) + if ("object" !== typeof attributeConfig) + ("object" !== typeof nextProp || + null === nextProp || + deepDiffer(prevProp, nextProp)) && + ((updatePayload || (updatePayload = {}))[propKey] = nextProp); + else if ( + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ) { + if ( + void 0 === prevProp || + ("function" === typeof attributeConfig.diff + ? attributeConfig.diff(prevProp, nextProp) + : "object" !== typeof nextProp || + null === nextProp || + deepDiffer(prevProp, nextProp)) + ) + (attributeConfig = + "function" === typeof attributeConfig.process + ? attributeConfig.process(nextProp) + : nextProp), + ((updatePayload || (updatePayload = {}))[ + propKey + ] = attributeConfig); + } else + (removedKeys = null), + (removedKeyCount = 0), + (updatePayload = diffNestedProperty( + updatePayload, + prevProp, + nextProp, + attributeConfig + )), + 0 < removedKeyCount && + updatePayload && + (restoreDeletedValuesInNestedArray( + updatePayload, + nextProp, + attributeConfig + ), + (removedKeys = null)); + } + for (var _propKey in prevProps) + void 0 === nextProps[_propKey] && + (!(attributeConfig = validAttributes[_propKey]) || + (updatePayload && void 0 !== updatePayload[_propKey]) || + ((prevProp = prevProps[_propKey]), + void 0 !== prevProp && + ("object" !== typeof attributeConfig || + "function" === typeof attributeConfig.diff || + "function" === typeof attributeConfig.process + ? (((updatePayload || (updatePayload = {}))[_propKey] = null), + removedKeys || (removedKeys = {}), + removedKeys[_propKey] || + ((removedKeys[_propKey] = !0), removedKeyCount++)) + : (updatePayload = clearNestedProperty( + updatePayload, + prevProp, + attributeConfig + ))))); + return updatePayload; +} +function mountSafeCallback(context, callback) { + return function() { + if (callback) { + if ("boolean" === typeof context.__isMounted) { + if (!context.__isMounted) return; + } else if ( + "function" === typeof context.isMounted && + !context.isMounted() + ) + return; + return callback.apply(context, arguments); + } + }; +} +var ReactNativeFiberHostComponent = (function() { + function ReactNativeFiberHostComponent(tag, viewConfig) { + if (!(this instanceof ReactNativeFiberHostComponent)) + throw new TypeError("Cannot call a class as a function"); + this._nativeTag = tag; + this._children = []; + this.viewConfig = viewConfig; + } + ReactNativeFiberHostComponent.prototype.blur = function() { + TextInputState.blurTextInput(this._nativeTag); + }; + ReactNativeFiberHostComponent.prototype.focus = function() { + TextInputState.focusTextInput(this._nativeTag); + }; + ReactNativeFiberHostComponent.prototype.measure = function(callback) { + UIManager.measure(this._nativeTag, mountSafeCallback(this, callback)); + }; + ReactNativeFiberHostComponent.prototype.measureInWindow = function( + callback + ) { + UIManager.measureInWindow( + this._nativeTag, + mountSafeCallback(this, callback) + ); + }; + ReactNativeFiberHostComponent.prototype.measureLayout = function( + relativeToNativeNode, + onSuccess, + onFail + ) { + UIManager.measureLayout( + this._nativeTag, + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }; + ReactNativeFiberHostComponent.prototype.setNativeProps = function( + nativeProps + ) { + nativeProps = diffProperties( + null, + emptyObject$1, + nativeProps, + this.viewConfig.validAttributes + ); + null != nativeProps && + UIManager.updateView( + this._nativeTag, + this.viewConfig.uiViewClassName, + nativeProps + ); + }; + return ReactNativeFiberHostComponent; + })(), + now$1 = + "object" === typeof performance && "function" === typeof performance.now + ? function() { + return performance.now(); + } + : function() { + return Date.now(); + }, + scheduledCallback = null, + frameDeadline = 0, + frameDeadlineObject = { + timeRemaining: function() { + return frameDeadline - now$1(); + }, + didTimeout: !1 + }; +function setTimeoutCallback() { + frameDeadline = now$1() + 5; + var callback = scheduledCallback; + scheduledCallback = null; + null !== callback && callback(frameDeadlineObject); +} +function shim$1() { + invariant( + !1, + "The current renderer does not support hyration. This error is likely caused by a bug in React. Please file an issue." + ); +} +var nextReactTag = 3; +function allocateTag() { + var tag = nextReactTag; + 1 === tag % 10 && (tag += 2); + nextReactTag = tag + 2; + return tag; +} +function recursivelyUncacheFiberNode(node) { + "number" === typeof node + ? uncacheFiberNode(node) + : (uncacheFiberNode(node._nativeTag), + node._children.forEach(recursivelyUncacheFiberNode)); +} +function finalizeInitialChildren(parentInstance) { + if (0 === parentInstance._children.length) return !1; + var nativeTags = parentInstance._children.map(function(child) { + return "number" === typeof child ? child : child._nativeTag; + }); + UIManager.setChildren(parentInstance._nativeTag, nativeTags); + return !1; +} +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 valueStack = [], + index = -1; +function createCursor(defaultValue) { + return { current: defaultValue }; +} +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; +} +var contextStackCursor = createCursor(emptyObject), + didPerformWorkStackCursor = createCursor(!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 popTopLevelContextObject(fiber) { + pop(didPerformWorkStackCursor, fiber); + pop(contextStackCursor, fiber); +} +function pushTopLevelContextObject(fiber, context, didChange) { + invariant( + contextStackCursor.current === emptyObject, + "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; + this.sibling = this.child = this.return = this.stateNode = this.type = null; + this.index = 0; + this.ref = null; + this.pendingProps = pendingProps; + this.memoizedState = this.updateQueue = this.memoizedProps = null; + this.mode = mode; + this.effectTag = 0; + this.lastEffect = this.firstEffect = this.nextEffect = null; + this.expirationTime = 0; + this.alternate = null; + this.treeBaseTime = this.selfBaseTime = this.actualStartTime = this.actualDuration = 0; +} +function createWorkInProgress(current, pendingProps, expirationTime) { + var workInProgress = current.alternate; + null === workInProgress + ? ((workInProgress = new FiberNode( + current.tag, + pendingProps, + current.key, + current.mode + )), + (workInProgress.type = current.type), + (workInProgress.stateNode = current.stateNode), + (workInProgress.alternate = current), + (current.alternate = workInProgress)) + : ((workInProgress.pendingProps = pendingProps), + (workInProgress.effectTag = 0), + (workInProgress.nextEffect = null), + (workInProgress.firstEffect = null), + (workInProgress.lastEffect = null), + (workInProgress.actualDuration = 0), + (workInProgress.actualStartTime = 0)); + workInProgress.expirationTime = expirationTime; + workInProgress.child = current.child; + workInProgress.memoizedProps = current.memoizedProps; + workInProgress.memoizedState = current.memoizedState; + workInProgress.updateQueue = current.updateQueue; + workInProgress.sibling = current.sibling; + workInProgress.index = current.index; + workInProgress.ref = current.ref; + workInProgress.selfBaseTime = current.selfBaseTime; + workInProgress.treeBaseTime = current.treeBaseTime; + return workInProgress; +} +function createFiberFromElement(element, mode, expirationTime) { + var type = element.type, + key = element.key; + element = element.props; + if ("function" === typeof type) + var fiberTag = type.prototype && type.prototype.isReactComponent ? 2 : 0; + else if ("string" === typeof type) fiberTag = 5; + else + switch (type) { + case REACT_FRAGMENT_TYPE: + return createFiberFromFragment( + element.children, + mode, + expirationTime, + key + ); + case REACT_ASYNC_MODE_TYPE: + fiberTag = 11; + mode |= 3; + break; + case REACT_STRICT_MODE_TYPE: + fiberTag = 11; + mode |= 2; + break; + case REACT_PROFILER_TYPE: + return ( + (type = new FiberNode(15, element, key, mode | 4)), + (type.type = REACT_PROFILER_TYPE), + (type.expirationTime = expirationTime), + type + ); + case REACT_TIMEOUT_TYPE: + fiberTag = 16; + mode |= 2; + break; + default: + a: { + switch ("object" === typeof type && null !== type + ? type.$$typeof + : null) { + case REACT_PROVIDER_TYPE: + fiberTag = 13; + break a; + case REACT_CONTEXT_TYPE: + fiberTag = 12; + break a; + case REACT_FORWARD_REF_TYPE: + fiberTag = 14; + break a; + default: + invariant( + !1, + "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", + null == type ? type : typeof type, + "" + ); + } + fiberTag = void 0; + } + } + mode = new FiberNode(fiberTag, element, key, mode); + mode.type = type; + mode.expirationTime = expirationTime; + return mode; +} +function createFiberFromFragment(elements, mode, expirationTime, key) { + elements = new FiberNode(10, elements, key, mode); + elements.expirationTime = expirationTime; + return elements; +} +function createFiberFromText(content, mode, expirationTime) { + content = new FiberNode(6, content, null, mode); + content.expirationTime = expirationTime; + return content; +} +function createFiberFromPortal(portal, mode, expirationTime) { + mode = new FiberNode( + 4, + null !== portal.children ? portal.children : [], + portal.key, + mode + ); + mode.expirationTime = expirationTime; + mode.stateNode = { + containerInfo: portal.containerInfo, + pendingChildren: null, + implementation: portal.implementation + }; + return mode; +} +function createFiberRoot(containerInfo, isAsync, hydrate) { + isAsync = new FiberNode(3, null, null, isAsync ? 3 : 0); + containerInfo = { + current: isAsync, + containerInfo: containerInfo, + pendingChildren: null, + earliestPendingTime: 0, + latestPendingTime: 0, + earliestSuspendedTime: 0, + latestSuspendedTime: 0, + latestPingedTime: 0, + didError: !1, + pendingCommitExpirationTime: 0, + finishedWork: null, + context: null, + pendingContext: null, + hydrate: hydrate, + nextExpirationTimeToWorkOn: 0, + expirationTime: 0, + firstBatch: null, + nextScheduledRoot: null + }; + return (isAsync.stateNode = containerInfo); +} +var onCommitFiberRoot = null, + onCommitFiberUnmount = null; +function catchErrors(fn) { + return function(arg) { + try { + return fn(arg); + } catch (err) {} + }; +} +function injectInternals(internals) { + if ("undefined" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) return !1; + var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__; + if (hook.isDisabled || !hook.supportsFiber) return !0; + try { + var rendererID = hook.inject(internals); + onCommitFiberRoot = catchErrors(function(root) { + return hook.onCommitFiberRoot(rendererID, root); + }); + onCommitFiberUnmount = catchErrors(function(fiber) { + return hook.onCommitFiberUnmount(rendererID, fiber); + }); + } catch (err) {} + return !0; +} +function onCommitRoot(root) { + "function" === typeof onCommitFiberRoot && onCommitFiberRoot(root); +} +function onCommitUnmount(fiber) { + "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(fiber); +} +function markPendingPriorityLevel(root, expirationTime) { + root.didError = !1; + var earliestPendingTime = root.earliestPendingTime; + 0 === earliestPendingTime + ? (root.earliestPendingTime = root.latestPendingTime = expirationTime) + : earliestPendingTime > expirationTime + ? (root.earliestPendingTime = expirationTime) + : root.latestPendingTime < expirationTime && + (root.latestPendingTime = expirationTime); + findNextPendingPriorityLevel(root); +} +function findNextPendingPriorityLevel(root) { + var earliestSuspendedTime = root.earliestSuspendedTime, + earliestPendingTime = root.earliestPendingTime; + if (0 === earliestSuspendedTime) + var nextExpirationTimeToWorkOn = (earliestSuspendedTime = earliestPendingTime); + else + 0 !== earliestPendingTime + ? ((nextExpirationTimeToWorkOn = earliestPendingTime), + (earliestSuspendedTime = + earliestSuspendedTime < earliestPendingTime + ? earliestSuspendedTime + : earliestPendingTime)) + : (nextExpirationTimeToWorkOn = earliestSuspendedTime = + root.latestPingedTime); + root.didError && (earliestSuspendedTime = 1); + root.nextExpirationTimeToWorkOn = nextExpirationTimeToWorkOn; + root.expirationTime = earliestSuspendedTime; +} +var hasForceUpdate = !1; +function createUpdateQueue(baseState) { + return { + expirationTime: 0, + baseState: baseState, + firstUpdate: null, + lastUpdate: null, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; +} +function cloneUpdateQueue(currentQueue) { + return { + expirationTime: currentQueue.expirationTime, + baseState: currentQueue.baseState, + firstUpdate: currentQueue.firstUpdate, + lastUpdate: currentQueue.lastUpdate, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; +} +function createUpdate(expirationTime) { + return { + expirationTime: expirationTime, + tag: 0, + payload: null, + callback: null, + next: null, + nextEffect: null + }; +} +function appendUpdateToQueue(queue, update, expirationTime) { + null === queue.lastUpdate + ? (queue.firstUpdate = queue.lastUpdate = update) + : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); + if (0 === queue.expirationTime || queue.expirationTime > expirationTime) + queue.expirationTime = expirationTime; +} +function enqueueUpdate(fiber, update, expirationTime) { + var alternate = fiber.alternate; + if (null === alternate) { + var queue1 = fiber.updateQueue; + var queue2 = null; + null === queue1 && + (queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState)); + } else + (queue1 = fiber.updateQueue), + (queue2 = alternate.updateQueue), + null === queue1 + ? null === queue2 + ? ((queue1 = fiber.updateQueue = createUpdateQueue( + fiber.memoizedState + )), + (queue2 = alternate.updateQueue = createUpdateQueue( + alternate.memoizedState + ))) + : (queue1 = fiber.updateQueue = cloneUpdateQueue(queue2)) + : null === queue2 && + (queue2 = alternate.updateQueue = cloneUpdateQueue(queue1)); + null === queue2 || queue1 === queue2 + ? appendUpdateToQueue(queue1, update, expirationTime) + : null === queue1.lastUpdate || null === queue2.lastUpdate + ? (appendUpdateToQueue(queue1, update, expirationTime), + appendUpdateToQueue(queue2, update, expirationTime)) + : (appendUpdateToQueue(queue1, update, expirationTime), + (queue2.lastUpdate = update)); +} +function enqueueCapturedUpdate(workInProgress, update, renderExpirationTime) { + var workInProgressQueue = workInProgress.updateQueue; + workInProgressQueue = + null === workInProgressQueue + ? (workInProgress.updateQueue = createUpdateQueue( + workInProgress.memoizedState + )) + : ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue); + null === workInProgressQueue.lastCapturedUpdate + ? (workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update) + : ((workInProgressQueue.lastCapturedUpdate.next = update), + (workInProgressQueue.lastCapturedUpdate = update)); + if ( + 0 === workInProgressQueue.expirationTime || + workInProgressQueue.expirationTime > renderExpirationTime + ) + workInProgressQueue.expirationTime = renderExpirationTime; +} +function ensureWorkInProgressQueueIsAClone(workInProgress, queue) { + var current = workInProgress.alternate; + null !== current && + queue === current.updateQueue && + (queue = workInProgress.updateQueue = cloneUpdateQueue(queue)); + return queue; +} +function getStateFromUpdate( + workInProgress, + queue, + update, + prevState, + nextProps, + instance +) { + switch (update.tag) { + case 1: + return ( + (workInProgress = update.payload), + "function" === typeof workInProgress + ? workInProgress.call(instance, prevState, nextProps) + : workInProgress + ); + case 3: + workInProgress.effectTag = (workInProgress.effectTag & -1025) | 64; + case 0: + workInProgress = update.payload; + nextProps = + "function" === typeof workInProgress + ? workInProgress.call(instance, prevState, nextProps) + : workInProgress; + if (null === nextProps || void 0 === nextProps) break; + return Object.assign({}, prevState, nextProps); + case 2: + hasForceUpdate = !0; + } + return prevState; +} +function processUpdateQueue( + workInProgress, + queue, + props, + instance, + renderExpirationTime +) { + hasForceUpdate = !1; + if ( + !(0 === queue.expirationTime || queue.expirationTime > renderExpirationTime) + ) { + queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + for ( + var newBaseState = queue.baseState, + newFirstUpdate = null, + newExpirationTime = 0, + update = queue.firstUpdate, + resultState = newBaseState; + null !== update; + + ) { + var updateExpirationTime = update.expirationTime; + if (updateExpirationTime > renderExpirationTime) { + if ( + (null === newFirstUpdate && + ((newFirstUpdate = update), (newBaseState = resultState)), + 0 === newExpirationTime || newExpirationTime > updateExpirationTime) + ) + newExpirationTime = updateExpirationTime; + } else + (resultState = getStateFromUpdate( + workInProgress, + queue, + update, + resultState, + props, + instance + )), + null !== update.callback && + ((workInProgress.effectTag |= 32), + (update.nextEffect = null), + null === queue.lastEffect + ? (queue.firstEffect = queue.lastEffect = update) + : ((queue.lastEffect.nextEffect = update), + (queue.lastEffect = update))); + update = update.next; + } + updateExpirationTime = null; + for (update = queue.firstCapturedUpdate; null !== update; ) { + var _updateExpirationTime = update.expirationTime; + if (_updateExpirationTime > renderExpirationTime) { + if ( + (null === updateExpirationTime && + ((updateExpirationTime = update), + null === newFirstUpdate && (newBaseState = resultState)), + 0 === newExpirationTime || newExpirationTime > _updateExpirationTime) + ) + newExpirationTime = _updateExpirationTime; + } else + (resultState = getStateFromUpdate( + workInProgress, + queue, + update, + resultState, + props, + instance + )), + null !== update.callback && + ((workInProgress.effectTag |= 32), + (update.nextEffect = null), + null === queue.lastCapturedEffect + ? (queue.firstCapturedEffect = queue.lastCapturedEffect = update) + : ((queue.lastCapturedEffect.nextEffect = update), + (queue.lastCapturedEffect = update))); + update = update.next; + } + null === newFirstUpdate && (queue.lastUpdate = null); + null === updateExpirationTime + ? (queue.lastCapturedUpdate = null) + : (workInProgress.effectTag |= 32); + null === newFirstUpdate && + null === updateExpirationTime && + (newBaseState = resultState); + queue.baseState = newBaseState; + queue.firstUpdate = newFirstUpdate; + queue.firstCapturedUpdate = updateExpirationTime; + queue.expirationTime = newExpirationTime; + workInProgress.memoizedState = resultState; + } +} +function callCallback(callback, context) { + invariant( + "function" === typeof callback, + "Invalid argument passed as callback. Expected a function. Instead received: %s", + callback + ); + callback.call(context); +} +function commitUpdateQueue(finishedWork, finishedQueue, instance) { + null !== finishedQueue.firstCapturedUpdate && + (null !== finishedQueue.lastUpdate && + ((finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate), + (finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate)), + (finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null)); + finishedWork = finishedQueue.firstEffect; + for ( + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + null !== finishedWork; + + ) { + var _callback3 = finishedWork.callback; + null !== _callback3 && + ((finishedWork.callback = null), callCallback(_callback3, instance)); + finishedWork = finishedWork.nextEffect; + } + finishedWork = finishedQueue.firstCapturedEffect; + for ( + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; + null !== finishedWork; + + ) + (finishedQueue = finishedWork.callback), + null !== finishedQueue && + ((finishedWork.callback = null), callCallback(finishedQueue, instance)), + (finishedWork = finishedWork.nextEffect); +} +function createCapturedValue(value, source) { + return { + value: value, + source: source, + stack: getStackAddendumByWorkInProgressFiber(source) + }; +} +var providerCursor = createCursor(null), + valueCursor = createCursor(null), + changedBitsCursor = createCursor(0); +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; +} +function popProvider(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; +} +var NO_CONTEXT = {}, + contextStackCursor$1 = createCursor(NO_CONTEXT), + contextFiberStackCursor = createCursor(NO_CONTEXT), + rootInstanceStackCursor = createCursor(NO_CONTEXT); +function requiredContext(c) { + invariant( + c !== NO_CONTEXT, + "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." + ); + return c; +} +function pushHostContainer(fiber, nextRootInstance) { + push(rootInstanceStackCursor, nextRootInstance, fiber); + push(contextFiberStackCursor, fiber, fiber); + push(contextStackCursor$1, NO_CONTEXT, fiber); + pop(contextStackCursor$1, fiber); + push(contextStackCursor$1, { isInAParentText: !1 }, fiber); +} +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} +function popHostContext(fiber) { + contextFiberStackCursor.current === fiber && + (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); +} +var commitTime = 0, + timerPausedAt = 0, + totalElapsedPauseTime = 0; +function recordElapsedActualRenderTime(fiber) { + fiber.actualDuration = now$1() - totalElapsedPauseTime - fiber.actualDuration; +} +function resumeActualRenderTimerIfPaused() { + 0 < timerPausedAt && + ((totalElapsedPauseTime += now$1() - timerPausedAt), (timerPausedAt = 0)); +} +var baseStartTime = -1, + hasOwnProperty = Object.prototype.hasOwnProperty; +function is(x, y) { + return x === y ? 0 !== x || 0 !== y || 1 / x === 1 / y : x !== x && y !== y; +} +function shallowEqual(objA, objB) { + if (is(objA, objB)) return !0; + if ( + "object" !== typeof objA || + null === objA || + "object" !== typeof objB || + null === objB + ) + return !1; + var keysA = Object.keys(objA), + keysB = Object.keys(objB); + if (keysA.length !== keysB.length) return !1; + for (keysB = 0; keysB < keysA.length; keysB++) + if ( + !hasOwnProperty.call(objB, keysA[keysB]) || + !is(objA[keysA[keysB]], objB[keysA[keysB]]) + ) + return !1; + return !0; +} +function applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + nextProps +) { + var prevState = workInProgress.memoizedState; + getDerivedStateFromProps = getDerivedStateFromProps(nextProps, prevState); + prevState = + null === getDerivedStateFromProps || void 0 === getDerivedStateFromProps + ? prevState + : Object.assign({}, prevState, getDerivedStateFromProps); + workInProgress.memoizedState = prevState; + workInProgress = workInProgress.updateQueue; + null !== workInProgress && + 0 === workInProgress.expirationTime && + (workInProgress.baseState = prevState); +} +var classComponentUpdater = { + isMounted: function(component) { + return (component = component._reactInternalFiber) + ? 2 === isFiberMountedImpl(component) + : !1; + }, + enqueueSetState: function(inst, payload, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.payload = payload; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + }, + enqueueReplaceState: function(inst, payload, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.tag = 1; + update.payload = payload; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + }, + enqueueForceUpdate: function(inst, callback) { + inst = inst._reactInternalFiber; + var currentTime = recalculateCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, inst); + var update = createUpdate(currentTime); + update.tag = 2; + void 0 !== callback && null !== callback && (update.callback = callback); + enqueueUpdate(inst, update, currentTime); + scheduleWork(inst, currentTime); + } +}; +function checkShouldComponentUpdate( + workInProgress, + oldProps, + newProps, + oldState, + newState, + newContext +) { + var instance = workInProgress.stateNode; + workInProgress = workInProgress.type; + return "function" === typeof instance.shouldComponentUpdate + ? instance.shouldComponentUpdate(newProps, newState, newContext) + : workInProgress.prototype && workInProgress.prototype.isPureReactComponent + ? !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) + : !0; +} +function callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + newContext +) { + workInProgress = instance.state; + "function" === typeof instance.componentWillReceiveProps && + instance.componentWillReceiveProps(newProps, newContext); + "function" === typeof instance.UNSAFE_componentWillReceiveProps && + instance.UNSAFE_componentWillReceiveProps(newProps, newContext); + instance.state !== workInProgress && + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); +} +function mountClassInstance(workInProgress, renderExpirationTime) { + var ctor = workInProgress.type, + instance = workInProgress.stateNode, + props = workInProgress.pendingProps, + unmaskedContext = getUnmaskedContext(workInProgress); + instance.props = props; + instance.state = workInProgress.memoizedState; + instance.refs = emptyObject; + instance.context = getMaskedContext(workInProgress, unmaskedContext); + unmaskedContext = workInProgress.updateQueue; + null !== unmaskedContext && + (processUpdateQueue( + workInProgress, + unmaskedContext, + props, + instance, + renderExpirationTime + ), + (instance.state = workInProgress.memoizedState)); + unmaskedContext = workInProgress.type.getDerivedStateFromProps; + "function" === typeof unmaskedContext && + (applyDerivedStateFromProps(workInProgress, unmaskedContext, props), + (instance.state = workInProgress.memoizedState)); + "function" === typeof ctor.getDerivedStateFromProps || + "function" === typeof instance.getSnapshotBeforeUpdate || + ("function" !== typeof instance.UNSAFE_componentWillMount && + "function" !== typeof instance.componentWillMount) || + ((ctor = instance.state), + "function" === typeof instance.componentWillMount && + instance.componentWillMount(), + "function" === typeof instance.UNSAFE_componentWillMount && + instance.UNSAFE_componentWillMount(), + ctor !== instance.state && + classComponentUpdater.enqueueReplaceState(instance, instance.state, null), + (unmaskedContext = workInProgress.updateQueue), + null !== unmaskedContext && + (processUpdateQueue( + workInProgress, + unmaskedContext, + props, + instance, + renderExpirationTime + ), + (instance.state = workInProgress.memoizedState))); + "function" === typeof instance.componentDidMount && + (workInProgress.effectTag |= 4); +} +var isArray$1 = Array.isArray; +function coerceRef(returnFiber, current, element) { + returnFiber = element.ref; + if ( + null !== returnFiber && + "function" !== typeof returnFiber && + "object" !== typeof returnFiber + ) { + if (element._owner) { + element = element._owner; + var inst = void 0; + element && + (invariant( + 2 === element.tag, + "Stateless function components cannot have refs." + ), + (inst = element.stateNode)); + invariant( + inst, + "Missing owner for string ref %s. This error is likely caused by a bug in React. Please file an issue.", + returnFiber + ); + var stringRef = "" + returnFiber; + if ( + null !== current && + null !== current.ref && + "function" === typeof current.ref && + current.ref._stringRef === stringRef + ) + return current.ref; + current = function(value) { + var refs = inst.refs === emptyObject ? (inst.refs = {}) : inst.refs; + null === value ? delete refs[stringRef] : (refs[stringRef] = value); + }; + current._stringRef = stringRef; + return current; + } + invariant( + "string" === typeof returnFiber, + "Expected ref to be a function or a string." + ); + invariant( + element._owner, + "Element ref was specified as a string (%s) but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a functional component\n2. You may be adding a ref to a component that was not created inside a component's render method\n3. You have multiple copies of React loaded\nSee https://fb.me/react-refs-must-have-owner for more information.", + returnFiber + ); + } + return returnFiber; +} +function throwOnInvalidObjectType(returnFiber, newChild) { + "textarea" !== returnFiber.type && + invariant( + !1, + "Objects are not valid as a React child (found: %s).%s", + "[object Object]" === Object.prototype.toString.call(newChild) + ? "object with keys {" + Object.keys(newChild).join(", ") + "}" + : newChild, + "" + ); +} +function ChildReconciler(shouldTrackSideEffects) { + function deleteChild(returnFiber, childToDelete) { + if (shouldTrackSideEffects) { + var last = returnFiber.lastEffect; + null !== last + ? ((last.nextEffect = childToDelete), + (returnFiber.lastEffect = childToDelete)) + : (returnFiber.firstEffect = returnFiber.lastEffect = childToDelete); + childToDelete.nextEffect = null; + childToDelete.effectTag = 8; + } + } + function deleteRemainingChildren(returnFiber, currentFirstChild) { + if (!shouldTrackSideEffects) return null; + for (; null !== currentFirstChild; ) + deleteChild(returnFiber, currentFirstChild), + (currentFirstChild = currentFirstChild.sibling); + return null; + } + function mapRemainingChildren(returnFiber, currentFirstChild) { + for (returnFiber = new Map(); null !== currentFirstChild; ) + null !== currentFirstChild.key + ? returnFiber.set(currentFirstChild.key, currentFirstChild) + : returnFiber.set(currentFirstChild.index, currentFirstChild), + (currentFirstChild = currentFirstChild.sibling); + return returnFiber; + } + function useFiber(fiber, pendingProps, expirationTime) { + fiber = createWorkInProgress(fiber, pendingProps, expirationTime); + fiber.index = 0; + fiber.sibling = null; + return fiber; + } + function placeChild(newFiber, lastPlacedIndex, newIndex) { + newFiber.index = newIndex; + if (!shouldTrackSideEffects) return lastPlacedIndex; + newIndex = newFiber.alternate; + if (null !== newIndex) + return ( + (newIndex = newIndex.index), + newIndex < lastPlacedIndex + ? ((newFiber.effectTag = 2), lastPlacedIndex) + : newIndex + ); + newFiber.effectTag = 2; + return lastPlacedIndex; + } + function placeSingleChild(newFiber) { + shouldTrackSideEffects && + null === newFiber.alternate && + (newFiber.effectTag = 2); + return newFiber; + } + function updateTextNode(returnFiber, current, textContent, expirationTime) { + if (null === current || 6 !== current.tag) + return ( + (current = createFiberFromText( + textContent, + returnFiber.mode, + expirationTime + )), + (current.return = returnFiber), + current + ); + current = useFiber(current, textContent, expirationTime); + current.return = returnFiber; + return current; + } + function updateElement(returnFiber, current, element, expirationTime) { + if (null !== current && current.type === element.type) + return ( + (expirationTime = useFiber(current, element.props, expirationTime)), + (expirationTime.ref = coerceRef(returnFiber, current, element)), + (expirationTime.return = returnFiber), + expirationTime + ); + expirationTime = createFiberFromElement( + element, + returnFiber.mode, + expirationTime + ); + expirationTime.ref = coerceRef(returnFiber, current, element); + expirationTime.return = returnFiber; + return expirationTime; + } + function updatePortal(returnFiber, current, portal, expirationTime) { + if ( + null === current || + 4 !== current.tag || + current.stateNode.containerInfo !== portal.containerInfo || + current.stateNode.implementation !== portal.implementation + ) + return ( + (current = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime + )), + (current.return = returnFiber), + current + ); + current = useFiber(current, portal.children || [], expirationTime); + current.return = returnFiber; + return current; + } + function updateFragment(returnFiber, current, fragment, expirationTime, key) { + if (null === current || 10 !== current.tag) + return ( + (current = createFiberFromFragment( + fragment, + returnFiber.mode, + expirationTime, + key + )), + (current.return = returnFiber), + current + ); + current = useFiber(current, fragment, expirationTime); + current.return = returnFiber; + return current; + } + function createChild(returnFiber, newChild, expirationTime) { + if ("string" === typeof newChild || "number" === typeof newChild) + return ( + (newChild = createFiberFromText( + "" + newChild, + returnFiber.mode, + expirationTime + )), + (newChild.return = returnFiber), + newChild + ); + if ("object" === typeof newChild && null !== newChild) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + return ( + (expirationTime = createFiberFromElement( + newChild, + returnFiber.mode, + expirationTime + )), + (expirationTime.ref = coerceRef(returnFiber, null, newChild)), + (expirationTime.return = returnFiber), + expirationTime + ); + case REACT_PORTAL_TYPE: + return ( + (newChild = createFiberFromPortal( + newChild, + returnFiber.mode, + expirationTime + )), + (newChild.return = returnFiber), + newChild + ); + } + if (isArray$1(newChild) || getIteratorFn(newChild)) + return ( + (newChild = createFiberFromFragment( + newChild, + returnFiber.mode, + expirationTime, + null + )), + (newChild.return = returnFiber), + newChild + ); + throwOnInvalidObjectType(returnFiber, newChild); + } + return null; + } + function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { + var key = null !== oldFiber ? oldFiber.key : null; + if ("string" === typeof newChild || "number" === typeof newChild) + return null !== key + ? null + : updateTextNode(returnFiber, oldFiber, "" + newChild, expirationTime); + if ("object" === typeof newChild && null !== newChild) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + return newChild.key === key + ? newChild.type === REACT_FRAGMENT_TYPE + ? updateFragment( + returnFiber, + oldFiber, + newChild.props.children, + expirationTime, + key + ) + : updateElement(returnFiber, oldFiber, newChild, expirationTime) + : null; + case REACT_PORTAL_TYPE: + return newChild.key === key + ? updatePortal(returnFiber, oldFiber, newChild, expirationTime) + : null; + } + if (isArray$1(newChild) || getIteratorFn(newChild)) + return null !== key + ? null + : updateFragment( + returnFiber, + oldFiber, + newChild, + expirationTime, + null + ); + throwOnInvalidObjectType(returnFiber, newChild); + } + return null; + } + function updateFromMap( + existingChildren, + returnFiber, + newIdx, + newChild, + expirationTime + ) { + if ("string" === typeof newChild || "number" === typeof newChild) + return ( + (existingChildren = existingChildren.get(newIdx) || null), + updateTextNode( + returnFiber, + existingChildren, + "" + newChild, + expirationTime + ) + ); + if ("object" === typeof newChild && null !== newChild) { + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + return ( + (existingChildren = + existingChildren.get( + null === newChild.key ? newIdx : newChild.key + ) || null), + newChild.type === REACT_FRAGMENT_TYPE + ? updateFragment( + returnFiber, + existingChildren, + newChild.props.children, + expirationTime, + newChild.key + ) + : updateElement( + returnFiber, + existingChildren, + newChild, + expirationTime + ) + ); + case REACT_PORTAL_TYPE: + return ( + (existingChildren = + existingChildren.get( + null === newChild.key ? newIdx : newChild.key + ) || null), + updatePortal( + returnFiber, + existingChildren, + newChild, + expirationTime + ) + ); + } + if (isArray$1(newChild) || getIteratorFn(newChild)) + return ( + (existingChildren = existingChildren.get(newIdx) || null), + updateFragment( + returnFiber, + existingChildren, + newChild, + expirationTime, + null + ) + ); + throwOnInvalidObjectType(returnFiber, newChild); + } + return null; + } + function reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChildren, + expirationTime + ) { + for ( + var resultingFirstChild = null, + previousNewFiber = null, + oldFiber = currentFirstChild, + newIdx = (currentFirstChild = 0), + nextOldFiber = null; + null !== oldFiber && newIdx < newChildren.length; + newIdx++ + ) { + oldFiber.index > newIdx + ? ((nextOldFiber = oldFiber), (oldFiber = null)) + : (nextOldFiber = oldFiber.sibling); + var newFiber = updateSlot( + returnFiber, + oldFiber, + newChildren[newIdx], + expirationTime + ); + if (null === newFiber) { + null === oldFiber && (oldFiber = nextOldFiber); + break; + } + shouldTrackSideEffects && + oldFiber && + null === newFiber.alternate && + deleteChild(returnFiber, oldFiber); + currentFirstChild = placeChild(newFiber, currentFirstChild, newIdx); + null === previousNewFiber + ? (resultingFirstChild = newFiber) + : (previousNewFiber.sibling = newFiber); + previousNewFiber = newFiber; + oldFiber = nextOldFiber; + } + if (newIdx === newChildren.length) + return ( + deleteRemainingChildren(returnFiber, oldFiber), resultingFirstChild + ); + if (null === oldFiber) { + for (; newIdx < newChildren.length; newIdx++) + if ( + (oldFiber = createChild( + returnFiber, + newChildren[newIdx], + expirationTime + )) + ) + (currentFirstChild = placeChild(oldFiber, currentFirstChild, newIdx)), + null === previousNewFiber + ? (resultingFirstChild = oldFiber) + : (previousNewFiber.sibling = oldFiber), + (previousNewFiber = oldFiber); + return resultingFirstChild; + } + for ( + oldFiber = mapRemainingChildren(returnFiber, oldFiber); + newIdx < newChildren.length; + newIdx++ + ) + if ( + (nextOldFiber = updateFromMap( + oldFiber, + returnFiber, + newIdx, + newChildren[newIdx], + expirationTime + )) + ) + shouldTrackSideEffects && + null !== nextOldFiber.alternate && + oldFiber.delete( + null === nextOldFiber.key ? newIdx : nextOldFiber.key + ), + (currentFirstChild = placeChild( + nextOldFiber, + currentFirstChild, + newIdx + )), + null === previousNewFiber + ? (resultingFirstChild = nextOldFiber) + : (previousNewFiber.sibling = nextOldFiber), + (previousNewFiber = nextOldFiber); + shouldTrackSideEffects && + oldFiber.forEach(function(child) { + return deleteChild(returnFiber, child); + }); + return resultingFirstChild; + } + function reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChildrenIterable, + expirationTime + ) { + var iteratorFn = getIteratorFn(newChildrenIterable); + invariant( + "function" === typeof iteratorFn, + "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue." + ); + newChildrenIterable = iteratorFn.call(newChildrenIterable); + invariant( + null != newChildrenIterable, + "An iterable object provided no iterator." + ); + for ( + var previousNewFiber = (iteratorFn = null), + oldFiber = currentFirstChild, + newIdx = (currentFirstChild = 0), + nextOldFiber = null, + step = newChildrenIterable.next(); + null !== oldFiber && !step.done; + newIdx++, step = newChildrenIterable.next() + ) { + oldFiber.index > newIdx + ? ((nextOldFiber = oldFiber), (oldFiber = null)) + : (nextOldFiber = oldFiber.sibling); + var newFiber = updateSlot( + returnFiber, + oldFiber, + step.value, + expirationTime + ); + if (null === newFiber) { + oldFiber || (oldFiber = nextOldFiber); + break; + } + shouldTrackSideEffects && + oldFiber && + null === newFiber.alternate && + deleteChild(returnFiber, oldFiber); + currentFirstChild = placeChild(newFiber, currentFirstChild, newIdx); + null === previousNewFiber + ? (iteratorFn = newFiber) + : (previousNewFiber.sibling = newFiber); + previousNewFiber = newFiber; + oldFiber = nextOldFiber; + } + if (step.done) + return deleteRemainingChildren(returnFiber, oldFiber), iteratorFn; + if (null === oldFiber) { + for (; !step.done; newIdx++, step = newChildrenIterable.next()) + (step = createChild(returnFiber, step.value, expirationTime)), + null !== step && + ((currentFirstChild = placeChild(step, currentFirstChild, newIdx)), + null === previousNewFiber + ? (iteratorFn = step) + : (previousNewFiber.sibling = step), + (previousNewFiber = step)); + return iteratorFn; + } + for ( + oldFiber = mapRemainingChildren(returnFiber, oldFiber); + !step.done; + newIdx++, step = newChildrenIterable.next() + ) + (step = updateFromMap( + oldFiber, + returnFiber, + newIdx, + step.value, + expirationTime + )), + null !== step && + (shouldTrackSideEffects && + null !== step.alternate && + oldFiber.delete(null === step.key ? newIdx : step.key), + (currentFirstChild = placeChild(step, currentFirstChild, newIdx)), + null === previousNewFiber + ? (iteratorFn = step) + : (previousNewFiber.sibling = step), + (previousNewFiber = step)); + shouldTrackSideEffects && + oldFiber.forEach(function(child) { + return deleteChild(returnFiber, child); + }); + return iteratorFn; + } + return function(returnFiber, currentFirstChild, newChild, expirationTime) { + var isUnkeyedTopLevelFragment = + "object" === typeof newChild && + null !== newChild && + newChild.type === REACT_FRAGMENT_TYPE && + null === newChild.key; + isUnkeyedTopLevelFragment && (newChild = newChild.props.children); + var isObject = "object" === typeof newChild && null !== newChild; + if (isObject) + switch (newChild.$$typeof) { + case REACT_ELEMENT_TYPE: + a: { + isObject = newChild.key; + for ( + isUnkeyedTopLevelFragment = currentFirstChild; + null !== isUnkeyedTopLevelFragment; + + ) { + if (isUnkeyedTopLevelFragment.key === isObject) + if ( + 10 === isUnkeyedTopLevelFragment.tag + ? newChild.type === REACT_FRAGMENT_TYPE + : isUnkeyedTopLevelFragment.type === newChild.type + ) { + deleteRemainingChildren( + returnFiber, + isUnkeyedTopLevelFragment.sibling + ); + currentFirstChild = useFiber( + isUnkeyedTopLevelFragment, + newChild.type === REACT_FRAGMENT_TYPE + ? newChild.props.children + : newChild.props, + expirationTime + ); + currentFirstChild.ref = coerceRef( + returnFiber, + isUnkeyedTopLevelFragment, + newChild + ); + currentFirstChild.return = returnFiber; + returnFiber = currentFirstChild; + break a; + } else { + deleteRemainingChildren( + returnFiber, + isUnkeyedTopLevelFragment + ); + break; + } + else deleteChild(returnFiber, isUnkeyedTopLevelFragment); + isUnkeyedTopLevelFragment = isUnkeyedTopLevelFragment.sibling; + } + newChild.type === REACT_FRAGMENT_TYPE + ? ((currentFirstChild = createFiberFromFragment( + newChild.props.children, + returnFiber.mode, + expirationTime, + newChild.key + )), + (currentFirstChild.return = returnFiber), + (returnFiber = currentFirstChild)) + : ((expirationTime = createFiberFromElement( + newChild, + returnFiber.mode, + expirationTime + )), + (expirationTime.ref = coerceRef( + returnFiber, + currentFirstChild, + newChild + )), + (expirationTime.return = returnFiber), + (returnFiber = expirationTime)); + } + return placeSingleChild(returnFiber); + case REACT_PORTAL_TYPE: + a: { + for ( + isUnkeyedTopLevelFragment = newChild.key; + null !== currentFirstChild; + + ) { + if (currentFirstChild.key === isUnkeyedTopLevelFragment) + if ( + 4 === currentFirstChild.tag && + currentFirstChild.stateNode.containerInfo === + newChild.containerInfo && + currentFirstChild.stateNode.implementation === + newChild.implementation + ) { + deleteRemainingChildren( + returnFiber, + currentFirstChild.sibling + ); + currentFirstChild = useFiber( + currentFirstChild, + newChild.children || [], + expirationTime + ); + currentFirstChild.return = returnFiber; + returnFiber = currentFirstChild; + break a; + } else { + deleteRemainingChildren(returnFiber, currentFirstChild); + break; + } + else deleteChild(returnFiber, currentFirstChild); + currentFirstChild = currentFirstChild.sibling; + } + currentFirstChild = createFiberFromPortal( + newChild, + returnFiber.mode, + expirationTime + ); + currentFirstChild.return = returnFiber; + returnFiber = currentFirstChild; + } + return placeSingleChild(returnFiber); + } + if ("string" === typeof newChild || "number" === typeof newChild) + return ( + (newChild = "" + newChild), + null !== currentFirstChild && 6 === currentFirstChild.tag + ? (deleteRemainingChildren(returnFiber, currentFirstChild.sibling), + (currentFirstChild = useFiber( + currentFirstChild, + newChild, + expirationTime + )), + (currentFirstChild.return = returnFiber), + (returnFiber = currentFirstChild)) + : (deleteRemainingChildren(returnFiber, currentFirstChild), + (currentFirstChild = createFiberFromText( + newChild, + returnFiber.mode, + expirationTime + )), + (currentFirstChild.return = returnFiber), + (returnFiber = currentFirstChild)), + placeSingleChild(returnFiber) + ); + if (isArray$1(newChild)) + return reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); + if (getIteratorFn(newChild)) + return reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); + isObject && throwOnInvalidObjectType(returnFiber, newChild); + if ("undefined" === typeof newChild && !isUnkeyedTopLevelFragment) + switch (returnFiber.tag) { + case 2: + case 1: + (expirationTime = returnFiber.type), + invariant( + !1, + "%s(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.", + expirationTime.displayName || expirationTime.name || "Component" + ); + } + return deleteRemainingChildren(returnFiber, currentFirstChild); + }; +} +var reconcileChildFibers = ChildReconciler(!0), + mountChildFibers = ChildReconciler(!1), + hydrationParentFiber = null, + nextHydratableInstance = null, + isHydrating = !1; +function tryHydrate(fiber, nextInstance) { + switch (fiber.tag) { + case 5: + return ( + (nextInstance = shim$1(nextInstance, fiber.type, fiber.pendingProps)), + null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 + ); + case 6: + return ( + (nextInstance = shim$1(nextInstance, fiber.pendingProps)), + null !== nextInstance ? ((fiber.stateNode = nextInstance), !0) : !1 + ); + default: + return !1; + } +} +function tryToClaimNextHydratableInstance(fiber$jscomp$0) { + if (isHydrating) { + var nextInstance = nextHydratableInstance; + if (nextInstance) { + var firstAttemptedInstance = nextInstance; + if (!tryHydrate(fiber$jscomp$0, nextInstance)) { + nextInstance = shim$1(firstAttemptedInstance); + if (!nextInstance || !tryHydrate(fiber$jscomp$0, nextInstance)) { + fiber$jscomp$0.effectTag |= 2; + isHydrating = !1; + hydrationParentFiber = fiber$jscomp$0; + return; + } + var returnFiber = hydrationParentFiber, + fiber = new FiberNode(5, null, null, 0); + fiber.type = "DELETED"; + fiber.stateNode = firstAttemptedInstance; + fiber.return = returnFiber; + fiber.effectTag = 8; + null !== returnFiber.lastEffect + ? ((returnFiber.lastEffect.nextEffect = fiber), + (returnFiber.lastEffect = fiber)) + : (returnFiber.firstEffect = returnFiber.lastEffect = fiber); + } + hydrationParentFiber = fiber$jscomp$0; + nextHydratableInstance = shim$1(nextInstance); + } else + (fiber$jscomp$0.effectTag |= 2), + (isHydrating = !1), + (hydrationParentFiber = fiber$jscomp$0); + } +} +function reconcileChildren(current, workInProgress, nextChildren) { + reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + workInProgress.expirationTime + ); +} +function reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime +) { + workInProgress.child = + null === current + ? mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime + ) + : reconcileChildFibers( + workInProgress, + current.child, + nextChildren, + renderExpirationTime + ); +} +function markRef(current, workInProgress) { + var ref = workInProgress.ref; + if ( + (null === current && null !== ref) || + (null !== current && current.ref !== ref) + ) + workInProgress.effectTag |= 128; +} +function finishClassComponent( + current, + workInProgress, + shouldUpdate, + hasContext, + renderExpirationTime +) { + markRef(current, workInProgress); + var didCaptureError = 0 !== (workInProgress.effectTag & 64); + if (!shouldUpdate && !didCaptureError) + return ( + hasContext && invalidateContextProvider(workInProgress, !1), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + shouldUpdate = workInProgress.stateNode; + ReactCurrentOwner.current = workInProgress; + if (didCaptureError) { + var nextChildren = null; + baseStartTime = -1; + } else nextChildren = shouldUpdate.render(); + workInProgress.effectTag |= 1; + didCaptureError && + (reconcileChildrenAtExpirationTime( + current, + workInProgress, + null, + renderExpirationTime + ), + (workInProgress.child = null)); + reconcileChildrenAtExpirationTime( + current, + workInProgress, + nextChildren, + renderExpirationTime + ); + workInProgress.memoizedState = shouldUpdate.state; + workInProgress.memoizedProps = shouldUpdate.props; + hasContext && invalidateContextProvider(workInProgress, !0); + return workInProgress.child; +} +function pushHostRootContext(workInProgress) { + var root = workInProgress.stateNode; + root.pendingContext + ? pushTopLevelContextObject( + workInProgress, + root.pendingContext, + root.pendingContext !== root.context + ) + : root.context && + pushTopLevelContextObject(workInProgress, root.context, !1); + pushHostContainer(workInProgress, root.containerInfo); +} +function propagateContextChange( + workInProgress, + context, + changedBits, + renderExpirationTime +) { + var fiber = workInProgress.child; + null !== fiber && (fiber.return = workInProgress); + for (; null !== fiber; ) { + switch (fiber.tag) { + case 12: + var nextFiber = fiber.stateNode | 0; + if (fiber.type === context && 0 !== (nextFiber & changedBits)) { + for (nextFiber = fiber; null !== nextFiber; ) { + var alternate = nextFiber.alternate; + if ( + 0 === nextFiber.expirationTime || + nextFiber.expirationTime > renderExpirationTime + ) + (nextFiber.expirationTime = renderExpirationTime), + null !== alternate && + (0 === alternate.expirationTime || + alternate.expirationTime > renderExpirationTime) && + (alternate.expirationTime = renderExpirationTime); + else if ( + null !== alternate && + (0 === alternate.expirationTime || + alternate.expirationTime > renderExpirationTime) + ) + alternate.expirationTime = renderExpirationTime; + else break; + nextFiber = nextFiber.return; + } + nextFiber = null; + } else nextFiber = fiber.child; + break; + case 13: + nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + break; + default: + nextFiber = fiber.child; + } + if (null !== nextFiber) nextFiber.return = fiber; + else + for (nextFiber = fiber; null !== nextFiber; ) { + if (nextFiber === workInProgress) { + nextFiber = null; + break; + } + fiber = nextFiber.sibling; + if (null !== fiber) { + fiber.return = nextFiber.return; + nextFiber = fiber; + break; + } + nextFiber = nextFiber.return; + } + fiber = nextFiber; + } +} +function updateContextProvider(current, workInProgress, renderExpirationTime) { + var context = workInProgress.type._context, + newProps = workInProgress.pendingProps, + oldProps = workInProgress.memoizedProps, + canBailOnProps = !0; + if (didPerformWorkStackCursor.current) canBailOnProps = !1; + else if (oldProps === newProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + var newValue = newProps.value; + workInProgress.memoizedProps = newProps; + if (null === oldProps) newValue = 1073741823; + else if (oldProps.value === newProps.value) { + if (oldProps.children === newProps.children && canBailOnProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + newValue = 0; + } else { + var oldValue = oldProps.value; + if ( + (oldValue === newValue && + (0 !== oldValue || 1 / oldValue === 1 / newValue)) || + (oldValue !== oldValue && newValue !== newValue) + ) { + if (oldProps.children === newProps.children && canBailOnProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + newValue = 0; + } else if ( + ((newValue = + "function" === typeof context._calculateChangedBits + ? context._calculateChangedBits(oldValue, newValue) + : 1073741823), + (newValue |= 0), + 0 === newValue) + ) { + if (oldProps.children === newProps.children && canBailOnProps) + return ( + (workInProgress.stateNode = 0), + pushProvider(workInProgress), + bailoutOnAlreadyFinishedWork(current, workInProgress) + ); + } else + propagateContextChange( + workInProgress, + context, + newValue, + renderExpirationTime + ); + } + workInProgress.stateNode = newValue; + pushProvider(workInProgress); + reconcileChildren(current, workInProgress, newProps.children); + return workInProgress.child; +} +function bailoutOnAlreadyFinishedWork(current, workInProgress) { + baseStartTime = -1; + invariant( + null === current || workInProgress.child === current.child, + "Resuming work not yet implemented." + ); + if (null !== workInProgress.child) { + current = workInProgress.child; + var newChild = createWorkInProgress( + current, + current.pendingProps, + current.expirationTime + ); + workInProgress.child = newChild; + for (newChild.return = workInProgress; null !== current.sibling; ) + (current = current.sibling), + (newChild = newChild.sibling = createWorkInProgress( + current, + current.pendingProps, + current.expirationTime + )), + (newChild.return = workInProgress); + newChild.sibling = null; + } + return workInProgress.child; +} +function beginWork(current, workInProgress, renderExpirationTime) { + workInProgress.mode & 4 && + ((workInProgress.actualDuration = + now$1() - workInProgress.actualDuration - totalElapsedPauseTime), + (workInProgress.actualStartTime = now$1())); + if ( + 0 === workInProgress.expirationTime || + workInProgress.expirationTime > renderExpirationTime + ) { + baseStartTime = -1; + switch (workInProgress.tag) { + case 3: + pushHostRootContext(workInProgress); + break; + case 2: + pushContextProvider(workInProgress); + break; + case 4: + pushHostContainer( + workInProgress, + workInProgress.stateNode.containerInfo + ); + break; + case 13: + pushProvider(workInProgress); + } + return null; + } + switch (workInProgress.tag) { + case 0: + invariant( + null === current, + "An indeterminate component should never have mounted. This error is likely caused by a bug in React. Please file an issue." + ); + var fn = workInProgress.type, + props = workInProgress.pendingProps, + unmaskedContext = getUnmaskedContext(workInProgress); + unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); + fn = fn(props, unmaskedContext); + workInProgress.effectTag |= 1; + "object" === typeof fn && + null !== fn && + "function" === typeof fn.render && + void 0 === fn.$$typeof + ? ((unmaskedContext = workInProgress.type), + (workInProgress.tag = 2), + (workInProgress.memoizedState = + null !== fn.state && void 0 !== fn.state ? fn.state : null), + (unmaskedContext = unmaskedContext.getDerivedStateFromProps), + "function" === typeof unmaskedContext && + applyDerivedStateFromProps(workInProgress, unmaskedContext, props), + (props = pushContextProvider(workInProgress)), + (fn.updater = classComponentUpdater), + (workInProgress.stateNode = fn), + (fn._reactInternalFiber = workInProgress), + mountClassInstance(workInProgress, renderExpirationTime), + (current = finishClassComponent( + current, + workInProgress, + !0, + props, + renderExpirationTime + ))) + : ((workInProgress.tag = 1), + reconcileChildren(current, workInProgress, fn), + (workInProgress.memoizedProps = props), + (current = workInProgress.child)); + return current; + case 1: + return ( + (props = workInProgress.type), + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime + ? ((fn = getUnmaskedContext(workInProgress)), + (fn = getMaskedContext(workInProgress, fn)), + (props = props(renderExpirationTime, fn)), + (workInProgress.effectTag |= 1), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 2: + props = pushContextProvider(workInProgress); + if (null === current) + if (null === workInProgress.stateNode) { + var props$jscomp$0 = workInProgress.pendingProps, + ctor = workInProgress.type; + fn = getUnmaskedContext(workInProgress); + var needsContext = + 2 === workInProgress.tag && + null != workInProgress.type.contextTypes; + unmaskedContext = needsContext + ? getMaskedContext(workInProgress, fn) + : emptyObject; + props$jscomp$0 = new ctor(props$jscomp$0, unmaskedContext); + workInProgress.memoizedState = + null !== props$jscomp$0.state && void 0 !== props$jscomp$0.state + ? props$jscomp$0.state + : null; + props$jscomp$0.updater = classComponentUpdater; + workInProgress.stateNode = props$jscomp$0; + props$jscomp$0._reactInternalFiber = workInProgress; + needsContext && + ((needsContext = workInProgress.stateNode), + (needsContext.__reactInternalMemoizedUnmaskedChildContext = fn), + (needsContext.__reactInternalMemoizedMaskedChildContext = unmaskedContext)); + mountClassInstance(workInProgress, renderExpirationTime); + fn = !0; + } else { + ctor = workInProgress.type; + fn = workInProgress.stateNode; + needsContext = workInProgress.memoizedProps; + unmaskedContext = workInProgress.pendingProps; + fn.props = needsContext; + var oldContext = fn.context; + props$jscomp$0 = getUnmaskedContext(workInProgress); + props$jscomp$0 = getMaskedContext(workInProgress, props$jscomp$0); + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + (ctor = + "function" === typeof getDerivedStateFromProps || + "function" === typeof fn.getSnapshotBeforeUpdate) || + ("function" !== typeof fn.UNSAFE_componentWillReceiveProps && + "function" !== typeof fn.componentWillReceiveProps) || + ((needsContext !== unmaskedContext || + oldContext !== props$jscomp$0) && + callComponentWillReceiveProps( + workInProgress, + fn, + unmaskedContext, + props$jscomp$0 + )); + hasForceUpdate = !1; + var oldState = workInProgress.memoizedState; + oldContext = fn.state = oldState; + var updateQueue = workInProgress.updateQueue; + null !== updateQueue && + (processUpdateQueue( + workInProgress, + updateQueue, + unmaskedContext, + fn, + renderExpirationTime + ), + (oldContext = workInProgress.memoizedState)); + needsContext !== unmaskedContext || + oldState !== oldContext || + didPerformWorkStackCursor.current || + hasForceUpdate + ? ("function" === typeof getDerivedStateFromProps && + (applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + unmaskedContext + ), + (oldContext = workInProgress.memoizedState)), + (needsContext = + hasForceUpdate || + checkShouldComponentUpdate( + workInProgress, + needsContext, + unmaskedContext, + oldState, + oldContext, + props$jscomp$0 + )) + ? (ctor || + ("function" !== typeof fn.UNSAFE_componentWillMount && + "function" !== typeof fn.componentWillMount) || + ("function" === typeof fn.componentWillMount && + fn.componentWillMount(), + "function" === typeof fn.UNSAFE_componentWillMount && + fn.UNSAFE_componentWillMount()), + "function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4)) + : ("function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4), + (workInProgress.memoizedProps = unmaskedContext), + (workInProgress.memoizedState = oldContext)), + (fn.props = unmaskedContext), + (fn.state = oldContext), + (fn.context = props$jscomp$0), + (fn = needsContext)) + : ("function" === typeof fn.componentDidMount && + (workInProgress.effectTag |= 4), + (fn = !1)); + } + else + (ctor = workInProgress.type), + (fn = workInProgress.stateNode), + (unmaskedContext = workInProgress.memoizedProps), + (needsContext = workInProgress.pendingProps), + (fn.props = unmaskedContext), + (oldContext = fn.context), + (props$jscomp$0 = getUnmaskedContext(workInProgress)), + (props$jscomp$0 = getMaskedContext(workInProgress, props$jscomp$0)), + (getDerivedStateFromProps = ctor.getDerivedStateFromProps), + (ctor = + "function" === typeof getDerivedStateFromProps || + "function" === typeof fn.getSnapshotBeforeUpdate) || + ("function" !== typeof fn.UNSAFE_componentWillReceiveProps && + "function" !== typeof fn.componentWillReceiveProps) || + ((unmaskedContext !== needsContext || + oldContext !== props$jscomp$0) && + callComponentWillReceiveProps( + workInProgress, + fn, + needsContext, + props$jscomp$0 + )), + (hasForceUpdate = !1), + (oldContext = workInProgress.memoizedState), + (oldState = fn.state = oldContext), + (updateQueue = workInProgress.updateQueue), + null !== updateQueue && + (processUpdateQueue( + workInProgress, + updateQueue, + needsContext, + fn, + renderExpirationTime + ), + (oldState = workInProgress.memoizedState)), + unmaskedContext !== needsContext || + oldContext !== oldState || + didPerformWorkStackCursor.current || + hasForceUpdate + ? ("function" === typeof getDerivedStateFromProps && + (applyDerivedStateFromProps( + workInProgress, + getDerivedStateFromProps, + needsContext + ), + (oldState = workInProgress.memoizedState)), + (getDerivedStateFromProps = + hasForceUpdate || + checkShouldComponentUpdate( + workInProgress, + unmaskedContext, + needsContext, + oldContext, + oldState, + props$jscomp$0 + )) + ? (ctor || + ("function" !== typeof fn.UNSAFE_componentWillUpdate && + "function" !== typeof fn.componentWillUpdate) || + ("function" === typeof fn.componentWillUpdate && + fn.componentWillUpdate( + needsContext, + oldState, + props$jscomp$0 + ), + "function" === typeof fn.UNSAFE_componentWillUpdate && + fn.UNSAFE_componentWillUpdate( + needsContext, + oldState, + props$jscomp$0 + )), + "function" === typeof fn.componentDidUpdate && + (workInProgress.effectTag |= 4), + "function" === typeof fn.getSnapshotBeforeUpdate && + (workInProgress.effectTag |= 256)) + : ("function" !== typeof fn.componentDidUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 4), + "function" !== typeof fn.getSnapshotBeforeUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 256), + (workInProgress.memoizedProps = needsContext), + (workInProgress.memoizedState = oldState)), + (fn.props = needsContext), + (fn.state = oldState), + (fn.context = props$jscomp$0), + (fn = getDerivedStateFromProps)) + : ("function" !== typeof fn.componentDidUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 4), + "function" !== typeof fn.getSnapshotBeforeUpdate || + (unmaskedContext === current.memoizedProps && + oldContext === current.memoizedState) || + (workInProgress.effectTag |= 256), + (fn = !1)); + return finishClassComponent( + current, + workInProgress, + fn, + props, + renderExpirationTime + ); + case 3: + return ( + pushHostRootContext(workInProgress), + (props = workInProgress.updateQueue), + null !== props + ? ((fn = workInProgress.memoizedState), + (fn = null !== fn ? fn.element : null), + processUpdateQueue( + workInProgress, + props, + workInProgress.pendingProps, + null, + renderExpirationTime + ), + (renderExpirationTime = workInProgress.memoizedState.element), + renderExpirationTime === fn + ? (current = bailoutOnAlreadyFinishedWork( + current, + workInProgress + )) + : (reconcileChildren( + current, + workInProgress, + renderExpirationTime + ), + (current = workInProgress.child))) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 5: + return ( + requiredContext(rootInstanceStackCursor.current), + (renderExpirationTime = requiredContext(contextStackCursor$1.current)), + (props = workInProgress.type), + (props = + "AndroidTextInput" === props || + "RCTMultilineTextInputView" === props || + "RCTSinglelineTextInputView" === props || + "RCTText" === props || + "RCTVirtualText" === props), + (props = + renderExpirationTime.isInAParentText !== props + ? { isInAParentText: props } + : renderExpirationTime), + renderExpirationTime !== props && + (push(contextFiberStackCursor, workInProgress, workInProgress), + push(contextStackCursor$1, props, workInProgress)), + null === current && tryToClaimNextHydratableInstance(workInProgress), + (props = workInProgress.memoizedProps), + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || props !== renderExpirationTime + ? ((props = renderExpirationTime.children), + markRef(current, workInProgress), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 6: + return ( + null === current && tryToClaimNextHydratableInstance(workInProgress), + (workInProgress.memoizedProps = workInProgress.pendingProps), + null + ); + case 16: + return null; + case 4: + return ( + pushHostContainer( + workInProgress, + workInProgress.stateNode.containerInfo + ), + (props = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== props + ? (null === current + ? (workInProgress.child = reconcileChildFibers( + workInProgress, + null, + props, + renderExpirationTime + )) + : reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = props), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 14: + return ( + (props = workInProgress.type.render), + (renderExpirationTime = workInProgress.pendingProps), + (fn = workInProgress.ref), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime || + fn !== (null !== current ? current.ref : null) + ? ((props = props(renderExpirationTime, fn)), + reconcileChildren(current, workInProgress, props), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 10: + return ( + (renderExpirationTime = workInProgress.pendingProps), + didPerformWorkStackCursor.current || + workInProgress.memoizedProps !== renderExpirationTime + ? (reconcileChildren(current, workInProgress, renderExpirationTime), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 11: + return ( + (renderExpirationTime = workInProgress.pendingProps.children), + didPerformWorkStackCursor.current || + (null !== renderExpirationTime && + workInProgress.memoizedProps !== renderExpirationTime) + ? (reconcileChildren(current, workInProgress, renderExpirationTime), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)) + : (current = bailoutOnAlreadyFinishedWork(current, workInProgress)), + current + ); + case 15: + return ( + (renderExpirationTime = workInProgress.pendingProps), + (workInProgress.effectTag |= 4), + workInProgress.memoizedProps === renderExpirationTime + ? (current = bailoutOnAlreadyFinishedWork(current, workInProgress)) + : (reconcileChildren( + current, + workInProgress, + renderExpirationTime.children + ), + (workInProgress.memoizedProps = renderExpirationTime), + (current = workInProgress.child)), + current + ); + case 13: + return updateContextProvider( + current, + workInProgress, + renderExpirationTime + ); + case 12: + a: if ( + ((fn = workInProgress.type), + (unmaskedContext = workInProgress.pendingProps), + (needsContext = workInProgress.memoizedProps), + (props = fn._currentValue), + (props$jscomp$0 = fn._changedBits), + didPerformWorkStackCursor.current || + 0 !== props$jscomp$0 || + needsContext !== unmaskedContext) + ) { + workInProgress.memoizedProps = unmaskedContext; + ctor = unmaskedContext.unstable_observedBits; + if (void 0 === ctor || null === ctor) ctor = 1073741823; + workInProgress.stateNode = ctor; + if (0 !== (props$jscomp$0 & ctor)) + propagateContextChange( + workInProgress, + fn, + props$jscomp$0, + renderExpirationTime + ); + else if (needsContext === unmaskedContext) { + current = bailoutOnAlreadyFinishedWork(current, workInProgress); + break a; + } + renderExpirationTime = unmaskedContext.children; + renderExpirationTime = renderExpirationTime(props); + workInProgress.effectTag |= 1; + reconcileChildren(current, workInProgress, renderExpirationTime); + current = workInProgress.child; + } else current = bailoutOnAlreadyFinishedWork(current, workInProgress); + return current; + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } +} +var updateHostContainer = void 0, + updateHostComponent$1 = void 0, + updateHostText$1 = void 0; +updateHostContainer = function() {}; +updateHostComponent$1 = function(current, workInProgress, updatePayload) { + if ((workInProgress.updateQueue = updatePayload)) + workInProgress.effectTag |= 4; +}; +updateHostText$1 = function(current, workInProgress, oldText, newText) { + oldText !== newText && (workInProgress.effectTag |= 4); +}; +function completeWork(current, workInProgress) { + var newProps = workInProgress.pendingProps; + workInProgress.mode & 4 && recordElapsedActualRenderTime(workInProgress); + switch (workInProgress.tag) { + case 1: + return null; + case 2: + return popContextProvider(workInProgress), null; + case 3: + popHostContainer(workInProgress); + popTopLevelContextObject(workInProgress); + newProps = workInProgress.stateNode; + newProps.pendingContext && + ((newProps.context = newProps.pendingContext), + (newProps.pendingContext = null)); + if (null === current || null === current.child) + workInProgress.effectTag &= -3; + updateHostContainer(workInProgress); + return null; + case 5: + popHostContext(workInProgress); + var rootContainerInstance = requiredContext( + rootInstanceStackCursor.current + ), + type = workInProgress.type; + if (null !== current && null != workInProgress.stateNode) { + var oldProps = current.memoizedProps, + currentHostContext = requiredContext(contextStackCursor$1.current); + updateHostComponent$1( + current, + workInProgress, + emptyObject, + type, + oldProps, + newProps, + rootContainerInstance, + currentHostContext + ); + current.ref !== workInProgress.ref && (workInProgress.effectTag |= 128); + } else { + if (!newProps) + return ( + invariant( + null !== workInProgress.stateNode, + "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." + ), + null + ); + current = requiredContext(contextStackCursor$1.current); + oldProps = allocateTag(); + currentHostContext = ReactNativeViewConfigRegistry.get(type); + invariant( + "RCTView" !== type || !current.isInAParentText, + "Nesting of within is not currently supported." + ); + var updatePayload = diffProperties( + null, + emptyObject$1, + newProps, + currentHostContext.validAttributes + ); + UIManager.createView( + oldProps, + currentHostContext.uiViewClassName, + rootContainerInstance, + updatePayload + ); + currentHostContext = new ReactNativeFiberHostComponent( + oldProps, + currentHostContext + ); + instanceCache[oldProps] = workInProgress; + instanceProps[oldProps] = newProps; + a: for (oldProps = workInProgress.child; null !== oldProps; ) { + if (5 === oldProps.tag || 6 === oldProps.tag) + currentHostContext._children.push(oldProps.stateNode); + else if (4 !== oldProps.tag && null !== oldProps.child) { + oldProps.child.return = oldProps; + oldProps = oldProps.child; + continue; + } + if (oldProps === workInProgress) break; + for (; null === oldProps.sibling; ) { + if (null === oldProps.return || oldProps.return === workInProgress) + break a; + oldProps = oldProps.return; + } + oldProps.sibling.return = oldProps.return; + oldProps = oldProps.sibling; + } + finalizeInitialChildren( + currentHostContext, + type, + newProps, + rootContainerInstance, + current + ) && (workInProgress.effectTag |= 4); + workInProgress.stateNode = currentHostContext; + null !== workInProgress.ref && (workInProgress.effectTag |= 128); + } + return null; + case 6: + if (current && null != workInProgress.stateNode) + updateHostText$1( + current, + workInProgress, + current.memoizedProps, + newProps + ); + else { + if ("string" !== typeof newProps) + return ( + invariant( + null !== workInProgress.stateNode, + "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." + ), + null + ); + rootContainerInstance = requiredContext( + rootInstanceStackCursor.current + ); + type = requiredContext(contextStackCursor$1.current); + invariant( + type.isInAParentText, + "Text strings must be rendered within a component." + ); + type = allocateTag(); + UIManager.createView(type, "RCTRawText", rootContainerInstance, { + text: newProps + }); + instanceCache[type] = workInProgress; + workInProgress.stateNode = type; + } + return null; + case 14: + return null; + case 16: + return null; + case 10: + return null; + case 11: + return null; + case 15: + return null; + case 4: + return ( + popHostContainer(workInProgress), + updateHostContainer(workInProgress), + null + ); + case 13: + return popProvider(workInProgress), null; + case 12: + return null; + case 0: + invariant( + !1, + "An indeterminate component should have become determinate before completing. This error is likely caused by a bug in React. Please file an issue." + ); + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } +} +function logError(boundary, errorInfo) { + var source = errorInfo.source, + stack = errorInfo.stack; + null === stack && + null !== source && + (stack = getStackAddendumByWorkInProgressFiber(source)); + null !== source && getComponentName(source); + source = null !== stack ? stack : ""; + errorInfo = errorInfo.value; + null !== boundary && 2 === boundary.tag && getComponentName(boundary); + try { + if (errorInfo instanceof Error) { + var message = errorInfo.message, + name = errorInfo.name; + var errorToHandle = errorInfo; + try { + errorToHandle.message = + (message ? name + ": " + message : name) + + "\n\nThis error is located at:" + + source; + } catch (e) {} + } else + errorToHandle = + "string" === typeof errorInfo + ? Error(errorInfo + "\n\nThis error is located at:" + source) + : Error("Unspecified error at:" + source); + ExceptionsManager.handleException(errorToHandle, !1); + } catch (e) { + (e && e.suppressReactErrorLogging) || console.error(e); + } +} +function safelyDetachRef(current) { + var ref = current.ref; + if (null !== ref) + if ("function" === typeof ref) + try { + ref(null); + } catch (refError) { + captureCommitPhaseError(current, refError); + } + else ref.current = null; +} +function commitUnmount(current) { + "function" === typeof onCommitUnmount && onCommitUnmount(current); + switch (current.tag) { + case 2: + safelyDetachRef(current); + var instance = current.stateNode; + if ("function" === typeof instance.componentWillUnmount) + try { + (instance.props = current.memoizedProps), + (instance.state = current.memoizedState), + instance.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current, unmountError); + } + break; + case 5: + safelyDetachRef(current); + break; + case 4: + unmountHostComponents(current); + } +} +function isHostParent(fiber) { + return 5 === fiber.tag || 3 === fiber.tag || 4 === fiber.tag; +} +function commitPlacement(finishedWork) { + a: { + for (var parent = finishedWork.return; null !== parent; ) { + if (isHostParent(parent)) { + var parentFiber = parent; + break a; + } + parent = parent.return; + } + invariant( + !1, + "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." + ); + parentFiber = void 0; + } + var isContainer = (parent = void 0); + switch (parentFiber.tag) { + case 5: + parent = parentFiber.stateNode; + isContainer = !1; + break; + case 3: + parent = parentFiber.stateNode.containerInfo; + isContainer = !0; + break; + case 4: + parent = parentFiber.stateNode.containerInfo; + isContainer = !0; + break; + default: + invariant( + !1, + "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue." + ); + } + parentFiber.effectTag & 16 && (parentFiber.effectTag &= -17); + a: b: for (parentFiber = finishedWork; ; ) { + for (; null === parentFiber.sibling; ) { + if (null === parentFiber.return || isHostParent(parentFiber.return)) { + parentFiber = null; + break a; + } + parentFiber = parentFiber.return; + } + parentFiber.sibling.return = parentFiber.return; + for ( + parentFiber = parentFiber.sibling; + 5 !== parentFiber.tag && 6 !== parentFiber.tag; + + ) { + if (parentFiber.effectTag & 2) continue b; + if (null === parentFiber.child || 4 === parentFiber.tag) continue b; + else + (parentFiber.child.return = parentFiber), + (parentFiber = parentFiber.child); + } + if (!(parentFiber.effectTag & 2)) { + parentFiber = parentFiber.stateNode; + break a; + } + } + for (var node = finishedWork; ; ) { + if (5 === node.tag || 6 === node.tag) + if (parentFiber) + if (isContainer) + invariant( + "number" !== typeof parent, + "Container does not support insertBefore operation" + ); + else { + var parentInstance = parent, + child = node.stateNode, + beforeChild = parentFiber, + children = parentInstance._children, + index = children.indexOf(child); + 0 <= index + ? (children.splice(index, 1), + (beforeChild = children.indexOf(beforeChild)), + children.splice(beforeChild, 0, child), + UIManager.manageChildren( + parentInstance._nativeTag, + [index], + [beforeChild], + [], + [], + [] + )) + : ((index = children.indexOf(beforeChild)), + children.splice(index, 0, child), + UIManager.manageChildren( + parentInstance._nativeTag, + [], + [], + ["number" === typeof child ? child : child._nativeTag], + [index], + [] + )); + } + else + isContainer + ? ((parentInstance = node.stateNode), + UIManager.setChildren(parent, [ + "number" === typeof parentInstance + ? parentInstance + : parentInstance._nativeTag + ])) + : ((parentInstance = parent), + (child = node.stateNode), + (children = "number" === typeof child ? child : child._nativeTag), + (index = parentInstance._children), + (beforeChild = index.indexOf(child)), + 0 <= beforeChild + ? (index.splice(beforeChild, 1), + index.push(child), + UIManager.manageChildren( + parentInstance._nativeTag, + [beforeChild], + [index.length - 1], + [], + [], + [] + )) + : (index.push(child), + UIManager.manageChildren( + parentInstance._nativeTag, + [], + [], + [children], + [index.length - 1], + [] + ))); + else if (4 !== node.tag && null !== node.child) { + node.child.return = node; + node = node.child; + continue; + } + if (node === finishedWork) break; + for (; null === node.sibling; ) { + if (null === node.return || node.return === finishedWork) return; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } +} +function unmountHostComponents(current) { + for ( + var node = current, + currentParentIsValid = !1, + currentParent = void 0, + currentParentIsContainer = void 0; + ; + + ) { + if (!currentParentIsValid) { + currentParentIsValid = node.return; + a: for (;;) { + invariant( + null !== currentParentIsValid, + "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." + ); + switch (currentParentIsValid.tag) { + case 5: + currentParent = currentParentIsValid.stateNode; + currentParentIsContainer = !1; + break a; + case 3: + currentParent = currentParentIsValid.stateNode.containerInfo; + currentParentIsContainer = !0; + break a; + case 4: + currentParent = currentParentIsValid.stateNode.containerInfo; + currentParentIsContainer = !0; + break a; + } + currentParentIsValid = currentParentIsValid.return; + } + currentParentIsValid = !0; + } + if (5 === node.tag || 6 === node.tag) { + a: for (var root = node, node$jscomp$0 = root; ; ) + if ( + (commitUnmount(node$jscomp$0), + null !== node$jscomp$0.child && 4 !== node$jscomp$0.tag) + ) + (node$jscomp$0.child.return = node$jscomp$0), + (node$jscomp$0 = node$jscomp$0.child); + else { + if (node$jscomp$0 === root) break; + for (; null === node$jscomp$0.sibling; ) { + if (null === node$jscomp$0.return || node$jscomp$0.return === root) + break a; + node$jscomp$0 = node$jscomp$0.return; + } + node$jscomp$0.sibling.return = node$jscomp$0.return; + node$jscomp$0 = node$jscomp$0.sibling; + } + if (currentParentIsContainer) + (root = currentParent), + recursivelyUncacheFiberNode(node.stateNode), + UIManager.manageChildren(root, [], [], [], [], [0]); + else { + root = currentParent; + var child = node.stateNode; + recursivelyUncacheFiberNode(child); + node$jscomp$0 = root._children; + child = node$jscomp$0.indexOf(child); + node$jscomp$0.splice(child, 1); + UIManager.manageChildren(root._nativeTag, [], [], [], [], [child]); + } + } else if ( + (4 === node.tag + ? (currentParent = node.stateNode.containerInfo) + : commitUnmount(node), + null !== node.child) + ) { + node.child.return = node; + node = node.child; + continue; + } + if (node === current) break; + for (; null === node.sibling; ) { + if (null === node.return || node.return === current) return; + node = node.return; + 4 === node.tag && (currentParentIsValid = !1); + } + node.sibling.return = node.return; + node = node.sibling; + } +} +function commitWork(current, finishedWork) { + switch (finishedWork.tag) { + case 2: + break; + case 5: + var instance = finishedWork.stateNode; + if (null != instance) { + var newProps = finishedWork.memoizedProps; + current = null !== current ? current.memoizedProps : newProps; + var updatePayload = finishedWork.updateQueue; + finishedWork.updateQueue = null; + null !== updatePayload && + ((finishedWork = instance.viewConfig), + (instanceProps[instance._nativeTag] = newProps), + (newProps = diffProperties( + null, + current, + newProps, + finishedWork.validAttributes + )), + null != newProps && + UIManager.updateView( + instance._nativeTag, + finishedWork.uiViewClassName, + newProps + )); + } + break; + case 6: + invariant( + null !== finishedWork.stateNode, + "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue." + ); + UIManager.updateView(finishedWork.stateNode, "RCTRawText", { + text: finishedWork.memoizedProps + }); + break; + case 3: + break; + case 15: + instance = finishedWork.memoizedProps.onRender; + instance( + finishedWork.memoizedProps.id, + null === current ? "mount" : "update", + finishedWork.actualDuration, + finishedWork.treeBaseTime, + finishedWork.actualStartTime, + commitTime + ); + break; + case 16: + 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." + ); + } +} +function createRootErrorUpdate(fiber, errorInfo, expirationTime) { + expirationTime = createUpdate(expirationTime); + expirationTime.tag = 3; + expirationTime.payload = { element: null }; + var error = errorInfo.value; + expirationTime.callback = function() { + onUncaughtError(error); + logError(fiber, errorInfo); + }; + return expirationTime; +} +function createClassErrorUpdate(fiber, errorInfo, expirationTime) { + expirationTime = createUpdate(expirationTime); + expirationTime.tag = 3; + var inst = fiber.stateNode; + null !== inst && + "function" === typeof inst.componentDidCatch && + (expirationTime.callback = function() { + null === legacyErrorBoundariesThatAlreadyFailed + ? (legacyErrorBoundariesThatAlreadyFailed = new Set([this])) + : legacyErrorBoundariesThatAlreadyFailed.add(this); + var error = errorInfo.value, + stack = errorInfo.stack; + logError(fiber, errorInfo); + this.componentDidCatch(error, { + componentStack: null !== stack ? stack : "" + }); + }); + return expirationTime; +} +function unwindWork(workInProgress) { + workInProgress.mode & 4 && recordElapsedActualRenderTime(workInProgress); + switch (workInProgress.tag) { + case 2: + popContextProvider(workInProgress); + var effectTag = workInProgress.effectTag; + return effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null; + case 3: + return ( + popHostContainer(workInProgress), + popTopLevelContextObject(workInProgress), + (effectTag = workInProgress.effectTag), + effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null + ); + case 5: + return popHostContext(workInProgress), null; + case 16: + return ( + (effectTag = workInProgress.effectTag), + effectTag & 1024 + ? ((workInProgress.effectTag = (effectTag & -1025) | 64), + workInProgress) + : null + ); + case 4: + return popHostContainer(workInProgress), null; + case 13: + return popProvider(workInProgress), null; + default: + return null; + } +} +var originalStartTimeMs = now$1(), + mostRecentCurrentTime = 2, + mostRecentCurrentTimeMs = originalStartTimeMs, + lastUniqueAsyncExpiration = 0, + expirationContext = 0, + isWorking = !1, + nextUnitOfWork = null, + nextRoot = null, + nextRenderExpirationTime = 0, + nextLatestTimeoutMs = -1, + nextRenderDidError = !1, + nextEffect = null, + isCommitting$1 = !1, + legacyErrorBoundariesThatAlreadyFailed = null; +function resetStack() { + if (null !== nextUnitOfWork) + for ( + var interruptedWork = nextUnitOfWork.return; + null !== interruptedWork; + + ) { + var interruptedWork$jscomp$0 = interruptedWork; + interruptedWork$jscomp$0.mode & 4 && + (resumeActualRenderTimerIfPaused(), + recordElapsedActualRenderTime(interruptedWork$jscomp$0)); + switch (interruptedWork$jscomp$0.tag) { + case 2: + popContextProvider(interruptedWork$jscomp$0); + break; + case 3: + popHostContainer(interruptedWork$jscomp$0); + popTopLevelContextObject(interruptedWork$jscomp$0); + break; + case 5: + popHostContext(interruptedWork$jscomp$0); + break; + case 4: + popHostContainer(interruptedWork$jscomp$0); + break; + case 13: + popProvider(interruptedWork$jscomp$0); + } + interruptedWork = interruptedWork.return; + } + nextRoot = null; + nextRenderExpirationTime = 0; + nextLatestTimeoutMs = -1; + nextRenderDidError = !1; + nextUnitOfWork = null; +} +function completeUnitOfWork(workInProgress$jscomp$0) { + for (;;) { + var current = workInProgress$jscomp$0.alternate, + returnFiber = workInProgress$jscomp$0.return, + siblingFiber = workInProgress$jscomp$0.sibling; + if (0 === (workInProgress$jscomp$0.effectTag & 512)) { + current = completeWork( + current, + workInProgress$jscomp$0, + nextRenderExpirationTime + ); + var workInProgress = workInProgress$jscomp$0; + if ( + 1073741823 === nextRenderExpirationTime || + 1073741823 !== workInProgress.expirationTime + ) { + var newExpirationTime = 0; + switch (workInProgress.tag) { + case 3: + case 2: + var updateQueue = workInProgress.updateQueue; + null !== updateQueue && + (newExpirationTime = updateQueue.expirationTime); + } + if (workInProgress.mode & 4) { + updateQueue = workInProgress.selfBaseTime; + for (var child = workInProgress.child; null !== child; ) + (updateQueue += child.treeBaseTime), + 0 !== child.expirationTime && + (0 === newExpirationTime || + newExpirationTime > child.expirationTime) && + (newExpirationTime = child.expirationTime), + (child = child.sibling); + workInProgress.treeBaseTime = updateQueue; + } else + for (updateQueue = workInProgress.child; null !== updateQueue; ) + 0 !== updateQueue.expirationTime && + (0 === newExpirationTime || + newExpirationTime > updateQueue.expirationTime) && + (newExpirationTime = updateQueue.expirationTime), + (updateQueue = updateQueue.sibling); + workInProgress.expirationTime = newExpirationTime; + } + if (null !== current) return current; + null !== returnFiber && + 0 === (returnFiber.effectTag & 512) && + (null === returnFiber.firstEffect && + (returnFiber.firstEffect = workInProgress$jscomp$0.firstEffect), + null !== workInProgress$jscomp$0.lastEffect && + (null !== returnFiber.lastEffect && + (returnFiber.lastEffect.nextEffect = + workInProgress$jscomp$0.firstEffect), + (returnFiber.lastEffect = workInProgress$jscomp$0.lastEffect)), + 1 < workInProgress$jscomp$0.effectTag && + (null !== returnFiber.lastEffect + ? (returnFiber.lastEffect.nextEffect = workInProgress$jscomp$0) + : (returnFiber.firstEffect = workInProgress$jscomp$0), + (returnFiber.lastEffect = workInProgress$jscomp$0))); + } else { + workInProgress$jscomp$0 = unwindWork( + workInProgress$jscomp$0, + nextRenderExpirationTime + ); + if (null !== workInProgress$jscomp$0) + return ( + (workInProgress$jscomp$0.effectTag &= 511), workInProgress$jscomp$0 + ); + null !== returnFiber && + ((returnFiber.firstEffect = returnFiber.lastEffect = null), + (returnFiber.effectTag |= 512)); + } + if (null !== siblingFiber) return siblingFiber; + if (null !== returnFiber) workInProgress$jscomp$0 = returnFiber; + else break; + } + return null; +} +function performUnitOfWork(workInProgress) { + var current = workInProgress.alternate; + workInProgress.mode & 4 && (baseStartTime = now$1()); + current = beginWork(current, workInProgress, nextRenderExpirationTime); + workInProgress.mode & 4 && + (-1 !== baseStartTime && + (workInProgress.selfBaseTime = now$1() - baseStartTime), + (baseStartTime = -1)); + null === current && (current = completeUnitOfWork(workInProgress)); + ReactCurrentOwner.current = null; + return current; +} +function renderRoot(root$jscomp$0, isYieldy) { + invariant( + !isWorking, + "renderRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." + ); + isWorking = !0; + var expirationTime = root$jscomp$0.nextExpirationTimeToWorkOn; + if ( + expirationTime !== nextRenderExpirationTime || + root$jscomp$0 !== nextRoot || + null === nextUnitOfWork + ) + resetStack(), + (nextRoot = root$jscomp$0), + (nextRenderExpirationTime = expirationTime), + (nextLatestTimeoutMs = -1), + (nextRenderDidError = !1), + (nextUnitOfWork = createWorkInProgress( + nextRoot.current, + null, + nextRenderExpirationTime + )), + (root$jscomp$0.pendingCommitExpirationTime = 0); + var didFatal = !1; + do { + try { + if (isYieldy) { + for (; null !== nextUnitOfWork && !shouldYield(); ) + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + 0 === timerPausedAt && (timerPausedAt = now$1()); + } else + for (; null !== nextUnitOfWork; ) + nextUnitOfWork = performUnitOfWork(nextUnitOfWork); + } catch (thrownValue) { + if (((baseStartTime = -1), null === nextUnitOfWork)) + (didFatal = !0), onUncaughtError(thrownValue); + else { + invariant( + null !== nextUnitOfWork, + "Failed to replay rendering after an error. This is likely caused by a bug in React. Please file an issue with a reproducing case to help us find it." + ); + isYieldy = nextUnitOfWork; + var returnFiber = isYieldy.return; + if (null === returnFiber) { + didFatal = !0; + onUncaughtError(thrownValue); + break; + } + a: { + var root = root$jscomp$0, + returnFiber$jscomp$0 = returnFiber, + sourceFiber = isYieldy, + value = thrownValue; + returnFiber = nextRenderExpirationTime; + sourceFiber.effectTag |= 512; + sourceFiber.firstEffect = sourceFiber.lastEffect = null; + nextRenderDidError = !0; + if ( + (root.didError || 1 === returnFiber) && + (returnFiber === root.latestPendingTime || + returnFiber === root.latestSuspendedTime) + ) { + value = createCapturedValue(value, sourceFiber); + root = returnFiber$jscomp$0; + do { + switch (root.tag) { + case 3: + root.effectTag |= 1024; + value = createRootErrorUpdate(root, value, returnFiber); + enqueueCapturedUpdate(root, value, returnFiber); + break a; + case 2: + if ( + ((returnFiber$jscomp$0 = value), + (sourceFiber = root.stateNode), + 0 === (root.effectTag & 64) && + null !== sourceFiber && + "function" === typeof sourceFiber.componentDidCatch && + (null === legacyErrorBoundariesThatAlreadyFailed || + !legacyErrorBoundariesThatAlreadyFailed.has( + sourceFiber + ))) + ) { + root.effectTag |= 1024; + value = createClassErrorUpdate( + root, + returnFiber$jscomp$0, + returnFiber + ); + enqueueCapturedUpdate(root, value, returnFiber); + break a; + } + } + root = root.return; + } while (null !== root); + } + } + nextUnitOfWork = completeUnitOfWork(isYieldy); + } + } + break; + } while (1); + isWorking = !1; + didFatal + ? (root$jscomp$0.finishedWork = null) + : null === nextUnitOfWork + ? ((didFatal = root$jscomp$0.current.alternate), + invariant( + null !== didFatal, + "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue." + ), + 0 === (didFatal.effectTag & 512) + ? ((root$jscomp$0.pendingCommitExpirationTime = expirationTime), + (root$jscomp$0.finishedWork = didFatal)) + : (!nextRenderDidError || + (expirationTime !== root$jscomp$0.latestPendingTime && + expirationTime !== root$jscomp$0.latestSuspendedTime) + ? ((didFatal = root$jscomp$0.earliestPendingTime), + (isYieldy = root$jscomp$0.latestPendingTime), + didFatal === expirationTime + ? (root$jscomp$0.earliestPendingTime = + isYieldy === expirationTime + ? (root$jscomp$0.latestPendingTime = 0) + : isYieldy) + : isYieldy === expirationTime && + (root$jscomp$0.latestPendingTime = didFatal), + (didFatal = root$jscomp$0.latestSuspendedTime), + didFatal === expirationTime && + (root$jscomp$0.latestPingedTime = 0), + (isYieldy = root$jscomp$0.earliestSuspendedTime), + 0 === isYieldy + ? (root$jscomp$0.earliestSuspendedTime = root$jscomp$0.latestSuspendedTime = expirationTime) + : isYieldy > expirationTime + ? (root$jscomp$0.earliestSuspendedTime = expirationTime) + : didFatal < expirationTime && + (root$jscomp$0.latestSuspendedTime = expirationTime)) + : (root$jscomp$0.didError = !0), + findNextPendingPriorityLevel(root$jscomp$0), + onSuspend( + root$jscomp$0, + expirationTime, + root$jscomp$0.expirationTime, + nextLatestTimeoutMs + ))) + : (root$jscomp$0.finishedWork = null); +} +function captureCommitPhaseError(fiber, error) { + var JSCompiler_inline_result; + a: { + invariant( + !isWorking || isCommitting$1, + "dispatch: Cannot dispatch during the render phase." + ); + for ( + JSCompiler_inline_result = fiber.return; + null !== JSCompiler_inline_result; + + ) { + switch (JSCompiler_inline_result.tag) { + case 2: + var instance = JSCompiler_inline_result.stateNode; + if ( + "function" === + typeof JSCompiler_inline_result.type.getDerivedStateFromCatch || + ("function" === typeof instance.componentDidCatch && + (null === legacyErrorBoundariesThatAlreadyFailed || + !legacyErrorBoundariesThatAlreadyFailed.has(instance))) + ) { + fiber = createCapturedValue(error, fiber); + fiber = createClassErrorUpdate(JSCompiler_inline_result, fiber, 1); + enqueueUpdate(JSCompiler_inline_result, fiber, 1); + scheduleWork(JSCompiler_inline_result, 1); + JSCompiler_inline_result = void 0; + break a; + } + break; + case 3: + fiber = createCapturedValue(error, fiber); + fiber = createRootErrorUpdate(JSCompiler_inline_result, fiber, 1); + enqueueUpdate(JSCompiler_inline_result, fiber, 1); + scheduleWork(JSCompiler_inline_result, 1); + JSCompiler_inline_result = void 0; + break a; + } + JSCompiler_inline_result = JSCompiler_inline_result.return; + } + 3 === fiber.tag && + ((JSCompiler_inline_result = createCapturedValue(error, fiber)), + (JSCompiler_inline_result = createRootErrorUpdate( + fiber, + JSCompiler_inline_result, + 1 + )), + enqueueUpdate(fiber, JSCompiler_inline_result, 1), + scheduleWork(fiber, 1)); + JSCompiler_inline_result = void 0; + } + return JSCompiler_inline_result; +} +function computeExpirationForFiber(currentTime, fiber) { + currentTime = + 0 !== expirationContext + ? expirationContext + : isWorking + ? isCommitting$1 ? 1 : nextRenderExpirationTime + : fiber.mode & 1 + ? isBatchingInteractiveUpdates + ? 2 + 10 * ((((currentTime - 2 + 15) / 10) | 0) + 1) + : 2 + 25 * ((((currentTime - 2 + 500) / 25) | 0) + 1) + : 1; + isBatchingInteractiveUpdates && + (0 === lowestPendingInteractiveExpirationTime || + currentTime > lowestPendingInteractiveExpirationTime) && + (lowestPendingInteractiveExpirationTime = currentTime); + return currentTime; +} +function scheduleWork(fiber, expirationTime) { + for (; null !== fiber; ) { + if (0 === fiber.expirationTime || fiber.expirationTime > expirationTime) + fiber.expirationTime = expirationTime; + null !== fiber.alternate && + (0 === fiber.alternate.expirationTime || + fiber.alternate.expirationTime > expirationTime) && + (fiber.alternate.expirationTime = expirationTime); + if (null === fiber.return) + if (3 === fiber.tag) { + var root = fiber.stateNode; + !isWorking && + 0 !== nextRenderExpirationTime && + expirationTime < nextRenderExpirationTime && + resetStack(); + markPendingPriorityLevel(root, expirationTime); + (isWorking && !isCommitting$1 && nextRoot === root) || + requestWork(root, root.expirationTime); + nestedUpdateCount > NESTED_UPDATE_LIMIT && + invariant( + !1, + "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops." + ); + } else break; + fiber = fiber.return; + } +} +function recalculateCurrentTime() { + mostRecentCurrentTimeMs = now$1() - originalStartTimeMs; + return (mostRecentCurrentTime = ((mostRecentCurrentTimeMs / 10) | 0) + 2); +} +function syncUpdates(fn, a, b, c, d) { + var previousExpirationContext = expirationContext; + expirationContext = 1; + try { + return fn(a, b, c, d); + } finally { + expirationContext = previousExpirationContext; + } +} +var firstScheduledRoot = null, + lastScheduledRoot = null, + callbackExpirationTime = 0, + callbackID = void 0, + isRendering = !1, + nextFlushedRoot = null, + nextFlushedExpirationTime = 0, + lowestPendingInteractiveExpirationTime = 0, + deadlineDidExpire = !1, + hasUnhandledError = !1, + unhandledError = null, + deadline = null, + isBatchingUpdates = !1, + isUnbatchingUpdates = !1, + isBatchingInteractiveUpdates = !1, + completedBatches = null, + NESTED_UPDATE_LIMIT = 1e3, + nestedUpdateCount = 0, + timeHeuristicForUnitOfWork = 1; +function scheduleCallbackWithExpirationTime(expirationTime) { + if (0 !== callbackExpirationTime) { + if (expirationTime > callbackExpirationTime) return; + if (null !== callbackID) { + var callbackID$jscomp$0 = callbackID; + scheduledCallback = null; + clearTimeout(callbackID$jscomp$0); + } + } + callbackExpirationTime = expirationTime; + now$1(); + scheduledCallback = performAsyncWork; + callbackID = setTimeout(setTimeoutCallback, 1); +} +function onSuspend(root, suspendedExpirationTime, expirationTime, timeoutMs) { + 0 <= timeoutMs && + setTimeout(function() { + var latestSuspendedTime = root.latestSuspendedTime; + 0 !== latestSuspendedTime && + latestSuspendedTime <= suspendedExpirationTime && + ((latestSuspendedTime = root.latestPingedTime), + 0 === latestSuspendedTime || + latestSuspendedTime < suspendedExpirationTime) && + (root.latestPingedTime = suspendedExpirationTime); + findNextPendingPriorityLevel(root); + latestSuspendedTime = root.expirationTime; + 0 !== latestSuspendedTime && requestWork(root, latestSuspendedTime); + }, timeoutMs); + root.expirationTime = expirationTime; +} +function requestWork(root, expirationTime) { + if (null === root.nextScheduledRoot) + (root.expirationTime = expirationTime), + null === lastScheduledRoot + ? ((firstScheduledRoot = lastScheduledRoot = root), + (root.nextScheduledRoot = root)) + : ((lastScheduledRoot = lastScheduledRoot.nextScheduledRoot = root), + (lastScheduledRoot.nextScheduledRoot = firstScheduledRoot)); + else { + var remainingExpirationTime = root.expirationTime; + if ( + 0 === remainingExpirationTime || + expirationTime < remainingExpirationTime + ) + root.expirationTime = expirationTime; + } + isRendering || + (isBatchingUpdates + ? isUnbatchingUpdates && + ((nextFlushedRoot = root), + (nextFlushedExpirationTime = 1), + performWorkOnRoot(root, 1, !1)) + : 1 === expirationTime + ? performWork(1, null) + : scheduleCallbackWithExpirationTime(expirationTime)); +} +function findHighestPriorityRoot() { + var highestPriorityWork = 0, + highestPriorityRoot = null; + if (null !== lastScheduledRoot) + for ( + var previousScheduledRoot = lastScheduledRoot, root = firstScheduledRoot; + null !== root; + + ) { + var remainingExpirationTime = root.expirationTime; + if (0 === remainingExpirationTime) { + invariant( + null !== previousScheduledRoot && null !== lastScheduledRoot, + "Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue." + ); + if (root === root.nextScheduledRoot) { + firstScheduledRoot = lastScheduledRoot = root.nextScheduledRoot = null; + break; + } else if (root === firstScheduledRoot) + (firstScheduledRoot = remainingExpirationTime = + root.nextScheduledRoot), + (lastScheduledRoot.nextScheduledRoot = remainingExpirationTime), + (root.nextScheduledRoot = null); + else if (root === lastScheduledRoot) { + lastScheduledRoot = previousScheduledRoot; + lastScheduledRoot.nextScheduledRoot = firstScheduledRoot; + root.nextScheduledRoot = null; + break; + } else + (previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot), + (root.nextScheduledRoot = null); + root = previousScheduledRoot.nextScheduledRoot; + } else { + if ( + 0 === highestPriorityWork || + remainingExpirationTime < highestPriorityWork + ) + (highestPriorityWork = remainingExpirationTime), + (highestPriorityRoot = root); + if (root === lastScheduledRoot) break; + previousScheduledRoot = root; + root = root.nextScheduledRoot; + } + } + previousScheduledRoot = nextFlushedRoot; + null !== previousScheduledRoot && + previousScheduledRoot === highestPriorityRoot && + 1 === highestPriorityWork + ? nestedUpdateCount++ + : (nestedUpdateCount = 0); + nextFlushedRoot = highestPriorityRoot; + nextFlushedExpirationTime = highestPriorityWork; +} +function performAsyncWork(dl) { + performWork(0, dl); +} +function performWork(minExpirationTime, dl) { + deadline = dl; + findHighestPriorityRoot(); + resumeActualRenderTimerIfPaused(); + if (null !== deadline) + for ( + ; + null !== nextFlushedRoot && + 0 !== nextFlushedExpirationTime && + (0 === minExpirationTime || + minExpirationTime >= nextFlushedExpirationTime) && + (!deadlineDidExpire || + recalculateCurrentTime() >= nextFlushedExpirationTime); + + ) + recalculateCurrentTime(), + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !0), + findHighestPriorityRoot(); + else + for ( + ; + null !== nextFlushedRoot && + 0 !== nextFlushedExpirationTime && + (0 === minExpirationTime || + minExpirationTime >= nextFlushedExpirationTime); + + ) + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, !1), + findHighestPriorityRoot(); + null !== deadline && ((callbackExpirationTime = 0), (callbackID = null)); + 0 !== nextFlushedExpirationTime && + scheduleCallbackWithExpirationTime(nextFlushedExpirationTime); + deadline = null; + deadlineDidExpire = !1; + finishRendering(); +} +function finishRendering() { + nestedUpdateCount = 0; + if (null !== completedBatches) { + var batches = completedBatches; + completedBatches = null; + for (var i = 0; i < batches.length; i++) { + var batch = batches[i]; + try { + batch._onComplete(); + } catch (error) { + hasUnhandledError || + ((hasUnhandledError = !0), (unhandledError = error)); + } + } + } + if (hasUnhandledError) + throw ((batches = unhandledError), + (unhandledError = null), + (hasUnhandledError = !1), + batches); +} +function performWorkOnRoot(root, expirationTime, isYieldy) { + invariant( + !isRendering, + "performWorkOnRoot was called recursively. This error is likely caused by a bug in React. Please file an issue." + ); + isRendering = !0; + isYieldy + ? ((isYieldy = root.finishedWork), + null !== isYieldy + ? completeRoot(root, isYieldy, expirationTime) + : ((root.finishedWork = null), + renderRoot(root, !0), + (isYieldy = root.finishedWork), + null !== isYieldy && + (shouldYield() + ? ((root.finishedWork = isYieldy), + 0 === timerPausedAt && (timerPausedAt = now$1())) + : completeRoot(root, isYieldy, expirationTime)))) + : ((isYieldy = root.finishedWork), + null !== isYieldy + ? completeRoot(root, isYieldy, expirationTime) + : ((root.finishedWork = null), + renderRoot(root, !1), + (isYieldy = root.finishedWork), + null !== isYieldy && completeRoot(root, isYieldy, expirationTime))); + isRendering = !1; +} +function completeRoot(root, finishedWork$jscomp$0, expirationTime) { + var firstBatch = root.firstBatch; + if ( + null !== firstBatch && + firstBatch._expirationTime <= expirationTime && + (null === completedBatches + ? (completedBatches = [firstBatch]) + : completedBatches.push(firstBatch), + firstBatch._defer) + ) { + root.finishedWork = finishedWork$jscomp$0; + root.expirationTime = 0; + return; + } + root.finishedWork = null; + isCommitting$1 = isWorking = !0; + invariant( + root.current !== finishedWork$jscomp$0, + "Cannot commit the same tree as before. This is probably a bug related to the return field. This error is likely caused by a bug in React. Please file an issue." + ); + expirationTime = root.pendingCommitExpirationTime; + invariant( + 0 !== expirationTime, + "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." + ); + root.pendingCommitExpirationTime = 0; + firstBatch = finishedWork$jscomp$0.expirationTime; + recalculateCurrentTime(); + root.didError = !1; + if (0 === firstBatch) + (root.earliestPendingTime = 0), + (root.latestPendingTime = 0), + (root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0); + else { + var latestPendingTime = root.latestPendingTime; + 0 !== latestPendingTime && + (latestPendingTime < firstBatch + ? (root.earliestPendingTime = root.latestPendingTime = 0) + : root.earliestPendingTime < firstBatch && + (root.earliestPendingTime = root.latestPendingTime)); + latestPendingTime = root.earliestSuspendedTime; + 0 === latestPendingTime + ? markPendingPriorityLevel(root, firstBatch) + : firstBatch > root.latestSuspendedTime + ? ((root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0), + markPendingPriorityLevel(root, firstBatch)) + : firstBatch < latestPendingTime && + markPendingPriorityLevel(root, firstBatch); + } + findNextPendingPriorityLevel(root); + ReactCurrentOwner.current = null; + 1 < finishedWork$jscomp$0.effectTag + ? null !== finishedWork$jscomp$0.lastEffect + ? ((finishedWork$jscomp$0.lastEffect.nextEffect = finishedWork$jscomp$0), + (firstBatch = finishedWork$jscomp$0.firstEffect)) + : (firstBatch = finishedWork$jscomp$0) + : (firstBatch = finishedWork$jscomp$0.firstEffect); + for (nextEffect = firstBatch; null !== nextEffect; ) { + latestPendingTime = !1; + var error = void 0; + try { + for (; null !== nextEffect; ) { + if (nextEffect.effectTag & 256) { + var current = nextEffect.alternate, + finishedWork = nextEffect; + switch (finishedWork.tag) { + case 2: + if (finishedWork.effectTag & 256 && null !== current) { + var prevProps = current.memoizedProps, + prevState = current.memoizedState, + instance = finishedWork.stateNode; + instance.props = finishedWork.memoizedProps; + instance.state = finishedWork.memoizedState; + var snapshot = instance.getSnapshotBeforeUpdate( + prevProps, + prevState + ); + instance.__reactInternalSnapshotBeforeUpdate = snapshot; + } + 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." + ); + } + } + nextEffect = nextEffect.nextEffect; + } + } catch (e) { + (latestPendingTime = !0), (error = e); + } + latestPendingTime && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, error), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + commitTime = now$1(); + for (nextEffect = firstBatch; null !== nextEffect; ) { + current = !1; + prevProps = void 0; + try { + for (; null !== nextEffect; ) { + var effectTag = nextEffect.effectTag; + if (effectTag & 128) { + var current$jscomp$0 = nextEffect.alternate; + if (null !== current$jscomp$0) { + var currentRef = current$jscomp$0.ref; + null !== currentRef && + ("function" === typeof currentRef + ? currentRef(null) + : (currentRef.current = null)); + } + } + switch (effectTag & 14) { + case 2: + commitPlacement(nextEffect); + nextEffect.effectTag &= -3; + break; + case 6: + commitPlacement(nextEffect); + nextEffect.effectTag &= -3; + commitWork(nextEffect.alternate, nextEffect); + break; + case 4: + commitWork(nextEffect.alternate, nextEffect); + break; + case 8: + (prevState = nextEffect), + unmountHostComponents(prevState), + (prevState.return = null), + (prevState.child = null), + prevState.alternate && + ((prevState.alternate.child = null), + (prevState.alternate.return = null)); + } + nextEffect = nextEffect.nextEffect; + } + } catch (e) { + (current = !0), (prevProps = e); + } + current && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, prevProps), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + root.current = finishedWork$jscomp$0; + for (nextEffect = firstBatch; null !== nextEffect; ) { + effectTag = !1; + current$jscomp$0 = void 0; + try { + for (currentRef = expirationTime; null !== nextEffect; ) { + var effectTag$jscomp$0 = nextEffect.effectTag; + if (effectTag$jscomp$0 & 36) { + var current$jscomp$1 = nextEffect.alternate; + current = nextEffect; + prevProps = currentRef; + switch (current.tag) { + case 2: + var instance$jscomp$0 = current.stateNode; + if (current.effectTag & 4) + if (null === current$jscomp$1) + (instance$jscomp$0.props = current.memoizedProps), + (instance$jscomp$0.state = current.memoizedState), + instance$jscomp$0.componentDidMount(); + else { + var prevProps$jscomp$0 = current$jscomp$1.memoizedProps, + prevState$jscomp$0 = current$jscomp$1.memoizedState; + instance$jscomp$0.props = current.memoizedProps; + instance$jscomp$0.state = current.memoizedState; + instance$jscomp$0.componentDidUpdate( + prevProps$jscomp$0, + prevState$jscomp$0, + instance$jscomp$0.__reactInternalSnapshotBeforeUpdate + ); + } + var updateQueue = current.updateQueue; + null !== updateQueue && + ((instance$jscomp$0.props = current.memoizedProps), + (instance$jscomp$0.state = current.memoizedState), + commitUpdateQueue( + current, + updateQueue, + instance$jscomp$0, + prevProps + )); + break; + case 3: + var _updateQueue = current.updateQueue; + if (null !== _updateQueue) { + prevState = null; + if (null !== current.child) + switch (current.child.tag) { + case 5: + prevState = current.child.stateNode; + break; + case 2: + prevState = current.child.stateNode; + } + commitUpdateQueue(current, _updateQueue, prevState, prevProps); + } + break; + case 5: + break; + case 6: + break; + case 4: + break; + case 15: + break; + case 16: + 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." + ); + } + } + if (effectTag$jscomp$0 & 128) { + current = void 0; + var ref = nextEffect.ref; + if (null !== ref) { + var instance$jscomp$1 = nextEffect.stateNode; + switch (nextEffect.tag) { + case 5: + current = instance$jscomp$1; + break; + default: + current = instance$jscomp$1; + } + "function" === typeof ref ? ref(current) : (ref.current = current); + } + } + var next = nextEffect.nextEffect; + nextEffect.nextEffect = null; + nextEffect = next; + } + } catch (e) { + (effectTag = !0), (current$jscomp$0 = e); + } + effectTag && + (invariant( + null !== nextEffect, + "Should have next effect. This error is likely caused by a bug in React. Please file an issue." + ), + captureCommitPhaseError(nextEffect, current$jscomp$0), + null !== nextEffect && (nextEffect = nextEffect.nextEffect)); + } + totalElapsedPauseTime = 0; + isWorking = isCommitting$1 = !1; + "function" === typeof onCommitRoot && + onCommitRoot(finishedWork$jscomp$0.stateNode); + finishedWork$jscomp$0 = root.expirationTime; + 0 === finishedWork$jscomp$0 && + (legacyErrorBoundariesThatAlreadyFailed = null); + root.expirationTime = finishedWork$jscomp$0; + root.finishedWork = null; +} +function shouldYield() { + return null === deadline || + deadlineDidExpire || + deadline.timeRemaining() > timeHeuristicForUnitOfWork + ? !1 + : (deadlineDidExpire = !0); +} +function onUncaughtError(error) { + invariant( + null !== nextFlushedRoot, + "Should be working on a root. This error is likely caused by a bug in React. Please file an issue." + ); + nextFlushedRoot.expirationTime = 0; + hasUnhandledError || ((hasUnhandledError = !0), (unhandledError = error)); +} +function updateContainerAtExpirationTime( + element, + container, + parentComponent, + expirationTime, + callback +) { + var current = container.current; + if (parentComponent) { + parentComponent = parentComponent._reactInternalFiber; + var parentContext; + b: { + invariant( + 2 === isFiberMountedImpl(parentComponent) && 2 === parentComponent.tag, + "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." + ); + for (parentContext = parentComponent; 3 !== parentContext.tag; ) { + if (isContextProvider(parentContext)) { + parentContext = + parentContext.stateNode.__reactInternalMemoizedMergedChildContext; + break b; + } + parentContext = parentContext.return; + invariant( + parentContext, + "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." + ); + } + parentContext = parentContext.stateNode.context; + } + parentComponent = isContextProvider(parentComponent) + ? processChildContext(parentComponent, parentContext) + : parentContext; + } else parentComponent = emptyObject; + null === container.context + ? (container.context = parentComponent) + : (container.pendingContext = parentComponent); + container = callback; + callback = createUpdate(expirationTime); + callback.payload = { element: element }; + container = void 0 === container ? null : container; + null !== container && (callback.callback = container); + enqueueUpdate(current, callback, expirationTime); + scheduleWork(current, expirationTime); + return expirationTime; +} +function findHostInstance$1(component) { + var fiber = component._reactInternalFiber; + void 0 === fiber && + ("function" === typeof component.render + ? invariant(!1, "Unable to find node on an unmounted component.") + : invariant( + !1, + "Argument appears to not be a ReactComponent. Keys: %s", + Object.keys(component) + )); + component = findCurrentHostFiber(fiber); + return null === component ? null : component.stateNode; +} +function updateContainer(element, container, parentComponent, callback) { + var current = container.current, + currentTime = recalculateCurrentTime(); + current = computeExpirationForFiber(currentTime, current); + return updateContainerAtExpirationTime( + element, + container, + parentComponent, + current, + callback + ); +} +function getPublicRootInstance(container) { + container = container.current; + if (!container.child) return null; + switch (container.child.tag) { + case 5: + return container.child.stateNode; + default: + return container.child.stateNode; + } +} +function injectIntoDevTools(devToolsConfig) { + var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; + return injectInternals( + Object.assign({}, devToolsConfig, { + findHostInstanceByFiber: function(fiber) { + fiber = findCurrentHostFiber(fiber); + return null === fiber ? null : fiber.stateNode; + }, + findFiberByHostInstance: function(instance) { + return findFiberByHostInstance + ? findFiberByHostInstance(instance) + : null; + } + }) + ); +} +var ReactNativeFiberRenderer = { + updateContainerAtExpirationTime: updateContainerAtExpirationTime, + createContainer: function(containerInfo, isAsync, hydrate) { + return createFiberRoot(containerInfo, isAsync, hydrate); + }, + updateContainer: updateContainer, + flushRoot: function(root, expirationTime) { + invariant( + !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); + performWork(1, null); + finishRendering(); + }, + requestWork: requestWork, + computeUniqueAsyncExpiration: function() { + var result = + 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); + result <= lastUniqueAsyncExpiration && + (result = lastUniqueAsyncExpiration + 1); + return (lastUniqueAsyncExpiration = result); + }, + batchedUpdates: function(fn, a) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + return fn(a); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + unbatchedUpdates: function(fn, a) { + if (isBatchingUpdates && !isUnbatchingUpdates) { + isUnbatchingUpdates = !0; + try { + return fn(a); + } finally { + isUnbatchingUpdates = !1; + } + } + return fn(a); + }, + deferredUpdates: function(fn) { + var previousExpirationContext = expirationContext; + expirationContext = + 2 + 25 * ((((recalculateCurrentTime() - 2 + 500) / 25) | 0) + 1); + try { + return fn(); + } finally { + expirationContext = previousExpirationContext; + } + }, + syncUpdates: syncUpdates, + interactiveUpdates: function(fn, a, b) { + if (isBatchingInteractiveUpdates) return fn(a, b); + isBatchingUpdates || + isRendering || + 0 === lowestPendingInteractiveExpirationTime || + (performWork(lowestPendingInteractiveExpirationTime, null), + (lowestPendingInteractiveExpirationTime = 0)); + var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates, + previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = isBatchingInteractiveUpdates = !0; + try { + return fn(a, b); + } finally { + (isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates), + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + flushInteractiveUpdates: function() { + isRendering || + 0 === lowestPendingInteractiveExpirationTime || + (performWork(lowestPendingInteractiveExpirationTime, null), + (lowestPendingInteractiveExpirationTime = 0)); + }, + flushControlled: function(fn) { + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + syncUpdates(fn); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates) || + isRendering || + performWork(1, null); + } + }, + flushSync: function(fn, a) { + invariant( + !isRendering, + "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering." + ); + var previousIsBatchingUpdates = isBatchingUpdates; + isBatchingUpdates = !0; + try { + return syncUpdates(fn, a); + } finally { + (isBatchingUpdates = previousIsBatchingUpdates), performWork(1, null); + } + }, + getPublicRootInstance: getPublicRootInstance, + findHostInstance: findHostInstance$1, + findHostInstanceWithNoPortals: function(fiber) { + fiber = findCurrentHostFiberWithNoPortals(fiber); + return null === fiber ? null : fiber.stateNode; + }, + injectIntoDevTools: injectIntoDevTools +}; +function createPortal(children, containerInfo, implementation) { + var key = + 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null; + return { + $$typeof: REACT_PORTAL_TYPE, + key: null == key ? null : "" + key, + children: children, + containerInfo: containerInfo, + implementation: implementation + }; +} +function _inherits(subClass, superClass) { + if ("function" !== typeof superClass && null !== superClass) + throw new TypeError( + "Super expression must either be null or a function, not " + + typeof superClass + ); + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: !1, + writable: !0, + configurable: !0 + } + }); + superClass && + (Object.setPrototypeOf + ? Object.setPrototypeOf(subClass, superClass) + : (subClass.__proto__ = superClass)); +} +var getInspectorDataForViewTag = void 0; +getInspectorDataForViewTag = function() { + invariant(!1, "getInspectorDataForViewTag() is not available in production"); +}; +function findNodeHandle(componentOrHandle) { + if (null == componentOrHandle) return null; + if ("number" === typeof componentOrHandle) return componentOrHandle; + if (componentOrHandle._nativeTag) return componentOrHandle._nativeTag; + if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) + return componentOrHandle.canonical._nativeTag; + componentOrHandle = findHostInstance$1(componentOrHandle); + return null == componentOrHandle + ? componentOrHandle + : componentOrHandle.canonical + ? componentOrHandle.canonical._nativeTag + : componentOrHandle._nativeTag; +} +_batchedUpdates = ReactNativeFiberRenderer.batchedUpdates; +_flushInteractiveUpdates = ReactNativeFiberRenderer.flushInteractiveUpdates; +var roots = new Map(), + ReactNativeRenderer = { + NativeComponent: (function(findNodeHandle, findHostInstance) { + return (function(_React$Component) { + function ReactNativeComponent() { + if (!(this instanceof ReactNativeComponent)) + throw new TypeError("Cannot call a class as a function"); + var call = _React$Component.apply(this, arguments); + if (!this) + throw new ReferenceError( + "this hasn't been initialised - super() hasn't been called" + ); + return !call || + ("object" !== typeof call && "function" !== typeof call) + ? this + : call; + } + _inherits(ReactNativeComponent, _React$Component); + ReactNativeComponent.prototype.blur = function() { + TextInputState.blurTextInput(findNodeHandle(this)); + }; + ReactNativeComponent.prototype.focus = function() { + TextInputState.focusTextInput(findNodeHandle(this)); + }; + ReactNativeComponent.prototype.measure = function(callback) { + UIManager.measure( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }; + ReactNativeComponent.prototype.measureInWindow = function(callback) { + UIManager.measureInWindow( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }; + ReactNativeComponent.prototype.measureLayout = function( + relativeToNativeNode, + onSuccess, + onFail + ) { + UIManager.measureLayout( + findNodeHandle(this), + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }; + ReactNativeComponent.prototype.setNativeProps = function(nativeProps) { + var maybeInstance = void 0; + try { + maybeInstance = findHostInstance(this); + } catch (error) {} + if (null != maybeInstance) { + var viewConfig = + maybeInstance.viewConfig || maybeInstance.canonical.viewConfig; + nativeProps = diffProperties( + null, + emptyObject$1, + nativeProps, + viewConfig.validAttributes + ); + null != nativeProps && + UIManager.updateView( + maybeInstance._nativeTag, + viewConfig.uiViewClassName, + nativeProps + ); + } + }; + return ReactNativeComponent; + })(React.Component); + })(findNodeHandle, findHostInstance$1), + findNodeHandle: findNodeHandle, + render: function(element, containerTag, callback) { + var root = roots.get(containerTag); + root || + ((root = createFiberRoot(containerTag, !1, !1)), + roots.set(containerTag, root)); + updateContainer(element, root, null, callback); + return getPublicRootInstance(root); + }, + unmountComponentAtNode: function(containerTag) { + var root = roots.get(containerTag); + root && + updateContainer(null, root, null, function() { + roots.delete(containerTag); + }); + }, + unmountComponentAtNodeAndRemoveContainer: function(containerTag) { + ReactNativeRenderer.unmountComponentAtNode(containerTag); + UIManager.removeRootView(containerTag); + }, + createPortal: function(children, containerTag) { + return createPortal( + children, + containerTag, + null, + 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : null + ); + }, + unstable_batchedUpdates: batchedUpdates, + __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: { + NativeMethodsMixin: (function(findNodeHandle, findHostInstance) { + return { + measure: function(callback) { + UIManager.measure( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }, + measureInWindow: function(callback) { + UIManager.measureInWindow( + findNodeHandle(this), + mountSafeCallback(this, callback) + ); + }, + measureLayout: function(relativeToNativeNode, onSuccess, onFail) { + UIManager.measureLayout( + findNodeHandle(this), + relativeToNativeNode, + mountSafeCallback(this, onFail), + mountSafeCallback(this, onSuccess) + ); + }, + setNativeProps: function(nativeProps) { + var maybeInstance = void 0; + try { + maybeInstance = findHostInstance(this); + } catch (error) {} + if (null != maybeInstance) { + var viewConfig = maybeInstance.viewConfig; + nativeProps = diffProperties( + null, + emptyObject$1, + nativeProps, + viewConfig.validAttributes + ); + null != nativeProps && + UIManager.updateView( + maybeInstance._nativeTag, + viewConfig.uiViewClassName, + nativeProps + ); + } + }, + focus: function() { + TextInputState.focusTextInput(findNodeHandle(this)); + }, + blur: function() { + TextInputState.blurTextInput(findNodeHandle(this)); + } + }; + })(findNodeHandle, findHostInstance$1), + computeComponentStackForErrorReporting: function(reactTag) { + return (reactTag = getInstanceFromTag(reactTag)) + ? getStackAddendumByWorkInProgressFiber(reactTag) + : ""; + } + } + }; +injectIntoDevTools({ + findFiberByHostInstance: getInstanceFromTag, + getInspectorDataForViewTag: getInspectorDataForViewTag, + bundleType: 0, + version: "16.4.1", + rendererPackageName: "react-native-renderer" +}); +var ReactNativeRenderer$2 = { default: ReactNativeRenderer }, + ReactNativeRenderer$3 = + (ReactNativeRenderer$2 && ReactNativeRenderer) || ReactNativeRenderer$2; +module.exports = ReactNativeRenderer$3.default + ? ReactNativeRenderer$3.default + : ReactNativeRenderer$3; diff --git a/Libraries/Renderer/shims/ReactNativeComponentTree.js b/Libraries/Renderer/shims/ReactNativeComponentTree.js deleted file mode 100644 index 702b621a5e46e7..00000000000000 --- a/Libraries/Renderer/shims/ReactNativeComponentTree.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow - */ - -'use strict'; - -const { - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, -} = require('ReactNative'); - -module.exports = - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactNativeComponentTree; diff --git a/Libraries/Renderer/shims/ReactNativeTypes.js b/Libraries/Renderer/shims/ReactNativeTypes.js index c38b0b44ebcf9e..991aa338e77016 100644 --- a/Libraries/Renderer/shims/ReactNativeTypes.js +++ b/Libraries/Renderer/shims/ReactNativeTypes.js @@ -89,7 +89,6 @@ export type NativeMethodsMixinType = { type SecretInternalsType = { NativeMethodsMixin: NativeMethodsMixinType, - ReactNativeComponentTree: any, computeComponentStackForErrorReporting(tag: number): string, // TODO (bvaughn) Decide which additional types to expose here? // And how much information to fill in for the above types. @@ -97,7 +96,6 @@ type SecretInternalsType = { type SecretInternalsFabricType = { NativeMethodsMixin: NativeMethodsMixinType, - ReactNativeComponentTree: any, }; /** diff --git a/package.json b/package.json index f6d00306385fa8..e8f5a895c96dd0 100644 --- a/package.json +++ b/package.json @@ -143,7 +143,7 @@ "react-native": "local-cli/wrong-react-native.js" }, "peerDependencies": { - "react": "16.3.2" + "react": "16.4.1" }, "dependencies": { "absolute-path": "^0.0.0", @@ -216,8 +216,8 @@ "jest": "23.1.0", "jest-junit": "4.0.0", "prettier": "1.13.4", - "react": "16.3.2", - "react-test-renderer": "16.3.2", + "react": "16.4.1", + "react-test-renderer": "16.4.1", "shelljs": "^0.7.8", "sinon": "^2.2.0" }