From ccefc700d0120539eba73747d1d6b65effb0645d Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Fri, 8 Feb 2019 07:04:29 -0800 Subject: [PATCH] React sync for revisions 6bf5e85...aa94237 (#23320) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: allow-large-files This sync includes the following changes: - **[45fc46bfa](https://github.com/facebook/react/commit/45fc46bfa )**: 16.8.1 packages //// - **[f2e2637c8](https://github.com/facebook/react/commit/f2e2637c8 )**: Backwards compat fix for ReactCurrentDispatcher on older react versions (#14770) //// - **[1107b9673](https://github.com/facebook/react/commit/1107b9673 )**: [TestUtils.act] warn when using TestUtils.act in node (#14768) //// - **[0975ea327](https://github.com/facebook/react/commit/0975ea327 )**: eslint-plugin-react-hooks v1.0.0 //// - **[bc9818f24](https://github.com/facebook/react/commit/bc9818f24 )**: Scheduler.unstable_next (#14756) //// - **[ce6ecd3fb](https://github.com/facebook/react/commit/ce6ecd3fb )**: Add 16.8.0 changelog and update some READMEs (#14692) //// - **[008a2ab9c](https://github.com/facebook/react/commit/008a2ab9c )**: 16.8.0 //// - **[d1326f466](https://github.com/facebook/react/commit/d1326f466 )**: [TestUtils.act] fix return result checking (#14758) //// - **[267ed9814](https://github.com/facebook/react/commit/267ed9814 )**: expose `TestUtils.act()` for batching actions in tests (#14744) //// - **[fb3f7bfde](https://github.com/facebook/react/commit/fb3f7bfde )**: Avoid importing Scheduler directly (#14757) //// - **[e602b5291](https://github.com/facebook/react/commit/e602b5291 )**: Use SameValue instead of === to check for dispatchAction equivalence (#14752) //// - **[e489c3f9c](https://github.com/facebook/react/commit/e489c3f9c )**: Update the version with Hooks proposal in README (#14751) //// - **[c21c41ecf](https://github.com/facebook/react/commit/c21c41ecf )**: Tweak invalid Hook warning and error (#14747) //// - **[fec00a869](https://github.com/facebook/react/commit/fec00a869 )**: Typo in comment (#14739) //// - **[66eb29374](https://github.com/facebook/react/commit/66eb29374 )**: Restrict effect return type to a function or nothing (#14119) //// - **[51c07912a](https://github.com/facebook/react/commit/51c07912a )**: Warn when second argument is passed to useCallback (#14729) //// - **[70d407583](https://github.com/facebook/react/commit/70d407583 )**: Move Hook mismatch warning to first mismatch site (#14720) //// - **[ba6477aa3](https://github.com/facebook/react/commit/ba6477aa3 )**: Improve Reducer Hook's lazy init API (#14723) //// - **[cb1ff430e](https://github.com/facebook/react/commit/cb1ff430e )**: Phased dispatcher (#14701) //// - **[9d483dcfd](https://github.com/facebook/react/commit/9d483dcfd )**: Spelling abitrarily -> arbitrarily (#14710) //// - **[e19c9e106](https://github.com/facebook/react/commit/e19c9e106 )**: Fix issue with multiple code branches in hooks linter (#14661) //// - **[f11a9c1cb](https://github.com/facebook/react/commit/f11a9c1cb )**: State update bug in concurrent mode (#14698) //// - **[e679a4b6e](https://github.com/facebook/react/commit/e679a4b6e )**: Fix typo in code comment (#14696) //// - **[8bcc88f2e](https://github.com/facebook/react/commit/8bcc88f2e )**: Make all readContext() and Hook-in-a-Hook checks DEV-only (#14677) //// - **[6cb26774e](https://github.com/facebook/react/commit/6cb26774e )**: Enable hooks! (#14679) //// - **[73962c366](https://github.com/facebook/react/commit/73962c366 )**: Revert "Revert "Double-render function components with Hooks in DEV in StrictMode" (#14652)" (#14654) //// - **[994439228](https://github.com/facebook/react/commit/994439228 )**: Put DEV-only code into DEV blocks (#14673) //// - **[f0befae65](https://github.com/facebook/react/commit/f0befae65 )**: Tweak context invariant message (#14671) //// - **[a129259ad](https://github.com/facebook/react/commit/a129259ad )**: Disallow reading context during useMemo etc (#14653) //// - **[c068d31cc](https://github.com/facebook/react/commit/c068d31cc )**: Add unit tests for concurrent mode event dispatching (#14415) //// - **[38247cba3](https://github.com/facebook/react/commit/38247cba3 )**: --save is no longer needed (#14302) //// - **[3f0bcaf0d](https://github.com/facebook/react/commit/3f0bcaf0d )**: Importing React for the first example. (#14346) //// - **[ecd919a2f](https://github.com/facebook/react/commit/ecd919a2f )**: RFC: warn when returning different hooks on subsequent renders (#14585) //// - **[3fbebb2a0](https://github.com/facebook/react/commit/3fbebb2a0 )**: Revert "Double-render function components with Hooks in DEV in StrictMode" (#14652) //// - **[5fce6488c](https://github.com/facebook/react/commit/5fce6488c )**: Revert "Disallow reading context during useMemo etc" (#14651) //// - **[fe2ecd276](https://github.com/facebook/react/commit/fe2ecd276 )**: Add test coverage for readContext() on the server (#14649) //// - **[8f45a7fdc](https://github.com/facebook/react/commit/8f45a7fdc )**: Warn about incorrect use of useImperativeHandle() (#14647) //// - **[1fcbd2243](https://github.com/facebook/react/commit/1fcbd2243 )**: Disallow reading context during useMemo etc (#14648) //// - **[2a084f51a](https://github.com/facebook/react/commit/2a084f51a )**: Warn about refs on lazy function components (#14645) //// - **[b5a3df6e8](https://github.com/facebook/react/commit/b5a3df6e8 )**: Fix typo (#14560) //// - **[9c146e675](https://github.com/facebook/react/commit/9c146e675 )**: fix typo (#14316) //// - **[baa6d40fc](https://github.com/facebook/react/commit/baa6d40fc )**: Mention forwardRef() in errors and warnings (#14644) //// - **[a1414e894](https://github.com/facebook/react/commit/a1414e894 )**: Double-render function components with Hooks in DEV in StrictMode (#14643) //// - **[10a7a5b5c](https://github.com/facebook/react/commit/10a7a5b5c )**: Fix synchronous thenable rejection (#14633) //// - **[a2fa6eb98](https://github.com/facebook/react/commit/a2fa6eb98 )**: Move lazy._result assignment (#14632) //// - **[9120f6c2d](https://github.com/facebook/react/commit/9120f6c2d )**: Support sync thenables for lazy() (#14626) //// - **[b66e6e41e](https://github.com/facebook/react/commit/b66e6e41e )**: Add directory details to the package.json of all packages (#14628) //// - **[177fb7635](https://github.com/facebook/react/commit/177fb7635 )**: Warn when second callback is passed to setState/dispatch in Hooks (#14625) //// - **[d17d0b99c](https://github.com/facebook/react/commit/d17d0b99c )**: Use public context.report interface in eslint rules (#14623) //// - **[4f332885a](https://github.com/facebook/react/commit/4f332885a )**: Fix shallow renderer set instance state after gDSFP before calling sCU (#14613) //// - **[e1cd83e49](https://github.com/facebook/react/commit/e1cd83e49 )**: Throw an error when using hooks inside useMemo/useState/useReducer, or .memo's comparator (#14608) //// - **[be457ca68](https://github.com/facebook/react/commit/be457ca68 )**: Small tweaks to SSR to match #14594 (#14618) //// - **[17d70df91](https://github.com/facebook/react/commit/17d70df91 )**: Warn when mixing createRoot() and old APIs (#14615) //// - **[4feab7fc9](https://github.com/facebook/react/commit/4feab7fc9 )**: Add hooks support to ReactShallowRenderer (#14567) //// - **[1454a8be0](https://github.com/facebook/react/commit/1454a8be0 )**: Don't bother comparing constructor when deps are not provided (#14594) //// - **[71b64d521](https://github.com/facebook/react/commit/71b64d521 )**: Warn if number of hooks increases (#14591) //// - **[790c8ef04](https://github.com/facebook/react/commit/790c8ef04 )**: Allow useReducer to bail out of rendering by returning previous state (#14569) //// - **[7ab8a8e97](https://github.com/facebook/react/commit/7ab8a8e97 )**: Added Flow type to keep hooks dispatchers in-sync (#14599) //// - **[4392e3821](https://github.com/facebook/react/commit/4392e3821 )**: useDebugValue should throw if used in a class component (#14601) //// - **[153a0b598](https://github.com/facebook/react/commit/153a0b598 )**: Add noop useDebugValue hook to partial/server renderer (#14597) //// - **[7ad9806d1](https://github.com/facebook/react/commit/7ad9806d1 )**: Tweak to avoid property read (#14593) //// - **[0fc154751](https://github.com/facebook/react/commit/0fc154751 )**: Avoid new Set([iterable]) for thenables (#14592) //// - **[edb1f5956](https://github.com/facebook/react/commit/edb1f5956 )**: Support configurable labels for custom hooks (#14559) //// - **[3e15b1c69](https://github.com/facebook/react/commit/3e15b1c69 )**: make a fork for ReactCurrentDispatcher (#14588) //// - **[0005d1e3f](https://github.com/facebook/react/commit/0005d1e3f )**: Fix typo (#14576) //// - **[f290138d3](https://github.com/facebook/react/commit/f290138d3 )**: react-debug-tools accepts currentDispatcher ref as param (#14556) //// - **[b4ad8e947](https://github.com/facebook/react/commit/b4ad8e947 )**: rename useImperativeMethods -> useImperativeHandle (#14565) //// - **[ab03e3d65](https://github.com/facebook/react/commit/ab03e3d65 )**: Inject ReactCurrentDispatcher ref to DevTools (#14550) //// - **[19ef0ec11](https://github.com/facebook/react/commit/19ef0ec11 )**: Separate current owner and dispatcher (#14548) //// - **[a9b035b0c](https://github.com/facebook/react/commit/a9b035b0c )**: Separate Object.is polyfill (#14334) //// - **[547e059f0](https://github.com/facebook/react/commit/547e059f0 )**: Simplify wording of key warning (#14503) //// - **[3494ee57e](https://github.com/facebook/react/commit/3494ee57e )**: Update ReactUpdateQueue.js (#14521) //// - **[659c13963](https://github.com/facebook/react/commit/659c13963 )**: Update ReactFiberScheduler.js (#14477) //// - **[c695b2384](https://github.com/facebook/react/commit/c695b2384 )**: React v16.7.0 //// - **[1c5aa2f23](https://github.com/facebook/react/commit/1c5aa2f23 )**: Move SchedulerFeatureFlags fork to src directory to fix lint //// - **[653bc582f](https://github.com/facebook/react/commit/653bc582f )**: Create separate SchedulerFeatureFlags instead of using ReactFeatureFlags (#14455) //// - **[8bfef0da5](https://github.com/facebook/react/commit/8bfef0da5 )**: Make scheduler debugging feature flag static //// - **[4a1072194](https://github.com/facebook/react/commit/4a1072194 )**: Memoize promise listeners to prevent exponential growth (#14429) //// - **[535804f5c](https://github.com/facebook/react/commit/535804f5c )**: Removed Fabric-specific feature flag files and updated Rollup to use the (non-Fabric) React Native flag files. (#14437) //// - **[2743fb7b2](https://github.com/facebook/react/commit/2743fb7b2 )**: Enable hooks by default for FB React Native renderer (#14435) //// - **[7325ebe4d](https://github.com/facebook/react/commit/7325ebe4d )**: Inject overrideProps() fn to DevTools (#14427) //// - **[a22880e5e](https://github.com/facebook/react/commit/a22880e5e )**: Add support for Suspense & lazy() to the react-is package (#14423) //// - **[947bddd5c](https://github.com/facebook/react/commit/947bddd5c )**: Remove redundant argument of getPlugins function (#14419) //// - **[8df4d59be](https://github.com/facebook/react/commit/8df4d59be )**: Implement pauseExecution, continueExecution, dumpQueue for Scheduler (#14053) //// - **[5bb4ad737](https://github.com/facebook/react/commit/5bb4ad737 )**: Added ErrorBoundary tests for useEffect and useLayoutEffect (#14401) //// - **[98eb5ae53](https://github.com/facebook/react/commit/98eb5ae53 )**: TestRenderer toJSON should not expose the Array wrapper Suspense uses for hidden trees (#14392) //// - **[39489e767](https://github.com/facebook/react/commit/39489e767 )**: Enable hooks in fabric (#14301) //// - **[1dc108e58](https://github.com/facebook/react/commit/1dc108e58 )**: Tweaked wording for v8 "performance cliff" issue //// Release Notes: [GENERAL] [Changed] - React sync for revisions 6bf5e85...aa94237 (React 16.8.1) Pull Request resolved: https://github.com/facebook/react-native/pull/23320 Reviewed By: rickhanlonii Differential Revision: D13976467 fbshipit-source-id: 4ce198e86a54658e1c35aa36bffe4a7dc2956a2e --- Libraries/Renderer/REVISION | 2 +- Libraries/Renderer/oss/ReactFabric-dev.js | 8742 +++++++++-------- Libraries/Renderer/oss/ReactFabric-prod.js | 2840 +++--- .../Renderer/oss/ReactFabric-profiling.js | 2359 +++-- .../Renderer/oss/ReactNativeRenderer-dev.js | 8742 +++++++++-------- .../Renderer/oss/ReactNativeRenderer-prod.js | 2847 ++++-- .../oss/ReactNativeRenderer-profiling.js | 2449 +++-- package.json | 6 +- yarn.lock | 68 +- 9 files changed, 16255 insertions(+), 11800 deletions(-) diff --git a/Libraries/Renderer/REVISION b/Libraries/Renderer/REVISION index 3455723424e22f..4f12f00350501b 100644 --- a/Libraries/Renderer/REVISION +++ b/Libraries/Renderer/REVISION @@ -1 +1 @@ -6bf5e859860938b8cb7153ee928c01ad45656969 \ No newline at end of file +aa9423701e99a194d65a8b835882502902a65a50 \ No newline at end of file diff --git a/Libraries/Renderer/oss/ReactFabric-dev.js b/Libraries/Renderer/oss/ReactFabric-dev.js index 6cd1ed2407d89d..7d3affa02f7377 100644 --- a/Libraries/Renderer/oss/ReactFabric-dev.js +++ b/Libraries/Renderer/oss/ReactFabric-dev.js @@ -2572,6 +2572,15 @@ function set(key, value) { var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; +// Prevent newer renderers from RTE when used with older react package versions. +// Current owner and dispatcher used to share the same ref, +// but PR #14548 split them out to better support the react-debug-tools package. +if (!ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher")) { + ReactSharedInternals.ReactCurrentDispatcher = { + current: null + }; +} + // 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. var hasSymbol = typeof Symbol === "function" && Symbol.for; @@ -3910,6 +3919,8 @@ var shouldYield$$1 = shouldYield$1; var scheduleTimeout = setTimeout; var cancelTimeout = clearTimeout; var noTimeout = -1; +var schedulePassiveEffects = scheduleDeferredCallback$$1; +var cancelPassiveEffects = cancelDeferredCallback$$1; // ------------------- // Persistence @@ -4113,9 +4124,8 @@ function setCurrentPhase(lifeCyclePhase) { var debugRenderPhaseSideEffects = false; var debugRenderPhaseSideEffectsForStrictMode = false; var enableUserTimingAPI = true; -var enableHooks = false; -var warnAboutDeprecatedLifecycles = false; var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; +var warnAboutDeprecatedLifecycles = false; var enableProfilerTimer = true; var enableSchedulerTracing = true; @@ -5116,7 +5126,7 @@ function FiberNode(tag, pendingProps, key, mode) { this.memoizedProps = null; this.updateQueue = null; this.memoizedState = null; - this.firstContextDependency = null; + this.contextDependencies = null; this.mode = mode; @@ -5133,14 +5143,16 @@ function FiberNode(tag, pendingProps, key, mode) { this.alternate = null; if (enableProfilerTimer) { - // Note: The following is done to avoid a v8 deopt. + // Note: The following is done to avoid a v8 performance cliff. // - // It is important to initialize the fields below with doubles. - // Otherwise Fibers will deopt and end up having separate shapes when - // doubles are later assigned to fields that initially contained smis. - // This is a bug in v8 having something to do with Object.preventExtension(). + // Initializing the fields below to smis and later updating them with + // double values will cause Fibers to end up having separate shapes. + // This behavior/bug has something to do with Object.preventExtension(). + // Fortunately this only impacts DEV builds. + // Unfortunately it makes React unusably slow for some applications. + // To work around this, initialize the fields below with doubles. // - // Learn more about this deopt here: + // Learn more about this here: // https://github.com/facebook/react/issues/14365 // https://bugs.chromium.org/p/v8/issues/detail?id=8538 this.actualDuration = Number.NaN; @@ -5149,7 +5161,8 @@ function FiberNode(tag, pendingProps, key, mode) { this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization. - // This simplifies other profiler code and doesn't trigger the deopt. + // This won't trigger the performance cliff mentioned above, + // and it simplifies other profiler code (including DevTools). this.actualDuration = 0; this.actualStartTime = -1; this.selfBaseDuration = 0; @@ -5270,7 +5283,7 @@ function createWorkInProgress(current, pendingProps, expirationTime) { workInProgress.memoizedProps = current.memoizedProps; workInProgress.memoizedState = current.memoizedState; workInProgress.updateQueue = current.updateQueue; - workInProgress.firstContextDependency = current.firstContextDependency; + workInProgress.contextDependencies = current.contextDependencies; // These will be overridden during the parent's reconciliation workInProgress.sibling = current.sibling; @@ -5536,7 +5549,7 @@ function assignFiberPropertiesInDEV(target, source) { target.memoizedProps = source.memoizedProps; target.updateQueue = source.updateQueue; target.memoizedState = source.memoizedState; - target.firstContextDependency = source.firstContextDependency; + target.contextDependencies = source.contextDependencies; target.mode = source.mode; target.effectTag = source.effectTag; target.nextEffect = source.nextEffect; @@ -5589,6 +5602,8 @@ function createFiberRoot(containerInfo, isConcurrent, hydrate) { latestSuspendedTime: NoWork, latestPingedTime: NoWork, + pingCache: null, + didError: false, pendingCommitExpirationTime: NoWork, @@ -5612,6 +5627,8 @@ function createFiberRoot(containerInfo, isConcurrent, hydrate) { containerInfo: containerInfo, pendingChildren: null, + pingCache: null, + earliestPendingTime: NoWork, latestPendingTime: NoWork, earliestSuspendedTime: NoWork, @@ -5761,7 +5778,7 @@ var ReactStrictModeWarnings = { lifecycleWarningsMap, strictRoot ) { - var lifecyclesWarningMesages = []; + var lifecyclesWarningMessages = []; Object.keys(lifecycleWarningsMap).forEach(function(lifecycle) { var lifecycleWarnings = lifecycleWarningsMap[lifecycle]; @@ -5776,7 +5793,7 @@ var ReactStrictModeWarnings = { var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle]; var sortedComponentNames = setToSortedString(componentNames); - lifecyclesWarningMesages.push( + lifecyclesWarningMessages.push( formatted + ": Please update the following components to use " + (suggestion + " instead: " + sortedComponentNames) @@ -5784,7 +5801,7 @@ var ReactStrictModeWarnings = { } }); - if (lifecyclesWarningMesages.length > 0) { + if (lifecyclesWarningMessages.length > 0) { var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot); warningWithoutStack$1( @@ -5794,7 +5811,7 @@ var ReactStrictModeWarnings = { "\n\nLearn more about this warning here:" + "\nhttps://fb.me/react-strict-mode-warnings", strictRootComponentStack, - lifecyclesWarningMesages.join("\n\n") + lifecyclesWarningMessages.join("\n\n") ); } }); @@ -6095,6 +6112,10 @@ function markCommittedPriorityLevels(root, earliestRemainingTime) { return; } + if (earliestRemainingTime < root.latestPingedTime) { + root.latestPingedTime = NoWork; + } + // Let's see if the previous latest known pending level was just flushed. var latestPendingTime = root.latestPendingTime; if (latestPendingTime !== NoWork) { @@ -6230,10 +6251,8 @@ function markPingedPriorityLevel(root, pingedTime) { } function clearPing(root, completedTime) { - // TODO: Track whether the root was pinged during the render phase. If so, - // we need to make sure we don't lose track of it. var latestPingedTime = root.latestPingedTime; - if (latestPingedTime !== NoWork && latestPingedTime >= completedTime) { + if (latestPingedTime >= completedTime) { root.latestPingedTime = NoWork; } } @@ -6294,4167 +6313,3975 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) { 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; +/** + * 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. + */ -// 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 warning = warningWithoutStack$1; -var didWarnUpdateInsideUpdate = void 0; -var currentlyProcessingQueue = void 0; -var resetCurrentlyProcessingQueue = void 0; { - didWarnUpdateInsideUpdate = false; - currentlyProcessingQueue = null; - resetCurrentlyProcessingQueue = function() { - currentlyProcessingQueue = null; + warning = function(condition, format) { + if (condition) { + return; + } + var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; + var stack = ReactDebugCurrentFrame.getStackAddendum(); + // eslint-disable-next-line react-internal/warning-and-invariant-args + + for ( + var _len = arguments.length, + args = Array(_len > 2 ? _len - 2 : 0), + _key = 2; + _key < _len; + _key++ + ) { + args[_key - 2] = arguments[_key]; + } + + warningWithoutStack$1.apply( + undefined, + [false, format + "%s"].concat(args, [stack]) + ); }; } -function createUpdateQueue(baseState) { - var queue = { - baseState: baseState, - firstUpdate: null, - lastUpdate: null, - firstCapturedUpdate: null, - lastCapturedUpdate: null, - firstEffect: null, - lastEffect: null, - firstCapturedEffect: null, - lastCapturedEffect: null - }; - return queue; +var warning$1 = warning; + +/** + * 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) { + return ( + (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare + ); } -function cloneUpdateQueue(currentQueue) { - var queue = { - baseState: currentQueue.baseState, - firstUpdate: currentQueue.firstUpdate, - lastUpdate: currentQueue.lastUpdate, +var hasOwnProperty = Object.prototype.hasOwnProperty; - // TODO: With resuming, if we bail out and resuse the child tree, we should - // keep these effects. - firstCapturedUpdate: null, - lastCapturedUpdate: null, +/** + * 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; + } - firstEffect: null, - lastEffect: null, + if ( + typeof objA !== "object" || + objA === null || + typeof objB !== "object" || + objB === null + ) { + return false; + } - firstCapturedEffect: null, - lastCapturedEffect: null - }; - return queue; -} + var keysA = Object.keys(objA); + var keysB = Object.keys(objB); -function createUpdate(expirationTime) { - return { - expirationTime: expirationTime, + if (keysA.length !== keysB.length) { + return false; + } - tag: UpdateState, - payload: null, - callback: null, + // 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; + } + } - next: null, - nextEffect: null - }; + return true; } -function appendUpdateToQueue(queue, update) { - // 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; +function resolveDefaultProps(Component, baseProps) { + if (Component && Component.defaultProps) { + // Resolve default props. Taken from ReactElement + var props = Object.assign({}, baseProps); + var defaultProps = Component.defaultProps; + for (var propName in defaultProps) { + if (props[propName] === undefined) { + props[propName] = defaultProps[propName]; + } + } + return props; } + return baseProps; } -function enqueueUpdate(fiber, update) { - // 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); +function readLazyComponentType(lazyComponent) { + var status = lazyComponent._status; + var result = lazyComponent._result; + switch (status) { + case Resolved: { + var Component = result; + return Component; } - } 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. - } + case Rejected: { + var error = result; + throw error; } - } - if (queue2 === null || queue1 === queue2) { - // There's only a single queue. - appendUpdateToQueue(queue1, update); - } 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); - appendUpdateToQueue(queue2, update); - } 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); - // But we still need to update the `lastUpdate` pointer of queue2. - queue2.lastUpdate = update; + case Pending: { + var thenable = result; + throw thenable; } - } - - { - if ( - fiber.tag === ClassComponent && - (currentlyProcessingQueue === queue1 || - (queue2 !== null && currentlyProcessingQueue === queue2)) && - !didWarnUpdateInsideUpdate - ) { - warningWithoutStack$1( - 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." + default: { + lazyComponent._status = Pending; + var ctor = lazyComponent._ctor; + var _thenable = ctor(); + _thenable.then( + function(moduleObject) { + if (lazyComponent._status === Pending) { + var defaultExport = moduleObject.default; + { + if (defaultExport === undefined) { + warning$1( + false, + "lazy: Expected the result of a dynamic import() call. " + + "Instead received: %s\n\nYour code should look like: \n " + + "const MyComponent = lazy(() => import('./MyComponent'))", + moduleObject + ); + } + } + lazyComponent._status = Resolved; + lazyComponent._result = defaultExport; + } + }, + function(error) { + if (lazyComponent._status === Pending) { + lazyComponent._status = Rejected; + lazyComponent._result = error; + } + } ); - didWarnUpdateInsideUpdate = true; + // Handle synchronous thenables. + switch (lazyComponent._status) { + case Resolved: + return lazyComponent._result; + case Rejected: + throw lazyComponent._result; + } + lazyComponent._result = _thenable; + throw _thenable; } } } -function enqueueCapturedUpdate(workInProgress, update) { - // 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 - ); - } +var fakeInternalInstance = {}; +var isArray$1 = Array.isArray; - // 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; - } -} +// React.Component uses a shared frozen object by default. +// We'll use it to determine whether we need to initialize legacy refs. +var emptyRefsObject = new React.Component().refs; -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; -} +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 didWarnAboutDirectlyAssigningPropsToState = void 0; +var didWarnAboutContextTypeAndContextTypes = void 0; +var didWarnAboutInvalidateContextType = void 0; -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; +{ + didWarnAboutStateAssignmentForComponent = new Set(); + didWarnAboutUninitializedState = new Set(); + didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); + didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); + didWarnAboutDirectlyAssigningPropsToState = new Set(); + didWarnAboutUndefinedDerivedState = new Set(); + didWarnAboutContextTypeAndContextTypes = new Set(); + didWarnAboutInvalidateContextType = new Set(); + + var didWarnOnInvalidCallback = new Set(); + + warnOnInvalidCallback = function(callback, callerName) { + if (callback === null || typeof callback === "function") { + return; } - case CaptureUpdate: { - workInProgress.effectTag = - (workInProgress.effectTag & ~ShouldCapture) | DidCapture; + var key = callerName + "_" + callback; + if (!didWarnOnInvalidCallback.has(key)) { + didWarnOnInvalidCallback.add(key); + warningWithoutStack$1( + false, + "%s(...): Expected the last optional `callback` argument to be a " + + "function. Instead received: %s.", + callerName, + callback + ); } - // 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; + }; + + warnOnUndefinedDerivedState = function(type, partialState) { + if (partialState === undefined) { + var componentName = getComponentName(type) || "Component"; + if (!didWarnAboutUndefinedDerivedState.has(componentName)) { + didWarnAboutUndefinedDerivedState.add(componentName); + warningWithoutStack$1( + false, + "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + + "You have returned undefined.", + componentName + ); } - // Merge the partial state and the previous state. - return Object.assign({}, prevState, partialState); } - case ForceUpdate: { - hasForceUpdate = true; - return prevState; + }; + + // 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)." + ); } - } - return prevState; + }); + Object.freeze(fakeInternalInstance); } -function processUpdateQueue( +function applyDerivedStateFromProps( workInProgress, - queue, - props, - instance, - renderExpirationTime + ctor, + getDerivedStateFromProps, + nextProps ) { - hasForceUpdate = false; + var prevState = workInProgress.memoizedState; - queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + { + 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); { - currentlyProcessingQueue = queue; + warnOnUndefinedDerivedState(ctor, partialState); } + // Merge the partial state and the previous state. + var memoizedState = + partialState === null || partialState === undefined + ? prevState + : Object.assign({}, prevState, partialState); + workInProgress.memoizedState = memoizedState; - // These values may change as we process the queue. - var newBaseState = queue.baseState; - var newFirstUpdate = null; - var newExpirationTime = NoWork; + // Once the update queue is empty, persist the derived state onto the + // base state. + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null && workInProgress.expirationTime === NoWork) { + updateQueue.baseState = memoizedState; + } +} - // 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 < 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; - } +var classComponentUpdater = { + isMounted: isMounted, + enqueueSetState: function(inst, payload, callback) { + var fiber = get$1(inst); + var currentTime = requestCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); + + var update = createUpdate(expirationTime); + update.payload = payload; + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "setState"); } + update.callback = callback; } - // 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 < _updateExpirationTime) { - newExpirationTime = _updateExpirationTime; + flushPassiveEffects(); + enqueueUpdate(fiber, update); + scheduleWork(fiber, expirationTime); + }, + enqueueReplaceState: function(inst, payload, callback) { + var fiber = get$1(inst); + var currentTime = requestCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); + + var update = createUpdate(expirationTime); + update.tag = ReplaceState; + update.payload = payload; + + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "replaceState"); } - } 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.callback = callback; + } + + flushPassiveEffects(); + enqueueUpdate(fiber, update); + scheduleWork(fiber, expirationTime); + }, + enqueueForceUpdate: function(inst, callback) { + var fiber = get$1(inst); + var currentTime = requestCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); + + var update = createUpdate(expirationTime); + update.tag = ForceUpdate; + + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "forceUpdate"); } + update.callback = callback; } - 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; + flushPassiveEffects(); + enqueueUpdate(fiber, update); + scheduleWork(fiber, expirationTime); } +}; - queue.baseState = newBaseState; - queue.firstUpdate = newFirstUpdate; - queue.firstCapturedUpdate = newFirstCapturedUpdate; +function checkShouldComponentUpdate( + workInProgress, + ctor, + oldProps, + newProps, + oldState, + newState, + nextContext +) { + var instance = workInProgress.stateNode; + if (typeof instance.shouldComponentUpdate === "function") { + startPhaseTimer(workInProgress, "shouldComponentUpdate"); + var shouldUpdate = instance.shouldComponentUpdate( + newProps, + newState, + nextContext + ); + stopPhaseTimer(); - // Set the remaining expiration time to be whatever is remaining in the queue. - // This should be fine because the only two other things that contribute to - // expiration time are props and context. We're already in the middle of the - // begin phase by the time we start processing the queue, so we've already - // dealt with the props. Context in components that specify - // shouldComponentUpdate is tricky; but we'll have to account for - // that regardless. - workInProgress.expirationTime = newExpirationTime; - workInProgress.memoizedState = resultState; + { + !(shouldUpdate !== undefined) + ? warningWithoutStack$1( + false, + "%s.shouldComponentUpdate(): Returned undefined instead of a " + + "boolean value. Make sure to return true or false.", + getComponentName(ctor) || "Component" + ) + : void 0; + } - { - currentlyProcessingQueue = null; + return shouldUpdate; } -} -function callCallback(callback, context) { - invariant( - typeof callback === "function", - "Invalid argument passed as callback. Expected a function. Instead " + - "received: %s", - callback - ); - callback.call(context); -} + if (ctor.prototype && ctor.prototype.isPureReactComponent) { + return ( + !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) + ); + } -function resetHasForceUpdateBeforeProcessing() { - hasForceUpdate = false; + return true; } -function checkHasForceUpdateAfterProcessing() { - return hasForceUpdate; -} +function checkClassInstance(workInProgress, ctor, newProps) { + var instance = workInProgress.stateNode; + { + var name = getComponentName(ctor) || "Component"; + var renderPresent = instance.render; -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; + if (!renderPresent) { + if (ctor.prototype && typeof ctor.prototype.render === "function") { + warningWithoutStack$1( + false, + "%s(...): No `render` method found on the returned component " + + "instance: did you accidentally return an object from the constructor?", + name + ); + } else { + warningWithoutStack$1( + false, + "%s(...): No `render` method found on the returned component " + + "instance: you may have forgotten to define `render`.", + name + ); + } } - // Clear the list of captured updates. - finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null; - } - // Commit the effects - commitUpdateEffects(finishedQueue.firstEffect, instance); - finishedQueue.firstEffect = finishedQueue.lastEffect = null; - - commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); - finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; -} + var noGetInitialStateOnES6 = + !instance.getInitialState || + instance.getInitialState.isReactClassApproved || + instance.state; + !noGetInitialStateOnES6 + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + false, + "propTypes was defined as an instance property on %s. Use a static " + + "property to define propTypes instead.", + name + ) + : void 0; + var noInstanceContextType = !instance.contextType; + !noInstanceContextType + ? warningWithoutStack$1( + false, + "contextType was defined as an instance property on %s. Use a static " + + "property to define contextType instead.", + name + ) + : void 0; + var noInstanceContextTypes = !instance.contextTypes; + !noInstanceContextTypes + ? warningWithoutStack$1( + false, + "contextTypes was defined as an instance property on %s. Use a static " + + "property to define contextTypes instead.", + name + ) + : void 0; -function commitUpdateEffects(effect, instance) { - while (effect !== null) { - var _callback3 = effect.callback; - if (_callback3 !== null) { - effect.callback = null; - callCallback(_callback3, instance); + if ( + ctor.contextType && + ctor.contextTypes && + !didWarnAboutContextTypeAndContextTypes.has(ctor) + ) { + didWarnAboutContextTypeAndContextTypes.add(ctor); + warningWithoutStack$1( + false, + "%s declares both contextTypes and contextType static properties. " + + "The legacy contextTypes property will be ignored.", + name + ); } - effect = effect.nextEffect; - } -} - -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: getStackByFiberInDevAndProd(source) - }; -} - -/** - * 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 warning = warningWithoutStack$1; -{ - warning = function(condition, format) { - if (condition) { - return; + var noComponentShouldUpdate = + typeof instance.componentShouldUpdate !== "function"; + !noComponentShouldUpdate + ? warningWithoutStack$1( + 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 ( + ctor.prototype && + ctor.prototype.isPureReactComponent && + typeof instance.shouldComponentUpdate !== "undefined" + ) { + warningWithoutStack$1( + 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(ctor) || "A pure component" + ); } - var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; - var stack = ReactDebugCurrentFrame.getStackAddendum(); - // eslint-disable-next-line react-internal/warning-and-invariant-args + var noComponentDidUnmount = + typeof instance.componentDidUnmount !== "function"; + !noComponentDidUnmount + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + false, + "%s has a method called " + + "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", + name + ) + : void 0; + var noUnsafeComponentWillRecieveProps = + typeof instance.UNSAFE_componentWillRecieveProps !== "function"; + !noUnsafeComponentWillRecieveProps + ? warningWithoutStack$1( + false, + "%s has a method called " + + "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?", + name + ) + : void 0; + var hasMutatedProps = instance.props !== newProps; + !(instance.props === undefined || !hasMutatedProps) + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + 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; - for ( - var _len = arguments.length, - args = Array(_len > 2 ? _len - 2 : 0), - _key = 2; - _key < _len; - _key++ + if ( + typeof instance.getSnapshotBeforeUpdate === "function" && + typeof instance.componentDidUpdate !== "function" && + !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor) ) { - args[_key - 2] = arguments[_key]; + didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor); + warningWithoutStack$1( + false, + "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " + + "This component defines getSnapshotBeforeUpdate() only.", + getComponentName(ctor) + ); } - warningWithoutStack$1.apply( - undefined, - [false, format + "%s"].concat(args, [stack]) - ); - }; -} - -var warning$1 = warning; - -var valueCursor = createCursor(null); - -var rendererSigil = void 0; -{ - // Use this to detect multiple renderers using the same context - rendererSigil = {}; -} - -var currentlyRenderingFiber = null; -var lastContextDependency = null; -var lastContextWithAllBitsObserved = null; - -function resetContextDependences() { - // This is called right before React yields execution, to ensure `readContext` - // cannot be called outside the render phase. - currentlyRenderingFiber = null; - lastContextDependency = null; - lastContextWithAllBitsObserved = null; -} - -function pushProvider(providerFiber, nextValue) { - var context = providerFiber.type._context; - - if (isPrimaryRenderer) { - push(valueCursor, context._currentValue, providerFiber); - - context._currentValue = nextValue; - { - !( - context._currentRenderer === undefined || - context._currentRenderer === null || - context._currentRenderer === rendererSigil - ) - ? warningWithoutStack$1( - false, - "Detected multiple renderers concurrently rendering the " + - "same context provider. This is currently unsupported." - ) - : void 0; - context._currentRenderer = rendererSigil; + var noInstanceGetDerivedStateFromProps = + typeof instance.getDerivedStateFromProps !== "function"; + !noInstanceGetDerivedStateFromProps + ? warningWithoutStack$1( + 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.getDerivedStateFromError !== "function"; + !noInstanceGetDerivedStateFromCatch + ? warningWithoutStack$1( + false, + "%s: getDerivedStateFromError() is defined as an instance method " + + "and will be ignored. Instead, declare it as a static method.", + name + ) + : void 0; + var noStaticGetSnapshotBeforeUpdate = + typeof ctor.getSnapshotBeforeUpdate !== "function"; + !noStaticGetSnapshotBeforeUpdate + ? warningWithoutStack$1( + 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$1(_state))) { + warningWithoutStack$1( + false, + "%s.state: must be set to an object or null", + name + ); } - } else { - push(valueCursor, context._currentValue2, providerFiber); - - context._currentValue2 = nextValue; - { - !( - context._currentRenderer2 === undefined || - context._currentRenderer2 === null || - context._currentRenderer2 === rendererSigil - ) + if (typeof instance.getChildContext === "function") { + !(typeof ctor.childContextTypes === "object") ? warningWithoutStack$1( false, - "Detected multiple renderers concurrently rendering the " + - "same context provider. This is currently unsupported." + "%s.getChildContext(): childContextTypes must be defined in order to " + + "use getChildContext().", + name ) : void 0; - context._currentRenderer2 = rendererSigil; } } } -function popProvider(providerFiber) { - var currentValue = valueCursor.current; - - pop(valueCursor, providerFiber); - - var context = providerFiber.type._context; - if (isPrimaryRenderer) { - context._currentValue = currentValue; - } else { - context._currentValue2 = currentValue; +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 calculateChangedBits(context, newValue, oldValue) { - // 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 - return 0; - } else { - var changedBits = - typeof context._calculateChangedBits === "function" - ? context._calculateChangedBits(oldValue, newValue) - : maxSigned31BitInt; - +function constructClassInstance( + workInProgress, + ctor, + props, + renderExpirationTime +) { + var isLegacyContextConsumer = false; + var unmaskedContext = emptyContextObject; + var context = null; + var contextType = ctor.contextType; + if (typeof contextType === "object" && contextType !== null) { { - !((changedBits & maxSigned31BitInt) === changedBits) - ? warning$1( - false, - "calculateChangedBits: Expected the return value to be a " + - "31-bit integer. Instead received: %s", - changedBits - ) - : void 0; + if ( + contextType.$$typeof !== REACT_CONTEXT_TYPE && + !didWarnAboutInvalidateContextType.has(ctor) + ) { + didWarnAboutInvalidateContextType.add(ctor); + warningWithoutStack$1( + false, + "%s defines an invalid contextType. " + + "contextType should point to the Context object returned by React.createContext(). " + + "Did you accidentally pass the Context.Provider instead?", + getComponentName(ctor) || "Component" + ); + } } - return changedBits | 0; + + context = readContext(contextType); + } else { + unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); + var contextTypes = ctor.contextTypes; + isLegacyContextConsumer = + contextTypes !== null && contextTypes !== undefined; + context = isLegacyContextConsumer + ? getMaskedContext(workInProgress, unmaskedContext) + : emptyContextObject; } -} -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; + // Instantiate twice to help detect side-effects. + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + new ctor(props, context); // eslint-disable-line no-new + } } - while (fiber !== null) { - var nextFiber = void 0; - // Visit this fiber. - var dependency = fiber.firstContextDependency; - if (dependency !== null) { - do { - // Check if the context matches. - if ( - dependency.context === context && - (dependency.observedBits & changedBits) !== 0 - ) { - // Match! Schedule an update on this fiber. + var instance = new ctor(props, context); + var state = (workInProgress.memoizedState = + instance.state !== null && instance.state !== undefined + ? instance.state + : null); + adoptClassInstance(workInProgress, instance); - if (fiber.tag === ClassComponent) { - // Schedule a force update on the work-in-progress. - var update = createUpdate(renderExpirationTime); - update.tag = ForceUpdate; - // TODO: Because we don't have a work-in-progress, this will add the - // update to the current fiber, too, which means it will persist even if - // this render is thrown away. Since it's a race condition, not sure it's - // worth fixing. - enqueueUpdate(fiber, update); - } + { + if (typeof ctor.getDerivedStateFromProps === "function" && state === null) { + var componentName = getComponentName(ctor) || "Component"; + if (!didWarnAboutUninitializedState.has(componentName)) { + didWarnAboutUninitializedState.add(componentName); + warningWithoutStack$1( + false, + "`%s` uses `getDerivedStateFromProps` but its initial state is " + + "%s. This is not recommended. Instead, define the initial state by " + + "assigning an object to `this.state` in the constructor of `%s`. " + + "This ensures that `getDerivedStateFromProps` arguments have a consistent shape.", + componentName, + instance.state === null ? "null" : "undefined", + componentName + ); + } + } - if (fiber.expirationTime < renderExpirationTime) { - fiber.expirationTime = renderExpirationTime; - } - var alternate = fiber.alternate; - if ( - alternate !== null && - alternate.expirationTime < renderExpirationTime - ) { - alternate.expirationTime = renderExpirationTime; - } - // Update the child expiration time of all the ancestors, including - // the alternates. - var node = fiber.return; - while (node !== null) { - alternate = node.alternate; - if (node.childExpirationTime < renderExpirationTime) { - node.childExpirationTime = renderExpirationTime; - if ( - alternate !== null && - alternate.childExpirationTime < renderExpirationTime - ) { - alternate.childExpirationTime = renderExpirationTime; - } - } else if ( - alternate !== null && - alternate.childExpirationTime < renderExpirationTime - ) { - alternate.childExpirationTime = renderExpirationTime; - } else { - // Neither alternate was updated, which means the rest of the - // ancestor path already has sufficient priority. - break; - } - node = node.return; - } - } - nextFiber = fiber.child; - dependency = dependency.next; - } while (dependency !== null); - } else if (fiber.tag === ContextProvider) { - // Don't scan deeper if this is a matching provider - nextFiber = fiber.type === workInProgress.type ? null : fiber.child; - } else { - // Traverse down. - nextFiber = fiber.child; - } - - if (nextFiber !== null) { - // Set the return pointer of the child to the work-in-progress fiber. - nextFiber.return = fiber; - } else { - // No child. Traverse to next sibling. - nextFiber = fiber; - while (nextFiber !== null) { - if (nextFiber === workInProgress) { - // We're back to the root of this subtree. Exit. - nextFiber = null; - break; - } - var sibling = nextFiber.sibling; - if (sibling !== null) { - // Set the return pointer of the sibling to the work-in-progress fiber. - sibling.return = nextFiber.return; - nextFiber = sibling; - break; + // 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(ctor) || "Component"; + var newApiName = + typeof ctor.getDerivedStateFromProps === "function" + ? "getDerivedStateFromProps()" + : "getSnapshotBeforeUpdate()"; + if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) { + didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName); + warningWithoutStack$1( + 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 : "" + ); } - // No more siblings. Traverse up. - nextFiber = nextFiber.return; } } - fiber = nextFiber; } -} -function prepareToReadContext(workInProgress, renderExpirationTime) { - currentlyRenderingFiber = workInProgress; - lastContextDependency = null; - lastContextWithAllBitsObserved = null; + // 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 (isLegacyContextConsumer) { + cacheContext(workInProgress, unmaskedContext, context); + } - // Reset the work-in-progress list - workInProgress.firstContextDependency = null; + return instance; } -function readContext(context, observedBits) { - if (lastContextWithAllBitsObserved === context) { - // Nothing to do. We already observe everything in this context. - } else if (observedBits === false || observedBits === 0) { - // Do not observe any updates. - } else { - var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types. - if ( - typeof observedBits !== "number" || - observedBits === maxSigned31BitInt - ) { - // Observe all updates. - lastContextWithAllBitsObserved = context; - resolvedObservedBits = maxSigned31BitInt; - } else { - resolvedObservedBits = observedBits; - } +function callComponentWillMount(workInProgress, instance) { + startPhaseTimer(workInProgress, "componentWillMount"); + var oldState = instance.state; - var contextItem = { - context: context, - observedBits: resolvedObservedBits, - next: null - }; + if (typeof instance.componentWillMount === "function") { + instance.componentWillMount(); + } + if (typeof instance.UNSAFE_componentWillMount === "function") { + instance.UNSAFE_componentWillMount(); + } - if (lastContextDependency === null) { - invariant( - currentlyRenderingFiber !== null, - "Context can only be read while React is " + - "rendering, e.g. inside the render method or getDerivedStateFromProps." + stopPhaseTimer(); + + if (oldState !== instance.state) { + { + warningWithoutStack$1( + false, + "%s.componentWillMount(): Assigning directly to this.state is " + + "deprecated (except inside a component's " + + "constructor). Use setState instead.", + getComponentName(workInProgress.type) || "Component" ); - // This is the first dependency in the list - currentlyRenderingFiber.firstContextDependency = lastContextDependency = contextItem; - } else { - // Append a new context item. - lastContextDependency = lastContextDependency.next = contextItem; } + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); } - return isPrimaryRenderer ? context._currentValue : context._currentValue2; } -var NoEffect$1 = /* */ 0; -var UnmountSnapshot = /* */ 2; -var UnmountMutation = /* */ 4; -var MountMutation = /* */ 8; -var UnmountLayout = /* */ 16; -var MountLayout = /* */ 32; -var MountPassive = /* */ 64; -var UnmountPassive = /* */ 128; +function callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + nextContext +) { + var oldState = instance.state; + startPhaseTimer(workInProgress, "componentWillReceiveProps"); + if (typeof instance.componentWillReceiveProps === "function") { + instance.componentWillReceiveProps(newProps, nextContext); + } + if (typeof instance.UNSAFE_componentWillReceiveProps === "function") { + instance.UNSAFE_componentWillReceiveProps(newProps, nextContext); + } + stopPhaseTimer(); -function areHookInputsEqual(arr1, arr2) { - // Don't bother comparing lengths in prod because these arrays should be - // passed inline. - { - !(arr1.length === arr2.length) - ? warning$1( + if (instance.state !== oldState) { + { + var componentName = getComponentName(workInProgress.type) || "Component"; + if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { + didWarnAboutStateAssignmentForComponent.add(componentName); + warningWithoutStack$1( false, - "Detected a variable number of hook dependencies. The length of the " + - "dependencies array should be constant between renders.\n\n" + - "Previous: %s\n" + - "Incoming: %s", - arr1.join(", "), - arr2.join(", ") - ) - : void 0; - } - for (var i = 0; i < arr1.length; i++) { - // Inlined Object.is polyfill. - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is - var val1 = arr1[i]; - var val2 = arr2[i]; - if ( - (val1 === val2 && (val1 !== 0 || 1 / val1 === 1 / val2)) || - (val1 !== val1 && val2 !== val2) // eslint-disable-line no-self-compare - ) { - continue; + "%s.componentWillReceiveProps(): Assigning directly to " + + "this.state is deprecated (except inside a component's " + + "constructor). Use setState instead.", + componentName + ); + } } - return false; + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); } - return true; } -// These are set right before calling the component. -var renderExpirationTime = NoWork; -// The work-in-progress fiber. I've named it differently to distinguish it from -// the work-in-progress hook. -var currentlyRenderingFiber$1 = null; - -// Hooks are stored as a linked list on the fiber's memoizedState field. The -// current hook list is the list that belongs to the current fiber. The -// work-in-progress hook list is a new list that will be added to the -// work-in-progress fiber. -var firstCurrentHook = null; -var currentHook = null; -var firstWorkInProgressHook = null; -var workInProgressHook = null; +// Invokes the mount life-cycles on a previously never rendered instance. +function mountClassInstance( + workInProgress, + ctor, + newProps, + renderExpirationTime +) { + { + checkClassInstance(workInProgress, ctor, newProps); + } -var remainingExpirationTime = NoWork; -var componentUpdateQueue = null; + var instance = workInProgress.stateNode; + instance.props = newProps; + instance.state = workInProgress.memoizedState; + instance.refs = emptyRefsObject; -// Updates scheduled during render will trigger an immediate re-render at the -// end of the current pass. We can't store these updates on the normal queue, -// because if the work is aborted, they should be discarded. Because this is -// a relatively rare case, we also don't want to add an additional field to -// either the hook or queue object types. So we store them in a lazily create -// map of queue -> render-phase updates, which are discarded once the component -// completes without re-rendering. + var contextType = ctor.contextType; + if (typeof contextType === "object" && contextType !== null) { + instance.context = readContext(contextType); + } else { + var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); + instance.context = getMaskedContext(workInProgress, unmaskedContext); + } -// Whether the work-in-progress hook is a re-rendered hook -var isReRender = false; -// Whether an update was scheduled during the currently executing render pass. -var didScheduleRenderPhaseUpdate = false; -// Lazily created map of render-phase updates -var renderPhaseUpdates = null; -// Counter to prevent infinite loops. -var numberOfReRenders = 0; -var RE_RENDER_LIMIT = 25; + { + if (instance.state === newProps) { + var componentName = getComponentName(ctor) || "Component"; + if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) { + didWarnAboutDirectlyAssigningPropsToState.add(componentName); + warningWithoutStack$1( + false, + "%s: It is not recommended to assign props directly to state " + + "because updates to props won't be reflected in state. " + + "In most cases, it is better to use props directly.", + componentName + ); + } + } -function resolveCurrentlyRenderingFiber() { - invariant( - currentlyRenderingFiber$1 !== null, - "Hooks can only be called inside the body of a function component." - ); - return currentlyRenderingFiber$1; -} + if (workInProgress.mode & StrictMode) { + ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( + workInProgress, + instance + ); -function prepareToUseHooks(current, workInProgress, nextRenderExpirationTime) { - if (!enableHooks) { - return; - } - renderExpirationTime = nextRenderExpirationTime; - currentlyRenderingFiber$1 = workInProgress; - firstCurrentHook = current !== null ? current.memoizedState : null; + ReactStrictModeWarnings.recordLegacyContextWarning( + workInProgress, + instance + ); + } - // The following should have already been reset - // currentHook = null; - // workInProgressHook = null; + if (warnAboutDeprecatedLifecycles) { + ReactStrictModeWarnings.recordDeprecationWarnings( + workInProgress, + instance + ); + } + } - // remainingExpirationTime = NoWork; - // componentUpdateQueue = null; + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + newProps, + instance, + renderExpirationTime + ); + instance.state = workInProgress.memoizedState; + } - // isReRender = false; - // didScheduleRenderPhaseUpdate = false; - // renderPhaseUpdates = null; - // numberOfReRenders = 0; -} + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + ctor, + getDerivedStateFromProps, + newProps + ); + instance.state = workInProgress.memoizedState; + } -function finishHooks(Component, props, children, refOrContext) { - if (!enableHooks) { - return children; + // 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, + newProps, + instance, + renderExpirationTime + ); + instance.state = workInProgress.memoizedState; + } } - // This must be called after every function component to prevent hooks from - // being used in classes. + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; + } +} - while (didScheduleRenderPhaseUpdate) { - // Updates were scheduled during the render phase. They are stored in - // the `renderPhaseUpdates` map. Call the component again, reusing the - // work-in-progress hooks and applying the additional updates on top. Keep - // restarting until no more updates are scheduled. - didScheduleRenderPhaseUpdate = false; - numberOfReRenders += 1; +function resumeMountClassInstance( + workInProgress, + ctor, + newProps, + renderExpirationTime +) { + var instance = workInProgress.stateNode; - // Start over from the beginning of the list - currentHook = null; - workInProgressHook = null; - componentUpdateQueue = null; + var oldProps = workInProgress.memoizedProps; + instance.props = oldProps; - children = Component(props, refOrContext); + var oldContext = instance.context; + var contextType = ctor.contextType; + var nextContext = void 0; + if (typeof contextType === "object" && contextType !== null) { + nextContext = readContext(contextType); + } else { + var nextLegacyUnmaskedContext = getUnmaskedContext( + workInProgress, + ctor, + true + ); + nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext); } - renderPhaseUpdates = null; - numberOfReRenders = 0; - - var renderedWork = currentlyRenderingFiber$1; - - renderedWork.memoizedState = firstWorkInProgressHook; - renderedWork.expirationTime = remainingExpirationTime; - renderedWork.updateQueue = componentUpdateQueue; - var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null; + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + var hasNewLifecycles = + typeof getDerivedStateFromProps === "function" || + typeof instance.getSnapshotBeforeUpdate === "function"; - renderExpirationTime = NoWork; - currentlyRenderingFiber$1 = null; + // 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. - firstCurrentHook = null; - currentHook = null; - firstWorkInProgressHook = null; - workInProgressHook = null; + // 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 !== nextContext) { + callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + nextContext + ); + } + } - remainingExpirationTime = NoWork; - componentUpdateQueue = null; + resetHasForceUpdateBeforeProcessing(); - // Always set during createWorkInProgress - // isReRender = 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; + } + return false; + } - // These were reset above - // didScheduleRenderPhaseUpdate = false; - // renderPhaseUpdates = null; - // numberOfReRenders = 0; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + ctor, + getDerivedStateFromProps, + newProps + ); + newState = workInProgress.memoizedState; + } - invariant( - !didRenderTooFewHooks, - "Rendered fewer hooks than expected. This may be caused by an accidental " + - "early return statement." - ); + var shouldUpdate = + checkHasForceUpdateAfterProcessing() || + checkShouldComponentUpdate( + workInProgress, + ctor, + oldProps, + newProps, + oldState, + newState, + nextContext + ); - return children; -} + 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 resetHooks() { - if (!enableHooks) { - return; + // 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; } - // This is called instead of `finishHooks` if the component throws. It's also - // called inside mountIndeterminateComponent if we determine the component - // is a module-style component. - renderExpirationTime = NoWork; - currentlyRenderingFiber$1 = null; + // Update the existing instance's state, props, and context pointers even + // if shouldComponentUpdate returns false. + instance.props = newProps; + instance.state = newState; + instance.context = nextContext; - firstCurrentHook = null; - currentHook = null; - firstWorkInProgressHook = null; - workInProgressHook = null; - - remainingExpirationTime = NoWork; - componentUpdateQueue = null; + return shouldUpdate; +} - // Always set during createWorkInProgress - // isReRender = false; +// Invokes the update life-cycles and returns false if it shouldn't rerender. +function updateClassInstance( + current, + workInProgress, + ctor, + newProps, + renderExpirationTime +) { + var instance = workInProgress.stateNode; - didScheduleRenderPhaseUpdate = false; - renderPhaseUpdates = null; - numberOfReRenders = 0; -} + var oldProps = workInProgress.memoizedProps; + instance.props = + workInProgress.type === workInProgress.elementType + ? oldProps + : resolveDefaultProps(workInProgress.type, oldProps); -function createHook() { - return { - memoizedState: null, + var oldContext = instance.context; + var contextType = ctor.contextType; + var nextContext = void 0; + if (typeof contextType === "object" && contextType !== null) { + nextContext = readContext(contextType); + } else { + var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true); + nextContext = getMaskedContext(workInProgress, nextUnmaskedContext); + } - baseState: null, - queue: null, - baseUpdate: null, + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + var hasNewLifecycles = + typeof getDerivedStateFromProps === "function" || + typeof instance.getSnapshotBeforeUpdate === "function"; - next: null - }; -} + // 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. -function cloneHook(hook) { - return { - memoizedState: hook.memoizedState, + // 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 !== nextContext) { + callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + nextContext + ); + } + } - baseState: hook.baseState, - queue: hook.queue, - baseUpdate: hook.baseUpdate, + resetHasForceUpdateBeforeProcessing(); - next: null - }; -} + 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 createWorkInProgressHook() { - if (workInProgressHook === null) { - // This is the first hook in the list - if (firstWorkInProgressHook === null) { - isReRender = false; - currentHook = firstCurrentHook; - if (currentHook === null) { - // This is a newly mounted hook - workInProgressHook = createHook(); - } else { - // Clone the current hook. - workInProgressHook = cloneHook(currentHook); + 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; } - firstWorkInProgressHook = workInProgressHook; - } else { - // There's already a work-in-progress. Reuse it. - isReRender = true; - currentHook = firstCurrentHook; - workInProgressHook = firstWorkInProgressHook; } - } else { - if (workInProgressHook.next === null) { - isReRender = false; - var hook = void 0; - if (currentHook === null) { - // This is a newly mounted hook - hook = createHook(); - } else { - currentHook = currentHook.next; - if (currentHook === null) { - // This is a newly mounted hook - hook = createHook(); - } else { - // Clone the current hook. - hook = cloneHook(currentHook); - } + if (typeof instance.getSnapshotBeforeUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + workInProgress.effectTag |= Snapshot; } - // Append to the end of the list - workInProgressHook = workInProgressHook.next = hook; - } else { - // There's already a work-in-progress. Reuse it. - isReRender = true; - workInProgressHook = workInProgressHook.next; - currentHook = currentHook !== null ? currentHook.next : null; } + return false; } - return workInProgressHook; -} - -function createFunctionComponentUpdateQueue() { - return { - lastEffect: null - }; -} - -function basicStateReducer(state, action) { - return typeof action === "function" ? action(state) : action; -} - -function useContext(context, observedBits) { - // Ensure we're in a function component (class components support only the - // .unstable_read() form) - resolveCurrentlyRenderingFiber(); - return readContext(context, observedBits); -} -function useState(initialState) { - return useReducer( - basicStateReducer, - // useReducer has a special case to support lazy useState initializers - initialState - ); -} + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + ctor, + getDerivedStateFromProps, + newProps + ); + newState = workInProgress.memoizedState; + } -function useReducer(reducer, initialState, initialAction) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); - var queue = workInProgressHook.queue; - if (queue !== null) { - // Already have a queue, so this is an update. - if (isReRender) { - // This is a re-render. Apply the new render phase updates to the previous - var _dispatch2 = queue.dispatch; - if (renderPhaseUpdates !== null) { - // Render phase updates are stored in a map of queue -> linked list - var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); - if (firstRenderPhaseUpdate !== undefined) { - renderPhaseUpdates.delete(queue); - var newState = workInProgressHook.memoizedState; - var update = firstRenderPhaseUpdate; - do { - // Process this render phase update. We don't have to check the - // priority because it will always be the same as the current - // render's. - var _action = update.action; - newState = reducer(newState, _action); - update = update.next; - } while (update !== null); - - workInProgressHook.memoizedState = newState; - - // Don't persist the state accumlated from the render phase updates to - // the base state unless the queue is empty. - // TODO: Not sure if this is the desired semantics, but it's what we - // do for gDSFP. I can't remember why. - if (workInProgressHook.baseUpdate === queue.last) { - workInProgressHook.baseState = newState; - } + var shouldUpdate = + checkHasForceUpdateAfterProcessing() || + checkShouldComponentUpdate( + workInProgress, + ctor, + oldProps, + newProps, + oldState, + newState, + nextContext + ); - return [newState, _dispatch2]; - } + 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, nextContext); } - return [workInProgressHook.memoizedState, _dispatch2]; - } - - // The last update in the entire queue - var _last = queue.last; - // The last update that is part of the base state. - var _baseUpdate = workInProgressHook.baseUpdate; - - // Find the first unprocessed update. - var first = void 0; - if (_baseUpdate !== null) { - if (_last !== null) { - // For the first update, the queue is a circular linked list where - // `queue.last.next = queue.first`. Once the first update commits, and - // the `baseUpdate` is no longer empty, we can unravel the list. - _last.next = null; - } - first = _baseUpdate.next; - } else { - first = _last !== null ? _last.next : null; - } - if (first !== null) { - var _newState = workInProgressHook.baseState; - var newBaseState = null; - var newBaseUpdate = null; - var prevUpdate = _baseUpdate; - var _update = first; - var didSkip = false; - do { - var updateExpirationTime = _update.expirationTime; - if (updateExpirationTime < renderExpirationTime) { - // Priority is insufficient. Skip this update. If this is the first - // skipped update, the previous update/state is the new base - // update/state. - if (!didSkip) { - didSkip = true; - newBaseUpdate = prevUpdate; - newBaseState = _newState; - } - // Update the remaining priority in the queue. - if (updateExpirationTime > remainingExpirationTime) { - remainingExpirationTime = updateExpirationTime; - } - } else { - // Process this update. - var _action2 = _update.action; - _newState = reducer(_newState, _action2); - } - prevUpdate = _update; - _update = _update.next; - } while (_update !== null && _update !== first); - - if (!didSkip) { - newBaseUpdate = prevUpdate; - newBaseState = _newState; + if (typeof instance.UNSAFE_componentWillUpdate === "function") { + instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext); } - - workInProgressHook.memoizedState = _newState; - workInProgressHook.baseUpdate = newBaseUpdate; - workInProgressHook.baseState = newBaseState; + stopPhaseTimer(); } - - var _dispatch = queue.dispatch; - return [workInProgressHook.memoizedState, _dispatch]; - } - - // There's no existing queue, so this is the initial render. - if (reducer === basicStateReducer) { - // Special case for `useState`. - if (typeof initialState === "function") { - initialState = initialState(); + if (typeof instance.componentDidUpdate === "function") { + workInProgress.effectTag |= Update; + } + if (typeof instance.getSnapshotBeforeUpdate === "function") { + workInProgress.effectTag |= Snapshot; } - } else if (initialAction !== undefined && initialAction !== null) { - initialState = reducer(initialState, initialAction); - } - workInProgressHook.memoizedState = workInProgressHook.baseState = initialState; - queue = workInProgressHook.queue = { - last: null, - dispatch: null - }; - var dispatch = (queue.dispatch = dispatchAction.bind( - null, - currentlyRenderingFiber$1, - queue - )); - return [workInProgressHook.memoizedState, dispatch]; -} - -function pushEffect(tag, create, destroy, inputs) { - var effect = { - tag: tag, - create: create, - destroy: destroy, - inputs: inputs, - // Circular - next: null - }; - if (componentUpdateQueue === null) { - componentUpdateQueue = createFunctionComponentUpdateQueue(); - componentUpdateQueue.lastEffect = effect.next = effect; } else { - var _lastEffect = componentUpdateQueue.lastEffect; - if (_lastEffect === null) { - componentUpdateQueue.lastEffect = effect.next = effect; - } else { - var firstEffect = _lastEffect.next; - _lastEffect.next = effect; - effect.next = firstEffect; - componentUpdateQueue.lastEffect = effect; + // 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 effect; -} - -function useRef(initialValue) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); - var ref = void 0; - - if (workInProgressHook.memoizedState === null) { - ref = { current: initialValue }; - { - Object.seal(ref); + if (typeof instance.getSnapshotBeforeUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + workInProgress.effectTag |= Snapshot; + } } - workInProgressHook.memoizedState = ref; - } else { - ref = workInProgressHook.memoizedState; + + // 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; } - return ref; -} -function useLayoutEffect(create, inputs) { - useEffectImpl(Update, UnmountMutation | MountLayout, create, inputs); + // Update the existing instance's state, props, and context pointers even + // if shouldComponentUpdate returns false. + instance.props = newProps; + instance.state = newState; + instance.context = nextContext; + + return shouldUpdate; } -function useEffect(create, inputs) { - useEffectImpl( - Update | Passive, - UnmountPassive | MountPassive, - create, - inputs - ); -} +var didWarnAboutMaps = void 0; +var didWarnAboutGenerators = void 0; +var didWarnAboutStringRefInStrictMode = void 0; +var ownerHasKeyUseWarning = void 0; +var ownerHasFunctionTypeWarning = void 0; +var warnForMissingKey = function(child) {}; -function useEffectImpl(fiberEffectTag, hookEffectTag, create, inputs) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); +{ + didWarnAboutMaps = false; + didWarnAboutGenerators = false; + didWarnAboutStringRefInStrictMode = {}; - var nextInputs = inputs !== undefined && inputs !== null ? inputs : [create]; - var destroy = null; - if (currentHook !== null) { - var prevEffect = currentHook.memoizedState; - destroy = prevEffect.destroy; - if (areHookInputsEqual(nextInputs, prevEffect.inputs)) { - pushEffect(NoEffect$1, create, destroy, nextInputs); + /** + * 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; - currentlyRenderingFiber$1.effectTag |= fiberEffectTag; - workInProgressHook.memoizedState = pushEffect( - hookEffectTag, - create, - destroy, - nextInputs - ); + var currentComponentErrorInfo = + "Each child in a list should have a unique " + + '"key" prop. See https://fb.me/react-warning-keys for ' + + "more information." + + getCurrentFiberStackInDev(); + if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { + return; + } + ownerHasKeyUseWarning[currentComponentErrorInfo] = true; + + warning$1( + false, + "Each child in a list should have a unique " + + '"key" prop. See https://fb.me/react-warning-keys for ' + + "more information." + ); + }; } -function useImperativeMethods(ref, create, inputs) { - // TODO: If inputs are provided, should we skip comparing the ref itself? - var nextInputs = - inputs !== null && inputs !== undefined - ? inputs.concat([ref]) - : [ref, create]; +var isArray = Array.isArray; - // TODO: I've implemented this on top of useEffect because it's almost the - // same thing, and it would require an equal amount of code. It doesn't seem - // like a common enough use case to justify the additional size. - useLayoutEffect(function() { - if (typeof ref === "function") { - var refCallback = ref; - var _inst = create(); - refCallback(_inst); - return function() { - return refCallback(null); - }; - } else if (ref !== null && ref !== undefined) { - var refObject = ref; - var _inst2 = create(); - refObject.current = _inst2; - return function() { - refObject.current = null; +function coerceRef(returnFiber, current$$1, element) { + var mixedRef = element.ref; + if ( + mixedRef !== null && + typeof mixedRef !== "function" && + typeof mixedRef !== "object" + ) { + { + if (returnFiber.mode & StrictMode) { + var componentName = getComponentName(returnFiber.type) || "Component"; + if (!didWarnAboutStringRefInStrictMode[componentName]) { + warningWithoutStack$1( + 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, + getStackByFiberInDevAndProd(returnFiber) + ); + didWarnAboutStringRefInStrictMode[componentName] = true; + } + } + } + + if (element._owner) { + var owner = element._owner; + var inst = void 0; + if (owner) { + var ownerFiber = owner; + invariant( + ownerFiber.tag === ClassComponent, + "Function components cannot have refs. " + + "Did you mean to use React.forwardRef()?" + ); + 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$$1 !== null && + current$$1.ref !== null && + typeof current$$1.ref === "function" && + current$$1.ref._stringRef === stringRef + ) { + return current$$1.ref; + } + var ref = function(value) { + var refs = inst.refs; + if (refs === emptyRefsObject) { + // This is a lazy pooled frozen object, so we need to initialize. + 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, a string, an object returned by React.createRef(), or null." + ); + 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 function component\n" + + "2. You may be adding a ref to a component that was not created inside a component's render method\n" + + "3. You have multiple copies of React loaded\n" + + "See https://fb.me/react-refs-must-have-owner for more information.", + mixedRef + ); } - }, nextInputs); + } + return mixedRef; } -function useCallback(callback, inputs) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); - - var nextInputs = - inputs !== undefined && inputs !== null ? inputs : [callback]; - - var prevState = workInProgressHook.memoizedState; - if (prevState !== null) { - var prevInputs = prevState[1]; - if (areHookInputsEqual(nextInputs, prevInputs)) { - return prevState[0]; +function throwOnInvalidObjectType(returnFiber, newChild) { + if (returnFiber.type !== "textarea") { + var addendum = ""; + { + addendum = + " If you meant to render a collection of children, use an array " + + "instead." + + getCurrentFiberStackInDev(); } + 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 + ); } - workInProgressHook.memoizedState = [callback, nextInputs]; - return callback; } -function useMemo(nextCreate, inputs) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); - - var nextInputs = - inputs !== undefined && inputs !== null ? inputs : [nextCreate]; +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." + + getCurrentFiberStackInDev(); - var prevState = workInProgressHook.memoizedState; - if (prevState !== null) { - var prevInputs = prevState[1]; - if (areHookInputsEqual(nextInputs, prevInputs)) { - return prevState[0]; - } + if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) { + return; } + ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; - var nextValue = nextCreate(); - workInProgressHook.memoizedState = [nextValue, nextInputs]; - return nextValue; -} - -function dispatchAction(fiber, queue, action) { - invariant( - numberOfReRenders < RE_RENDER_LIMIT, - "Too many re-renders. React limits the number of renders to prevent " + - "an infinite loop." + warning$1( + 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." ); +} - var alternate = fiber.alternate; - if ( - fiber === currentlyRenderingFiber$1 || - (alternate !== null && alternate === currentlyRenderingFiber$1) - ) { - // This is a render phase update. Stash it in a lazily-created map of - // queue -> linked list of updates. After this render pass, we'll restart - // and apply the stashed updates on top of the work-in-progress hook. - didScheduleRenderPhaseUpdate = true; - var update = { - expirationTime: renderExpirationTime, - action: action, - next: null - }; - if (renderPhaseUpdates === null) { - renderPhaseUpdates = new Map(); - } - var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); - if (firstRenderPhaseUpdate === undefined) { - renderPhaseUpdates.set(queue, update); - } else { - // Append the update to the end of the list. - var lastRenderPhaseUpdate = firstRenderPhaseUpdate; - while (lastRenderPhaseUpdate.next !== null) { - lastRenderPhaseUpdate = lastRenderPhaseUpdate.next; - } - lastRenderPhaseUpdate.next = update; +// 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; } - } else { - var currentTime = requestCurrentTime(); - var _expirationTime = computeExpirationForFiber(currentTime, fiber); - var _update2 = { - expirationTime: _expirationTime, - action: action, - next: null - }; - flushPassiveEffects(); - // Append the update to the end of the list. - var _last2 = queue.last; - if (_last2 === null) { - // This is the first update. Create a circular list. - _update2.next = _update2; + // 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 { - var first = _last2.next; - if (first !== null) { - // Still circular. - _update2.next = first; - } - _last2.next = _update2; + returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; } - queue.last = _update2; - scheduleWork(fiber, _expirationTime); + childToDelete.nextEffect = null; + childToDelete.effectTag = Deletion; } -} - -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; -var profilerStartTime = -1; - -function getCommitTime() { - return commitTime; -} - -function recordCommitTime() { - if (!enableProfilerTimer) { - return; - } - commitTime = now$$1(); -} + function deleteRemainingChildren(returnFiber, currentFirstChild) { + if (!shouldTrackSideEffects) { + // Noop. + return null; + } -function startProfilerTimer(fiber) { - if (!enableProfilerTimer) { - 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; + } + return null; } - profilerStartTime = now$$1(); - - if (fiber.actualStartTime < 0) { - fiber.actualStartTime = now$$1(); - } -} + 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(); -function stopProfilerTimerIfRunning(fiber) { - if (!enableProfilerTimer) { - return; + var existingChild = currentFirstChild; + while (existingChild !== null) { + if (existingChild.key !== null) { + existingChildren.set(existingChild.key, existingChild); + } else { + existingChildren.set(existingChild.index, existingChild); + } + existingChild = existingChild.sibling; + } + return existingChildren; } - profilerStartTime = -1; -} -function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) { - if (!enableProfilerTimer) { - return; + 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 (profilerStartTime >= 0) { - var elapsedTime = now$$1() - profilerStartTime; - fiber.actualDuration += elapsedTime; - if (overrideBaseTime) { - fiber.selfBaseDuration = elapsedTime; + function placeChild(newFiber, lastPlacedIndex, newIndex) { + newFiber.index = newIndex; + if (!shouldTrackSideEffects) { + // Noop. + return lastPlacedIndex; + } + var current$$1 = newFiber.alternate; + if (current$$1 !== null) { + var oldIndex = current$$1.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; } - profilerStartTime = -1; - } -} - -/*eslint-disable no-self-compare */ - -var hasOwnProperty = Object.prototype.hasOwnProperty; - -/** - * 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; } -} -/** - * 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; + 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; } - if ( - typeof objA !== "object" || - objA === null || - typeof objB !== "object" || - objB === null + function updateTextNode( + returnFiber, + current$$1, + textContent, + expirationTime ) { - return false; + if (current$$1 === null || current$$1.tag !== HostText) { + // Insert + var created = createFiberFromText( + textContent, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber(current$$1, textContent, expirationTime); + existing.return = returnFiber; + return existing; + } } - var keysA = Object.keys(objA); - var keysB = Object.keys(objB); - - if (keysA.length !== keysB.length) { - return false; + function updateElement(returnFiber, current$$1, element, expirationTime) { + if (current$$1 !== null && current$$1.elementType === element.type) { + // Move based on index + var existing = useFiber(current$$1, element.props, expirationTime); + existing.ref = coerceRef(returnFiber, current$$1, 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$$1, element); + created.return = returnFiber; + return created; + } } - // Test for A's keys different from B. - for (var i = 0; i < keysA.length; i++) { + function updatePortal(returnFiber, current$$1, portal, expirationTime) { if ( - !hasOwnProperty.call(objB, keysA[i]) || - !is(objA[keysA[i]], objB[keysA[i]]) + current$$1 === null || + current$$1.tag !== HostPortal || + current$$1.stateNode.containerInfo !== portal.containerInfo || + current$$1.stateNode.implementation !== portal.implementation ) { - return false; + // Insert + var created = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber( + current$$1, + portal.children || [], + expirationTime + ); + existing.return = returnFiber; + return existing; } } - return true; -} - -function resolveDefaultProps(Component, baseProps) { - if (Component && Component.defaultProps) { - // Resolve default props. Taken from ReactElement - var props = Object.assign({}, baseProps); - var defaultProps = Component.defaultProps; - for (var propName in defaultProps) { - if (props[propName] === undefined) { - props[propName] = defaultProps[propName]; - } + function updateFragment( + returnFiber, + current$$1, + fragment, + expirationTime, + key + ) { + if (current$$1 === null || current$$1.tag !== Fragment) { + // Insert + var created = createFiberFromFragment( + fragment, + returnFiber.mode, + expirationTime, + key + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber(current$$1, fragment, expirationTime); + existing.return = returnFiber; + return existing; } - return props; } - return baseProps; -} -function readLazyComponentType(lazyComponent) { - var status = lazyComponent._status; - var result = lazyComponent._result; - switch (status) { - case Resolved: { - var Component = result; - return Component; - } - case Rejected: { - var error = result; - throw error; - } - case Pending: { - var thenable = result; - throw thenable; - } - default: { - lazyComponent._status = Pending; - var ctor = lazyComponent._ctor; - var _thenable = ctor(); - _thenable.then( - function(moduleObject) { - if (lazyComponent._status === Pending) { - var defaultExport = moduleObject.default; - { - if (defaultExport === undefined) { - warning$1( - false, - "lazy: Expected the result of a dynamic import() call. " + - "Instead received: %s\n\nYour code should look like: \n " + - "const MyComponent = lazy(() => import('./MyComponent'))", - moduleObject - ); - } - } - lazyComponent._status = Resolved; - lazyComponent._result = defaultExport; - } - }, - function(error) { - if (lazyComponent._status === Pending) { - lazyComponent._status = Rejected; - lazyComponent._result = error; - } - } + 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 ); - lazyComponent._result = _thenable; - throw _thenable; + created.return = returnFiber; + return created; } - } -} - -var ReactCurrentOwner$4 = ReactSharedInternals.ReactCurrentOwner; -function readContext$1(contextType) { - var dispatcher = ReactCurrentOwner$4.currentDispatcher; - return dispatcher.readContext(contextType); -} + 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; + } + } -var fakeInternalInstance = {}; -var isArray$1 = Array.isArray; + if (isArray(newChild) || getIteratorFn(newChild)) { + var _created3 = createFiberFromFragment( + newChild, + returnFiber.mode, + expirationTime, + null + ); + _created3.return = returnFiber; + return _created3; + } -// React.Component uses a shared frozen object by default. -// We'll use it to determine whether we need to initialize legacy refs. -var emptyRefsObject = new React.Component().refs; + throwOnInvalidObjectType(returnFiber, newChild); + } -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 didWarnAboutDirectlyAssigningPropsToState = void 0; -var didWarnAboutContextTypeAndContextTypes = void 0; -var didWarnAboutInvalidateContextType = void 0; + { + if (typeof newChild === "function") { + warnOnFunctionType(); + } + } -{ - didWarnAboutStateAssignmentForComponent = new Set(); - didWarnAboutUninitializedState = new Set(); - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); - didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); - didWarnAboutDirectlyAssigningPropsToState = new Set(); - didWarnAboutUndefinedDerivedState = new Set(); - didWarnAboutContextTypeAndContextTypes = new Set(); - didWarnAboutInvalidateContextType = new Set(); + return null; + } - var didWarnOnInvalidCallback = new Set(); + function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { + // Update the fiber if the keys match, otherwise return null. - warnOnInvalidCallback = function(callback, callerName) { - if (callback === null || typeof callback === "function") { - return; - } - var key = callerName + "_" + callback; - if (!didWarnOnInvalidCallback.has(key)) { - didWarnOnInvalidCallback.add(key); - warningWithoutStack$1( - false, - "%s(...): Expected the last optional `callback` argument to be a " + - "function. Instead received: %s.", - callerName, - callback - ); - } - }; + var key = oldFiber !== null ? oldFiber.key : null; - warnOnUndefinedDerivedState = function(type, partialState) { - if (partialState === undefined) { - var componentName = getComponentName(type) || "Component"; - if (!didWarnAboutUndefinedDerivedState.has(componentName)) { - didWarnAboutUndefinedDerivedState.add(componentName); - warningWithoutStack$1( - false, - "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + - "You have returned undefined.", - componentName - ); + 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; } - } - }; - - // 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)." + return updateTextNode( + returnFiber, + oldFiber, + "" + newChild, + expirationTime ); } - }); - Object.freeze(fakeInternalInstance); -} - -function applyDerivedStateFromProps( - workInProgress, - ctor, - 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); + 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; + } + } + } - { - warnOnUndefinedDerivedState(ctor, partialState); - } - // Merge the partial state and the previous state. - var memoizedState = - partialState === null || partialState === undefined - ? prevState - : Object.assign({}, prevState, partialState); - workInProgress.memoizedState = memoizedState; + if (isArray(newChild) || getIteratorFn(newChild)) { + if (key !== null) { + return null; + } - // Once the update queue is empty, persist the derived state onto the - // base state. - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null && workInProgress.expirationTime === NoWork) { - updateQueue.baseState = memoizedState; - } -} + return updateFragment( + returnFiber, + oldFiber, + newChild, + expirationTime, + null + ); + } -var classComponentUpdater = { - isMounted: isMounted, - enqueueSetState: function(inst, payload, callback) { - var fiber = get$1(inst); - var currentTime = requestCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); + throwOnInvalidObjectType(returnFiber, newChild); + } - var update = createUpdate(expirationTime); - update.payload = payload; - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "setState"); + { + if (typeof newChild === "function") { + warnOnFunctionType(); } - update.callback = callback; } - flushPassiveEffects(); - enqueueUpdate(fiber, update); - scheduleWork(fiber, expirationTime); - }, - enqueueReplaceState: function(inst, payload, callback) { - var fiber = get$1(inst); - var currentTime = requestCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); + return null; + } - var update = createUpdate(expirationTime); - update.tag = ReplaceState; - update.payload = payload; + 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 + ); + } - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "replaceState"); + 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 + ); + } } - update.callback = callback; - } - flushPassiveEffects(); - enqueueUpdate(fiber, update); - scheduleWork(fiber, expirationTime); - }, - enqueueForceUpdate: function(inst, callback) { - var fiber = get$1(inst); - var currentTime = requestCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); + if (isArray(newChild) || getIteratorFn(newChild)) { + var _matchedFiber3 = existingChildren.get(newIdx) || null; + return updateFragment( + returnFiber, + _matchedFiber3, + newChild, + expirationTime, + null + ); + } - var update = createUpdate(expirationTime); - update.tag = ForceUpdate; + throwOnInvalidObjectType(returnFiber, newChild); + } - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "forceUpdate"); + { + if (typeof newChild === "function") { + warnOnFunctionType(); } - update.callback = callback; } - flushPassiveEffects(); - enqueueUpdate(fiber, update); - scheduleWork(fiber, expirationTime); + return null; } -}; - -function checkShouldComponentUpdate( - workInProgress, - ctor, - oldProps, - newProps, - oldState, - newState, - nextContext -) { - var instance = workInProgress.stateNode; - if (typeof instance.shouldComponentUpdate === "function") { - startPhaseTimer(workInProgress, "shouldComponentUpdate"); - var shouldUpdate = instance.shouldComponentUpdate( - newProps, - newState, - nextContext - ); - stopPhaseTimer(); + /** + * Warns if there is a duplicate or missing key + */ + function warnOnInvalidKey(child, knownKeys) { { - !(shouldUpdate !== undefined) - ? warningWithoutStack$1( + 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$1( false, - "%s.shouldComponentUpdate(): Returned undefined instead of a " + - "boolean value. Make sure to return true or false.", - getComponentName(ctor) || "Component" - ) - : void 0; - } - - return shouldUpdate; - } - - if (ctor.prototype && ctor.prototype.isPureReactComponent) { - return ( - !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) - ); + "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.", + key + ); + break; + default: + break; + } + } + return knownKeys; } - return true; -} + 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 checkClassInstance(workInProgress, ctor, newProps) { - var instance = workInProgress.stateNode; - { - var name = getComponentName(ctor) || "Component"; - var renderPresent = instance.render; + // 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. - if (!renderPresent) { - if (ctor.prototype && typeof ctor.prototype.render === "function") { - warningWithoutStack$1( - false, - "%s(...): No `render` method found on the returned component " + - "instance: did you accidentally return an object from the constructor?", - name - ); + // In this first iteration, we'll just live with hitting the bad case + // (adding everything to a Map) in for every insert/move. + + // If you change this code, also update reconcileChildrenIterator() which + // uses the same algorithm. + + { + // First, validate keys. + var knownKeys = null; + for (var i = 0; i < newChildren.length; i++) { + var child = newChildren[i]; + knownKeys = warnOnInvalidKey(child, knownKeys); + } + } + + 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 { - warningWithoutStack$1( - false, - "%s(...): No `render` method found on the returned component " + - "instance: you may have forgotten to define `render`.", - name + 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; + } + + if (newIdx === newChildren.length) { + // We've reached the end of the new children. We can delete the rest. + deleteRemainingChildren(returnFiber, oldFiber); + return resultingFirstChild; + } + + if (oldFiber === null) { + // If we don't have any more existing children we can choose a fast path + // since the rest will all be insertions. + for (; newIdx < newChildren.length; newIdx++) { + var _newFiber = createChild( + returnFiber, + newChildren[newIdx], + 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; } - var noGetInitialStateOnES6 = - !instance.getInitialState || - instance.getInitialState.isReactClassApproved || - instance.state; - !noGetInitialStateOnES6 - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - false, - "propTypes was defined as an instance property on %s. Use a static " + - "property to define propTypes instead.", - name - ) - : void 0; - var noInstanceContextType = !instance.contextType; - !noInstanceContextType - ? warningWithoutStack$1( - false, - "contextType was defined as an instance property on %s. Use a static " + - "property to define contextType instead.", - name - ) - : void 0; - var noInstanceContextTypes = !instance.contextTypes; - !noInstanceContextTypes - ? warningWithoutStack$1( - false, - "contextTypes was defined as an instance property on %s. Use a static " + - "property to define contextTypes instead.", - name - ) - : void 0; + // Add all children to a key map for quick lookups. + var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - if ( - ctor.contextType && - ctor.contextTypes && - !didWarnAboutContextTypeAndContextTypes.has(ctor) - ) { - didWarnAboutContextTypeAndContextTypes.add(ctor); - warningWithoutStack$1( - false, - "%s declares both contextTypes and contextType static properties. " + - "The legacy contextTypes property will be ignored.", - name + // 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; + } } - var noComponentShouldUpdate = - typeof instance.componentShouldUpdate !== "function"; - !noComponentShouldUpdate - ? warningWithoutStack$1( - 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 ( - ctor.prototype && - ctor.prototype.isPureReactComponent && - typeof instance.shouldComponentUpdate !== "undefined" - ) { - warningWithoutStack$1( - 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(ctor) || "A pure component" - ); - } - var noComponentDidUnmount = - typeof instance.componentDidUnmount !== "function"; - !noComponentDidUnmount - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - false, - "%s has a method called " + - "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", - name - ) - : void 0; - var noUnsafeComponentWillRecieveProps = - typeof instance.UNSAFE_componentWillRecieveProps !== "function"; - !noUnsafeComponentWillRecieveProps - ? warningWithoutStack$1( - false, - "%s has a method called " + - "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?", - name - ) - : void 0; - var hasMutatedProps = instance.props !== newProps; - !(instance.props === undefined || !hasMutatedProps) - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - 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(ctor) - ) { - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor); - warningWithoutStack$1( - false, - "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " + - "This component defines getSnapshotBeforeUpdate() only.", - getComponentName(ctor) - ); + 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 noInstanceGetDerivedStateFromProps = - typeof instance.getDerivedStateFromProps !== "function"; - !noInstanceGetDerivedStateFromProps - ? warningWithoutStack$1( - 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.getDerivedStateFromError !== "function"; - !noInstanceGetDerivedStateFromCatch - ? warningWithoutStack$1( - false, - "%s: getDerivedStateFromError() is defined as an instance method " + - "and will be ignored. Instead, declare it as a static method.", - name - ) - : void 0; - var noStaticGetSnapshotBeforeUpdate = - typeof ctor.getSnapshotBeforeUpdate !== "function"; - !noStaticGetSnapshotBeforeUpdate - ? warningWithoutStack$1( - 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$1(_state))) { - warningWithoutStack$1( - false, - "%s.state: must be set to an object or null", - name - ); - } - if (typeof instance.getChildContext === "function") { - !(typeof ctor.childContextTypes === "object") - ? warningWithoutStack$1( - false, - "%s.getChildContext(): childContextTypes must be defined in order to " + - "use getChildContext().", - name - ) - : void 0; - } + return resultingFirstChild; } -} -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 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." + ); -function constructClassInstance( - workInProgress, - ctor, - props, - renderExpirationTime -) { - var isLegacyContextConsumer = false; - var unmaskedContext = emptyContextObject; - var context = null; - var contextType = ctor.contextType; - if (typeof contextType === "object" && contextType !== null) { { + // We don't support rendering Generators because it's a mutation. + // See https://github.com/facebook/react/issues/12995 if ( - contextType.$$typeof !== REACT_CONTEXT_TYPE && - !didWarnAboutInvalidateContextType.has(ctor) + typeof Symbol === "function" && + // $FlowFixMe Flow doesn't know about toStringTag + newChildrenIterable[Symbol.toStringTag] === "Generator" ) { - didWarnAboutInvalidateContextType.add(ctor); - warningWithoutStack$1( - false, - "%s defines an invalid contextType. " + - "contextType should point to the Context object returned by React.createContext(). " + - "Did you accidentally pass the Context.Provider instead?", - getComponentName(ctor) || "Component" - ); + !didWarnAboutGenerators + ? warning$1( + false, + "Using Generators as children is unsupported and will likely yield " + + "unexpected results because enumerating a generator mutates it. " + + "You may convert it to an array with `Array.from()` or the " + + "`[...spread]` operator before rendering. Keep in mind " + + "you might need to polyfill these features for older browsers." + ) + : void 0; + didWarnAboutGenerators = true; } - } - context = readContext$1(contextType); - } else { - unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); - var contextTypes = ctor.contextTypes; - isLegacyContextConsumer = - contextTypes !== null && contextTypes !== undefined; - context = isLegacyContextConsumer - ? getMaskedContext(workInProgress, unmaskedContext) - : emptyContextObject; - } + // Warn about using Maps as children + if (newChildrenIterable.entries === iteratorFn) { + !didWarnAboutMaps + ? warning$1( + false, + "Using Maps as children is unsupported and will likely yield " + + "unexpected results. Convert it to a sequence/iterable of keyed " + + "ReactElements instead." + ) + : void 0; + didWarnAboutMaps = true; + } - // Instantiate twice to help detect side-effects. - { - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - new ctor(props, context); // eslint-disable-line no-new + // 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 instance = new ctor(props, context); - var state = (workInProgress.memoizedState = - instance.state !== null && instance.state !== undefined - ? instance.state - : null); - adoptClassInstance(workInProgress, instance); + var newChildren = iteratorFn.call(newChildrenIterable); + invariant(newChildren != null, "An iterable object provided no iterator."); - { - if (typeof ctor.getDerivedStateFromProps === "function" && state === null) { - var componentName = getComponentName(ctor) || "Component"; - if (!didWarnAboutUninitializedState.has(componentName)) { - didWarnAboutUninitializedState.add(componentName); - warningWithoutStack$1( - false, - "`%s` uses `getDerivedStateFromProps` but its initial state is " + - "%s. This is not recommended. Instead, define the initial state by " + - "assigning an object to `this.state` in the constructor of `%s`. " + - "This ensures that `getDerivedStateFromProps` arguments have a consistent shape.", - componentName, - instance.state === null ? "null" : "undefined", - componentName - ); - } - } + var resultingFirstChild = null; + var previousNewFiber = 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 oldFiber = currentFirstChild; + var lastPlacedIndex = 0; + var newIdx = 0; + var nextOldFiber = null; + + var step = newChildren.next(); + for ( + ; + oldFiber !== null && !step.done; + newIdx++, step = newChildren.next() ) { - 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 (oldFiber.index > newIdx) { + nextOldFiber = oldFiber; + oldFiber = null; + } else { + nextOldFiber = oldFiber.sibling; } - if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true - ) { - foundWillUpdateName = "componentWillUpdate"; - } else if (typeof instance.UNSAFE_componentWillUpdate === "function") { - foundWillUpdateName = "UNSAFE_componentWillUpdate"; + 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 ( - foundWillMountName !== null || - foundWillReceivePropsName !== null || - foundWillUpdateName !== null - ) { - var _componentName = getComponentName(ctor) || "Component"; - var newApiName = - typeof ctor.getDerivedStateFromProps === "function" - ? "getDerivedStateFromProps()" - : "getSnapshotBeforeUpdate()"; - if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) { - didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName); - warningWithoutStack$1( - 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 : "" - ); + 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; } - } - - // 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 (isLegacyContextConsumer) { - cacheContext(workInProgress, unmaskedContext, context); - } - - return instance; -} -function callComponentWillMount(workInProgress, instance) { - startPhaseTimer(workInProgress, "componentWillMount"); - var oldState = instance.state; + if (step.done) { + // We've reached the end of the new children. We can delete the rest. + deleteRemainingChildren(returnFiber, oldFiber); + return resultingFirstChild; + } - if (typeof instance.componentWillMount === "function") { - instance.componentWillMount(); - } - if (typeof instance.UNSAFE_componentWillMount === "function") { - instance.UNSAFE_componentWillMount(); - } + 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; + } - stopPhaseTimer(); + // Add all children to a key map for quick lookups. + var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - if (oldState !== instance.state) { - { - warningWithoutStack$1( - false, - "%s.componentWillMount(): Assigning directly to this.state is " + - "deprecated (except inside a component's " + - "constructor). Use setState instead.", - getComponentName(workInProgress.type) || "Component" + // 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; + } } - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); - } -} - -function callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - nextContext -) { - var oldState = instance.state; - startPhaseTimer(workInProgress, "componentWillReceiveProps"); - if (typeof instance.componentWillReceiveProps === "function") { - instance.componentWillReceiveProps(newProps, nextContext); - } - if (typeof instance.UNSAFE_componentWillReceiveProps === "function") { - instance.UNSAFE_componentWillReceiveProps(newProps, nextContext); - } - stopPhaseTimer(); - if (instance.state !== oldState) { - { - var componentName = getComponentName(workInProgress.type) || "Component"; - if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { - didWarnAboutStateAssignmentForComponent.add(componentName); - warningWithoutStack$1( - false, - "%s.componentWillReceiveProps(): Assigning directly to " + - "this.state is deprecated (except inside a component's " + - "constructor). Use setState instead.", - componentName - ); - } + 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); + }); } - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); - } -} -// Invokes the mount life-cycles on a previously never rendered instance. -function mountClassInstance( - workInProgress, - ctor, - newProps, - renderExpirationTime -) { - { - checkClassInstance(workInProgress, ctor, newProps); + return resultingFirstChild; } - var instance = workInProgress.stateNode; - instance.props = newProps; - instance.state = workInProgress.memoizedState; - instance.refs = emptyRefsObject; - - var contextType = ctor.contextType; - if (typeof contextType === "object" && contextType !== null) { - instance.context = readContext$1(contextType); - } else { - var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); - instance.context = getMaskedContext(workInProgress, unmaskedContext); + 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; } - { - if (instance.state === newProps) { - var componentName = getComponentName(ctor) || "Component"; - if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) { - didWarnAboutDirectlyAssigningPropsToState.add(componentName); - warningWithoutStack$1( - false, - "%s: It is not recommended to assign props directly to state " + - "because updates to props won't be reflected in state. " + - "In most cases, it is better to use props directly.", - componentName - ); + 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.elementType === 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 { + deleteChild(returnFiber, child); } + child = child.sibling; } - if (workInProgress.mode & StrictMode) { - ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( - workInProgress, - instance - ); - - ReactStrictModeWarnings.recordLegacyContextWarning( - workInProgress, - instance + if (element.type === REACT_FRAGMENT_TYPE) { + var created = createFiberFromFragment( + element.props.children, + returnFiber.mode, + expirationTime, + element.key ); - } - - if (warnAboutDeprecatedLifecycles) { - ReactStrictModeWarnings.recordDeprecationWarnings( - workInProgress, - instance + created.return = returnFiber; + return created; + } else { + var _created4 = createFiberFromElement( + element, + returnFiber.mode, + expirationTime ); + _created4.ref = coerceRef(returnFiber, currentFirstChild, element); + _created4.return = returnFiber; + return _created4; } } - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime - ); - instance.state = workInProgress.memoizedState; - } + 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; + } + } else { + deleteChild(returnFiber, child); + } + child = child.sibling; + } - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - newProps + var created = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime ); - instance.state = workInProgress.memoizedState; + created.return = returnFiber; + return created; } - // 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") + // 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 ) { - 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, - newProps, - instance, - renderExpirationTime - ); - instance.state = workInProgress.memoizedState; - } - } + // 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. - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; - } -} + // 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 resumeMountClassInstance( - workInProgress, - ctor, - newProps, - renderExpirationTime -) { - var instance = workInProgress.stateNode; + // Handle object types + var isObject = typeof newChild === "object" && newChild !== null; - var oldProps = workInProgress.memoizedProps; - instance.props = oldProps; + 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 + ) + ); + } + } - var oldContext = instance.context; - var contextType = ctor.contextType; - var nextContext = void 0; - if (typeof contextType === "object" && contextType !== null) { - nextContext = readContext$1(contextType); - } else { - var nextLegacyUnmaskedContext = getUnmaskedContext( - workInProgress, - ctor, - true - ); - nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext); - } - - 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 !== nextContext) { - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - nextContext + if (typeof newChild === "string" || typeof newChild === "number") { + return placeSingleChild( + reconcileSingleTextNode( + returnFiber, + currentFirstChild, + "" + newChild, + expirationTime + ) ); } - } - - 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.componentDidMount === "function") { - workInProgress.effectTag |= Update; + if (isArray(newChild)) { + return reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); } - return false; - } - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - newProps - ); - newState = workInProgress.memoizedState; - } + if (getIteratorFn(newChild)) { + return reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); + } - var shouldUpdate = - checkHasForceUpdateAfterProcessing() || - checkShouldComponentUpdate( - workInProgress, - ctor, - oldProps, - newProps, - oldState, - newState, - nextContext - ); + if (isObject) { + throwOnInvalidObjectType(returnFiber, newChild); + } - 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(); + { + if (typeof newChild === "function") { + warnOnFunctionType(); } - 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 (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 FunctionComponent: { + 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 shouldComponentUpdate returned false, we should still update the - // memoized state to indicate that this work can be reused. - workInProgress.memoizedProps = newProps; - workInProgress.memoizedState = newState; + // Remaining cases are all treated as empty. + return deleteRemainingChildren(returnFiber, currentFirstChild); } - // Update the existing instance's state, props, and context pointers even - // if shouldComponentUpdate returns false. - instance.props = newProps; - instance.state = newState; - instance.context = nextContext; - - return shouldUpdate; + return reconcileChildFibers; } -// Invokes the update life-cycles and returns false if it shouldn't rerender. -function updateClassInstance( - current, - workInProgress, - ctor, - newProps, - renderExpirationTime -) { - var instance = workInProgress.stateNode; - - var oldProps = workInProgress.memoizedProps; - instance.props = - workInProgress.type === workInProgress.elementType - ? oldProps - : resolveDefaultProps(workInProgress.type, oldProps); - - var oldContext = instance.context; - var contextType = ctor.contextType; - var nextContext = void 0; - if (typeof contextType === "object" && contextType !== null) { - nextContext = readContext$1(contextType); - } else { - var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true); - nextContext = getMaskedContext(workInProgress, nextUnmaskedContext); - } - - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - var hasNewLifecycles = - typeof getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; +var reconcileChildFibers = ChildReconciler(true); +var mountChildFibers = ChildReconciler(false); - // 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. +function cloneChildFibers(current$$1, workInProgress) { + invariant( + current$$1 === null || workInProgress.child === current$$1.child, + "Resuming work not yet implemented." + ); - // 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 !== nextContext) { - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - nextContext - ); - } + if (workInProgress.child === null) { + return; } - resetHasForceUpdateBeforeProcessing(); + var currentChild = workInProgress.child; + var newChild = createWorkInProgress( + currentChild, + currentChild.pendingProps, + currentChild.expirationTime + ); + workInProgress.child = newChild; - var oldState = workInProgress.memoizedState; - var newState = (instance.state = oldState); - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime + newChild.return = workInProgress; + while (currentChild.sibling !== null) { + currentChild = currentChild.sibling; + newChild = newChild.sibling = createWorkInProgress( + currentChild, + currentChild.pendingProps, + currentChild.expirationTime ); - newState = workInProgress.memoizedState; + newChild.return = workInProgress; } + newChild.sibling = null; +} - 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; - } - } - return false; - } +var NO_CONTEXT = {}; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - newProps - ); - newState = workInProgress.memoizedState; - } +var contextStackCursor$1 = createCursor(NO_CONTEXT); +var contextFiberStackCursor = createCursor(NO_CONTEXT); +var rootInstanceStackCursor = createCursor(NO_CONTEXT); - var shouldUpdate = - checkHasForceUpdateAfterProcessing() || - checkShouldComponentUpdate( - workInProgress, - ctor, - oldProps, - newProps, - oldState, - newState, - nextContext - ); +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; +} - 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, nextContext); - } - if (typeof instance.UNSAFE_componentWillUpdate === "function") { - instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext); - } - 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 getRootHostContainer() { + var rootInstance = requiredContext(rootInstanceStackCursor.current); + return rootInstance; +} - // 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 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); - // Update the existing instance's state, props, and context pointers even - // if shouldComponentUpdate returns false. - instance.props = newProps; - instance.state = newState; - instance.context = nextContext; + // 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); +} - return shouldUpdate; +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); } -var didWarnAboutMaps = void 0; -var didWarnAboutGenerators = void 0; -var didWarnAboutStringRefInStrictMode = void 0; -var ownerHasKeyUseWarning = void 0; -var ownerHasFunctionTypeWarning = void 0; -var warnForMissingKey = function(child) {}; +function getHostContext() { + var context = requiredContext(contextStackCursor$1.current); + return context; +} -{ - didWarnAboutMaps = false; - didWarnAboutGenerators = false; - didWarnAboutStringRefInStrictMode = {}; +function pushHostContext(fiber) { + var rootInstance = requiredContext(rootInstanceStackCursor.current); + var context = requiredContext(contextStackCursor$1.current); + var nextContext = getChildHostContext(context, fiber.type, rootInstance); - /** - * 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 = {}; + // Don't push this Fiber's context unless it's unique. + if (context === nextContext) { + return; + } - 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; + // 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); +} - 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." + - getCurrentFiberStackInDev(); - if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { - return; - } - ownerHasKeyUseWarning[currentComponentErrorInfo] = true; +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; + } - warning$1( - false, - "Each child in an array or iterator should have a unique " + - '"key" prop. See https://fb.me/react-warning-keys for ' + - "more information." - ); - }; + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); } -var isArray = Array.isArray; +var NoEffect$1 = /* */ 0; +var UnmountSnapshot = /* */ 2; +var UnmountMutation = /* */ 4; +var MountMutation = /* */ 8; +var UnmountLayout = /* */ 16; +var MountLayout = /* */ 32; +var MountPassive = /* */ 64; +var UnmountPassive = /* */ 128; -function coerceRef(returnFiber, current$$1, element) { - var mixedRef = element.ref; - if ( - mixedRef !== null && - typeof mixedRef !== "function" && - typeof mixedRef !== "object" - ) { - { - if (returnFiber.mode & StrictMode) { - var componentName = getComponentName(returnFiber.type) || "Component"; - if (!didWarnAboutStringRefInStrictMode[componentName]) { - warningWithoutStack$1( - 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, - getStackByFiberInDevAndProd(returnFiber) - ); - didWarnAboutStringRefInStrictMode[componentName] = true; - } - } - } +var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher; - if (element._owner) { - var owner = element._owner; - var inst = void 0; - if (owner) { - var ownerFiber = owner; - invariant( - ownerFiber.tag === ClassComponent, - "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$$1 !== null && - current$$1.ref !== null && - typeof current$$1.ref === "function" && - current$$1.ref._stringRef === stringRef - ) { - return current$$1.ref; - } - var ref = function(value) { - var refs = inst.refs; - if (refs === emptyRefsObject) { - // This is a lazy pooled frozen object, so we need to initialize. - 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, a string, an object returned by React.createRef(), or null." - ); - 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 function component\n" + - "2. You may be adding a ref to a component that was not created inside a component's render method\n" + - "3. You have multiple copies of React loaded\n" + - "See https://fb.me/react-refs-must-have-owner for more information.", - mixedRef - ); - } - } - return mixedRef; +var didWarnAboutMismatchedHooksForComponent = void 0; +{ + didWarnAboutMismatchedHooksForComponent = new Set(); } -function throwOnInvalidObjectType(returnFiber, newChild) { - if (returnFiber.type !== "textarea") { - var addendum = ""; - { - addendum = - " If you meant to render a collection of children, use an array " + - "instead." + - getCurrentFiberStackInDev(); - } - 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 - ); - } -} +// These are set right before calling the component. +var renderExpirationTime = NoWork; +// The work-in-progress fiber. I've named it differently to distinguish it from +// the work-in-progress hook. +var currentlyRenderingFiber$1 = 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." + - getCurrentFiberStackInDev(); +// Hooks are stored as a linked list on the fiber's memoizedState field. The +// current hook list is the list that belongs to the current fiber. The +// work-in-progress hook list is a new list that will be added to the +// work-in-progress fiber. +var firstCurrentHook = null; +var currentHook = null; +var nextCurrentHook = null; +var firstWorkInProgressHook = null; +var workInProgressHook = null; +var nextWorkInProgressHook = null; - if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) { - return; +var remainingExpirationTime = NoWork; +var componentUpdateQueue = null; +var sideEffectTag = 0; + +// Updates scheduled during render will trigger an immediate re-render at the +// end of the current pass. We can't store these updates on the normal queue, +// because if the work is aborted, they should be discarded. Because this is +// a relatively rare case, we also don't want to add an additional field to +// either the hook or queue object types. So we store them in a lazily create +// map of queue -> render-phase updates, which are discarded once the component +// completes without re-rendering. + +// Whether an update was scheduled during the currently executing render pass. +var didScheduleRenderPhaseUpdate = false; +// Lazily created map of render-phase updates +var renderPhaseUpdates = null; +// Counter to prevent infinite loops. +var numberOfReRenders = 0; +var RE_RENDER_LIMIT = 25; + +// In DEV, this is the name of the currently executing primitive hook +var currentHookNameInDev = null; + +function warnOnHookMismatchInDev() { + { + var componentName = getComponentName(currentlyRenderingFiber$1.type); + if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) { + didWarnAboutMismatchedHooksForComponent.add(componentName); + + var secondColumnStart = 22; + + var table = ""; + var prevHook = firstCurrentHook; + var nextHook = firstWorkInProgressHook; + var n = 1; + while (prevHook !== null && nextHook !== null) { + var oldHookName = prevHook._debugType; + var newHookName = nextHook._debugType; + + var row = n + ". " + oldHookName; + + // Extra space so second column lines up + // lol @ IE not supporting String#repeat + while (row.length < secondColumnStart) { + row += " "; + } + + row += newHookName + "\n"; + + table += row; + prevHook = prevHook.next; + nextHook = nextHook.next; + n++; + } + + warning$1( + false, + "React has detected a change in the order of Hooks called by %s. " + + "This will lead to bugs and errors if not fixed. " + + "For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n" + + " Previous render Next render\n" + + " -------------------------------\n" + + "%s" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + componentName, + table + ); + } } - ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; +} - warning$1( +function throwInvalidHookError() { + invariant( 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." + "Hooks can only be called inside the body of a function component. " + + "(https://fb.me/react-invalid-hook-call)" ); } -// 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; +function areHookInputsEqual(nextDeps, prevDeps) { + if (prevDeps === null) { + { + warning$1( + false, + "%s received a final argument during this render, but not during " + + "the previous render. Even though the final argument is optional, " + + "its type cannot change between renders.", + currentHookNameInDev + ); } - childToDelete.nextEffect = null; - childToDelete.effectTag = Deletion; + return false; } - function deleteRemainingChildren(returnFiber, currentFirstChild) { - if (!shouldTrackSideEffects) { - // Noop. - return null; + { + // Don't bother comparing lengths in prod because these arrays should be + // passed inline. + if (nextDeps.length !== prevDeps.length) { + warning$1( + false, + "The final argument passed to %s changed size between renders. The " + + "order and size of this array must remain constant.\n\n" + + "Previous: %s\n" + + "Incoming: %s", + currentHookNameInDev, + "[" + nextDeps.join(", ") + "]", + "[" + prevDeps.join(", ") + "]" + ); } - - // 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; + } + for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) { + if (is(nextDeps[i], prevDeps[i])) { + continue; } - return null; + return false; } + return true; +} - 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(); +function renderWithHooks( + current, + workInProgress, + Component, + props, + refOrContext, + nextRenderExpirationTime +) { + renderExpirationTime = nextRenderExpirationTime; + currentlyRenderingFiber$1 = workInProgress; + firstCurrentHook = nextCurrentHook = + current !== null ? current.memoizedState : null; - var existingChild = currentFirstChild; - while (existingChild !== null) { - if (existingChild.key !== null) { - existingChildren.set(existingChild.key, existingChild); - } else { - existingChildren.set(existingChild.index, existingChild); - } - existingChild = existingChild.sibling; - } - return existingChildren; - } + // The following should have already been reset + // currentHook = null; + // workInProgressHook = null; - 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; + // remainingExpirationTime = NoWork; + // componentUpdateQueue = null; + + // didScheduleRenderPhaseUpdate = false; + // renderPhaseUpdates = null; + // numberOfReRenders = 0; + // sideEffectTag = 0; + + { + ReactCurrentDispatcher$1.current = + nextCurrentHook === null + ? HooksDispatcherOnMountInDEV + : HooksDispatcherOnUpdateInDEV; } - function placeChild(newFiber, lastPlacedIndex, newIndex) { - newFiber.index = newIndex; - if (!shouldTrackSideEffects) { - // Noop. - return lastPlacedIndex; - } - var current$$1 = newFiber.alternate; - if (current$$1 !== null) { - var oldIndex = current$$1.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; - } + var children = Component(props, refOrContext); + + if (didScheduleRenderPhaseUpdate) { + do { + didScheduleRenderPhaseUpdate = false; + numberOfReRenders += 1; + + // Start over from the beginning of the list + firstCurrentHook = nextCurrentHook = + current !== null ? current.memoizedState : null; + nextWorkInProgressHook = firstWorkInProgressHook; + + currentHook = null; + workInProgressHook = null; + componentUpdateQueue = null; + + ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV; + + children = Component(props, refOrContext); + } while (didScheduleRenderPhaseUpdate); + + renderPhaseUpdates = null; + numberOfReRenders = 0; } - 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; + { + currentHookNameInDev = null; } - function updateTextNode( - returnFiber, - current$$1, - textContent, - expirationTime - ) { - if (current$$1 === null || current$$1.tag !== HostText) { - // Insert - var created = createFiberFromText( - textContent, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current$$1, textContent, expirationTime); - existing.return = returnFiber; - return existing; - } + // We can assume the previous dispatcher is always this one, since we set it + // at the beginning of the render phase and there's no re-entrancy. + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + + var renderedWork = currentlyRenderingFiber$1; + + renderedWork.memoizedState = firstWorkInProgressHook; + renderedWork.expirationTime = remainingExpirationTime; + renderedWork.updateQueue = componentUpdateQueue; + renderedWork.effectTag |= sideEffectTag; + + var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null; + + renderExpirationTime = NoWork; + currentlyRenderingFiber$1 = null; + + firstCurrentHook = null; + currentHook = null; + nextCurrentHook = null; + firstWorkInProgressHook = null; + workInProgressHook = null; + nextWorkInProgressHook = null; + + remainingExpirationTime = NoWork; + componentUpdateQueue = null; + sideEffectTag = 0; + + // These were reset above + // didScheduleRenderPhaseUpdate = false; + // renderPhaseUpdates = null; + // numberOfReRenders = 0; + + invariant( + !didRenderTooFewHooks, + "Rendered fewer hooks than expected. This may be caused by an accidental " + + "early return statement." + ); + + return children; +} + +function bailoutHooks(current, workInProgress, expirationTime) { + workInProgress.updateQueue = current.updateQueue; + workInProgress.effectTag &= ~(Passive | Update); + if (current.expirationTime <= expirationTime) { + current.expirationTime = NoWork; } +} - function updateElement(returnFiber, current$$1, element, expirationTime) { - if (current$$1 !== null && current$$1.elementType === element.type) { - // Move based on index - var existing = useFiber(current$$1, element.props, expirationTime); - existing.ref = coerceRef(returnFiber, current$$1, 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$$1, element); - created.return = returnFiber; - return created; - } +function resetHooks() { + // We can assume the previous dispatcher is always this one, since we set it + // at the beginning of the render phase and there's no re-entrancy. + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + + // This is used to reset the state of this module when a component throws. + // It's also called inside mountIndeterminateComponent if we determine the + // component is a module-style component. + renderExpirationTime = NoWork; + currentlyRenderingFiber$1 = null; + + firstCurrentHook = null; + currentHook = null; + nextCurrentHook = null; + firstWorkInProgressHook = null; + workInProgressHook = null; + nextWorkInProgressHook = null; + + remainingExpirationTime = NoWork; + componentUpdateQueue = null; + sideEffectTag = 0; + + { + currentHookNameInDev = null; } - function updatePortal(returnFiber, current$$1, portal, expirationTime) { + didScheduleRenderPhaseUpdate = false; + renderPhaseUpdates = null; + numberOfReRenders = 0; +} + +function mountWorkInProgressHook() { + var hook = { + memoizedState: null, + + baseState: null, + queue: null, + baseUpdate: null, + + next: null + }; + + { + hook._debugType = currentHookNameInDev; if ( - current$$1 === null || - current$$1.tag !== HostPortal || - current$$1.stateNode.containerInfo !== portal.containerInfo || - current$$1.stateNode.implementation !== portal.implementation + currentlyRenderingFiber$1 !== null && + currentlyRenderingFiber$1.alternate !== null ) { - // Insert - var created = createFiberFromPortal( - portal, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber( - current$$1, - portal.children || [], - expirationTime + warning$1( + false, + "%s: Rendered more hooks than during the previous render. This is " + + "not currently supported and may lead to unexpected behavior.", + getComponentName(currentlyRenderingFiber$1.type) ); - existing.return = returnFiber; - return existing; } } - - function updateFragment( - returnFiber, - current$$1, - fragment, - expirationTime, - key - ) { - if (current$$1 === null || current$$1.tag !== Fragment) { - // Insert - var created = createFiberFromFragment( - fragment, - returnFiber.mode, - expirationTime, - key - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current$$1, fragment, expirationTime); - existing.return = returnFiber; - return existing; - } + if (workInProgressHook === null) { + // This is the first hook in the list + firstWorkInProgressHook = workInProgressHook = hook; + } else { + // Append to the end of the list + workInProgressHook = workInProgressHook.next = hook; } + return workInProgressHook; +} - 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; - } +function updateWorkInProgressHook() { + // This function is used both for updates and for re-renders triggered by a + // render phase update. It assumes there is either a current hook we can + // clone, or a work-in-progress hook from a previous render pass that we can + // use as a base. When we reach the end of the base list, we must switch to + // the dispatcher used for mounts. + if (nextWorkInProgressHook !== null) { + // There's already a work-in-progress. Reuse it. + workInProgressHook = nextWorkInProgressHook; + nextWorkInProgressHook = workInProgressHook.next; - 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; - } - } + currentHook = nextCurrentHook; + nextCurrentHook = currentHook !== null ? currentHook.next : null; + } else { + // Clone from the current hook. + invariant( + nextCurrentHook !== null, + "Rendered more hooks than during the previous render." + ); + currentHook = nextCurrentHook; - if (isArray(newChild) || getIteratorFn(newChild)) { - var _created3 = createFiberFromFragment( - newChild, - returnFiber.mode, - expirationTime, - null - ); - _created3.return = returnFiber; - return _created3; - } + var newHook = { + memoizedState: currentHook.memoizedState, - throwOnInvalidObjectType(returnFiber, newChild); + baseState: currentHook.baseState, + queue: currentHook.queue, + baseUpdate: currentHook.baseUpdate, + + next: null + }; + + if (workInProgressHook === null) { + // This is the first hook in the list. + workInProgressHook = firstWorkInProgressHook = newHook; + } else { + // Append to the end of the list. + workInProgressHook = workInProgressHook.next = newHook; } + nextCurrentHook = currentHook.next; { - if (typeof newChild === "function") { - warnOnFunctionType(); + newHook._debugType = currentHookNameInDev; + if (currentHookNameInDev !== currentHook._debugType) { + warnOnHookMismatchInDev(); } } - - return null; } + return workInProgressHook; +} - function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { - // Update the fiber if the keys match, otherwise return null. +function createFunctionComponentUpdateQueue() { + return { + lastEffect: null + }; +} - var key = oldFiber !== null ? oldFiber.key : null; +function basicStateReducer(state, action) { + return typeof action === "function" ? action(state) : action; +} - 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 - ); - } +function mountContext(context, observedBits) { + { + mountWorkInProgressHook(); + } + return readContext(context, observedBits); +} - 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; - } - } - } +function updateContext(context, observedBits) { + { + updateWorkInProgressHook(); + } + return readContext(context, observedBits); +} - if (isArray(newChild) || getIteratorFn(newChild)) { - if (key !== null) { - return null; +function mountReducer(reducer, initialArg, init) { + var hook = mountWorkInProgressHook(); + var initialState = void 0; + if (init !== undefined) { + initialState = init(initialArg); + } else { + initialState = initialArg; + } + hook.memoizedState = hook.baseState = initialState; + var queue = (hook.queue = { + last: null, + dispatch: null, + eagerReducer: reducer, + eagerState: initialState + }); + var dispatch = (queue.dispatch = dispatchAction.bind( + null, + // Flow doesn't know this is non-null, but we do. + currentlyRenderingFiber$1, + queue + )); + return [hook.memoizedState, dispatch]; +} + +function updateReducer(reducer, initialArg, init) { + var hook = updateWorkInProgressHook(); + var queue = hook.queue; + invariant( + queue !== null, + "Should have a queue. This is likely a bug in React. Please file an issue." + ); + + if (numberOfReRenders > 0) { + // This is a re-render. Apply the new render phase updates to the previous + var _dispatch = queue.dispatch; + if (renderPhaseUpdates !== null) { + // Render phase updates are stored in a map of queue -> linked list + var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); + if (firstRenderPhaseUpdate !== undefined) { + renderPhaseUpdates.delete(queue); + var newState = hook.memoizedState; + var update = firstRenderPhaseUpdate; + do { + // Process this render phase update. We don't have to check the + // priority because it will always be the same as the current + // render's. + var _action = update.action; + newState = reducer(newState, _action); + update = update.next; + } while (update !== null); + + // Mark that the fiber performed work, but only if the new state is + // different from the current state. + if (!is(newState, hook.memoizedState)) { + markWorkInProgressReceivedUpdate(); } - return updateFragment( - returnFiber, - oldFiber, - newChild, - expirationTime, - null - ); - } + hook.memoizedState = newState; - throwOnInvalidObjectType(returnFiber, newChild); - } + // Don't persist the state accumlated from the render phase updates to + // the base state unless the queue is empty. + // TODO: Not sure if this is the desired semantics, but it's what we + // do for gDSFP. I can't remember why. + if (hook.baseUpdate === queue.last) { + hook.baseState = newState; + } - { - if (typeof newChild === "function") { - warnOnFunctionType(); + return [newState, _dispatch]; } } - - return null; + return [hook.memoizedState, _dispatch]; } - 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 - ); - } + // The last update in the entire queue + var last = queue.last; + // The last update that is part of the base state. + var baseUpdate = hook.baseUpdate; + var baseState = hook.baseState; - 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 - ); + // Find the first unprocessed update. + var first = void 0; + if (baseUpdate !== null) { + if (last !== null) { + // For the first update, the queue is a circular linked list where + // `queue.last.next = queue.first`. Once the first update commits, and + // the `baseUpdate` is no longer empty, we can unravel the list. + last.next = null; + } + first = baseUpdate.next; + } else { + first = last !== null ? last.next : null; + } + if (first !== null) { + var _newState = baseState; + var newBaseState = null; + var newBaseUpdate = null; + var prevUpdate = baseUpdate; + var _update = first; + var didSkip = false; + do { + var updateExpirationTime = _update.expirationTime; + if (updateExpirationTime < renderExpirationTime) { + // Priority is insufficient. Skip this update. If this is the first + // skipped update, the previous update/state is the new base + // update/state. + if (!didSkip) { + didSkip = true; + newBaseUpdate = prevUpdate; + newBaseState = _newState; } - case REACT_PORTAL_TYPE: { - var _matchedFiber2 = - existingChildren.get( - newChild.key === null ? newIdx : newChild.key - ) || null; - return updatePortal( - returnFiber, - _matchedFiber2, - newChild, - expirationTime - ); + // Update the remaining priority in the queue. + if (updateExpirationTime > remainingExpirationTime) { + remainingExpirationTime = updateExpirationTime; + } + } else { + // Process this update. + if (_update.eagerReducer === reducer) { + // If this update was processed eagerly, and its reducer matches the + // current reducer, we can use the eagerly computed state. + _newState = _update.eagerState; + } else { + var _action2 = _update.action; + _newState = reducer(_newState, _action2); } } + prevUpdate = _update; + _update = _update.next; + } while (_update !== null && _update !== first); - if (isArray(newChild) || getIteratorFn(newChild)) { - var _matchedFiber3 = existingChildren.get(newIdx) || null; - return updateFragment( - returnFiber, - _matchedFiber3, - newChild, - expirationTime, - null - ); - } - - throwOnInvalidObjectType(returnFiber, newChild); + if (!didSkip) { + newBaseUpdate = prevUpdate; + newBaseState = _newState; } - { - if (typeof newChild === "function") { - warnOnFunctionType(); - } + // Mark that the fiber performed work, but only if the new state is + // different from the current state. + if (!is(_newState, hook.memoizedState)) { + markWorkInProgressReceivedUpdate(); } - return null; + hook.memoizedState = _newState; + hook.baseUpdate = newBaseUpdate; + hook.baseState = newBaseState; + + queue.eagerReducer = reducer; + queue.eagerState = _newState; } - /** - * 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$1( - 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.", - key - ); - break; - default: - break; - } + var dispatch = queue.dispatch; + return [hook.memoizedState, dispatch]; +} + +function mountState(initialState) { + var hook = mountWorkInProgressHook(); + if (typeof initialState === "function") { + initialState = initialState(); + } + hook.memoizedState = hook.baseState = initialState; + var queue = (hook.queue = { + last: null, + dispatch: null, + eagerReducer: basicStateReducer, + eagerState: initialState + }); + var dispatch = (queue.dispatch = dispatchAction.bind( + null, + // Flow doesn't know this is non-null, but we do. + currentlyRenderingFiber$1, + queue + )); + return [hook.memoizedState, dispatch]; +} + +function updateState(initialState) { + return updateReducer(basicStateReducer, initialState); +} + +function pushEffect(tag, create, destroy, deps) { + var effect = { + tag: tag, + create: create, + destroy: destroy, + deps: deps, + // Circular + next: null + }; + if (componentUpdateQueue === null) { + componentUpdateQueue = createFunctionComponentUpdateQueue(); + componentUpdateQueue.lastEffect = effect.next = effect; + } else { + var _lastEffect = componentUpdateQueue.lastEffect; + if (_lastEffect === null) { + componentUpdateQueue.lastEffect = effect.next = effect; + } else { + var firstEffect = _lastEffect.next; + _lastEffect.next = effect; + effect.next = firstEffect; + componentUpdateQueue.lastEffect = effect; } - return knownKeys; } + return effect; +} - 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 mountRef(initialValue) { + var hook = mountWorkInProgressHook(); + var ref = { current: initialValue }; + { + Object.seal(ref); + } + hook.memoizedState = ref; + return ref; +} - // 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. +function updateRef(initialValue) { + var hook = updateWorkInProgressHook(); + return hook.memoizedState; +} - // In this first iteration, we'll just live with hitting the bad case - // (adding everything to a Map) in for every insert/move. +function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = mountWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps); +} - // If you change this code, also update reconcileChildrenIterator() which - // uses the same algorithm. +function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = updateWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + var destroy = undefined; - { - // First, validate keys. - var knownKeys = null; - for (var i = 0; i < newChildren.length; i++) { - var child = newChildren[i]; - knownKeys = warnOnInvalidKey(child, knownKeys); + if (currentHook !== null) { + var prevEffect = currentHook.memoizedState; + destroy = prevEffect.destroy; + if (nextDeps !== null) { + var prevDeps = prevEffect.deps; + if (areHookInputsEqual(nextDeps, prevDeps)) { + pushEffect(NoEffect$1, create, destroy, nextDeps); + return; } } + } - var resultingFirstChild = null; - var previousNewFiber = null; + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps); +} - 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; - } +function mountEffect(create, deps) { + return mountEffectImpl( + Update | Passive, + UnmountPassive | MountPassive, + create, + deps + ); +} - if (newIdx === newChildren.length) { - // We've reached the end of the new children. We can delete the rest. - deleteRemainingChildren(returnFiber, oldFiber); - return resultingFirstChild; - } +function updateEffect(create, deps) { + return updateEffectImpl( + Update | Passive, + UnmountPassive | MountPassive, + create, + deps + ); +} - 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 mountLayoutEffect(create, deps) { + return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps); +} - // Add all children to a key map for quick lookups. - var existingChildren = mapRemainingChildren(returnFiber, oldFiber); +function updateLayoutEffect(create, deps) { + return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps); +} - // 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; - } +function imperativeHandleEffect(create, ref) { + if (typeof ref === "function") { + var refCallback = ref; + var _inst = create(); + refCallback(_inst); + return function() { + refCallback(null); + }; + } else if (ref !== null && ref !== undefined) { + var refObject = ref; + { + !refObject.hasOwnProperty("current") + ? warning$1( + false, + "Expected useImperativeHandle() first argument to either be a " + + "ref callback or React.createRef() object. Instead received: %s.", + "an object with keys {" + Object.keys(refObject).join(", ") + "}" + ) + : void 0; } + var _inst2 = create(); + refObject.current = _inst2; + return function() { + refObject.current = null; + }; + } +} - 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 mountImperativeHandle(ref, create, deps) { + { + !(typeof create === "function") + ? warning$1( + false, + "Expected useImperativeHandle() second argument to be a function " + + "that creates a handle. Instead received: %s.", + create !== null ? typeof create : "null" + ) + : void 0; + } - return resultingFirstChild; + // TODO: If deps are provided, should we skip comparing the ref itself? + var effectDeps = + deps !== null && deps !== undefined ? deps.concat([ref]) : [ref]; + + return mountEffectImpl( + Update, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + effectDeps + ); +} + +function updateImperativeHandle(ref, create, deps) { + { + !(typeof create === "function") + ? warning$1( + false, + "Expected useImperativeHandle() second argument to be a function " + + "that creates a handle. Instead received: %s.", + create !== null ? typeof create : "null" + ) + : void 0; } - function reconcileChildrenIterator( - returnFiber, - currentFirstChild, - newChildrenIterable, - expirationTime - ) { - // This is the same implementation as reconcileChildrenArray(), - // but using the iterator instead. + // TODO: If deps are provided, should we skip comparing the ref itself? + var effectDeps = + deps !== null && deps !== undefined ? deps.concat([ref]) : [ref]; - 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." - ); + return updateEffectImpl( + Update, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + effectDeps + ); +} - { - // We don't support rendering Generators because it's a mutation. - // See https://github.com/facebook/react/issues/12995 - if ( - typeof Symbol === "function" && - // $FlowFixMe Flow doesn't know about toStringTag - newChildrenIterable[Symbol.toStringTag] === "Generator" - ) { - !didWarnAboutGenerators - ? warning$1( - false, - "Using Generators as children is unsupported and will likely yield " + - "unexpected results because enumerating a generator mutates it. " + - "You may convert it to an array with `Array.from()` or the " + - "`[...spread]` operator before rendering. Keep in mind " + - "you might need to polyfill these features for older browsers." - ) - : void 0; - didWarnAboutGenerators = true; - } +function mountDebugValue(value, formatterFn) { + // This hook is normally a no-op. + // The react-debug-hooks package injects its own implementation + // so that e.g. DevTools can display custom hook values. +} - // Warn about using Maps as children - if (newChildrenIterable.entries === iteratorFn) { - !didWarnAboutMaps - ? warning$1( - false, - "Using Maps as children is unsupported and will likely yield " + - "unexpected results. Convert it to a sequence/iterable of keyed " + - "ReactElements instead." - ) - : void 0; - didWarnAboutMaps = true; +var updateDebugValue = mountDebugValue; + +function mountCallback(callback, deps) { + var hook = mountWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + hook.memoizedState = [callback, nextDeps]; + return callback; +} + +function updateCallback(callback, deps) { + var hook = updateWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + var prevState = hook.memoizedState; + if (prevState !== null) { + if (nextDeps !== null) { + var prevDeps = prevState[1]; + if (areHookInputsEqual(nextDeps, prevDeps)) { + return prevState[0]; } + } + } + hook.memoizedState = [callback, nextDeps]; + return callback; +} - // 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 mountMemo(nextCreate, deps) { + var hook = mountWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + var nextValue = nextCreate(); + hook.memoizedState = [nextValue, nextDeps]; + return nextValue; +} + +function updateMemo(nextCreate, deps) { + var hook = updateWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + var prevState = hook.memoizedState; + if (prevState !== null) { + // Assume these are defined. If they're not, areHookInputsEqual will warn. + if (nextDeps !== null) { + var prevDeps = prevState[1]; + if (areHookInputsEqual(nextDeps, prevDeps)) { + return prevState[0]; } } + } + var nextValue = nextCreate(); + hook.memoizedState = [nextValue, nextDeps]; + return nextValue; +} - var newChildren = iteratorFn.call(newChildrenIterable); - invariant(newChildren != null, "An iterable object provided no iterator."); +// in a test-like environment, we want to warn if dispatchAction() +// is called outside of a batchedUpdates/TestUtils.act(...) call. +var shouldWarnForUnbatchedSetState = false; - var resultingFirstChild = null; - var previousNewFiber = null; +{ + // jest isnt' a 'global', it's just exposed to tests via a wrapped function + // further, this isn't a test file, so flow doesn't recognize the symbol. So... + // $FlowExpectedError - because requirements don't give a damn about your type sigs. + if ("undefined" !== typeof jest) { + shouldWarnForUnbatchedSetState = true; + } +} - var oldFiber = currentFirstChild; - var lastPlacedIndex = 0; - var newIdx = 0; - var nextOldFiber = null; +function dispatchAction(fiber, queue, action) { + invariant( + numberOfReRenders < RE_RENDER_LIMIT, + "Too many re-renders. React limits the number of renders to prevent " + + "an infinite loop." + ); - 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; + { + !(arguments.length <= 3) + ? warning$1( + false, + "State updates from the useState() and useReducer() Hooks don't support the " + + "second callback argument. To execute a side effect after " + + "rendering, declare it in the component body with useEffect()." + ) + : void 0; + } + + var alternate = fiber.alternate; + if ( + fiber === currentlyRenderingFiber$1 || + (alternate !== null && alternate === currentlyRenderingFiber$1) + ) { + // This is a render phase update. Stash it in a lazily-created map of + // queue -> linked list of updates. After this render pass, we'll restart + // and apply the stashed updates on top of the work-in-progress hook. + didScheduleRenderPhaseUpdate = true; + var update = { + expirationTime: renderExpirationTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }; + if (renderPhaseUpdates === null) { + renderPhaseUpdates = new Map(); + } + var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); + if (firstRenderPhaseUpdate === undefined) { + renderPhaseUpdates.set(queue, update); + } else { + // Append the update to the end of the list. + var lastRenderPhaseUpdate = firstRenderPhaseUpdate; + while (lastRenderPhaseUpdate.next !== null) { + lastRenderPhaseUpdate = lastRenderPhaseUpdate.next; } - previousNewFiber = newFiber; - oldFiber = nextOldFiber; + lastRenderPhaseUpdate.next = update; } + } else { + flushPassiveEffects(); - if (step.done) { - // We've reached the end of the new children. We can delete the rest. - deleteRemainingChildren(returnFiber, oldFiber); - return resultingFirstChild; - } + var currentTime = requestCurrentTime(); + 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 _update2 = { + expirationTime: _expirationTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }; + + // Append the update to the end of the list. + var _last = queue.last; + if (_last === null) { + // This is the first update. Create a circular list. + _update2.next = _update2; + } else { + var first = _last.next; + if (first !== null) { + // Still circular. + _update2.next = first; } - return resultingFirstChild; + _last.next = _update2; } + queue.last = _update2; - // Add all children to a key map for quick lookups. - var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - - // Keep scanning and use the map to restore deleted items as moves. - for (; !step.done; newIdx++, step = newChildren.next()) { - var _newFiber4 = updateFromMap( - existingChildren, - returnFiber, - newIdx, - step.value, - 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 ( + fiber.expirationTime === NoWork && + (alternate === null || alternate.expirationTime === NoWork) + ) { + // The queue is currently empty, which means we can eagerly compute the + // next state before entering the render phase. If the new state is the + // same as the current state, we may be able to bail out entirely. + var _eagerReducer = queue.eagerReducer; + if (_eagerReducer !== null) { + var prevDispatcher = void 0; + { + prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; } - lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - resultingFirstChild = _newFiber4; - } else { - previousNewFiber.sibling = _newFiber4; + try { + var currentState = queue.eagerState; + var _eagerState = _eagerReducer(currentState, action); + // Stash the eagerly computed state, and the reducer used to compute + // it, on the update object. If the reducer hasn't changed by the + // time we enter the render phase, then the eager state can be used + // without calling the reducer again. + _update2.eagerReducer = _eagerReducer; + _update2.eagerState = _eagerState; + if (is(_eagerState, currentState)) { + // Fast path. We can bail out without scheduling React to re-render. + // It's still possible that we'll need to rebase this update later, + // if the component re-renders for a different reason and by that + // time the reducer has changed. + return; + } + } catch (error) { + // Suppress the error. It will throw again in the render phase. + } finally { + { + ReactCurrentDispatcher$1.current = prevDispatcher; + } } - previousNewFiber = _newFiber4; } } - - if (shouldTrackSideEffects) { - // Any existing children that weren't consumed above were deleted. We need - // to add them to the deletion list. - existingChildren.forEach(function(child) { - return deleteChild(returnFiber, child); - }); + { + if (shouldWarnForUnbatchedSetState === true) { + warnIfNotCurrentlyBatchingInDev(fiber); + } } - - return resultingFirstChild; + scheduleWork(fiber, _expirationTime); } +} - 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 +var ContextOnlyDispatcher = { + readContext: readContext, + + useCallback: throwInvalidHookError, + useContext: throwInvalidHookError, + useEffect: throwInvalidHookError, + useImperativeHandle: throwInvalidHookError, + useLayoutEffect: throwInvalidHookError, + useMemo: throwInvalidHookError, + useReducer: throwInvalidHookError, + useRef: throwInvalidHookError, + useState: throwInvalidHookError, + useDebugValue: throwInvalidHookError +}; + +var HooksDispatcherOnMountInDEV = null; +var HooksDispatcherOnUpdateInDEV = null; +var InvalidNestedHooksDispatcherOnMountInDEV = null; +var InvalidNestedHooksDispatcherOnUpdateInDEV = null; + +{ + var warnInvalidContextAccess = function() { + warning$1( + false, + "Context can only be read while React is rendering. " + + "In classes, you can read it in the render method or getDerivedStateFromProps. " + + "In function components, you can read it directly in the function body, but not " + + "inside Hooks like useReducer() or useMemo()." ); - 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.elementType === 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 { - deleteChild(returnFiber, child); + var warnInvalidHookAccess = function() { + warning$1( + false, + "Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. " + + "You can only call Hooks at the top level of your React function. " + + "For more information, see " + + "https://fb.me/rules-of-hooks" + ); + }; + + HooksDispatcherOnMountInDEV = { + readContext: function(context, observedBits) { + return readContext(context, observedBits); + }, + useCallback: function(callback, deps) { + currentHookNameInDev = "useCallback"; + return mountCallback(callback, deps); + }, + useContext: function(context, observedBits) { + currentHookNameInDev = "useContext"; + return mountContext(context, observedBits); + }, + useEffect: function(create, deps) { + currentHookNameInDev = "useEffect"; + return mountEffect(create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + currentHookNameInDev = "useImperativeHandle"; + return mountImperativeHandle(ref, create, deps); + }, + useLayoutEffect: function(create, deps) { + currentHookNameInDev = "useLayoutEffect"; + return mountLayoutEffect(create, deps); + }, + useMemo: function(create, deps) { + currentHookNameInDev = "useMemo"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountMemo(create, deps); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; } - child = child.sibling; + }, + useReducer: function(reducer, initialArg, init) { + currentHookNameInDev = "useReducer"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountReducer(reducer, initialArg, init); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useRef: function(initialValue) { + currentHookNameInDev = "useRef"; + return mountRef(initialValue); + }, + useState: function(initialState) { + currentHookNameInDev = "useState"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountState(initialState); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useDebugValue: function(value, formatterFn) { + currentHookNameInDev = "useDebugValue"; + return mountDebugValue(value, formatterFn); } + }; - 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 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; - } - } else { - deleteChild(returnFiber, child); + HooksDispatcherOnUpdateInDEV = { + readContext: function(context, observedBits) { + return readContext(context, observedBits); + }, + useCallback: function(callback, deps) { + currentHookNameInDev = "useCallback"; + return updateCallback(callback, deps); + }, + useContext: function(context, observedBits) { + currentHookNameInDev = "useContext"; + return updateContext(context, observedBits); + }, + useEffect: function(create, deps) { + currentHookNameInDev = "useEffect"; + return updateEffect(create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + currentHookNameInDev = "useImperativeHandle"; + return updateImperativeHandle(ref, create, deps); + }, + useLayoutEffect: function(create, deps) { + currentHookNameInDev = "useLayoutEffect"; + return updateLayoutEffect(create, deps); + }, + useMemo: function(create, deps) { + currentHookNameInDev = "useMemo"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateMemo(create, deps); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; } - child = child.sibling; + }, + useReducer: function(reducer, initialArg, init) { + currentHookNameInDev = "useReducer"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateReducer(reducer, initialArg, init); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useRef: function(initialValue) { + currentHookNameInDev = "useRef"; + return updateRef(initialValue); + }, + useState: function(initialState) { + currentHookNameInDev = "useState"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateState(initialState); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useDebugValue: function(value, formatterFn) { + currentHookNameInDev = "useDebugValue"; + return updateDebugValue(value, formatterFn); } + }; - var created = createFiberFromPortal( - portal, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } - - // 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; + InvalidNestedHooksDispatcherOnMountInDEV = { + readContext: function(context, observedBits) { + warnInvalidContextAccess(); + return readContext(context, observedBits); + }, + useCallback: function(callback, deps) { + currentHookNameInDev = "useCallback"; + warnInvalidHookAccess(); + return mountCallback(callback, deps); + }, + useContext: function(context, observedBits) { + currentHookNameInDev = "useContext"; + warnInvalidHookAccess(); + return mountContext(context, observedBits); + }, + useEffect: function(create, deps) { + currentHookNameInDev = "useEffect"; + warnInvalidHookAccess(); + return mountEffect(create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + currentHookNameInDev = "useImperativeHandle"; + warnInvalidHookAccess(); + return mountImperativeHandle(ref, create, deps); + }, + useLayoutEffect: function(create, deps) { + currentHookNameInDev = "useLayoutEffect"; + warnInvalidHookAccess(); + return mountLayoutEffect(create, deps); + }, + useMemo: function(create, deps) { + currentHookNameInDev = "useMemo"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountMemo(create, deps); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useReducer: function(reducer, initialArg, init) { + currentHookNameInDev = "useReducer"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountReducer(reducer, initialArg, init); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useRef: function(initialValue) { + currentHookNameInDev = "useRef"; + warnInvalidHookAccess(); + return mountRef(initialValue); + }, + useState: function(initialState) { + currentHookNameInDev = "useState"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountState(initialState); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useDebugValue: function(value, formatterFn) { + currentHookNameInDev = "useDebugValue"; + warnInvalidHookAccess(); + return mountDebugValue(value, formatterFn); } + }; - // Handle object types - var isObject = typeof newChild === "object" && newChild !== null; - - 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 - ) - ); + InvalidNestedHooksDispatcherOnUpdateInDEV = { + readContext: function(context, observedBits) { + warnInvalidContextAccess(); + return readContext(context, observedBits); + }, + useCallback: function(callback, deps) { + currentHookNameInDev = "useCallback"; + warnInvalidHookAccess(); + return updateCallback(callback, deps); + }, + useContext: function(context, observedBits) { + currentHookNameInDev = "useContext"; + warnInvalidHookAccess(); + return updateContext(context, observedBits); + }, + useEffect: function(create, deps) { + currentHookNameInDev = "useEffect"; + warnInvalidHookAccess(); + return updateEffect(create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + currentHookNameInDev = "useImperativeHandle"; + warnInvalidHookAccess(); + return updateImperativeHandle(ref, create, deps); + }, + useLayoutEffect: function(create, deps) { + currentHookNameInDev = "useLayoutEffect"; + warnInvalidHookAccess(); + return updateLayoutEffect(create, deps); + }, + useMemo: function(create, deps) { + currentHookNameInDev = "useMemo"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateMemo(create, deps); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useReducer: function(reducer, initialArg, init) { + currentHookNameInDev = "useReducer"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateReducer(reducer, initialArg, init); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useRef: function(initialValue) { + currentHookNameInDev = "useRef"; + warnInvalidHookAccess(); + return updateRef(initialValue); + }, + useState: function(initialState) { + currentHookNameInDev = "useState"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateState(initialState); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; } + }, + useDebugValue: function(value, formatterFn) { + currentHookNameInDev = "useDebugValue"; + warnInvalidHookAccess(); + return updateDebugValue(value, formatterFn); } + }; +} - if (typeof newChild === "string" || typeof newChild === "number") { - return placeSingleChild( - reconcileSingleTextNode( - returnFiber, - currentFirstChild, - "" + newChild, - expirationTime - ) - ); - } +var commitTime = 0; +var profilerStartTime = -1; - if (isArray(newChild)) { - return reconcileChildrenArray( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ); - } +function getCommitTime() { + return commitTime; +} - if (getIteratorFn(newChild)) { - return reconcileChildrenIterator( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ); - } +function recordCommitTime() { + if (!enableProfilerTimer) { + return; + } + commitTime = now$$1(); +} - if (isObject) { - throwOnInvalidObjectType(returnFiber, newChild); - } +function startProfilerTimer(fiber) { + if (!enableProfilerTimer) { + return; + } - { - 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 FunctionComponent: { - 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" - ); - } - } - } + profilerStartTime = now$$1(); - // Remaining cases are all treated as empty. - return deleteRemainingChildren(returnFiber, currentFirstChild); + if (fiber.actualStartTime < 0) { + fiber.actualStartTime = now$$1(); } - - return reconcileChildFibers; } -var reconcileChildFibers = ChildReconciler(true); -var mountChildFibers = ChildReconciler(false); - -function cloneChildFibers(current$$1, workInProgress) { - invariant( - current$$1 === null || workInProgress.child === current$$1.child, - "Resuming work not yet implemented." - ); +function stopProfilerTimerIfRunning(fiber) { + if (!enableProfilerTimer) { + return; + } + profilerStartTime = -1; +} - if (workInProgress.child === null) { +function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) { + if (!enableProfilerTimer) { 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; + if (profilerStartTime >= 0) { + var elapsedTime = now$$1() - profilerStartTime; + fiber.actualDuration += elapsedTime; + if (overrideBaseTime) { + fiber.selfBaseDuration = elapsedTime; + } + profilerStartTime = -1; } - newChild.sibling = null; } // The deepest Fiber on the stack involved in a hydration context. @@ -10776,6 +10603,8 @@ function resetHydrationState() { var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner; +var didReceiveUpdate = false; + var didWarnAboutBadClass = void 0; var didWarnAboutContextTypeOnFunctionComponent = void 0; var didWarnAboutGetDerivedStateOnFunctionComponent = void 0; @@ -10885,14 +10714,45 @@ function updateForwardRef( // The rest is a fork of updateFunctionComponent var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - prepareToUseHooks(current$$1, workInProgress, renderExpirationTime); { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); - nextChildren = render(nextProps, ref); + nextChildren = renderWithHooks( + current$$1, + workInProgress, + render, + nextProps, + ref, + renderExpirationTime + ); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + // Only double-render components with Hooks + if (workInProgress.memoizedState !== null) { + nextChildren = renderWithHooks( + current$$1, + workInProgress, + render, + nextProps, + ref, + renderExpirationTime + ); + } + } setCurrentPhase(null); } - nextChildren = finishHooks(render, nextProps, nextChildren, ref); + + if (current$$1 !== null && !didReceiveUpdate) { + bailoutHooks(current$$1, workInProgress, renderExpirationTime); + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } // React DevTools reads this flag. workInProgress.effectTag |= PerformedWork; @@ -11044,17 +10904,20 @@ function updateSimpleMemoComponent( // Inner propTypes will be validated in the function component path. } } - if (current$$1 !== null && updateExpirationTime < renderExpirationTime) { + if (current$$1 !== null) { var prevProps = current$$1.memoizedProps; if ( shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref ) { - return bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); + didReceiveUpdate = false; + if (updateExpirationTime < renderExpirationTime) { + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } } } return updateFunctionComponent( @@ -11143,14 +11006,45 @@ function updateFunctionComponent( var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - prepareToUseHooks(current$$1, workInProgress, renderExpirationTime); { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); - nextChildren = Component(nextProps, context); + nextChildren = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + context, + renderExpirationTime + ); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + // Only double-render components with Hooks + if (workInProgress.memoizedState !== null) { + nextChildren = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + context, + renderExpirationTime + ); + } + } setCurrentPhase(null); } - nextChildren = finishHooks(Component, nextProps, nextChildren, context); + + if (current$$1 !== null && !didReceiveUpdate) { + bailoutHooks(current$$1, workInProgress, renderExpirationTime); + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } // React DevTools reads this flag. workInProgress.effectTag |= PerformedWork; @@ -11485,7 +11379,7 @@ function updateHostComponent(current$$1, workInProgress, renderExpirationTime) { shouldDeprioritizeSubtree(type, nextProps) ) { // Schedule this fiber to re-render at offscreen priority. Then bailout. - workInProgress.expirationTime = Never; + workInProgress.expirationTime = workInProgress.childExpirationTime = Never; return null; } @@ -11538,6 +11432,9 @@ function mountLazyComponent( var child = void 0; switch (resolvedTag) { case FunctionComponent: { + { + validateFunctionComponentInDev(workInProgress, Component); + } child = updateFunctionComponent( null, workInProgress, @@ -11698,7 +11595,6 @@ function mountIndeterminateComponent( var context = getMaskedContext(workInProgress, unmaskedContext); prepareToReadContext(workInProgress, renderExpirationTime); - prepareToUseHooks(null, workInProgress, renderExpirationTime); var value = void 0; @@ -11726,7 +11622,14 @@ function mountIndeterminateComponent( } ReactCurrentOwner$3.current = workInProgress; - value = Component(props, context); + value = renderWithHooks( + null, + workInProgress, + Component, + props, + context, + renderExpirationTime + ); } // React DevTools reads this flag. workInProgress.effectTag |= PerformedWork; @@ -11780,7 +11683,25 @@ function mountIndeterminateComponent( } else { // Proceed under the assumption that this is a function component workInProgress.tag = FunctionComponent; - value = finishHooks(Component, props, value, context); + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + // Only double-render components with Hooks + if (workInProgress.memoizedState !== null) { + value = renderWithHooks( + null, + workInProgress, + Component, + props, + context, + renderExpirationTime + ); + } + } + } reconcileChildren(null, workInProgress, value, renderExpirationTime); { validateFunctionComponentInDev(workInProgress, Component); @@ -11816,7 +11737,8 @@ function validateFunctionComponentInDev(workInProgress, Component) { warning$1( false, "Function components cannot be given refs. " + - "Attempts to access this ref will fail.%s", + "Attempts to access this ref will fail. " + + "Did you mean to use React.forwardRef()?%s", info ); } @@ -12105,6 +12027,7 @@ function updateSuspenseComponent( ); } } + workInProgress.stateNode = current$$1.stateNode; } workInProgress.memoizedState = nextState; @@ -12275,6 +12198,10 @@ function updateContextConsumer( return workInProgress.child; } +function markWorkInProgressReceivedUpdate() { + didReceiveUpdate = true; +} + function bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -12284,7 +12211,7 @@ function bailoutOnAlreadyFinishedWork( if (current$$1 !== null) { // Reuse previous context list - workInProgress.firstContextDependency = current$$1.firstContextDependency; + workInProgress.contextDependencies = current$$1.contextDependencies; } if (enableProfilerTimer) { @@ -12313,11 +12240,13 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { if (current$$1 !== null) { var oldProps = current$$1.memoizedProps; var newProps = workInProgress.pendingProps; - if ( - oldProps === newProps && - !hasContextChanged() && - updateExpirationTime < renderExpirationTime - ) { + + if (oldProps !== newProps || hasContextChanged()) { + // If props or context changed, mark the fiber as having performed work. + // This may be unset if the props are determined to be equal later (memo). + didReceiveUpdate = true; + } else if (updateExpirationTime < renderExpirationTime) { + didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering // the begin phase. There's still some bookkeeping we that needs to be done // in this optimized path, mostly pushing stuff onto the stack. @@ -12399,6 +12328,8 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); } + } else { + didReceiveUpdate = false; } // Before entering the begin phase, clear the expiration time. @@ -12558,20 +12489,900 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { return mountIncompleteClassComponent( current$$1, workInProgress, - _Component3, - _resolvedProps4, - renderExpirationTime + _Component3, + _resolvedProps4, + renderExpirationTime + ); + } + default: + invariant( + false, + "Unknown unit of work tag. This error is likely caused by a bug in " + + "React. Please file an issue." + ); + } +} + +var valueCursor = createCursor(null); + +var rendererSigil = void 0; +{ + // Use this to detect multiple renderers using the same context + rendererSigil = {}; +} + +var currentlyRenderingFiber = null; +var lastContextDependency = null; +var lastContextWithAllBitsObserved = null; + +var isDisallowedContextReadInDEV = false; + +function resetContextDependences() { + // This is called right before React yields execution, to ensure `readContext` + // cannot be called outside the render phase. + currentlyRenderingFiber = null; + lastContextDependency = null; + lastContextWithAllBitsObserved = null; + { + isDisallowedContextReadInDEV = false; + } +} + +function enterDisallowedContextReadInDEV() { + { + isDisallowedContextReadInDEV = true; + } +} + +function exitDisallowedContextReadInDEV() { + { + isDisallowedContextReadInDEV = false; + } +} + +function pushProvider(providerFiber, nextValue) { + var context = providerFiber.type._context; + + if (isPrimaryRenderer) { + push(valueCursor, context._currentValue, providerFiber); + + context._currentValue = nextValue; + { + !( + context._currentRenderer === undefined || + context._currentRenderer === null || + context._currentRenderer === rendererSigil + ) + ? warningWithoutStack$1( + false, + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." + ) + : void 0; + context._currentRenderer = rendererSigil; + } + } else { + push(valueCursor, context._currentValue2, providerFiber); + + context._currentValue2 = nextValue; + { + !( + context._currentRenderer2 === undefined || + context._currentRenderer2 === null || + context._currentRenderer2 === rendererSigil + ) + ? warningWithoutStack$1( + false, + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." + ) + : void 0; + context._currentRenderer2 = rendererSigil; + } + } +} + +function popProvider(providerFiber) { + var currentValue = valueCursor.current; + + pop(valueCursor, providerFiber); + + var context = providerFiber.type._context; + if (isPrimaryRenderer) { + context._currentValue = currentValue; + } else { + context._currentValue2 = currentValue; + } +} + +function calculateChangedBits(context, newValue, oldValue) { + if (is(oldValue, newValue)) { + // No change + return 0; + } else { + var changedBits = + typeof context._calculateChangedBits === "function" + ? context._calculateChangedBits(oldValue, newValue) + : maxSigned31BitInt; + + { + !((changedBits & maxSigned31BitInt) === changedBits) + ? warning$1( + false, + "calculateChangedBits: Expected the return value to be a " + + "31-bit integer. Instead received: %s", + changedBits + ) + : void 0; + } + return changedBits | 0; + } +} + +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. + var list = fiber.contextDependencies; + if (list !== null) { + nextFiber = fiber.child; + + var dependency = list.first; + while (dependency !== null) { + // Check if the context matches. + if ( + dependency.context === context && + (dependency.observedBits & changedBits) !== 0 + ) { + // Match! Schedule an update on this fiber. + + if (fiber.tag === ClassComponent) { + // Schedule a force update on the work-in-progress. + var update = createUpdate(renderExpirationTime); + update.tag = ForceUpdate; + // TODO: Because we don't have a work-in-progress, this will add the + // update to the current fiber, too, which means it will persist even if + // this render is thrown away. Since it's a race condition, not sure it's + // worth fixing. + enqueueUpdate(fiber, update); + } + + if (fiber.expirationTime < renderExpirationTime) { + fiber.expirationTime = renderExpirationTime; + } + var alternate = fiber.alternate; + if ( + alternate !== null && + alternate.expirationTime < renderExpirationTime + ) { + alternate.expirationTime = renderExpirationTime; + } + // Update the child expiration time of all the ancestors, including + // the alternates. + var node = fiber.return; + while (node !== null) { + alternate = node.alternate; + if (node.childExpirationTime < renderExpirationTime) { + node.childExpirationTime = renderExpirationTime; + if ( + alternate !== null && + alternate.childExpirationTime < renderExpirationTime + ) { + alternate.childExpirationTime = renderExpirationTime; + } + } else if ( + alternate !== null && + alternate.childExpirationTime < renderExpirationTime + ) { + alternate.childExpirationTime = renderExpirationTime; + } else { + // Neither alternate was updated, which means the rest of the + // ancestor path already has sufficient priority. + break; + } + node = node.return; + } + + // Mark the expiration time on the list, too. + if (list.expirationTime < renderExpirationTime) { + list.expirationTime = renderExpirationTime; + } + + // Since we already found a match, we can stop traversing the + // dependency list. + break; + } + dependency = dependency.next; + } + } else if (fiber.tag === ContextProvider) { + // Don't scan deeper if this is a matching provider + nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + } else { + // Traverse down. + nextFiber = fiber.child; + } + + if (nextFiber !== null) { + // Set the return pointer of the child to the work-in-progress fiber. + nextFiber.return = fiber; + } else { + // No child. Traverse to next sibling. + nextFiber = fiber; + while (nextFiber !== null) { + if (nextFiber === workInProgress) { + // We're back to the root of this subtree. Exit. + nextFiber = null; + break; + } + var sibling = nextFiber.sibling; + if (sibling !== null) { + // Set the return pointer of the sibling to the work-in-progress fiber. + sibling.return = nextFiber.return; + nextFiber = sibling; + break; + } + // No more siblings. Traverse up. + nextFiber = nextFiber.return; + } + } + fiber = nextFiber; + } +} + +function prepareToReadContext(workInProgress, renderExpirationTime) { + currentlyRenderingFiber = workInProgress; + lastContextDependency = null; + lastContextWithAllBitsObserved = null; + + var currentDependencies = workInProgress.contextDependencies; + if ( + currentDependencies !== null && + currentDependencies.expirationTime >= renderExpirationTime + ) { + // Context list has a pending update. Mark that this fiber performed work. + markWorkInProgressReceivedUpdate(); + } + + // Reset the work-in-progress list + workInProgress.contextDependencies = null; +} + +function readContext(context, observedBits) { + { + // This warning would fire if you read context inside a Hook like useMemo. + // Unlike the class check below, it's not enforced in production for perf. + !!isDisallowedContextReadInDEV + ? warning$1( + false, + "Context can only be read while React is rendering. " + + "In classes, you can read it in the render method or getDerivedStateFromProps. " + + "In function components, you can read it directly in the function body, but not " + + "inside Hooks like useReducer() or useMemo()." + ) + : void 0; + } + + if (lastContextWithAllBitsObserved === context) { + // Nothing to do. We already observe everything in this context. + } else if (observedBits === false || observedBits === 0) { + // Do not observe any updates. + } else { + var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types. + if ( + typeof observedBits !== "number" || + observedBits === maxSigned31BitInt + ) { + // Observe all updates. + lastContextWithAllBitsObserved = context; + resolvedObservedBits = maxSigned31BitInt; + } else { + resolvedObservedBits = observedBits; + } + + var contextItem = { + context: context, + observedBits: resolvedObservedBits, + next: null + }; + + if (lastContextDependency === null) { + invariant( + currentlyRenderingFiber !== null, + "Context can only be read while React is rendering. " + + "In classes, you can read it in the render method or getDerivedStateFromProps. " + + "In function components, you can read it directly in the function body, but not " + + "inside Hooks like useReducer() or useMemo()." + ); + + // This is the first dependency for this component. Create a new list. + lastContextDependency = contextItem; + currentlyRenderingFiber.contextDependencies = { + first: contextItem, + expirationTime: NoWork + }; + } else { + // Append a new context item. + lastContextDependency = lastContextDependency.next = contextItem; + } + } + return isPrimaryRenderer ? context._currentValue : context._currentValue2; +} + +// 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 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 = { + 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 = { + 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) { + // 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; + } +} + +function enqueueUpdate(fiber, update) { + // 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); + } 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); + appendUpdateToQueue(queue2, update); + } 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); + // 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 + ) { + warningWithoutStack$1( + 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) { + // 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; + } +} + +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 + { + enterDisallowedContextReadInDEV(); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + _payload.call(instance, prevState, nextProps); + } + } + var nextState = _payload.call(instance, prevState, nextProps); + { + exitDisallowedContextReadInDEV(); + } + return nextState; + } + // 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 + { + enterDisallowedContextReadInDEV(); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + _payload2.call(instance, prevState, nextProps); + } + } + partialState = _payload2.call(instance, prevState, nextProps); + { + exitDisallowedContextReadInDEV(); + } + } 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; + + 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 < 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 < _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; + } + } } - default: - invariant( - false, - "Unknown unit of work tag. This error is likely caused by a bug in " + - "React. Please file an issue." - ); + 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; + } + + queue.baseState = newBaseState; + queue.firstUpdate = newFirstUpdate; + queue.firstCapturedUpdate = newFirstCapturedUpdate; + + // Set the remaining expiration time to be whatever is remaining in the queue. + // This should be fine because the only two other things that contribute to + // expiration time are props and context. We're already in the middle of the + // begin phase by the time we start processing the queue, so we've already + // dealt with the props. Context in components that specify + // shouldComponentUpdate is tricky; but we'll have to account for + // that regardless. + workInProgress.expirationTime = newExpirationTime; + workInProgress.memoizedState = resultState; + + { + 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; + } + + // Commit the effects + commitUpdateEffects(finishedQueue.firstEffect, instance); + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + + commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; +} + +function commitUpdateEffects(effect, instance) { + while (effect !== null) { + var _callback3 = effect.callback; + if (_callback3 !== null) { + effect.callback = null; + callCallback(_callback3, instance); + } + effect = effect.nextEffect; } } +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: getStackByFiberInDevAndProd(source) + }; +} + function markUpdate(workInProgress) { // Tag the fiber with an update effect. This turns a Placement into // a PlacementAndUpdate. @@ -13192,18 +14003,10 @@ function completeWork(current, workInProgress, renderExpirationTime) { } } - // The children either timed out after previously being visible, or - // were restored after previously being hidden. Schedule an effect - // to update their visiblity. - if ( - // - nextDidTimeout !== prevDidTimeout || - // Outside concurrent mode, the primary children commit in an - // inconsistent state, even if they are hidden. So if they are hidden, - // we need to schedule an effect to re-hide them, just in case. - ((workInProgress.effectTag & ConcurrentMode) === NoContext && - nextDidTimeout) - ) { + if (nextDidTimeout || prevDidTimeout) { + // If the children are hidden, or if they were previous hidden, schedule + // an effect to toggle their visibility. This is also used to attach a + // retry listener to the promise. workInProgress.effectTag |= Update; } break; @@ -13246,7 +14049,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { return null; } -function shouldCaptureSuspense(current, workInProgress) { +function shouldCaptureSuspense(workInProgress) { // In order to capture, the Suspense component must have a fallback prop. if (workInProgress.memoizedProps.fallback === undefined) { return false; @@ -13378,6 +14181,8 @@ var didWarnAboutUndefinedSnapshotBeforeUpdate = null; didWarnAboutUndefinedSnapshotBeforeUpdate = new Set(); } +var PossiblyWeakSet = typeof WeakSet === "function" ? WeakSet : Set; + function logError(boundary, errorInfo) { var source = errorInfo.source; var stack = errorInfo.stack; @@ -13556,9 +14361,6 @@ function commitBeforeMutationLifeCycles(current$$1, finishedWork) { } function commitHookEffectList(unmountTag, mountTag, finishedWork) { - if (!enableHooks) { - return; - } var updateQueue = finishedWork.updateQueue; var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null; if (lastEffect !== null) { @@ -13568,42 +14370,49 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { if ((effect.tag & unmountTag) !== NoEffect$1) { // Unmount var destroy = effect.destroy; - effect.destroy = null; - if (destroy !== null) { + effect.destroy = undefined; + if (destroy !== undefined) { destroy(); } } if ((effect.tag & mountTag) !== NoEffect$1) { // Mount var create = effect.create; - var _destroy = create(); - if (typeof _destroy !== "function") { - { - if (_destroy !== null && _destroy !== undefined) { - warningWithoutStack$1( - false, - "useEffect function must return a cleanup function or " + - "nothing.%s%s", - typeof _destroy.then === "function" - ? "\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. " + - "Instead, you may write an async function separately " + - "and then call it from inside the effect:\n\n" + - "async function fetchComment(commentId) {\n" + - " // You can await here\n" + - "}\n\n" + - "useEffect(() => {\n" + - " fetchComment(commentId);\n" + - "}, [commentId]);\n\n" + - "In the future, React will provide a more idiomatic solution for data fetching " + - "that doesn't involve writing effects manually." - : "", - getStackByFiberInDevAndProd(finishedWork) - ); + effect.destroy = create(); + + { + var _destroy = effect.destroy; + if (_destroy !== undefined && typeof _destroy !== "function") { + var addendum = void 0; + if (_destroy === null) { + addendum = + " You returned null. If your effect does not require clean " + + "up, return undefined (or nothing)."; + } else if (typeof _destroy.then === "function") { + addendum = + "\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. " + + "Instead, you may write an async function separately " + + "and then call it from inside the effect:\n\n" + + "async function fetchComment(commentId) {\n" + + " // You can await here\n" + + "}\n\n" + + "useEffect(() => {\n" + + " fetchComment(commentId);\n" + + "}, [commentId]);\n\n" + + "In the future, React will provide a more idiomatic solution for data fetching " + + "that doesn't involve writing effects manually."; + } else { + addendum = " You returned: " + _destroy; } + warningWithoutStack$1( + false, + "An Effect function must not return anything besides a function, " + + "which is used for clean-up.%s%s", + addendum, + getStackByFiberInDevAndProd(finishedWork) + ); } - _destroy = null; } - effect.destroy = _destroy; } effect = effect.next; } while (effect !== firstEffect); @@ -13957,7 +14766,7 @@ function commitUnmount(current$$1) { var effect = firstEffect; do { var destroy = effect.destroy; - if (destroy !== null) { + if (destroy !== undefined) { safelyCallDestroy(current$$1, destroy); } effect = effect.next; @@ -14435,6 +15244,30 @@ function commitWork(current$$1, finishedWork) { if (primaryChildParent !== null) { hideOrUnhideAllChildren(primaryChildParent, newDidTimeout); } + + // If this boundary just timed out, then it will have a set of thenables. + // For each thenable, attach a listener so that when it resolves, React + // attempts to re-render the boundary in the primary (pre-timeout) state. + var thenables = finishedWork.updateQueue; + if (thenables !== null) { + finishedWork.updateQueue = null; + var retryCache = finishedWork.stateNode; + if (retryCache === null) { + retryCache = finishedWork.stateNode = new PossiblyWeakSet(); + } + thenables.forEach(function(thenable) { + // Memoize using the boundary fiber to prevent redundant listeners. + var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable); + if (enableSchedulerTracing) { + retry = tracing.unstable_wrap(retry); + } + if (!retryCache.has(thenable)) { + retryCache.add(thenable); + thenable.then(retry, retry); + } + }); + } + return; } case IncompleteClassComponent: { @@ -14457,6 +15290,8 @@ function commitResetTextContent(current$$1) { resetTextContent(current$$1.stateNode); } +var PossiblyWeakMap = typeof WeakMap === "function" ? WeakMap : Map; + function createRootErrorUpdate(fiber, errorInfo, expirationTime) { var update = createUpdate(expirationTime); // Unmount the root by rendering null. @@ -14582,29 +15417,19 @@ function throwException( do { if ( _workInProgress.tag === SuspenseComponent && - shouldCaptureSuspense(_workInProgress.alternate, _workInProgress) + shouldCaptureSuspense(_workInProgress) ) { // Found the nearest boundary. - // If the boundary is not in concurrent mode, we should not suspend, and - // likewise, when the promise resolves, we should ping synchronously. - var pingTime = - (_workInProgress.mode & ConcurrentMode) === NoEffect - ? Sync - : renderExpirationTime; - - // Attach a listener to the promise to "ping" the root and retry. - var onResolveOrReject = retrySuspendedRoot.bind( - null, - root, - _workInProgress, - sourceFiber, - pingTime - ); - if (enableSchedulerTracing) { - onResolveOrReject = tracing.unstable_wrap(onResolveOrReject); + // Stash the promise on the boundary fiber. If the boundary times out, we'll + var thenables = _workInProgress.updateQueue; + if (thenables === null) { + var updateQueue = new Set(); + updateQueue.add(thenable); + _workInProgress.updateQueue = updateQueue; + } else { + thenables.add(thenable); } - thenable.then(onResolveOrReject, onResolveOrReject); // If the boundary is outside of concurrent mode, we should *not* // suspend the commit. Pretend as if the suspended component rendered @@ -14623,18 +15448,25 @@ function throwException( sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete); if (sourceFiber.tag === ClassComponent) { - var _current = sourceFiber.alternate; - if (_current === null) { + var currentSourceFiber = sourceFiber.alternate; + if (currentSourceFiber === null) { // This is a new mount. Change the tag so it's not mistaken for a // completed class component. For example, we should not call // componentWillUnmount if it is deleted. sourceFiber.tag = IncompleteClassComponent; + } else { + // When we try rendering again, we should not reuse the current fiber, + // since it's known to be in an inconsistent state. Use a force updte to + // prevent a bail out. + var update = createUpdate(Sync); + update.tag = ForceUpdate; + enqueueUpdate(sourceFiber, update); } } - // The source fiber did not complete. Mark it with the current - // render priority to indicate that it still has pending work. - sourceFiber.expirationTime = renderExpirationTime; + // The source fiber did not complete. Mark it with Sync priority to + // indicate that it still has pending work. + sourceFiber.expirationTime = Sync; // Exit without suspending. return; @@ -14643,9 +15475,40 @@ function throwException( // Confirmed that the boundary is in a concurrent mode tree. Continue // with the normal suspend path. + // Attach a listener to the promise to "ping" the root and retry. But + // only if one does not already exist for the current render expiration + // time (which acts like a "thread ID" here). + var pingCache = root.pingCache; + var threadIDs = void 0; + if (pingCache === null) { + pingCache = root.pingCache = new PossiblyWeakMap(); + threadIDs = new Set(); + pingCache.set(thenable, threadIDs); + } else { + threadIDs = pingCache.get(thenable); + if (threadIDs === undefined) { + threadIDs = new Set(); + pingCache.set(thenable, threadIDs); + } + } + if (!threadIDs.has(renderExpirationTime)) { + // Memoize using the thread ID to prevent redundant listeners. + threadIDs.add(renderExpirationTime); + var ping = pingSuspendedRoot.bind( + null, + root, + thenable, + renderExpirationTime + ); + if (enableSchedulerTracing) { + ping = tracing.unstable_wrap(ping); + } + thenable.then(ping, ping); + } + var absoluteTimeoutMs = void 0; if (earliestTimeoutMs === -1) { - // If no explicit threshold is given, default to an abitrarily large + // If no explicit threshold is given, default to an arbitrarily large // value. The actual size doesn't matter because the threshold for the // whole tree will be clamped to the expiration time. absoluteTimeoutMs = maxSigned31BitInt; @@ -14710,12 +15573,12 @@ function throwException( var _errorInfo = value; workInProgress.effectTag |= ShouldCapture; workInProgress.expirationTime = renderExpirationTime; - var update = createRootErrorUpdate( + var _update = createRootErrorUpdate( workInProgress, _errorInfo, renderExpirationTime ); - enqueueCapturedUpdate(workInProgress, update); + enqueueCapturedUpdate(workInProgress, _update); return; } case ClassComponent: @@ -14733,12 +15596,12 @@ function throwException( workInProgress.effectTag |= ShouldCapture; workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state - var _update = createClassErrorUpdate( + var _update2 = createClassErrorUpdate( workInProgress, errorInfo, renderExpirationTime ); - enqueueCapturedUpdate(workInProgress, _update); + enqueueCapturedUpdate(workInProgress, _update2); return; } break; @@ -14828,22 +15691,7 @@ function unwindInterruptedWork(interruptedWork) { } } -var Dispatcher = { - readContext: readContext, - useCallback: useCallback, - useContext: useContext, - useEffect: useEffect, - useImperativeMethods: useImperativeMethods, - useLayoutEffect: useLayoutEffect, - useMemo: useMemo, - useReducer: useReducer, - useRef: useRef, - useState: useState -}; -var DispatcherWithoutHooks = { - readContext: readContext -}; - +var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner; var didWarnAboutStateTransition = void 0; @@ -14916,11 +15764,6 @@ if (enableSchedulerTracing) { }; } -// 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. @@ -15153,6 +15996,9 @@ function commitAllLifeCycles(finishedRoot, committedExpirationTime) { } } while (nextEffect !== null) { + { + setCurrentFiber(nextEffect); + } var effectTag = nextEffect.effectTag; if (effectTag & (Update | Callback)) { @@ -15171,12 +16017,15 @@ function commitAllLifeCycles(finishedRoot, committedExpirationTime) { commitAttachRef(nextEffect); } - if (enableHooks && effectTag & Passive) { + if (effectTag & Passive) { rootWithPendingPassiveEffects = finishedRoot; } nextEffect = nextEffect.nextEffect; } + { + resetCurrentFiber(); + } } function commitPassiveEffects(root, firstEffect) { @@ -15190,6 +16039,10 @@ function commitPassiveEffects(root, firstEffect) { var effect = firstEffect; do { + { + setCurrentFiber(effect); + } + if (effect.effectTag & Passive) { var didError = false; var error = void 0; @@ -15206,6 +16059,9 @@ function commitPassiveEffects(root, firstEffect) { } effect = effect.nextEffect; } while (effect !== null); + { + resetCurrentFiber(); + } isRendering = previousIsRendering; @@ -15232,8 +16088,10 @@ function markLegacyErrorBoundaryAsFailed(instance) { } function flushPassiveEffects() { + if (passiveEffectCallbackHandle !== null) { + cancelPassiveEffects(passiveEffectCallbackHandle); + } if (passiveEffectCallback !== null) { - scheduler.unstable_cancelCallback(passiveEffectCallbackHandle); // We call the scheduled callback instead of commitPassiveEffects directly // to ensure tracing works correctly. passiveEffectCallback(); @@ -15407,11 +16265,7 @@ function commitRoot(root, finishedWork) { } } - if ( - enableHooks && - firstEffect !== null && - rootWithPendingPassiveEffects !== null - ) { + if (firstEffect !== null && rootWithPendingPassiveEffects !== null) { // This commit included a passive effect. These do not need to fire until // after the next paint. Schedule an callback to fire them in an async // event. To ensure serial execution, the callback will be flushed early if @@ -15423,7 +16277,12 @@ function commitRoot(root, finishedWork) { // here because that code is still in flux. callback = tracing.unstable_wrap(callback); } - passiveEffectCallbackHandle = scheduler.unstable_scheduleCallback(callback); + passiveEffectCallbackHandle = scheduler.unstable_runWithPriority( + scheduler.unstable_NormalPriority, + function() { + return schedulePassiveEffects(callback); + } + ); passiveEffectCallback = callback; } @@ -15842,11 +16701,8 @@ function renderRoot(root, isYieldy) { flushPassiveEffects(); isWorking = true; - if (enableHooks) { - ReactCurrentOwner$2.currentDispatcher = Dispatcher; - } else { - ReactCurrentOwner$2.currentDispatcher = DispatcherWithoutHooks; - } + var previousDispatcher = ReactCurrentDispatcher.current; + ReactCurrentDispatcher.current = ContextOnlyDispatcher; var expirationTime = root.nextExpirationTimeToWorkOn; @@ -15900,7 +16756,7 @@ function renderRoot(root, isYieldy) { subscriber.onWorkStarted(interactions, threadID); } catch (error) { // Work thrown by an interaction tracing subscriber should be rethrown, - // But only once it's safe (to avoid leaveing the scheduler in an invalid state). + // But only once it's safe (to avoid leaving the scheduler in an invalid state). // Store the error for now and we'll re-throw in finishRendering(). if (!hasUnhandledError) { hasUnhandledError = true; @@ -16007,7 +16863,7 @@ function renderRoot(root, isYieldy) { // We're done performing work. Time to clean up. isWorking = false; - ReactCurrentOwner$2.currentDispatcher = null; + ReactCurrentDispatcher.current = previousDispatcher; resetContextDependences(); resetHooks(); @@ -16191,52 +17047,58 @@ function computeThreadID(expirationTime, interactionThreadID) { } function computeExpirationForFiber(currentTime, fiber) { + var priorityLevel = scheduler.unstable_getCurrentPriorityLevel(); + 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; - } + if ((fiber.mode & ConcurrentMode) === NoContext) { + // Outside of concurrent mode, updates are always synchronous. + expirationTime = Sync; + } else if (isWorking && !isCommitting$1) { + // During render phase, updates expire during as the current render. + expirationTime = nextRenderExpirationTime; } else { - // No explicit expiration context was set, and we're not currently - // performing work. Calculate a new expiration time. - if (fiber.mode & ConcurrentMode) { - if (isBatchingInteractiveUpdates) { - // This is an interactive update + switch (priorityLevel) { + case scheduler.unstable_ImmediatePriority: + expirationTime = Sync; + break; + case scheduler.unstable_UserBlockingPriority: expirationTime = computeInteractiveExpiration(currentTime); - } else { - // This is an async update + break; + case scheduler.unstable_NormalPriority: + // This is a normal, concurrent update expirationTime = computeAsyncExpiration(currentTime); - } - // If we're in the middle of rendering a tree, do not update at the same - // expiration time that is already rendering. - if (nextRoot !== null && expirationTime === nextRenderExpirationTime) { - expirationTime -= 1; - } - } else { - // This is a sync update - expirationTime = Sync; + break; + case scheduler.unstable_LowPriority: + case scheduler.unstable_IdlePriority: + expirationTime = Never; + break; + default: + invariant( + false, + "Unknown priority level. This error is likely caused by a bug in " + + "React. Please file an issue." + ); } - } - 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 ( - lowestPriorityPendingInteractiveExpirationTime === NoWork || - expirationTime < lowestPriorityPendingInteractiveExpirationTime - ) { - lowestPriorityPendingInteractiveExpirationTime = expirationTime; + + // If we're in the middle of rendering a tree, do not update at the same + // expiration time that is already rendering. + if (nextRoot !== null && expirationTime === nextRenderExpirationTime) { + expirationTime -= 1; } } + + // Keep track of the lowest pending interactive expiration time. This + // allows us to synchronously flush all interactive updates + // when needed. + // TODO: Move this to renderer? + if ( + priorityLevel === scheduler.unstable_UserBlockingPriority && + (lowestPriorityPendingInteractiveExpirationTime === NoWork || + expirationTime < lowestPriorityPendingInteractiveExpirationTime) + ) { + lowestPriorityPendingInteractiveExpirationTime = expirationTime; + } + return expirationTime; } @@ -16254,56 +17116,54 @@ function renderDidError() { nextRenderDidError = true; } -function retrySuspendedRoot(root, boundaryFiber, sourceFiber, suspendedTime) { - var retryTime = void 0; +function pingSuspendedRoot(root, thenable, pingTime) { + // A promise that previously suspended React from committing has resolved. + // If React is still suspended, try again at the previous level (pingTime). - if (isPriorityLevelSuspended(root, suspendedTime)) { - // Ping at the original level - retryTime = suspendedTime; - - markPingedPriorityLevel(root, retryTime); - } else { - // Suspense already timed out. Compute a new expiration time - var currentTime = requestCurrentTime(); - retryTime = computeExpirationForFiber(currentTime, boundaryFiber); - markPendingPriorityLevel(root, retryTime); + var pingCache = root.pingCache; + if (pingCache !== null) { + // The thenable resolved, so we no longer need to memoize, because it will + // never be thrown again. + pingCache.delete(thenable); } - // TODO: If the suspense fiber has already rendered the primary children - // without suspending (that is, all of the promises have already resolved), - // we should not trigger another update here. One case this happens is when - // we are in sync mode and a single promise is thrown both on initial render - // and on update; we attach two .then(retrySuspendedRoot) callbacks and each - // one performs Sync work, rerendering the Suspense. - - if ((boundaryFiber.mode & ConcurrentMode) !== NoContext) { - if (root === nextRoot && nextRenderExpirationTime === suspendedTime) { - // Received a ping at the same priority level at which we're currently - // rendering. Restart from the root. - nextRoot = null; + if (nextRoot !== null && nextRenderExpirationTime === pingTime) { + // Received a ping at the same priority level at which we're currently + // rendering. Restart from the root. + nextRoot = null; + } else { + // Confirm that the root is still suspended at this level. Otherwise exit. + if (isPriorityLevelSuspended(root, pingTime)) { + // Ping at the original level + markPingedPriorityLevel(root, pingTime); + var rootExpirationTime = root.expirationTime; + if (rootExpirationTime !== NoWork) { + requestWork(root, rootExpirationTime); + } } } +} - scheduleWorkToRoot(boundaryFiber, retryTime); - if ((boundaryFiber.mode & ConcurrentMode) === NoContext) { - // Outside of concurrent mode, we must schedule an update on the source - // fiber, too, since it already committed in an inconsistent state and - // therefore does not have any pending work. - scheduleWorkToRoot(sourceFiber, retryTime); - var sourceTag = sourceFiber.tag; - if (sourceTag === ClassComponent && sourceFiber.stateNode !== null) { - // When we try rendering again, we should not reuse the current fiber, - // since it's known to be in an inconsistent state. Use a force updte to - // prevent a bail out. - var update = createUpdate(retryTime); - update.tag = ForceUpdate; - enqueueUpdate(sourceFiber, update); - } +function retryTimedOutBoundary(boundaryFiber, thenable) { + // The boundary fiber (a Suspense component) previously timed out and was + // rendered in its fallback state. One of the promises that suspended it has + // resolved, which means at least part of the tree was likely unblocked. Try + var retryCache = boundaryFiber.stateNode; + if (retryCache !== null) { + // The thenable resolved, so we no longer need to memoize, because it will + // never be thrown again. + retryCache.delete(thenable); } - var rootExpirationTime = root.expirationTime; - if (rootExpirationTime !== NoWork) { - requestWork(root, rootExpirationTime); + var currentTime = requestCurrentTime(); + var retryTime = computeExpirationForFiber(currentTime, boundaryFiber); + var root = scheduleWorkToRoot(boundaryFiber, retryTime); + if (root !== null) { + markPendingPriorityLevel(root, retryTime); + var rootExpirationTime = root.expirationTime; + if (rootExpirationTime !== NoWork) { + requestWork(root, rootExpirationTime); + } } } @@ -16393,6 +17253,25 @@ function scheduleWorkToRoot(fiber, expirationTime) { return root; } +function warnIfNotCurrentlyBatchingInDev(fiber) { + { + if (isRendering === false && isBatchingUpdates === false) { + warningWithoutStack$1( + false, + "An update to %s inside a test was not wrapped in act(...).\n\n" + + "When testing, code that causes React state updates should be wrapped into act(...):\n\n" + + "act(() => {\n" + + " /* fire events that update state */\n" + + "});\n" + + "/* assert on the output */\n\n" + + "This ensures that you're testing the behavior the user would see in the browser." + + " Learn more at https://fb.me/react-wrap-tests-with-act", + getComponentName(fiber.type) + ); + } + } +} + function scheduleWork(fiber, expirationTime) { var root = scheduleWorkToRoot(fiber, expirationTime); if (root === null) { @@ -16464,7 +17343,6 @@ var unhandledError = null; var isBatchingUpdates = false; var isUnbatchingUpdates = false; -var isBatchingInteractiveUpdates = false; var completedBatches = null; @@ -16980,7 +17858,12 @@ function completeRoot$1(root, finishedWork, expirationTime) { lastCommittedRootDuringThisBatch = root; nestedUpdateCount = 0; } - commitRoot(root, finishedWork); + scheduler.unstable_runWithPriority( + scheduler.unstable_ImmediatePriority, + function() { + commitRoot(root, finishedWork); + } + ); } function onUncaughtError(error) { @@ -17014,9 +17897,6 @@ function batchedUpdates$1(fn, a) { } 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 @@ -17030,14 +17910,16 @@ function interactiveUpdates$1(fn, a, b) { performWork(lowestPriorityPendingInteractiveExpirationTime, false); lowestPriorityPendingInteractiveExpirationTime = NoWork; } - var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates; var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingInteractiveUpdates = true; isBatchingUpdates = true; try { - return fn(a, b); + return scheduler.unstable_runWithPriority( + scheduler.unstable_UserBlockingPriority, + function() { + return fn(a, b); + } + ); } finally { - isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates; isBatchingUpdates = previousIsBatchingUpdates; if (!isBatchingUpdates && !isRendering) { performSyncWork(); @@ -17265,11 +18147,43 @@ function getPublicRootInstance(container) { } } +var overrideProps = null; + +{ + var copyWithSetImpl = function(obj, path, idx, value) { + if (idx >= path.length) { + return value; + } + var key = path[idx]; + var updated = Array.isArray(obj) ? obj.slice() : Object.assign({}, obj); + // $FlowFixMe number or string is fine here + updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value); + return updated; + }; + + var copyWithSet = function(obj, path, value) { + return copyWithSetImpl(obj, path, 0, value); + }; + + // Support DevTools props for function components, forwardRef, memo, host components, etc. + overrideProps = function(fiber, path, value) { + flushPassiveEffects(); + fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value); + if (fiber.alternate) { + fiber.alternate.pendingProps = fiber.pendingProps; + } + scheduleWork(fiber, Sync); + }; +} + function injectIntoDevTools(devToolsConfig) { var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; + var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; return injectInternals( Object.assign({}, devToolsConfig, { + overrideProps: overrideProps, + currentDispatcherRef: ReactCurrentDispatcher, findHostInstanceByFiber: function(fiber) { var hostFiber = findCurrentHostFiber(fiber); if (hostFiber === null) { @@ -17312,7 +18226,7 @@ function createPortal( // TODO: this is special because it gets imported during build. -var ReactVersion = "16.6.1"; +var ReactVersion = "16.8.1"; // Modules provided by RN: var NativeMethodsMixin = function(findNodeHandle, findHostInstance) { diff --git a/Libraries/Renderer/oss/ReactFabric-prod.js b/Libraries/Renderer/oss/ReactFabric-prod.js index 95eeffce359f83..538811967996ff 100644 --- a/Libraries/Renderer/oss/ReactFabric-prod.js +++ b/Libraries/Renderer/oss/ReactFabric-prod.js @@ -1019,8 +1019,10 @@ ResponderEventPlugin.injection.injectGlobalResponderHandler({ } }); var ReactSharedInternals = - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, - hasSymbol = "function" === typeof Symbol && Symbol.for, + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; +ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher") || + (ReactSharedInternals.ReactCurrentDispatcher = { current: null }); +var 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, @@ -1430,6 +1432,10 @@ function setTimeoutCallback() { scheduledCallback = null; null !== callback && callback(); } +function scheduleDeferredCallback$1(callback) { + scheduledCallback = callback; + return setTimeout(setTimeoutCallback, 1); +} var restoreTarget = null, restoreQueue = null; function restoreStateOfTarget(target) { @@ -1777,7 +1783,7 @@ function FiberNode(tag, pendingProps, key, mode) { this.index = 0; this.ref = null; this.pendingProps = pendingProps; - this.firstContextDependency = this.memoizedState = this.updateQueue = this.memoizedProps = null; + this.contextDependencies = this.memoizedState = this.updateQueue = this.memoizedProps = null; this.mode = mode; this.effectTag = 0; this.lastEffect = this.firstEffect = this.nextEffect = null; @@ -1826,7 +1832,7 @@ function createWorkInProgress(current, pendingProps) { workInProgress.memoizedProps = current.memoizedProps; workInProgress.memoizedState = current.memoizedState; workInProgress.updateQueue = current.updateQueue; - workInProgress.firstContextDependency = current.firstContextDependency; + workInProgress.contextDependencies = current.contextDependencies; workInProgress.sibling = current.sibling; workInProgress.index = current.index; workInProgress.ref = current.ref; @@ -1950,26 +1956,53 @@ function markPendingPriorityLevel(root, expirationTime) { (root.latestPendingTime = expirationTime); findNextExpirationTimeToWorkOn(expirationTime, root); } +function markCommittedPriorityLevels(root, earliestRemainingTime) { + root.didError = !1; + if (0 === earliestRemainingTime) + (root.earliestPendingTime = 0), + (root.latestPendingTime = 0), + (root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0); + else { + earliestRemainingTime < root.latestPingedTime && + (root.latestPingedTime = 0); + var latestPendingTime = root.latestPendingTime; + 0 !== latestPendingTime && + (latestPendingTime > earliestRemainingTime + ? (root.earliestPendingTime = root.latestPendingTime = 0) + : root.earliestPendingTime > earliestRemainingTime && + (root.earliestPendingTime = root.latestPendingTime)); + latestPendingTime = root.earliestSuspendedTime; + 0 === latestPendingTime + ? markPendingPriorityLevel(root, earliestRemainingTime) + : earliestRemainingTime < root.latestSuspendedTime + ? ((root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0), + markPendingPriorityLevel(root, earliestRemainingTime)) + : earliestRemainingTime > latestPendingTime && + markPendingPriorityLevel(root, earliestRemainingTime); + } + findNextExpirationTimeToWorkOn(0, root); +} function markSuspendedPriorityLevel(root, suspendedTime) { root.didError = !1; - var latestPingedTime = root.latestPingedTime; - 0 !== latestPingedTime && - latestPingedTime >= suspendedTime && - (root.latestPingedTime = 0); - latestPingedTime = root.earliestPendingTime; - var latestPendingTime = root.latestPendingTime; - latestPingedTime === suspendedTime + root.latestPingedTime >= suspendedTime && (root.latestPingedTime = 0); + var earliestPendingTime = root.earliestPendingTime, + latestPendingTime = root.latestPendingTime; + earliestPendingTime === suspendedTime ? (root.earliestPendingTime = latestPendingTime === suspendedTime ? (root.latestPendingTime = 0) : latestPendingTime) : latestPendingTime === suspendedTime && - (root.latestPendingTime = latestPingedTime); - latestPingedTime = root.earliestSuspendedTime; + (root.latestPendingTime = earliestPendingTime); + earliestPendingTime = root.earliestSuspendedTime; latestPendingTime = root.latestSuspendedTime; - 0 === latestPingedTime + 0 === earliestPendingTime ? (root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime) - : latestPingedTime < suspendedTime + : earliestPendingTime < suspendedTime ? (root.earliestSuspendedTime = suspendedTime) : latestPendingTime > suspendedTime && (root.latestSuspendedTime = suspendedTime); @@ -2001,394 +2034,81 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) { root.nextExpirationTimeToWorkOn = earliestPendingTime; root.expirationTime = completedExpirationTime; } -var hasForceUpdate = !1; -function createUpdateQueue(baseState) { - return { - baseState: baseState, - firstUpdate: null, - lastUpdate: null, - firstCapturedUpdate: null, - lastCapturedUpdate: null, - firstEffect: null, - lastEffect: null, - firstCapturedEffect: null, - lastCapturedEffect: null - }; -} -function cloneUpdateQueue(currentQueue) { - return { - 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) { - null === queue.lastUpdate - ? (queue.firstUpdate = queue.lastUpdate = update) - : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); -} -function enqueueUpdate(fiber, update) { - 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) - : null === queue1.lastUpdate || null === queue2.lastUpdate - ? (appendUpdateToQueue(queue1, update), - appendUpdateToQueue(queue2, update)) - : (appendUpdateToQueue(queue1, update), (queue2.lastUpdate = update)); +function is(x, y) { + return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); } -function enqueueCapturedUpdate(workInProgress, update) { - 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)); +var hasOwnProperty = Object.prototype.hasOwnProperty; +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 ensureWorkInProgressQueueIsAClone(workInProgress, queue) { - var current = workInProgress.alternate; - null !== current && - queue === current.updateQueue && - (queue = workInProgress.updateQueue = cloneUpdateQueue(queue)); - return queue; +function resolveDefaultProps(Component, baseProps) { + if (Component && Component.defaultProps) { + baseProps = Object.assign({}, baseProps); + Component = Component.defaultProps; + for (var propName in Component) + void 0 === baseProps[propName] && + (baseProps[propName] = Component[propName]); + } + return baseProps; } -function getStateFromUpdate( - workInProgress, - queue, - update, - prevState, - nextProps, - instance -) { - switch (update.tag) { +function readLazyComponentType(lazyComponent) { + var result = lazyComponent._result; + switch (lazyComponent._status) { case 1: - return ( - (workInProgress = update.payload), - "function" === typeof workInProgress - ? workInProgress.call(instance, prevState, nextProps) - : workInProgress - ); - case 3: - workInProgress.effectTag = (workInProgress.effectTag & -2049) | 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); + return result; case 2: - hasForceUpdate = !0; + throw result; + case 0: + throw result; + default: + lazyComponent._status = 0; + result = lazyComponent._ctor; + result = result(); + result.then( + function(moduleObject) { + 0 === lazyComponent._status && + ((moduleObject = moduleObject.default), + (lazyComponent._status = 1), + (lazyComponent._result = moduleObject)); + }, + function(error) { + 0 === lazyComponent._status && + ((lazyComponent._status = 2), (lazyComponent._result = error)); + } + ); + switch (lazyComponent._status) { + case 1: + return lazyComponent._result; + case 2: + throw lazyComponent._result; + } + lazyComponent._result = result; + throw result; } - return prevState; } -function processUpdateQueue( +var emptyRefsObject = new React.Component().refs; +function applyDerivedStateFromProps( workInProgress, - queue, - props, - instance, - renderExpirationTime -) { - hasForceUpdate = !1; - queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); - for ( - var newBaseState = queue.baseState, - newFirstUpdate = null, - newExpirationTime = 0, - update = queue.firstUpdate, - resultState = newBaseState; - null !== update; - - ) { - var updateExpirationTime = update.expirationTime; - updateExpirationTime < renderExpirationTime - ? (null === newFirstUpdate && - ((newFirstUpdate = update), (newBaseState = resultState)), - newExpirationTime < updateExpirationTime && - (newExpirationTime = updateExpirationTime)) - : ((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; - _updateExpirationTime < renderExpirationTime - ? (null === updateExpirationTime && - ((updateExpirationTime = update), - null === newFirstUpdate && (newBaseState = resultState)), - newExpirationTime < _updateExpirationTime && - (newExpirationTime = _updateExpirationTime)) - : ((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; - workInProgress.expirationTime = newExpirationTime; - workInProgress.memoizedState = resultState; -} -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)); - commitUpdateEffects(finishedQueue.firstEffect, instance); - finishedQueue.firstEffect = finishedQueue.lastEffect = null; - commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); - finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; -} -function commitUpdateEffects(effect, instance) { - for (; null !== effect; ) { - var _callback3 = effect.callback; - if (null !== _callback3) { - effect.callback = null; - var context = instance; - invariant( - "function" === typeof _callback3, - "Invalid argument passed as callback. Expected a function. Instead received: %s", - _callback3 - ); - _callback3.call(context); - } - effect = effect.nextEffect; - } -} -function createCapturedValue(value, source) { - return { - value: value, - source: source, - stack: getStackByFiberInDevAndProd(source) - }; -} -var valueCursor = { current: null }, - currentlyRenderingFiber = null, - lastContextDependency = null, - lastContextWithAllBitsObserved = null; -function pushProvider(providerFiber, nextValue) { - var context = providerFiber.type._context; - push(valueCursor, context._currentValue2, providerFiber); - context._currentValue2 = nextValue; -} -function popProvider(providerFiber) { - var currentValue = valueCursor.current; - pop(valueCursor, providerFiber); - providerFiber.type._context._currentValue2 = currentValue; -} -function prepareToReadContext(workInProgress) { - currentlyRenderingFiber = workInProgress; - lastContextWithAllBitsObserved = lastContextDependency = null; - workInProgress.firstContextDependency = null; -} -function readContext(context, observedBits) { - if ( - lastContextWithAllBitsObserved !== context && - !1 !== observedBits && - 0 !== observedBits - ) { - if ("number" !== typeof observedBits || 1073741823 === observedBits) - (lastContextWithAllBitsObserved = context), (observedBits = 1073741823); - observedBits = { context: context, observedBits: observedBits, next: null }; - null === lastContextDependency - ? (invariant( - null !== currentlyRenderingFiber, - "Context can only be read while React is rendering, e.g. inside the render method or getDerivedStateFromProps." - ), - (currentlyRenderingFiber.firstContextDependency = lastContextDependency = observedBits)) - : (lastContextDependency = lastContextDependency.next = observedBits); - } - return context._currentValue2; -} -var NO_CONTEXT = {}, - contextStackCursor$1 = { current: NO_CONTEXT }, - contextFiberStackCursor = { current: NO_CONTEXT }, - rootInstanceStackCursor = { current: 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 pushHostContext(fiber) { - requiredContext(rootInstanceStackCursor.current); - var context = requiredContext(contextStackCursor$1.current); - var nextContext = fiber.type; - nextContext = - "AndroidTextInput" === nextContext || - "RCTMultilineTextInputView" === nextContext || - "RCTSinglelineTextInputView" === nextContext || - "RCTText" === nextContext || - "RCTVirtualText" === nextContext; - nextContext = - context.isInAParentText !== nextContext - ? { isInAParentText: nextContext } - : context; - context !== nextContext && - (push(contextFiberStackCursor, fiber, fiber), - push(contextStackCursor$1, nextContext, 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 resolveDefaultProps(Component, baseProps) { - if (Component && Component.defaultProps) { - baseProps = Object.assign({}, baseProps); - Component = Component.defaultProps; - for (var propName in Component) - void 0 === baseProps[propName] && - (baseProps[propName] = Component[propName]); - } - return baseProps; -} -function readLazyComponentType(lazyComponent) { - var result = lazyComponent._result; - switch (lazyComponent._status) { - case 1: - return result; - case 2: - throw result; - case 0: - throw result; - default: - throw ((lazyComponent._status = 0), - (result = lazyComponent._ctor), - (result = result()), - result.then( - function(moduleObject) { - 0 === lazyComponent._status && - ((moduleObject = moduleObject.default), - (lazyComponent._status = 1), - (lazyComponent._result = moduleObject)); - }, - function(error) { - 0 === lazyComponent._status && - ((lazyComponent._status = 2), (lazyComponent._result = error)); - } - ), - (lazyComponent._result = result), - result); - } -} -var ReactCurrentOwner$4 = ReactSharedInternals.ReactCurrentOwner, - emptyRefsObject = new React.Component().refs; -function applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - nextProps + ctor, + getDerivedStateFromProps, + nextProps ) { ctor = workInProgress.memoizedState; getDerivedStateFromProps = getDerivedStateFromProps(nextProps, ctor); @@ -2424,7 +2144,7 @@ var classComponentUpdater = { var currentTime = requestCurrentTime(); currentTime = computeExpirationForFiber(currentTime, inst); var update = createUpdate(currentTime); - update.tag = 1; + update.tag = ReplaceState; update.payload = payload; void 0 !== callback && null !== callback && (update.callback = callback); flushPassiveEffects(); @@ -2436,7 +2156,7 @@ var classComponentUpdater = { var currentTime = requestCurrentTime(); currentTime = computeExpirationForFiber(currentTime, inst); var update = createUpdate(currentTime); - update.tag = 2; + update.tag = ForceUpdate; void 0 !== callback && null !== callback && (update.callback = callback); flushPassiveEffects(); enqueueUpdate(inst, update); @@ -2464,7 +2184,7 @@ function constructClassInstance(workInProgress, ctor, props) { unmaskedContext = emptyContextObject; var context = ctor.contextType; "object" === typeof context && null !== context - ? (context = ReactCurrentOwner$4.currentDispatcher.readContext(context)) + ? (context = readContext(context)) : ((unmaskedContext = isContextProvider(ctor) ? previousContext : contextStackCursor.current), @@ -2511,9 +2231,7 @@ function mountClassInstance( instance.refs = emptyRefsObject; var contextType = ctor.contextType; "object" === typeof contextType && null !== contextType - ? (instance.context = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (instance.context = readContext(contextType)) : ((contextType = isContextProvider(ctor) ? previousContext : contextStackCursor.current), @@ -2568,7 +2286,10 @@ function coerceRef(returnFiber, current$$1, element) { element = element._owner; var inst = void 0; element && - (invariant(1 === element.tag, "Function components cannot have refs."), + (invariant( + 1 === element.tag, + "Function components cannot have refs. Did you mean to use React.forwardRef()?" + ), (inst = element.stateNode)); invariant( inst, @@ -3268,72 +2989,577 @@ function ChildReconciler(shouldTrackSideEffects) { } 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; - } + NO_CONTEXT = {}, + contextStackCursor$1 = { current: NO_CONTEXT }, + contextFiberStackCursor = { current: NO_CONTEXT }, + rootInstanceStackCursor = { current: 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 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 = createFiber(5, null, null, 0); - fiber.elementType = "DELETED"; - 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 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); } -var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner; -function reconcileChildren( - current$$1, - workInProgress, - nextChildren, - renderExpirationTime -) { - workInProgress.child = - null === current$$1 - ? mountChildFibers( - workInProgress, - null, - nextChildren, - renderExpirationTime +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} +function pushHostContext(fiber) { + requiredContext(rootInstanceStackCursor.current); + var context = requiredContext(contextStackCursor$1.current); + var nextContext = fiber.type; + nextContext = + "AndroidTextInput" === nextContext || + "RCTMultilineTextInputView" === nextContext || + "RCTSinglelineTextInputView" === nextContext || + "RCTText" === nextContext || + "RCTVirtualText" === nextContext; + nextContext = + context.isInAParentText !== nextContext + ? { isInAParentText: nextContext } + : context; + context !== nextContext && + (push(contextFiberStackCursor, fiber, fiber), + push(contextStackCursor$1, nextContext, fiber)); +} +function popHostContext(fiber) { + contextFiberStackCursor.current === fiber && + (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); +} +var NoEffect$1 = 0, + UnmountSnapshot = 2, + UnmountMutation = 4, + MountMutation = 8, + UnmountLayout = 16, + MountLayout = 32, + MountPassive = 64, + UnmountPassive = 128, + ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher, + renderExpirationTime = 0, + currentlyRenderingFiber$1 = null, + currentHook = null, + nextCurrentHook = null, + firstWorkInProgressHook = null, + workInProgressHook = null, + nextWorkInProgressHook = null, + remainingExpirationTime = 0, + componentUpdateQueue = null, + sideEffectTag = 0, + didScheduleRenderPhaseUpdate = !1, + renderPhaseUpdates = null, + numberOfReRenders = 0; +function throwInvalidHookError() { + invariant( + !1, + "Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)" + ); +} +function areHookInputsEqual(nextDeps, prevDeps) { + if (null === prevDeps) return !1; + for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) + if (!is(nextDeps[i], prevDeps[i])) return !1; + return !0; +} +function renderWithHooks( + current, + workInProgress, + Component, + props, + refOrContext, + nextRenderExpirationTime +) { + renderExpirationTime = nextRenderExpirationTime; + currentlyRenderingFiber$1 = workInProgress; + nextCurrentHook = null !== current ? current.memoizedState : null; + ReactCurrentDispatcher$1.current = + null === nextCurrentHook ? HooksDispatcherOnMount : HooksDispatcherOnUpdate; + workInProgress = Component(props, refOrContext); + if (didScheduleRenderPhaseUpdate) { + do + (didScheduleRenderPhaseUpdate = !1), + (numberOfReRenders += 1), + (nextCurrentHook = null !== current ? current.memoizedState : null), + (nextWorkInProgressHook = firstWorkInProgressHook), + (componentUpdateQueue = workInProgressHook = currentHook = null), + (ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdate), + (workInProgress = Component(props, refOrContext)); + while (didScheduleRenderPhaseUpdate); + renderPhaseUpdates = null; + numberOfReRenders = 0; + } + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + current = currentlyRenderingFiber$1; + current.memoizedState = firstWorkInProgressHook; + current.expirationTime = remainingExpirationTime; + current.updateQueue = componentUpdateQueue; + current.effectTag |= sideEffectTag; + current = null !== currentHook && null !== currentHook.next; + renderExpirationTime = 0; + nextWorkInProgressHook = workInProgressHook = firstWorkInProgressHook = nextCurrentHook = currentHook = currentlyRenderingFiber$1 = null; + remainingExpirationTime = 0; + componentUpdateQueue = null; + sideEffectTag = 0; + invariant( + !current, + "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." + ); + return workInProgress; +} +function resetHooks() { + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + renderExpirationTime = 0; + nextWorkInProgressHook = workInProgressHook = firstWorkInProgressHook = nextCurrentHook = currentHook = currentlyRenderingFiber$1 = null; + remainingExpirationTime = 0; + componentUpdateQueue = null; + sideEffectTag = 0; + didScheduleRenderPhaseUpdate = !1; + renderPhaseUpdates = null; + numberOfReRenders = 0; +} +function mountWorkInProgressHook() { + var hook = { + memoizedState: null, + baseState: null, + queue: null, + baseUpdate: null, + next: null + }; + null === workInProgressHook + ? (firstWorkInProgressHook = workInProgressHook = hook) + : (workInProgressHook = workInProgressHook.next = hook); + return workInProgressHook; +} +function updateWorkInProgressHook() { + if (null !== nextWorkInProgressHook) + (workInProgressHook = nextWorkInProgressHook), + (nextWorkInProgressHook = workInProgressHook.next), + (currentHook = nextCurrentHook), + (nextCurrentHook = null !== currentHook ? currentHook.next : null); + else { + invariant( + null !== nextCurrentHook, + "Rendered more hooks than during the previous render." + ); + currentHook = nextCurrentHook; + var newHook = { + memoizedState: currentHook.memoizedState, + baseState: currentHook.baseState, + queue: currentHook.queue, + baseUpdate: currentHook.baseUpdate, + next: null + }; + workInProgressHook = + null === workInProgressHook + ? (firstWorkInProgressHook = newHook) + : (workInProgressHook.next = newHook); + nextCurrentHook = currentHook.next; + } + return workInProgressHook; +} +function basicStateReducer(state, action) { + return "function" === typeof action ? action(state) : action; +} +function updateReducer(reducer) { + var hook = updateWorkInProgressHook(), + queue = hook.queue; + invariant( + null !== queue, + "Should have a queue. This is likely a bug in React. Please file an issue." + ); + if (0 < numberOfReRenders) { + var _dispatch = queue.dispatch; + if (null !== renderPhaseUpdates) { + var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); + if (void 0 !== firstRenderPhaseUpdate) { + renderPhaseUpdates.delete(queue); + var newState = hook.memoizedState; + do + (newState = reducer(newState, firstRenderPhaseUpdate.action)), + (firstRenderPhaseUpdate = firstRenderPhaseUpdate.next); + while (null !== firstRenderPhaseUpdate); + is(newState, hook.memoizedState) || (didReceiveUpdate = !0); + hook.memoizedState = newState; + hook.baseUpdate === queue.last && (hook.baseState = newState); + return [newState, _dispatch]; + } + } + return [hook.memoizedState, _dispatch]; + } + _dispatch = queue.last; + var baseUpdate = hook.baseUpdate; + newState = hook.baseState; + null !== baseUpdate + ? (null !== _dispatch && (_dispatch.next = null), + (_dispatch = baseUpdate.next)) + : (_dispatch = null !== _dispatch ? _dispatch.next : null); + if (null !== _dispatch) { + var newBaseUpdate = (firstRenderPhaseUpdate = null), + _update = _dispatch, + didSkip = !1; + do { + var updateExpirationTime = _update.expirationTime; + updateExpirationTime < renderExpirationTime + ? (didSkip || + ((didSkip = !0), + (newBaseUpdate = baseUpdate), + (firstRenderPhaseUpdate = newState)), + updateExpirationTime > remainingExpirationTime && + (remainingExpirationTime = updateExpirationTime)) + : (newState = + _update.eagerReducer === reducer + ? _update.eagerState + : reducer(newState, _update.action)); + baseUpdate = _update; + _update = _update.next; + } while (null !== _update && _update !== _dispatch); + didSkip || + ((newBaseUpdate = baseUpdate), (firstRenderPhaseUpdate = newState)); + is(newState, hook.memoizedState) || (didReceiveUpdate = !0); + hook.memoizedState = newState; + hook.baseUpdate = newBaseUpdate; + hook.baseState = firstRenderPhaseUpdate; + queue.eagerReducer = reducer; + queue.eagerState = newState; + } + return [hook.memoizedState, queue.dispatch]; +} +function pushEffect(tag, create, destroy, deps) { + tag = { tag: tag, create: create, destroy: destroy, deps: deps, next: null }; + null === componentUpdateQueue + ? ((componentUpdateQueue = { lastEffect: null }), + (componentUpdateQueue.lastEffect = tag.next = tag)) + : ((create = componentUpdateQueue.lastEffect), + null === create + ? (componentUpdateQueue.lastEffect = tag.next = tag) + : ((destroy = create.next), + (create.next = tag), + (tag.next = destroy), + (componentUpdateQueue.lastEffect = tag))); + return tag; +} +function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = mountWorkInProgressHook(); + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect( + hookEffectTag, + create, + void 0, + void 0 === deps ? null : deps + ); +} +function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var destroy = void 0; + if (null !== currentHook) { + var prevEffect = currentHook.memoizedState; + destroy = prevEffect.destroy; + if (null !== deps && areHookInputsEqual(deps, prevEffect.deps)) { + pushEffect(NoEffect$1, create, destroy, deps); + return; + } + } + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect(hookEffectTag, create, destroy, deps); +} +function imperativeHandleEffect(create, ref) { + if ("function" === typeof ref) + return ( + (create = create()), + ref(create), + function() { + ref(null); + } + ); + if (null !== ref && void 0 !== ref) + return ( + (create = create()), + (ref.current = create), + function() { + ref.current = null; + } + ); +} +function mountDebugValue() {} +function dispatchAction(fiber, queue, action) { + invariant( + 25 > numberOfReRenders, + "Too many re-renders. React limits the number of renders to prevent an infinite loop." + ); + var alternate = fiber.alternate; + if ( + fiber === currentlyRenderingFiber$1 || + (null !== alternate && alternate === currentlyRenderingFiber$1) + ) + if ( + ((didScheduleRenderPhaseUpdate = !0), + (fiber = { + expirationTime: renderExpirationTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }), + null === renderPhaseUpdates && (renderPhaseUpdates = new Map()), + (action = renderPhaseUpdates.get(queue)), + void 0 === action) + ) + renderPhaseUpdates.set(queue, fiber); + else { + for (queue = action; null !== queue.next; ) queue = queue.next; + queue.next = fiber; + } + else { + flushPassiveEffects(); + var currentTime = requestCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, fiber); + var _update2 = { + expirationTime: currentTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }, + _last = queue.last; + if (null === _last) _update2.next = _update2; + else { + var first = _last.next; + null !== first && (_update2.next = first); + _last.next = _update2; + } + queue.last = _update2; + if ( + 0 === fiber.expirationTime && + (null === alternate || 0 === alternate.expirationTime) && + ((alternate = queue.eagerReducer), null !== alternate) + ) + try { + var currentState = queue.eagerState, + _eagerState = alternate(currentState, action); + _update2.eagerReducer = alternate; + _update2.eagerState = _eagerState; + if (is(_eagerState, currentState)) return; + } catch (error) { + } finally { + } + scheduleWork(fiber, currentTime); + } +} +var ContextOnlyDispatcher = { + readContext: readContext, + useCallback: throwInvalidHookError, + useContext: throwInvalidHookError, + useEffect: throwInvalidHookError, + useImperativeHandle: throwInvalidHookError, + useLayoutEffect: throwInvalidHookError, + useMemo: throwInvalidHookError, + useReducer: throwInvalidHookError, + useRef: throwInvalidHookError, + useState: throwInvalidHookError, + useDebugValue: throwInvalidHookError + }, + HooksDispatcherOnMount = { + readContext: readContext, + useCallback: function(callback, deps) { + mountWorkInProgressHook().memoizedState = [ + callback, + void 0 === deps ? null : deps + ]; + return callback; + }, + useContext: readContext, + useEffect: function(create, deps) { + return mountEffectImpl(516, UnmountPassive | MountPassive, create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + deps = null !== deps && void 0 !== deps ? deps.concat([ref]) : [ref]; + return mountEffectImpl( + 4, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + deps + ); + }, + useLayoutEffect: function(create, deps) { + return mountEffectImpl(4, UnmountMutation | MountLayout, create, deps); + }, + useMemo: function(nextCreate, deps) { + var hook = mountWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + nextCreate = nextCreate(); + hook.memoizedState = [nextCreate, deps]; + return nextCreate; + }, + useReducer: function(reducer, initialArg, init) { + var hook = mountWorkInProgressHook(); + initialArg = void 0 !== init ? init(initialArg) : initialArg; + hook.memoizedState = hook.baseState = initialArg; + reducer = hook.queue = { + last: null, + dispatch: null, + eagerReducer: reducer, + eagerState: initialArg + }; + reducer = reducer.dispatch = dispatchAction.bind( + null, + currentlyRenderingFiber$1, + reducer + ); + return [hook.memoizedState, reducer]; + }, + useRef: function(initialValue) { + var hook = mountWorkInProgressHook(); + initialValue = { current: initialValue }; + return (hook.memoizedState = initialValue); + }, + useState: function(initialState) { + var hook = mountWorkInProgressHook(); + "function" === typeof initialState && (initialState = initialState()); + hook.memoizedState = hook.baseState = initialState; + initialState = hook.queue = { + last: null, + dispatch: null, + eagerReducer: basicStateReducer, + eagerState: initialState + }; + initialState = initialState.dispatch = dispatchAction.bind( + null, + currentlyRenderingFiber$1, + initialState + ); + return [hook.memoizedState, initialState]; + }, + useDebugValue: mountDebugValue + }, + HooksDispatcherOnUpdate = { + readContext: readContext, + useCallback: function(callback, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var prevState = hook.memoizedState; + if ( + null !== prevState && + null !== deps && + areHookInputsEqual(deps, prevState[1]) + ) + return prevState[0]; + hook.memoizedState = [callback, deps]; + return callback; + }, + useContext: readContext, + useEffect: function(create, deps) { + return updateEffectImpl(516, UnmountPassive | MountPassive, create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + deps = null !== deps && void 0 !== deps ? deps.concat([ref]) : [ref]; + return updateEffectImpl( + 4, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + deps + ); + }, + useLayoutEffect: function(create, deps) { + return updateEffectImpl(4, UnmountMutation | MountLayout, create, deps); + }, + useMemo: function(nextCreate, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var prevState = hook.memoizedState; + if ( + null !== prevState && + null !== deps && + areHookInputsEqual(deps, prevState[1]) + ) + return prevState[0]; + nextCreate = nextCreate(); + hook.memoizedState = [nextCreate, deps]; + return nextCreate; + }, + useReducer: updateReducer, + useRef: function() { + return updateWorkInProgressHook().memoizedState; + }, + useState: function(initialState) { + return updateReducer(basicStateReducer, initialState); + }, + useDebugValue: mountDebugValue + }, + 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 = createFiber(5, null, null, 0); + fiber.elementType = "DELETED"; + 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); + } +} +var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner, + didReceiveUpdate = !1; +function reconcileChildren( + current$$1, + workInProgress, + nextChildren, + renderExpirationTime +) { + workInProgress.child = + null === current$$1 + ? mountChildFibers( + workInProgress, + null, + nextChildren, + renderExpirationTime ) : reconcileChildFibers( workInProgress, @@ -3352,7 +3578,26 @@ function updateForwardRef( Component = Component.render; var ref = workInProgress.ref; prepareToReadContext(workInProgress, renderExpirationTime); - nextProps = Component(nextProps, ref); + nextProps = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + ref, + renderExpirationTime + ); + if (null !== current$$1 && !didReceiveUpdate) + return ( + (workInProgress.updateQueue = current$$1.updateQueue), + (workInProgress.effectTag &= -517), + current$$1.expirationTime <= renderExpirationTime && + (current$$1.expirationTime = 0), + bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ) + ); workInProgress.effectTag |= 1; reconcileChildren( current$$1, @@ -3432,9 +3677,9 @@ function updateSimpleMemoComponent( renderExpirationTime ) { return null !== current$$1 && - updateExpirationTime < renderExpirationTime && shallowEqual(current$$1.memoizedProps, nextProps) && - current$$1.ref === workInProgress.ref + current$$1.ref === workInProgress.ref && + ((didReceiveUpdate = !1), updateExpirationTime < renderExpirationTime) ? bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -3468,7 +3713,26 @@ function updateFunctionComponent( : contextStackCursor.current; unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); prepareToReadContext(workInProgress, renderExpirationTime); - Component = Component(nextProps, unmaskedContext); + Component = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + unmaskedContext, + renderExpirationTime + ); + if (null !== current$$1 && !didReceiveUpdate) + return ( + (workInProgress.updateQueue = current$$1.updateQueue), + (workInProgress.effectTag &= -517), + current$$1.expirationTime <= renderExpirationTime && + (current$$1.expirationTime = 0), + bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ) + ); workInProgress.effectTag |= 1; reconcileChildren( current$$1, @@ -3515,9 +3779,7 @@ function updateClassComponent( var oldContext = instance.context, contextType = Component.contextType; "object" === typeof contextType && null !== contextType - ? (contextType = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (contextType = readContext(contextType)) : ((contextType = isContextProvider(Component) ? previousContext : contextStackCursor.current), @@ -3602,9 +3864,7 @@ function updateClassComponent( (oldContext = instance.context), (contextType = Component.contextType), "object" === typeof contextType && null !== contextType - ? (contextType = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (contextType = readContext(contextType)) : ((contextType = isContextProvider(Component) ? previousContext : contextStackCursor.current), @@ -3785,33 +4045,35 @@ function updateSuspenseComponent( (nextState = { timedOutAt: null !== nextState ? nextState.timedOutAt : 0 }), (nextDidTimeout = !0), (workInProgress.effectTag &= -65); - null === current$$1 - ? nextDidTimeout - ? ((nextDidTimeout = nextProps.fallback), - (nextProps = createFiberFromFragment(null, mode, 0, null)), - 0 === (workInProgress.mode & 1) && - (nextProps.child = - null !== workInProgress.memoizedState - ? workInProgress.child.child - : workInProgress.child), - (mode = createFiberFromFragment( - nextDidTimeout, - mode, - renderExpirationTime, - null - )), - (nextProps.sibling = mode), - (renderExpirationTime = nextProps), - (renderExpirationTime.return = mode.return = workInProgress)) - : (renderExpirationTime = mode = mountChildFibers( - workInProgress, - null, - nextProps.children, - renderExpirationTime - )) - : null !== current$$1.memoizedState + if (null === current$$1) + if (nextDidTimeout) { + var nextFallbackChildren = nextProps.fallback; + current$$1 = createFiberFromFragment(null, mode, 0, null); + 0 === (workInProgress.mode & 1) && + (current$$1.child = + null !== workInProgress.memoizedState + ? workInProgress.child.child + : workInProgress.child); + mode = createFiberFromFragment( + nextFallbackChildren, + mode, + renderExpirationTime, + null + ); + current$$1.sibling = mode; + renderExpirationTime = current$$1; + renderExpirationTime.return = mode.return = workInProgress; + } else + renderExpirationTime = mode = mountChildFibers( + workInProgress, + null, + nextProps.children, + renderExpirationTime + ); + else + null !== current$$1.memoizedState ? ((mode = current$$1.child), - (current$$1 = mode.sibling), + (nextFallbackChildren = mode.sibling), nextDidTimeout ? ((renderExpirationTime = nextProps.fallback), (nextProps = createWorkInProgress(mode, mode.pendingProps, 0)), @@ -3823,9 +4085,9 @@ function updateSuspenseComponent( nextDidTimeout !== mode.child && (nextProps.child = nextDidTimeout)), (mode = nextProps.sibling = createWorkInProgress( - current$$1, + nextFallbackChildren, renderExpirationTime, - current$$1.expirationTime + nextFallbackChildren.expirationTime )), (renderExpirationTime = nextProps), (nextProps.childExpirationTime = 0), @@ -3836,11 +4098,11 @@ function updateSuspenseComponent( nextProps.children, renderExpirationTime ))) - : ((current$$1 = current$$1.child), + : ((nextFallbackChildren = current$$1.child), nextDidTimeout ? ((nextDidTimeout = nextProps.fallback), (nextProps = createFiberFromFragment(null, mode, 0, null)), - (nextProps.child = current$$1), + (nextProps.child = nextFallbackChildren), 0 === (workInProgress.mode & 1) && (nextProps.child = null !== workInProgress.memoizedState @@ -3858,10 +4120,11 @@ function updateSuspenseComponent( (renderExpirationTime.return = mode.return = workInProgress)) : (mode = renderExpirationTime = reconcileChildFibers( workInProgress, - current$$1, + nextFallbackChildren, nextProps.children, renderExpirationTime - ))); + ))), + (workInProgress.stateNode = current$$1.stateNode); workInProgress.memoizedState = nextState; workInProgress.child = renderExpirationTime; return mode; @@ -3872,7 +4135,7 @@ function bailoutOnAlreadyFinishedWork( renderExpirationTime ) { null !== current$$1 && - (workInProgress.firstContextDependency = current$$1.firstContextDependency); + (workInProgress.contextDependencies = current$$1.contextDependencies); if (workInProgress.childExpirationTime < renderExpirationTime) return null; invariant( null === current$$1 || workInProgress.child === current$$1.child, @@ -3904,58 +4167,63 @@ function bailoutOnAlreadyFinishedWork( } function beginWork(current$$1, workInProgress, renderExpirationTime) { var updateExpirationTime = workInProgress.expirationTime; - if ( - null !== current$$1 && - current$$1.memoizedProps === workInProgress.pendingProps && - !didPerformWorkStackCursor.current && - updateExpirationTime < renderExpirationTime - ) { - switch (workInProgress.tag) { - case 3: - pushHostRootContext(workInProgress); - break; - case 5: - pushHostContext(workInProgress); - break; - case 1: - isContextProvider(workInProgress.type) && - pushContextProvider(workInProgress); - break; - case 4: - pushHostContainer( - workInProgress, - workInProgress.stateNode.containerInfo - ); - break; - case 10: - pushProvider(workInProgress, workInProgress.memoizedProps.value); - break; - case 13: - if (null !== workInProgress.memoizedState) { - updateExpirationTime = workInProgress.child.childExpirationTime; - if ( - 0 !== updateExpirationTime && - updateExpirationTime >= renderExpirationTime - ) - return updateSuspenseComponent( - current$$1, + if (null !== current$$1) + if ( + current$$1.memoizedProps !== workInProgress.pendingProps || + didPerformWorkStackCursor.current + ) + didReceiveUpdate = !0; + else { + if (updateExpirationTime < renderExpirationTime) { + didReceiveUpdate = !1; + switch (workInProgress.tag) { + case 3: + pushHostRootContext(workInProgress); + break; + case 5: + pushHostContext(workInProgress); + break; + case 1: + isContextProvider(workInProgress.type) && + pushContextProvider(workInProgress); + break; + case 4: + pushHostContainer( workInProgress, - renderExpirationTime + workInProgress.stateNode.containerInfo ); - workInProgress = bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); - return null !== workInProgress ? workInProgress.sibling : null; + break; + case 10: + pushProvider(workInProgress, workInProgress.memoizedProps.value); + break; + case 13: + if (null !== workInProgress.memoizedState) { + updateExpirationTime = workInProgress.child.childExpirationTime; + if ( + 0 !== updateExpirationTime && + updateExpirationTime >= renderExpirationTime + ) + return updateSuspenseComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress = bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + return null !== workInProgress ? workInProgress.sibling : null; + } } + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } } - return bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); - } + else didReceiveUpdate = !1; workInProgress.expirationTime = 0; switch (workInProgress.tag) { case 2: @@ -3970,7 +4238,14 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = updateExpirationTime(current$$1, context); + context = renderWithHooks( + null, + workInProgress, + updateExpirationTime, + current$$1, + context, + renderExpirationTime + ); workInProgress.effectTag |= 1; if ( "object" === typeof context && @@ -3979,6 +4254,7 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { void 0 === context.$$typeof ) { workInProgress.tag = 1; + resetHooks(); if (isContextProvider(updateExpirationTime)) { var hasContext = !0; pushContextProvider(workInProgress); @@ -4250,18 +4526,14 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; - hasContext = - (oldValue === hasContext && - (0 !== oldValue || 1 / oldValue === 1 / hasContext)) || - (oldValue !== oldValue && hasContext !== hasContext) - ? 0 - : ("function" === - typeof updateExpirationTime._calculateChangedBits - ? updateExpirationTime._calculateChangedBits( - oldValue, - hasContext - ) - : 1073741823) | 0; + hasContext = is(oldValue, hasContext) + ? 0 + : ("function" === typeof updateExpirationTime._calculateChangedBits + ? updateExpirationTime._calculateChangedBits( + oldValue, + hasContext + ) + : 1073741823) | 0; if (0 === hasContext) { if ( getDerivedStateFromProps.children === context.children && @@ -4276,83 +4548,79 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { } } else for ( - getDerivedStateFromProps = workInProgress.child, - null !== getDerivedStateFromProps && - (getDerivedStateFromProps.return = workInProgress); - null !== getDerivedStateFromProps; + oldValue = workInProgress.child, + null !== oldValue && (oldValue.return = workInProgress); + null !== oldValue; ) { - oldValue = getDerivedStateFromProps.firstContextDependency; - if (null !== oldValue) { - do { + var list = oldValue.contextDependencies; + if (null !== list) { + getDerivedStateFromProps = oldValue.child; + for (var dependency = list.first; null !== dependency; ) { if ( - oldValue.context === updateExpirationTime && - 0 !== (oldValue.observedBits & hasContext) + dependency.context === updateExpirationTime && + 0 !== (dependency.observedBits & hasContext) ) { - if (1 === getDerivedStateFromProps.tag) { - var nextFiber = createUpdate(renderExpirationTime); - nextFiber.tag = 2; - enqueueUpdate(getDerivedStateFromProps, nextFiber); - } - getDerivedStateFromProps.expirationTime < - renderExpirationTime && - (getDerivedStateFromProps.expirationTime = renderExpirationTime); - nextFiber = getDerivedStateFromProps.alternate; - null !== nextFiber && - nextFiber.expirationTime < renderExpirationTime && - (nextFiber.expirationTime = renderExpirationTime); - for ( - var node = getDerivedStateFromProps.return; - null !== node; - - ) { - nextFiber = node.alternate; + 1 === oldValue.tag && + ((dependency = createUpdate(renderExpirationTime)), + (dependency.tag = ForceUpdate), + enqueueUpdate(oldValue, dependency)); + oldValue.expirationTime < renderExpirationTime && + (oldValue.expirationTime = renderExpirationTime); + dependency = oldValue.alternate; + null !== dependency && + dependency.expirationTime < renderExpirationTime && + (dependency.expirationTime = renderExpirationTime); + for (var node = oldValue.return; null !== node; ) { + dependency = node.alternate; if (node.childExpirationTime < renderExpirationTime) (node.childExpirationTime = renderExpirationTime), - null !== nextFiber && - nextFiber.childExpirationTime < + null !== dependency && + dependency.childExpirationTime < renderExpirationTime && - (nextFiber.childExpirationTime = renderExpirationTime); + (dependency.childExpirationTime = renderExpirationTime); else if ( - null !== nextFiber && - nextFiber.childExpirationTime < renderExpirationTime + null !== dependency && + dependency.childExpirationTime < renderExpirationTime ) - nextFiber.childExpirationTime = renderExpirationTime; + dependency.childExpirationTime = renderExpirationTime; else break; node = node.return; } + list.expirationTime < renderExpirationTime && + (list.expirationTime = renderExpirationTime); + break; } - nextFiber = getDerivedStateFromProps.child; - oldValue = oldValue.next; - } while (null !== oldValue); + dependency = dependency.next; + } } else - nextFiber = - 10 === getDerivedStateFromProps.tag - ? getDerivedStateFromProps.type === workInProgress.type + getDerivedStateFromProps = + 10 === oldValue.tag + ? oldValue.type === workInProgress.type ? null - : getDerivedStateFromProps.child - : getDerivedStateFromProps.child; - if (null !== nextFiber) - nextFiber.return = getDerivedStateFromProps; + : oldValue.child + : oldValue.child; + if (null !== getDerivedStateFromProps) + getDerivedStateFromProps.return = oldValue; else for ( - nextFiber = getDerivedStateFromProps; - null !== nextFiber; + getDerivedStateFromProps = oldValue; + null !== getDerivedStateFromProps; ) { - if (nextFiber === workInProgress) { - nextFiber = null; + if (getDerivedStateFromProps === workInProgress) { + getDerivedStateFromProps = null; break; } - getDerivedStateFromProps = nextFiber.sibling; - if (null !== getDerivedStateFromProps) { - getDerivedStateFromProps.return = nextFiber.return; - nextFiber = getDerivedStateFromProps; + oldValue = getDerivedStateFromProps.sibling; + if (null !== oldValue) { + oldValue.return = getDerivedStateFromProps.return; + getDerivedStateFromProps = oldValue; break; } - nextFiber = nextFiber.return; + getDerivedStateFromProps = getDerivedStateFromProps.return; } - getDerivedStateFromProps = nextFiber; + oldValue = getDerivedStateFromProps; } } reconcileChildren( @@ -4452,6 +4720,291 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { ); } } +var valueCursor = { current: null }, + currentlyRenderingFiber = null, + lastContextDependency = null, + lastContextWithAllBitsObserved = null; +function pushProvider(providerFiber, nextValue) { + var context = providerFiber.type._context; + push(valueCursor, context._currentValue2, providerFiber); + context._currentValue2 = nextValue; +} +function popProvider(providerFiber) { + var currentValue = valueCursor.current; + pop(valueCursor, providerFiber); + providerFiber.type._context._currentValue2 = currentValue; +} +function prepareToReadContext(workInProgress, renderExpirationTime) { + currentlyRenderingFiber = workInProgress; + lastContextWithAllBitsObserved = lastContextDependency = null; + var currentDependencies = workInProgress.contextDependencies; + null !== currentDependencies && + currentDependencies.expirationTime >= renderExpirationTime && + (didReceiveUpdate = !0); + workInProgress.contextDependencies = null; +} +function readContext(context, observedBits) { + if ( + lastContextWithAllBitsObserved !== context && + !1 !== observedBits && + 0 !== observedBits + ) { + if ("number" !== typeof observedBits || 1073741823 === observedBits) + (lastContextWithAllBitsObserved = context), (observedBits = 1073741823); + observedBits = { context: context, observedBits: observedBits, next: null }; + null === lastContextDependency + ? (invariant( + null !== currentlyRenderingFiber, + "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()." + ), + (lastContextDependency = observedBits), + (currentlyRenderingFiber.contextDependencies = { + first: observedBits, + expirationTime: 0 + })) + : (lastContextDependency = lastContextDependency.next = observedBits); + } + return context._currentValue2; +} +var UpdateState = 0, + ReplaceState = 1, + ForceUpdate = 2, + CaptureUpdate = 3, + hasForceUpdate = !1; +function createUpdateQueue(baseState) { + return { + baseState: baseState, + firstUpdate: null, + lastUpdate: null, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; +} +function cloneUpdateQueue(currentQueue) { + return { + 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: UpdateState, + payload: null, + callback: null, + next: null, + nextEffect: null + }; +} +function appendUpdateToQueue(queue, update) { + null === queue.lastUpdate + ? (queue.firstUpdate = queue.lastUpdate = update) + : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); +} +function enqueueUpdate(fiber, update) { + 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) + : null === queue1.lastUpdate || null === queue2.lastUpdate + ? (appendUpdateToQueue(queue1, update), + appendUpdateToQueue(queue2, update)) + : (appendUpdateToQueue(queue1, update), (queue2.lastUpdate = update)); +} +function enqueueCapturedUpdate(workInProgress, update) { + 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)); +} +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 ReplaceState: + return ( + (workInProgress = update.payload), + "function" === typeof workInProgress + ? workInProgress.call(instance, prevState, nextProps) + : workInProgress + ); + case CaptureUpdate: + workInProgress.effectTag = (workInProgress.effectTag & -2049) | 64; + case UpdateState: + 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 ForceUpdate: + hasForceUpdate = !0; + } + return prevState; +} +function processUpdateQueue( + workInProgress, + queue, + props, + instance, + renderExpirationTime +) { + hasForceUpdate = !1; + queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + for ( + var newBaseState = queue.baseState, + newFirstUpdate = null, + newExpirationTime = 0, + update = queue.firstUpdate, + resultState = newBaseState; + null !== update; + + ) { + var updateExpirationTime = update.expirationTime; + updateExpirationTime < renderExpirationTime + ? (null === newFirstUpdate && + ((newFirstUpdate = update), (newBaseState = resultState)), + newExpirationTime < updateExpirationTime && + (newExpirationTime = updateExpirationTime)) + : ((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; + _updateExpirationTime < renderExpirationTime + ? (null === updateExpirationTime && + ((updateExpirationTime = update), + null === newFirstUpdate && (newBaseState = resultState)), + newExpirationTime < _updateExpirationTime && + (newExpirationTime = _updateExpirationTime)) + : ((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; + workInProgress.expirationTime = newExpirationTime; + workInProgress.memoizedState = resultState; +} +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)); + commitUpdateEffects(finishedQueue.firstEffect, instance); + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; +} +function commitUpdateEffects(effect, instance) { + for (; null !== effect; ) { + var _callback3 = effect.callback; + if (null !== _callback3) { + effect.callback = null; + var context = instance; + invariant( + "function" === typeof _callback3, + "Invalid argument passed as callback. Expected a function. Instead received: %s", + _callback3 + ); + _callback3.call(context); + } + effect = effect.nextEffect; + } +} +function createCapturedValue(value, source) { + return { + value: value, + source: source, + stack: getStackByFiberInDevAndProd(source) + }; +} var appendAllChildren = void 0, updateHostContainer = void 0, updateHostComponent$1 = void 0, @@ -4695,12 +5248,30 @@ function safelyDetachRef(current$$1) { } else ref.current = null; } +function commitHookEffectList(unmountTag, mountTag, finishedWork) { + finishedWork = finishedWork.updateQueue; + finishedWork = null !== finishedWork ? finishedWork.lastEffect : null; + if (null !== finishedWork) { + var effect = (finishedWork = finishedWork.next); + do { + if ((effect.tag & unmountTag) !== NoEffect$1) { + var destroy = effect.destroy; + effect.destroy = void 0; + void 0 !== destroy && destroy(); + } + (effect.tag & mountTag) !== NoEffect$1 && + ((destroy = effect.create), (effect.destroy = destroy())); + effect = effect.next; + } while (effect !== finishedWork); + } +} function commitWork(current$$1, finishedWork) { switch (finishedWork.tag) { case 0: case 11: case 14: case 15: + commitHookEffectList(UnmountMutation, MountMutation, finishedWork); return; } switch (finishedWork.tag) { @@ -4720,9 +5291,10 @@ function commitWork(current$$1, finishedWork) { ); } } +var PossiblyWeakMap = "function" === typeof WeakMap ? WeakMap : Map; function createRootErrorUpdate(fiber, errorInfo, expirationTime) { expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; + expirationTime.tag = CaptureUpdate; expirationTime.payload = { element: null }; var error = errorInfo.value; expirationTime.callback = function() { @@ -4733,7 +5305,7 @@ function createRootErrorUpdate(fiber, errorInfo, expirationTime) { } function createClassErrorUpdate(fiber, errorInfo, expirationTime) { expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; + expirationTime.tag = CaptureUpdate; var getDerivedStateFromError = fiber.type.getDerivedStateFromError; if ("function" === typeof getDerivedStateFromError) { var error$jscomp$0 = errorInfo.value; @@ -4797,7 +5369,7 @@ function unwindWork(workInProgress) { return null; } } -var DispatcherWithoutHooks = { readContext: readContext }, +var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher, ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner, isWorking = !1, nextUnitOfWork = null, @@ -4807,6 +5379,7 @@ var DispatcherWithoutHooks = { readContext: readContext }, nextRenderDidError = !1, nextEffect = null, isCommitting$1 = !1, + rootWithPendingPassiveEffects = null, passiveEffectCallbackHandle = null, passiveEffectCallback = null, legacyErrorBoundariesThatAlreadyFailed = null; @@ -4820,37 +5393,413 @@ function resetStack() { var interruptedWork$jscomp$0 = interruptedWork; switch (interruptedWork$jscomp$0.tag) { case 1: - var childContextTypes = - interruptedWork$jscomp$0.type.childContextTypes; - null !== childContextTypes && - void 0 !== childContextTypes && - popContext(interruptedWork$jscomp$0); + var childContextTypes = + interruptedWork$jscomp$0.type.childContextTypes; + null !== childContextTypes && + void 0 !== childContextTypes && + popContext(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 10: + popProvider(interruptedWork$jscomp$0); + } + interruptedWork = interruptedWork.return; + } + nextRoot = null; + nextRenderExpirationTime = 0; + nextLatestAbsoluteTimeoutMs = -1; + nextRenderDidError = !1; + nextUnitOfWork = null; +} +function commitAllHostEffects() { + for (; null !== nextEffect; ) { + var effectTag = nextEffect.effectTag; + if (effectTag & 128) { + var current$$1 = nextEffect.alternate; + null !== current$$1 && + ((current$$1 = current$$1.ref), + null !== current$$1 && + ("function" === typeof current$$1 + ? current$$1(null) + : (current$$1.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: + effectTag = nextEffect; + a: for (var node = (current$$1 = effectTag); ; ) { + var current$$1$jscomp$0 = node; + "function" === typeof onCommitFiberUnmount && + onCommitFiberUnmount(current$$1$jscomp$0); + switch (current$$1$jscomp$0.tag) { + case 0: + case 11: + case 14: + case 15: + var updateQueue = current$$1$jscomp$0.updateQueue; + if ( + null !== updateQueue && + ((updateQueue = updateQueue.lastEffect), null !== updateQueue) + ) { + var effect = (updateQueue = updateQueue.next); + do { + var destroy = effect.destroy; + if (void 0 !== destroy) { + var current$$1$jscomp$1 = current$$1$jscomp$0; + try { + destroy(); + } catch (error) { + captureCommitPhaseError(current$$1$jscomp$1, error); + } + } + effect = effect.next; + } while (effect !== updateQueue); + } + break; + case 1: + safelyDetachRef(current$$1$jscomp$0); + updateQueue = current$$1$jscomp$0.stateNode; + if ("function" === typeof updateQueue.componentWillUnmount) + try { + (updateQueue.props = current$$1$jscomp$0.memoizedProps), + (updateQueue.state = current$$1$jscomp$0.memoizedState), + updateQueue.componentWillUnmount(); + } catch (unmountError) { + captureCommitPhaseError(current$$1$jscomp$0, unmountError); + } + break; + case 5: + safelyDetachRef(current$$1$jscomp$0); + break; + case 4: + FabricUIManager.createChildSet( + current$$1$jscomp$0.stateNode.containerInfo + ); + } + if (null !== node.child) + (node.child.return = node), (node = node.child); + else { + if (node === current$$1) break; + for (; null === node.sibling; ) { + if (null === node.return || node.return === current$$1) break a; + node = node.return; + } + node.sibling.return = node.return; + node = node.sibling; + } + } + effectTag.return = null; + effectTag.child = null; + effectTag.memoizedState = null; + effectTag.updateQueue = null; + effectTag = effectTag.alternate; + null !== effectTag && + ((effectTag.return = null), + (effectTag.child = null), + (effectTag.memoizedState = null), + (effectTag.updateQueue = null)); + } + nextEffect = nextEffect.nextEffect; + } +} +function commitBeforeMutationLifecycles() { + for (; null !== nextEffect; ) { + if (nextEffect.effectTag & 256) + a: { + var current$$1 = nextEffect.alternate, + finishedWork = nextEffect; + switch (finishedWork.tag) { + case 0: + case 11: + case 15: + commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork); + break a; + case 1: + if (finishedWork.effectTag & 256 && null !== current$$1) { + var prevProps = current$$1.memoizedProps, + prevState = current$$1.memoizedState; + current$$1 = finishedWork.stateNode; + finishedWork = current$$1.getSnapshotBeforeUpdate( + finishedWork.elementType === finishedWork.type + ? prevProps + : resolveDefaultProps(finishedWork.type, prevProps), + prevState + ); + current$$1.__reactInternalSnapshotBeforeUpdate = finishedWork; + } + break a; + case 3: + case 5: + case 6: + case 4: + case 17: + break a; + 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 commitAllLifeCycles(finishedRoot, committedExpirationTime$jscomp$0) { + for (; null !== nextEffect; ) { + var effectTag = nextEffect.effectTag; + if (effectTag & 36) { + var current$$1 = nextEffect.alternate, + finishedWork = nextEffect, + committedExpirationTime = committedExpirationTime$jscomp$0; + switch (finishedWork.tag) { + case 0: + case 11: + case 15: + commitHookEffectList(UnmountLayout, MountLayout, finishedWork); + break; + case 1: + var instance = finishedWork.stateNode; + if (finishedWork.effectTag & 4) + if (null === current$$1) instance.componentDidMount(); + else { + var prevProps = + finishedWork.elementType === finishedWork.type + ? current$$1.memoizedProps + : resolveDefaultProps( + finishedWork.type, + current$$1.memoizedProps + ); + instance.componentDidUpdate( + prevProps, + current$$1.memoizedState, + instance.__reactInternalSnapshotBeforeUpdate + ); + } + current$$1 = finishedWork.updateQueue; + null !== current$$1 && + commitUpdateQueue( + finishedWork, + current$$1, + instance, + committedExpirationTime + ); break; case 3: - popHostContainer(interruptedWork$jscomp$0); - popTopLevelContextObject(interruptedWork$jscomp$0); + instance = finishedWork.updateQueue; + if (null !== instance) { + current$$1 = null; + if (null !== finishedWork.child) + switch (finishedWork.child.tag) { + case 5: + current$$1 = finishedWork.child.stateNode.canonical; + break; + case 1: + current$$1 = finishedWork.child.stateNode; + } + commitUpdateQueue( + finishedWork, + instance, + current$$1, + committedExpirationTime + ); + } break; case 5: - popHostContext(interruptedWork$jscomp$0); + null === current$$1 && + finishedWork.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: - popHostContainer(interruptedWork$jscomp$0); break; - case 10: - popProvider(interruptedWork$jscomp$0); + case 12: + break; + case 13: + break; + case 17: + 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." + ); } - interruptedWork = interruptedWork.return; } - nextRoot = null; - nextRenderExpirationTime = 0; - nextLatestAbsoluteTimeoutMs = -1; - nextRenderDidError = !1; - nextUnitOfWork = null; + if ( + effectTag & 128 && + ((finishedWork = nextEffect.ref), null !== finishedWork) + ) { + committedExpirationTime = nextEffect.stateNode; + switch (nextEffect.tag) { + case 5: + committedExpirationTime = committedExpirationTime.canonical; + } + "function" === typeof finishedWork + ? finishedWork(committedExpirationTime) + : (finishedWork.current = committedExpirationTime); + } + effectTag & 512 && (rootWithPendingPassiveEffects = finishedRoot); + nextEffect = nextEffect.nextEffect; + } +} +function commitPassiveEffects(root, firstEffect) { + passiveEffectCallback = passiveEffectCallbackHandle = rootWithPendingPassiveEffects = null; + var previousIsRendering = isRendering; + isRendering = !0; + do { + if (firstEffect.effectTag & 512) { + var didError = !1, + error = void 0; + try { + var finishedWork = firstEffect; + commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork); + commitHookEffectList(NoEffect$1, MountPassive, finishedWork); + } catch (e) { + (didError = !0), (error = e); + } + didError && captureCommitPhaseError(firstEffect, error); + } + firstEffect = firstEffect.nextEffect; + } while (null !== firstEffect); + isRendering = previousIsRendering; + previousIsRendering = root.expirationTime; + 0 !== previousIsRendering && requestWork(root, previousIsRendering); } function flushPassiveEffects() { - null !== passiveEffectCallback && - (scheduler.unstable_cancelCallback(passiveEffectCallbackHandle), - passiveEffectCallback()); + if (null !== passiveEffectCallbackHandle) { + var callbackID = passiveEffectCallbackHandle; + scheduledCallback = null; + clearTimeout(callbackID); + } + null !== passiveEffectCallback && passiveEffectCallback(); +} +function commitRoot(root, finishedWork) { + isCommitting$1 = isWorking = !0; + 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( + 0 !== committedExpirationTime, + "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." + ); + root.pendingCommitExpirationTime = 0; + var updateExpirationTimeBeforeCommit = finishedWork.expirationTime, + childExpirationTimeBeforeCommit = finishedWork.childExpirationTime; + markCommittedPriorityLevels( + root, + childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit + ? childExpirationTimeBeforeCommit + : updateExpirationTimeBeforeCommit + ); + ReactCurrentOwner$2.current = null; + updateExpirationTimeBeforeCommit = void 0; + 1 < finishedWork.effectTag + ? null !== finishedWork.lastEffect + ? ((finishedWork.lastEffect.nextEffect = finishedWork), + (updateExpirationTimeBeforeCommit = finishedWork.firstEffect)) + : (updateExpirationTimeBeforeCommit = finishedWork) + : (updateExpirationTimeBeforeCommit = finishedWork.firstEffect); + for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) { + childExpirationTimeBeforeCommit = !1; + var error = void 0; + try { + commitBeforeMutationLifecycles(); + } catch (e) { + (childExpirationTimeBeforeCommit = !0), (error = e); + } + childExpirationTimeBeforeCommit && + (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 = updateExpirationTimeBeforeCommit; null !== nextEffect; ) { + childExpirationTimeBeforeCommit = !1; + error = void 0; + try { + commitAllHostEffects(); + } catch (e) { + (childExpirationTimeBeforeCommit = !0), (error = e); + } + childExpirationTimeBeforeCommit && + (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)); + } + root.current = finishedWork; + for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) { + childExpirationTimeBeforeCommit = !1; + error = void 0; + try { + commitAllLifeCycles(root, committedExpirationTime); + } catch (e) { + (childExpirationTimeBeforeCommit = !0), (error = e); + } + childExpirationTimeBeforeCommit && + (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)); + } + if ( + null !== updateExpirationTimeBeforeCommit && + null !== rootWithPendingPassiveEffects + ) { + var callback = commitPassiveEffects.bind( + null, + root, + updateExpirationTimeBeforeCommit + ); + passiveEffectCallbackHandle = scheduler.unstable_runWithPriority( + scheduler.unstable_NormalPriority, + function() { + return scheduleDeferredCallback$1(callback); + } + ); + passiveEffectCallback = callback; + } + isWorking = isCommitting$1 = !1; + "function" === typeof onCommitFiberRoot && + onCommitFiberRoot(finishedWork.stateNode); + committedExpirationTime = finishedWork.expirationTime; + finishedWork = finishedWork.childExpirationTime; + finishedWork = + finishedWork > committedExpirationTime + ? finishedWork + : committedExpirationTime; + 0 === finishedWork && (legacyErrorBoundariesThatAlreadyFailed = null); + onCommit(root, finishedWork); } function completeUnitOfWork(workInProgress) { for (;;) { @@ -4989,11 +5938,7 @@ function completeUnitOfWork(workInProgress) { : ((current$$1.firstEffect = current$$1.lastEffect = current), (current.nextEffect = null)), (current.effectTag = 8))); - if ( - instance !== renderExpirationTime || - (0 === (current$$1.effectTag & 1) && instance) - ) - current$$1.effectTag |= 4; + if (instance || renderExpirationTime) current$$1.effectTag |= 4; break; case 7: break; @@ -5084,7 +6029,8 @@ function renderRoot(root$jscomp$0, isYieldy) { ); flushPassiveEffects(); isWorking = !0; - ReactCurrentOwner$2.currentDispatcher = DispatcherWithoutHooks; + var previousDispatcher = ReactCurrentDispatcher.current; + ReactCurrentDispatcher.current = ContextOnlyDispatcher; var expirationTime = root$jscomp$0.nextExpirationTimeToWorkOn; if ( expirationTime !== nextRenderExpirationTime || @@ -5112,6 +6058,7 @@ function renderRoot(root$jscomp$0, isYieldy) { } catch (thrownValue) { if ( ((lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = null), + resetHooks(), null === nextUnitOfWork) ) (didFatal = !0), onUncaughtError(thrownValue); @@ -5171,23 +6118,47 @@ function renderRoot(root$jscomp$0, isYieldy) { ? !1 : null === value.memoizedState; if (current$$1) { - returnFiber$jscomp$0 = retrySuspendedRoot.bind( - null, - root, - value, - sourceFiber$jscomp$0, - 0 === (value.mode & 1) ? 1073741823 : returnFiber - ); - thenable.then(returnFiber$jscomp$0, returnFiber$jscomp$0); + returnFiber$jscomp$0 = value.updateQueue; + null === returnFiber$jscomp$0 + ? ((returnFiber$jscomp$0 = new Set()), + returnFiber$jscomp$0.add(thenable), + (value.updateQueue = returnFiber$jscomp$0)) + : returnFiber$jscomp$0.add(thenable); if (0 === (value.mode & 1)) { value.effectTag |= 64; sourceFiber$jscomp$0.effectTag &= -1957; 1 === sourceFiber$jscomp$0.tag && - null === sourceFiber$jscomp$0.alternate && - (sourceFiber$jscomp$0.tag = 17); - sourceFiber$jscomp$0.expirationTime = returnFiber; + (null === sourceFiber$jscomp$0.alternate + ? (sourceFiber$jscomp$0.tag = 17) + : ((returnFiber = createUpdate(1073741823)), + (returnFiber.tag = ForceUpdate), + enqueueUpdate(sourceFiber$jscomp$0, returnFiber))); + sourceFiber$jscomp$0.expirationTime = 1073741823; break a; } + sourceFiber$jscomp$0 = root.pingCache; + null === sourceFiber$jscomp$0 + ? ((sourceFiber$jscomp$0 = root.pingCache = new PossiblyWeakMap()), + (returnFiber$jscomp$0 = new Set()), + sourceFiber$jscomp$0.set(thenable, returnFiber$jscomp$0)) + : ((returnFiber$jscomp$0 = sourceFiber$jscomp$0.get( + thenable + )), + void 0 === returnFiber$jscomp$0 && + ((returnFiber$jscomp$0 = new Set()), + sourceFiber$jscomp$0.set( + thenable, + returnFiber$jscomp$0 + ))); + returnFiber$jscomp$0.has(returnFiber) || + (returnFiber$jscomp$0.add(returnFiber), + (sourceFiber$jscomp$0 = pingSuspendedRoot.bind( + null, + root, + thenable, + returnFiber + )), + thenable.then(sourceFiber$jscomp$0, sourceFiber$jscomp$0)); -1 === earliestTimeoutMs ? (root = 1073741823) : (-1 === startTimeMs && @@ -5222,36 +6193,31 @@ function renderRoot(root$jscomp$0, isYieldy) { do { switch (root.tag) { case 3: - sourceFiber$jscomp$0 = value; root.effectTag |= 2048; root.expirationTime = returnFiber; - returnFiber = createRootErrorUpdate( - root, - sourceFiber$jscomp$0, - returnFiber - ); + returnFiber = createRootErrorUpdate(root, value, returnFiber); enqueueCapturedUpdate(root, returnFiber); break a; case 1: if ( - ((sourceFiber$jscomp$0 = value), - (returnFiber$jscomp$0 = root.type), - (thenable = root.stateNode), + ((thenable = value), + (earliestTimeoutMs = root.type), + (startTimeMs = root.stateNode), 0 === (root.effectTag & 64) && ("function" === - typeof returnFiber$jscomp$0.getDerivedStateFromError || - (null !== thenable && - "function" === typeof thenable.componentDidCatch && + typeof earliestTimeoutMs.getDerivedStateFromError || + (null !== startTimeMs && + "function" === typeof startTimeMs.componentDidCatch && (null === legacyErrorBoundariesThatAlreadyFailed || !legacyErrorBoundariesThatAlreadyFailed.has( - thenable + startTimeMs ))))) ) { root.effectTag |= 2048; root.expirationTime = returnFiber; returnFiber = createClassErrorUpdate( root, - sourceFiber$jscomp$0, + thenable, returnFiber ); enqueueCapturedUpdate(root, returnFiber); @@ -5269,29 +6235,31 @@ function renderRoot(root$jscomp$0, isYieldy) { break; } while (1); isWorking = !1; - lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = ReactCurrentOwner$2.currentDispatcher = null; + ReactCurrentDispatcher.current = previousDispatcher; + lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = null; + resetHooks(); if (didFatal) (nextRoot = null), (root$jscomp$0.finishedWork = null); else if (null !== nextUnitOfWork) root$jscomp$0.finishedWork = null; else { - didFatal = root$jscomp$0.current.alternate; + previousDispatcher = root$jscomp$0.current.alternate; invariant( - null !== didFatal, + null !== previousDispatcher, "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue." ); nextRoot = null; if (nextRenderDidError) { - sourceFiber = root$jscomp$0.latestPendingTime; - returnFiber = root$jscomp$0.latestSuspendedTime; - root = root$jscomp$0.latestPingedTime; + didFatal = root$jscomp$0.latestPendingTime; + sourceFiber = root$jscomp$0.latestSuspendedTime; + returnFiber = root$jscomp$0.latestPingedTime; if ( + (0 !== didFatal && didFatal < expirationTime) || (0 !== sourceFiber && sourceFiber < expirationTime) || - (0 !== returnFiber && returnFiber < expirationTime) || - (0 !== root && root < expirationTime) + (0 !== returnFiber && returnFiber < expirationTime) ) { markSuspendedPriorityLevel(root$jscomp$0, expirationTime); onSuspend( root$jscomp$0, - didFatal, + previousDispatcher, expirationTime, root$jscomp$0.expirationTime, -1 @@ -5302,7 +6270,13 @@ function renderRoot(root$jscomp$0, isYieldy) { root$jscomp$0.didError = !0; expirationTime = root$jscomp$0.nextExpirationTimeToWorkOn = expirationTime; isYieldy = root$jscomp$0.expirationTime = 1073741823; - onSuspend(root$jscomp$0, didFatal, expirationTime, isYieldy, -1); + onSuspend( + root$jscomp$0, + previousDispatcher, + expirationTime, + isYieldy, + -1 + ); return; } } @@ -5321,13 +6295,13 @@ function renderRoot(root$jscomp$0, isYieldy) { (isYieldy = nextLatestAbsoluteTimeoutMs - isYieldy), onSuspend( root$jscomp$0, - didFatal, + previousDispatcher, expirationTime, root$jscomp$0.expirationTime, 0 > isYieldy ? 0 : isYieldy )) : ((root$jscomp$0.pendingCommitExpirationTime = expirationTime), - (root$jscomp$0.finishedWork = didFatal)); + (root$jscomp$0.finishedWork = previousDispatcher)); } } function captureCommitPhaseError(sourceFiber, value) { @@ -5364,57 +6338,63 @@ function captureCommitPhaseError(sourceFiber, value) { scheduleWork(sourceFiber, 1073741823)); } function computeExpirationForFiber(currentTime, fiber) { - isWorking - ? (currentTime = isCommitting$1 ? 1073741823 : nextRenderExpirationTime) - : fiber.mode & 1 - ? ((currentTime = isBatchingInteractiveUpdates - ? 1073741822 - 10 * ((((1073741822 - currentTime + 15) / 10) | 0) + 1) - : 1073741822 - - 25 * ((((1073741822 - currentTime + 500) / 25) | 0) + 1)), - null !== nextRoot && - currentTime === nextRenderExpirationTime && - --currentTime) - : (currentTime = 1073741823); - isBatchingInteractiveUpdates && + var priorityLevel = scheduler.unstable_getCurrentPriorityLevel(), + expirationTime = void 0; + if (0 === (fiber.mode & 1)) expirationTime = 1073741823; + else if (isWorking && !isCommitting$1) + expirationTime = nextRenderExpirationTime; + else { + switch (priorityLevel) { + case scheduler.unstable_ImmediatePriority: + expirationTime = 1073741823; + break; + case scheduler.unstable_UserBlockingPriority: + expirationTime = + 1073741822 - 10 * ((((1073741822 - currentTime + 15) / 10) | 0) + 1); + break; + case scheduler.unstable_NormalPriority: + expirationTime = + 1073741822 - 25 * ((((1073741822 - currentTime + 500) / 25) | 0) + 1); + break; + case scheduler.unstable_LowPriority: + case scheduler.unstable_IdlePriority: + expirationTime = 1; + break; + default: + invariant( + !1, + "Unknown priority level. This error is likely caused by a bug in React. Please file an issue." + ); + } + null !== nextRoot && + expirationTime === nextRenderExpirationTime && + --expirationTime; + } + priorityLevel === scheduler.unstable_UserBlockingPriority && (0 === lowestPriorityPendingInteractiveExpirationTime || - currentTime < lowestPriorityPendingInteractiveExpirationTime) && - (lowestPriorityPendingInteractiveExpirationTime = currentTime); - return currentTime; + expirationTime < lowestPriorityPendingInteractiveExpirationTime) && + (lowestPriorityPendingInteractiveExpirationTime = expirationTime); + return expirationTime; } -function retrySuspendedRoot(root, boundaryFiber, sourceFiber, suspendedTime) { - var retryTime = root.earliestSuspendedTime; - var latestSuspendedTime = root.latestSuspendedTime; - if ( - 0 !== retryTime && - suspendedTime <= retryTime && - suspendedTime >= latestSuspendedTime +function pingSuspendedRoot(root, thenable, pingTime) { + var pingCache = root.pingCache; + null !== pingCache && pingCache.delete(thenable); + if (null !== nextRoot && nextRenderExpirationTime === pingTime) + nextRoot = null; + else if ( + ((thenable = root.earliestSuspendedTime), + (pingCache = root.latestSuspendedTime), + 0 !== thenable && pingTime <= thenable && pingTime >= pingCache) ) { - latestSuspendedTime = retryTime = suspendedTime; root.didError = !1; - var latestPingedTime = root.latestPingedTime; - if (0 === latestPingedTime || latestPingedTime > latestSuspendedTime) - root.latestPingedTime = latestSuspendedTime; - findNextExpirationTimeToWorkOn(latestSuspendedTime, root); - } else - (retryTime = requestCurrentTime()), - (retryTime = computeExpirationForFiber(retryTime, boundaryFiber)), - markPendingPriorityLevel(root, retryTime); - 0 !== (boundaryFiber.mode & 1) && - root === nextRoot && - nextRenderExpirationTime === suspendedTime && - (nextRoot = null); - scheduleWorkToRoot(boundaryFiber, retryTime); - 0 === (boundaryFiber.mode & 1) && - (scheduleWorkToRoot(sourceFiber, retryTime), - 1 === sourceFiber.tag && - null !== sourceFiber.stateNode && - ((boundaryFiber = createUpdate(retryTime)), - (boundaryFiber.tag = 2), - enqueueUpdate(sourceFiber, boundaryFiber))); - sourceFiber = root.expirationTime; - 0 !== sourceFiber && requestWork(root, sourceFiber); -} -function scheduleWorkToRoot(fiber, expirationTime) { + thenable = root.latestPingedTime; + if (0 === thenable || thenable > pingTime) root.latestPingedTime = pingTime; + findNextExpirationTimeToWorkOn(pingTime, root); + pingTime = root.expirationTime; + 0 !== pingTime && requestWork(root, pingTime); + } +} +function scheduleWork(fiber, expirationTime) { fiber.expirationTime < expirationTime && (fiber.expirationTime = expirationTime); var alternate = fiber.alternate; @@ -5438,10 +6418,7 @@ function scheduleWorkToRoot(fiber, expirationTime) { } node = node.return; } - return root; -} -function scheduleWork(fiber, expirationTime) { - fiber = scheduleWorkToRoot(fiber, expirationTime); + fiber = root; null !== fiber && (!isWorking && 0 !== nextRenderExpirationTime && @@ -5469,7 +6446,6 @@ var firstScheduledRoot = null, unhandledError = null, isBatchingUpdates = !1, isUnbatchingUpdates = !1, - isBatchingInteractiveUpdates = !1, completedBatches = null, originalStartTimeMs = now$1(), currentRendererTime = 1073741822 - ((originalStartTimeMs / 10) | 0), @@ -5488,9 +6464,10 @@ function scheduleCallbackWithExpirationTime(root, expirationTime) { ((root = callbackID), (scheduledCallback = null), clearTimeout(root)); } callbackExpirationTime = expirationTime; - now$1(); - scheduledCallback = performAsyncWork; - callbackID = setTimeout(setTimeoutCallback, 1); + root = now$1() - originalStartTimeMs; + callbackID = scheduleDeferredCallback$1(performAsyncWork, { + timeout: 10 * (1073741822 - expirationTime) - root + }); } function onSuspend( root, @@ -5523,6 +6500,10 @@ function onTimeout(root, finishedWork, suspendedExpirationTime) { performWorkOnRoot(root, suspendedExpirationTime, !1); performWork(1073741823, !1); } +function onCommit(root, expirationTime) { + root.expirationTime = expirationTime; + root.finishedWork = null; +} function requestCurrentTime() { if (isRendering) return currentSchedulerTime; findHighestPriorityRoot(); @@ -5712,7 +6693,7 @@ function performWorkOnRoot(root, expirationTime, isYieldy) { completeRoot$1(root, _finishedWork, expirationTime)); isRendering = !1; } -function completeRoot$1(root, finishedWork$jscomp$0, expirationTime) { +function completeRoot$1(root, finishedWork, expirationTime) { var firstBatch = root.firstBatch; if ( null !== firstBatch && @@ -5722,7 +6703,7 @@ function completeRoot$1(root, finishedWork$jscomp$0, expirationTime) { : completedBatches.push(firstBatch), firstBatch._defer) ) { - root.finishedWork = finishedWork$jscomp$0; + root.finishedWork = finishedWork; root.expirationTime = 0; return; } @@ -5730,364 +6711,12 @@ function completeRoot$1(root, finishedWork$jscomp$0, expirationTime) { root === lastCommittedRootDuringThisBatch ? nestedUpdateCount++ : ((lastCommittedRootDuringThisBatch = root), (nestedUpdateCount = 0)); - 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; - var childExpirationTimeBeforeCommit = - finishedWork$jscomp$0.childExpirationTime; - firstBatch = - childExpirationTimeBeforeCommit > firstBatch - ? childExpirationTimeBeforeCommit - : firstBatch; - root.didError = !1; - 0 === firstBatch - ? ((root.earliestPendingTime = 0), - (root.latestPendingTime = 0), - (root.earliestSuspendedTime = 0), - (root.latestSuspendedTime = 0), - (root.latestPingedTime = 0)) - : ((childExpirationTimeBeforeCommit = root.latestPendingTime), - 0 !== childExpirationTimeBeforeCommit && - (childExpirationTimeBeforeCommit > firstBatch - ? (root.earliestPendingTime = root.latestPendingTime = 0) - : root.earliestPendingTime > firstBatch && - (root.earliestPendingTime = root.latestPendingTime)), - (childExpirationTimeBeforeCommit = root.earliestSuspendedTime), - 0 === childExpirationTimeBeforeCommit - ? markPendingPriorityLevel(root, firstBatch) - : firstBatch < root.latestSuspendedTime - ? ((root.earliestSuspendedTime = 0), - (root.latestSuspendedTime = 0), - (root.latestPingedTime = 0), - markPendingPriorityLevel(root, firstBatch)) - : firstBatch > childExpirationTimeBeforeCommit && - markPendingPriorityLevel(root, firstBatch)); - findNextExpirationTimeToWorkOn(0, root); - ReactCurrentOwner$2.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; ) { - childExpirationTimeBeforeCommit = !1; - var error$jscomp$0 = void 0; - try { - for (; null !== nextEffect; ) { - if (nextEffect.effectTag & 256) - a: { - var current$$1 = nextEffect.alternate, - finishedWork = nextEffect; - switch (finishedWork.tag) { - case 0: - case 11: - case 15: - break a; - case 1: - if (finishedWork.effectTag & 256 && null !== current$$1) { - var prevProps = current$$1.memoizedProps, - prevState = current$$1.memoizedState, - instance = finishedWork.stateNode, - snapshot = instance.getSnapshotBeforeUpdate( - finishedWork.elementType === finishedWork.type - ? prevProps - : resolveDefaultProps(finishedWork.type, prevProps), - prevState - ); - instance.__reactInternalSnapshotBeforeUpdate = snapshot; - } - break a; - case 3: - case 5: - case 6: - case 4: - case 17: - break a; - 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) { - (childExpirationTimeBeforeCommit = !0), (error$jscomp$0 = e); - } - childExpirationTimeBeforeCommit && - (invariant( - null !== nextEffect, - "Should have next effect. This error is likely caused by a bug in React. Please file an issue." - ), - captureCommitPhaseError(nextEffect, error$jscomp$0), - null !== nextEffect && (nextEffect = nextEffect.nextEffect)); - } - for (nextEffect = firstBatch; null !== nextEffect; ) { - current$$1 = !1; - prevProps = void 0; - try { - for (; null !== nextEffect; ) { - var effectTag = nextEffect.effectTag; - if (effectTag & 128) { - var current$$1$jscomp$0 = nextEffect.alternate; - if (null !== current$$1$jscomp$0) { - var currentRef = current$$1$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; ; ) { - childExpirationTimeBeforeCommit = snapshot; - "function" === typeof onCommitFiberUnmount && - onCommitFiberUnmount(childExpirationTimeBeforeCommit); - switch (childExpirationTimeBeforeCommit.tag) { - case 0: - case 11: - case 14: - case 15: - var updateQueue = childExpirationTimeBeforeCommit.updateQueue; - if (null !== updateQueue) { - var lastEffect = updateQueue.lastEffect; - if (null !== lastEffect) { - var firstEffect = lastEffect.next; - error$jscomp$0 = firstEffect; - do { - var destroy = error$jscomp$0.destroy; - if (null !== destroy) { - finishedWork = childExpirationTimeBeforeCommit; - try { - destroy(); - } catch (error) { - captureCommitPhaseError(finishedWork, error); - } - } - error$jscomp$0 = error$jscomp$0.next; - } while (error$jscomp$0 !== firstEffect); - } - } - break; - case 1: - safelyDetachRef(childExpirationTimeBeforeCommit); - var instance$jscomp$0 = - childExpirationTimeBeforeCommit.stateNode; - if ( - "function" === typeof instance$jscomp$0.componentWillUnmount - ) - try { - (instance$jscomp$0.props = - childExpirationTimeBeforeCommit.memoizedProps), - (instance$jscomp$0.state = - childExpirationTimeBeforeCommit.memoizedState), - instance$jscomp$0.componentWillUnmount(); - } catch (unmountError) { - captureCommitPhaseError( - childExpirationTimeBeforeCommit, - unmountError - ); - } - break; - case 5: - safelyDetachRef(childExpirationTimeBeforeCommit); - break; - case 4: - FabricUIManager.createChildSet( - childExpirationTimeBeforeCommit.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.memoizedState = null; - prevState.updateQueue = null; - var alternate = prevState.alternate; - null !== alternate && - ((alternate.return = null), - (alternate.child = null), - (alternate.memoizedState = null), - (alternate.updateQueue = null)); - } - nextEffect = nextEffect.nextEffect; - } - } catch (e) { - (current$$1 = !0), (prevProps = e); - } - current$$1 && - (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$$1$jscomp$0 = void 0; - try { - for (currentRef = expirationTime; null !== nextEffect; ) { - var effectTag$jscomp$0 = nextEffect.effectTag; - if (effectTag$jscomp$0 & 36) { - var current$$1$jscomp$1 = nextEffect.alternate; - updateQueue = nextEffect; - lastEffect = currentRef; - switch (updateQueue.tag) { - case 0: - case 11: - case 15: - break; - case 1: - var instance$jscomp$1 = updateQueue.stateNode; - if (updateQueue.effectTag & 4) - if (null === current$$1$jscomp$1) - instance$jscomp$1.componentDidMount(); - else { - var prevProps$jscomp$0 = - updateQueue.elementType === updateQueue.type - ? current$$1$jscomp$1.memoizedProps - : resolveDefaultProps( - updateQueue.type, - current$$1$jscomp$1.memoizedProps - ); - instance$jscomp$1.componentDidUpdate( - prevProps$jscomp$0, - current$$1$jscomp$1.memoizedState, - instance$jscomp$1.__reactInternalSnapshotBeforeUpdate - ); - } - var updateQueue$jscomp$0 = updateQueue.updateQueue; - null !== updateQueue$jscomp$0 && - commitUpdateQueue( - updateQueue, - updateQueue$jscomp$0, - instance$jscomp$1, - lastEffect - ); - break; - case 3: - var _updateQueue = updateQueue.updateQueue; - if (null !== _updateQueue) { - firstEffect = null; - if (null !== updateQueue.child) - switch (updateQueue.child.tag) { - case 5: - firstEffect = updateQueue.child.stateNode.canonical; - break; - case 1: - firstEffect = updateQueue.child.stateNode; - } - commitUpdateQueue( - updateQueue, - _updateQueue, - firstEffect, - lastEffect - ); - } - break; - case 5: - null === current$$1$jscomp$1 && - updateQueue.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 12: - break; - case 13: - break; - case 17: - 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) { - var ref = nextEffect.ref; - if (null !== ref) { - var instance$jscomp$2 = nextEffect.stateNode; - switch (nextEffect.tag) { - case 5: - var instanceToUse = instance$jscomp$2.canonical; - break; - default: - instanceToUse = instance$jscomp$2; - } - "function" === typeof ref - ? ref(instanceToUse) - : (ref.current = instanceToUse); - } - } - nextEffect = nextEffect.nextEffect; - } - } catch (e) { - (effectTag = !0), (current$$1$jscomp$0 = e); + scheduler.unstable_runWithPriority( + scheduler.unstable_ImmediatePriority, + function() { + commitRoot(root, finishedWork); } - 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$$1$jscomp$0), - null !== nextEffect && (nextEffect = nextEffect.nextEffect)); - } - isWorking = isCommitting$1 = !1; - "function" === typeof onCommitFiberRoot && - onCommitFiberRoot(finishedWork$jscomp$0.stateNode); - effectTag$jscomp$0 = finishedWork$jscomp$0.expirationTime; - finishedWork$jscomp$0 = finishedWork$jscomp$0.childExpirationTime; - finishedWork$jscomp$0 = - finishedWork$jscomp$0 > effectTag$jscomp$0 - ? finishedWork$jscomp$0 - : effectTag$jscomp$0; - 0 === finishedWork$jscomp$0 && - (legacyErrorBoundariesThatAlreadyFailed = null); - root.expirationTime = finishedWork$jscomp$0; - root.finishedWork = null; + ); } function onUncaughtError(error) { invariant( @@ -6316,6 +6945,7 @@ var roots = new Map(), current: root, containerInfo: containerTag, pendingChildren: null, + pingCache: null, earliestPendingTime: 0, latestPendingTime: 0, earliestSuspendedTime: 0, @@ -6421,6 +7051,8 @@ var roots = new Map(), var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; return injectInternals( Object.assign({}, devToolsConfig, { + overrideProps: null, + currentDispatcherRef: ReactSharedInternals.ReactCurrentDispatcher, findHostInstanceByFiber: function(fiber) { fiber = findCurrentHostFiber(fiber); return null === fiber ? null : fiber.stateNode; @@ -6436,7 +7068,7 @@ var roots = new Map(), findFiberByHostInstance: getInstanceFromInstance, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 0, - version: "16.6.1", + version: "16.8.1", rendererPackageName: "react-native-renderer" }); var ReactFabric$2 = { default: ReactFabric }, diff --git a/Libraries/Renderer/oss/ReactFabric-profiling.js b/Libraries/Renderer/oss/ReactFabric-profiling.js index f327de43d86241..6ec6204f8c0abb 100644 --- a/Libraries/Renderer/oss/ReactFabric-profiling.js +++ b/Libraries/Renderer/oss/ReactFabric-profiling.js @@ -1020,8 +1020,10 @@ ResponderEventPlugin.injection.injectGlobalResponderHandler({ } }); var ReactSharedInternals = - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, - hasSymbol = "function" === typeof Symbol && Symbol.for, + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; +ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher") || + (ReactSharedInternals.ReactCurrentDispatcher = { current: null }); +var 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, @@ -1431,6 +1433,10 @@ function setTimeoutCallback() { scheduledCallback = null; null !== callback && callback(); } +function scheduleDeferredCallback$1(callback) { + scheduledCallback = callback; + return setTimeout(setTimeoutCallback, 1); +} var restoreTarget = null, restoreQueue = null; function restoreStateOfTarget(target) { @@ -1779,7 +1785,7 @@ function FiberNode(tag, pendingProps, key, mode) { this.index = 0; this.ref = null; this.pendingProps = pendingProps; - this.firstContextDependency = this.memoizedState = this.updateQueue = this.memoizedProps = null; + this.contextDependencies = this.memoizedState = this.updateQueue = this.memoizedProps = null; this.mode = mode; this.effectTag = 0; this.lastEffect = this.firstEffect = this.nextEffect = null; @@ -1833,7 +1839,7 @@ function createWorkInProgress(current, pendingProps) { workInProgress.memoizedProps = current.memoizedProps; workInProgress.memoizedState = current.memoizedState; workInProgress.updateQueue = current.updateQueue; - workInProgress.firstContextDependency = current.firstContextDependency; + workInProgress.contextDependencies = current.contextDependencies; workInProgress.sibling = current.sibling; workInProgress.index = current.index; workInProgress.ref = current.ref; @@ -1968,6 +1974,8 @@ function markCommittedPriorityLevels(root, earliestRemainingTime) { (root.latestSuspendedTime = 0), (root.latestPingedTime = 0); else { + earliestRemainingTime < root.latestPingedTime && + (root.latestPingedTime = 0); var latestPendingTime = root.latestPendingTime; 0 !== latestPendingTime && (latestPendingTime > earliestRemainingTime @@ -2000,24 +2008,21 @@ function hasLowerPriorityWork(root, erroredExpirationTime) { } function markSuspendedPriorityLevel(root, suspendedTime) { root.didError = !1; - var latestPingedTime = root.latestPingedTime; - 0 !== latestPingedTime && - latestPingedTime >= suspendedTime && - (root.latestPingedTime = 0); - latestPingedTime = root.earliestPendingTime; - var latestPendingTime = root.latestPendingTime; - latestPingedTime === suspendedTime + root.latestPingedTime >= suspendedTime && (root.latestPingedTime = 0); + var earliestPendingTime = root.earliestPendingTime, + latestPendingTime = root.latestPendingTime; + earliestPendingTime === suspendedTime ? (root.earliestPendingTime = latestPendingTime === suspendedTime ? (root.latestPendingTime = 0) : latestPendingTime) : latestPendingTime === suspendedTime && - (root.latestPendingTime = latestPingedTime); - latestPingedTime = root.earliestSuspendedTime; + (root.latestPendingTime = earliestPendingTime); + earliestPendingTime = root.earliestSuspendedTime; latestPendingTime = root.latestSuspendedTime; - 0 === latestPingedTime + 0 === earliestPendingTime ? (root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime) - : latestPingedTime < suspendedTime + : earliestPendingTime < suspendedTime ? (root.earliestSuspendedTime = suspendedTime) : latestPendingTime > suspendedTime && (root.latestSuspendedTime = suspendedTime); @@ -2049,404 +2054,81 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) { root.nextExpirationTimeToWorkOn = earliestPendingTime; root.expirationTime = completedExpirationTime; } -var hasForceUpdate = !1; -function createUpdateQueue(baseState) { - return { - baseState: baseState, - firstUpdate: null, - lastUpdate: null, - firstCapturedUpdate: null, - lastCapturedUpdate: null, - firstEffect: null, - lastEffect: null, - firstCapturedEffect: null, - lastCapturedEffect: null - }; -} -function cloneUpdateQueue(currentQueue) { - return { - 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) { - null === queue.lastUpdate - ? (queue.firstUpdate = queue.lastUpdate = update) - : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); -} -function enqueueUpdate(fiber, update) { - 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) - : null === queue1.lastUpdate || null === queue2.lastUpdate - ? (appendUpdateToQueue(queue1, update), - appendUpdateToQueue(queue2, update)) - : (appendUpdateToQueue(queue1, update), (queue2.lastUpdate = update)); +function is(x, y) { + return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); } -function enqueueCapturedUpdate(workInProgress, update) { - 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)); +var hasOwnProperty = Object.prototype.hasOwnProperty; +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 ensureWorkInProgressQueueIsAClone(workInProgress, queue) { - var current = workInProgress.alternate; - null !== current && - queue === current.updateQueue && - (queue = workInProgress.updateQueue = cloneUpdateQueue(queue)); - return queue; +function resolveDefaultProps(Component, baseProps) { + if (Component && Component.defaultProps) { + baseProps = Object.assign({}, baseProps); + Component = Component.defaultProps; + for (var propName in Component) + void 0 === baseProps[propName] && + (baseProps[propName] = Component[propName]); + } + return baseProps; } -function getStateFromUpdate( - workInProgress, - queue, - update, - prevState, - nextProps, - instance -) { - switch (update.tag) { +function readLazyComponentType(lazyComponent) { + var result = lazyComponent._result; + switch (lazyComponent._status) { case 1: - return ( - (workInProgress = update.payload), - "function" === typeof workInProgress - ? workInProgress.call(instance, prevState, nextProps) - : workInProgress - ); - case 3: - workInProgress.effectTag = (workInProgress.effectTag & -2049) | 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); + return result; case 2: - hasForceUpdate = !0; + throw result; + case 0: + throw result; + default: + lazyComponent._status = 0; + result = lazyComponent._ctor; + result = result(); + result.then( + function(moduleObject) { + 0 === lazyComponent._status && + ((moduleObject = moduleObject.default), + (lazyComponent._status = 1), + (lazyComponent._result = moduleObject)); + }, + function(error) { + 0 === lazyComponent._status && + ((lazyComponent._status = 2), (lazyComponent._result = error)); + } + ); + switch (lazyComponent._status) { + case 1: + return lazyComponent._result; + case 2: + throw lazyComponent._result; + } + lazyComponent._result = result; + throw result; } - return prevState; } -function processUpdateQueue( +var emptyRefsObject = new React.Component().refs; +function applyDerivedStateFromProps( workInProgress, - queue, - props, - instance, - renderExpirationTime -) { - hasForceUpdate = !1; - queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); - for ( - var newBaseState = queue.baseState, - newFirstUpdate = null, - newExpirationTime = 0, - update = queue.firstUpdate, - resultState = newBaseState; - null !== update; - - ) { - var updateExpirationTime = update.expirationTime; - updateExpirationTime < renderExpirationTime - ? (null === newFirstUpdate && - ((newFirstUpdate = update), (newBaseState = resultState)), - newExpirationTime < updateExpirationTime && - (newExpirationTime = updateExpirationTime)) - : ((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; - _updateExpirationTime < renderExpirationTime - ? (null === updateExpirationTime && - ((updateExpirationTime = update), - null === newFirstUpdate && (newBaseState = resultState)), - newExpirationTime < _updateExpirationTime && - (newExpirationTime = _updateExpirationTime)) - : ((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; - workInProgress.expirationTime = newExpirationTime; - workInProgress.memoizedState = resultState; -} -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)); - commitUpdateEffects(finishedQueue.firstEffect, instance); - finishedQueue.firstEffect = finishedQueue.lastEffect = null; - commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); - finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; -} -function commitUpdateEffects(effect, instance) { - for (; null !== effect; ) { - var _callback3 = effect.callback; - if (null !== _callback3) { - effect.callback = null; - var context = instance; - invariant( - "function" === typeof _callback3, - "Invalid argument passed as callback. Expected a function. Instead received: %s", - _callback3 - ); - _callback3.call(context); - } - effect = effect.nextEffect; - } -} -function createCapturedValue(value, source) { - return { - value: value, - source: source, - stack: getStackByFiberInDevAndProd(source) - }; -} -var valueCursor = { current: null }, - currentlyRenderingFiber = null, - lastContextDependency = null, - lastContextWithAllBitsObserved = null; -function pushProvider(providerFiber, nextValue) { - var context = providerFiber.type._context; - push(valueCursor, context._currentValue2, providerFiber); - context._currentValue2 = nextValue; -} -function popProvider(providerFiber) { - var currentValue = valueCursor.current; - pop(valueCursor, providerFiber); - providerFiber.type._context._currentValue2 = currentValue; -} -function prepareToReadContext(workInProgress) { - currentlyRenderingFiber = workInProgress; - lastContextWithAllBitsObserved = lastContextDependency = null; - workInProgress.firstContextDependency = null; -} -function readContext(context, observedBits) { - if ( - lastContextWithAllBitsObserved !== context && - !1 !== observedBits && - 0 !== observedBits - ) { - if ("number" !== typeof observedBits || 1073741823 === observedBits) - (lastContextWithAllBitsObserved = context), (observedBits = 1073741823); - observedBits = { context: context, observedBits: observedBits, next: null }; - null === lastContextDependency - ? (invariant( - null !== currentlyRenderingFiber, - "Context can only be read while React is rendering, e.g. inside the render method or getDerivedStateFromProps." - ), - (currentlyRenderingFiber.firstContextDependency = lastContextDependency = observedBits)) - : (lastContextDependency = lastContextDependency.next = observedBits); - } - return context._currentValue2; -} -var NO_CONTEXT = {}, - contextStackCursor$1 = { current: NO_CONTEXT }, - contextFiberStackCursor = { current: NO_CONTEXT }, - rootInstanceStackCursor = { current: 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 pushHostContext(fiber) { - requiredContext(rootInstanceStackCursor.current); - var context = requiredContext(contextStackCursor$1.current); - var nextContext = fiber.type; - nextContext = - "AndroidTextInput" === nextContext || - "RCTMultilineTextInputView" === nextContext || - "RCTSinglelineTextInputView" === nextContext || - "RCTText" === nextContext || - "RCTVirtualText" === nextContext; - nextContext = - context.isInAParentText !== nextContext - ? { isInAParentText: nextContext } - : context; - context !== nextContext && - (push(contextFiberStackCursor, fiber, fiber), - push(contextStackCursor$1, nextContext, fiber)); -} -function popHostContext(fiber) { - contextFiberStackCursor.current === fiber && - (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); -} -var commitTime = 0, - profilerStartTime = -1; -function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) { - if (0 <= profilerStartTime) { - var elapsedTime = now$1() - profilerStartTime; - fiber.actualDuration += elapsedTime; - overrideBaseTime && (fiber.selfBaseDuration = elapsedTime); - profilerStartTime = -1; - } -} -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 resolveDefaultProps(Component, baseProps) { - if (Component && Component.defaultProps) { - baseProps = Object.assign({}, baseProps); - Component = Component.defaultProps; - for (var propName in Component) - void 0 === baseProps[propName] && - (baseProps[propName] = Component[propName]); - } - return baseProps; -} -function readLazyComponentType(lazyComponent) { - var result = lazyComponent._result; - switch (lazyComponent._status) { - case 1: - return result; - case 2: - throw result; - case 0: - throw result; - default: - throw ((lazyComponent._status = 0), - (result = lazyComponent._ctor), - (result = result()), - result.then( - function(moduleObject) { - 0 === lazyComponent._status && - ((moduleObject = moduleObject.default), - (lazyComponent._status = 1), - (lazyComponent._result = moduleObject)); - }, - function(error) { - 0 === lazyComponent._status && - ((lazyComponent._status = 2), (lazyComponent._result = error)); - } - ), - (lazyComponent._result = result), - result); - } -} -var ReactCurrentOwner$4 = ReactSharedInternals.ReactCurrentOwner, - emptyRefsObject = new React.Component().refs; -function applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - nextProps + ctor, + getDerivedStateFromProps, + nextProps ) { ctor = workInProgress.memoizedState; getDerivedStateFromProps = getDerivedStateFromProps(nextProps, ctor); @@ -2482,7 +2164,7 @@ var classComponentUpdater = { var currentTime = requestCurrentTime(); currentTime = computeExpirationForFiber(currentTime, inst); var update = createUpdate(currentTime); - update.tag = 1; + update.tag = ReplaceState; update.payload = payload; void 0 !== callback && null !== callback && (update.callback = callback); flushPassiveEffects(); @@ -2494,7 +2176,7 @@ var classComponentUpdater = { var currentTime = requestCurrentTime(); currentTime = computeExpirationForFiber(currentTime, inst); var update = createUpdate(currentTime); - update.tag = 2; + update.tag = ForceUpdate; void 0 !== callback && null !== callback && (update.callback = callback); flushPassiveEffects(); enqueueUpdate(inst, update); @@ -2522,7 +2204,7 @@ function constructClassInstance(workInProgress, ctor, props) { unmaskedContext = emptyContextObject; var context = ctor.contextType; "object" === typeof context && null !== context - ? (context = ReactCurrentOwner$4.currentDispatcher.readContext(context)) + ? (context = readContext(context)) : ((unmaskedContext = isContextProvider(ctor) ? previousContext : contextStackCursor.current), @@ -2569,9 +2251,7 @@ function mountClassInstance( instance.refs = emptyRefsObject; var contextType = ctor.contextType; "object" === typeof contextType && null !== contextType - ? (instance.context = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (instance.context = readContext(contextType)) : ((contextType = isContextProvider(ctor) ? previousContext : contextStackCursor.current), @@ -2626,7 +2306,10 @@ function coerceRef(returnFiber, current$$1, element) { element = element._owner; var inst = void 0; element && - (invariant(1 === element.tag, "Function components cannot have refs."), + (invariant( + 1 === element.tag, + "Function components cannot have refs. Did you mean to use React.forwardRef()?" + ), (inst = element.stateNode)); invariant( inst, @@ -3326,71 +3009,586 @@ function ChildReconciler(shouldTrackSideEffects) { } 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; - } + NO_CONTEXT = {}, + contextStackCursor$1 = { current: NO_CONTEXT }, + contextFiberStackCursor = { current: NO_CONTEXT }, + rootInstanceStackCursor = { current: 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 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 = createFiber(5, null, null, 0); - fiber.elementType = "DELETED"; - 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 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); } -var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner; -function reconcileChildren( - current$$1, - workInProgress, - nextChildren, - renderExpirationTime -) { - workInProgress.child = - null === current$$1 - ? mountChildFibers( - workInProgress, - null, - nextChildren, +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} +function pushHostContext(fiber) { + requiredContext(rootInstanceStackCursor.current); + var context = requiredContext(contextStackCursor$1.current); + var nextContext = fiber.type; + nextContext = + "AndroidTextInput" === nextContext || + "RCTMultilineTextInputView" === nextContext || + "RCTSinglelineTextInputView" === nextContext || + "RCTText" === nextContext || + "RCTVirtualText" === nextContext; + nextContext = + context.isInAParentText !== nextContext + ? { isInAParentText: nextContext } + : context; + context !== nextContext && + (push(contextFiberStackCursor, fiber, fiber), + push(contextStackCursor$1, nextContext, fiber)); +} +function popHostContext(fiber) { + contextFiberStackCursor.current === fiber && + (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); +} +var NoEffect$1 = 0, + UnmountSnapshot = 2, + UnmountMutation = 4, + MountMutation = 8, + UnmountLayout = 16, + MountLayout = 32, + MountPassive = 64, + UnmountPassive = 128, + ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher, + renderExpirationTime = 0, + currentlyRenderingFiber$1 = null, + currentHook = null, + nextCurrentHook = null, + firstWorkInProgressHook = null, + workInProgressHook = null, + nextWorkInProgressHook = null, + remainingExpirationTime = 0, + componentUpdateQueue = null, + sideEffectTag = 0, + didScheduleRenderPhaseUpdate = !1, + renderPhaseUpdates = null, + numberOfReRenders = 0; +function throwInvalidHookError() { + invariant( + !1, + "Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)" + ); +} +function areHookInputsEqual(nextDeps, prevDeps) { + if (null === prevDeps) return !1; + for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) + if (!is(nextDeps[i], prevDeps[i])) return !1; + return !0; +} +function renderWithHooks( + current, + workInProgress, + Component, + props, + refOrContext, + nextRenderExpirationTime +) { + renderExpirationTime = nextRenderExpirationTime; + currentlyRenderingFiber$1 = workInProgress; + nextCurrentHook = null !== current ? current.memoizedState : null; + ReactCurrentDispatcher$1.current = + null === nextCurrentHook ? HooksDispatcherOnMount : HooksDispatcherOnUpdate; + workInProgress = Component(props, refOrContext); + if (didScheduleRenderPhaseUpdate) { + do + (didScheduleRenderPhaseUpdate = !1), + (numberOfReRenders += 1), + (nextCurrentHook = null !== current ? current.memoizedState : null), + (nextWorkInProgressHook = firstWorkInProgressHook), + (componentUpdateQueue = workInProgressHook = currentHook = null), + (ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdate), + (workInProgress = Component(props, refOrContext)); + while (didScheduleRenderPhaseUpdate); + renderPhaseUpdates = null; + numberOfReRenders = 0; + } + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + current = currentlyRenderingFiber$1; + current.memoizedState = firstWorkInProgressHook; + current.expirationTime = remainingExpirationTime; + current.updateQueue = componentUpdateQueue; + current.effectTag |= sideEffectTag; + current = null !== currentHook && null !== currentHook.next; + renderExpirationTime = 0; + nextWorkInProgressHook = workInProgressHook = firstWorkInProgressHook = nextCurrentHook = currentHook = currentlyRenderingFiber$1 = null; + remainingExpirationTime = 0; + componentUpdateQueue = null; + sideEffectTag = 0; + invariant( + !current, + "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." + ); + return workInProgress; +} +function resetHooks() { + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + renderExpirationTime = 0; + nextWorkInProgressHook = workInProgressHook = firstWorkInProgressHook = nextCurrentHook = currentHook = currentlyRenderingFiber$1 = null; + remainingExpirationTime = 0; + componentUpdateQueue = null; + sideEffectTag = 0; + didScheduleRenderPhaseUpdate = !1; + renderPhaseUpdates = null; + numberOfReRenders = 0; +} +function mountWorkInProgressHook() { + var hook = { + memoizedState: null, + baseState: null, + queue: null, + baseUpdate: null, + next: null + }; + null === workInProgressHook + ? (firstWorkInProgressHook = workInProgressHook = hook) + : (workInProgressHook = workInProgressHook.next = hook); + return workInProgressHook; +} +function updateWorkInProgressHook() { + if (null !== nextWorkInProgressHook) + (workInProgressHook = nextWorkInProgressHook), + (nextWorkInProgressHook = workInProgressHook.next), + (currentHook = nextCurrentHook), + (nextCurrentHook = null !== currentHook ? currentHook.next : null); + else { + invariant( + null !== nextCurrentHook, + "Rendered more hooks than during the previous render." + ); + currentHook = nextCurrentHook; + var newHook = { + memoizedState: currentHook.memoizedState, + baseState: currentHook.baseState, + queue: currentHook.queue, + baseUpdate: currentHook.baseUpdate, + next: null + }; + workInProgressHook = + null === workInProgressHook + ? (firstWorkInProgressHook = newHook) + : (workInProgressHook.next = newHook); + nextCurrentHook = currentHook.next; + } + return workInProgressHook; +} +function basicStateReducer(state, action) { + return "function" === typeof action ? action(state) : action; +} +function updateReducer(reducer) { + var hook = updateWorkInProgressHook(), + queue = hook.queue; + invariant( + null !== queue, + "Should have a queue. This is likely a bug in React. Please file an issue." + ); + if (0 < numberOfReRenders) { + var _dispatch = queue.dispatch; + if (null !== renderPhaseUpdates) { + var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); + if (void 0 !== firstRenderPhaseUpdate) { + renderPhaseUpdates.delete(queue); + var newState = hook.memoizedState; + do + (newState = reducer(newState, firstRenderPhaseUpdate.action)), + (firstRenderPhaseUpdate = firstRenderPhaseUpdate.next); + while (null !== firstRenderPhaseUpdate); + is(newState, hook.memoizedState) || (didReceiveUpdate = !0); + hook.memoizedState = newState; + hook.baseUpdate === queue.last && (hook.baseState = newState); + return [newState, _dispatch]; + } + } + return [hook.memoizedState, _dispatch]; + } + _dispatch = queue.last; + var baseUpdate = hook.baseUpdate; + newState = hook.baseState; + null !== baseUpdate + ? (null !== _dispatch && (_dispatch.next = null), + (_dispatch = baseUpdate.next)) + : (_dispatch = null !== _dispatch ? _dispatch.next : null); + if (null !== _dispatch) { + var newBaseUpdate = (firstRenderPhaseUpdate = null), + _update = _dispatch, + didSkip = !1; + do { + var updateExpirationTime = _update.expirationTime; + updateExpirationTime < renderExpirationTime + ? (didSkip || + ((didSkip = !0), + (newBaseUpdate = baseUpdate), + (firstRenderPhaseUpdate = newState)), + updateExpirationTime > remainingExpirationTime && + (remainingExpirationTime = updateExpirationTime)) + : (newState = + _update.eagerReducer === reducer + ? _update.eagerState + : reducer(newState, _update.action)); + baseUpdate = _update; + _update = _update.next; + } while (null !== _update && _update !== _dispatch); + didSkip || + ((newBaseUpdate = baseUpdate), (firstRenderPhaseUpdate = newState)); + is(newState, hook.memoizedState) || (didReceiveUpdate = !0); + hook.memoizedState = newState; + hook.baseUpdate = newBaseUpdate; + hook.baseState = firstRenderPhaseUpdate; + queue.eagerReducer = reducer; + queue.eagerState = newState; + } + return [hook.memoizedState, queue.dispatch]; +} +function pushEffect(tag, create, destroy, deps) { + tag = { tag: tag, create: create, destroy: destroy, deps: deps, next: null }; + null === componentUpdateQueue + ? ((componentUpdateQueue = { lastEffect: null }), + (componentUpdateQueue.lastEffect = tag.next = tag)) + : ((create = componentUpdateQueue.lastEffect), + null === create + ? (componentUpdateQueue.lastEffect = tag.next = tag) + : ((destroy = create.next), + (create.next = tag), + (tag.next = destroy), + (componentUpdateQueue.lastEffect = tag))); + return tag; +} +function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = mountWorkInProgressHook(); + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect( + hookEffectTag, + create, + void 0, + void 0 === deps ? null : deps + ); +} +function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var destroy = void 0; + if (null !== currentHook) { + var prevEffect = currentHook.memoizedState; + destroy = prevEffect.destroy; + if (null !== deps && areHookInputsEqual(deps, prevEffect.deps)) { + pushEffect(NoEffect$1, create, destroy, deps); + return; + } + } + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect(hookEffectTag, create, destroy, deps); +} +function imperativeHandleEffect(create, ref) { + if ("function" === typeof ref) + return ( + (create = create()), + ref(create), + function() { + ref(null); + } + ); + if (null !== ref && void 0 !== ref) + return ( + (create = create()), + (ref.current = create), + function() { + ref.current = null; + } + ); +} +function mountDebugValue() {} +function dispatchAction(fiber, queue, action) { + invariant( + 25 > numberOfReRenders, + "Too many re-renders. React limits the number of renders to prevent an infinite loop." + ); + var alternate = fiber.alternate; + if ( + fiber === currentlyRenderingFiber$1 || + (null !== alternate && alternate === currentlyRenderingFiber$1) + ) + if ( + ((didScheduleRenderPhaseUpdate = !0), + (fiber = { + expirationTime: renderExpirationTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }), + null === renderPhaseUpdates && (renderPhaseUpdates = new Map()), + (action = renderPhaseUpdates.get(queue)), + void 0 === action) + ) + renderPhaseUpdates.set(queue, fiber); + else { + for (queue = action; null !== queue.next; ) queue = queue.next; + queue.next = fiber; + } + else { + flushPassiveEffects(); + var currentTime = requestCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, fiber); + var _update2 = { + expirationTime: currentTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }, + _last = queue.last; + if (null === _last) _update2.next = _update2; + else { + var first = _last.next; + null !== first && (_update2.next = first); + _last.next = _update2; + } + queue.last = _update2; + if ( + 0 === fiber.expirationTime && + (null === alternate || 0 === alternate.expirationTime) && + ((alternate = queue.eagerReducer), null !== alternate) + ) + try { + var currentState = queue.eagerState, + _eagerState = alternate(currentState, action); + _update2.eagerReducer = alternate; + _update2.eagerState = _eagerState; + if (is(_eagerState, currentState)) return; + } catch (error) { + } finally { + } + scheduleWork(fiber, currentTime); + } +} +var ContextOnlyDispatcher = { + readContext: readContext, + useCallback: throwInvalidHookError, + useContext: throwInvalidHookError, + useEffect: throwInvalidHookError, + useImperativeHandle: throwInvalidHookError, + useLayoutEffect: throwInvalidHookError, + useMemo: throwInvalidHookError, + useReducer: throwInvalidHookError, + useRef: throwInvalidHookError, + useState: throwInvalidHookError, + useDebugValue: throwInvalidHookError + }, + HooksDispatcherOnMount = { + readContext: readContext, + useCallback: function(callback, deps) { + mountWorkInProgressHook().memoizedState = [ + callback, + void 0 === deps ? null : deps + ]; + return callback; + }, + useContext: readContext, + useEffect: function(create, deps) { + return mountEffectImpl(516, UnmountPassive | MountPassive, create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + deps = null !== deps && void 0 !== deps ? deps.concat([ref]) : [ref]; + return mountEffectImpl( + 4, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + deps + ); + }, + useLayoutEffect: function(create, deps) { + return mountEffectImpl(4, UnmountMutation | MountLayout, create, deps); + }, + useMemo: function(nextCreate, deps) { + var hook = mountWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + nextCreate = nextCreate(); + hook.memoizedState = [nextCreate, deps]; + return nextCreate; + }, + useReducer: function(reducer, initialArg, init) { + var hook = mountWorkInProgressHook(); + initialArg = void 0 !== init ? init(initialArg) : initialArg; + hook.memoizedState = hook.baseState = initialArg; + reducer = hook.queue = { + last: null, + dispatch: null, + eagerReducer: reducer, + eagerState: initialArg + }; + reducer = reducer.dispatch = dispatchAction.bind( + null, + currentlyRenderingFiber$1, + reducer + ); + return [hook.memoizedState, reducer]; + }, + useRef: function(initialValue) { + var hook = mountWorkInProgressHook(); + initialValue = { current: initialValue }; + return (hook.memoizedState = initialValue); + }, + useState: function(initialState) { + var hook = mountWorkInProgressHook(); + "function" === typeof initialState && (initialState = initialState()); + hook.memoizedState = hook.baseState = initialState; + initialState = hook.queue = { + last: null, + dispatch: null, + eagerReducer: basicStateReducer, + eagerState: initialState + }; + initialState = initialState.dispatch = dispatchAction.bind( + null, + currentlyRenderingFiber$1, + initialState + ); + return [hook.memoizedState, initialState]; + }, + useDebugValue: mountDebugValue + }, + HooksDispatcherOnUpdate = { + readContext: readContext, + useCallback: function(callback, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var prevState = hook.memoizedState; + if ( + null !== prevState && + null !== deps && + areHookInputsEqual(deps, prevState[1]) + ) + return prevState[0]; + hook.memoizedState = [callback, deps]; + return callback; + }, + useContext: readContext, + useEffect: function(create, deps) { + return updateEffectImpl(516, UnmountPassive | MountPassive, create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + deps = null !== deps && void 0 !== deps ? deps.concat([ref]) : [ref]; + return updateEffectImpl( + 4, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + deps + ); + }, + useLayoutEffect: function(create, deps) { + return updateEffectImpl(4, UnmountMutation | MountLayout, create, deps); + }, + useMemo: function(nextCreate, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var prevState = hook.memoizedState; + if ( + null !== prevState && + null !== deps && + areHookInputsEqual(deps, prevState[1]) + ) + return prevState[0]; + nextCreate = nextCreate(); + hook.memoizedState = [nextCreate, deps]; + return nextCreate; + }, + useReducer: updateReducer, + useRef: function() { + return updateWorkInProgressHook().memoizedState; + }, + useState: function(initialState) { + return updateReducer(basicStateReducer, initialState); + }, + useDebugValue: mountDebugValue + }, + commitTime = 0, + profilerStartTime = -1; +function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) { + if (0 <= profilerStartTime) { + var elapsedTime = now$1() - profilerStartTime; + fiber.actualDuration += elapsedTime; + overrideBaseTime && (fiber.selfBaseDuration = elapsedTime); + profilerStartTime = -1; + } +} +var 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 = createFiber(5, null, null, 0); + fiber.elementType = "DELETED"; + 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); + } +} +var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner, + didReceiveUpdate = !1; +function reconcileChildren( + current$$1, + workInProgress, + nextChildren, + renderExpirationTime +) { + workInProgress.child = + null === current$$1 + ? mountChildFibers( + workInProgress, + null, + nextChildren, renderExpirationTime ) : reconcileChildFibers( @@ -3410,7 +3608,26 @@ function updateForwardRef( Component = Component.render; var ref = workInProgress.ref; prepareToReadContext(workInProgress, renderExpirationTime); - nextProps = Component(nextProps, ref); + nextProps = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + ref, + renderExpirationTime + ); + if (null !== current$$1 && !didReceiveUpdate) + return ( + (workInProgress.updateQueue = current$$1.updateQueue), + (workInProgress.effectTag &= -517), + current$$1.expirationTime <= renderExpirationTime && + (current$$1.expirationTime = 0), + bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ) + ); workInProgress.effectTag |= 1; reconcileChildren( current$$1, @@ -3490,9 +3707,9 @@ function updateSimpleMemoComponent( renderExpirationTime ) { return null !== current$$1 && - updateExpirationTime < renderExpirationTime && shallowEqual(current$$1.memoizedProps, nextProps) && - current$$1.ref === workInProgress.ref + current$$1.ref === workInProgress.ref && + ((didReceiveUpdate = !1), updateExpirationTime < renderExpirationTime) ? bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -3526,7 +3743,26 @@ function updateFunctionComponent( : contextStackCursor.current; unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); prepareToReadContext(workInProgress, renderExpirationTime); - Component = Component(nextProps, unmaskedContext); + Component = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + unmaskedContext, + renderExpirationTime + ); + if (null !== current$$1 && !didReceiveUpdate) + return ( + (workInProgress.updateQueue = current$$1.updateQueue), + (workInProgress.effectTag &= -517), + current$$1.expirationTime <= renderExpirationTime && + (current$$1.expirationTime = 0), + bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ) + ); workInProgress.effectTag |= 1; reconcileChildren( current$$1, @@ -3573,9 +3809,7 @@ function updateClassComponent( var oldContext = instance.context, contextType = Component.contextType; "object" === typeof contextType && null !== contextType - ? (contextType = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (contextType = readContext(contextType)) : ((contextType = isContextProvider(Component) ? previousContext : contextStackCursor.current), @@ -3660,9 +3894,7 @@ function updateClassComponent( (oldContext = instance.context), (contextType = Component.contextType), "object" === typeof contextType && null !== contextType - ? (contextType = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (contextType = readContext(contextType)) : ((contextType = isContextProvider(Component) ? previousContext : contextStackCursor.current), @@ -3848,104 +4080,119 @@ function updateSuspenseComponent( (nextDidTimeout = !0), (workInProgress.effectTag &= -65); if (null === current$$1) - nextDidTimeout - ? ((nextDidTimeout = nextProps.fallback), - (nextProps = createFiberFromFragment(null, mode, 0, null)), - 0 === (workInProgress.mode & 1) && - (nextProps.child = - null !== workInProgress.memoizedState - ? workInProgress.child.child - : workInProgress.child), - (renderExpirationTime = createFiberFromFragment( - nextDidTimeout, - mode, - renderExpirationTime, - null - )), - (nextProps.sibling = renderExpirationTime), - (mode = nextProps), - (mode.return = renderExpirationTime.return = workInProgress)) - : (mode = renderExpirationTime = mountChildFibers( - workInProgress, - null, - nextProps.children, - renderExpirationTime - )); - else if (null !== current$$1.memoizedState) - if ( - ((current$$1 = current$$1.child), - (mode = current$$1.sibling), - nextDidTimeout) - ) { - nextProps = nextProps.fallback; - renderExpirationTime = createWorkInProgress( - current$$1, - current$$1.pendingProps, - 0 - ); + if (nextDidTimeout) { + var nextFallbackChildren = nextProps.fallback; + current$$1 = createFiberFromFragment(null, mode, 0, null); 0 === (workInProgress.mode & 1) && - ((nextDidTimeout = + (current$$1.child = null !== workInProgress.memoizedState ? workInProgress.child.child - : workInProgress.child), - nextDidTimeout !== current$$1.child && - (renderExpirationTime.child = nextDidTimeout)); - if (workInProgress.mode & 4) { - nextDidTimeout = 0; - for (current$$1 = renderExpirationTime.child; null !== current$$1; ) - (nextDidTimeout += current$$1.treeBaseDuration), - (current$$1 = current$$1.sibling); - renderExpirationTime.treeBaseDuration = nextDidTimeout; - } - nextProps = renderExpirationTime.sibling = createWorkInProgress( + : workInProgress.child); + renderExpirationTime = createFiberFromFragment( + nextFallbackChildren, mode, - nextProps, - mode.expirationTime + renderExpirationTime, + null ); - mode = renderExpirationTime; - renderExpirationTime.childExpirationTime = 0; - renderExpirationTime = nextProps; + current$$1.sibling = renderExpirationTime; + mode = current$$1; mode.return = renderExpirationTime.return = workInProgress; } else - mode = renderExpirationTime = reconcileChildFibers( + mode = renderExpirationTime = mountChildFibers( workInProgress, - current$$1.child, + null, nextProps.children, renderExpirationTime ); - else if (((current$$1 = current$$1.child), nextDidTimeout)) { - nextDidTimeout = nextProps.fallback; - nextProps = createFiberFromFragment(null, mode, 0, null); - nextProps.child = current$$1; - 0 === (workInProgress.mode & 1) && - (nextProps.child = - null !== workInProgress.memoizedState - ? workInProgress.child.child - : workInProgress.child); - if (workInProgress.mode & 4) { - current$$1 = 0; - for (var _hiddenChild = nextProps.child; null !== _hiddenChild; ) - (current$$1 += _hiddenChild.treeBaseDuration), - (_hiddenChild = _hiddenChild.sibling); - nextProps.treeBaseDuration = current$$1; - } - renderExpirationTime = nextProps.sibling = createFiberFromFragment( - nextDidTimeout, - mode, - renderExpirationTime, - null - ); - renderExpirationTime.effectTag |= 2; - mode = nextProps; - nextProps.childExpirationTime = 0; - mode.return = renderExpirationTime.return = workInProgress; - } else - renderExpirationTime = mode = reconcileChildFibers( - workInProgress, - current$$1, - nextProps.children, - renderExpirationTime - ); + else { + if (null !== current$$1.memoizedState) + if ( + ((nextFallbackChildren = current$$1.child), + (mode = nextFallbackChildren.sibling), + nextDidTimeout) + ) { + nextProps = nextProps.fallback; + renderExpirationTime = createWorkInProgress( + nextFallbackChildren, + nextFallbackChildren.pendingProps, + 0 + ); + 0 === (workInProgress.mode & 1) && + ((nextDidTimeout = + null !== workInProgress.memoizedState + ? workInProgress.child.child + : workInProgress.child), + nextDidTimeout !== nextFallbackChildren.child && + (renderExpirationTime.child = nextDidTimeout)); + if (workInProgress.mode & 4) { + nextFallbackChildren = 0; + for ( + nextDidTimeout = renderExpirationTime.child; + null !== nextDidTimeout; + + ) + (nextFallbackChildren += nextDidTimeout.treeBaseDuration), + (nextDidTimeout = nextDidTimeout.sibling); + renderExpirationTime.treeBaseDuration = nextFallbackChildren; + } + nextFallbackChildren = renderExpirationTime.sibling = createWorkInProgress( + mode, + nextProps, + mode.expirationTime + ); + mode = renderExpirationTime; + renderExpirationTime.childExpirationTime = 0; + renderExpirationTime = nextFallbackChildren; + mode.return = renderExpirationTime.return = workInProgress; + } else + mode = renderExpirationTime = reconcileChildFibers( + workInProgress, + nextFallbackChildren.child, + nextProps.children, + renderExpirationTime + ); + else { + var _currentPrimaryChild = current$$1.child; + if (nextDidTimeout) { + nextProps = nextProps.fallback; + nextFallbackChildren = createFiberFromFragment(null, mode, 0, null); + nextFallbackChildren.child = _currentPrimaryChild; + 0 === (workInProgress.mode & 1) && + (nextFallbackChildren.child = + null !== workInProgress.memoizedState + ? workInProgress.child.child + : workInProgress.child); + if (workInProgress.mode & 4) { + nextDidTimeout = 0; + for ( + _currentPrimaryChild = nextFallbackChildren.child; + null !== _currentPrimaryChild; + + ) + (nextDidTimeout += _currentPrimaryChild.treeBaseDuration), + (_currentPrimaryChild = _currentPrimaryChild.sibling); + nextFallbackChildren.treeBaseDuration = nextDidTimeout; + } + renderExpirationTime = nextFallbackChildren.sibling = createFiberFromFragment( + nextProps, + mode, + renderExpirationTime, + null + ); + renderExpirationTime.effectTag |= 2; + mode = nextFallbackChildren; + nextFallbackChildren.childExpirationTime = 0; + mode.return = renderExpirationTime.return = workInProgress; + } else + renderExpirationTime = mode = reconcileChildFibers( + workInProgress, + _currentPrimaryChild, + nextProps.children, + renderExpirationTime + ); + } + workInProgress.stateNode = current$$1.stateNode; + } workInProgress.memoizedState = nextState; workInProgress.child = mode; return renderExpirationTime; @@ -3956,7 +4203,7 @@ function bailoutOnAlreadyFinishedWork( renderExpirationTime ) { null !== current$$1 && - (workInProgress.firstContextDependency = current$$1.firstContextDependency); + (workInProgress.contextDependencies = current$$1.contextDependencies); profilerStartTime = -1; if (workInProgress.childExpirationTime < renderExpirationTime) return null; invariant( @@ -3989,61 +4236,66 @@ function bailoutOnAlreadyFinishedWork( } function beginWork(current$$1, workInProgress, renderExpirationTime) { var updateExpirationTime = workInProgress.expirationTime; - if ( - null !== current$$1 && - current$$1.memoizedProps === workInProgress.pendingProps && - !didPerformWorkStackCursor.current && - updateExpirationTime < renderExpirationTime - ) { - switch (workInProgress.tag) { - case 3: - pushHostRootContext(workInProgress); - break; - case 5: - pushHostContext(workInProgress); - break; - case 1: - isContextProvider(workInProgress.type) && - pushContextProvider(workInProgress); - break; - case 4: - pushHostContainer( - workInProgress, - workInProgress.stateNode.containerInfo - ); - break; - case 10: - pushProvider(workInProgress, workInProgress.memoizedProps.value); - break; - case 12: - workInProgress.effectTag |= 4; - break; - case 13: - if (null !== workInProgress.memoizedState) { - updateExpirationTime = workInProgress.child.childExpirationTime; - if ( - 0 !== updateExpirationTime && - updateExpirationTime >= renderExpirationTime - ) - return updateSuspenseComponent( - current$$1, + if (null !== current$$1) + if ( + current$$1.memoizedProps !== workInProgress.pendingProps || + didPerformWorkStackCursor.current + ) + didReceiveUpdate = !0; + else { + if (updateExpirationTime < renderExpirationTime) { + didReceiveUpdate = !1; + switch (workInProgress.tag) { + case 3: + pushHostRootContext(workInProgress); + break; + case 5: + pushHostContext(workInProgress); + break; + case 1: + isContextProvider(workInProgress.type) && + pushContextProvider(workInProgress); + break; + case 4: + pushHostContainer( workInProgress, - renderExpirationTime + workInProgress.stateNode.containerInfo ); - workInProgress = bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); - return null !== workInProgress ? workInProgress.sibling : null; + break; + case 10: + pushProvider(workInProgress, workInProgress.memoizedProps.value); + break; + case 12: + workInProgress.effectTag |= 4; + break; + case 13: + if (null !== workInProgress.memoizedState) { + updateExpirationTime = workInProgress.child.childExpirationTime; + if ( + 0 !== updateExpirationTime && + updateExpirationTime >= renderExpirationTime + ) + return updateSuspenseComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress = bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + return null !== workInProgress ? workInProgress.sibling : null; + } } + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } } - return bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); - } + else didReceiveUpdate = !1; workInProgress.expirationTime = 0; switch (workInProgress.tag) { case 2: @@ -4058,7 +4310,14 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = updateExpirationTime(current$$1, context); + context = renderWithHooks( + null, + workInProgress, + updateExpirationTime, + current$$1, + context, + renderExpirationTime + ); workInProgress.effectTag |= 1; if ( "object" === typeof context && @@ -4067,6 +4326,7 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { void 0 === context.$$typeof ) { workInProgress.tag = 1; + resetHooks(); if (isContextProvider(updateExpirationTime)) { var hasContext = !0; pushContextProvider(workInProgress); @@ -4339,18 +4599,14 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; - hasContext = - (oldValue === hasContext && - (0 !== oldValue || 1 / oldValue === 1 / hasContext)) || - (oldValue !== oldValue && hasContext !== hasContext) - ? 0 - : ("function" === - typeof updateExpirationTime._calculateChangedBits - ? updateExpirationTime._calculateChangedBits( - oldValue, - hasContext - ) - : 1073741823) | 0; + hasContext = is(oldValue, hasContext) + ? 0 + : ("function" === typeof updateExpirationTime._calculateChangedBits + ? updateExpirationTime._calculateChangedBits( + oldValue, + hasContext + ) + : 1073741823) | 0; if (0 === hasContext) { if ( getDerivedStateFromProps.children === context.children && @@ -4365,83 +4621,79 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { } } else for ( - getDerivedStateFromProps = workInProgress.child, - null !== getDerivedStateFromProps && - (getDerivedStateFromProps.return = workInProgress); - null !== getDerivedStateFromProps; + oldValue = workInProgress.child, + null !== oldValue && (oldValue.return = workInProgress); + null !== oldValue; ) { - oldValue = getDerivedStateFromProps.firstContextDependency; - if (null !== oldValue) { - do { + var list = oldValue.contextDependencies; + if (null !== list) { + getDerivedStateFromProps = oldValue.child; + for (var dependency = list.first; null !== dependency; ) { if ( - oldValue.context === updateExpirationTime && - 0 !== (oldValue.observedBits & hasContext) + dependency.context === updateExpirationTime && + 0 !== (dependency.observedBits & hasContext) ) { - if (1 === getDerivedStateFromProps.tag) { - var nextFiber = createUpdate(renderExpirationTime); - nextFiber.tag = 2; - enqueueUpdate(getDerivedStateFromProps, nextFiber); - } - getDerivedStateFromProps.expirationTime < - renderExpirationTime && - (getDerivedStateFromProps.expirationTime = renderExpirationTime); - nextFiber = getDerivedStateFromProps.alternate; - null !== nextFiber && - nextFiber.expirationTime < renderExpirationTime && - (nextFiber.expirationTime = renderExpirationTime); - for ( - var node = getDerivedStateFromProps.return; - null !== node; - - ) { - nextFiber = node.alternate; + 1 === oldValue.tag && + ((dependency = createUpdate(renderExpirationTime)), + (dependency.tag = ForceUpdate), + enqueueUpdate(oldValue, dependency)); + oldValue.expirationTime < renderExpirationTime && + (oldValue.expirationTime = renderExpirationTime); + dependency = oldValue.alternate; + null !== dependency && + dependency.expirationTime < renderExpirationTime && + (dependency.expirationTime = renderExpirationTime); + for (var node = oldValue.return; null !== node; ) { + dependency = node.alternate; if (node.childExpirationTime < renderExpirationTime) (node.childExpirationTime = renderExpirationTime), - null !== nextFiber && - nextFiber.childExpirationTime < + null !== dependency && + dependency.childExpirationTime < renderExpirationTime && - (nextFiber.childExpirationTime = renderExpirationTime); + (dependency.childExpirationTime = renderExpirationTime); else if ( - null !== nextFiber && - nextFiber.childExpirationTime < renderExpirationTime + null !== dependency && + dependency.childExpirationTime < renderExpirationTime ) - nextFiber.childExpirationTime = renderExpirationTime; + dependency.childExpirationTime = renderExpirationTime; else break; node = node.return; } + list.expirationTime < renderExpirationTime && + (list.expirationTime = renderExpirationTime); + break; } - nextFiber = getDerivedStateFromProps.child; - oldValue = oldValue.next; - } while (null !== oldValue); + dependency = dependency.next; + } } else - nextFiber = - 10 === getDerivedStateFromProps.tag - ? getDerivedStateFromProps.type === workInProgress.type + getDerivedStateFromProps = + 10 === oldValue.tag + ? oldValue.type === workInProgress.type ? null - : getDerivedStateFromProps.child - : getDerivedStateFromProps.child; - if (null !== nextFiber) - nextFiber.return = getDerivedStateFromProps; + : oldValue.child + : oldValue.child; + if (null !== getDerivedStateFromProps) + getDerivedStateFromProps.return = oldValue; else for ( - nextFiber = getDerivedStateFromProps; - null !== nextFiber; + getDerivedStateFromProps = oldValue; + null !== getDerivedStateFromProps; ) { - if (nextFiber === workInProgress) { - nextFiber = null; + if (getDerivedStateFromProps === workInProgress) { + getDerivedStateFromProps = null; break; } - getDerivedStateFromProps = nextFiber.sibling; - if (null !== getDerivedStateFromProps) { - getDerivedStateFromProps.return = nextFiber.return; - nextFiber = getDerivedStateFromProps; + oldValue = getDerivedStateFromProps.sibling; + if (null !== oldValue) { + oldValue.return = getDerivedStateFromProps.return; + getDerivedStateFromProps = oldValue; break; } - nextFiber = nextFiber.return; + getDerivedStateFromProps = getDerivedStateFromProps.return; } - getDerivedStateFromProps = nextFiber; + oldValue = getDerivedStateFromProps; } } reconcileChildren( @@ -4472,75 +4724,360 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { ); case 14: return ( - (context = workInProgress.type), - (hasContext = resolveDefaultProps( - context, - workInProgress.pendingProps - )), - (hasContext = resolveDefaultProps(context.type, hasContext)), - updateMemoComponent( - current$$1, - workInProgress, - context, - hasContext, - updateExpirationTime, - renderExpirationTime - ) - ); - case 15: - return updateSimpleMemoComponent( - current$$1, - workInProgress, - workInProgress.type, - workInProgress.pendingProps, - updateExpirationTime, - renderExpirationTime + (context = workInProgress.type), + (hasContext = resolveDefaultProps( + context, + workInProgress.pendingProps + )), + (hasContext = resolveDefaultProps(context.type, hasContext)), + updateMemoComponent( + current$$1, + workInProgress, + context, + hasContext, + updateExpirationTime, + renderExpirationTime + ) + ); + case 15: + return updateSimpleMemoComponent( + current$$1, + workInProgress, + workInProgress.type, + workInProgress.pendingProps, + updateExpirationTime, + renderExpirationTime + ); + case 17: + return ( + (updateExpirationTime = workInProgress.type), + (context = workInProgress.pendingProps), + (context = + workInProgress.elementType === updateExpirationTime + ? context + : resolveDefaultProps(updateExpirationTime, context)), + null !== current$$1 && + ((current$$1.alternate = null), + (workInProgress.alternate = null), + (workInProgress.effectTag |= 2)), + (workInProgress.tag = 1), + isContextProvider(updateExpirationTime) + ? ((current$$1 = !0), pushContextProvider(workInProgress)) + : (current$$1 = !1), + prepareToReadContext(workInProgress, renderExpirationTime), + constructClassInstance( + workInProgress, + updateExpirationTime, + context, + renderExpirationTime + ), + mountClassInstance( + workInProgress, + updateExpirationTime, + context, + renderExpirationTime + ), + finishClassComponent( + null, + workInProgress, + updateExpirationTime, + !0, + current$$1, + renderExpirationTime + ) + ); + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } +} +var valueCursor = { current: null }, + currentlyRenderingFiber = null, + lastContextDependency = null, + lastContextWithAllBitsObserved = null; +function pushProvider(providerFiber, nextValue) { + var context = providerFiber.type._context; + push(valueCursor, context._currentValue2, providerFiber); + context._currentValue2 = nextValue; +} +function popProvider(providerFiber) { + var currentValue = valueCursor.current; + pop(valueCursor, providerFiber); + providerFiber.type._context._currentValue2 = currentValue; +} +function prepareToReadContext(workInProgress, renderExpirationTime) { + currentlyRenderingFiber = workInProgress; + lastContextWithAllBitsObserved = lastContextDependency = null; + var currentDependencies = workInProgress.contextDependencies; + null !== currentDependencies && + currentDependencies.expirationTime >= renderExpirationTime && + (didReceiveUpdate = !0); + workInProgress.contextDependencies = null; +} +function readContext(context, observedBits) { + if ( + lastContextWithAllBitsObserved !== context && + !1 !== observedBits && + 0 !== observedBits + ) { + if ("number" !== typeof observedBits || 1073741823 === observedBits) + (lastContextWithAllBitsObserved = context), (observedBits = 1073741823); + observedBits = { context: context, observedBits: observedBits, next: null }; + null === lastContextDependency + ? (invariant( + null !== currentlyRenderingFiber, + "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()." + ), + (lastContextDependency = observedBits), + (currentlyRenderingFiber.contextDependencies = { + first: observedBits, + expirationTime: 0 + })) + : (lastContextDependency = lastContextDependency.next = observedBits); + } + return context._currentValue2; +} +var UpdateState = 0, + ReplaceState = 1, + ForceUpdate = 2, + CaptureUpdate = 3, + hasForceUpdate = !1; +function createUpdateQueue(baseState) { + return { + baseState: baseState, + firstUpdate: null, + lastUpdate: null, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; +} +function cloneUpdateQueue(currentQueue) { + return { + 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: UpdateState, + payload: null, + callback: null, + next: null, + nextEffect: null + }; +} +function appendUpdateToQueue(queue, update) { + null === queue.lastUpdate + ? (queue.firstUpdate = queue.lastUpdate = update) + : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); +} +function enqueueUpdate(fiber, update) { + 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) + : null === queue1.lastUpdate || null === queue2.lastUpdate + ? (appendUpdateToQueue(queue1, update), + appendUpdateToQueue(queue2, update)) + : (appendUpdateToQueue(queue1, update), (queue2.lastUpdate = update)); +} +function enqueueCapturedUpdate(workInProgress, update) { + 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)); +} +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 ReplaceState: + return ( + (workInProgress = update.payload), + "function" === typeof workInProgress + ? workInProgress.call(instance, prevState, nextProps) + : workInProgress ); - case 17: - return ( - (updateExpirationTime = workInProgress.type), - (context = workInProgress.pendingProps), - (context = - workInProgress.elementType === updateExpirationTime - ? context - : resolveDefaultProps(updateExpirationTime, context)), - null !== current$$1 && - ((current$$1.alternate = null), - (workInProgress.alternate = null), - (workInProgress.effectTag |= 2)), - (workInProgress.tag = 1), - isContextProvider(updateExpirationTime) - ? ((current$$1 = !0), pushContextProvider(workInProgress)) - : (current$$1 = !1), - prepareToReadContext(workInProgress, renderExpirationTime), - constructClassInstance( - workInProgress, - updateExpirationTime, - context, - renderExpirationTime - ), - mountClassInstance( + case CaptureUpdate: + workInProgress.effectTag = (workInProgress.effectTag & -2049) | 64; + case UpdateState: + 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 ForceUpdate: + hasForceUpdate = !0; + } + return prevState; +} +function processUpdateQueue( + workInProgress, + queue, + props, + instance, + renderExpirationTime +) { + hasForceUpdate = !1; + queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + for ( + var newBaseState = queue.baseState, + newFirstUpdate = null, + newExpirationTime = 0, + update = queue.firstUpdate, + resultState = newBaseState; + null !== update; + + ) { + var updateExpirationTime = update.expirationTime; + updateExpirationTime < renderExpirationTime + ? (null === newFirstUpdate && + ((newFirstUpdate = update), (newBaseState = resultState)), + newExpirationTime < updateExpirationTime && + (newExpirationTime = updateExpirationTime)) + : ((resultState = getStateFromUpdate( workInProgress, - updateExpirationTime, - context, - renderExpirationTime - ), - finishClassComponent( - null, + 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; + _updateExpirationTime < renderExpirationTime + ? (null === updateExpirationTime && + ((updateExpirationTime = update), + null === newFirstUpdate && (newBaseState = resultState)), + newExpirationTime < _updateExpirationTime && + (newExpirationTime = _updateExpirationTime)) + : ((resultState = getStateFromUpdate( workInProgress, - updateExpirationTime, - !0, - current$$1, - renderExpirationTime - ) - ); - default: + 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; + workInProgress.expirationTime = newExpirationTime; + workInProgress.memoizedState = resultState; +} +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)); + commitUpdateEffects(finishedQueue.firstEffect, instance); + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; +} +function commitUpdateEffects(effect, instance) { + for (; null !== effect; ) { + var _callback3 = effect.callback; + if (null !== _callback3) { + effect.callback = null; + var context = instance; invariant( - !1, - "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + "function" === typeof _callback3, + "Invalid argument passed as callback. Expected a function. Instead received: %s", + _callback3 ); + _callback3.call(context); + } + effect = effect.nextEffect; } } +function createCapturedValue(value, source) { + return { + value: value, + source: source, + stack: getStackByFiberInDevAndProd(source) + }; +} var appendAllChildren = void 0, updateHostContainer = void 0, updateHostComponent$1 = void 0, @@ -4784,12 +5321,30 @@ function safelyDetachRef(current$$1) { } else ref.current = null; } +function commitHookEffectList(unmountTag, mountTag, finishedWork) { + finishedWork = finishedWork.updateQueue; + finishedWork = null !== finishedWork ? finishedWork.lastEffect : null; + if (null !== finishedWork) { + var effect = (finishedWork = finishedWork.next); + do { + if ((effect.tag & unmountTag) !== NoEffect$1) { + var destroy = effect.destroy; + effect.destroy = void 0; + void 0 !== destroy && destroy(); + } + (effect.tag & mountTag) !== NoEffect$1 && + ((destroy = effect.create), (effect.destroy = destroy())); + effect = effect.next; + } while (effect !== finishedWork); + } +} function commitWork(current$$1, finishedWork) { switch (finishedWork.tag) { case 0: case 11: case 14: case 15: + commitHookEffectList(UnmountMutation, MountMutation, finishedWork); return; } switch (finishedWork.tag) { @@ -4809,9 +5364,10 @@ function commitWork(current$$1, finishedWork) { ); } } +var PossiblyWeakMap = "function" === typeof WeakMap ? WeakMap : Map; function createRootErrorUpdate(fiber, errorInfo, expirationTime) { expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; + expirationTime.tag = CaptureUpdate; expirationTime.payload = { element: null }; var error = errorInfo.value; expirationTime.callback = function() { @@ -4822,7 +5378,7 @@ function createRootErrorUpdate(fiber, errorInfo, expirationTime) { } function createClassErrorUpdate(fiber, errorInfo, expirationTime) { expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; + expirationTime.tag = CaptureUpdate; var getDerivedStateFromError = fiber.type.getDerivedStateFromError; if ("function" === typeof getDerivedStateFromError) { var error$jscomp$0 = errorInfo.value; @@ -4891,24 +5447,43 @@ function throwException( ? !1 : null === value.memoizedState; if (current$$1) { - returnFiber = retrySuspendedRoot.bind( - null, - root, - value, - sourceFiber, - 0 === (value.mode & 1) ? 1073741823 : renderExpirationTime - ); - returnFiber = tracing.unstable_wrap(returnFiber); - thenable.then(returnFiber, returnFiber); + returnFiber = value.updateQueue; + null === returnFiber + ? ((returnFiber = new Set()), + returnFiber.add(thenable), + (value.updateQueue = returnFiber)) + : returnFiber.add(thenable); if (0 === (value.mode & 1)) { value.effectTag |= 64; sourceFiber.effectTag &= -1957; 1 === sourceFiber.tag && - null === sourceFiber.alternate && - (sourceFiber.tag = 17); - sourceFiber.expirationTime = renderExpirationTime; + (null === sourceFiber.alternate + ? (sourceFiber.tag = 17) + : ((renderExpirationTime = createUpdate(1073741823)), + (renderExpirationTime.tag = ForceUpdate), + enqueueUpdate(sourceFiber, renderExpirationTime))); + sourceFiber.expirationTime = 1073741823; return; } + sourceFiber = root.pingCache; + null === sourceFiber + ? ((sourceFiber = root.pingCache = new PossiblyWeakMap()), + (returnFiber = new Set()), + sourceFiber.set(thenable, returnFiber)) + : ((returnFiber = sourceFiber.get(thenable)), + void 0 === returnFiber && + ((returnFiber = new Set()), + sourceFiber.set(thenable, returnFiber))); + returnFiber.has(renderExpirationTime) || + (returnFiber.add(renderExpirationTime), + (sourceFiber = pingSuspendedRoot.bind( + null, + root, + thenable, + renderExpirationTime + )), + (sourceFiber = tracing.unstable_wrap(sourceFiber)), + thenable.then(sourceFiber, sourceFiber)); -1 === earliestTimeoutMs ? (root = 1073741823) : (-1 === startTimeMs && @@ -4942,33 +5517,32 @@ function throwException( do { switch (root.tag) { case 3: - sourceFiber = value; root.effectTag |= 2048; root.expirationTime = renderExpirationTime; renderExpirationTime = createRootErrorUpdate( root, - sourceFiber, + value, renderExpirationTime ); enqueueCapturedUpdate(root, renderExpirationTime); return; case 1: if ( - ((sourceFiber = value), - (returnFiber = root.type), - (thenable = root.stateNode), + ((thenable = value), + (earliestTimeoutMs = root.type), + (startTimeMs = root.stateNode), 0 === (root.effectTag & 64) && - ("function" === typeof returnFiber.getDerivedStateFromError || - (null !== thenable && - "function" === typeof thenable.componentDidCatch && + ("function" === typeof earliestTimeoutMs.getDerivedStateFromError || + (null !== startTimeMs && + "function" === typeof startTimeMs.componentDidCatch && (null === legacyErrorBoundariesThatAlreadyFailed || - !legacyErrorBoundariesThatAlreadyFailed.has(thenable))))) + !legacyErrorBoundariesThatAlreadyFailed.has(startTimeMs))))) ) { root.effectTag |= 2048; root.expirationTime = renderExpirationTime; renderExpirationTime = createClassErrorUpdate( root, - sourceFiber, + thenable, renderExpirationTime ); enqueueCapturedUpdate(root, renderExpirationTime); @@ -5017,7 +5591,7 @@ function unwindWork(workInProgress) { return null; } } -var DispatcherWithoutHooks = { readContext: readContext }, +var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher, ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner; invariant( null != tracing.__interactionsRef && @@ -5032,6 +5606,7 @@ var isWorking = !1, nextRenderDidError = !1, nextEffect = null, isCommitting$1 = !1, + rootWithPendingPassiveEffects = null, passiveEffectCallbackHandle = null, passiveEffectCallback = null, legacyErrorBoundariesThatAlreadyFailed = null; @@ -5114,7 +5689,7 @@ function commitAllHostEffects() { var effect = (updateQueue = updateQueue.next); do { var destroy = effect.destroy; - if (null !== destroy) { + if (void 0 !== destroy) { var current$$1$jscomp$1 = current$$1$jscomp$0; try { destroy(); @@ -5182,6 +5757,7 @@ function commitBeforeMutationLifecycles() { case 0: case 11: case 15: + commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork); break a; case 1: if (finishedWork.effectTag & 256 && null !== current$$1) { @@ -5228,6 +5804,7 @@ function commitAllLifeCycles( case 0: case 11: case 15: + commitHookEffectList(UnmountLayout, MountLayout, finishedWork); break; case 1: finishedRoot = finishedWork.stateNode; @@ -5311,23 +5888,53 @@ function commitAllLifeCycles( ); } } - if (effectTag & 128 && ((effectTag = nextEffect.ref), null !== effectTag)) { - finishedWork = nextEffect.stateNode; + if ( + effectTag & 128 && + ((finishedWork = nextEffect.ref), null !== finishedWork) + ) { + committedExpirationTime = nextEffect.stateNode; switch (nextEffect.tag) { case 5: - finishedWork = finishedWork.canonical; + committedExpirationTime = committedExpirationTime.canonical; } - "function" === typeof effectTag - ? effectTag(finishedWork) - : (effectTag.current = finishedWork); + "function" === typeof finishedWork + ? finishedWork(committedExpirationTime) + : (finishedWork.current = committedExpirationTime); } + effectTag & 512 && (rootWithPendingPassiveEffects = finishedRoot$jscomp$0); nextEffect = nextEffect.nextEffect; } } +function commitPassiveEffects(root, firstEffect) { + passiveEffectCallback = passiveEffectCallbackHandle = rootWithPendingPassiveEffects = null; + var previousIsRendering = isRendering; + isRendering = !0; + do { + if (firstEffect.effectTag & 512) { + var didError = !1, + error = void 0; + try { + var finishedWork = firstEffect; + commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork); + commitHookEffectList(NoEffect$1, MountPassive, finishedWork); + } catch (e) { + (didError = !0), (error = e); + } + didError && captureCommitPhaseError(firstEffect, error); + } + firstEffect = firstEffect.nextEffect; + } while (null !== firstEffect); + isRendering = previousIsRendering; + previousIsRendering = root.expirationTime; + 0 !== previousIsRendering && requestWork(root, previousIsRendering); +} function flushPassiveEffects() { - null !== passiveEffectCallback && - (scheduler.unstable_cancelCallback(passiveEffectCallbackHandle), - passiveEffectCallback()); + if (null !== passiveEffectCallbackHandle) { + var callbackID = passiveEffectCallbackHandle; + scheduledCallback = null; + clearTimeout(callbackID); + } + null !== passiveEffectCallback && passiveEffectCallback(); } function commitRoot(root, finishedWork) { isCommitting$1 = isWorking = !0; @@ -5395,21 +6002,39 @@ function commitRoot(root, finishedWork) { } root.current = finishedWork; for (nextEffect = childExpirationTimeBeforeCommit; null !== nextEffect; ) { - childExpirationTimeBeforeCommit = !1; - didError = void 0; + didError = !1; + error$jscomp$0 = void 0; try { commitAllLifeCycles(root, committedExpirationTime); } catch (e) { - (childExpirationTimeBeforeCommit = !0), (didError = e); + (didError = !0), (error$jscomp$0 = e); } - childExpirationTimeBeforeCommit && + didError && (invariant( null !== nextEffect, "Should have next effect. This error is likely caused by a bug in React. Please file an issue." ), - captureCommitPhaseError(nextEffect, didError), + captureCommitPhaseError(nextEffect, error$jscomp$0), null !== nextEffect && (nextEffect = nextEffect.nextEffect)); } + if ( + null !== childExpirationTimeBeforeCommit && + null !== rootWithPendingPassiveEffects + ) { + var callback = commitPassiveEffects.bind( + null, + root, + childExpirationTimeBeforeCommit + ); + callback = tracing.unstable_wrap(callback); + passiveEffectCallbackHandle = scheduler.unstable_runWithPriority( + scheduler.unstable_NormalPriority, + function() { + return scheduleDeferredCallback$1(callback); + } + ); + passiveEffectCallback = callback; + } isWorking = isCommitting$1 = !1; "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode); @@ -5594,11 +6219,7 @@ function completeUnitOfWork(workInProgress) { : ((current$$1.firstEffect = current$$1.lastEffect = current), (current.nextEffect = null)), (current.effectTag = 8))); - if ( - fiber !== renderExpirationTime || - (0 === (current$$1.effectTag & 1) && fiber) - ) - current$$1.effectTag |= 4; + if (fiber || renderExpirationTime) current$$1.effectTag |= 4; break; case 7: break; @@ -5718,7 +6339,8 @@ function renderRoot(root, isYieldy) { ); flushPassiveEffects(); isWorking = !0; - ReactCurrentOwner$2.currentDispatcher = DispatcherWithoutHooks; + var previousDispatcher = ReactCurrentDispatcher.current; + ReactCurrentDispatcher.current = ContextOnlyDispatcher; var expirationTime = root.nextExpirationTimeToWorkOn; if ( expirationTime !== nextRenderExpirationTime || @@ -5773,6 +6395,7 @@ function renderRoot(root, isYieldy) { } catch (thrownValue) { if ( ((lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = null), + resetHooks(), null === nextUnitOfWork) ) (threadID = !0), onUncaughtError(thrownValue); @@ -5803,27 +6426,35 @@ function renderRoot(root, isYieldy) { } while (1); tracing.__interactionsRef.current = subscriber; isWorking = !1; - lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = ReactCurrentOwner$2.currentDispatcher = null; + ReactCurrentDispatcher.current = previousDispatcher; + lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = null; + resetHooks(); if (threadID) (nextRoot = null), (root.finishedWork = null); else if (null !== nextUnitOfWork) root.finishedWork = null; else { - subscriber = root.current.alternate; + previousDispatcher = root.current.alternate; invariant( - null !== subscriber, + null !== previousDispatcher, "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue." ); nextRoot = null; if (nextRenderDidError) { if (hasLowerPriorityWork(root, expirationTime)) { markSuspendedPriorityLevel(root, expirationTime); - onSuspend(root, subscriber, expirationTime, root.expirationTime, -1); + onSuspend( + root, + previousDispatcher, + expirationTime, + root.expirationTime, + -1 + ); return; } if (!root.didError && isYieldy) { root.didError = !0; isYieldy = root.nextExpirationTimeToWorkOn = expirationTime; - threadID = root.expirationTime = 1073741823; - onSuspend(root, subscriber, isYieldy, threadID, -1); + subscriber = root.expirationTime = 1073741823; + onSuspend(root, previousDispatcher, isYieldy, subscriber, -1); return; } } @@ -5839,12 +6470,12 @@ function renderRoot(root, isYieldy) { (isYieldy = nextLatestAbsoluteTimeoutMs - isYieldy), onSuspend( root, - subscriber, + previousDispatcher, expirationTime, root.expirationTime, 0 > isYieldy ? 0 : isYieldy )) - : onComplete(root, subscriber, expirationTime); + : onComplete(root, previousDispatcher, expirationTime); } } function captureCommitPhaseError(sourceFiber, value) { @@ -5881,55 +6512,61 @@ function captureCommitPhaseError(sourceFiber, value) { scheduleWork(sourceFiber, 1073741823)); } function computeExpirationForFiber(currentTime, fiber) { - isWorking - ? (currentTime = isCommitting$1 ? 1073741823 : nextRenderExpirationTime) - : fiber.mode & 1 - ? ((currentTime = isBatchingInteractiveUpdates - ? 1073741822 - 10 * ((((1073741822 - currentTime + 15) / 10) | 0) + 1) - : 1073741822 - - 25 * ((((1073741822 - currentTime + 500) / 25) | 0) + 1)), - null !== nextRoot && - currentTime === nextRenderExpirationTime && - --currentTime) - : (currentTime = 1073741823); - isBatchingInteractiveUpdates && + var priorityLevel = scheduler.unstable_getCurrentPriorityLevel(), + expirationTime = void 0; + if (0 === (fiber.mode & 1)) expirationTime = 1073741823; + else if (isWorking && !isCommitting$1) + expirationTime = nextRenderExpirationTime; + else { + switch (priorityLevel) { + case scheduler.unstable_ImmediatePriority: + expirationTime = 1073741823; + break; + case scheduler.unstable_UserBlockingPriority: + expirationTime = + 1073741822 - 10 * ((((1073741822 - currentTime + 15) / 10) | 0) + 1); + break; + case scheduler.unstable_NormalPriority: + expirationTime = + 1073741822 - 25 * ((((1073741822 - currentTime + 500) / 25) | 0) + 1); + break; + case scheduler.unstable_LowPriority: + case scheduler.unstable_IdlePriority: + expirationTime = 1; + break; + default: + invariant( + !1, + "Unknown priority level. This error is likely caused by a bug in React. Please file an issue." + ); + } + null !== nextRoot && + expirationTime === nextRenderExpirationTime && + --expirationTime; + } + priorityLevel === scheduler.unstable_UserBlockingPriority && (0 === lowestPriorityPendingInteractiveExpirationTime || - currentTime < lowestPriorityPendingInteractiveExpirationTime) && - (lowestPriorityPendingInteractiveExpirationTime = currentTime); - return currentTime; + expirationTime < lowestPriorityPendingInteractiveExpirationTime) && + (lowestPriorityPendingInteractiveExpirationTime = expirationTime); + return expirationTime; } -function retrySuspendedRoot(root, boundaryFiber, sourceFiber, suspendedTime) { - var retryTime = root.earliestSuspendedTime; - var latestSuspendedTime = root.latestSuspendedTime; - if ( - 0 !== retryTime && - suspendedTime <= retryTime && - suspendedTime >= latestSuspendedTime +function pingSuspendedRoot(root, thenable, pingTime) { + var pingCache = root.pingCache; + null !== pingCache && pingCache.delete(thenable); + if (null !== nextRoot && nextRenderExpirationTime === pingTime) + nextRoot = null; + else if ( + ((thenable = root.earliestSuspendedTime), + (pingCache = root.latestSuspendedTime), + 0 !== thenable && pingTime <= thenable && pingTime >= pingCache) ) { - latestSuspendedTime = retryTime = suspendedTime; root.didError = !1; - var latestPingedTime = root.latestPingedTime; - if (0 === latestPingedTime || latestPingedTime > latestSuspendedTime) - root.latestPingedTime = latestSuspendedTime; - findNextExpirationTimeToWorkOn(latestSuspendedTime, root); - } else - (retryTime = requestCurrentTime()), - (retryTime = computeExpirationForFiber(retryTime, boundaryFiber)), - markPendingPriorityLevel(root, retryTime); - 0 !== (boundaryFiber.mode & 1) && - root === nextRoot && - nextRenderExpirationTime === suspendedTime && - (nextRoot = null); - scheduleWorkToRoot(boundaryFiber, retryTime); - 0 === (boundaryFiber.mode & 1) && - (scheduleWorkToRoot(sourceFiber, retryTime), - 1 === sourceFiber.tag && - null !== sourceFiber.stateNode && - ((boundaryFiber = createUpdate(retryTime)), - (boundaryFiber.tag = 2), - enqueueUpdate(sourceFiber, boundaryFiber))); - sourceFiber = root.expirationTime; - 0 !== sourceFiber && requestWork(root, sourceFiber); + thenable = root.latestPingedTime; + if (0 === thenable || thenable > pingTime) root.latestPingedTime = pingTime; + findNextExpirationTimeToWorkOn(pingTime, root); + pingTime = root.expirationTime; + 0 !== pingTime && requestWork(root, pingTime); + } } function scheduleWorkToRoot(fiber, expirationTime) { fiber.expirationTime < expirationTime && @@ -6008,7 +6645,6 @@ var firstScheduledRoot = null, unhandledError = null, isBatchingUpdates = !1, isUnbatchingUpdates = !1, - isBatchingInteractiveUpdates = !1, completedBatches = null, originalStartTimeMs = now$1(), currentRendererTime = 1073741822 - ((originalStartTimeMs / 10) | 0), @@ -6027,9 +6663,10 @@ function scheduleCallbackWithExpirationTime(root, expirationTime) { ((root = callbackID), (scheduledCallback = null), clearTimeout(root)); } callbackExpirationTime = expirationTime; - now$1(); - scheduledCallback = performAsyncWork; - callbackID = setTimeout(setTimeoutCallback, 1); + root = now$1() - originalStartTimeMs; + callbackID = scheduleDeferredCallback$1(performAsyncWork, { + timeout: 10 * (1073741822 - expirationTime) - root + }); } function onComplete(root, finishedWork, expirationTime) { root.pendingCommitExpirationTime = expirationTime; @@ -6277,7 +6914,12 @@ function completeRoot$1(root, finishedWork, expirationTime) { root === lastCommittedRootDuringThisBatch ? nestedUpdateCount++ : ((lastCommittedRootDuringThisBatch = root), (nestedUpdateCount = 0)); - commitRoot(root, finishedWork); + scheduler.unstable_runWithPriority( + scheduler.unstable_ImmediatePriority, + function() { + commitRoot(root, finishedWork); + } + ); } function onUncaughtError(error) { invariant( @@ -6513,6 +7155,7 @@ var roots = new Map(), earliestSuspendedTime: 0, latestSuspendedTime: 0, latestPingedTime: 0, + pingCache: null, didError: !1, pendingCommitExpirationTime: 0, finishedWork: null, @@ -6616,6 +7259,8 @@ var roots = new Map(), var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; return injectInternals( Object.assign({}, devToolsConfig, { + overrideProps: null, + currentDispatcherRef: ReactSharedInternals.ReactCurrentDispatcher, findHostInstanceByFiber: function(fiber) { fiber = findCurrentHostFiber(fiber); return null === fiber ? null : fiber.stateNode; @@ -6631,7 +7276,7 @@ var roots = new Map(), findFiberByHostInstance: getInstanceFromInstance, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 0, - version: "16.6.1", + version: "16.8.1", rendererPackageName: "react-native-renderer" }); var ReactFabric$2 = { default: ReactFabric }, diff --git a/Libraries/Renderer/oss/ReactNativeRenderer-dev.js b/Libraries/Renderer/oss/ReactNativeRenderer-dev.js index 329aabccc5d1ed..2b8c25f70e797f 100644 --- a/Libraries/Renderer/oss/ReactNativeRenderer-dev.js +++ b/Libraries/Renderer/oss/ReactNativeRenderer-dev.js @@ -2840,6 +2840,15 @@ function set(key, value) { var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; +// Prevent newer renderers from RTE when used with older react package versions. +// Current owner and dispatcher used to share the same ref, +// but PR #14548 split them out to better support the react-debug-tools package. +if (!ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher")) { + ReactSharedInternals.ReactCurrentDispatcher = { + current: null + }; +} + // 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. var hasSymbol = typeof Symbol === "function" && Symbol.for; @@ -4082,6 +4091,8 @@ var shouldYield$$1 = shouldYield$1; var scheduleTimeout = setTimeout; var cancelTimeout = clearTimeout; var noTimeout = -1; +var schedulePassiveEffects = scheduleDeferredCallback$$1; +var cancelPassiveEffects = cancelDeferredCallback$$1; function shouldDeprioritizeSubtree(type, props) { return false; @@ -4403,7 +4414,6 @@ function setCurrentPhase(lifeCyclePhase) { var debugRenderPhaseSideEffects = false; var debugRenderPhaseSideEffectsForStrictMode = false; -var enableHooks = false; var enableUserTimingAPI = true; var replayFailedUnitOfWorkWithInvokeGuardedCallback = true; var warnAboutDeprecatedLifecycles = false; @@ -5407,7 +5417,7 @@ function FiberNode(tag, pendingProps, key, mode) { this.memoizedProps = null; this.updateQueue = null; this.memoizedState = null; - this.firstContextDependency = null; + this.contextDependencies = null; this.mode = mode; @@ -5424,14 +5434,16 @@ function FiberNode(tag, pendingProps, key, mode) { this.alternate = null; if (enableProfilerTimer) { - // Note: The following is done to avoid a v8 deopt. + // Note: The following is done to avoid a v8 performance cliff. // - // It is important to initialize the fields below with doubles. - // Otherwise Fibers will deopt and end up having separate shapes when - // doubles are later assigned to fields that initially contained smis. - // This is a bug in v8 having something to do with Object.preventExtension(). + // Initializing the fields below to smis and later updating them with + // double values will cause Fibers to end up having separate shapes. + // This behavior/bug has something to do with Object.preventExtension(). + // Fortunately this only impacts DEV builds. + // Unfortunately it makes React unusably slow for some applications. + // To work around this, initialize the fields below with doubles. // - // Learn more about this deopt here: + // Learn more about this here: // https://github.com/facebook/react/issues/14365 // https://bugs.chromium.org/p/v8/issues/detail?id=8538 this.actualDuration = Number.NaN; @@ -5440,7 +5452,8 @@ function FiberNode(tag, pendingProps, key, mode) { this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization. - // This simplifies other profiler code and doesn't trigger the deopt. + // This won't trigger the performance cliff mentioned above, + // and it simplifies other profiler code (including DevTools). this.actualDuration = 0; this.actualStartTime = -1; this.selfBaseDuration = 0; @@ -5561,7 +5574,7 @@ function createWorkInProgress(current, pendingProps, expirationTime) { workInProgress.memoizedProps = current.memoizedProps; workInProgress.memoizedState = current.memoizedState; workInProgress.updateQueue = current.updateQueue; - workInProgress.firstContextDependency = current.firstContextDependency; + workInProgress.contextDependencies = current.contextDependencies; // These will be overridden during the parent's reconciliation workInProgress.sibling = current.sibling; @@ -5827,7 +5840,7 @@ function assignFiberPropertiesInDEV(target, source) { target.memoizedProps = source.memoizedProps; target.updateQueue = source.updateQueue; target.memoizedState = source.memoizedState; - target.firstContextDependency = source.firstContextDependency; + target.contextDependencies = source.contextDependencies; target.mode = source.mode; target.effectTag = source.effectTag; target.nextEffect = source.nextEffect; @@ -5880,6 +5893,8 @@ function createFiberRoot(containerInfo, isConcurrent, hydrate) { latestSuspendedTime: NoWork, latestPingedTime: NoWork, + pingCache: null, + didError: false, pendingCommitExpirationTime: NoWork, @@ -5903,6 +5918,8 @@ function createFiberRoot(containerInfo, isConcurrent, hydrate) { containerInfo: containerInfo, pendingChildren: null, + pingCache: null, + earliestPendingTime: NoWork, latestPendingTime: NoWork, earliestSuspendedTime: NoWork, @@ -6052,7 +6069,7 @@ var ReactStrictModeWarnings = { lifecycleWarningsMap, strictRoot ) { - var lifecyclesWarningMesages = []; + var lifecyclesWarningMessages = []; Object.keys(lifecycleWarningsMap).forEach(function(lifecycle) { var lifecycleWarnings = lifecycleWarningsMap[lifecycle]; @@ -6067,7 +6084,7 @@ var ReactStrictModeWarnings = { var suggestion = LIFECYCLE_SUGGESTIONS[lifecycle]; var sortedComponentNames = setToSortedString(componentNames); - lifecyclesWarningMesages.push( + lifecyclesWarningMessages.push( formatted + ": Please update the following components to use " + (suggestion + " instead: " + sortedComponentNames) @@ -6075,7 +6092,7 @@ var ReactStrictModeWarnings = { } }); - if (lifecyclesWarningMesages.length > 0) { + if (lifecyclesWarningMessages.length > 0) { var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot); warningWithoutStack$1( @@ -6085,7 +6102,7 @@ var ReactStrictModeWarnings = { "\n\nLearn more about this warning here:" + "\nhttps://fb.me/react-strict-mode-warnings", strictRootComponentStack, - lifecyclesWarningMesages.join("\n\n") + lifecyclesWarningMessages.join("\n\n") ); } }); @@ -6386,6 +6403,10 @@ function markCommittedPriorityLevels(root, earliestRemainingTime) { return; } + if (earliestRemainingTime < root.latestPingedTime) { + root.latestPingedTime = NoWork; + } + // Let's see if the previous latest known pending level was just flushed. var latestPendingTime = root.latestPendingTime; if (latestPendingTime !== NoWork) { @@ -6521,10 +6542,8 @@ function markPingedPriorityLevel(root, pingedTime) { } function clearPing(root, completedTime) { - // TODO: Track whether the root was pinged during the render phase. If so, - // we need to make sure we don't lose track of it. var latestPingedTime = root.latestPingedTime; - if (latestPingedTime !== NoWork && latestPingedTime >= completedTime) { + if (latestPingedTime >= completedTime) { root.latestPingedTime = NoWork; } } @@ -6585,4167 +6604,3975 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) { 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; +/** + * 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. + */ -// 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 warning = warningWithoutStack$1; -var didWarnUpdateInsideUpdate = void 0; -var currentlyProcessingQueue = void 0; -var resetCurrentlyProcessingQueue = void 0; { - didWarnUpdateInsideUpdate = false; - currentlyProcessingQueue = null; - resetCurrentlyProcessingQueue = function() { - currentlyProcessingQueue = null; - }; -} + warning = function(condition, format) { + if (condition) { + return; + } + var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; + var stack = ReactDebugCurrentFrame.getStackAddendum(); + // eslint-disable-next-line react-internal/warning-and-invariant-args -function createUpdateQueue(baseState) { - var queue = { - baseState: baseState, - firstUpdate: null, - lastUpdate: null, - firstCapturedUpdate: null, - lastCapturedUpdate: null, - firstEffect: null, - lastEffect: null, - firstCapturedEffect: null, - lastCapturedEffect: null + for ( + var _len = arguments.length, + args = Array(_len > 2 ? _len - 2 : 0), + _key = 2; + _key < _len; + _key++ + ) { + args[_key - 2] = arguments[_key]; + } + + warningWithoutStack$1.apply( + undefined, + [false, format + "%s"].concat(args, [stack]) + ); }; - return queue; } -function cloneUpdateQueue(currentQueue) { - var queue = { - baseState: currentQueue.baseState, - firstUpdate: currentQueue.firstUpdate, - lastUpdate: currentQueue.lastUpdate, +var warning$1 = warning; - // TODO: With resuming, if we bail out and resuse the child tree, we should - // keep these effects. - firstCapturedUpdate: null, - lastCapturedUpdate: null, +/** + * 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) { + return ( + (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare + ); +} - firstEffect: null, - lastEffect: null, +var hasOwnProperty = Object.prototype.hasOwnProperty; - firstCapturedEffect: null, - lastCapturedEffect: null - }; - return queue; -} +/** + * 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; + } -function createUpdate(expirationTime) { - return { - expirationTime: expirationTime, + if ( + typeof objA !== "object" || + objA === null || + typeof objB !== "object" || + objB === null + ) { + return false; + } - tag: UpdateState, - payload: null, - callback: null, + var keysA = Object.keys(objA); + var keysB = Object.keys(objB); - next: null, - nextEffect: null - }; -} + if (keysA.length !== keysB.length) { + return false; + } -function appendUpdateToQueue(queue, update) { - // 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; + // 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; + } } + + return true; } -function enqueueUpdate(fiber, update) { - // 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. +function resolveDefaultProps(Component, baseProps) { + if (Component && Component.defaultProps) { + // Resolve default props. Taken from ReactElement + var props = Object.assign({}, baseProps); + var defaultProps = Component.defaultProps; + for (var propName in defaultProps) { + if (props[propName] === undefined) { + props[propName] = defaultProps[propName]; } } + return props; } - if (queue2 === null || queue1 === queue2) { - // There's only a single queue. - appendUpdateToQueue(queue1, update); - } 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); - appendUpdateToQueue(queue2, update); - } 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); - // But we still need to update the `lastUpdate` pointer of queue2. - queue2.lastUpdate = update; - } - } + return baseProps; +} - { - if ( - fiber.tag === ClassComponent && - (currentlyProcessingQueue === queue1 || - (queue2 !== null && currentlyProcessingQueue === queue2)) && - !didWarnUpdateInsideUpdate - ) { - warningWithoutStack$1( - 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." +function readLazyComponentType(lazyComponent) { + var status = lazyComponent._status; + var result = lazyComponent._result; + switch (status) { + case Resolved: { + var Component = result; + return Component; + } + case Rejected: { + var error = result; + throw error; + } + case Pending: { + var thenable = result; + throw thenable; + } + default: { + lazyComponent._status = Pending; + var ctor = lazyComponent._ctor; + var _thenable = ctor(); + _thenable.then( + function(moduleObject) { + if (lazyComponent._status === Pending) { + var defaultExport = moduleObject.default; + { + if (defaultExport === undefined) { + warning$1( + false, + "lazy: Expected the result of a dynamic import() call. " + + "Instead received: %s\n\nYour code should look like: \n " + + "const MyComponent = lazy(() => import('./MyComponent'))", + moduleObject + ); + } + } + lazyComponent._status = Resolved; + lazyComponent._result = defaultExport; + } + }, + function(error) { + if (lazyComponent._status === Pending) { + lazyComponent._status = Rejected; + lazyComponent._result = error; + } + } ); - didWarnUpdateInsideUpdate = true; + // Handle synchronous thenables. + switch (lazyComponent._status) { + case Resolved: + return lazyComponent._result; + case Rejected: + throw lazyComponent._result; + } + lazyComponent._result = _thenable; + throw _thenable; } } } -function enqueueCapturedUpdate(workInProgress, update) { - // 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 - ); - } +var fakeInternalInstance = {}; +var isArray$1 = Array.isArray; - // 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; - } -} +// React.Component uses a shared frozen object by default. +// We'll use it to determine whether we need to initialize legacy refs. +var emptyRefsObject = new React.Component().refs; -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; -} +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 didWarnAboutDirectlyAssigningPropsToState = void 0; +var didWarnAboutContextTypeAndContextTypes = void 0; +var didWarnAboutInvalidateContextType = void 0; -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; +{ + didWarnAboutStateAssignmentForComponent = new Set(); + didWarnAboutUninitializedState = new Set(); + didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); + didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); + didWarnAboutDirectlyAssigningPropsToState = new Set(); + didWarnAboutUndefinedDerivedState = new Set(); + didWarnAboutContextTypeAndContextTypes = new Set(); + didWarnAboutInvalidateContextType = new Set(); + + var didWarnOnInvalidCallback = new Set(); + + warnOnInvalidCallback = function(callback, callerName) { + if (callback === null || typeof callback === "function") { + return; } - case CaptureUpdate: { - workInProgress.effectTag = - (workInProgress.effectTag & ~ShouldCapture) | DidCapture; + var key = callerName + "_" + callback; + if (!didWarnOnInvalidCallback.has(key)) { + didWarnOnInvalidCallback.add(key); + warningWithoutStack$1( + false, + "%s(...): Expected the last optional `callback` argument to be a " + + "function. Instead received: %s.", + callerName, + callback + ); } - // 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; + }; + + warnOnUndefinedDerivedState = function(type, partialState) { + if (partialState === undefined) { + var componentName = getComponentName(type) || "Component"; + if (!didWarnAboutUndefinedDerivedState.has(componentName)) { + didWarnAboutUndefinedDerivedState.add(componentName); + warningWithoutStack$1( + false, + "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + + "You have returned undefined.", + componentName + ); } - // Merge the partial state and the previous state. - return Object.assign({}, prevState, partialState); } - case ForceUpdate: { - hasForceUpdate = true; - return prevState; + }; + + // 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)." + ); } - } - return prevState; + }); + Object.freeze(fakeInternalInstance); } -function processUpdateQueue( +function applyDerivedStateFromProps( workInProgress, - queue, - props, - instance, - renderExpirationTime + ctor, + getDerivedStateFromProps, + nextProps ) { - hasForceUpdate = false; + var prevState = workInProgress.memoizedState; - queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + { + 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); { - currentlyProcessingQueue = queue; + warnOnUndefinedDerivedState(ctor, partialState); } + // Merge the partial state and the previous state. + var memoizedState = + partialState === null || partialState === undefined + ? prevState + : Object.assign({}, prevState, partialState); + workInProgress.memoizedState = memoizedState; - // These values may change as we process the queue. - var newBaseState = queue.baseState; - var newFirstUpdate = null; - var newExpirationTime = NoWork; + // Once the update queue is empty, persist the derived state onto the + // base state. + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null && workInProgress.expirationTime === NoWork) { + updateQueue.baseState = memoizedState; + } +} - // 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 < 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; - } +var classComponentUpdater = { + isMounted: isMounted, + enqueueSetState: function(inst, payload, callback) { + var fiber = get$1(inst); + var currentTime = requestCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); + + var update = createUpdate(expirationTime); + update.payload = payload; + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "setState"); } + update.callback = callback; } - // 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 < _updateExpirationTime) { - newExpirationTime = _updateExpirationTime; + flushPassiveEffects(); + enqueueUpdate(fiber, update); + scheduleWork(fiber, expirationTime); + }, + enqueueReplaceState: function(inst, payload, callback) { + var fiber = get$1(inst); + var currentTime = requestCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); + + var update = createUpdate(expirationTime); + update.tag = ReplaceState; + update.payload = payload; + + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "replaceState"); } - } 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.callback = callback; + } + + flushPassiveEffects(); + enqueueUpdate(fiber, update); + scheduleWork(fiber, expirationTime); + }, + enqueueForceUpdate: function(inst, callback) { + var fiber = get$1(inst); + var currentTime = requestCurrentTime(); + var expirationTime = computeExpirationForFiber(currentTime, fiber); + + var update = createUpdate(expirationTime); + update.tag = ForceUpdate; + + if (callback !== undefined && callback !== null) { + { + warnOnInvalidCallback(callback, "forceUpdate"); } + update.callback = callback; } - 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; + flushPassiveEffects(); + enqueueUpdate(fiber, update); + scheduleWork(fiber, expirationTime); } +}; - queue.baseState = newBaseState; - queue.firstUpdate = newFirstUpdate; - queue.firstCapturedUpdate = newFirstCapturedUpdate; +function checkShouldComponentUpdate( + workInProgress, + ctor, + oldProps, + newProps, + oldState, + newState, + nextContext +) { + var instance = workInProgress.stateNode; + if (typeof instance.shouldComponentUpdate === "function") { + startPhaseTimer(workInProgress, "shouldComponentUpdate"); + var shouldUpdate = instance.shouldComponentUpdate( + newProps, + newState, + nextContext + ); + stopPhaseTimer(); - // Set the remaining expiration time to be whatever is remaining in the queue. - // This should be fine because the only two other things that contribute to - // expiration time are props and context. We're already in the middle of the - // begin phase by the time we start processing the queue, so we've already - // dealt with the props. Context in components that specify - // shouldComponentUpdate is tricky; but we'll have to account for - // that regardless. - workInProgress.expirationTime = newExpirationTime; - workInProgress.memoizedState = resultState; + { + !(shouldUpdate !== undefined) + ? warningWithoutStack$1( + false, + "%s.shouldComponentUpdate(): Returned undefined instead of a " + + "boolean value. Make sure to return true or false.", + getComponentName(ctor) || "Component" + ) + : void 0; + } - { - currentlyProcessingQueue = null; + return shouldUpdate; } -} -function callCallback(callback, context) { - invariant( - typeof callback === "function", - "Invalid argument passed as callback. Expected a function. Instead " + - "received: %s", - callback - ); - callback.call(context); -} + if (ctor.prototype && ctor.prototype.isPureReactComponent) { + return ( + !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) + ); + } -function resetHasForceUpdateBeforeProcessing() { - hasForceUpdate = false; + return true; } -function checkHasForceUpdateAfterProcessing() { - return hasForceUpdate; -} +function checkClassInstance(workInProgress, ctor, newProps) { + var instance = workInProgress.stateNode; + { + var name = getComponentName(ctor) || "Component"; + var renderPresent = instance.render; -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; + if (!renderPresent) { + if (ctor.prototype && typeof ctor.prototype.render === "function") { + warningWithoutStack$1( + false, + "%s(...): No `render` method found on the returned component " + + "instance: did you accidentally return an object from the constructor?", + name + ); + } else { + warningWithoutStack$1( + false, + "%s(...): No `render` method found on the returned component " + + "instance: you may have forgotten to define `render`.", + name + ); + } } - // Clear the list of captured updates. - finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null; - } - // Commit the effects - commitUpdateEffects(finishedQueue.firstEffect, instance); - finishedQueue.firstEffect = finishedQueue.lastEffect = null; - - commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); - finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; -} + var noGetInitialStateOnES6 = + !instance.getInitialState || + instance.getInitialState.isReactClassApproved || + instance.state; + !noGetInitialStateOnES6 + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + false, + "propTypes was defined as an instance property on %s. Use a static " + + "property to define propTypes instead.", + name + ) + : void 0; + var noInstanceContextType = !instance.contextType; + !noInstanceContextType + ? warningWithoutStack$1( + false, + "contextType was defined as an instance property on %s. Use a static " + + "property to define contextType instead.", + name + ) + : void 0; + var noInstanceContextTypes = !instance.contextTypes; + !noInstanceContextTypes + ? warningWithoutStack$1( + false, + "contextTypes was defined as an instance property on %s. Use a static " + + "property to define contextTypes instead.", + name + ) + : void 0; -function commitUpdateEffects(effect, instance) { - while (effect !== null) { - var _callback3 = effect.callback; - if (_callback3 !== null) { - effect.callback = null; - callCallback(_callback3, instance); + if ( + ctor.contextType && + ctor.contextTypes && + !didWarnAboutContextTypeAndContextTypes.has(ctor) + ) { + didWarnAboutContextTypeAndContextTypes.add(ctor); + warningWithoutStack$1( + false, + "%s declares both contextTypes and contextType static properties. " + + "The legacy contextTypes property will be ignored.", + name + ); } - effect = effect.nextEffect; - } -} - -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: getStackByFiberInDevAndProd(source) - }; -} - -/** - * 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 warning = warningWithoutStack$1; -{ - warning = function(condition, format) { - if (condition) { - return; + var noComponentShouldUpdate = + typeof instance.componentShouldUpdate !== "function"; + !noComponentShouldUpdate + ? warningWithoutStack$1( + 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 ( + ctor.prototype && + ctor.prototype.isPureReactComponent && + typeof instance.shouldComponentUpdate !== "undefined" + ) { + warningWithoutStack$1( + 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(ctor) || "A pure component" + ); } - var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; - var stack = ReactDebugCurrentFrame.getStackAddendum(); - // eslint-disable-next-line react-internal/warning-and-invariant-args + var noComponentDidUnmount = + typeof instance.componentDidUnmount !== "function"; + !noComponentDidUnmount + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + false, + "%s has a method called " + + "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", + name + ) + : void 0; + var noUnsafeComponentWillRecieveProps = + typeof instance.UNSAFE_componentWillRecieveProps !== "function"; + !noUnsafeComponentWillRecieveProps + ? warningWithoutStack$1( + false, + "%s has a method called " + + "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?", + name + ) + : void 0; + var hasMutatedProps = instance.props !== newProps; + !(instance.props === undefined || !hasMutatedProps) + ? warningWithoutStack$1( + 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 + ? warningWithoutStack$1( + 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; - for ( - var _len = arguments.length, - args = Array(_len > 2 ? _len - 2 : 0), - _key = 2; - _key < _len; - _key++ + if ( + typeof instance.getSnapshotBeforeUpdate === "function" && + typeof instance.componentDidUpdate !== "function" && + !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor) ) { - args[_key - 2] = arguments[_key]; + didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor); + warningWithoutStack$1( + false, + "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " + + "This component defines getSnapshotBeforeUpdate() only.", + getComponentName(ctor) + ); } - warningWithoutStack$1.apply( - undefined, - [false, format + "%s"].concat(args, [stack]) - ); - }; -} - -var warning$1 = warning; - -var valueCursor = createCursor(null); - -var rendererSigil = void 0; -{ - // Use this to detect multiple renderers using the same context - rendererSigil = {}; -} - -var currentlyRenderingFiber = null; -var lastContextDependency = null; -var lastContextWithAllBitsObserved = null; - -function resetContextDependences() { - // This is called right before React yields execution, to ensure `readContext` - // cannot be called outside the render phase. - currentlyRenderingFiber = null; - lastContextDependency = null; - lastContextWithAllBitsObserved = null; -} - -function pushProvider(providerFiber, nextValue) { - var context = providerFiber.type._context; - - if (isPrimaryRenderer) { - push(valueCursor, context._currentValue, providerFiber); - - context._currentValue = nextValue; - { - !( - context._currentRenderer === undefined || - context._currentRenderer === null || - context._currentRenderer === rendererSigil - ) - ? warningWithoutStack$1( - false, - "Detected multiple renderers concurrently rendering the " + - "same context provider. This is currently unsupported." - ) - : void 0; - context._currentRenderer = rendererSigil; + var noInstanceGetDerivedStateFromProps = + typeof instance.getDerivedStateFromProps !== "function"; + !noInstanceGetDerivedStateFromProps + ? warningWithoutStack$1( + 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.getDerivedStateFromError !== "function"; + !noInstanceGetDerivedStateFromCatch + ? warningWithoutStack$1( + false, + "%s: getDerivedStateFromError() is defined as an instance method " + + "and will be ignored. Instead, declare it as a static method.", + name + ) + : void 0; + var noStaticGetSnapshotBeforeUpdate = + typeof ctor.getSnapshotBeforeUpdate !== "function"; + !noStaticGetSnapshotBeforeUpdate + ? warningWithoutStack$1( + 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$1(_state))) { + warningWithoutStack$1( + false, + "%s.state: must be set to an object or null", + name + ); } - } else { - push(valueCursor, context._currentValue2, providerFiber); - - context._currentValue2 = nextValue; - { - !( - context._currentRenderer2 === undefined || - context._currentRenderer2 === null || - context._currentRenderer2 === rendererSigil - ) + if (typeof instance.getChildContext === "function") { + !(typeof ctor.childContextTypes === "object") ? warningWithoutStack$1( false, - "Detected multiple renderers concurrently rendering the " + - "same context provider. This is currently unsupported." + "%s.getChildContext(): childContextTypes must be defined in order to " + + "use getChildContext().", + name ) : void 0; - context._currentRenderer2 = rendererSigil; } } } -function popProvider(providerFiber) { - var currentValue = valueCursor.current; - - pop(valueCursor, providerFiber); - - var context = providerFiber.type._context; - if (isPrimaryRenderer) { - context._currentValue = currentValue; - } else { - context._currentValue2 = currentValue; +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 calculateChangedBits(context, newValue, oldValue) { - // 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 - return 0; - } else { - var changedBits = - typeof context._calculateChangedBits === "function" - ? context._calculateChangedBits(oldValue, newValue) - : maxSigned31BitInt; - +function constructClassInstance( + workInProgress, + ctor, + props, + renderExpirationTime +) { + var isLegacyContextConsumer = false; + var unmaskedContext = emptyContextObject; + var context = null; + var contextType = ctor.contextType; + if (typeof contextType === "object" && contextType !== null) { { - !((changedBits & maxSigned31BitInt) === changedBits) - ? warning$1( - false, - "calculateChangedBits: Expected the return value to be a " + - "31-bit integer. Instead received: %s", - changedBits - ) - : void 0; + if ( + contextType.$$typeof !== REACT_CONTEXT_TYPE && + !didWarnAboutInvalidateContextType.has(ctor) + ) { + didWarnAboutInvalidateContextType.add(ctor); + warningWithoutStack$1( + false, + "%s defines an invalid contextType. " + + "contextType should point to the Context object returned by React.createContext(). " + + "Did you accidentally pass the Context.Provider instead?", + getComponentName(ctor) || "Component" + ); + } } - return changedBits | 0; + + context = readContext(contextType); + } else { + unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); + var contextTypes = ctor.contextTypes; + isLegacyContextConsumer = + contextTypes !== null && contextTypes !== undefined; + context = isLegacyContextConsumer + ? getMaskedContext(workInProgress, unmaskedContext) + : emptyContextObject; } -} -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; + // Instantiate twice to help detect side-effects. + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + new ctor(props, context); // eslint-disable-line no-new + } } - while (fiber !== null) { - var nextFiber = void 0; - // Visit this fiber. - var dependency = fiber.firstContextDependency; - if (dependency !== null) { - do { - // Check if the context matches. - if ( - dependency.context === context && - (dependency.observedBits & changedBits) !== 0 - ) { - // Match! Schedule an update on this fiber. + var instance = new ctor(props, context); + var state = (workInProgress.memoizedState = + instance.state !== null && instance.state !== undefined + ? instance.state + : null); + adoptClassInstance(workInProgress, instance); - if (fiber.tag === ClassComponent) { - // Schedule a force update on the work-in-progress. - var update = createUpdate(renderExpirationTime); - update.tag = ForceUpdate; - // TODO: Because we don't have a work-in-progress, this will add the - // update to the current fiber, too, which means it will persist even if - // this render is thrown away. Since it's a race condition, not sure it's - // worth fixing. - enqueueUpdate(fiber, update); - } + { + if (typeof ctor.getDerivedStateFromProps === "function" && state === null) { + var componentName = getComponentName(ctor) || "Component"; + if (!didWarnAboutUninitializedState.has(componentName)) { + didWarnAboutUninitializedState.add(componentName); + warningWithoutStack$1( + false, + "`%s` uses `getDerivedStateFromProps` but its initial state is " + + "%s. This is not recommended. Instead, define the initial state by " + + "assigning an object to `this.state` in the constructor of `%s`. " + + "This ensures that `getDerivedStateFromProps` arguments have a consistent shape.", + componentName, + instance.state === null ? "null" : "undefined", + componentName + ); + } + } - if (fiber.expirationTime < renderExpirationTime) { - fiber.expirationTime = renderExpirationTime; - } - var alternate = fiber.alternate; - if ( - alternate !== null && - alternate.expirationTime < renderExpirationTime - ) { - alternate.expirationTime = renderExpirationTime; - } - // Update the child expiration time of all the ancestors, including - // the alternates. - var node = fiber.return; - while (node !== null) { - alternate = node.alternate; - if (node.childExpirationTime < renderExpirationTime) { - node.childExpirationTime = renderExpirationTime; - if ( - alternate !== null && - alternate.childExpirationTime < renderExpirationTime - ) { - alternate.childExpirationTime = renderExpirationTime; - } - } else if ( - alternate !== null && - alternate.childExpirationTime < renderExpirationTime - ) { - alternate.childExpirationTime = renderExpirationTime; - } else { - // Neither alternate was updated, which means the rest of the - // ancestor path already has sufficient priority. - break; - } - node = node.return; - } - } - nextFiber = fiber.child; - dependency = dependency.next; - } while (dependency !== null); - } else if (fiber.tag === ContextProvider) { - // Don't scan deeper if this is a matching provider - nextFiber = fiber.type === workInProgress.type ? null : fiber.child; - } else { - // Traverse down. - nextFiber = fiber.child; - } - - if (nextFiber !== null) { - // Set the return pointer of the child to the work-in-progress fiber. - nextFiber.return = fiber; - } else { - // No child. Traverse to next sibling. - nextFiber = fiber; - while (nextFiber !== null) { - if (nextFiber === workInProgress) { - // We're back to the root of this subtree. Exit. - nextFiber = null; - break; - } - var sibling = nextFiber.sibling; - if (sibling !== null) { - // Set the return pointer of the sibling to the work-in-progress fiber. - sibling.return = nextFiber.return; - nextFiber = sibling; - break; + // 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(ctor) || "Component"; + var newApiName = + typeof ctor.getDerivedStateFromProps === "function" + ? "getDerivedStateFromProps()" + : "getSnapshotBeforeUpdate()"; + if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) { + didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName); + warningWithoutStack$1( + 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 : "" + ); } - // No more siblings. Traverse up. - nextFiber = nextFiber.return; } } - fiber = nextFiber; } -} -function prepareToReadContext(workInProgress, renderExpirationTime) { - currentlyRenderingFiber = workInProgress; - lastContextDependency = null; - lastContextWithAllBitsObserved = null; + // 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 (isLegacyContextConsumer) { + cacheContext(workInProgress, unmaskedContext, context); + } - // Reset the work-in-progress list - workInProgress.firstContextDependency = null; + return instance; } -function readContext(context, observedBits) { - if (lastContextWithAllBitsObserved === context) { - // Nothing to do. We already observe everything in this context. - } else if (observedBits === false || observedBits === 0) { - // Do not observe any updates. - } else { - var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types. - if ( - typeof observedBits !== "number" || - observedBits === maxSigned31BitInt - ) { - // Observe all updates. - lastContextWithAllBitsObserved = context; - resolvedObservedBits = maxSigned31BitInt; - } else { - resolvedObservedBits = observedBits; - } +function callComponentWillMount(workInProgress, instance) { + startPhaseTimer(workInProgress, "componentWillMount"); + var oldState = instance.state; - var contextItem = { - context: context, - observedBits: resolvedObservedBits, - next: null - }; + if (typeof instance.componentWillMount === "function") { + instance.componentWillMount(); + } + if (typeof instance.UNSAFE_componentWillMount === "function") { + instance.UNSAFE_componentWillMount(); + } - if (lastContextDependency === null) { - invariant( - currentlyRenderingFiber !== null, - "Context can only be read while React is " + - "rendering, e.g. inside the render method or getDerivedStateFromProps." + stopPhaseTimer(); + + if (oldState !== instance.state) { + { + warningWithoutStack$1( + false, + "%s.componentWillMount(): Assigning directly to this.state is " + + "deprecated (except inside a component's " + + "constructor). Use setState instead.", + getComponentName(workInProgress.type) || "Component" ); - // This is the first dependency in the list - currentlyRenderingFiber.firstContextDependency = lastContextDependency = contextItem; - } else { - // Append a new context item. - lastContextDependency = lastContextDependency.next = contextItem; } + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); } - return isPrimaryRenderer ? context._currentValue : context._currentValue2; } -var NoEffect$1 = /* */ 0; -var UnmountSnapshot = /* */ 2; -var UnmountMutation = /* */ 4; -var MountMutation = /* */ 8; -var UnmountLayout = /* */ 16; -var MountLayout = /* */ 32; -var MountPassive = /* */ 64; -var UnmountPassive = /* */ 128; +function callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + nextContext +) { + var oldState = instance.state; + startPhaseTimer(workInProgress, "componentWillReceiveProps"); + if (typeof instance.componentWillReceiveProps === "function") { + instance.componentWillReceiveProps(newProps, nextContext); + } + if (typeof instance.UNSAFE_componentWillReceiveProps === "function") { + instance.UNSAFE_componentWillReceiveProps(newProps, nextContext); + } + stopPhaseTimer(); -function areHookInputsEqual(arr1, arr2) { - // Don't bother comparing lengths in prod because these arrays should be - // passed inline. - { - !(arr1.length === arr2.length) - ? warning$1( + if (instance.state !== oldState) { + { + var componentName = getComponentName(workInProgress.type) || "Component"; + if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { + didWarnAboutStateAssignmentForComponent.add(componentName); + warningWithoutStack$1( false, - "Detected a variable number of hook dependencies. The length of the " + - "dependencies array should be constant between renders.\n\n" + - "Previous: %s\n" + - "Incoming: %s", - arr1.join(", "), - arr2.join(", ") - ) - : void 0; - } - for (var i = 0; i < arr1.length; i++) { - // Inlined Object.is polyfill. - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is - var val1 = arr1[i]; - var val2 = arr2[i]; - if ( - (val1 === val2 && (val1 !== 0 || 1 / val1 === 1 / val2)) || - (val1 !== val1 && val2 !== val2) // eslint-disable-line no-self-compare - ) { - continue; + "%s.componentWillReceiveProps(): Assigning directly to " + + "this.state is deprecated (except inside a component's " + + "constructor). Use setState instead.", + componentName + ); + } } - return false; + classComponentUpdater.enqueueReplaceState(instance, instance.state, null); } - return true; } -// These are set right before calling the component. -var renderExpirationTime = NoWork; -// The work-in-progress fiber. I've named it differently to distinguish it from -// the work-in-progress hook. -var currentlyRenderingFiber$1 = null; - -// Hooks are stored as a linked list on the fiber's memoizedState field. The -// current hook list is the list that belongs to the current fiber. The -// work-in-progress hook list is a new list that will be added to the -// work-in-progress fiber. -var firstCurrentHook = null; -var currentHook = null; -var firstWorkInProgressHook = null; -var workInProgressHook = null; +// Invokes the mount life-cycles on a previously never rendered instance. +function mountClassInstance( + workInProgress, + ctor, + newProps, + renderExpirationTime +) { + { + checkClassInstance(workInProgress, ctor, newProps); + } -var remainingExpirationTime = NoWork; -var componentUpdateQueue = null; + var instance = workInProgress.stateNode; + instance.props = newProps; + instance.state = workInProgress.memoizedState; + instance.refs = emptyRefsObject; -// Updates scheduled during render will trigger an immediate re-render at the -// end of the current pass. We can't store these updates on the normal queue, -// because if the work is aborted, they should be discarded. Because this is -// a relatively rare case, we also don't want to add an additional field to -// either the hook or queue object types. So we store them in a lazily create -// map of queue -> render-phase updates, which are discarded once the component -// completes without re-rendering. + var contextType = ctor.contextType; + if (typeof contextType === "object" && contextType !== null) { + instance.context = readContext(contextType); + } else { + var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); + instance.context = getMaskedContext(workInProgress, unmaskedContext); + } -// Whether the work-in-progress hook is a re-rendered hook -var isReRender = false; -// Whether an update was scheduled during the currently executing render pass. -var didScheduleRenderPhaseUpdate = false; -// Lazily created map of render-phase updates -var renderPhaseUpdates = null; -// Counter to prevent infinite loops. -var numberOfReRenders = 0; -var RE_RENDER_LIMIT = 25; + { + if (instance.state === newProps) { + var componentName = getComponentName(ctor) || "Component"; + if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) { + didWarnAboutDirectlyAssigningPropsToState.add(componentName); + warningWithoutStack$1( + false, + "%s: It is not recommended to assign props directly to state " + + "because updates to props won't be reflected in state. " + + "In most cases, it is better to use props directly.", + componentName + ); + } + } -function resolveCurrentlyRenderingFiber() { - invariant( - currentlyRenderingFiber$1 !== null, - "Hooks can only be called inside the body of a function component." - ); - return currentlyRenderingFiber$1; -} + if (workInProgress.mode & StrictMode) { + ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( + workInProgress, + instance + ); -function prepareToUseHooks(current, workInProgress, nextRenderExpirationTime) { - if (!enableHooks) { - return; - } - renderExpirationTime = nextRenderExpirationTime; - currentlyRenderingFiber$1 = workInProgress; - firstCurrentHook = current !== null ? current.memoizedState : null; + ReactStrictModeWarnings.recordLegacyContextWarning( + workInProgress, + instance + ); + } - // The following should have already been reset - // currentHook = null; - // workInProgressHook = null; + if (warnAboutDeprecatedLifecycles) { + ReactStrictModeWarnings.recordDeprecationWarnings( + workInProgress, + instance + ); + } + } - // remainingExpirationTime = NoWork; - // componentUpdateQueue = null; + var updateQueue = workInProgress.updateQueue; + if (updateQueue !== null) { + processUpdateQueue( + workInProgress, + updateQueue, + newProps, + instance, + renderExpirationTime + ); + instance.state = workInProgress.memoizedState; + } - // isReRender = false; - // didScheduleRenderPhaseUpdate = false; - // renderPhaseUpdates = null; - // numberOfReRenders = 0; -} + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + ctor, + getDerivedStateFromProps, + newProps + ); + instance.state = workInProgress.memoizedState; + } -function finishHooks(Component, props, children, refOrContext) { - if (!enableHooks) { - return children; + // 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, + newProps, + instance, + renderExpirationTime + ); + instance.state = workInProgress.memoizedState; + } } - // This must be called after every function component to prevent hooks from - // being used in classes. + if (typeof instance.componentDidMount === "function") { + workInProgress.effectTag |= Update; + } +} - while (didScheduleRenderPhaseUpdate) { - // Updates were scheduled during the render phase. They are stored in - // the `renderPhaseUpdates` map. Call the component again, reusing the - // work-in-progress hooks and applying the additional updates on top. Keep - // restarting until no more updates are scheduled. - didScheduleRenderPhaseUpdate = false; - numberOfReRenders += 1; +function resumeMountClassInstance( + workInProgress, + ctor, + newProps, + renderExpirationTime +) { + var instance = workInProgress.stateNode; - // Start over from the beginning of the list - currentHook = null; - workInProgressHook = null; - componentUpdateQueue = null; + var oldProps = workInProgress.memoizedProps; + instance.props = oldProps; - children = Component(props, refOrContext); + var oldContext = instance.context; + var contextType = ctor.contextType; + var nextContext = void 0; + if (typeof contextType === "object" && contextType !== null) { + nextContext = readContext(contextType); + } else { + var nextLegacyUnmaskedContext = getUnmaskedContext( + workInProgress, + ctor, + true + ); + nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext); } - renderPhaseUpdates = null; - numberOfReRenders = 0; - - var renderedWork = currentlyRenderingFiber$1; - - renderedWork.memoizedState = firstWorkInProgressHook; - renderedWork.expirationTime = remainingExpirationTime; - renderedWork.updateQueue = componentUpdateQueue; - var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null; + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + var hasNewLifecycles = + typeof getDerivedStateFromProps === "function" || + typeof instance.getSnapshotBeforeUpdate === "function"; - renderExpirationTime = NoWork; - currentlyRenderingFiber$1 = null; + // 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. - firstCurrentHook = null; - currentHook = null; - firstWorkInProgressHook = null; - workInProgressHook = null; + // 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 !== nextContext) { + callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + nextContext + ); + } + } - remainingExpirationTime = NoWork; - componentUpdateQueue = null; + resetHasForceUpdateBeforeProcessing(); - // Always set during createWorkInProgress - // isReRender = 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; + } + return false; + } - // These were reset above - // didScheduleRenderPhaseUpdate = false; - // renderPhaseUpdates = null; - // numberOfReRenders = 0; + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + ctor, + getDerivedStateFromProps, + newProps + ); + newState = workInProgress.memoizedState; + } - invariant( - !didRenderTooFewHooks, - "Rendered fewer hooks than expected. This may be caused by an accidental " + - "early return statement." - ); + var shouldUpdate = + checkHasForceUpdateAfterProcessing() || + checkShouldComponentUpdate( + workInProgress, + ctor, + oldProps, + newProps, + oldState, + newState, + nextContext + ); - return children; -} + 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 resetHooks() { - if (!enableHooks) { - return; + // 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; } - // This is called instead of `finishHooks` if the component throws. It's also - // called inside mountIndeterminateComponent if we determine the component - // is a module-style component. - renderExpirationTime = NoWork; - currentlyRenderingFiber$1 = null; + // Update the existing instance's state, props, and context pointers even + // if shouldComponentUpdate returns false. + instance.props = newProps; + instance.state = newState; + instance.context = nextContext; - firstCurrentHook = null; - currentHook = null; - firstWorkInProgressHook = null; - workInProgressHook = null; - - remainingExpirationTime = NoWork; - componentUpdateQueue = null; + return shouldUpdate; +} - // Always set during createWorkInProgress - // isReRender = false; +// Invokes the update life-cycles and returns false if it shouldn't rerender. +function updateClassInstance( + current, + workInProgress, + ctor, + newProps, + renderExpirationTime +) { + var instance = workInProgress.stateNode; - didScheduleRenderPhaseUpdate = false; - renderPhaseUpdates = null; - numberOfReRenders = 0; -} + var oldProps = workInProgress.memoizedProps; + instance.props = + workInProgress.type === workInProgress.elementType + ? oldProps + : resolveDefaultProps(workInProgress.type, oldProps); -function createHook() { - return { - memoizedState: null, + var oldContext = instance.context; + var contextType = ctor.contextType; + var nextContext = void 0; + if (typeof contextType === "object" && contextType !== null) { + nextContext = readContext(contextType); + } else { + var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true); + nextContext = getMaskedContext(workInProgress, nextUnmaskedContext); + } - baseState: null, - queue: null, - baseUpdate: null, + var getDerivedStateFromProps = ctor.getDerivedStateFromProps; + var hasNewLifecycles = + typeof getDerivedStateFromProps === "function" || + typeof instance.getSnapshotBeforeUpdate === "function"; - next: null - }; -} + // 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. -function cloneHook(hook) { - return { - memoizedState: hook.memoizedState, + // 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 !== nextContext) { + callComponentWillReceiveProps( + workInProgress, + instance, + newProps, + nextContext + ); + } + } - baseState: hook.baseState, - queue: hook.queue, - baseUpdate: hook.baseUpdate, + resetHasForceUpdateBeforeProcessing(); - next: null - }; -} + 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 createWorkInProgressHook() { - if (workInProgressHook === null) { - // This is the first hook in the list - if (firstWorkInProgressHook === null) { - isReRender = false; - currentHook = firstCurrentHook; - if (currentHook === null) { - // This is a newly mounted hook - workInProgressHook = createHook(); - } else { - // Clone the current hook. - workInProgressHook = cloneHook(currentHook); + 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; } - firstWorkInProgressHook = workInProgressHook; - } else { - // There's already a work-in-progress. Reuse it. - isReRender = true; - currentHook = firstCurrentHook; - workInProgressHook = firstWorkInProgressHook; } - } else { - if (workInProgressHook.next === null) { - isReRender = false; - var hook = void 0; - if (currentHook === null) { - // This is a newly mounted hook - hook = createHook(); - } else { - currentHook = currentHook.next; - if (currentHook === null) { - // This is a newly mounted hook - hook = createHook(); - } else { - // Clone the current hook. - hook = cloneHook(currentHook); - } + if (typeof instance.getSnapshotBeforeUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + workInProgress.effectTag |= Snapshot; } - // Append to the end of the list - workInProgressHook = workInProgressHook.next = hook; - } else { - // There's already a work-in-progress. Reuse it. - isReRender = true; - workInProgressHook = workInProgressHook.next; - currentHook = currentHook !== null ? currentHook.next : null; } + return false; } - return workInProgressHook; -} - -function createFunctionComponentUpdateQueue() { - return { - lastEffect: null - }; -} - -function basicStateReducer(state, action) { - return typeof action === "function" ? action(state) : action; -} - -function useContext(context, observedBits) { - // Ensure we're in a function component (class components support only the - // .unstable_read() form) - resolveCurrentlyRenderingFiber(); - return readContext(context, observedBits); -} -function useState(initialState) { - return useReducer( - basicStateReducer, - // useReducer has a special case to support lazy useState initializers - initialState - ); -} + if (typeof getDerivedStateFromProps === "function") { + applyDerivedStateFromProps( + workInProgress, + ctor, + getDerivedStateFromProps, + newProps + ); + newState = workInProgress.memoizedState; + } -function useReducer(reducer, initialState, initialAction) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); - var queue = workInProgressHook.queue; - if (queue !== null) { - // Already have a queue, so this is an update. - if (isReRender) { - // This is a re-render. Apply the new render phase updates to the previous - var _dispatch2 = queue.dispatch; - if (renderPhaseUpdates !== null) { - // Render phase updates are stored in a map of queue -> linked list - var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); - if (firstRenderPhaseUpdate !== undefined) { - renderPhaseUpdates.delete(queue); - var newState = workInProgressHook.memoizedState; - var update = firstRenderPhaseUpdate; - do { - // Process this render phase update. We don't have to check the - // priority because it will always be the same as the current - // render's. - var _action = update.action; - newState = reducer(newState, _action); - update = update.next; - } while (update !== null); - - workInProgressHook.memoizedState = newState; - - // Don't persist the state accumlated from the render phase updates to - // the base state unless the queue is empty. - // TODO: Not sure if this is the desired semantics, but it's what we - // do for gDSFP. I can't remember why. - if (workInProgressHook.baseUpdate === queue.last) { - workInProgressHook.baseState = newState; - } + var shouldUpdate = + checkHasForceUpdateAfterProcessing() || + checkShouldComponentUpdate( + workInProgress, + ctor, + oldProps, + newProps, + oldState, + newState, + nextContext + ); - return [newState, _dispatch2]; - } + 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, nextContext); } - return [workInProgressHook.memoizedState, _dispatch2]; - } - - // The last update in the entire queue - var _last = queue.last; - // The last update that is part of the base state. - var _baseUpdate = workInProgressHook.baseUpdate; - - // Find the first unprocessed update. - var first = void 0; - if (_baseUpdate !== null) { - if (_last !== null) { - // For the first update, the queue is a circular linked list where - // `queue.last.next = queue.first`. Once the first update commits, and - // the `baseUpdate` is no longer empty, we can unravel the list. - _last.next = null; - } - first = _baseUpdate.next; - } else { - first = _last !== null ? _last.next : null; - } - if (first !== null) { - var _newState = workInProgressHook.baseState; - var newBaseState = null; - var newBaseUpdate = null; - var prevUpdate = _baseUpdate; - var _update = first; - var didSkip = false; - do { - var updateExpirationTime = _update.expirationTime; - if (updateExpirationTime < renderExpirationTime) { - // Priority is insufficient. Skip this update. If this is the first - // skipped update, the previous update/state is the new base - // update/state. - if (!didSkip) { - didSkip = true; - newBaseUpdate = prevUpdate; - newBaseState = _newState; - } - // Update the remaining priority in the queue. - if (updateExpirationTime > remainingExpirationTime) { - remainingExpirationTime = updateExpirationTime; - } - } else { - // Process this update. - var _action2 = _update.action; - _newState = reducer(_newState, _action2); - } - prevUpdate = _update; - _update = _update.next; - } while (_update !== null && _update !== first); - - if (!didSkip) { - newBaseUpdate = prevUpdate; - newBaseState = _newState; + if (typeof instance.UNSAFE_componentWillUpdate === "function") { + instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext); } - - workInProgressHook.memoizedState = _newState; - workInProgressHook.baseUpdate = newBaseUpdate; - workInProgressHook.baseState = newBaseState; + stopPhaseTimer(); } - - var _dispatch = queue.dispatch; - return [workInProgressHook.memoizedState, _dispatch]; - } - - // There's no existing queue, so this is the initial render. - if (reducer === basicStateReducer) { - // Special case for `useState`. - if (typeof initialState === "function") { - initialState = initialState(); + if (typeof instance.componentDidUpdate === "function") { + workInProgress.effectTag |= Update; + } + if (typeof instance.getSnapshotBeforeUpdate === "function") { + workInProgress.effectTag |= Snapshot; } - } else if (initialAction !== undefined && initialAction !== null) { - initialState = reducer(initialState, initialAction); - } - workInProgressHook.memoizedState = workInProgressHook.baseState = initialState; - queue = workInProgressHook.queue = { - last: null, - dispatch: null - }; - var dispatch = (queue.dispatch = dispatchAction.bind( - null, - currentlyRenderingFiber$1, - queue - )); - return [workInProgressHook.memoizedState, dispatch]; -} - -function pushEffect(tag, create, destroy, inputs) { - var effect = { - tag: tag, - create: create, - destroy: destroy, - inputs: inputs, - // Circular - next: null - }; - if (componentUpdateQueue === null) { - componentUpdateQueue = createFunctionComponentUpdateQueue(); - componentUpdateQueue.lastEffect = effect.next = effect; } else { - var _lastEffect = componentUpdateQueue.lastEffect; - if (_lastEffect === null) { - componentUpdateQueue.lastEffect = effect.next = effect; - } else { - var firstEffect = _lastEffect.next; - _lastEffect.next = effect; - effect.next = firstEffect; - componentUpdateQueue.lastEffect = effect; + // 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 effect; -} - -function useRef(initialValue) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); - var ref = void 0; - - if (workInProgressHook.memoizedState === null) { - ref = { current: initialValue }; - { - Object.seal(ref); + if (typeof instance.getSnapshotBeforeUpdate === "function") { + if ( + oldProps !== current.memoizedProps || + oldState !== current.memoizedState + ) { + workInProgress.effectTag |= Snapshot; + } } - workInProgressHook.memoizedState = ref; - } else { - ref = workInProgressHook.memoizedState; + + // 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; } - return ref; -} -function useLayoutEffect(create, inputs) { - useEffectImpl(Update, UnmountMutation | MountLayout, create, inputs); + // Update the existing instance's state, props, and context pointers even + // if shouldComponentUpdate returns false. + instance.props = newProps; + instance.state = newState; + instance.context = nextContext; + + return shouldUpdate; } -function useEffect(create, inputs) { - useEffectImpl( - Update | Passive, - UnmountPassive | MountPassive, - create, - inputs - ); -} +var didWarnAboutMaps = void 0; +var didWarnAboutGenerators = void 0; +var didWarnAboutStringRefInStrictMode = void 0; +var ownerHasKeyUseWarning = void 0; +var ownerHasFunctionTypeWarning = void 0; +var warnForMissingKey = function(child) {}; -function useEffectImpl(fiberEffectTag, hookEffectTag, create, inputs) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); +{ + didWarnAboutMaps = false; + didWarnAboutGenerators = false; + didWarnAboutStringRefInStrictMode = {}; - var nextInputs = inputs !== undefined && inputs !== null ? inputs : [create]; - var destroy = null; - if (currentHook !== null) { - var prevEffect = currentHook.memoizedState; - destroy = prevEffect.destroy; - if (areHookInputsEqual(nextInputs, prevEffect.inputs)) { - pushEffect(NoEffect$1, create, destroy, nextInputs); + /** + * 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; - currentlyRenderingFiber$1.effectTag |= fiberEffectTag; - workInProgressHook.memoizedState = pushEffect( - hookEffectTag, - create, - destroy, - nextInputs - ); + var currentComponentErrorInfo = + "Each child in a list should have a unique " + + '"key" prop. See https://fb.me/react-warning-keys for ' + + "more information." + + getCurrentFiberStackInDev(); + if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { + return; + } + ownerHasKeyUseWarning[currentComponentErrorInfo] = true; + + warning$1( + false, + "Each child in a list should have a unique " + + '"key" prop. See https://fb.me/react-warning-keys for ' + + "more information." + ); + }; } -function useImperativeMethods(ref, create, inputs) { - // TODO: If inputs are provided, should we skip comparing the ref itself? - var nextInputs = - inputs !== null && inputs !== undefined - ? inputs.concat([ref]) - : [ref, create]; +var isArray = Array.isArray; - // TODO: I've implemented this on top of useEffect because it's almost the - // same thing, and it would require an equal amount of code. It doesn't seem - // like a common enough use case to justify the additional size. - useLayoutEffect(function() { - if (typeof ref === "function") { - var refCallback = ref; - var _inst = create(); - refCallback(_inst); - return function() { - return refCallback(null); - }; - } else if (ref !== null && ref !== undefined) { - var refObject = ref; - var _inst2 = create(); - refObject.current = _inst2; - return function() { - refObject.current = null; +function coerceRef(returnFiber, current$$1, element) { + var mixedRef = element.ref; + if ( + mixedRef !== null && + typeof mixedRef !== "function" && + typeof mixedRef !== "object" + ) { + { + if (returnFiber.mode & StrictMode) { + var componentName = getComponentName(returnFiber.type) || "Component"; + if (!didWarnAboutStringRefInStrictMode[componentName]) { + warningWithoutStack$1( + 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, + getStackByFiberInDevAndProd(returnFiber) + ); + didWarnAboutStringRefInStrictMode[componentName] = true; + } + } + } + + if (element._owner) { + var owner = element._owner; + var inst = void 0; + if (owner) { + var ownerFiber = owner; + invariant( + ownerFiber.tag === ClassComponent, + "Function components cannot have refs. " + + "Did you mean to use React.forwardRef()?" + ); + 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$$1 !== null && + current$$1.ref !== null && + typeof current$$1.ref === "function" && + current$$1.ref._stringRef === stringRef + ) { + return current$$1.ref; + } + var ref = function(value) { + var refs = inst.refs; + if (refs === emptyRefsObject) { + // This is a lazy pooled frozen object, so we need to initialize. + 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, a string, an object returned by React.createRef(), or null." + ); + 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 function component\n" + + "2. You may be adding a ref to a component that was not created inside a component's render method\n" + + "3. You have multiple copies of React loaded\n" + + "See https://fb.me/react-refs-must-have-owner for more information.", + mixedRef + ); } - }, nextInputs); + } + return mixedRef; } -function useCallback(callback, inputs) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); - - var nextInputs = - inputs !== undefined && inputs !== null ? inputs : [callback]; - - var prevState = workInProgressHook.memoizedState; - if (prevState !== null) { - var prevInputs = prevState[1]; - if (areHookInputsEqual(nextInputs, prevInputs)) { - return prevState[0]; +function throwOnInvalidObjectType(returnFiber, newChild) { + if (returnFiber.type !== "textarea") { + var addendum = ""; + { + addendum = + " If you meant to render a collection of children, use an array " + + "instead." + + getCurrentFiberStackInDev(); } + 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 + ); } - workInProgressHook.memoizedState = [callback, nextInputs]; - return callback; } -function useMemo(nextCreate, inputs) { - currentlyRenderingFiber$1 = resolveCurrentlyRenderingFiber(); - workInProgressHook = createWorkInProgressHook(); - - var nextInputs = - inputs !== undefined && inputs !== null ? inputs : [nextCreate]; +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." + + getCurrentFiberStackInDev(); - var prevState = workInProgressHook.memoizedState; - if (prevState !== null) { - var prevInputs = prevState[1]; - if (areHookInputsEqual(nextInputs, prevInputs)) { - return prevState[0]; - } + if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) { + return; } + ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; - var nextValue = nextCreate(); - workInProgressHook.memoizedState = [nextValue, nextInputs]; - return nextValue; -} - -function dispatchAction(fiber, queue, action) { - invariant( - numberOfReRenders < RE_RENDER_LIMIT, - "Too many re-renders. React limits the number of renders to prevent " + - "an infinite loop." + warning$1( + 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." ); +} - var alternate = fiber.alternate; - if ( - fiber === currentlyRenderingFiber$1 || - (alternate !== null && alternate === currentlyRenderingFiber$1) - ) { - // This is a render phase update. Stash it in a lazily-created map of - // queue -> linked list of updates. After this render pass, we'll restart - // and apply the stashed updates on top of the work-in-progress hook. - didScheduleRenderPhaseUpdate = true; - var update = { - expirationTime: renderExpirationTime, - action: action, - next: null - }; - if (renderPhaseUpdates === null) { - renderPhaseUpdates = new Map(); - } - var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); - if (firstRenderPhaseUpdate === undefined) { - renderPhaseUpdates.set(queue, update); - } else { - // Append the update to the end of the list. - var lastRenderPhaseUpdate = firstRenderPhaseUpdate; - while (lastRenderPhaseUpdate.next !== null) { - lastRenderPhaseUpdate = lastRenderPhaseUpdate.next; - } - lastRenderPhaseUpdate.next = update; +// 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; } - } else { - var currentTime = requestCurrentTime(); - var _expirationTime = computeExpirationForFiber(currentTime, fiber); - var _update2 = { - expirationTime: _expirationTime, - action: action, - next: null - }; - flushPassiveEffects(); - // Append the update to the end of the list. - var _last2 = queue.last; - if (_last2 === null) { - // This is the first update. Create a circular list. - _update2.next = _update2; + // 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 { - var first = _last2.next; - if (first !== null) { - // Still circular. - _update2.next = first; - } - _last2.next = _update2; + returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; } - queue.last = _update2; - scheduleWork(fiber, _expirationTime); + childToDelete.nextEffect = null; + childToDelete.effectTag = Deletion; } -} - -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; -var profilerStartTime = -1; - -function getCommitTime() { - return commitTime; -} - -function recordCommitTime() { - if (!enableProfilerTimer) { - return; - } - commitTime = now$$1(); -} + function deleteRemainingChildren(returnFiber, currentFirstChild) { + if (!shouldTrackSideEffects) { + // Noop. + return null; + } -function startProfilerTimer(fiber) { - if (!enableProfilerTimer) { - 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; + } + return null; } - profilerStartTime = now$$1(); - - if (fiber.actualStartTime < 0) { - fiber.actualStartTime = now$$1(); - } -} + 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(); -function stopProfilerTimerIfRunning(fiber) { - if (!enableProfilerTimer) { - return; + var existingChild = currentFirstChild; + while (existingChild !== null) { + if (existingChild.key !== null) { + existingChildren.set(existingChild.key, existingChild); + } else { + existingChildren.set(existingChild.index, existingChild); + } + existingChild = existingChild.sibling; + } + return existingChildren; } - profilerStartTime = -1; -} -function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) { - if (!enableProfilerTimer) { - return; + 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 (profilerStartTime >= 0) { - var elapsedTime = now$$1() - profilerStartTime; - fiber.actualDuration += elapsedTime; - if (overrideBaseTime) { - fiber.selfBaseDuration = elapsedTime; + function placeChild(newFiber, lastPlacedIndex, newIndex) { + newFiber.index = newIndex; + if (!shouldTrackSideEffects) { + // Noop. + return lastPlacedIndex; + } + var current$$1 = newFiber.alternate; + if (current$$1 !== null) { + var oldIndex = current$$1.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; } - profilerStartTime = -1; - } -} - -/*eslint-disable no-self-compare */ - -var hasOwnProperty = Object.prototype.hasOwnProperty; - -/** - * 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; } -} -/** - * 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; + 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; } - if ( - typeof objA !== "object" || - objA === null || - typeof objB !== "object" || - objB === null + function updateTextNode( + returnFiber, + current$$1, + textContent, + expirationTime ) { - return false; + if (current$$1 === null || current$$1.tag !== HostText) { + // Insert + var created = createFiberFromText( + textContent, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber(current$$1, textContent, expirationTime); + existing.return = returnFiber; + return existing; + } } - var keysA = Object.keys(objA); - var keysB = Object.keys(objB); - - if (keysA.length !== keysB.length) { - return false; + function updateElement(returnFiber, current$$1, element, expirationTime) { + if (current$$1 !== null && current$$1.elementType === element.type) { + // Move based on index + var existing = useFiber(current$$1, element.props, expirationTime); + existing.ref = coerceRef(returnFiber, current$$1, 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$$1, element); + created.return = returnFiber; + return created; + } } - // Test for A's keys different from B. - for (var i = 0; i < keysA.length; i++) { + function updatePortal(returnFiber, current$$1, portal, expirationTime) { if ( - !hasOwnProperty.call(objB, keysA[i]) || - !is(objA[keysA[i]], objB[keysA[i]]) + current$$1 === null || + current$$1.tag !== HostPortal || + current$$1.stateNode.containerInfo !== portal.containerInfo || + current$$1.stateNode.implementation !== portal.implementation ) { - return false; + // Insert + var created = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber( + current$$1, + portal.children || [], + expirationTime + ); + existing.return = returnFiber; + return existing; } } - return true; -} - -function resolveDefaultProps(Component, baseProps) { - if (Component && Component.defaultProps) { - // Resolve default props. Taken from ReactElement - var props = Object.assign({}, baseProps); - var defaultProps = Component.defaultProps; - for (var propName in defaultProps) { - if (props[propName] === undefined) { - props[propName] = defaultProps[propName]; - } + function updateFragment( + returnFiber, + current$$1, + fragment, + expirationTime, + key + ) { + if (current$$1 === null || current$$1.tag !== Fragment) { + // Insert + var created = createFiberFromFragment( + fragment, + returnFiber.mode, + expirationTime, + key + ); + created.return = returnFiber; + return created; + } else { + // Update + var existing = useFiber(current$$1, fragment, expirationTime); + existing.return = returnFiber; + return existing; } - return props; } - return baseProps; -} -function readLazyComponentType(lazyComponent) { - var status = lazyComponent._status; - var result = lazyComponent._result; - switch (status) { - case Resolved: { - var Component = result; - return Component; - } - case Rejected: { - var error = result; - throw error; - } - case Pending: { - var thenable = result; - throw thenable; - } - default: { - lazyComponent._status = Pending; - var ctor = lazyComponent._ctor; - var _thenable = ctor(); - _thenable.then( - function(moduleObject) { - if (lazyComponent._status === Pending) { - var defaultExport = moduleObject.default; - { - if (defaultExport === undefined) { - warning$1( - false, - "lazy: Expected the result of a dynamic import() call. " + - "Instead received: %s\n\nYour code should look like: \n " + - "const MyComponent = lazy(() => import('./MyComponent'))", - moduleObject - ); - } - } - lazyComponent._status = Resolved; - lazyComponent._result = defaultExport; - } - }, - function(error) { - if (lazyComponent._status === Pending) { - lazyComponent._status = Rejected; - lazyComponent._result = error; - } - } + 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 ); - lazyComponent._result = _thenable; - throw _thenable; + created.return = returnFiber; + return created; } - } -} - -var ReactCurrentOwner$4 = ReactSharedInternals.ReactCurrentOwner; -function readContext$1(contextType) { - var dispatcher = ReactCurrentOwner$4.currentDispatcher; - return dispatcher.readContext(contextType); -} + 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; + } + } -var fakeInternalInstance = {}; -var isArray$1 = Array.isArray; + if (isArray(newChild) || getIteratorFn(newChild)) { + var _created3 = createFiberFromFragment( + newChild, + returnFiber.mode, + expirationTime, + null + ); + _created3.return = returnFiber; + return _created3; + } -// React.Component uses a shared frozen object by default. -// We'll use it to determine whether we need to initialize legacy refs. -var emptyRefsObject = new React.Component().refs; + throwOnInvalidObjectType(returnFiber, newChild); + } -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 didWarnAboutDirectlyAssigningPropsToState = void 0; -var didWarnAboutContextTypeAndContextTypes = void 0; -var didWarnAboutInvalidateContextType = void 0; + { + if (typeof newChild === "function") { + warnOnFunctionType(); + } + } -{ - didWarnAboutStateAssignmentForComponent = new Set(); - didWarnAboutUninitializedState = new Set(); - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set(); - didWarnAboutLegacyLifecyclesAndDerivedState = new Set(); - didWarnAboutDirectlyAssigningPropsToState = new Set(); - didWarnAboutUndefinedDerivedState = new Set(); - didWarnAboutContextTypeAndContextTypes = new Set(); - didWarnAboutInvalidateContextType = new Set(); + return null; + } - var didWarnOnInvalidCallback = new Set(); + function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { + // Update the fiber if the keys match, otherwise return null. - warnOnInvalidCallback = function(callback, callerName) { - if (callback === null || typeof callback === "function") { - return; - } - var key = callerName + "_" + callback; - if (!didWarnOnInvalidCallback.has(key)) { - didWarnOnInvalidCallback.add(key); - warningWithoutStack$1( - false, - "%s(...): Expected the last optional `callback` argument to be a " + - "function. Instead received: %s.", - callerName, - callback - ); - } - }; + var key = oldFiber !== null ? oldFiber.key : null; - warnOnUndefinedDerivedState = function(type, partialState) { - if (partialState === undefined) { - var componentName = getComponentName(type) || "Component"; - if (!didWarnAboutUndefinedDerivedState.has(componentName)) { - didWarnAboutUndefinedDerivedState.add(componentName); - warningWithoutStack$1( - false, - "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " + - "You have returned undefined.", - componentName - ); + 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; } - } - }; - - // 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)." + return updateTextNode( + returnFiber, + oldFiber, + "" + newChild, + expirationTime ); } - }); - Object.freeze(fakeInternalInstance); -} - -function applyDerivedStateFromProps( - workInProgress, - ctor, - 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); + 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; + } + } + } - { - warnOnUndefinedDerivedState(ctor, partialState); - } - // Merge the partial state and the previous state. - var memoizedState = - partialState === null || partialState === undefined - ? prevState - : Object.assign({}, prevState, partialState); - workInProgress.memoizedState = memoizedState; + if (isArray(newChild) || getIteratorFn(newChild)) { + if (key !== null) { + return null; + } - // Once the update queue is empty, persist the derived state onto the - // base state. - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null && workInProgress.expirationTime === NoWork) { - updateQueue.baseState = memoizedState; - } -} + return updateFragment( + returnFiber, + oldFiber, + newChild, + expirationTime, + null + ); + } -var classComponentUpdater = { - isMounted: isMounted, - enqueueSetState: function(inst, payload, callback) { - var fiber = get$1(inst); - var currentTime = requestCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); + throwOnInvalidObjectType(returnFiber, newChild); + } - var update = createUpdate(expirationTime); - update.payload = payload; - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "setState"); + { + if (typeof newChild === "function") { + warnOnFunctionType(); } - update.callback = callback; } - flushPassiveEffects(); - enqueueUpdate(fiber, update); - scheduleWork(fiber, expirationTime); - }, - enqueueReplaceState: function(inst, payload, callback) { - var fiber = get$1(inst); - var currentTime = requestCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); + return null; + } - var update = createUpdate(expirationTime); - update.tag = ReplaceState; - update.payload = payload; + 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 + ); + } - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "replaceState"); + 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 + ); + } } - update.callback = callback; - } - flushPassiveEffects(); - enqueueUpdate(fiber, update); - scheduleWork(fiber, expirationTime); - }, - enqueueForceUpdate: function(inst, callback) { - var fiber = get$1(inst); - var currentTime = requestCurrentTime(); - var expirationTime = computeExpirationForFiber(currentTime, fiber); + if (isArray(newChild) || getIteratorFn(newChild)) { + var _matchedFiber3 = existingChildren.get(newIdx) || null; + return updateFragment( + returnFiber, + _matchedFiber3, + newChild, + expirationTime, + null + ); + } - var update = createUpdate(expirationTime); - update.tag = ForceUpdate; + throwOnInvalidObjectType(returnFiber, newChild); + } - if (callback !== undefined && callback !== null) { - { - warnOnInvalidCallback(callback, "forceUpdate"); + { + if (typeof newChild === "function") { + warnOnFunctionType(); } - update.callback = callback; } - flushPassiveEffects(); - enqueueUpdate(fiber, update); - scheduleWork(fiber, expirationTime); + return null; } -}; - -function checkShouldComponentUpdate( - workInProgress, - ctor, - oldProps, - newProps, - oldState, - newState, - nextContext -) { - var instance = workInProgress.stateNode; - if (typeof instance.shouldComponentUpdate === "function") { - startPhaseTimer(workInProgress, "shouldComponentUpdate"); - var shouldUpdate = instance.shouldComponentUpdate( - newProps, - newState, - nextContext - ); - stopPhaseTimer(); + /** + * Warns if there is a duplicate or missing key + */ + function warnOnInvalidKey(child, knownKeys) { { - !(shouldUpdate !== undefined) - ? warningWithoutStack$1( + 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$1( false, - "%s.shouldComponentUpdate(): Returned undefined instead of a " + - "boolean value. Make sure to return true or false.", - getComponentName(ctor) || "Component" - ) - : void 0; - } - - return shouldUpdate; - } - - if (ctor.prototype && ctor.prototype.isPureReactComponent) { - return ( - !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState) - ); + "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.", + key + ); + break; + default: + break; + } + } + return knownKeys; } - return true; -} + 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 checkClassInstance(workInProgress, ctor, newProps) { - var instance = workInProgress.stateNode; - { - var name = getComponentName(ctor) || "Component"; - var renderPresent = instance.render; + // 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. - if (!renderPresent) { - if (ctor.prototype && typeof ctor.prototype.render === "function") { - warningWithoutStack$1( - false, - "%s(...): No `render` method found on the returned component " + - "instance: did you accidentally return an object from the constructor?", - name - ); + // In this first iteration, we'll just live with hitting the bad case + // (adding everything to a Map) in for every insert/move. + + // If you change this code, also update reconcileChildrenIterator() which + // uses the same algorithm. + + { + // First, validate keys. + var knownKeys = null; + for (var i = 0; i < newChildren.length; i++) { + var child = newChildren[i]; + knownKeys = warnOnInvalidKey(child, knownKeys); + } + } + + 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 { - warningWithoutStack$1( - false, - "%s(...): No `render` method found on the returned component " + - "instance: you may have forgotten to define `render`.", - name + 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; + } + + if (newIdx === newChildren.length) { + // We've reached the end of the new children. We can delete the rest. + deleteRemainingChildren(returnFiber, oldFiber); + return resultingFirstChild; + } + + if (oldFiber === null) { + // If we don't have any more existing children we can choose a fast path + // since the rest will all be insertions. + for (; newIdx < newChildren.length; newIdx++) { + var _newFiber = createChild( + returnFiber, + newChildren[newIdx], + 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; } - var noGetInitialStateOnES6 = - !instance.getInitialState || - instance.getInitialState.isReactClassApproved || - instance.state; - !noGetInitialStateOnES6 - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - false, - "propTypes was defined as an instance property on %s. Use a static " + - "property to define propTypes instead.", - name - ) - : void 0; - var noInstanceContextType = !instance.contextType; - !noInstanceContextType - ? warningWithoutStack$1( - false, - "contextType was defined as an instance property on %s. Use a static " + - "property to define contextType instead.", - name - ) - : void 0; - var noInstanceContextTypes = !instance.contextTypes; - !noInstanceContextTypes - ? warningWithoutStack$1( - false, - "contextTypes was defined as an instance property on %s. Use a static " + - "property to define contextTypes instead.", - name - ) - : void 0; + // Add all children to a key map for quick lookups. + var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - if ( - ctor.contextType && - ctor.contextTypes && - !didWarnAboutContextTypeAndContextTypes.has(ctor) - ) { - didWarnAboutContextTypeAndContextTypes.add(ctor); - warningWithoutStack$1( - false, - "%s declares both contextTypes and contextType static properties. " + - "The legacy contextTypes property will be ignored.", - name + // 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; + } } - var noComponentShouldUpdate = - typeof instance.componentShouldUpdate !== "function"; - !noComponentShouldUpdate - ? warningWithoutStack$1( - 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 ( - ctor.prototype && - ctor.prototype.isPureReactComponent && - typeof instance.shouldComponentUpdate !== "undefined" - ) { - warningWithoutStack$1( - 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(ctor) || "A pure component" - ); - } - var noComponentDidUnmount = - typeof instance.componentDidUnmount !== "function"; - !noComponentDidUnmount - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - false, - "%s has a method called " + - "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?", - name - ) - : void 0; - var noUnsafeComponentWillRecieveProps = - typeof instance.UNSAFE_componentWillRecieveProps !== "function"; - !noUnsafeComponentWillRecieveProps - ? warningWithoutStack$1( - false, - "%s has a method called " + - "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?", - name - ) - : void 0; - var hasMutatedProps = instance.props !== newProps; - !(instance.props === undefined || !hasMutatedProps) - ? warningWithoutStack$1( - 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 - ? warningWithoutStack$1( - 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(ctor) - ) { - didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor); - warningWithoutStack$1( - false, - "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " + - "This component defines getSnapshotBeforeUpdate() only.", - getComponentName(ctor) - ); + 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 noInstanceGetDerivedStateFromProps = - typeof instance.getDerivedStateFromProps !== "function"; - !noInstanceGetDerivedStateFromProps - ? warningWithoutStack$1( - 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.getDerivedStateFromError !== "function"; - !noInstanceGetDerivedStateFromCatch - ? warningWithoutStack$1( - false, - "%s: getDerivedStateFromError() is defined as an instance method " + - "and will be ignored. Instead, declare it as a static method.", - name - ) - : void 0; - var noStaticGetSnapshotBeforeUpdate = - typeof ctor.getSnapshotBeforeUpdate !== "function"; - !noStaticGetSnapshotBeforeUpdate - ? warningWithoutStack$1( - 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$1(_state))) { - warningWithoutStack$1( - false, - "%s.state: must be set to an object or null", - name - ); - } - if (typeof instance.getChildContext === "function") { - !(typeof ctor.childContextTypes === "object") - ? warningWithoutStack$1( - false, - "%s.getChildContext(): childContextTypes must be defined in order to " + - "use getChildContext().", - name - ) - : void 0; - } + return resultingFirstChild; } -} -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 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." + ); -function constructClassInstance( - workInProgress, - ctor, - props, - renderExpirationTime -) { - var isLegacyContextConsumer = false; - var unmaskedContext = emptyContextObject; - var context = null; - var contextType = ctor.contextType; - if (typeof contextType === "object" && contextType !== null) { { + // We don't support rendering Generators because it's a mutation. + // See https://github.com/facebook/react/issues/12995 if ( - contextType.$$typeof !== REACT_CONTEXT_TYPE && - !didWarnAboutInvalidateContextType.has(ctor) + typeof Symbol === "function" && + // $FlowFixMe Flow doesn't know about toStringTag + newChildrenIterable[Symbol.toStringTag] === "Generator" ) { - didWarnAboutInvalidateContextType.add(ctor); - warningWithoutStack$1( - false, - "%s defines an invalid contextType. " + - "contextType should point to the Context object returned by React.createContext(). " + - "Did you accidentally pass the Context.Provider instead?", - getComponentName(ctor) || "Component" - ); + !didWarnAboutGenerators + ? warning$1( + false, + "Using Generators as children is unsupported and will likely yield " + + "unexpected results because enumerating a generator mutates it. " + + "You may convert it to an array with `Array.from()` or the " + + "`[...spread]` operator before rendering. Keep in mind " + + "you might need to polyfill these features for older browsers." + ) + : void 0; + didWarnAboutGenerators = true; } - } - context = readContext$1(contextType); - } else { - unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); - var contextTypes = ctor.contextTypes; - isLegacyContextConsumer = - contextTypes !== null && contextTypes !== undefined; - context = isLegacyContextConsumer - ? getMaskedContext(workInProgress, unmaskedContext) - : emptyContextObject; - } + // Warn about using Maps as children + if (newChildrenIterable.entries === iteratorFn) { + !didWarnAboutMaps + ? warning$1( + false, + "Using Maps as children is unsupported and will likely yield " + + "unexpected results. Convert it to a sequence/iterable of keyed " + + "ReactElements instead." + ) + : void 0; + didWarnAboutMaps = true; + } - // Instantiate twice to help detect side-effects. - { - if ( - debugRenderPhaseSideEffects || - (debugRenderPhaseSideEffectsForStrictMode && - workInProgress.mode & StrictMode) - ) { - new ctor(props, context); // eslint-disable-line no-new + // 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 instance = new ctor(props, context); - var state = (workInProgress.memoizedState = - instance.state !== null && instance.state !== undefined - ? instance.state - : null); - adoptClassInstance(workInProgress, instance); + var newChildren = iteratorFn.call(newChildrenIterable); + invariant(newChildren != null, "An iterable object provided no iterator."); - { - if (typeof ctor.getDerivedStateFromProps === "function" && state === null) { - var componentName = getComponentName(ctor) || "Component"; - if (!didWarnAboutUninitializedState.has(componentName)) { - didWarnAboutUninitializedState.add(componentName); - warningWithoutStack$1( - false, - "`%s` uses `getDerivedStateFromProps` but its initial state is " + - "%s. This is not recommended. Instead, define the initial state by " + - "assigning an object to `this.state` in the constructor of `%s`. " + - "This ensures that `getDerivedStateFromProps` arguments have a consistent shape.", - componentName, - instance.state === null ? "null" : "undefined", - componentName - ); - } - } + var resultingFirstChild = null; + var previousNewFiber = 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 oldFiber = currentFirstChild; + var lastPlacedIndex = 0; + var newIdx = 0; + var nextOldFiber = null; + + var step = newChildren.next(); + for ( + ; + oldFiber !== null && !step.done; + newIdx++, step = newChildren.next() ) { - 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 (oldFiber.index > newIdx) { + nextOldFiber = oldFiber; + oldFiber = null; + } else { + nextOldFiber = oldFiber.sibling; } - if ( - typeof instance.componentWillUpdate === "function" && - instance.componentWillUpdate.__suppressDeprecationWarning !== true - ) { - foundWillUpdateName = "componentWillUpdate"; - } else if (typeof instance.UNSAFE_componentWillUpdate === "function") { - foundWillUpdateName = "UNSAFE_componentWillUpdate"; + 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 ( - foundWillMountName !== null || - foundWillReceivePropsName !== null || - foundWillUpdateName !== null - ) { - var _componentName = getComponentName(ctor) || "Component"; - var newApiName = - typeof ctor.getDerivedStateFromProps === "function" - ? "getDerivedStateFromProps()" - : "getSnapshotBeforeUpdate()"; - if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) { - didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName); - warningWithoutStack$1( - 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 : "" - ); + 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; } - } - - // 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 (isLegacyContextConsumer) { - cacheContext(workInProgress, unmaskedContext, context); - } - - return instance; -} -function callComponentWillMount(workInProgress, instance) { - startPhaseTimer(workInProgress, "componentWillMount"); - var oldState = instance.state; + if (step.done) { + // We've reached the end of the new children. We can delete the rest. + deleteRemainingChildren(returnFiber, oldFiber); + return resultingFirstChild; + } - if (typeof instance.componentWillMount === "function") { - instance.componentWillMount(); - } - if (typeof instance.UNSAFE_componentWillMount === "function") { - instance.UNSAFE_componentWillMount(); - } + 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; + } - stopPhaseTimer(); + // Add all children to a key map for quick lookups. + var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - if (oldState !== instance.state) { - { - warningWithoutStack$1( - false, - "%s.componentWillMount(): Assigning directly to this.state is " + - "deprecated (except inside a component's " + - "constructor). Use setState instead.", - getComponentName(workInProgress.type) || "Component" + // 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; + } } - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); - } -} - -function callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - nextContext -) { - var oldState = instance.state; - startPhaseTimer(workInProgress, "componentWillReceiveProps"); - if (typeof instance.componentWillReceiveProps === "function") { - instance.componentWillReceiveProps(newProps, nextContext); - } - if (typeof instance.UNSAFE_componentWillReceiveProps === "function") { - instance.UNSAFE_componentWillReceiveProps(newProps, nextContext); - } - stopPhaseTimer(); - if (instance.state !== oldState) { - { - var componentName = getComponentName(workInProgress.type) || "Component"; - if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { - didWarnAboutStateAssignmentForComponent.add(componentName); - warningWithoutStack$1( - false, - "%s.componentWillReceiveProps(): Assigning directly to " + - "this.state is deprecated (except inside a component's " + - "constructor). Use setState instead.", - componentName - ); - } + 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); + }); } - classComponentUpdater.enqueueReplaceState(instance, instance.state, null); - } -} -// Invokes the mount life-cycles on a previously never rendered instance. -function mountClassInstance( - workInProgress, - ctor, - newProps, - renderExpirationTime -) { - { - checkClassInstance(workInProgress, ctor, newProps); + return resultingFirstChild; } - var instance = workInProgress.stateNode; - instance.props = newProps; - instance.state = workInProgress.memoizedState; - instance.refs = emptyRefsObject; - - var contextType = ctor.contextType; - if (typeof contextType === "object" && contextType !== null) { - instance.context = readContext$1(contextType); - } else { - var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); - instance.context = getMaskedContext(workInProgress, unmaskedContext); + 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; } - { - if (instance.state === newProps) { - var componentName = getComponentName(ctor) || "Component"; - if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) { - didWarnAboutDirectlyAssigningPropsToState.add(componentName); - warningWithoutStack$1( - false, - "%s: It is not recommended to assign props directly to state " + - "because updates to props won't be reflected in state. " + - "In most cases, it is better to use props directly.", - componentName - ); + 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.elementType === 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 { + deleteChild(returnFiber, child); } + child = child.sibling; } - if (workInProgress.mode & StrictMode) { - ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( - workInProgress, - instance - ); - - ReactStrictModeWarnings.recordLegacyContextWarning( - workInProgress, - instance + if (element.type === REACT_FRAGMENT_TYPE) { + var created = createFiberFromFragment( + element.props.children, + returnFiber.mode, + expirationTime, + element.key ); - } - - if (warnAboutDeprecatedLifecycles) { - ReactStrictModeWarnings.recordDeprecationWarnings( - workInProgress, - instance + created.return = returnFiber; + return created; + } else { + var _created4 = createFiberFromElement( + element, + returnFiber.mode, + expirationTime ); + _created4.ref = coerceRef(returnFiber, currentFirstChild, element); + _created4.return = returnFiber; + return _created4; } } - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime - ); - instance.state = workInProgress.memoizedState; - } + 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; + } + } else { + deleteChild(returnFiber, child); + } + child = child.sibling; + } - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - newProps + var created = createFiberFromPortal( + portal, + returnFiber.mode, + expirationTime ); - instance.state = workInProgress.memoizedState; + created.return = returnFiber; + return created; } - // 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") + // 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 ) { - 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, - newProps, - instance, - renderExpirationTime - ); - instance.state = workInProgress.memoizedState; - } - } + // 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. - if (typeof instance.componentDidMount === "function") { - workInProgress.effectTag |= Update; - } -} + // 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 resumeMountClassInstance( - workInProgress, - ctor, - newProps, - renderExpirationTime -) { - var instance = workInProgress.stateNode; + // Handle object types + var isObject = typeof newChild === "object" && newChild !== null; - var oldProps = workInProgress.memoizedProps; - instance.props = oldProps; + 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 + ) + ); + } + } - var oldContext = instance.context; - var contextType = ctor.contextType; - var nextContext = void 0; - if (typeof contextType === "object" && contextType !== null) { - nextContext = readContext$1(contextType); - } else { - var nextLegacyUnmaskedContext = getUnmaskedContext( - workInProgress, - ctor, - true - ); - nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext); - } - - 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 !== nextContext) { - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - nextContext + if (typeof newChild === "string" || typeof newChild === "number") { + return placeSingleChild( + reconcileSingleTextNode( + returnFiber, + currentFirstChild, + "" + newChild, + expirationTime + ) ); } - } - - 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.componentDidMount === "function") { - workInProgress.effectTag |= Update; + if (isArray(newChild)) { + return reconcileChildrenArray( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); } - return false; - } - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - newProps - ); - newState = workInProgress.memoizedState; - } + if (getIteratorFn(newChild)) { + return reconcileChildrenIterator( + returnFiber, + currentFirstChild, + newChild, + expirationTime + ); + } - var shouldUpdate = - checkHasForceUpdateAfterProcessing() || - checkShouldComponentUpdate( - workInProgress, - ctor, - oldProps, - newProps, - oldState, - newState, - nextContext - ); + if (isObject) { + throwOnInvalidObjectType(returnFiber, newChild); + } - 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(); + { + if (typeof newChild === "function") { + warnOnFunctionType(); } - 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 (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 FunctionComponent: { + 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 shouldComponentUpdate returned false, we should still update the - // memoized state to indicate that this work can be reused. - workInProgress.memoizedProps = newProps; - workInProgress.memoizedState = newState; + // Remaining cases are all treated as empty. + return deleteRemainingChildren(returnFiber, currentFirstChild); } - // Update the existing instance's state, props, and context pointers even - // if shouldComponentUpdate returns false. - instance.props = newProps; - instance.state = newState; - instance.context = nextContext; - - return shouldUpdate; + return reconcileChildFibers; } -// Invokes the update life-cycles and returns false if it shouldn't rerender. -function updateClassInstance( - current, - workInProgress, - ctor, - newProps, - renderExpirationTime -) { - var instance = workInProgress.stateNode; - - var oldProps = workInProgress.memoizedProps; - instance.props = - workInProgress.type === workInProgress.elementType - ? oldProps - : resolveDefaultProps(workInProgress.type, oldProps); - - var oldContext = instance.context; - var contextType = ctor.contextType; - var nextContext = void 0; - if (typeof contextType === "object" && contextType !== null) { - nextContext = readContext$1(contextType); - } else { - var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true); - nextContext = getMaskedContext(workInProgress, nextUnmaskedContext); - } - - var getDerivedStateFromProps = ctor.getDerivedStateFromProps; - var hasNewLifecycles = - typeof getDerivedStateFromProps === "function" || - typeof instance.getSnapshotBeforeUpdate === "function"; +var reconcileChildFibers = ChildReconciler(true); +var mountChildFibers = ChildReconciler(false); - // 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. +function cloneChildFibers(current$$1, workInProgress) { + invariant( + current$$1 === null || workInProgress.child === current$$1.child, + "Resuming work not yet implemented." + ); - // 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 !== nextContext) { - callComponentWillReceiveProps( - workInProgress, - instance, - newProps, - nextContext - ); - } + if (workInProgress.child === null) { + return; } - resetHasForceUpdateBeforeProcessing(); + var currentChild = workInProgress.child; + var newChild = createWorkInProgress( + currentChild, + currentChild.pendingProps, + currentChild.expirationTime + ); + workInProgress.child = newChild; - var oldState = workInProgress.memoizedState; - var newState = (instance.state = oldState); - var updateQueue = workInProgress.updateQueue; - if (updateQueue !== null) { - processUpdateQueue( - workInProgress, - updateQueue, - newProps, - instance, - renderExpirationTime + newChild.return = workInProgress; + while (currentChild.sibling !== null) { + currentChild = currentChild.sibling; + newChild = newChild.sibling = createWorkInProgress( + currentChild, + currentChild.pendingProps, + currentChild.expirationTime ); - newState = workInProgress.memoizedState; + newChild.return = workInProgress; } + newChild.sibling = null; +} - 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; - } - } - return false; - } +var NO_CONTEXT = {}; - if (typeof getDerivedStateFromProps === "function") { - applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - newProps - ); - newState = workInProgress.memoizedState; - } +var contextStackCursor$1 = createCursor(NO_CONTEXT); +var contextFiberStackCursor = createCursor(NO_CONTEXT); +var rootInstanceStackCursor = createCursor(NO_CONTEXT); - var shouldUpdate = - checkHasForceUpdateAfterProcessing() || - checkShouldComponentUpdate( - workInProgress, - ctor, - oldProps, - newProps, - oldState, - newState, - nextContext - ); +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; +} - 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, nextContext); - } - if (typeof instance.UNSAFE_componentWillUpdate === "function") { - instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext); - } - 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 getRootHostContainer() { + var rootInstance = requiredContext(rootInstanceStackCursor.current); + return rootInstance; +} - // 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 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); - // Update the existing instance's state, props, and context pointers even - // if shouldComponentUpdate returns false. - instance.props = newProps; - instance.state = newState; - instance.context = nextContext; + // 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); +} - return shouldUpdate; +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); } -var didWarnAboutMaps = void 0; -var didWarnAboutGenerators = void 0; -var didWarnAboutStringRefInStrictMode = void 0; -var ownerHasKeyUseWarning = void 0; -var ownerHasFunctionTypeWarning = void 0; -var warnForMissingKey = function(child) {}; +function getHostContext() { + var context = requiredContext(contextStackCursor$1.current); + return context; +} -{ - didWarnAboutMaps = false; - didWarnAboutGenerators = false; - didWarnAboutStringRefInStrictMode = {}; +function pushHostContext(fiber) { + var rootInstance = requiredContext(rootInstanceStackCursor.current); + var context = requiredContext(contextStackCursor$1.current); + var nextContext = getChildHostContext(context, fiber.type, rootInstance); - /** - * 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 = {}; + // Don't push this Fiber's context unless it's unique. + if (context === nextContext) { + return; + } - 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; + // 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); +} - 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." + - getCurrentFiberStackInDev(); - if (ownerHasKeyUseWarning[currentComponentErrorInfo]) { - return; - } - ownerHasKeyUseWarning[currentComponentErrorInfo] = true; +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; + } - warning$1( - false, - "Each child in an array or iterator should have a unique " + - '"key" prop. See https://fb.me/react-warning-keys for ' + - "more information." - ); - }; + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); } -var isArray = Array.isArray; +var NoEffect$1 = /* */ 0; +var UnmountSnapshot = /* */ 2; +var UnmountMutation = /* */ 4; +var MountMutation = /* */ 8; +var UnmountLayout = /* */ 16; +var MountLayout = /* */ 32; +var MountPassive = /* */ 64; +var UnmountPassive = /* */ 128; -function coerceRef(returnFiber, current$$1, element) { - var mixedRef = element.ref; - if ( - mixedRef !== null && - typeof mixedRef !== "function" && - typeof mixedRef !== "object" - ) { - { - if (returnFiber.mode & StrictMode) { - var componentName = getComponentName(returnFiber.type) || "Component"; - if (!didWarnAboutStringRefInStrictMode[componentName]) { - warningWithoutStack$1( - 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, - getStackByFiberInDevAndProd(returnFiber) - ); - didWarnAboutStringRefInStrictMode[componentName] = true; - } - } - } +var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher; - if (element._owner) { - var owner = element._owner; - var inst = void 0; - if (owner) { - var ownerFiber = owner; - invariant( - ownerFiber.tag === ClassComponent, - "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$$1 !== null && - current$$1.ref !== null && - typeof current$$1.ref === "function" && - current$$1.ref._stringRef === stringRef - ) { - return current$$1.ref; - } - var ref = function(value) { - var refs = inst.refs; - if (refs === emptyRefsObject) { - // This is a lazy pooled frozen object, so we need to initialize. - 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, a string, an object returned by React.createRef(), or null." - ); - 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 function component\n" + - "2. You may be adding a ref to a component that was not created inside a component's render method\n" + - "3. You have multiple copies of React loaded\n" + - "See https://fb.me/react-refs-must-have-owner for more information.", - mixedRef - ); - } - } - return mixedRef; +var didWarnAboutMismatchedHooksForComponent = void 0; +{ + didWarnAboutMismatchedHooksForComponent = new Set(); } -function throwOnInvalidObjectType(returnFiber, newChild) { - if (returnFiber.type !== "textarea") { - var addendum = ""; - { - addendum = - " If you meant to render a collection of children, use an array " + - "instead." + - getCurrentFiberStackInDev(); - } - 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 - ); - } -} +// These are set right before calling the component. +var renderExpirationTime = NoWork; +// The work-in-progress fiber. I've named it differently to distinguish it from +// the work-in-progress hook. +var currentlyRenderingFiber$1 = 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." + - getCurrentFiberStackInDev(); +// Hooks are stored as a linked list on the fiber's memoizedState field. The +// current hook list is the list that belongs to the current fiber. The +// work-in-progress hook list is a new list that will be added to the +// work-in-progress fiber. +var firstCurrentHook = null; +var currentHook = null; +var nextCurrentHook = null; +var firstWorkInProgressHook = null; +var workInProgressHook = null; +var nextWorkInProgressHook = null; - if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) { - return; +var remainingExpirationTime = NoWork; +var componentUpdateQueue = null; +var sideEffectTag = 0; + +// Updates scheduled during render will trigger an immediate re-render at the +// end of the current pass. We can't store these updates on the normal queue, +// because if the work is aborted, they should be discarded. Because this is +// a relatively rare case, we also don't want to add an additional field to +// either the hook or queue object types. So we store them in a lazily create +// map of queue -> render-phase updates, which are discarded once the component +// completes without re-rendering. + +// Whether an update was scheduled during the currently executing render pass. +var didScheduleRenderPhaseUpdate = false; +// Lazily created map of render-phase updates +var renderPhaseUpdates = null; +// Counter to prevent infinite loops. +var numberOfReRenders = 0; +var RE_RENDER_LIMIT = 25; + +// In DEV, this is the name of the currently executing primitive hook +var currentHookNameInDev = null; + +function warnOnHookMismatchInDev() { + { + var componentName = getComponentName(currentlyRenderingFiber$1.type); + if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) { + didWarnAboutMismatchedHooksForComponent.add(componentName); + + var secondColumnStart = 22; + + var table = ""; + var prevHook = firstCurrentHook; + var nextHook = firstWorkInProgressHook; + var n = 1; + while (prevHook !== null && nextHook !== null) { + var oldHookName = prevHook._debugType; + var newHookName = nextHook._debugType; + + var row = n + ". " + oldHookName; + + // Extra space so second column lines up + // lol @ IE not supporting String#repeat + while (row.length < secondColumnStart) { + row += " "; + } + + row += newHookName + "\n"; + + table += row; + prevHook = prevHook.next; + nextHook = nextHook.next; + n++; + } + + warning$1( + false, + "React has detected a change in the order of Hooks called by %s. " + + "This will lead to bugs and errors if not fixed. " + + "For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n" + + " Previous render Next render\n" + + " -------------------------------\n" + + "%s" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + componentName, + table + ); + } } - ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true; +} - warning$1( +function throwInvalidHookError() { + invariant( 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." + "Hooks can only be called inside the body of a function component. " + + "(https://fb.me/react-invalid-hook-call)" ); } -// 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; +function areHookInputsEqual(nextDeps, prevDeps) { + if (prevDeps === null) { + { + warning$1( + false, + "%s received a final argument during this render, but not during " + + "the previous render. Even though the final argument is optional, " + + "its type cannot change between renders.", + currentHookNameInDev + ); } - childToDelete.nextEffect = null; - childToDelete.effectTag = Deletion; + return false; } - function deleteRemainingChildren(returnFiber, currentFirstChild) { - if (!shouldTrackSideEffects) { - // Noop. - return null; + { + // Don't bother comparing lengths in prod because these arrays should be + // passed inline. + if (nextDeps.length !== prevDeps.length) { + warning$1( + false, + "The final argument passed to %s changed size between renders. The " + + "order and size of this array must remain constant.\n\n" + + "Previous: %s\n" + + "Incoming: %s", + currentHookNameInDev, + "[" + nextDeps.join(", ") + "]", + "[" + prevDeps.join(", ") + "]" + ); } - - // 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; + } + for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) { + if (is(nextDeps[i], prevDeps[i])) { + continue; } - return null; + return false; } + return true; +} - 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(); +function renderWithHooks( + current, + workInProgress, + Component, + props, + refOrContext, + nextRenderExpirationTime +) { + renderExpirationTime = nextRenderExpirationTime; + currentlyRenderingFiber$1 = workInProgress; + firstCurrentHook = nextCurrentHook = + current !== null ? current.memoizedState : null; - var existingChild = currentFirstChild; - while (existingChild !== null) { - if (existingChild.key !== null) { - existingChildren.set(existingChild.key, existingChild); - } else { - existingChildren.set(existingChild.index, existingChild); - } - existingChild = existingChild.sibling; - } - return existingChildren; - } + // The following should have already been reset + // currentHook = null; + // workInProgressHook = null; - 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; + // remainingExpirationTime = NoWork; + // componentUpdateQueue = null; + + // didScheduleRenderPhaseUpdate = false; + // renderPhaseUpdates = null; + // numberOfReRenders = 0; + // sideEffectTag = 0; + + { + ReactCurrentDispatcher$1.current = + nextCurrentHook === null + ? HooksDispatcherOnMountInDEV + : HooksDispatcherOnUpdateInDEV; } - function placeChild(newFiber, lastPlacedIndex, newIndex) { - newFiber.index = newIndex; - if (!shouldTrackSideEffects) { - // Noop. - return lastPlacedIndex; - } - var current$$1 = newFiber.alternate; - if (current$$1 !== null) { - var oldIndex = current$$1.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; - } + var children = Component(props, refOrContext); + + if (didScheduleRenderPhaseUpdate) { + do { + didScheduleRenderPhaseUpdate = false; + numberOfReRenders += 1; + + // Start over from the beginning of the list + firstCurrentHook = nextCurrentHook = + current !== null ? current.memoizedState : null; + nextWorkInProgressHook = firstWorkInProgressHook; + + currentHook = null; + workInProgressHook = null; + componentUpdateQueue = null; + + ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV; + + children = Component(props, refOrContext); + } while (didScheduleRenderPhaseUpdate); + + renderPhaseUpdates = null; + numberOfReRenders = 0; } - 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; + { + currentHookNameInDev = null; } - function updateTextNode( - returnFiber, - current$$1, - textContent, - expirationTime - ) { - if (current$$1 === null || current$$1.tag !== HostText) { - // Insert - var created = createFiberFromText( - textContent, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current$$1, textContent, expirationTime); - existing.return = returnFiber; - return existing; - } + // We can assume the previous dispatcher is always this one, since we set it + // at the beginning of the render phase and there's no re-entrancy. + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + + var renderedWork = currentlyRenderingFiber$1; + + renderedWork.memoizedState = firstWorkInProgressHook; + renderedWork.expirationTime = remainingExpirationTime; + renderedWork.updateQueue = componentUpdateQueue; + renderedWork.effectTag |= sideEffectTag; + + var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null; + + renderExpirationTime = NoWork; + currentlyRenderingFiber$1 = null; + + firstCurrentHook = null; + currentHook = null; + nextCurrentHook = null; + firstWorkInProgressHook = null; + workInProgressHook = null; + nextWorkInProgressHook = null; + + remainingExpirationTime = NoWork; + componentUpdateQueue = null; + sideEffectTag = 0; + + // These were reset above + // didScheduleRenderPhaseUpdate = false; + // renderPhaseUpdates = null; + // numberOfReRenders = 0; + + invariant( + !didRenderTooFewHooks, + "Rendered fewer hooks than expected. This may be caused by an accidental " + + "early return statement." + ); + + return children; +} + +function bailoutHooks(current, workInProgress, expirationTime) { + workInProgress.updateQueue = current.updateQueue; + workInProgress.effectTag &= ~(Passive | Update); + if (current.expirationTime <= expirationTime) { + current.expirationTime = NoWork; } +} - function updateElement(returnFiber, current$$1, element, expirationTime) { - if (current$$1 !== null && current$$1.elementType === element.type) { - // Move based on index - var existing = useFiber(current$$1, element.props, expirationTime); - existing.ref = coerceRef(returnFiber, current$$1, 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$$1, element); - created.return = returnFiber; - return created; - } +function resetHooks() { + // We can assume the previous dispatcher is always this one, since we set it + // at the beginning of the render phase and there's no re-entrancy. + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + + // This is used to reset the state of this module when a component throws. + // It's also called inside mountIndeterminateComponent if we determine the + // component is a module-style component. + renderExpirationTime = NoWork; + currentlyRenderingFiber$1 = null; + + firstCurrentHook = null; + currentHook = null; + nextCurrentHook = null; + firstWorkInProgressHook = null; + workInProgressHook = null; + nextWorkInProgressHook = null; + + remainingExpirationTime = NoWork; + componentUpdateQueue = null; + sideEffectTag = 0; + + { + currentHookNameInDev = null; } - function updatePortal(returnFiber, current$$1, portal, expirationTime) { + didScheduleRenderPhaseUpdate = false; + renderPhaseUpdates = null; + numberOfReRenders = 0; +} + +function mountWorkInProgressHook() { + var hook = { + memoizedState: null, + + baseState: null, + queue: null, + baseUpdate: null, + + next: null + }; + + { + hook._debugType = currentHookNameInDev; if ( - current$$1 === null || - current$$1.tag !== HostPortal || - current$$1.stateNode.containerInfo !== portal.containerInfo || - current$$1.stateNode.implementation !== portal.implementation + currentlyRenderingFiber$1 !== null && + currentlyRenderingFiber$1.alternate !== null ) { - // Insert - var created = createFiberFromPortal( - portal, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber( - current$$1, - portal.children || [], - expirationTime + warning$1( + false, + "%s: Rendered more hooks than during the previous render. This is " + + "not currently supported and may lead to unexpected behavior.", + getComponentName(currentlyRenderingFiber$1.type) ); - existing.return = returnFiber; - return existing; } } - - function updateFragment( - returnFiber, - current$$1, - fragment, - expirationTime, - key - ) { - if (current$$1 === null || current$$1.tag !== Fragment) { - // Insert - var created = createFiberFromFragment( - fragment, - returnFiber.mode, - expirationTime, - key - ); - created.return = returnFiber; - return created; - } else { - // Update - var existing = useFiber(current$$1, fragment, expirationTime); - existing.return = returnFiber; - return existing; - } + if (workInProgressHook === null) { + // This is the first hook in the list + firstWorkInProgressHook = workInProgressHook = hook; + } else { + // Append to the end of the list + workInProgressHook = workInProgressHook.next = hook; } + return workInProgressHook; +} - 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; - } +function updateWorkInProgressHook() { + // This function is used both for updates and for re-renders triggered by a + // render phase update. It assumes there is either a current hook we can + // clone, or a work-in-progress hook from a previous render pass that we can + // use as a base. When we reach the end of the base list, we must switch to + // the dispatcher used for mounts. + if (nextWorkInProgressHook !== null) { + // There's already a work-in-progress. Reuse it. + workInProgressHook = nextWorkInProgressHook; + nextWorkInProgressHook = workInProgressHook.next; - 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; - } - } + currentHook = nextCurrentHook; + nextCurrentHook = currentHook !== null ? currentHook.next : null; + } else { + // Clone from the current hook. + invariant( + nextCurrentHook !== null, + "Rendered more hooks than during the previous render." + ); + currentHook = nextCurrentHook; - if (isArray(newChild) || getIteratorFn(newChild)) { - var _created3 = createFiberFromFragment( - newChild, - returnFiber.mode, - expirationTime, - null - ); - _created3.return = returnFiber; - return _created3; - } + var newHook = { + memoizedState: currentHook.memoizedState, - throwOnInvalidObjectType(returnFiber, newChild); + baseState: currentHook.baseState, + queue: currentHook.queue, + baseUpdate: currentHook.baseUpdate, + + next: null + }; + + if (workInProgressHook === null) { + // This is the first hook in the list. + workInProgressHook = firstWorkInProgressHook = newHook; + } else { + // Append to the end of the list. + workInProgressHook = workInProgressHook.next = newHook; } + nextCurrentHook = currentHook.next; { - if (typeof newChild === "function") { - warnOnFunctionType(); + newHook._debugType = currentHookNameInDev; + if (currentHookNameInDev !== currentHook._debugType) { + warnOnHookMismatchInDev(); } } - - return null; } + return workInProgressHook; +} - function updateSlot(returnFiber, oldFiber, newChild, expirationTime) { - // Update the fiber if the keys match, otherwise return null. +function createFunctionComponentUpdateQueue() { + return { + lastEffect: null + }; +} - var key = oldFiber !== null ? oldFiber.key : null; +function basicStateReducer(state, action) { + return typeof action === "function" ? action(state) : action; +} - 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 - ); - } +function mountContext(context, observedBits) { + { + mountWorkInProgressHook(); + } + return readContext(context, observedBits); +} - 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; - } - } - } +function updateContext(context, observedBits) { + { + updateWorkInProgressHook(); + } + return readContext(context, observedBits); +} - if (isArray(newChild) || getIteratorFn(newChild)) { - if (key !== null) { - return null; +function mountReducer(reducer, initialArg, init) { + var hook = mountWorkInProgressHook(); + var initialState = void 0; + if (init !== undefined) { + initialState = init(initialArg); + } else { + initialState = initialArg; + } + hook.memoizedState = hook.baseState = initialState; + var queue = (hook.queue = { + last: null, + dispatch: null, + eagerReducer: reducer, + eagerState: initialState + }); + var dispatch = (queue.dispatch = dispatchAction.bind( + null, + // Flow doesn't know this is non-null, but we do. + currentlyRenderingFiber$1, + queue + )); + return [hook.memoizedState, dispatch]; +} + +function updateReducer(reducer, initialArg, init) { + var hook = updateWorkInProgressHook(); + var queue = hook.queue; + invariant( + queue !== null, + "Should have a queue. This is likely a bug in React. Please file an issue." + ); + + if (numberOfReRenders > 0) { + // This is a re-render. Apply the new render phase updates to the previous + var _dispatch = queue.dispatch; + if (renderPhaseUpdates !== null) { + // Render phase updates are stored in a map of queue -> linked list + var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); + if (firstRenderPhaseUpdate !== undefined) { + renderPhaseUpdates.delete(queue); + var newState = hook.memoizedState; + var update = firstRenderPhaseUpdate; + do { + // Process this render phase update. We don't have to check the + // priority because it will always be the same as the current + // render's. + var _action = update.action; + newState = reducer(newState, _action); + update = update.next; + } while (update !== null); + + // Mark that the fiber performed work, but only if the new state is + // different from the current state. + if (!is(newState, hook.memoizedState)) { + markWorkInProgressReceivedUpdate(); } - return updateFragment( - returnFiber, - oldFiber, - newChild, - expirationTime, - null - ); - } + hook.memoizedState = newState; - throwOnInvalidObjectType(returnFiber, newChild); - } + // Don't persist the state accumlated from the render phase updates to + // the base state unless the queue is empty. + // TODO: Not sure if this is the desired semantics, but it's what we + // do for gDSFP. I can't remember why. + if (hook.baseUpdate === queue.last) { + hook.baseState = newState; + } - { - if (typeof newChild === "function") { - warnOnFunctionType(); + return [newState, _dispatch]; } } - - return null; + return [hook.memoizedState, _dispatch]; } - 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 - ); - } + // The last update in the entire queue + var last = queue.last; + // The last update that is part of the base state. + var baseUpdate = hook.baseUpdate; + var baseState = hook.baseState; - 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 - ); + // Find the first unprocessed update. + var first = void 0; + if (baseUpdate !== null) { + if (last !== null) { + // For the first update, the queue is a circular linked list where + // `queue.last.next = queue.first`. Once the first update commits, and + // the `baseUpdate` is no longer empty, we can unravel the list. + last.next = null; + } + first = baseUpdate.next; + } else { + first = last !== null ? last.next : null; + } + if (first !== null) { + var _newState = baseState; + var newBaseState = null; + var newBaseUpdate = null; + var prevUpdate = baseUpdate; + var _update = first; + var didSkip = false; + do { + var updateExpirationTime = _update.expirationTime; + if (updateExpirationTime < renderExpirationTime) { + // Priority is insufficient. Skip this update. If this is the first + // skipped update, the previous update/state is the new base + // update/state. + if (!didSkip) { + didSkip = true; + newBaseUpdate = prevUpdate; + newBaseState = _newState; } - case REACT_PORTAL_TYPE: { - var _matchedFiber2 = - existingChildren.get( - newChild.key === null ? newIdx : newChild.key - ) || null; - return updatePortal( - returnFiber, - _matchedFiber2, - newChild, - expirationTime - ); + // Update the remaining priority in the queue. + if (updateExpirationTime > remainingExpirationTime) { + remainingExpirationTime = updateExpirationTime; + } + } else { + // Process this update. + if (_update.eagerReducer === reducer) { + // If this update was processed eagerly, and its reducer matches the + // current reducer, we can use the eagerly computed state. + _newState = _update.eagerState; + } else { + var _action2 = _update.action; + _newState = reducer(_newState, _action2); } } + prevUpdate = _update; + _update = _update.next; + } while (_update !== null && _update !== first); - if (isArray(newChild) || getIteratorFn(newChild)) { - var _matchedFiber3 = existingChildren.get(newIdx) || null; - return updateFragment( - returnFiber, - _matchedFiber3, - newChild, - expirationTime, - null - ); - } - - throwOnInvalidObjectType(returnFiber, newChild); + if (!didSkip) { + newBaseUpdate = prevUpdate; + newBaseState = _newState; } - { - if (typeof newChild === "function") { - warnOnFunctionType(); - } + // Mark that the fiber performed work, but only if the new state is + // different from the current state. + if (!is(_newState, hook.memoizedState)) { + markWorkInProgressReceivedUpdate(); } - return null; + hook.memoizedState = _newState; + hook.baseUpdate = newBaseUpdate; + hook.baseState = newBaseState; + + queue.eagerReducer = reducer; + queue.eagerState = _newState; } - /** - * 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$1( - 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.", - key - ); - break; - default: - break; - } + var dispatch = queue.dispatch; + return [hook.memoizedState, dispatch]; +} + +function mountState(initialState) { + var hook = mountWorkInProgressHook(); + if (typeof initialState === "function") { + initialState = initialState(); + } + hook.memoizedState = hook.baseState = initialState; + var queue = (hook.queue = { + last: null, + dispatch: null, + eagerReducer: basicStateReducer, + eagerState: initialState + }); + var dispatch = (queue.dispatch = dispatchAction.bind( + null, + // Flow doesn't know this is non-null, but we do. + currentlyRenderingFiber$1, + queue + )); + return [hook.memoizedState, dispatch]; +} + +function updateState(initialState) { + return updateReducer(basicStateReducer, initialState); +} + +function pushEffect(tag, create, destroy, deps) { + var effect = { + tag: tag, + create: create, + destroy: destroy, + deps: deps, + // Circular + next: null + }; + if (componentUpdateQueue === null) { + componentUpdateQueue = createFunctionComponentUpdateQueue(); + componentUpdateQueue.lastEffect = effect.next = effect; + } else { + var _lastEffect = componentUpdateQueue.lastEffect; + if (_lastEffect === null) { + componentUpdateQueue.lastEffect = effect.next = effect; + } else { + var firstEffect = _lastEffect.next; + _lastEffect.next = effect; + effect.next = firstEffect; + componentUpdateQueue.lastEffect = effect; } - return knownKeys; } + return effect; +} - 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 mountRef(initialValue) { + var hook = mountWorkInProgressHook(); + var ref = { current: initialValue }; + { + Object.seal(ref); + } + hook.memoizedState = ref; + return ref; +} - // 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. +function updateRef(initialValue) { + var hook = updateWorkInProgressHook(); + return hook.memoizedState; +} - // In this first iteration, we'll just live with hitting the bad case - // (adding everything to a Map) in for every insert/move. +function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = mountWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps); +} - // If you change this code, also update reconcileChildrenIterator() which - // uses the same algorithm. +function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = updateWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + var destroy = undefined; - { - // First, validate keys. - var knownKeys = null; - for (var i = 0; i < newChildren.length; i++) { - var child = newChildren[i]; - knownKeys = warnOnInvalidKey(child, knownKeys); + if (currentHook !== null) { + var prevEffect = currentHook.memoizedState; + destroy = prevEffect.destroy; + if (nextDeps !== null) { + var prevDeps = prevEffect.deps; + if (areHookInputsEqual(nextDeps, prevDeps)) { + pushEffect(NoEffect$1, create, destroy, nextDeps); + return; } } + } - var resultingFirstChild = null; - var previousNewFiber = null; + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps); +} - 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; - } +function mountEffect(create, deps) { + return mountEffectImpl( + Update | Passive, + UnmountPassive | MountPassive, + create, + deps + ); +} - if (newIdx === newChildren.length) { - // We've reached the end of the new children. We can delete the rest. - deleteRemainingChildren(returnFiber, oldFiber); - return resultingFirstChild; - } +function updateEffect(create, deps) { + return updateEffectImpl( + Update | Passive, + UnmountPassive | MountPassive, + create, + deps + ); +} - 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 mountLayoutEffect(create, deps) { + return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps); +} - // Add all children to a key map for quick lookups. - var existingChildren = mapRemainingChildren(returnFiber, oldFiber); +function updateLayoutEffect(create, deps) { + return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps); +} - // 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; - } +function imperativeHandleEffect(create, ref) { + if (typeof ref === "function") { + var refCallback = ref; + var _inst = create(); + refCallback(_inst); + return function() { + refCallback(null); + }; + } else if (ref !== null && ref !== undefined) { + var refObject = ref; + { + !refObject.hasOwnProperty("current") + ? warning$1( + false, + "Expected useImperativeHandle() first argument to either be a " + + "ref callback or React.createRef() object. Instead received: %s.", + "an object with keys {" + Object.keys(refObject).join(", ") + "}" + ) + : void 0; } + var _inst2 = create(); + refObject.current = _inst2; + return function() { + refObject.current = null; + }; + } +} - 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 mountImperativeHandle(ref, create, deps) { + { + !(typeof create === "function") + ? warning$1( + false, + "Expected useImperativeHandle() second argument to be a function " + + "that creates a handle. Instead received: %s.", + create !== null ? typeof create : "null" + ) + : void 0; + } - return resultingFirstChild; + // TODO: If deps are provided, should we skip comparing the ref itself? + var effectDeps = + deps !== null && deps !== undefined ? deps.concat([ref]) : [ref]; + + return mountEffectImpl( + Update, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + effectDeps + ); +} + +function updateImperativeHandle(ref, create, deps) { + { + !(typeof create === "function") + ? warning$1( + false, + "Expected useImperativeHandle() second argument to be a function " + + "that creates a handle. Instead received: %s.", + create !== null ? typeof create : "null" + ) + : void 0; } - function reconcileChildrenIterator( - returnFiber, - currentFirstChild, - newChildrenIterable, - expirationTime - ) { - // This is the same implementation as reconcileChildrenArray(), - // but using the iterator instead. + // TODO: If deps are provided, should we skip comparing the ref itself? + var effectDeps = + deps !== null && deps !== undefined ? deps.concat([ref]) : [ref]; - 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." - ); + return updateEffectImpl( + Update, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + effectDeps + ); +} - { - // We don't support rendering Generators because it's a mutation. - // See https://github.com/facebook/react/issues/12995 - if ( - typeof Symbol === "function" && - // $FlowFixMe Flow doesn't know about toStringTag - newChildrenIterable[Symbol.toStringTag] === "Generator" - ) { - !didWarnAboutGenerators - ? warning$1( - false, - "Using Generators as children is unsupported and will likely yield " + - "unexpected results because enumerating a generator mutates it. " + - "You may convert it to an array with `Array.from()` or the " + - "`[...spread]` operator before rendering. Keep in mind " + - "you might need to polyfill these features for older browsers." - ) - : void 0; - didWarnAboutGenerators = true; - } +function mountDebugValue(value, formatterFn) { + // This hook is normally a no-op. + // The react-debug-hooks package injects its own implementation + // so that e.g. DevTools can display custom hook values. +} - // Warn about using Maps as children - if (newChildrenIterable.entries === iteratorFn) { - !didWarnAboutMaps - ? warning$1( - false, - "Using Maps as children is unsupported and will likely yield " + - "unexpected results. Convert it to a sequence/iterable of keyed " + - "ReactElements instead." - ) - : void 0; - didWarnAboutMaps = true; +var updateDebugValue = mountDebugValue; + +function mountCallback(callback, deps) { + var hook = mountWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + hook.memoizedState = [callback, nextDeps]; + return callback; +} + +function updateCallback(callback, deps) { + var hook = updateWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + var prevState = hook.memoizedState; + if (prevState !== null) { + if (nextDeps !== null) { + var prevDeps = prevState[1]; + if (areHookInputsEqual(nextDeps, prevDeps)) { + return prevState[0]; } + } + } + hook.memoizedState = [callback, nextDeps]; + return callback; +} - // 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 mountMemo(nextCreate, deps) { + var hook = mountWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + var nextValue = nextCreate(); + hook.memoizedState = [nextValue, nextDeps]; + return nextValue; +} + +function updateMemo(nextCreate, deps) { + var hook = updateWorkInProgressHook(); + var nextDeps = deps === undefined ? null : deps; + var prevState = hook.memoizedState; + if (prevState !== null) { + // Assume these are defined. If they're not, areHookInputsEqual will warn. + if (nextDeps !== null) { + var prevDeps = prevState[1]; + if (areHookInputsEqual(nextDeps, prevDeps)) { + return prevState[0]; } } + } + var nextValue = nextCreate(); + hook.memoizedState = [nextValue, nextDeps]; + return nextValue; +} - var newChildren = iteratorFn.call(newChildrenIterable); - invariant(newChildren != null, "An iterable object provided no iterator."); +// in a test-like environment, we want to warn if dispatchAction() +// is called outside of a batchedUpdates/TestUtils.act(...) call. +var shouldWarnForUnbatchedSetState = false; - var resultingFirstChild = null; - var previousNewFiber = null; +{ + // jest isnt' a 'global', it's just exposed to tests via a wrapped function + // further, this isn't a test file, so flow doesn't recognize the symbol. So... + // $FlowExpectedError - because requirements don't give a damn about your type sigs. + if ("undefined" !== typeof jest) { + shouldWarnForUnbatchedSetState = true; + } +} - var oldFiber = currentFirstChild; - var lastPlacedIndex = 0; - var newIdx = 0; - var nextOldFiber = null; +function dispatchAction(fiber, queue, action) { + invariant( + numberOfReRenders < RE_RENDER_LIMIT, + "Too many re-renders. React limits the number of renders to prevent " + + "an infinite loop." + ); - 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; + { + !(arguments.length <= 3) + ? warning$1( + false, + "State updates from the useState() and useReducer() Hooks don't support the " + + "second callback argument. To execute a side effect after " + + "rendering, declare it in the component body with useEffect()." + ) + : void 0; + } + + var alternate = fiber.alternate; + if ( + fiber === currentlyRenderingFiber$1 || + (alternate !== null && alternate === currentlyRenderingFiber$1) + ) { + // This is a render phase update. Stash it in a lazily-created map of + // queue -> linked list of updates. After this render pass, we'll restart + // and apply the stashed updates on top of the work-in-progress hook. + didScheduleRenderPhaseUpdate = true; + var update = { + expirationTime: renderExpirationTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }; + if (renderPhaseUpdates === null) { + renderPhaseUpdates = new Map(); + } + var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); + if (firstRenderPhaseUpdate === undefined) { + renderPhaseUpdates.set(queue, update); + } else { + // Append the update to the end of the list. + var lastRenderPhaseUpdate = firstRenderPhaseUpdate; + while (lastRenderPhaseUpdate.next !== null) { + lastRenderPhaseUpdate = lastRenderPhaseUpdate.next; } - previousNewFiber = newFiber; - oldFiber = nextOldFiber; + lastRenderPhaseUpdate.next = update; } + } else { + flushPassiveEffects(); - if (step.done) { - // We've reached the end of the new children. We can delete the rest. - deleteRemainingChildren(returnFiber, oldFiber); - return resultingFirstChild; - } + var currentTime = requestCurrentTime(); + 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 _update2 = { + expirationTime: _expirationTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }; + + // Append the update to the end of the list. + var _last = queue.last; + if (_last === null) { + // This is the first update. Create a circular list. + _update2.next = _update2; + } else { + var first = _last.next; + if (first !== null) { + // Still circular. + _update2.next = first; } - return resultingFirstChild; + _last.next = _update2; } + queue.last = _update2; - // Add all children to a key map for quick lookups. - var existingChildren = mapRemainingChildren(returnFiber, oldFiber); - - // Keep scanning and use the map to restore deleted items as moves. - for (; !step.done; newIdx++, step = newChildren.next()) { - var _newFiber4 = updateFromMap( - existingChildren, - returnFiber, - newIdx, - step.value, - 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 ( + fiber.expirationTime === NoWork && + (alternate === null || alternate.expirationTime === NoWork) + ) { + // The queue is currently empty, which means we can eagerly compute the + // next state before entering the render phase. If the new state is the + // same as the current state, we may be able to bail out entirely. + var _eagerReducer = queue.eagerReducer; + if (_eagerReducer !== null) { + var prevDispatcher = void 0; + { + prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; } - lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx); - if (previousNewFiber === null) { - resultingFirstChild = _newFiber4; - } else { - previousNewFiber.sibling = _newFiber4; + try { + var currentState = queue.eagerState; + var _eagerState = _eagerReducer(currentState, action); + // Stash the eagerly computed state, and the reducer used to compute + // it, on the update object. If the reducer hasn't changed by the + // time we enter the render phase, then the eager state can be used + // without calling the reducer again. + _update2.eagerReducer = _eagerReducer; + _update2.eagerState = _eagerState; + if (is(_eagerState, currentState)) { + // Fast path. We can bail out without scheduling React to re-render. + // It's still possible that we'll need to rebase this update later, + // if the component re-renders for a different reason and by that + // time the reducer has changed. + return; + } + } catch (error) { + // Suppress the error. It will throw again in the render phase. + } finally { + { + ReactCurrentDispatcher$1.current = prevDispatcher; + } } - previousNewFiber = _newFiber4; } } - - if (shouldTrackSideEffects) { - // Any existing children that weren't consumed above were deleted. We need - // to add them to the deletion list. - existingChildren.forEach(function(child) { - return deleteChild(returnFiber, child); - }); + { + if (shouldWarnForUnbatchedSetState === true) { + warnIfNotCurrentlyBatchingInDev(fiber); + } } - - return resultingFirstChild; + scheduleWork(fiber, _expirationTime); } +} - 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 +var ContextOnlyDispatcher = { + readContext: readContext, + + useCallback: throwInvalidHookError, + useContext: throwInvalidHookError, + useEffect: throwInvalidHookError, + useImperativeHandle: throwInvalidHookError, + useLayoutEffect: throwInvalidHookError, + useMemo: throwInvalidHookError, + useReducer: throwInvalidHookError, + useRef: throwInvalidHookError, + useState: throwInvalidHookError, + useDebugValue: throwInvalidHookError +}; + +var HooksDispatcherOnMountInDEV = null; +var HooksDispatcherOnUpdateInDEV = null; +var InvalidNestedHooksDispatcherOnMountInDEV = null; +var InvalidNestedHooksDispatcherOnUpdateInDEV = null; + +{ + var warnInvalidContextAccess = function() { + warning$1( + false, + "Context can only be read while React is rendering. " + + "In classes, you can read it in the render method or getDerivedStateFromProps. " + + "In function components, you can read it directly in the function body, but not " + + "inside Hooks like useReducer() or useMemo()." ); - 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.elementType === 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 { - deleteChild(returnFiber, child); + var warnInvalidHookAccess = function() { + warning$1( + false, + "Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. " + + "You can only call Hooks at the top level of your React function. " + + "For more information, see " + + "https://fb.me/rules-of-hooks" + ); + }; + + HooksDispatcherOnMountInDEV = { + readContext: function(context, observedBits) { + return readContext(context, observedBits); + }, + useCallback: function(callback, deps) { + currentHookNameInDev = "useCallback"; + return mountCallback(callback, deps); + }, + useContext: function(context, observedBits) { + currentHookNameInDev = "useContext"; + return mountContext(context, observedBits); + }, + useEffect: function(create, deps) { + currentHookNameInDev = "useEffect"; + return mountEffect(create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + currentHookNameInDev = "useImperativeHandle"; + return mountImperativeHandle(ref, create, deps); + }, + useLayoutEffect: function(create, deps) { + currentHookNameInDev = "useLayoutEffect"; + return mountLayoutEffect(create, deps); + }, + useMemo: function(create, deps) { + currentHookNameInDev = "useMemo"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountMemo(create, deps); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; } - child = child.sibling; + }, + useReducer: function(reducer, initialArg, init) { + currentHookNameInDev = "useReducer"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountReducer(reducer, initialArg, init); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useRef: function(initialValue) { + currentHookNameInDev = "useRef"; + return mountRef(initialValue); + }, + useState: function(initialState) { + currentHookNameInDev = "useState"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountState(initialState); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useDebugValue: function(value, formatterFn) { + currentHookNameInDev = "useDebugValue"; + return mountDebugValue(value, formatterFn); } + }; - 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 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; - } - } else { - deleteChild(returnFiber, child); + HooksDispatcherOnUpdateInDEV = { + readContext: function(context, observedBits) { + return readContext(context, observedBits); + }, + useCallback: function(callback, deps) { + currentHookNameInDev = "useCallback"; + return updateCallback(callback, deps); + }, + useContext: function(context, observedBits) { + currentHookNameInDev = "useContext"; + return updateContext(context, observedBits); + }, + useEffect: function(create, deps) { + currentHookNameInDev = "useEffect"; + return updateEffect(create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + currentHookNameInDev = "useImperativeHandle"; + return updateImperativeHandle(ref, create, deps); + }, + useLayoutEffect: function(create, deps) { + currentHookNameInDev = "useLayoutEffect"; + return updateLayoutEffect(create, deps); + }, + useMemo: function(create, deps) { + currentHookNameInDev = "useMemo"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateMemo(create, deps); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; } - child = child.sibling; + }, + useReducer: function(reducer, initialArg, init) { + currentHookNameInDev = "useReducer"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateReducer(reducer, initialArg, init); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useRef: function(initialValue) { + currentHookNameInDev = "useRef"; + return updateRef(initialValue); + }, + useState: function(initialState) { + currentHookNameInDev = "useState"; + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateState(initialState); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useDebugValue: function(value, formatterFn) { + currentHookNameInDev = "useDebugValue"; + return updateDebugValue(value, formatterFn); } + }; - var created = createFiberFromPortal( - portal, - returnFiber.mode, - expirationTime - ); - created.return = returnFiber; - return created; - } - - // 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; + InvalidNestedHooksDispatcherOnMountInDEV = { + readContext: function(context, observedBits) { + warnInvalidContextAccess(); + return readContext(context, observedBits); + }, + useCallback: function(callback, deps) { + currentHookNameInDev = "useCallback"; + warnInvalidHookAccess(); + return mountCallback(callback, deps); + }, + useContext: function(context, observedBits) { + currentHookNameInDev = "useContext"; + warnInvalidHookAccess(); + return mountContext(context, observedBits); + }, + useEffect: function(create, deps) { + currentHookNameInDev = "useEffect"; + warnInvalidHookAccess(); + return mountEffect(create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + currentHookNameInDev = "useImperativeHandle"; + warnInvalidHookAccess(); + return mountImperativeHandle(ref, create, deps); + }, + useLayoutEffect: function(create, deps) { + currentHookNameInDev = "useLayoutEffect"; + warnInvalidHookAccess(); + return mountLayoutEffect(create, deps); + }, + useMemo: function(create, deps) { + currentHookNameInDev = "useMemo"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountMemo(create, deps); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useReducer: function(reducer, initialArg, init) { + currentHookNameInDev = "useReducer"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountReducer(reducer, initialArg, init); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useRef: function(initialValue) { + currentHookNameInDev = "useRef"; + warnInvalidHookAccess(); + return mountRef(initialValue); + }, + useState: function(initialState) { + currentHookNameInDev = "useState"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV; + try { + return mountState(initialState); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useDebugValue: function(value, formatterFn) { + currentHookNameInDev = "useDebugValue"; + warnInvalidHookAccess(); + return mountDebugValue(value, formatterFn); } + }; - // Handle object types - var isObject = typeof newChild === "object" && newChild !== null; - - 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 - ) - ); + InvalidNestedHooksDispatcherOnUpdateInDEV = { + readContext: function(context, observedBits) { + warnInvalidContextAccess(); + return readContext(context, observedBits); + }, + useCallback: function(callback, deps) { + currentHookNameInDev = "useCallback"; + warnInvalidHookAccess(); + return updateCallback(callback, deps); + }, + useContext: function(context, observedBits) { + currentHookNameInDev = "useContext"; + warnInvalidHookAccess(); + return updateContext(context, observedBits); + }, + useEffect: function(create, deps) { + currentHookNameInDev = "useEffect"; + warnInvalidHookAccess(); + return updateEffect(create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + currentHookNameInDev = "useImperativeHandle"; + warnInvalidHookAccess(); + return updateImperativeHandle(ref, create, deps); + }, + useLayoutEffect: function(create, deps) { + currentHookNameInDev = "useLayoutEffect"; + warnInvalidHookAccess(); + return updateLayoutEffect(create, deps); + }, + useMemo: function(create, deps) { + currentHookNameInDev = "useMemo"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateMemo(create, deps); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useReducer: function(reducer, initialArg, init) { + currentHookNameInDev = "useReducer"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateReducer(reducer, initialArg, init); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; + } + }, + useRef: function(initialValue) { + currentHookNameInDev = "useRef"; + warnInvalidHookAccess(); + return updateRef(initialValue); + }, + useState: function(initialState) { + currentHookNameInDev = "useState"; + warnInvalidHookAccess(); + var prevDispatcher = ReactCurrentDispatcher$1.current; + ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; + try { + return updateState(initialState); + } finally { + ReactCurrentDispatcher$1.current = prevDispatcher; } + }, + useDebugValue: function(value, formatterFn) { + currentHookNameInDev = "useDebugValue"; + warnInvalidHookAccess(); + return updateDebugValue(value, formatterFn); } + }; +} - if (typeof newChild === "string" || typeof newChild === "number") { - return placeSingleChild( - reconcileSingleTextNode( - returnFiber, - currentFirstChild, - "" + newChild, - expirationTime - ) - ); - } +var commitTime = 0; +var profilerStartTime = -1; - if (isArray(newChild)) { - return reconcileChildrenArray( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ); - } +function getCommitTime() { + return commitTime; +} - if (getIteratorFn(newChild)) { - return reconcileChildrenIterator( - returnFiber, - currentFirstChild, - newChild, - expirationTime - ); - } +function recordCommitTime() { + if (!enableProfilerTimer) { + return; + } + commitTime = now$$1(); +} - if (isObject) { - throwOnInvalidObjectType(returnFiber, newChild); - } +function startProfilerTimer(fiber) { + if (!enableProfilerTimer) { + return; + } - { - 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 FunctionComponent: { - 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" - ); - } - } - } + profilerStartTime = now$$1(); - // Remaining cases are all treated as empty. - return deleteRemainingChildren(returnFiber, currentFirstChild); + if (fiber.actualStartTime < 0) { + fiber.actualStartTime = now$$1(); } - - return reconcileChildFibers; } -var reconcileChildFibers = ChildReconciler(true); -var mountChildFibers = ChildReconciler(false); - -function cloneChildFibers(current$$1, workInProgress) { - invariant( - current$$1 === null || workInProgress.child === current$$1.child, - "Resuming work not yet implemented." - ); +function stopProfilerTimerIfRunning(fiber) { + if (!enableProfilerTimer) { + return; + } + profilerStartTime = -1; +} - if (workInProgress.child === null) { +function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) { + if (!enableProfilerTimer) { 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; + if (profilerStartTime >= 0) { + var elapsedTime = now$$1() - profilerStartTime; + fiber.actualDuration += elapsedTime; + if (overrideBaseTime) { + fiber.selfBaseDuration = elapsedTime; + } + profilerStartTime = -1; } - newChild.sibling = null; } // The deepest Fiber on the stack involved in a hydration context. @@ -11067,6 +10894,8 @@ function resetHydrationState() { var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner; +var didReceiveUpdate = false; + var didWarnAboutBadClass = void 0; var didWarnAboutContextTypeOnFunctionComponent = void 0; var didWarnAboutGetDerivedStateOnFunctionComponent = void 0; @@ -11176,14 +11005,45 @@ function updateForwardRef( // The rest is a fork of updateFunctionComponent var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - prepareToUseHooks(current$$1, workInProgress, renderExpirationTime); { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); - nextChildren = render(nextProps, ref); + nextChildren = renderWithHooks( + current$$1, + workInProgress, + render, + nextProps, + ref, + renderExpirationTime + ); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + // Only double-render components with Hooks + if (workInProgress.memoizedState !== null) { + nextChildren = renderWithHooks( + current$$1, + workInProgress, + render, + nextProps, + ref, + renderExpirationTime + ); + } + } setCurrentPhase(null); } - nextChildren = finishHooks(render, nextProps, nextChildren, ref); + + if (current$$1 !== null && !didReceiveUpdate) { + bailoutHooks(current$$1, workInProgress, renderExpirationTime); + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } // React DevTools reads this flag. workInProgress.effectTag |= PerformedWork; @@ -11335,17 +11195,20 @@ function updateSimpleMemoComponent( // Inner propTypes will be validated in the function component path. } } - if (current$$1 !== null && updateExpirationTime < renderExpirationTime) { + if (current$$1 !== null) { var prevProps = current$$1.memoizedProps; if ( shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref ) { - return bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); + didReceiveUpdate = false; + if (updateExpirationTime < renderExpirationTime) { + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } } } return updateFunctionComponent( @@ -11434,14 +11297,45 @@ function updateFunctionComponent( var nextChildren = void 0; prepareToReadContext(workInProgress, renderExpirationTime); - prepareToUseHooks(current$$1, workInProgress, renderExpirationTime); { ReactCurrentOwner$3.current = workInProgress; setCurrentPhase("render"); - nextChildren = Component(nextProps, context); + nextChildren = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + context, + renderExpirationTime + ); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + // Only double-render components with Hooks + if (workInProgress.memoizedState !== null) { + nextChildren = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + context, + renderExpirationTime + ); + } + } setCurrentPhase(null); } - nextChildren = finishHooks(Component, nextProps, nextChildren, context); + + if (current$$1 !== null && !didReceiveUpdate) { + bailoutHooks(current$$1, workInProgress, renderExpirationTime); + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } // React DevTools reads this flag. workInProgress.effectTag |= PerformedWork; @@ -11776,7 +11670,7 @@ function updateHostComponent(current$$1, workInProgress, renderExpirationTime) { shouldDeprioritizeSubtree(type, nextProps) ) { // Schedule this fiber to re-render at offscreen priority. Then bailout. - workInProgress.expirationTime = Never; + workInProgress.expirationTime = workInProgress.childExpirationTime = Never; return null; } @@ -11829,6 +11723,9 @@ function mountLazyComponent( var child = void 0; switch (resolvedTag) { case FunctionComponent: { + { + validateFunctionComponentInDev(workInProgress, Component); + } child = updateFunctionComponent( null, workInProgress, @@ -11989,7 +11886,6 @@ function mountIndeterminateComponent( var context = getMaskedContext(workInProgress, unmaskedContext); prepareToReadContext(workInProgress, renderExpirationTime); - prepareToUseHooks(null, workInProgress, renderExpirationTime); var value = void 0; @@ -12017,7 +11913,14 @@ function mountIndeterminateComponent( } ReactCurrentOwner$3.current = workInProgress; - value = Component(props, context); + value = renderWithHooks( + null, + workInProgress, + Component, + props, + context, + renderExpirationTime + ); } // React DevTools reads this flag. workInProgress.effectTag |= PerformedWork; @@ -12071,7 +11974,25 @@ function mountIndeterminateComponent( } else { // Proceed under the assumption that this is a function component workInProgress.tag = FunctionComponent; - value = finishHooks(Component, props, value, context); + { + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + // Only double-render components with Hooks + if (workInProgress.memoizedState !== null) { + value = renderWithHooks( + null, + workInProgress, + Component, + props, + context, + renderExpirationTime + ); + } + } + } reconcileChildren(null, workInProgress, value, renderExpirationTime); { validateFunctionComponentInDev(workInProgress, Component); @@ -12107,7 +12028,8 @@ function validateFunctionComponentInDev(workInProgress, Component) { warning$1( false, "Function components cannot be given refs. " + - "Attempts to access this ref will fail.%s", + "Attempts to access this ref will fail. " + + "Did you mean to use React.forwardRef()?%s", info ); } @@ -12396,6 +12318,7 @@ function updateSuspenseComponent( ); } } + workInProgress.stateNode = current$$1.stateNode; } workInProgress.memoizedState = nextState; @@ -12566,6 +12489,10 @@ function updateContextConsumer( return workInProgress.child; } +function markWorkInProgressReceivedUpdate() { + didReceiveUpdate = true; +} + function bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -12575,7 +12502,7 @@ function bailoutOnAlreadyFinishedWork( if (current$$1 !== null) { // Reuse previous context list - workInProgress.firstContextDependency = current$$1.firstContextDependency; + workInProgress.contextDependencies = current$$1.contextDependencies; } if (enableProfilerTimer) { @@ -12604,11 +12531,13 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { if (current$$1 !== null) { var oldProps = current$$1.memoizedProps; var newProps = workInProgress.pendingProps; - if ( - oldProps === newProps && - !hasContextChanged() && - updateExpirationTime < renderExpirationTime - ) { + + if (oldProps !== newProps || hasContextChanged()) { + // If props or context changed, mark the fiber as having performed work. + // This may be unset if the props are determined to be equal later (memo). + didReceiveUpdate = true; + } else if (updateExpirationTime < renderExpirationTime) { + didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering // the begin phase. There's still some bookkeeping we that needs to be done // in this optimized path, mostly pushing stuff onto the stack. @@ -12690,6 +12619,8 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { renderExpirationTime ); } + } else { + didReceiveUpdate = false; } // Before entering the begin phase, clear the expiration time. @@ -12849,20 +12780,900 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { return mountIncompleteClassComponent( current$$1, workInProgress, - _Component3, - _resolvedProps4, - renderExpirationTime + _Component3, + _resolvedProps4, + renderExpirationTime + ); + } + default: + invariant( + false, + "Unknown unit of work tag. This error is likely caused by a bug in " + + "React. Please file an issue." + ); + } +} + +var valueCursor = createCursor(null); + +var rendererSigil = void 0; +{ + // Use this to detect multiple renderers using the same context + rendererSigil = {}; +} + +var currentlyRenderingFiber = null; +var lastContextDependency = null; +var lastContextWithAllBitsObserved = null; + +var isDisallowedContextReadInDEV = false; + +function resetContextDependences() { + // This is called right before React yields execution, to ensure `readContext` + // cannot be called outside the render phase. + currentlyRenderingFiber = null; + lastContextDependency = null; + lastContextWithAllBitsObserved = null; + { + isDisallowedContextReadInDEV = false; + } +} + +function enterDisallowedContextReadInDEV() { + { + isDisallowedContextReadInDEV = true; + } +} + +function exitDisallowedContextReadInDEV() { + { + isDisallowedContextReadInDEV = false; + } +} + +function pushProvider(providerFiber, nextValue) { + var context = providerFiber.type._context; + + if (isPrimaryRenderer) { + push(valueCursor, context._currentValue, providerFiber); + + context._currentValue = nextValue; + { + !( + context._currentRenderer === undefined || + context._currentRenderer === null || + context._currentRenderer === rendererSigil + ) + ? warningWithoutStack$1( + false, + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." + ) + : void 0; + context._currentRenderer = rendererSigil; + } + } else { + push(valueCursor, context._currentValue2, providerFiber); + + context._currentValue2 = nextValue; + { + !( + context._currentRenderer2 === undefined || + context._currentRenderer2 === null || + context._currentRenderer2 === rendererSigil + ) + ? warningWithoutStack$1( + false, + "Detected multiple renderers concurrently rendering the " + + "same context provider. This is currently unsupported." + ) + : void 0; + context._currentRenderer2 = rendererSigil; + } + } +} + +function popProvider(providerFiber) { + var currentValue = valueCursor.current; + + pop(valueCursor, providerFiber); + + var context = providerFiber.type._context; + if (isPrimaryRenderer) { + context._currentValue = currentValue; + } else { + context._currentValue2 = currentValue; + } +} + +function calculateChangedBits(context, newValue, oldValue) { + if (is(oldValue, newValue)) { + // No change + return 0; + } else { + var changedBits = + typeof context._calculateChangedBits === "function" + ? context._calculateChangedBits(oldValue, newValue) + : maxSigned31BitInt; + + { + !((changedBits & maxSigned31BitInt) === changedBits) + ? warning$1( + false, + "calculateChangedBits: Expected the return value to be a " + + "31-bit integer. Instead received: %s", + changedBits + ) + : void 0; + } + return changedBits | 0; + } +} + +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. + var list = fiber.contextDependencies; + if (list !== null) { + nextFiber = fiber.child; + + var dependency = list.first; + while (dependency !== null) { + // Check if the context matches. + if ( + dependency.context === context && + (dependency.observedBits & changedBits) !== 0 + ) { + // Match! Schedule an update on this fiber. + + if (fiber.tag === ClassComponent) { + // Schedule a force update on the work-in-progress. + var update = createUpdate(renderExpirationTime); + update.tag = ForceUpdate; + // TODO: Because we don't have a work-in-progress, this will add the + // update to the current fiber, too, which means it will persist even if + // this render is thrown away. Since it's a race condition, not sure it's + // worth fixing. + enqueueUpdate(fiber, update); + } + + if (fiber.expirationTime < renderExpirationTime) { + fiber.expirationTime = renderExpirationTime; + } + var alternate = fiber.alternate; + if ( + alternate !== null && + alternate.expirationTime < renderExpirationTime + ) { + alternate.expirationTime = renderExpirationTime; + } + // Update the child expiration time of all the ancestors, including + // the alternates. + var node = fiber.return; + while (node !== null) { + alternate = node.alternate; + if (node.childExpirationTime < renderExpirationTime) { + node.childExpirationTime = renderExpirationTime; + if ( + alternate !== null && + alternate.childExpirationTime < renderExpirationTime + ) { + alternate.childExpirationTime = renderExpirationTime; + } + } else if ( + alternate !== null && + alternate.childExpirationTime < renderExpirationTime + ) { + alternate.childExpirationTime = renderExpirationTime; + } else { + // Neither alternate was updated, which means the rest of the + // ancestor path already has sufficient priority. + break; + } + node = node.return; + } + + // Mark the expiration time on the list, too. + if (list.expirationTime < renderExpirationTime) { + list.expirationTime = renderExpirationTime; + } + + // Since we already found a match, we can stop traversing the + // dependency list. + break; + } + dependency = dependency.next; + } + } else if (fiber.tag === ContextProvider) { + // Don't scan deeper if this is a matching provider + nextFiber = fiber.type === workInProgress.type ? null : fiber.child; + } else { + // Traverse down. + nextFiber = fiber.child; + } + + if (nextFiber !== null) { + // Set the return pointer of the child to the work-in-progress fiber. + nextFiber.return = fiber; + } else { + // No child. Traverse to next sibling. + nextFiber = fiber; + while (nextFiber !== null) { + if (nextFiber === workInProgress) { + // We're back to the root of this subtree. Exit. + nextFiber = null; + break; + } + var sibling = nextFiber.sibling; + if (sibling !== null) { + // Set the return pointer of the sibling to the work-in-progress fiber. + sibling.return = nextFiber.return; + nextFiber = sibling; + break; + } + // No more siblings. Traverse up. + nextFiber = nextFiber.return; + } + } + fiber = nextFiber; + } +} + +function prepareToReadContext(workInProgress, renderExpirationTime) { + currentlyRenderingFiber = workInProgress; + lastContextDependency = null; + lastContextWithAllBitsObserved = null; + + var currentDependencies = workInProgress.contextDependencies; + if ( + currentDependencies !== null && + currentDependencies.expirationTime >= renderExpirationTime + ) { + // Context list has a pending update. Mark that this fiber performed work. + markWorkInProgressReceivedUpdate(); + } + + // Reset the work-in-progress list + workInProgress.contextDependencies = null; +} + +function readContext(context, observedBits) { + { + // This warning would fire if you read context inside a Hook like useMemo. + // Unlike the class check below, it's not enforced in production for perf. + !!isDisallowedContextReadInDEV + ? warning$1( + false, + "Context can only be read while React is rendering. " + + "In classes, you can read it in the render method or getDerivedStateFromProps. " + + "In function components, you can read it directly in the function body, but not " + + "inside Hooks like useReducer() or useMemo()." + ) + : void 0; + } + + if (lastContextWithAllBitsObserved === context) { + // Nothing to do. We already observe everything in this context. + } else if (observedBits === false || observedBits === 0) { + // Do not observe any updates. + } else { + var resolvedObservedBits = void 0; // Avoid deopting on observable arguments or heterogeneous types. + if ( + typeof observedBits !== "number" || + observedBits === maxSigned31BitInt + ) { + // Observe all updates. + lastContextWithAllBitsObserved = context; + resolvedObservedBits = maxSigned31BitInt; + } else { + resolvedObservedBits = observedBits; + } + + var contextItem = { + context: context, + observedBits: resolvedObservedBits, + next: null + }; + + if (lastContextDependency === null) { + invariant( + currentlyRenderingFiber !== null, + "Context can only be read while React is rendering. " + + "In classes, you can read it in the render method or getDerivedStateFromProps. " + + "In function components, you can read it directly in the function body, but not " + + "inside Hooks like useReducer() or useMemo()." + ); + + // This is the first dependency for this component. Create a new list. + lastContextDependency = contextItem; + currentlyRenderingFiber.contextDependencies = { + first: contextItem, + expirationTime: NoWork + }; + } else { + // Append a new context item. + lastContextDependency = lastContextDependency.next = contextItem; + } + } + return isPrimaryRenderer ? context._currentValue : context._currentValue2; +} + +// 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 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 = { + 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 = { + 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) { + // 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; + } +} + +function enqueueUpdate(fiber, update) { + // 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); + } 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); + appendUpdateToQueue(queue2, update); + } 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); + // 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 + ) { + warningWithoutStack$1( + 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) { + // 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; + } +} + +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 + { + enterDisallowedContextReadInDEV(); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + _payload.call(instance, prevState, nextProps); + } + } + var nextState = _payload.call(instance, prevState, nextProps); + { + exitDisallowedContextReadInDEV(); + } + return nextState; + } + // 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 + { + enterDisallowedContextReadInDEV(); + if ( + debugRenderPhaseSideEffects || + (debugRenderPhaseSideEffectsForStrictMode && + workInProgress.mode & StrictMode) + ) { + _payload2.call(instance, prevState, nextProps); + } + } + partialState = _payload2.call(instance, prevState, nextProps); + { + exitDisallowedContextReadInDEV(); + } + } 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; + + 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 < 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 < _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; + } + } } - default: - invariant( - false, - "Unknown unit of work tag. This error is likely caused by a bug in " + - "React. Please file an issue." - ); + 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; + } + + queue.baseState = newBaseState; + queue.firstUpdate = newFirstUpdate; + queue.firstCapturedUpdate = newFirstCapturedUpdate; + + // Set the remaining expiration time to be whatever is remaining in the queue. + // This should be fine because the only two other things that contribute to + // expiration time are props and context. We're already in the middle of the + // begin phase by the time we start processing the queue, so we've already + // dealt with the props. Context in components that specify + // shouldComponentUpdate is tricky; but we'll have to account for + // that regardless. + workInProgress.expirationTime = newExpirationTime; + workInProgress.memoizedState = resultState; + + { + 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; + } + + // Commit the effects + commitUpdateEffects(finishedQueue.firstEffect, instance); + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + + commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; +} + +function commitUpdateEffects(effect, instance) { + while (effect !== null) { + var _callback3 = effect.callback; + if (_callback3 !== null) { + effect.callback = null; + callCallback(_callback3, instance); + } + effect = effect.nextEffect; } } +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: getStackByFiberInDevAndProd(source) + }; +} + function markUpdate(workInProgress) { // Tag the fiber with an update effect. This turns a Placement into // a PlacementAndUpdate. @@ -13483,18 +14294,10 @@ function completeWork(current, workInProgress, renderExpirationTime) { } } - // The children either timed out after previously being visible, or - // were restored after previously being hidden. Schedule an effect - // to update their visiblity. - if ( - // - nextDidTimeout !== prevDidTimeout || - // Outside concurrent mode, the primary children commit in an - // inconsistent state, even if they are hidden. So if they are hidden, - // we need to schedule an effect to re-hide them, just in case. - ((workInProgress.effectTag & ConcurrentMode) === NoContext && - nextDidTimeout) - ) { + if (nextDidTimeout || prevDidTimeout) { + // If the children are hidden, or if they were previous hidden, schedule + // an effect to toggle their visibility. This is also used to attach a + // retry listener to the promise. workInProgress.effectTag |= Update; } break; @@ -13537,7 +14340,7 @@ function completeWork(current, workInProgress, renderExpirationTime) { return null; } -function shouldCaptureSuspense(current, workInProgress) { +function shouldCaptureSuspense(workInProgress) { // In order to capture, the Suspense component must have a fallback prop. if (workInProgress.memoizedProps.fallback === undefined) { return false; @@ -13669,6 +14472,8 @@ var didWarnAboutUndefinedSnapshotBeforeUpdate = null; didWarnAboutUndefinedSnapshotBeforeUpdate = new Set(); } +var PossiblyWeakSet = typeof WeakSet === "function" ? WeakSet : Set; + function logError(boundary, errorInfo) { var source = errorInfo.source; var stack = errorInfo.stack; @@ -13847,9 +14652,6 @@ function commitBeforeMutationLifeCycles(current$$1, finishedWork) { } function commitHookEffectList(unmountTag, mountTag, finishedWork) { - if (!enableHooks) { - return; - } var updateQueue = finishedWork.updateQueue; var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null; if (lastEffect !== null) { @@ -13859,42 +14661,49 @@ function commitHookEffectList(unmountTag, mountTag, finishedWork) { if ((effect.tag & unmountTag) !== NoEffect$1) { // Unmount var destroy = effect.destroy; - effect.destroy = null; - if (destroy !== null) { + effect.destroy = undefined; + if (destroy !== undefined) { destroy(); } } if ((effect.tag & mountTag) !== NoEffect$1) { // Mount var create = effect.create; - var _destroy = create(); - if (typeof _destroy !== "function") { - { - if (_destroy !== null && _destroy !== undefined) { - warningWithoutStack$1( - false, - "useEffect function must return a cleanup function or " + - "nothing.%s%s", - typeof _destroy.then === "function" - ? "\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. " + - "Instead, you may write an async function separately " + - "and then call it from inside the effect:\n\n" + - "async function fetchComment(commentId) {\n" + - " // You can await here\n" + - "}\n\n" + - "useEffect(() => {\n" + - " fetchComment(commentId);\n" + - "}, [commentId]);\n\n" + - "In the future, React will provide a more idiomatic solution for data fetching " + - "that doesn't involve writing effects manually." - : "", - getStackByFiberInDevAndProd(finishedWork) - ); + effect.destroy = create(); + + { + var _destroy = effect.destroy; + if (_destroy !== undefined && typeof _destroy !== "function") { + var addendum = void 0; + if (_destroy === null) { + addendum = + " You returned null. If your effect does not require clean " + + "up, return undefined (or nothing)."; + } else if (typeof _destroy.then === "function") { + addendum = + "\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. " + + "Instead, you may write an async function separately " + + "and then call it from inside the effect:\n\n" + + "async function fetchComment(commentId) {\n" + + " // You can await here\n" + + "}\n\n" + + "useEffect(() => {\n" + + " fetchComment(commentId);\n" + + "}, [commentId]);\n\n" + + "In the future, React will provide a more idiomatic solution for data fetching " + + "that doesn't involve writing effects manually."; + } else { + addendum = " You returned: " + _destroy; } + warningWithoutStack$1( + false, + "An Effect function must not return anything besides a function, " + + "which is used for clean-up.%s%s", + addendum, + getStackByFiberInDevAndProd(finishedWork) + ); } - _destroy = null; } - effect.destroy = _destroy; } effect = effect.next; } while (effect !== firstEffect); @@ -14247,7 +15056,7 @@ function commitUnmount(current$$1) { var effect = firstEffect; do { var destroy = effect.destroy; - if (destroy !== null) { + if (destroy !== undefined) { safelyCallDestroy(current$$1, destroy); } effect = effect.next; @@ -14725,6 +15534,30 @@ function commitWork(current$$1, finishedWork) { if (primaryChildParent !== null) { hideOrUnhideAllChildren(primaryChildParent, newDidTimeout); } + + // If this boundary just timed out, then it will have a set of thenables. + // For each thenable, attach a listener so that when it resolves, React + // attempts to re-render the boundary in the primary (pre-timeout) state. + var thenables = finishedWork.updateQueue; + if (thenables !== null) { + finishedWork.updateQueue = null; + var retryCache = finishedWork.stateNode; + if (retryCache === null) { + retryCache = finishedWork.stateNode = new PossiblyWeakSet(); + } + thenables.forEach(function(thenable) { + // Memoize using the boundary fiber to prevent redundant listeners. + var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable); + if (enableSchedulerTracing) { + retry = tracing.unstable_wrap(retry); + } + if (!retryCache.has(thenable)) { + retryCache.add(thenable); + thenable.then(retry, retry); + } + }); + } + return; } case IncompleteClassComponent: { @@ -14747,6 +15580,8 @@ function commitResetTextContent(current$$1) { resetTextContent(current$$1.stateNode); } +var PossiblyWeakMap = typeof WeakMap === "function" ? WeakMap : Map; + function createRootErrorUpdate(fiber, errorInfo, expirationTime) { var update = createUpdate(expirationTime); // Unmount the root by rendering null. @@ -14872,29 +15707,19 @@ function throwException( do { if ( _workInProgress.tag === SuspenseComponent && - shouldCaptureSuspense(_workInProgress.alternate, _workInProgress) + shouldCaptureSuspense(_workInProgress) ) { // Found the nearest boundary. - // If the boundary is not in concurrent mode, we should not suspend, and - // likewise, when the promise resolves, we should ping synchronously. - var pingTime = - (_workInProgress.mode & ConcurrentMode) === NoEffect - ? Sync - : renderExpirationTime; - - // Attach a listener to the promise to "ping" the root and retry. - var onResolveOrReject = retrySuspendedRoot.bind( - null, - root, - _workInProgress, - sourceFiber, - pingTime - ); - if (enableSchedulerTracing) { - onResolveOrReject = tracing.unstable_wrap(onResolveOrReject); + // Stash the promise on the boundary fiber. If the boundary times out, we'll + var thenables = _workInProgress.updateQueue; + if (thenables === null) { + var updateQueue = new Set(); + updateQueue.add(thenable); + _workInProgress.updateQueue = updateQueue; + } else { + thenables.add(thenable); } - thenable.then(onResolveOrReject, onResolveOrReject); // If the boundary is outside of concurrent mode, we should *not* // suspend the commit. Pretend as if the suspended component rendered @@ -14913,18 +15738,25 @@ function throwException( sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete); if (sourceFiber.tag === ClassComponent) { - var _current = sourceFiber.alternate; - if (_current === null) { + var currentSourceFiber = sourceFiber.alternate; + if (currentSourceFiber === null) { // This is a new mount. Change the tag so it's not mistaken for a // completed class component. For example, we should not call // componentWillUnmount if it is deleted. sourceFiber.tag = IncompleteClassComponent; + } else { + // When we try rendering again, we should not reuse the current fiber, + // since it's known to be in an inconsistent state. Use a force updte to + // prevent a bail out. + var update = createUpdate(Sync); + update.tag = ForceUpdate; + enqueueUpdate(sourceFiber, update); } } - // The source fiber did not complete. Mark it with the current - // render priority to indicate that it still has pending work. - sourceFiber.expirationTime = renderExpirationTime; + // The source fiber did not complete. Mark it with Sync priority to + // indicate that it still has pending work. + sourceFiber.expirationTime = Sync; // Exit without suspending. return; @@ -14933,9 +15765,40 @@ function throwException( // Confirmed that the boundary is in a concurrent mode tree. Continue // with the normal suspend path. + // Attach a listener to the promise to "ping" the root and retry. But + // only if one does not already exist for the current render expiration + // time (which acts like a "thread ID" here). + var pingCache = root.pingCache; + var threadIDs = void 0; + if (pingCache === null) { + pingCache = root.pingCache = new PossiblyWeakMap(); + threadIDs = new Set(); + pingCache.set(thenable, threadIDs); + } else { + threadIDs = pingCache.get(thenable); + if (threadIDs === undefined) { + threadIDs = new Set(); + pingCache.set(thenable, threadIDs); + } + } + if (!threadIDs.has(renderExpirationTime)) { + // Memoize using the thread ID to prevent redundant listeners. + threadIDs.add(renderExpirationTime); + var ping = pingSuspendedRoot.bind( + null, + root, + thenable, + renderExpirationTime + ); + if (enableSchedulerTracing) { + ping = tracing.unstable_wrap(ping); + } + thenable.then(ping, ping); + } + var absoluteTimeoutMs = void 0; if (earliestTimeoutMs === -1) { - // If no explicit threshold is given, default to an abitrarily large + // If no explicit threshold is given, default to an arbitrarily large // value. The actual size doesn't matter because the threshold for the // whole tree will be clamped to the expiration time. absoluteTimeoutMs = maxSigned31BitInt; @@ -15000,12 +15863,12 @@ function throwException( var _errorInfo = value; workInProgress.effectTag |= ShouldCapture; workInProgress.expirationTime = renderExpirationTime; - var update = createRootErrorUpdate( + var _update = createRootErrorUpdate( workInProgress, _errorInfo, renderExpirationTime ); - enqueueCapturedUpdate(workInProgress, update); + enqueueCapturedUpdate(workInProgress, _update); return; } case ClassComponent: @@ -15023,12 +15886,12 @@ function throwException( workInProgress.effectTag |= ShouldCapture; workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state - var _update = createClassErrorUpdate( + var _update2 = createClassErrorUpdate( workInProgress, errorInfo, renderExpirationTime ); - enqueueCapturedUpdate(workInProgress, _update); + enqueueCapturedUpdate(workInProgress, _update2); return; } break; @@ -15118,22 +15981,7 @@ function unwindInterruptedWork(interruptedWork) { } } -var Dispatcher = { - readContext: readContext, - useCallback: useCallback, - useContext: useContext, - useEffect: useEffect, - useImperativeMethods: useImperativeMethods, - useLayoutEffect: useLayoutEffect, - useMemo: useMemo, - useReducer: useReducer, - useRef: useRef, - useState: useState -}; -var DispatcherWithoutHooks = { - readContext: readContext -}; - +var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner; var didWarnAboutStateTransition = void 0; @@ -15206,11 +16054,6 @@ if (enableSchedulerTracing) { }; } -// 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. @@ -15443,6 +16286,9 @@ function commitAllLifeCycles(finishedRoot, committedExpirationTime) { } } while (nextEffect !== null) { + { + setCurrentFiber(nextEffect); + } var effectTag = nextEffect.effectTag; if (effectTag & (Update | Callback)) { @@ -15461,12 +16307,15 @@ function commitAllLifeCycles(finishedRoot, committedExpirationTime) { commitAttachRef(nextEffect); } - if (enableHooks && effectTag & Passive) { + if (effectTag & Passive) { rootWithPendingPassiveEffects = finishedRoot; } nextEffect = nextEffect.nextEffect; } + { + resetCurrentFiber(); + } } function commitPassiveEffects(root, firstEffect) { @@ -15480,6 +16329,10 @@ function commitPassiveEffects(root, firstEffect) { var effect = firstEffect; do { + { + setCurrentFiber(effect); + } + if (effect.effectTag & Passive) { var didError = false; var error = void 0; @@ -15496,6 +16349,9 @@ function commitPassiveEffects(root, firstEffect) { } effect = effect.nextEffect; } while (effect !== null); + { + resetCurrentFiber(); + } isRendering = previousIsRendering; @@ -15522,8 +16378,10 @@ function markLegacyErrorBoundaryAsFailed(instance) { } function flushPassiveEffects() { + if (passiveEffectCallbackHandle !== null) { + cancelPassiveEffects(passiveEffectCallbackHandle); + } if (passiveEffectCallback !== null) { - scheduler.unstable_cancelCallback(passiveEffectCallbackHandle); // We call the scheduled callback instead of commitPassiveEffects directly // to ensure tracing works correctly. passiveEffectCallback(); @@ -15697,11 +16555,7 @@ function commitRoot(root, finishedWork) { } } - if ( - enableHooks && - firstEffect !== null && - rootWithPendingPassiveEffects !== null - ) { + if (firstEffect !== null && rootWithPendingPassiveEffects !== null) { // This commit included a passive effect. These do not need to fire until // after the next paint. Schedule an callback to fire them in an async // event. To ensure serial execution, the callback will be flushed early if @@ -15713,7 +16567,12 @@ function commitRoot(root, finishedWork) { // here because that code is still in flux. callback = tracing.unstable_wrap(callback); } - passiveEffectCallbackHandle = scheduler.unstable_scheduleCallback(callback); + passiveEffectCallbackHandle = scheduler.unstable_runWithPriority( + scheduler.unstable_NormalPriority, + function() { + return schedulePassiveEffects(callback); + } + ); passiveEffectCallback = callback; } @@ -16132,11 +16991,8 @@ function renderRoot(root, isYieldy) { flushPassiveEffects(); isWorking = true; - if (enableHooks) { - ReactCurrentOwner$2.currentDispatcher = Dispatcher; - } else { - ReactCurrentOwner$2.currentDispatcher = DispatcherWithoutHooks; - } + var previousDispatcher = ReactCurrentDispatcher.current; + ReactCurrentDispatcher.current = ContextOnlyDispatcher; var expirationTime = root.nextExpirationTimeToWorkOn; @@ -16190,7 +17046,7 @@ function renderRoot(root, isYieldy) { subscriber.onWorkStarted(interactions, threadID); } catch (error) { // Work thrown by an interaction tracing subscriber should be rethrown, - // But only once it's safe (to avoid leaveing the scheduler in an invalid state). + // But only once it's safe (to avoid leaving the scheduler in an invalid state). // Store the error for now and we'll re-throw in finishRendering(). if (!hasUnhandledError) { hasUnhandledError = true; @@ -16297,7 +17153,7 @@ function renderRoot(root, isYieldy) { // We're done performing work. Time to clean up. isWorking = false; - ReactCurrentOwner$2.currentDispatcher = null; + ReactCurrentDispatcher.current = previousDispatcher; resetContextDependences(); resetHooks(); @@ -16481,52 +17337,58 @@ function computeThreadID(expirationTime, interactionThreadID) { } function computeExpirationForFiber(currentTime, fiber) { + var priorityLevel = scheduler.unstable_getCurrentPriorityLevel(); + 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; - } + if ((fiber.mode & ConcurrentMode) === NoContext) { + // Outside of concurrent mode, updates are always synchronous. + expirationTime = Sync; + } else if (isWorking && !isCommitting$1) { + // During render phase, updates expire during as the current render. + expirationTime = nextRenderExpirationTime; } else { - // No explicit expiration context was set, and we're not currently - // performing work. Calculate a new expiration time. - if (fiber.mode & ConcurrentMode) { - if (isBatchingInteractiveUpdates) { - // This is an interactive update + switch (priorityLevel) { + case scheduler.unstable_ImmediatePriority: + expirationTime = Sync; + break; + case scheduler.unstable_UserBlockingPriority: expirationTime = computeInteractiveExpiration(currentTime); - } else { - // This is an async update + break; + case scheduler.unstable_NormalPriority: + // This is a normal, concurrent update expirationTime = computeAsyncExpiration(currentTime); - } - // If we're in the middle of rendering a tree, do not update at the same - // expiration time that is already rendering. - if (nextRoot !== null && expirationTime === nextRenderExpirationTime) { - expirationTime -= 1; - } - } else { - // This is a sync update - expirationTime = Sync; + break; + case scheduler.unstable_LowPriority: + case scheduler.unstable_IdlePriority: + expirationTime = Never; + break; + default: + invariant( + false, + "Unknown priority level. This error is likely caused by a bug in " + + "React. Please file an issue." + ); } - } - 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 ( - lowestPriorityPendingInteractiveExpirationTime === NoWork || - expirationTime < lowestPriorityPendingInteractiveExpirationTime - ) { - lowestPriorityPendingInteractiveExpirationTime = expirationTime; + + // If we're in the middle of rendering a tree, do not update at the same + // expiration time that is already rendering. + if (nextRoot !== null && expirationTime === nextRenderExpirationTime) { + expirationTime -= 1; } } + + // Keep track of the lowest pending interactive expiration time. This + // allows us to synchronously flush all interactive updates + // when needed. + // TODO: Move this to renderer? + if ( + priorityLevel === scheduler.unstable_UserBlockingPriority && + (lowestPriorityPendingInteractiveExpirationTime === NoWork || + expirationTime < lowestPriorityPendingInteractiveExpirationTime) + ) { + lowestPriorityPendingInteractiveExpirationTime = expirationTime; + } + return expirationTime; } @@ -16544,56 +17406,54 @@ function renderDidError() { nextRenderDidError = true; } -function retrySuspendedRoot(root, boundaryFiber, sourceFiber, suspendedTime) { - var retryTime = void 0; +function pingSuspendedRoot(root, thenable, pingTime) { + // A promise that previously suspended React from committing has resolved. + // If React is still suspended, try again at the previous level (pingTime). - if (isPriorityLevelSuspended(root, suspendedTime)) { - // Ping at the original level - retryTime = suspendedTime; - - markPingedPriorityLevel(root, retryTime); - } else { - // Suspense already timed out. Compute a new expiration time - var currentTime = requestCurrentTime(); - retryTime = computeExpirationForFiber(currentTime, boundaryFiber); - markPendingPriorityLevel(root, retryTime); + var pingCache = root.pingCache; + if (pingCache !== null) { + // The thenable resolved, so we no longer need to memoize, because it will + // never be thrown again. + pingCache.delete(thenable); } - // TODO: If the suspense fiber has already rendered the primary children - // without suspending (that is, all of the promises have already resolved), - // we should not trigger another update here. One case this happens is when - // we are in sync mode and a single promise is thrown both on initial render - // and on update; we attach two .then(retrySuspendedRoot) callbacks and each - // one performs Sync work, rerendering the Suspense. - - if ((boundaryFiber.mode & ConcurrentMode) !== NoContext) { - if (root === nextRoot && nextRenderExpirationTime === suspendedTime) { - // Received a ping at the same priority level at which we're currently - // rendering. Restart from the root. - nextRoot = null; + if (nextRoot !== null && nextRenderExpirationTime === pingTime) { + // Received a ping at the same priority level at which we're currently + // rendering. Restart from the root. + nextRoot = null; + } else { + // Confirm that the root is still suspended at this level. Otherwise exit. + if (isPriorityLevelSuspended(root, pingTime)) { + // Ping at the original level + markPingedPriorityLevel(root, pingTime); + var rootExpirationTime = root.expirationTime; + if (rootExpirationTime !== NoWork) { + requestWork(root, rootExpirationTime); + } } } +} - scheduleWorkToRoot(boundaryFiber, retryTime); - if ((boundaryFiber.mode & ConcurrentMode) === NoContext) { - // Outside of concurrent mode, we must schedule an update on the source - // fiber, too, since it already committed in an inconsistent state and - // therefore does not have any pending work. - scheduleWorkToRoot(sourceFiber, retryTime); - var sourceTag = sourceFiber.tag; - if (sourceTag === ClassComponent && sourceFiber.stateNode !== null) { - // When we try rendering again, we should not reuse the current fiber, - // since it's known to be in an inconsistent state. Use a force updte to - // prevent a bail out. - var update = createUpdate(retryTime); - update.tag = ForceUpdate; - enqueueUpdate(sourceFiber, update); - } +function retryTimedOutBoundary(boundaryFiber, thenable) { + // The boundary fiber (a Suspense component) previously timed out and was + // rendered in its fallback state. One of the promises that suspended it has + // resolved, which means at least part of the tree was likely unblocked. Try + var retryCache = boundaryFiber.stateNode; + if (retryCache !== null) { + // The thenable resolved, so we no longer need to memoize, because it will + // never be thrown again. + retryCache.delete(thenable); } - var rootExpirationTime = root.expirationTime; - if (rootExpirationTime !== NoWork) { - requestWork(root, rootExpirationTime); + var currentTime = requestCurrentTime(); + var retryTime = computeExpirationForFiber(currentTime, boundaryFiber); + var root = scheduleWorkToRoot(boundaryFiber, retryTime); + if (root !== null) { + markPendingPriorityLevel(root, retryTime); + var rootExpirationTime = root.expirationTime; + if (rootExpirationTime !== NoWork) { + requestWork(root, rootExpirationTime); + } } } @@ -16683,6 +17543,25 @@ function scheduleWorkToRoot(fiber, expirationTime) { return root; } +function warnIfNotCurrentlyBatchingInDev(fiber) { + { + if (isRendering === false && isBatchingUpdates === false) { + warningWithoutStack$1( + false, + "An update to %s inside a test was not wrapped in act(...).\n\n" + + "When testing, code that causes React state updates should be wrapped into act(...):\n\n" + + "act(() => {\n" + + " /* fire events that update state */\n" + + "});\n" + + "/* assert on the output */\n\n" + + "This ensures that you're testing the behavior the user would see in the browser." + + " Learn more at https://fb.me/react-wrap-tests-with-act", + getComponentName(fiber.type) + ); + } + } +} + function scheduleWork(fiber, expirationTime) { var root = scheduleWorkToRoot(fiber, expirationTime); if (root === null) { @@ -16754,7 +17633,6 @@ var unhandledError = null; var isBatchingUpdates = false; var isUnbatchingUpdates = false; -var isBatchingInteractiveUpdates = false; var completedBatches = null; @@ -17270,7 +18148,12 @@ function completeRoot(root, finishedWork, expirationTime) { lastCommittedRootDuringThisBatch = root; nestedUpdateCount = 0; } - commitRoot(root, finishedWork); + scheduler.unstable_runWithPriority( + scheduler.unstable_ImmediatePriority, + function() { + commitRoot(root, finishedWork); + } + ); } function onUncaughtError(error) { @@ -17304,9 +18187,6 @@ function batchedUpdates$1(fn, a) { } 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 @@ -17320,14 +18200,16 @@ function interactiveUpdates$1(fn, a, b) { performWork(lowestPriorityPendingInteractiveExpirationTime, false); lowestPriorityPendingInteractiveExpirationTime = NoWork; } - var previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates; var previousIsBatchingUpdates = isBatchingUpdates; - isBatchingInteractiveUpdates = true; isBatchingUpdates = true; try { - return fn(a, b); + return scheduler.unstable_runWithPriority( + scheduler.unstable_UserBlockingPriority, + function() { + return fn(a, b); + } + ); } finally { - isBatchingInteractiveUpdates = previousIsBatchingInteractiveUpdates; isBatchingUpdates = previousIsBatchingUpdates; if (!isBatchingUpdates && !isRendering) { performSyncWork(); @@ -17555,11 +18437,43 @@ function getPublicRootInstance(container) { } } +var overrideProps = null; + +{ + var copyWithSetImpl = function(obj, path, idx, value) { + if (idx >= path.length) { + return value; + } + var key = path[idx]; + var updated = Array.isArray(obj) ? obj.slice() : Object.assign({}, obj); + // $FlowFixMe number or string is fine here + updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value); + return updated; + }; + + var copyWithSet = function(obj, path, value) { + return copyWithSetImpl(obj, path, 0, value); + }; + + // Support DevTools props for function components, forwardRef, memo, host components, etc. + overrideProps = function(fiber, path, value) { + flushPassiveEffects(); + fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value); + if (fiber.alternate) { + fiber.alternate.pendingProps = fiber.pendingProps; + } + scheduleWork(fiber, Sync); + }; +} + function injectIntoDevTools(devToolsConfig) { var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; + var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; return injectInternals( Object.assign({}, devToolsConfig, { + overrideProps: overrideProps, + currentDispatcherRef: ReactCurrentDispatcher, findHostInstanceByFiber: function(fiber) { var hostFiber = findCurrentHostFiber(fiber); if (hostFiber === null) { @@ -17602,7 +18516,7 @@ function createPortal( // TODO: this is special because it gets imported during build. -var ReactVersion = "16.6.1"; +var ReactVersion = "16.8.1"; // Modules provided by RN: var NativeMethodsMixin = function(findNodeHandle, findHostInstance) { diff --git a/Libraries/Renderer/oss/ReactNativeRenderer-prod.js b/Libraries/Renderer/oss/ReactNativeRenderer-prod.js index e9268b6d2dd2e5..15b71e0ee7633d 100644 --- a/Libraries/Renderer/oss/ReactNativeRenderer-prod.js +++ b/Libraries/Renderer/oss/ReactNativeRenderer-prod.js @@ -1129,8 +1129,10 @@ ResponderEventPlugin.injection.injectGlobalResponderHandler({ } }); var ReactSharedInternals = - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, - hasSymbol = "function" === typeof Symbol && Symbol.for, + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; +ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher") || + (ReactSharedInternals.ReactCurrentDispatcher = { current: null }); +var 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, @@ -1598,6 +1600,10 @@ function setTimeoutCallback() { scheduledCallback = null; null !== callback && callback(); } +function scheduleDeferredCallback$1(callback) { + scheduledCallback = callback; + return setTimeout(setTimeoutCallback, 1); +} function shim$1() { invariant( !1, @@ -1631,8 +1637,24 @@ function finalizeInitialChildren(parentInstance) { return !1; } var scheduleTimeout = setTimeout, - cancelTimeout = clearTimeout, - BEFORE_SLASH_RE = /^(.*)[\\\/]/; + cancelTimeout = clearTimeout; +function commitUpdate(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 + ); +} +var BEFORE_SLASH_RE = /^(.*)[\\\/]/; function getStackByFiberInDevAndProd(workInProgress) { var info = ""; do { @@ -1797,7 +1819,7 @@ function FiberNode(tag, pendingProps, key, mode) { this.index = 0; this.ref = null; this.pendingProps = pendingProps; - this.firstContextDependency = this.memoizedState = this.updateQueue = this.memoizedProps = null; + this.contextDependencies = this.memoizedState = this.updateQueue = this.memoizedProps = null; this.mode = mode; this.effectTag = 0; this.lastEffect = this.firstEffect = this.nextEffect = null; @@ -1846,7 +1868,7 @@ function createWorkInProgress(current, pendingProps) { workInProgress.memoizedProps = current.memoizedProps; workInProgress.memoizedState = current.memoizedState; workInProgress.updateQueue = current.updateQueue; - workInProgress.firstContextDependency = current.firstContextDependency; + workInProgress.contextDependencies = current.contextDependencies; workInProgress.sibling = current.sibling; workInProgress.index = current.index; workInProgress.ref = current.ref; @@ -1970,26 +1992,53 @@ function markPendingPriorityLevel(root, expirationTime) { (root.latestPendingTime = expirationTime); findNextExpirationTimeToWorkOn(expirationTime, root); } +function markCommittedPriorityLevels(root, earliestRemainingTime) { + root.didError = !1; + if (0 === earliestRemainingTime) + (root.earliestPendingTime = 0), + (root.latestPendingTime = 0), + (root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0); + else { + earliestRemainingTime < root.latestPingedTime && + (root.latestPingedTime = 0); + var latestPendingTime = root.latestPendingTime; + 0 !== latestPendingTime && + (latestPendingTime > earliestRemainingTime + ? (root.earliestPendingTime = root.latestPendingTime = 0) + : root.earliestPendingTime > earliestRemainingTime && + (root.earliestPendingTime = root.latestPendingTime)); + latestPendingTime = root.earliestSuspendedTime; + 0 === latestPendingTime + ? markPendingPriorityLevel(root, earliestRemainingTime) + : earliestRemainingTime < root.latestSuspendedTime + ? ((root.earliestSuspendedTime = 0), + (root.latestSuspendedTime = 0), + (root.latestPingedTime = 0), + markPendingPriorityLevel(root, earliestRemainingTime)) + : earliestRemainingTime > latestPendingTime && + markPendingPriorityLevel(root, earliestRemainingTime); + } + findNextExpirationTimeToWorkOn(0, root); +} function markSuspendedPriorityLevel(root, suspendedTime) { root.didError = !1; - var latestPingedTime = root.latestPingedTime; - 0 !== latestPingedTime && - latestPingedTime >= suspendedTime && - (root.latestPingedTime = 0); - latestPingedTime = root.earliestPendingTime; - var latestPendingTime = root.latestPendingTime; - latestPingedTime === suspendedTime + root.latestPingedTime >= suspendedTime && (root.latestPingedTime = 0); + var earliestPendingTime = root.earliestPendingTime, + latestPendingTime = root.latestPendingTime; + earliestPendingTime === suspendedTime ? (root.earliestPendingTime = latestPendingTime === suspendedTime ? (root.latestPendingTime = 0) : latestPendingTime) : latestPendingTime === suspendedTime && - (root.latestPendingTime = latestPingedTime); - latestPingedTime = root.earliestSuspendedTime; + (root.latestPendingTime = earliestPendingTime); + earliestPendingTime = root.earliestSuspendedTime; latestPendingTime = root.latestSuspendedTime; - 0 === latestPingedTime + 0 === earliestPendingTime ? (root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime) - : latestPingedTime < suspendedTime + : earliestPendingTime < suspendedTime ? (root.earliestSuspendedTime = suspendedTime) : latestPendingTime > suspendedTime && (root.latestSuspendedTime = suspendedTime); @@ -2021,394 +2070,81 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) { root.nextExpirationTimeToWorkOn = earliestPendingTime; root.expirationTime = completedExpirationTime; } -var hasForceUpdate = !1; -function createUpdateQueue(baseState) { - return { - baseState: baseState, - firstUpdate: null, - lastUpdate: null, - firstCapturedUpdate: null, - lastCapturedUpdate: null, - firstEffect: null, - lastEffect: null, - firstCapturedEffect: null, - lastCapturedEffect: null - }; -} -function cloneUpdateQueue(currentQueue) { - return { - 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) { - null === queue.lastUpdate - ? (queue.firstUpdate = queue.lastUpdate = update) - : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); -} -function enqueueUpdate(fiber, update) { - 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) - : null === queue1.lastUpdate || null === queue2.lastUpdate - ? (appendUpdateToQueue(queue1, update), - appendUpdateToQueue(queue2, update)) - : (appendUpdateToQueue(queue1, update), (queue2.lastUpdate = update)); +function is(x, y) { + return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); } -function enqueueCapturedUpdate(workInProgress, update) { - 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)); +var hasOwnProperty = Object.prototype.hasOwnProperty; +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 ensureWorkInProgressQueueIsAClone(workInProgress, queue) { - var current = workInProgress.alternate; - null !== current && - queue === current.updateQueue && - (queue = workInProgress.updateQueue = cloneUpdateQueue(queue)); - return queue; +function resolveDefaultProps(Component, baseProps) { + if (Component && Component.defaultProps) { + baseProps = Object.assign({}, baseProps); + Component = Component.defaultProps; + for (var propName in Component) + void 0 === baseProps[propName] && + (baseProps[propName] = Component[propName]); + } + return baseProps; } -function getStateFromUpdate( - workInProgress, - queue, - update, - prevState, - nextProps, - instance -) { - switch (update.tag) { +function readLazyComponentType(lazyComponent) { + var result = lazyComponent._result; + switch (lazyComponent._status) { case 1: - return ( - (workInProgress = update.payload), - "function" === typeof workInProgress - ? workInProgress.call(instance, prevState, nextProps) - : workInProgress - ); - case 3: - workInProgress.effectTag = (workInProgress.effectTag & -2049) | 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); + return result; case 2: - hasForceUpdate = !0; + throw result; + case 0: + throw result; + default: + lazyComponent._status = 0; + result = lazyComponent._ctor; + result = result(); + result.then( + function(moduleObject) { + 0 === lazyComponent._status && + ((moduleObject = moduleObject.default), + (lazyComponent._status = 1), + (lazyComponent._result = moduleObject)); + }, + function(error) { + 0 === lazyComponent._status && + ((lazyComponent._status = 2), (lazyComponent._result = error)); + } + ); + switch (lazyComponent._status) { + case 1: + return lazyComponent._result; + case 2: + throw lazyComponent._result; + } + lazyComponent._result = result; + throw result; } - return prevState; } -function processUpdateQueue( +var emptyRefsObject = new React.Component().refs; +function applyDerivedStateFromProps( workInProgress, - queue, - props, - instance, - renderExpirationTime -) { - hasForceUpdate = !1; - queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); - for ( - var newBaseState = queue.baseState, - newFirstUpdate = null, - newExpirationTime = 0, - update = queue.firstUpdate, - resultState = newBaseState; - null !== update; - - ) { - var updateExpirationTime = update.expirationTime; - updateExpirationTime < renderExpirationTime - ? (null === newFirstUpdate && - ((newFirstUpdate = update), (newBaseState = resultState)), - newExpirationTime < updateExpirationTime && - (newExpirationTime = updateExpirationTime)) - : ((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; - _updateExpirationTime < renderExpirationTime - ? (null === updateExpirationTime && - ((updateExpirationTime = update), - null === newFirstUpdate && (newBaseState = resultState)), - newExpirationTime < _updateExpirationTime && - (newExpirationTime = _updateExpirationTime)) - : ((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; - workInProgress.expirationTime = newExpirationTime; - workInProgress.memoizedState = resultState; -} -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)); - commitUpdateEffects(finishedQueue.firstEffect, instance); - finishedQueue.firstEffect = finishedQueue.lastEffect = null; - commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); - finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; -} -function commitUpdateEffects(effect, instance) { - for (; null !== effect; ) { - var _callback3 = effect.callback; - if (null !== _callback3) { - effect.callback = null; - var context = instance; - invariant( - "function" === typeof _callback3, - "Invalid argument passed as callback. Expected a function. Instead received: %s", - _callback3 - ); - _callback3.call(context); - } - effect = effect.nextEffect; - } -} -function createCapturedValue(value, source) { - return { - value: value, - source: source, - stack: getStackByFiberInDevAndProd(source) - }; -} -var valueCursor = { current: null }, - currentlyRenderingFiber = null, - lastContextDependency = null, - lastContextWithAllBitsObserved = null; -function pushProvider(providerFiber, nextValue) { - var context = providerFiber.type._context; - push(valueCursor, context._currentValue, providerFiber); - context._currentValue = nextValue; -} -function popProvider(providerFiber) { - var currentValue = valueCursor.current; - pop(valueCursor, providerFiber); - providerFiber.type._context._currentValue = currentValue; -} -function prepareToReadContext(workInProgress) { - currentlyRenderingFiber = workInProgress; - lastContextWithAllBitsObserved = lastContextDependency = null; - workInProgress.firstContextDependency = null; -} -function readContext(context, observedBits) { - if ( - lastContextWithAllBitsObserved !== context && - !1 !== observedBits && - 0 !== observedBits - ) { - if ("number" !== typeof observedBits || 1073741823 === observedBits) - (lastContextWithAllBitsObserved = context), (observedBits = 1073741823); - observedBits = { context: context, observedBits: observedBits, next: null }; - null === lastContextDependency - ? (invariant( - null !== currentlyRenderingFiber, - "Context can only be read while React is rendering, e.g. inside the render method or getDerivedStateFromProps." - ), - (currentlyRenderingFiber.firstContextDependency = lastContextDependency = observedBits)) - : (lastContextDependency = lastContextDependency.next = observedBits); - } - return context._currentValue; -} -var NO_CONTEXT = {}, - contextStackCursor$1 = { current: NO_CONTEXT }, - contextFiberStackCursor = { current: NO_CONTEXT }, - rootInstanceStackCursor = { current: 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 pushHostContext(fiber) { - requiredContext(rootInstanceStackCursor.current); - var context = requiredContext(contextStackCursor$1.current); - var nextContext = fiber.type; - nextContext = - "AndroidTextInput" === nextContext || - "RCTMultilineTextInputView" === nextContext || - "RCTSinglelineTextInputView" === nextContext || - "RCTText" === nextContext || - "RCTVirtualText" === nextContext; - nextContext = - context.isInAParentText !== nextContext - ? { isInAParentText: nextContext } - : context; - context !== nextContext && - (push(contextFiberStackCursor, fiber, fiber), - push(contextStackCursor$1, nextContext, 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 resolveDefaultProps(Component, baseProps) { - if (Component && Component.defaultProps) { - baseProps = Object.assign({}, baseProps); - Component = Component.defaultProps; - for (var propName in Component) - void 0 === baseProps[propName] && - (baseProps[propName] = Component[propName]); - } - return baseProps; -} -function readLazyComponentType(lazyComponent) { - var result = lazyComponent._result; - switch (lazyComponent._status) { - case 1: - return result; - case 2: - throw result; - case 0: - throw result; - default: - throw ((lazyComponent._status = 0), - (result = lazyComponent._ctor), - (result = result()), - result.then( - function(moduleObject) { - 0 === lazyComponent._status && - ((moduleObject = moduleObject.default), - (lazyComponent._status = 1), - (lazyComponent._result = moduleObject)); - }, - function(error) { - 0 === lazyComponent._status && - ((lazyComponent._status = 2), (lazyComponent._result = error)); - } - ), - (lazyComponent._result = result), - result); - } -} -var ReactCurrentOwner$4 = ReactSharedInternals.ReactCurrentOwner, - emptyRefsObject = new React.Component().refs; -function applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - nextProps + ctor, + getDerivedStateFromProps, + nextProps ) { ctor = workInProgress.memoizedState; getDerivedStateFromProps = getDerivedStateFromProps(nextProps, ctor); @@ -2444,7 +2180,7 @@ var classComponentUpdater = { var currentTime = requestCurrentTime(); currentTime = computeExpirationForFiber(currentTime, inst); var update = createUpdate(currentTime); - update.tag = 1; + update.tag = ReplaceState; update.payload = payload; void 0 !== callback && null !== callback && (update.callback = callback); flushPassiveEffects(); @@ -2456,7 +2192,7 @@ var classComponentUpdater = { var currentTime = requestCurrentTime(); currentTime = computeExpirationForFiber(currentTime, inst); var update = createUpdate(currentTime); - update.tag = 2; + update.tag = ForceUpdate; void 0 !== callback && null !== callback && (update.callback = callback); flushPassiveEffects(); enqueueUpdate(inst, update); @@ -2484,7 +2220,7 @@ function constructClassInstance(workInProgress, ctor, props) { unmaskedContext = emptyContextObject; var context = ctor.contextType; "object" === typeof context && null !== context - ? (context = ReactCurrentOwner$4.currentDispatcher.readContext(context)) + ? (context = readContext(context)) : ((unmaskedContext = isContextProvider(ctor) ? previousContext : contextStackCursor.current), @@ -2531,9 +2267,7 @@ function mountClassInstance( instance.refs = emptyRefsObject; var contextType = ctor.contextType; "object" === typeof contextType && null !== contextType - ? (instance.context = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (instance.context = readContext(contextType)) : ((contextType = isContextProvider(ctor) ? previousContext : contextStackCursor.current), @@ -2588,7 +2322,10 @@ function coerceRef(returnFiber, current$$1, element) { element = element._owner; var inst = void 0; element && - (invariant(1 === element.tag, "Function components cannot have refs."), + (invariant( + 1 === element.tag, + "Function components cannot have refs. Did you mean to use React.forwardRef()?" + ), (inst = element.stateNode)); invariant( inst, @@ -3288,69 +3025,574 @@ function ChildReconciler(shouldTrackSideEffects) { } 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; - } + NO_CONTEXT = {}, + contextStackCursor$1 = { current: NO_CONTEXT }, + contextFiberStackCursor = { current: NO_CONTEXT }, + rootInstanceStackCursor = { current: 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 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 = createFiber(5, null, null, 0); - fiber.elementType = "DELETED"; - 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 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); } -var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner; -function reconcileChildren( - current$$1, - workInProgress, - nextChildren, - renderExpirationTime -) { - workInProgress.child = - null === current$$1 - ? mountChildFibers( - workInProgress, +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} +function pushHostContext(fiber) { + requiredContext(rootInstanceStackCursor.current); + var context = requiredContext(contextStackCursor$1.current); + var nextContext = fiber.type; + nextContext = + "AndroidTextInput" === nextContext || + "RCTMultilineTextInputView" === nextContext || + "RCTSinglelineTextInputView" === nextContext || + "RCTText" === nextContext || + "RCTVirtualText" === nextContext; + nextContext = + context.isInAParentText !== nextContext + ? { isInAParentText: nextContext } + : context; + context !== nextContext && + (push(contextFiberStackCursor, fiber, fiber), + push(contextStackCursor$1, nextContext, fiber)); +} +function popHostContext(fiber) { + contextFiberStackCursor.current === fiber && + (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); +} +var NoEffect$1 = 0, + UnmountSnapshot = 2, + UnmountMutation = 4, + MountMutation = 8, + UnmountLayout = 16, + MountLayout = 32, + MountPassive = 64, + UnmountPassive = 128, + ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher, + renderExpirationTime = 0, + currentlyRenderingFiber$1 = null, + currentHook = null, + nextCurrentHook = null, + firstWorkInProgressHook = null, + workInProgressHook = null, + nextWorkInProgressHook = null, + remainingExpirationTime = 0, + componentUpdateQueue = null, + sideEffectTag = 0, + didScheduleRenderPhaseUpdate = !1, + renderPhaseUpdates = null, + numberOfReRenders = 0; +function throwInvalidHookError() { + invariant( + !1, + "Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)" + ); +} +function areHookInputsEqual(nextDeps, prevDeps) { + if (null === prevDeps) return !1; + for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) + if (!is(nextDeps[i], prevDeps[i])) return !1; + return !0; +} +function renderWithHooks( + current, + workInProgress, + Component, + props, + refOrContext, + nextRenderExpirationTime +) { + renderExpirationTime = nextRenderExpirationTime; + currentlyRenderingFiber$1 = workInProgress; + nextCurrentHook = null !== current ? current.memoizedState : null; + ReactCurrentDispatcher$1.current = + null === nextCurrentHook ? HooksDispatcherOnMount : HooksDispatcherOnUpdate; + workInProgress = Component(props, refOrContext); + if (didScheduleRenderPhaseUpdate) { + do + (didScheduleRenderPhaseUpdate = !1), + (numberOfReRenders += 1), + (nextCurrentHook = null !== current ? current.memoizedState : null), + (nextWorkInProgressHook = firstWorkInProgressHook), + (componentUpdateQueue = workInProgressHook = currentHook = null), + (ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdate), + (workInProgress = Component(props, refOrContext)); + while (didScheduleRenderPhaseUpdate); + renderPhaseUpdates = null; + numberOfReRenders = 0; + } + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + current = currentlyRenderingFiber$1; + current.memoizedState = firstWorkInProgressHook; + current.expirationTime = remainingExpirationTime; + current.updateQueue = componentUpdateQueue; + current.effectTag |= sideEffectTag; + current = null !== currentHook && null !== currentHook.next; + renderExpirationTime = 0; + nextWorkInProgressHook = workInProgressHook = firstWorkInProgressHook = nextCurrentHook = currentHook = currentlyRenderingFiber$1 = null; + remainingExpirationTime = 0; + componentUpdateQueue = null; + sideEffectTag = 0; + invariant( + !current, + "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." + ); + return workInProgress; +} +function resetHooks() { + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + renderExpirationTime = 0; + nextWorkInProgressHook = workInProgressHook = firstWorkInProgressHook = nextCurrentHook = currentHook = currentlyRenderingFiber$1 = null; + remainingExpirationTime = 0; + componentUpdateQueue = null; + sideEffectTag = 0; + didScheduleRenderPhaseUpdate = !1; + renderPhaseUpdates = null; + numberOfReRenders = 0; +} +function mountWorkInProgressHook() { + var hook = { + memoizedState: null, + baseState: null, + queue: null, + baseUpdate: null, + next: null + }; + null === workInProgressHook + ? (firstWorkInProgressHook = workInProgressHook = hook) + : (workInProgressHook = workInProgressHook.next = hook); + return workInProgressHook; +} +function updateWorkInProgressHook() { + if (null !== nextWorkInProgressHook) + (workInProgressHook = nextWorkInProgressHook), + (nextWorkInProgressHook = workInProgressHook.next), + (currentHook = nextCurrentHook), + (nextCurrentHook = null !== currentHook ? currentHook.next : null); + else { + invariant( + null !== nextCurrentHook, + "Rendered more hooks than during the previous render." + ); + currentHook = nextCurrentHook; + var newHook = { + memoizedState: currentHook.memoizedState, + baseState: currentHook.baseState, + queue: currentHook.queue, + baseUpdate: currentHook.baseUpdate, + next: null + }; + workInProgressHook = + null === workInProgressHook + ? (firstWorkInProgressHook = newHook) + : (workInProgressHook.next = newHook); + nextCurrentHook = currentHook.next; + } + return workInProgressHook; +} +function basicStateReducer(state, action) { + return "function" === typeof action ? action(state) : action; +} +function updateReducer(reducer) { + var hook = updateWorkInProgressHook(), + queue = hook.queue; + invariant( + null !== queue, + "Should have a queue. This is likely a bug in React. Please file an issue." + ); + if (0 < numberOfReRenders) { + var _dispatch = queue.dispatch; + if (null !== renderPhaseUpdates) { + var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); + if (void 0 !== firstRenderPhaseUpdate) { + renderPhaseUpdates.delete(queue); + var newState = hook.memoizedState; + do + (newState = reducer(newState, firstRenderPhaseUpdate.action)), + (firstRenderPhaseUpdate = firstRenderPhaseUpdate.next); + while (null !== firstRenderPhaseUpdate); + is(newState, hook.memoizedState) || (didReceiveUpdate = !0); + hook.memoizedState = newState; + hook.baseUpdate === queue.last && (hook.baseState = newState); + return [newState, _dispatch]; + } + } + return [hook.memoizedState, _dispatch]; + } + _dispatch = queue.last; + var baseUpdate = hook.baseUpdate; + newState = hook.baseState; + null !== baseUpdate + ? (null !== _dispatch && (_dispatch.next = null), + (_dispatch = baseUpdate.next)) + : (_dispatch = null !== _dispatch ? _dispatch.next : null); + if (null !== _dispatch) { + var newBaseUpdate = (firstRenderPhaseUpdate = null), + _update = _dispatch, + didSkip = !1; + do { + var updateExpirationTime = _update.expirationTime; + updateExpirationTime < renderExpirationTime + ? (didSkip || + ((didSkip = !0), + (newBaseUpdate = baseUpdate), + (firstRenderPhaseUpdate = newState)), + updateExpirationTime > remainingExpirationTime && + (remainingExpirationTime = updateExpirationTime)) + : (newState = + _update.eagerReducer === reducer + ? _update.eagerState + : reducer(newState, _update.action)); + baseUpdate = _update; + _update = _update.next; + } while (null !== _update && _update !== _dispatch); + didSkip || + ((newBaseUpdate = baseUpdate), (firstRenderPhaseUpdate = newState)); + is(newState, hook.memoizedState) || (didReceiveUpdate = !0); + hook.memoizedState = newState; + hook.baseUpdate = newBaseUpdate; + hook.baseState = firstRenderPhaseUpdate; + queue.eagerReducer = reducer; + queue.eagerState = newState; + } + return [hook.memoizedState, queue.dispatch]; +} +function pushEffect(tag, create, destroy, deps) { + tag = { tag: tag, create: create, destroy: destroy, deps: deps, next: null }; + null === componentUpdateQueue + ? ((componentUpdateQueue = { lastEffect: null }), + (componentUpdateQueue.lastEffect = tag.next = tag)) + : ((create = componentUpdateQueue.lastEffect), + null === create + ? (componentUpdateQueue.lastEffect = tag.next = tag) + : ((destroy = create.next), + (create.next = tag), + (tag.next = destroy), + (componentUpdateQueue.lastEffect = tag))); + return tag; +} +function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = mountWorkInProgressHook(); + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect( + hookEffectTag, + create, + void 0, + void 0 === deps ? null : deps + ); +} +function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var destroy = void 0; + if (null !== currentHook) { + var prevEffect = currentHook.memoizedState; + destroy = prevEffect.destroy; + if (null !== deps && areHookInputsEqual(deps, prevEffect.deps)) { + pushEffect(NoEffect$1, create, destroy, deps); + return; + } + } + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect(hookEffectTag, create, destroy, deps); +} +function imperativeHandleEffect(create, ref) { + if ("function" === typeof ref) + return ( + (create = create()), + ref(create), + function() { + ref(null); + } + ); + if (null !== ref && void 0 !== ref) + return ( + (create = create()), + (ref.current = create), + function() { + ref.current = null; + } + ); +} +function mountDebugValue() {} +function dispatchAction(fiber, queue, action) { + invariant( + 25 > numberOfReRenders, + "Too many re-renders. React limits the number of renders to prevent an infinite loop." + ); + var alternate = fiber.alternate; + if ( + fiber === currentlyRenderingFiber$1 || + (null !== alternate && alternate === currentlyRenderingFiber$1) + ) + if ( + ((didScheduleRenderPhaseUpdate = !0), + (fiber = { + expirationTime: renderExpirationTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }), + null === renderPhaseUpdates && (renderPhaseUpdates = new Map()), + (action = renderPhaseUpdates.get(queue)), + void 0 === action) + ) + renderPhaseUpdates.set(queue, fiber); + else { + for (queue = action; null !== queue.next; ) queue = queue.next; + queue.next = fiber; + } + else { + flushPassiveEffects(); + var currentTime = requestCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, fiber); + var _update2 = { + expirationTime: currentTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }, + _last = queue.last; + if (null === _last) _update2.next = _update2; + else { + var first = _last.next; + null !== first && (_update2.next = first); + _last.next = _update2; + } + queue.last = _update2; + if ( + 0 === fiber.expirationTime && + (null === alternate || 0 === alternate.expirationTime) && + ((alternate = queue.eagerReducer), null !== alternate) + ) + try { + var currentState = queue.eagerState, + _eagerState = alternate(currentState, action); + _update2.eagerReducer = alternate; + _update2.eagerState = _eagerState; + if (is(_eagerState, currentState)) return; + } catch (error) { + } finally { + } + scheduleWork(fiber, currentTime); + } +} +var ContextOnlyDispatcher = { + readContext: readContext, + useCallback: throwInvalidHookError, + useContext: throwInvalidHookError, + useEffect: throwInvalidHookError, + useImperativeHandle: throwInvalidHookError, + useLayoutEffect: throwInvalidHookError, + useMemo: throwInvalidHookError, + useReducer: throwInvalidHookError, + useRef: throwInvalidHookError, + useState: throwInvalidHookError, + useDebugValue: throwInvalidHookError + }, + HooksDispatcherOnMount = { + readContext: readContext, + useCallback: function(callback, deps) { + mountWorkInProgressHook().memoizedState = [ + callback, + void 0 === deps ? null : deps + ]; + return callback; + }, + useContext: readContext, + useEffect: function(create, deps) { + return mountEffectImpl(516, UnmountPassive | MountPassive, create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + deps = null !== deps && void 0 !== deps ? deps.concat([ref]) : [ref]; + return mountEffectImpl( + 4, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + deps + ); + }, + useLayoutEffect: function(create, deps) { + return mountEffectImpl(4, UnmountMutation | MountLayout, create, deps); + }, + useMemo: function(nextCreate, deps) { + var hook = mountWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + nextCreate = nextCreate(); + hook.memoizedState = [nextCreate, deps]; + return nextCreate; + }, + useReducer: function(reducer, initialArg, init) { + var hook = mountWorkInProgressHook(); + initialArg = void 0 !== init ? init(initialArg) : initialArg; + hook.memoizedState = hook.baseState = initialArg; + reducer = hook.queue = { + last: null, + dispatch: null, + eagerReducer: reducer, + eagerState: initialArg + }; + reducer = reducer.dispatch = dispatchAction.bind( + null, + currentlyRenderingFiber$1, + reducer + ); + return [hook.memoizedState, reducer]; + }, + useRef: function(initialValue) { + var hook = mountWorkInProgressHook(); + initialValue = { current: initialValue }; + return (hook.memoizedState = initialValue); + }, + useState: function(initialState) { + var hook = mountWorkInProgressHook(); + "function" === typeof initialState && (initialState = initialState()); + hook.memoizedState = hook.baseState = initialState; + initialState = hook.queue = { + last: null, + dispatch: null, + eagerReducer: basicStateReducer, + eagerState: initialState + }; + initialState = initialState.dispatch = dispatchAction.bind( + null, + currentlyRenderingFiber$1, + initialState + ); + return [hook.memoizedState, initialState]; + }, + useDebugValue: mountDebugValue + }, + HooksDispatcherOnUpdate = { + readContext: readContext, + useCallback: function(callback, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var prevState = hook.memoizedState; + if ( + null !== prevState && + null !== deps && + areHookInputsEqual(deps, prevState[1]) + ) + return prevState[0]; + hook.memoizedState = [callback, deps]; + return callback; + }, + useContext: readContext, + useEffect: function(create, deps) { + return updateEffectImpl(516, UnmountPassive | MountPassive, create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + deps = null !== deps && void 0 !== deps ? deps.concat([ref]) : [ref]; + return updateEffectImpl( + 4, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + deps + ); + }, + useLayoutEffect: function(create, deps) { + return updateEffectImpl(4, UnmountMutation | MountLayout, create, deps); + }, + useMemo: function(nextCreate, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var prevState = hook.memoizedState; + if ( + null !== prevState && + null !== deps && + areHookInputsEqual(deps, prevState[1]) + ) + return prevState[0]; + nextCreate = nextCreate(); + hook.memoizedState = [nextCreate, deps]; + return nextCreate; + }, + useReducer: updateReducer, + useRef: function() { + return updateWorkInProgressHook().memoizedState; + }, + useState: function(initialState) { + return updateReducer(basicStateReducer, initialState); + }, + useDebugValue: mountDebugValue + }, + 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 = createFiber(5, null, null, 0); + fiber.elementType = "DELETED"; + 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); + } +} +var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner, + didReceiveUpdate = !1; +function reconcileChildren( + current$$1, + workInProgress, + nextChildren, + renderExpirationTime +) { + workInProgress.child = + null === current$$1 + ? mountChildFibers( + workInProgress, null, nextChildren, renderExpirationTime @@ -3372,7 +3614,26 @@ function updateForwardRef( Component = Component.render; var ref = workInProgress.ref; prepareToReadContext(workInProgress, renderExpirationTime); - nextProps = Component(nextProps, ref); + nextProps = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + ref, + renderExpirationTime + ); + if (null !== current$$1 && !didReceiveUpdate) + return ( + (workInProgress.updateQueue = current$$1.updateQueue), + (workInProgress.effectTag &= -517), + current$$1.expirationTime <= renderExpirationTime && + (current$$1.expirationTime = 0), + bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ) + ); workInProgress.effectTag |= 1; reconcileChildren( current$$1, @@ -3452,9 +3713,9 @@ function updateSimpleMemoComponent( renderExpirationTime ) { return null !== current$$1 && - updateExpirationTime < renderExpirationTime && shallowEqual(current$$1.memoizedProps, nextProps) && - current$$1.ref === workInProgress.ref + current$$1.ref === workInProgress.ref && + ((didReceiveUpdate = !1), updateExpirationTime < renderExpirationTime) ? bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -3488,7 +3749,26 @@ function updateFunctionComponent( : contextStackCursor.current; unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); prepareToReadContext(workInProgress, renderExpirationTime); - Component = Component(nextProps, unmaskedContext); + Component = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + unmaskedContext, + renderExpirationTime + ); + if (null !== current$$1 && !didReceiveUpdate) + return ( + (workInProgress.updateQueue = current$$1.updateQueue), + (workInProgress.effectTag &= -517), + current$$1.expirationTime <= renderExpirationTime && + (current$$1.expirationTime = 0), + bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ) + ); workInProgress.effectTag |= 1; reconcileChildren( current$$1, @@ -3535,9 +3815,7 @@ function updateClassComponent( var oldContext = instance.context, contextType = Component.contextType; "object" === typeof contextType && null !== contextType - ? (contextType = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (contextType = readContext(contextType)) : ((contextType = isContextProvider(Component) ? previousContext : contextStackCursor.current), @@ -3622,9 +3900,7 @@ function updateClassComponent( (oldContext = instance.context), (contextType = Component.contextType), "object" === typeof contextType && null !== contextType - ? (contextType = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (contextType = readContext(contextType)) : ((contextType = isContextProvider(Component) ? previousContext : contextStackCursor.current), @@ -3805,33 +4081,35 @@ function updateSuspenseComponent( (nextState = { timedOutAt: null !== nextState ? nextState.timedOutAt : 0 }), (nextDidTimeout = !0), (workInProgress.effectTag &= -65); - null === current$$1 - ? nextDidTimeout - ? ((nextDidTimeout = nextProps.fallback), - (nextProps = createFiberFromFragment(null, mode, 0, null)), - 0 === (workInProgress.mode & 1) && - (nextProps.child = - null !== workInProgress.memoizedState - ? workInProgress.child.child - : workInProgress.child), - (mode = createFiberFromFragment( - nextDidTimeout, - mode, - renderExpirationTime, - null - )), - (nextProps.sibling = mode), - (renderExpirationTime = nextProps), - (renderExpirationTime.return = mode.return = workInProgress)) - : (renderExpirationTime = mode = mountChildFibers( - workInProgress, - null, - nextProps.children, - renderExpirationTime - )) - : null !== current$$1.memoizedState + if (null === current$$1) + if (nextDidTimeout) { + var nextFallbackChildren = nextProps.fallback; + current$$1 = createFiberFromFragment(null, mode, 0, null); + 0 === (workInProgress.mode & 1) && + (current$$1.child = + null !== workInProgress.memoizedState + ? workInProgress.child.child + : workInProgress.child); + mode = createFiberFromFragment( + nextFallbackChildren, + mode, + renderExpirationTime, + null + ); + current$$1.sibling = mode; + renderExpirationTime = current$$1; + renderExpirationTime.return = mode.return = workInProgress; + } else + renderExpirationTime = mode = mountChildFibers( + workInProgress, + null, + nextProps.children, + renderExpirationTime + ); + else + null !== current$$1.memoizedState ? ((mode = current$$1.child), - (current$$1 = mode.sibling), + (nextFallbackChildren = mode.sibling), nextDidTimeout ? ((renderExpirationTime = nextProps.fallback), (nextProps = createWorkInProgress(mode, mode.pendingProps, 0)), @@ -3843,9 +4121,9 @@ function updateSuspenseComponent( nextDidTimeout !== mode.child && (nextProps.child = nextDidTimeout)), (mode = nextProps.sibling = createWorkInProgress( - current$$1, + nextFallbackChildren, renderExpirationTime, - current$$1.expirationTime + nextFallbackChildren.expirationTime )), (renderExpirationTime = nextProps), (nextProps.childExpirationTime = 0), @@ -3856,11 +4134,11 @@ function updateSuspenseComponent( nextProps.children, renderExpirationTime ))) - : ((current$$1 = current$$1.child), + : ((nextFallbackChildren = current$$1.child), nextDidTimeout ? ((nextDidTimeout = nextProps.fallback), (nextProps = createFiberFromFragment(null, mode, 0, null)), - (nextProps.child = current$$1), + (nextProps.child = nextFallbackChildren), 0 === (workInProgress.mode & 1) && (nextProps.child = null !== workInProgress.memoizedState @@ -3878,10 +4156,11 @@ function updateSuspenseComponent( (renderExpirationTime.return = mode.return = workInProgress)) : (mode = renderExpirationTime = reconcileChildFibers( workInProgress, - current$$1, + nextFallbackChildren, nextProps.children, renderExpirationTime - ))); + ))), + (workInProgress.stateNode = current$$1.stateNode); workInProgress.memoizedState = nextState; workInProgress.child = renderExpirationTime; return mode; @@ -3892,7 +4171,7 @@ function bailoutOnAlreadyFinishedWork( renderExpirationTime ) { null !== current$$1 && - (workInProgress.firstContextDependency = current$$1.firstContextDependency); + (workInProgress.contextDependencies = current$$1.contextDependencies); if (workInProgress.childExpirationTime < renderExpirationTime) return null; invariant( null === current$$1 || workInProgress.child === current$$1.child, @@ -3924,58 +4203,63 @@ function bailoutOnAlreadyFinishedWork( } function beginWork(current$$1, workInProgress, renderExpirationTime) { var updateExpirationTime = workInProgress.expirationTime; - if ( - null !== current$$1 && - current$$1.memoizedProps === workInProgress.pendingProps && - !didPerformWorkStackCursor.current && - updateExpirationTime < renderExpirationTime - ) { - switch (workInProgress.tag) { - case 3: - pushHostRootContext(workInProgress); - break; - case 5: - pushHostContext(workInProgress); - break; - case 1: - isContextProvider(workInProgress.type) && - pushContextProvider(workInProgress); - break; - case 4: - pushHostContainer( - workInProgress, - workInProgress.stateNode.containerInfo - ); - break; - case 10: - pushProvider(workInProgress, workInProgress.memoizedProps.value); - break; - case 13: - if (null !== workInProgress.memoizedState) { - updateExpirationTime = workInProgress.child.childExpirationTime; - if ( - 0 !== updateExpirationTime && - updateExpirationTime >= renderExpirationTime - ) - return updateSuspenseComponent( - current$$1, - workInProgress, - renderExpirationTime + if (null !== current$$1) + if ( + current$$1.memoizedProps !== workInProgress.pendingProps || + didPerformWorkStackCursor.current + ) + didReceiveUpdate = !0; + else { + if (updateExpirationTime < renderExpirationTime) { + didReceiveUpdate = !1; + switch (workInProgress.tag) { + case 3: + pushHostRootContext(workInProgress); + break; + case 5: + pushHostContext(workInProgress); + break; + case 1: + isContextProvider(workInProgress.type) && + pushContextProvider(workInProgress); + break; + case 4: + pushHostContainer( + workInProgress, + workInProgress.stateNode.containerInfo ); - workInProgress = bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); - return null !== workInProgress ? workInProgress.sibling : null; + break; + case 10: + pushProvider(workInProgress, workInProgress.memoizedProps.value); + break; + case 13: + if (null !== workInProgress.memoizedState) { + updateExpirationTime = workInProgress.child.childExpirationTime; + if ( + 0 !== updateExpirationTime && + updateExpirationTime >= renderExpirationTime + ) + return updateSuspenseComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress = bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + return null !== workInProgress ? workInProgress.sibling : null; + } } + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } } - return bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); - } + else didReceiveUpdate = !1; workInProgress.expirationTime = 0; switch (workInProgress.tag) { case 2: @@ -3990,7 +4274,14 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = updateExpirationTime(current$$1, context); + context = renderWithHooks( + null, + workInProgress, + updateExpirationTime, + current$$1, + context, + renderExpirationTime + ); workInProgress.effectTag |= 1; if ( "object" === typeof context && @@ -3999,6 +4290,7 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { void 0 === context.$$typeof ) { workInProgress.tag = 1; + resetHooks(); if (isContextProvider(updateExpirationTime)) { var hasContext = !0; pushContextProvider(workInProgress); @@ -4270,18 +4562,14 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; - hasContext = - (oldValue === hasContext && - (0 !== oldValue || 1 / oldValue === 1 / hasContext)) || - (oldValue !== oldValue && hasContext !== hasContext) - ? 0 - : ("function" === - typeof updateExpirationTime._calculateChangedBits - ? updateExpirationTime._calculateChangedBits( - oldValue, - hasContext - ) - : 1073741823) | 0; + hasContext = is(oldValue, hasContext) + ? 0 + : ("function" === typeof updateExpirationTime._calculateChangedBits + ? updateExpirationTime._calculateChangedBits( + oldValue, + hasContext + ) + : 1073741823) | 0; if (0 === hasContext) { if ( getDerivedStateFromProps.children === context.children && @@ -4296,83 +4584,79 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { } } else for ( - getDerivedStateFromProps = workInProgress.child, - null !== getDerivedStateFromProps && - (getDerivedStateFromProps.return = workInProgress); - null !== getDerivedStateFromProps; + oldValue = workInProgress.child, + null !== oldValue && (oldValue.return = workInProgress); + null !== oldValue; ) { - oldValue = getDerivedStateFromProps.firstContextDependency; - if (null !== oldValue) { - do { + var list = oldValue.contextDependencies; + if (null !== list) { + getDerivedStateFromProps = oldValue.child; + for (var dependency = list.first; null !== dependency; ) { if ( - oldValue.context === updateExpirationTime && - 0 !== (oldValue.observedBits & hasContext) + dependency.context === updateExpirationTime && + 0 !== (dependency.observedBits & hasContext) ) { - if (1 === getDerivedStateFromProps.tag) { - var nextFiber = createUpdate(renderExpirationTime); - nextFiber.tag = 2; - enqueueUpdate(getDerivedStateFromProps, nextFiber); - } - getDerivedStateFromProps.expirationTime < - renderExpirationTime && - (getDerivedStateFromProps.expirationTime = renderExpirationTime); - nextFiber = getDerivedStateFromProps.alternate; - null !== nextFiber && - nextFiber.expirationTime < renderExpirationTime && - (nextFiber.expirationTime = renderExpirationTime); - for ( - var node = getDerivedStateFromProps.return; - null !== node; - - ) { - nextFiber = node.alternate; + 1 === oldValue.tag && + ((dependency = createUpdate(renderExpirationTime)), + (dependency.tag = ForceUpdate), + enqueueUpdate(oldValue, dependency)); + oldValue.expirationTime < renderExpirationTime && + (oldValue.expirationTime = renderExpirationTime); + dependency = oldValue.alternate; + null !== dependency && + dependency.expirationTime < renderExpirationTime && + (dependency.expirationTime = renderExpirationTime); + for (var node = oldValue.return; null !== node; ) { + dependency = node.alternate; if (node.childExpirationTime < renderExpirationTime) (node.childExpirationTime = renderExpirationTime), - null !== nextFiber && - nextFiber.childExpirationTime < + null !== dependency && + dependency.childExpirationTime < renderExpirationTime && - (nextFiber.childExpirationTime = renderExpirationTime); + (dependency.childExpirationTime = renderExpirationTime); else if ( - null !== nextFiber && - nextFiber.childExpirationTime < renderExpirationTime + null !== dependency && + dependency.childExpirationTime < renderExpirationTime ) - nextFiber.childExpirationTime = renderExpirationTime; + dependency.childExpirationTime = renderExpirationTime; else break; node = node.return; } + list.expirationTime < renderExpirationTime && + (list.expirationTime = renderExpirationTime); + break; } - nextFiber = getDerivedStateFromProps.child; - oldValue = oldValue.next; - } while (null !== oldValue); + dependency = dependency.next; + } } else - nextFiber = - 10 === getDerivedStateFromProps.tag - ? getDerivedStateFromProps.type === workInProgress.type + getDerivedStateFromProps = + 10 === oldValue.tag + ? oldValue.type === workInProgress.type ? null - : getDerivedStateFromProps.child - : getDerivedStateFromProps.child; - if (null !== nextFiber) - nextFiber.return = getDerivedStateFromProps; + : oldValue.child + : oldValue.child; + if (null !== getDerivedStateFromProps) + getDerivedStateFromProps.return = oldValue; else for ( - nextFiber = getDerivedStateFromProps; - null !== nextFiber; + getDerivedStateFromProps = oldValue; + null !== getDerivedStateFromProps; ) { - if (nextFiber === workInProgress) { - nextFiber = null; + if (getDerivedStateFromProps === workInProgress) { + getDerivedStateFromProps = null; break; } - getDerivedStateFromProps = nextFiber.sibling; - if (null !== getDerivedStateFromProps) { - getDerivedStateFromProps.return = nextFiber.return; - nextFiber = getDerivedStateFromProps; + oldValue = getDerivedStateFromProps.sibling; + if (null !== oldValue) { + oldValue.return = getDerivedStateFromProps.return; + getDerivedStateFromProps = oldValue; break; } - nextFiber = nextFiber.return; + getDerivedStateFromProps = getDerivedStateFromProps.return; } - getDerivedStateFromProps = nextFiber; + oldValue = getDerivedStateFromProps; } } reconcileChildren( @@ -4472,6 +4756,291 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { ); } } +var valueCursor = { current: null }, + currentlyRenderingFiber = null, + lastContextDependency = null, + lastContextWithAllBitsObserved = null; +function pushProvider(providerFiber, nextValue) { + var context = providerFiber.type._context; + push(valueCursor, context._currentValue, providerFiber); + context._currentValue = nextValue; +} +function popProvider(providerFiber) { + var currentValue = valueCursor.current; + pop(valueCursor, providerFiber); + providerFiber.type._context._currentValue = currentValue; +} +function prepareToReadContext(workInProgress, renderExpirationTime) { + currentlyRenderingFiber = workInProgress; + lastContextWithAllBitsObserved = lastContextDependency = null; + var currentDependencies = workInProgress.contextDependencies; + null !== currentDependencies && + currentDependencies.expirationTime >= renderExpirationTime && + (didReceiveUpdate = !0); + workInProgress.contextDependencies = null; +} +function readContext(context, observedBits) { + if ( + lastContextWithAllBitsObserved !== context && + !1 !== observedBits && + 0 !== observedBits + ) { + if ("number" !== typeof observedBits || 1073741823 === observedBits) + (lastContextWithAllBitsObserved = context), (observedBits = 1073741823); + observedBits = { context: context, observedBits: observedBits, next: null }; + null === lastContextDependency + ? (invariant( + null !== currentlyRenderingFiber, + "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()." + ), + (lastContextDependency = observedBits), + (currentlyRenderingFiber.contextDependencies = { + first: observedBits, + expirationTime: 0 + })) + : (lastContextDependency = lastContextDependency.next = observedBits); + } + return context._currentValue; +} +var UpdateState = 0, + ReplaceState = 1, + ForceUpdate = 2, + CaptureUpdate = 3, + hasForceUpdate = !1; +function createUpdateQueue(baseState) { + return { + baseState: baseState, + firstUpdate: null, + lastUpdate: null, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; +} +function cloneUpdateQueue(currentQueue) { + return { + 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: UpdateState, + payload: null, + callback: null, + next: null, + nextEffect: null + }; +} +function appendUpdateToQueue(queue, update) { + null === queue.lastUpdate + ? (queue.firstUpdate = queue.lastUpdate = update) + : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); +} +function enqueueUpdate(fiber, update) { + 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) + : null === queue1.lastUpdate || null === queue2.lastUpdate + ? (appendUpdateToQueue(queue1, update), + appendUpdateToQueue(queue2, update)) + : (appendUpdateToQueue(queue1, update), (queue2.lastUpdate = update)); +} +function enqueueCapturedUpdate(workInProgress, update) { + 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)); +} +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 ReplaceState: + return ( + (workInProgress = update.payload), + "function" === typeof workInProgress + ? workInProgress.call(instance, prevState, nextProps) + : workInProgress + ); + case CaptureUpdate: + workInProgress.effectTag = (workInProgress.effectTag & -2049) | 64; + case UpdateState: + 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 ForceUpdate: + hasForceUpdate = !0; + } + return prevState; +} +function processUpdateQueue( + workInProgress, + queue, + props, + instance, + renderExpirationTime +) { + hasForceUpdate = !1; + queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + for ( + var newBaseState = queue.baseState, + newFirstUpdate = null, + newExpirationTime = 0, + update = queue.firstUpdate, + resultState = newBaseState; + null !== update; + + ) { + var updateExpirationTime = update.expirationTime; + updateExpirationTime < renderExpirationTime + ? (null === newFirstUpdate && + ((newFirstUpdate = update), (newBaseState = resultState)), + newExpirationTime < updateExpirationTime && + (newExpirationTime = updateExpirationTime)) + : ((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; + _updateExpirationTime < renderExpirationTime + ? (null === updateExpirationTime && + ((updateExpirationTime = update), + null === newFirstUpdate && (newBaseState = resultState)), + newExpirationTime < _updateExpirationTime && + (newExpirationTime = _updateExpirationTime)) + : ((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; + workInProgress.expirationTime = newExpirationTime; + workInProgress.memoizedState = resultState; +} +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)); + commitUpdateEffects(finishedQueue.firstEffect, instance); + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; +} +function commitUpdateEffects(effect, instance) { + for (; null !== effect; ) { + var _callback3 = effect.callback; + if (null !== _callback3) { + effect.callback = null; + var context = instance; + invariant( + "function" === typeof _callback3, + "Invalid argument passed as callback. Expected a function. Instead received: %s", + _callback3 + ); + _callback3.call(context); + } + effect = effect.nextEffect; + } +} +function createCapturedValue(value, source) { + return { + value: value, + source: source, + stack: getStackByFiberInDevAndProd(source) + }; +} var appendAllChildren = void 0, updateHostContainer = void 0, updateHostComponent$1 = void 0, @@ -4522,6 +5091,7 @@ function logCapturedError(capturedError) { : Error("Unspecified error at:" + componentStack); ExceptionsManager.handleException(error, !1); } +var PossiblyWeakSet = "function" === typeof WeakSet ? WeakSet : Set; function logError(boundary, errorInfo) { var source = errorInfo.source, stack = errorInfo.stack; @@ -4562,6 +5132,81 @@ function safelyDetachRef(current$$1) { } else ref.current = null; } +function commitHookEffectList(unmountTag, mountTag, finishedWork) { + finishedWork = finishedWork.updateQueue; + finishedWork = null !== finishedWork ? finishedWork.lastEffect : null; + if (null !== finishedWork) { + var effect = (finishedWork = finishedWork.next); + do { + if ((effect.tag & unmountTag) !== NoEffect$1) { + var destroy = effect.destroy; + effect.destroy = void 0; + void 0 !== destroy && destroy(); + } + (effect.tag & mountTag) !== NoEffect$1 && + ((destroy = effect.create), (effect.destroy = destroy())); + effect = effect.next; + } while (effect !== finishedWork); + } +} +function hideOrUnhideAllChildren(finishedWork, isHidden) { + for (var node = finishedWork; ; ) { + if (5 === node.tag) { + var instance = node.stateNode; + if (isHidden) { + var viewConfig = instance.viewConfig; + var updatePayload = diffProperties( + null, + emptyObject, + { style: { display: "none" } }, + viewConfig.validAttributes + ); + UIManager.updateView( + instance._nativeTag, + viewConfig.uiViewClassName, + updatePayload + ); + } else { + instance = node.stateNode; + updatePayload = node.memoizedProps; + viewConfig = instance.viewConfig; + var prevProps = Object.assign({}, updatePayload, { + style: [updatePayload.style, { display: "none" }] + }); + updatePayload = diffProperties( + null, + prevProps, + updatePayload, + viewConfig.validAttributes + ); + UIManager.updateView( + instance._nativeTag, + viewConfig.uiViewClassName, + updatePayload + ); + } + } else { + if (6 === node.tag) throw Error("Not yet implemented."); + if (13 === node.tag && null !== node.memoizedState) { + instance = node.child.sibling; + instance.return = node; + node = instance; + continue; + } else if (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 commitUnmount(current$$1$jscomp$0) { "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(current$$1$jscomp$0); @@ -4578,7 +5223,7 @@ function commitUnmount(current$$1$jscomp$0) { var effect = (updateQueue = updateQueue.next); do { var destroy = effect.destroy; - if (null !== destroy) { + if (void 0 !== destroy) { var current$$1 = current$$1$jscomp$0; try { destroy(); @@ -4849,6 +5494,7 @@ function commitWork(current$$1, finishedWork) { case 11: case 14: case 15: + commitHookEffectList(UnmountMutation, MountMutation, finishedWork); break; case 1: break; @@ -4857,23 +5503,18 @@ function commitWork(current$$1, finishedWork) { if (null != instance) { var newProps = finishedWork.memoizedProps; current$$1 = null !== current$$1 ? current$$1.memoizedProps : newProps; - var updatePayload = finishedWork.updateQueue; + var type = finishedWork.type, + updatePayload = finishedWork.updateQueue; finishedWork.updateQueue = null; null !== updatePayload && - ((finishedWork = instance.viewConfig), - (instanceProps[instance._nativeTag] = newProps), - (newProps = diffProperties( - null, + commitUpdate( + instance, + updatePayload, + type, current$$1, newProps, - finishedWork.validAttributes - )), - null != newProps && - UIManager.updateView( - instance._nativeTag, - finishedWork.uiViewClassName, - newProps - )); + finishedWork + ); } break; case 6: @@ -4890,71 +5531,28 @@ function commitWork(current$$1, finishedWork) { case 12: break; case 13: - newProps = finishedWork.memoizedState; + instance = finishedWork.memoizedState; + newProps = void 0; current$$1 = finishedWork; - null === newProps - ? (instance = !1) - : ((instance = !0), - (current$$1 = finishedWork.child), - 0 === newProps.timedOutAt && - (newProps.timedOutAt = requestCurrentTime())); - if (null !== current$$1) - a: for (newProps = finishedWork = current$$1; ; ) { - if (5 === newProps.tag) - if (((current$$1 = newProps.stateNode), instance)) { - updatePayload = current$$1.viewConfig; - var updatePayload$jscomp$0 = diffProperties( - null, - emptyObject, - { style: { display: "none" } }, - updatePayload.validAttributes - ); - UIManager.updateView( - current$$1._nativeTag, - updatePayload.uiViewClassName, - updatePayload$jscomp$0 - ); - } else { - current$$1 = newProps.stateNode; - updatePayload$jscomp$0 = newProps.memoizedProps; - updatePayload = current$$1.viewConfig; - var prevProps = Object.assign({}, updatePayload$jscomp$0, { - style: [updatePayload$jscomp$0.style, { display: "none" }] - }); - updatePayload$jscomp$0 = diffProperties( - null, - prevProps, - updatePayload$jscomp$0, - updatePayload.validAttributes - ); - UIManager.updateView( - current$$1._nativeTag, - updatePayload.uiViewClassName, - updatePayload$jscomp$0 - ); - } - else { - if (6 === newProps.tag) throw Error("Not yet implemented."); - if (13 === newProps.tag && null !== newProps.memoizedState) { - current$$1 = newProps.child.sibling; - current$$1.return = newProps; - newProps = current$$1; - continue; - } else if (null !== newProps.child) { - newProps.child.return = newProps; - newProps = newProps.child; - continue; - } - } - if (newProps === finishedWork) break a; - for (; null === newProps.sibling; ) { - if (null === newProps.return || newProps.return === finishedWork) - break a; - newProps = newProps.return; - } - newProps.sibling.return = newProps.return; - newProps = newProps.sibling; - } + null === instance + ? (newProps = !1) + : ((newProps = !0), + (current$$1 = finishedWork.child), + 0 === instance.timedOutAt && + (instance.timedOutAt = requestCurrentTime())); + null !== current$$1 && hideOrUnhideAllChildren(current$$1, newProps); + instance = finishedWork.updateQueue; + if (null !== instance) { + finishedWork.updateQueue = null; + var retryCache = finishedWork.stateNode; + null === retryCache && + (retryCache = finishedWork.stateNode = new PossiblyWeakSet()); + instance.forEach(function(thenable) { + var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable); + retryCache.has(thenable) || + (retryCache.add(thenable), thenable.then(retry, retry)); + }); + } break; case 17: break; @@ -4965,9 +5563,10 @@ function commitWork(current$$1, finishedWork) { ); } } +var PossiblyWeakMap = "function" === typeof WeakMap ? WeakMap : Map; function createRootErrorUpdate(fiber, errorInfo, expirationTime) { expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; + expirationTime.tag = CaptureUpdate; expirationTime.payload = { element: null }; var error = errorInfo.value; expirationTime.callback = function() { @@ -4978,7 +5577,7 @@ function createRootErrorUpdate(fiber, errorInfo, expirationTime) { } function createClassErrorUpdate(fiber, errorInfo, expirationTime) { expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; + expirationTime.tag = CaptureUpdate; var getDerivedStateFromError = fiber.type.getDerivedStateFromError; if ("function" === typeof getDerivedStateFromError) { var error$jscomp$0 = errorInfo.value; @@ -5042,7 +5641,7 @@ function unwindWork(workInProgress) { return null; } } -var DispatcherWithoutHooks = { readContext: readContext }, +var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher, ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner, isWorking = !1, nextUnitOfWork = null, @@ -5052,6 +5651,7 @@ var DispatcherWithoutHooks = { readContext: readContext }, nextRenderDidError = !1, nextEffect = null, isCommitting$1 = !1, + rootWithPendingPassiveEffects = null, passiveEffectCallbackHandle = null, passiveEffectCallback = null, legacyErrorBoundariesThatAlreadyFailed = null; @@ -5092,10 +5692,316 @@ function resetStack() { nextRenderDidError = !1; nextUnitOfWork = null; } +function commitAllHostEffects() { + for (; null !== nextEffect; ) { + var effectTag = nextEffect.effectTag; + if (effectTag & 128) { + var current$$1 = nextEffect.alternate; + null !== current$$1 && + ((current$$1 = current$$1.ref), + null !== current$$1 && + ("function" === typeof current$$1 + ? current$$1(null) + : (current$$1.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: + (effectTag = nextEffect), + unmountHostComponents(effectTag), + (effectTag.return = null), + (effectTag.child = null), + (effectTag.memoizedState = null), + (effectTag.updateQueue = null), + (effectTag = effectTag.alternate), + null !== effectTag && + ((effectTag.return = null), + (effectTag.child = null), + (effectTag.memoizedState = null), + (effectTag.updateQueue = null)); + } + nextEffect = nextEffect.nextEffect; + } +} +function commitBeforeMutationLifecycles() { + for (; null !== nextEffect; ) { + if (nextEffect.effectTag & 256) + a: { + var current$$1 = nextEffect.alternate, + finishedWork = nextEffect; + switch (finishedWork.tag) { + case 0: + case 11: + case 15: + commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork); + break a; + case 1: + if (finishedWork.effectTag & 256 && null !== current$$1) { + var prevProps = current$$1.memoizedProps, + prevState = current$$1.memoizedState; + current$$1 = finishedWork.stateNode; + finishedWork = current$$1.getSnapshotBeforeUpdate( + finishedWork.elementType === finishedWork.type + ? prevProps + : resolveDefaultProps(finishedWork.type, prevProps), + prevState + ); + current$$1.__reactInternalSnapshotBeforeUpdate = finishedWork; + } + break a; + case 3: + case 5: + case 6: + case 4: + case 17: + break a; + 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 commitAllLifeCycles(finishedRoot, committedExpirationTime$jscomp$0) { + for (; null !== nextEffect; ) { + var effectTag = nextEffect.effectTag; + if (effectTag & 36) { + var current$$1 = nextEffect.alternate, + finishedWork = nextEffect, + committedExpirationTime = committedExpirationTime$jscomp$0; + switch (finishedWork.tag) { + case 0: + case 11: + case 15: + commitHookEffectList(UnmountLayout, MountLayout, finishedWork); + break; + case 1: + var instance = finishedWork.stateNode; + if (finishedWork.effectTag & 4) + if (null === current$$1) instance.componentDidMount(); + else { + var prevProps = + finishedWork.elementType === finishedWork.type + ? current$$1.memoizedProps + : resolveDefaultProps( + finishedWork.type, + current$$1.memoizedProps + ); + instance.componentDidUpdate( + prevProps, + current$$1.memoizedState, + instance.__reactInternalSnapshotBeforeUpdate + ); + } + current$$1 = finishedWork.updateQueue; + null !== current$$1 && + commitUpdateQueue( + finishedWork, + current$$1, + instance, + committedExpirationTime + ); + break; + case 3: + instance = finishedWork.updateQueue; + if (null !== instance) { + current$$1 = null; + if (null !== finishedWork.child) + switch (finishedWork.child.tag) { + case 5: + current$$1 = finishedWork.child.stateNode; + break; + case 1: + current$$1 = finishedWork.child.stateNode; + } + commitUpdateQueue( + finishedWork, + instance, + current$$1, + committedExpirationTime + ); + } + break; + case 5: + break; + case 6: + break; + case 4: + break; + case 12: + break; + case 13: + break; + case 17: + 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." + ); + } + } + effectTag & 128 && + ((finishedWork = nextEffect.ref), + null !== finishedWork && + ((committedExpirationTime = nextEffect.stateNode), + "function" === typeof finishedWork + ? finishedWork(committedExpirationTime) + : (finishedWork.current = committedExpirationTime))); + effectTag & 512 && (rootWithPendingPassiveEffects = finishedRoot); + nextEffect = nextEffect.nextEffect; + } +} +function commitPassiveEffects(root, firstEffect) { + passiveEffectCallback = passiveEffectCallbackHandle = rootWithPendingPassiveEffects = null; + var previousIsRendering = isRendering; + isRendering = !0; + do { + if (firstEffect.effectTag & 512) { + var didError = !1, + error = void 0; + try { + var finishedWork = firstEffect; + commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork); + commitHookEffectList(NoEffect$1, MountPassive, finishedWork); + } catch (e) { + (didError = !0), (error = e); + } + didError && captureCommitPhaseError(firstEffect, error); + } + firstEffect = firstEffect.nextEffect; + } while (null !== firstEffect); + isRendering = previousIsRendering; + previousIsRendering = root.expirationTime; + 0 !== previousIsRendering && requestWork(root, previousIsRendering); +} function flushPassiveEffects() { - null !== passiveEffectCallback && - (scheduler.unstable_cancelCallback(passiveEffectCallbackHandle), - passiveEffectCallback()); + if (null !== passiveEffectCallbackHandle) { + var callbackID = passiveEffectCallbackHandle; + scheduledCallback = null; + clearTimeout(callbackID); + } + null !== passiveEffectCallback && passiveEffectCallback(); +} +function commitRoot(root, finishedWork) { + isCommitting$1 = isWorking = !0; + 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( + 0 !== committedExpirationTime, + "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." + ); + root.pendingCommitExpirationTime = 0; + var updateExpirationTimeBeforeCommit = finishedWork.expirationTime, + childExpirationTimeBeforeCommit = finishedWork.childExpirationTime; + markCommittedPriorityLevels( + root, + childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit + ? childExpirationTimeBeforeCommit + : updateExpirationTimeBeforeCommit + ); + ReactCurrentOwner$2.current = null; + updateExpirationTimeBeforeCommit = void 0; + 1 < finishedWork.effectTag + ? null !== finishedWork.lastEffect + ? ((finishedWork.lastEffect.nextEffect = finishedWork), + (updateExpirationTimeBeforeCommit = finishedWork.firstEffect)) + : (updateExpirationTimeBeforeCommit = finishedWork) + : (updateExpirationTimeBeforeCommit = finishedWork.firstEffect); + for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) { + childExpirationTimeBeforeCommit = !1; + var error = void 0; + try { + commitBeforeMutationLifecycles(); + } catch (e) { + (childExpirationTimeBeforeCommit = !0), (error = e); + } + childExpirationTimeBeforeCommit && + (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 = updateExpirationTimeBeforeCommit; null !== nextEffect; ) { + childExpirationTimeBeforeCommit = !1; + error = void 0; + try { + commitAllHostEffects(); + } catch (e) { + (childExpirationTimeBeforeCommit = !0), (error = e); + } + childExpirationTimeBeforeCommit && + (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)); + } + root.current = finishedWork; + for (nextEffect = updateExpirationTimeBeforeCommit; null !== nextEffect; ) { + childExpirationTimeBeforeCommit = !1; + error = void 0; + try { + commitAllLifeCycles(root, committedExpirationTime); + } catch (e) { + (childExpirationTimeBeforeCommit = !0), (error = e); + } + childExpirationTimeBeforeCommit && + (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)); + } + if ( + null !== updateExpirationTimeBeforeCommit && + null !== rootWithPendingPassiveEffects + ) { + var callback = commitPassiveEffects.bind( + null, + root, + updateExpirationTimeBeforeCommit + ); + passiveEffectCallbackHandle = scheduler.unstable_runWithPriority( + scheduler.unstable_NormalPriority, + function() { + return scheduleDeferredCallback$1(callback); + } + ); + passiveEffectCallback = callback; + } + isWorking = isCommitting$1 = !1; + "function" === typeof onCommitFiberRoot && + onCommitFiberRoot(finishedWork.stateNode); + committedExpirationTime = finishedWork.expirationTime; + finishedWork = finishedWork.childExpirationTime; + finishedWork = + finishedWork > committedExpirationTime + ? finishedWork + : committedExpirationTime; + 0 === finishedWork && (legacyErrorBoundariesThatAlreadyFailed = null); + onCommit(root, finishedWork); } function completeUnitOfWork(workInProgress) { for (;;) { @@ -5237,11 +6143,7 @@ function completeUnitOfWork(workInProgress) { : ((current$$1.firstEffect = current$$1.lastEffect = type), (type.nextEffect = null)), (type.effectTag = 8))); - if ( - newProps !== renderExpirationTime || - (0 === (current$$1.effectTag & 1) && newProps) - ) - current$$1.effectTag |= 4; + if (newProps || renderExpirationTime) current$$1.effectTag |= 4; break; case 7: break; @@ -5335,7 +6237,8 @@ function renderRoot(root$jscomp$0, isYieldy) { ); flushPassiveEffects(); isWorking = !0; - ReactCurrentOwner$2.currentDispatcher = DispatcherWithoutHooks; + var previousDispatcher = ReactCurrentDispatcher.current; + ReactCurrentDispatcher.current = ContextOnlyDispatcher; var expirationTime = root$jscomp$0.nextExpirationTimeToWorkOn; if ( expirationTime !== nextRenderExpirationTime || @@ -5363,6 +6266,7 @@ function renderRoot(root$jscomp$0, isYieldy) { } catch (thrownValue) { if ( ((lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = null), + resetHooks(), null === nextUnitOfWork) ) (didFatal = !0), onUncaughtError(thrownValue); @@ -5422,23 +6326,47 @@ function renderRoot(root$jscomp$0, isYieldy) { ? !1 : null === value.memoizedState; if (current$$1) { - returnFiber$jscomp$0 = retrySuspendedRoot.bind( - null, - root, - value, - sourceFiber$jscomp$0, - 0 === (value.mode & 1) ? 1073741823 : returnFiber - ); - thenable.then(returnFiber$jscomp$0, returnFiber$jscomp$0); + returnFiber$jscomp$0 = value.updateQueue; + null === returnFiber$jscomp$0 + ? ((returnFiber$jscomp$0 = new Set()), + returnFiber$jscomp$0.add(thenable), + (value.updateQueue = returnFiber$jscomp$0)) + : returnFiber$jscomp$0.add(thenable); if (0 === (value.mode & 1)) { value.effectTag |= 64; sourceFiber$jscomp$0.effectTag &= -1957; 1 === sourceFiber$jscomp$0.tag && - null === sourceFiber$jscomp$0.alternate && - (sourceFiber$jscomp$0.tag = 17); - sourceFiber$jscomp$0.expirationTime = returnFiber; + (null === sourceFiber$jscomp$0.alternate + ? (sourceFiber$jscomp$0.tag = 17) + : ((returnFiber = createUpdate(1073741823)), + (returnFiber.tag = ForceUpdate), + enqueueUpdate(sourceFiber$jscomp$0, returnFiber))); + sourceFiber$jscomp$0.expirationTime = 1073741823; break a; } + sourceFiber$jscomp$0 = root.pingCache; + null === sourceFiber$jscomp$0 + ? ((sourceFiber$jscomp$0 = root.pingCache = new PossiblyWeakMap()), + (returnFiber$jscomp$0 = new Set()), + sourceFiber$jscomp$0.set(thenable, returnFiber$jscomp$0)) + : ((returnFiber$jscomp$0 = sourceFiber$jscomp$0.get( + thenable + )), + void 0 === returnFiber$jscomp$0 && + ((returnFiber$jscomp$0 = new Set()), + sourceFiber$jscomp$0.set( + thenable, + returnFiber$jscomp$0 + ))); + returnFiber$jscomp$0.has(returnFiber) || + (returnFiber$jscomp$0.add(returnFiber), + (sourceFiber$jscomp$0 = pingSuspendedRoot.bind( + null, + root, + thenable, + returnFiber + )), + thenable.then(sourceFiber$jscomp$0, sourceFiber$jscomp$0)); -1 === earliestTimeoutMs ? (root = 1073741823) : (-1 === startTimeMs && @@ -5473,36 +6401,31 @@ function renderRoot(root$jscomp$0, isYieldy) { do { switch (root.tag) { case 3: - sourceFiber$jscomp$0 = value; root.effectTag |= 2048; root.expirationTime = returnFiber; - returnFiber = createRootErrorUpdate( - root, - sourceFiber$jscomp$0, - returnFiber - ); + returnFiber = createRootErrorUpdate(root, value, returnFiber); enqueueCapturedUpdate(root, returnFiber); break a; case 1: if ( - ((sourceFiber$jscomp$0 = value), - (returnFiber$jscomp$0 = root.type), - (thenable = root.stateNode), + ((thenable = value), + (earliestTimeoutMs = root.type), + (startTimeMs = root.stateNode), 0 === (root.effectTag & 64) && ("function" === - typeof returnFiber$jscomp$0.getDerivedStateFromError || - (null !== thenable && - "function" === typeof thenable.componentDidCatch && + typeof earliestTimeoutMs.getDerivedStateFromError || + (null !== startTimeMs && + "function" === typeof startTimeMs.componentDidCatch && (null === legacyErrorBoundariesThatAlreadyFailed || !legacyErrorBoundariesThatAlreadyFailed.has( - thenable + startTimeMs ))))) ) { root.effectTag |= 2048; root.expirationTime = returnFiber; returnFiber = createClassErrorUpdate( root, - sourceFiber$jscomp$0, + thenable, returnFiber ); enqueueCapturedUpdate(root, returnFiber); @@ -5520,29 +6443,31 @@ function renderRoot(root$jscomp$0, isYieldy) { break; } while (1); isWorking = !1; - lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = ReactCurrentOwner$2.currentDispatcher = null; + ReactCurrentDispatcher.current = previousDispatcher; + lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = null; + resetHooks(); if (didFatal) (nextRoot = null), (root$jscomp$0.finishedWork = null); else if (null !== nextUnitOfWork) root$jscomp$0.finishedWork = null; else { - didFatal = root$jscomp$0.current.alternate; + previousDispatcher = root$jscomp$0.current.alternate; invariant( - null !== didFatal, + null !== previousDispatcher, "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue." ); nextRoot = null; if (nextRenderDidError) { - sourceFiber = root$jscomp$0.latestPendingTime; - returnFiber = root$jscomp$0.latestSuspendedTime; - root = root$jscomp$0.latestPingedTime; + didFatal = root$jscomp$0.latestPendingTime; + sourceFiber = root$jscomp$0.latestSuspendedTime; + returnFiber = root$jscomp$0.latestPingedTime; if ( + (0 !== didFatal && didFatal < expirationTime) || (0 !== sourceFiber && sourceFiber < expirationTime) || - (0 !== returnFiber && returnFiber < expirationTime) || - (0 !== root && root < expirationTime) + (0 !== returnFiber && returnFiber < expirationTime) ) { markSuspendedPriorityLevel(root$jscomp$0, expirationTime); onSuspend( root$jscomp$0, - didFatal, + previousDispatcher, expirationTime, root$jscomp$0.expirationTime, -1 @@ -5553,7 +6478,13 @@ function renderRoot(root$jscomp$0, isYieldy) { root$jscomp$0.didError = !0; expirationTime = root$jscomp$0.nextExpirationTimeToWorkOn = expirationTime; isYieldy = root$jscomp$0.expirationTime = 1073741823; - onSuspend(root$jscomp$0, didFatal, expirationTime, isYieldy, -1); + onSuspend( + root$jscomp$0, + previousDispatcher, + expirationTime, + isYieldy, + -1 + ); return; } } @@ -5572,13 +6503,13 @@ function renderRoot(root$jscomp$0, isYieldy) { (isYieldy = nextLatestAbsoluteTimeoutMs - isYieldy), onSuspend( root$jscomp$0, - didFatal, + previousDispatcher, expirationTime, root$jscomp$0.expirationTime, 0 > isYieldy ? 0 : isYieldy )) : ((root$jscomp$0.pendingCommitExpirationTime = expirationTime), - (root$jscomp$0.finishedWork = didFatal)); + (root$jscomp$0.finishedWork = previousDispatcher)); } } function captureCommitPhaseError(sourceFiber, value) { @@ -5615,55 +6546,72 @@ function captureCommitPhaseError(sourceFiber, value) { scheduleWork(sourceFiber, 1073741823)); } function computeExpirationForFiber(currentTime, fiber) { - isWorking - ? (currentTime = isCommitting$1 ? 1073741823 : nextRenderExpirationTime) - : fiber.mode & 1 - ? ((currentTime = isBatchingInteractiveUpdates - ? 1073741822 - 10 * ((((1073741822 - currentTime + 15) / 10) | 0) + 1) - : 1073741822 - - 25 * ((((1073741822 - currentTime + 500) / 25) | 0) + 1)), - null !== nextRoot && - currentTime === nextRenderExpirationTime && - --currentTime) - : (currentTime = 1073741823); - isBatchingInteractiveUpdates && + var priorityLevel = scheduler.unstable_getCurrentPriorityLevel(), + expirationTime = void 0; + if (0 === (fiber.mode & 1)) expirationTime = 1073741823; + else if (isWorking && !isCommitting$1) + expirationTime = nextRenderExpirationTime; + else { + switch (priorityLevel) { + case scheduler.unstable_ImmediatePriority: + expirationTime = 1073741823; + break; + case scheduler.unstable_UserBlockingPriority: + expirationTime = + 1073741822 - 10 * ((((1073741822 - currentTime + 15) / 10) | 0) + 1); + break; + case scheduler.unstable_NormalPriority: + expirationTime = + 1073741822 - 25 * ((((1073741822 - currentTime + 500) / 25) | 0) + 1); + break; + case scheduler.unstable_LowPriority: + case scheduler.unstable_IdlePriority: + expirationTime = 1; + break; + default: + invariant( + !1, + "Unknown priority level. This error is likely caused by a bug in React. Please file an issue." + ); + } + null !== nextRoot && + expirationTime === nextRenderExpirationTime && + --expirationTime; + } + priorityLevel === scheduler.unstable_UserBlockingPriority && (0 === lowestPriorityPendingInteractiveExpirationTime || - currentTime < lowestPriorityPendingInteractiveExpirationTime) && - (lowestPriorityPendingInteractiveExpirationTime = currentTime); - return currentTime; + expirationTime < lowestPriorityPendingInteractiveExpirationTime) && + (lowestPriorityPendingInteractiveExpirationTime = expirationTime); + return expirationTime; } -function retrySuspendedRoot(root, boundaryFiber, sourceFiber, suspendedTime) { - var retryTime = root.earliestSuspendedTime; - var latestSuspendedTime = root.latestSuspendedTime; - if ( - 0 !== retryTime && - suspendedTime <= retryTime && - suspendedTime >= latestSuspendedTime +function pingSuspendedRoot(root, thenable, pingTime) { + var pingCache = root.pingCache; + null !== pingCache && pingCache.delete(thenable); + if (null !== nextRoot && nextRenderExpirationTime === pingTime) + nextRoot = null; + else if ( + ((thenable = root.earliestSuspendedTime), + (pingCache = root.latestSuspendedTime), + 0 !== thenable && pingTime <= thenable && pingTime >= pingCache) ) { - latestSuspendedTime = retryTime = suspendedTime; root.didError = !1; - var latestPingedTime = root.latestPingedTime; - if (0 === latestPingedTime || latestPingedTime > latestSuspendedTime) - root.latestPingedTime = latestSuspendedTime; - findNextExpirationTimeToWorkOn(latestSuspendedTime, root); - } else - (retryTime = requestCurrentTime()), - (retryTime = computeExpirationForFiber(retryTime, boundaryFiber)), - markPendingPriorityLevel(root, retryTime); - 0 !== (boundaryFiber.mode & 1) && - root === nextRoot && - nextRenderExpirationTime === suspendedTime && - (nextRoot = null); - scheduleWorkToRoot(boundaryFiber, retryTime); - 0 === (boundaryFiber.mode & 1) && - (scheduleWorkToRoot(sourceFiber, retryTime), - 1 === sourceFiber.tag && - null !== sourceFiber.stateNode && - ((boundaryFiber = createUpdate(retryTime)), - (boundaryFiber.tag = 2), - enqueueUpdate(sourceFiber, boundaryFiber))); - sourceFiber = root.expirationTime; - 0 !== sourceFiber && requestWork(root, sourceFiber); + thenable = root.latestPingedTime; + if (0 === thenable || thenable > pingTime) root.latestPingedTime = pingTime; + findNextExpirationTimeToWorkOn(pingTime, root); + pingTime = root.expirationTime; + 0 !== pingTime && requestWork(root, pingTime); + } +} +function retryTimedOutBoundary(boundaryFiber, thenable) { + var retryCache = boundaryFiber.stateNode; + null !== retryCache && retryCache.delete(thenable); + thenable = requestCurrentTime(); + thenable = computeExpirationForFiber(thenable, boundaryFiber); + boundaryFiber = scheduleWorkToRoot(boundaryFiber, thenable); + null !== boundaryFiber && + (markPendingPriorityLevel(boundaryFiber, thenable), + (thenable = boundaryFiber.expirationTime), + 0 !== thenable && requestWork(boundaryFiber, thenable)); } function scheduleWorkToRoot(fiber, expirationTime) { fiber.expirationTime < expirationTime && @@ -5720,7 +6668,6 @@ var firstScheduledRoot = null, unhandledError = null, isBatchingUpdates = !1, isUnbatchingUpdates = !1, - isBatchingInteractiveUpdates = !1, completedBatches = null, originalStartTimeMs = now$1(), currentRendererTime = 1073741822 - ((originalStartTimeMs / 10) | 0), @@ -5739,9 +6686,10 @@ function scheduleCallbackWithExpirationTime(root, expirationTime) { ((root = callbackID), (scheduledCallback = null), clearTimeout(root)); } callbackExpirationTime = expirationTime; - now$1(); - scheduledCallback = performAsyncWork; - callbackID = setTimeout(setTimeoutCallback, 1); + root = now$1() - originalStartTimeMs; + callbackID = scheduleDeferredCallback$1(performAsyncWork, { + timeout: 10 * (1073741822 - expirationTime) - root + }); } function onSuspend( root, @@ -5774,6 +6722,10 @@ function onTimeout(root, finishedWork, suspendedExpirationTime) { performWorkOnRoot(root, suspendedExpirationTime, !1); performWork(1073741823, !1); } +function onCommit(root, expirationTime) { + root.expirationTime = expirationTime; + root.finishedWork = null; +} function requestCurrentTime() { if (isRendering) return currentSchedulerTime; findHighestPriorityRoot(); @@ -5963,7 +6915,7 @@ function performWorkOnRoot(root, expirationTime, isYieldy) { completeRoot(root, _finishedWork, expirationTime)); isRendering = !1; } -function completeRoot(root, finishedWork$jscomp$0, expirationTime) { +function completeRoot(root, finishedWork, expirationTime) { var firstBatch = root.firstBatch; if ( null !== firstBatch && @@ -5973,7 +6925,7 @@ function completeRoot(root, finishedWork$jscomp$0, expirationTime) { : completedBatches.push(firstBatch), firstBatch._defer) ) { - root.finishedWork = finishedWork$jscomp$0; + root.finishedWork = finishedWork; root.expirationTime = 0; return; } @@ -5981,290 +6933,12 @@ function completeRoot(root, finishedWork$jscomp$0, expirationTime) { root === lastCommittedRootDuringThisBatch ? nestedUpdateCount++ : ((lastCommittedRootDuringThisBatch = root), (nestedUpdateCount = 0)); - 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; - var childExpirationTimeBeforeCommit = - finishedWork$jscomp$0.childExpirationTime; - firstBatch = - childExpirationTimeBeforeCommit > firstBatch - ? childExpirationTimeBeforeCommit - : firstBatch; - root.didError = !1; - 0 === firstBatch - ? ((root.earliestPendingTime = 0), - (root.latestPendingTime = 0), - (root.earliestSuspendedTime = 0), - (root.latestSuspendedTime = 0), - (root.latestPingedTime = 0)) - : ((childExpirationTimeBeforeCommit = root.latestPendingTime), - 0 !== childExpirationTimeBeforeCommit && - (childExpirationTimeBeforeCommit > firstBatch - ? (root.earliestPendingTime = root.latestPendingTime = 0) - : root.earliestPendingTime > firstBatch && - (root.earliestPendingTime = root.latestPendingTime)), - (childExpirationTimeBeforeCommit = root.earliestSuspendedTime), - 0 === childExpirationTimeBeforeCommit - ? markPendingPriorityLevel(root, firstBatch) - : firstBatch < root.latestSuspendedTime - ? ((root.earliestSuspendedTime = 0), - (root.latestSuspendedTime = 0), - (root.latestPingedTime = 0), - markPendingPriorityLevel(root, firstBatch)) - : firstBatch > childExpirationTimeBeforeCommit && - markPendingPriorityLevel(root, firstBatch)); - findNextExpirationTimeToWorkOn(0, root); - ReactCurrentOwner$2.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; ) { - childExpirationTimeBeforeCommit = !1; - var error = void 0; - try { - for (; null !== nextEffect; ) { - if (nextEffect.effectTag & 256) - a: { - var current$$1 = nextEffect.alternate, - finishedWork = nextEffect; - switch (finishedWork.tag) { - case 0: - case 11: - case 15: - break a; - case 1: - if (finishedWork.effectTag & 256 && null !== current$$1) { - var prevProps = current$$1.memoizedProps, - prevState = current$$1.memoizedState, - instance = finishedWork.stateNode, - snapshot = instance.getSnapshotBeforeUpdate( - finishedWork.elementType === finishedWork.type - ? prevProps - : resolveDefaultProps(finishedWork.type, prevProps), - prevState - ); - instance.__reactInternalSnapshotBeforeUpdate = snapshot; - } - break a; - case 3: - case 5: - case 6: - case 4: - case 17: - break a; - 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) { - (childExpirationTimeBeforeCommit = !0), (error = e); - } - childExpirationTimeBeforeCommit && - (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 = !1; - prevProps = void 0; - try { - for (; null !== nextEffect; ) { - var effectTag = nextEffect.effectTag; - if (effectTag & 128) { - var current$$1$jscomp$0 = nextEffect.alternate; - if (null !== current$$1$jscomp$0) { - var currentRef = current$$1$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.memoizedState = null; - prevState.updateQueue = null; - var alternate = prevState.alternate; - null !== alternate && - ((alternate.return = null), - (alternate.child = null), - (alternate.memoizedState = null), - (alternate.updateQueue = null)); - } - nextEffect = nextEffect.nextEffect; - } - } catch (e) { - (current$$1 = !0), (prevProps = e); - } - current$$1 && - (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$$1$jscomp$0 = void 0; - try { - for (currentRef = expirationTime; null !== nextEffect; ) { - var effectTag$jscomp$0 = nextEffect.effectTag; - if (effectTag$jscomp$0 & 36) { - var current$$1$jscomp$1 = nextEffect.alternate; - alternate = nextEffect; - current$$1 = currentRef; - switch (alternate.tag) { - case 0: - case 11: - case 15: - break; - case 1: - var instance$jscomp$0 = alternate.stateNode; - if (alternate.effectTag & 4) - if (null === current$$1$jscomp$1) - instance$jscomp$0.componentDidMount(); - else { - var prevProps$jscomp$0 = - alternate.elementType === alternate.type - ? current$$1$jscomp$1.memoizedProps - : resolveDefaultProps( - alternate.type, - current$$1$jscomp$1.memoizedProps - ); - instance$jscomp$0.componentDidUpdate( - prevProps$jscomp$0, - current$$1$jscomp$1.memoizedState, - instance$jscomp$0.__reactInternalSnapshotBeforeUpdate - ); - } - var updateQueue = alternate.updateQueue; - null !== updateQueue && - commitUpdateQueue( - alternate, - updateQueue, - instance$jscomp$0, - current$$1 - ); - break; - case 3: - var _updateQueue = alternate.updateQueue; - if (null !== _updateQueue) { - prevProps = null; - if (null !== alternate.child) - switch (alternate.child.tag) { - case 5: - prevProps = alternate.child.stateNode; - break; - case 1: - prevProps = alternate.child.stateNode; - } - commitUpdateQueue( - alternate, - _updateQueue, - prevProps, - current$$1 - ); - } - break; - case 5: - break; - case 6: - break; - case 4: - break; - case 12: - break; - case 13: - break; - case 17: - 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) { - var ref = nextEffect.ref; - if (null !== ref) { - var instance$jscomp$1 = nextEffect.stateNode; - switch (nextEffect.tag) { - case 5: - var instanceToUse = instance$jscomp$1; - break; - default: - instanceToUse = instance$jscomp$1; - } - "function" === typeof ref - ? ref(instanceToUse) - : (ref.current = instanceToUse); - } - } - nextEffect = nextEffect.nextEffect; - } - } catch (e) { - (effectTag = !0), (current$$1$jscomp$0 = e); + scheduler.unstable_runWithPriority( + scheduler.unstable_ImmediatePriority, + function() { + commitRoot(root, finishedWork); } - 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$$1$jscomp$0), - null !== nextEffect && (nextEffect = nextEffect.nextEffect)); - } - isWorking = isCommitting$1 = !1; - "function" === typeof onCommitFiberRoot && - onCommitFiberRoot(finishedWork$jscomp$0.stateNode); - effectTag$jscomp$0 = finishedWork$jscomp$0.expirationTime; - finishedWork$jscomp$0 = finishedWork$jscomp$0.childExpirationTime; - finishedWork$jscomp$0 = - finishedWork$jscomp$0 > effectTag$jscomp$0 - ? finishedWork$jscomp$0 - : effectTag$jscomp$0; - 0 === finishedWork$jscomp$0 && - (legacyErrorBoundariesThatAlreadyFailed = null); - root.expirationTime = finishedWork$jscomp$0; - root.finishedWork = null; + ); } function onUncaughtError(error) { invariant( @@ -6493,6 +7167,7 @@ var roots = new Map(), current: root, containerInfo: containerTag, pendingChildren: null, + pingCache: null, earliestPendingTime: 0, latestPendingTime: 0, earliestSuspendedTime: 0, @@ -6608,6 +7283,8 @@ var roots = new Map(), var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; return injectInternals( Object.assign({}, devToolsConfig, { + overrideProps: null, + currentDispatcherRef: ReactSharedInternals.ReactCurrentDispatcher, findHostInstanceByFiber: function(fiber) { fiber = findCurrentHostFiber(fiber); return null === fiber ? null : fiber.stateNode; @@ -6623,7 +7300,7 @@ var roots = new Map(), findFiberByHostInstance: getInstanceFromTag, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 0, - version: "16.6.1", + version: "16.8.1", rendererPackageName: "react-native-renderer" }); var ReactNativeRenderer$2 = { default: ReactNativeRenderer }, diff --git a/Libraries/Renderer/oss/ReactNativeRenderer-profiling.js b/Libraries/Renderer/oss/ReactNativeRenderer-profiling.js index 4d323e348dd55e..d07638635e5c4a 100644 --- a/Libraries/Renderer/oss/ReactNativeRenderer-profiling.js +++ b/Libraries/Renderer/oss/ReactNativeRenderer-profiling.js @@ -1130,8 +1130,10 @@ ResponderEventPlugin.injection.injectGlobalResponderHandler({ } }); var ReactSharedInternals = - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, - hasSymbol = "function" === typeof Symbol && Symbol.for, + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; +ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher") || + (ReactSharedInternals.ReactCurrentDispatcher = { current: null }); +var 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, @@ -1599,6 +1601,10 @@ function setTimeoutCallback() { scheduledCallback = null; null !== callback && callback(); } +function scheduleDeferredCallback$1(callback) { + scheduledCallback = callback; + return setTimeout(setTimeoutCallback, 1); +} function shim$1() { invariant( !1, @@ -1632,8 +1638,24 @@ function finalizeInitialChildren(parentInstance) { return !1; } var scheduleTimeout = setTimeout, - cancelTimeout = clearTimeout, - BEFORE_SLASH_RE = /^(.*)[\\\/]/; + cancelTimeout = clearTimeout; +function commitUpdate(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 + ); +} +var BEFORE_SLASH_RE = /^(.*)[\\\/]/; function getStackByFiberInDevAndProd(workInProgress) { var info = ""; do { @@ -1799,7 +1821,7 @@ function FiberNode(tag, pendingProps, key, mode) { this.index = 0; this.ref = null; this.pendingProps = pendingProps; - this.firstContextDependency = this.memoizedState = this.updateQueue = this.memoizedProps = null; + this.contextDependencies = this.memoizedState = this.updateQueue = this.memoizedProps = null; this.mode = mode; this.effectTag = 0; this.lastEffect = this.firstEffect = this.nextEffect = null; @@ -1853,7 +1875,7 @@ function createWorkInProgress(current, pendingProps) { workInProgress.memoizedProps = current.memoizedProps; workInProgress.memoizedState = current.memoizedState; workInProgress.updateQueue = current.updateQueue; - workInProgress.firstContextDependency = current.firstContextDependency; + workInProgress.contextDependencies = current.contextDependencies; workInProgress.sibling = current.sibling; workInProgress.index = current.index; workInProgress.ref = current.ref; @@ -1988,6 +2010,8 @@ function markCommittedPriorityLevels(root, earliestRemainingTime) { (root.latestSuspendedTime = 0), (root.latestPingedTime = 0); else { + earliestRemainingTime < root.latestPingedTime && + (root.latestPingedTime = 0); var latestPendingTime = root.latestPendingTime; 0 !== latestPendingTime && (latestPendingTime > earliestRemainingTime @@ -2020,24 +2044,21 @@ function hasLowerPriorityWork(root, erroredExpirationTime) { } function markSuspendedPriorityLevel(root, suspendedTime) { root.didError = !1; - var latestPingedTime = root.latestPingedTime; - 0 !== latestPingedTime && - latestPingedTime >= suspendedTime && - (root.latestPingedTime = 0); - latestPingedTime = root.earliestPendingTime; - var latestPendingTime = root.latestPendingTime; - latestPingedTime === suspendedTime + root.latestPingedTime >= suspendedTime && (root.latestPingedTime = 0); + var earliestPendingTime = root.earliestPendingTime, + latestPendingTime = root.latestPendingTime; + earliestPendingTime === suspendedTime ? (root.earliestPendingTime = latestPendingTime === suspendedTime ? (root.latestPendingTime = 0) : latestPendingTime) : latestPendingTime === suspendedTime && - (root.latestPendingTime = latestPingedTime); - latestPingedTime = root.earliestSuspendedTime; + (root.latestPendingTime = earliestPendingTime); + earliestPendingTime = root.earliestSuspendedTime; latestPendingTime = root.latestSuspendedTime; - 0 === latestPingedTime + 0 === earliestPendingTime ? (root.earliestSuspendedTime = root.latestSuspendedTime = suspendedTime) - : latestPingedTime < suspendedTime + : earliestPendingTime < suspendedTime ? (root.earliestSuspendedTime = suspendedTime) : latestPendingTime > suspendedTime && (root.latestSuspendedTime = suspendedTime); @@ -2069,404 +2090,81 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) { root.nextExpirationTimeToWorkOn = earliestPendingTime; root.expirationTime = completedExpirationTime; } -var hasForceUpdate = !1; -function createUpdateQueue(baseState) { - return { - baseState: baseState, - firstUpdate: null, - lastUpdate: null, - firstCapturedUpdate: null, - lastCapturedUpdate: null, - firstEffect: null, - lastEffect: null, - firstCapturedEffect: null, - lastCapturedEffect: null - }; -} -function cloneUpdateQueue(currentQueue) { - return { - 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) { - null === queue.lastUpdate - ? (queue.firstUpdate = queue.lastUpdate = update) - : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); -} -function enqueueUpdate(fiber, update) { - 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) - : null === queue1.lastUpdate || null === queue2.lastUpdate - ? (appendUpdateToQueue(queue1, update), - appendUpdateToQueue(queue2, update)) - : (appendUpdateToQueue(queue1, update), (queue2.lastUpdate = update)); +function is(x, y) { + return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); } -function enqueueCapturedUpdate(workInProgress, update) { - 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)); +var hasOwnProperty = Object.prototype.hasOwnProperty; +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 ensureWorkInProgressQueueIsAClone(workInProgress, queue) { - var current = workInProgress.alternate; - null !== current && - queue === current.updateQueue && - (queue = workInProgress.updateQueue = cloneUpdateQueue(queue)); - return queue; +function resolveDefaultProps(Component, baseProps) { + if (Component && Component.defaultProps) { + baseProps = Object.assign({}, baseProps); + Component = Component.defaultProps; + for (var propName in Component) + void 0 === baseProps[propName] && + (baseProps[propName] = Component[propName]); + } + return baseProps; } -function getStateFromUpdate( - workInProgress, - queue, - update, - prevState, - nextProps, - instance -) { - switch (update.tag) { +function readLazyComponentType(lazyComponent) { + var result = lazyComponent._result; + switch (lazyComponent._status) { case 1: - return ( - (workInProgress = update.payload), - "function" === typeof workInProgress - ? workInProgress.call(instance, prevState, nextProps) - : workInProgress - ); - case 3: - workInProgress.effectTag = (workInProgress.effectTag & -2049) | 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); + return result; case 2: - hasForceUpdate = !0; + throw result; + case 0: + throw result; + default: + lazyComponent._status = 0; + result = lazyComponent._ctor; + result = result(); + result.then( + function(moduleObject) { + 0 === lazyComponent._status && + ((moduleObject = moduleObject.default), + (lazyComponent._status = 1), + (lazyComponent._result = moduleObject)); + }, + function(error) { + 0 === lazyComponent._status && + ((lazyComponent._status = 2), (lazyComponent._result = error)); + } + ); + switch (lazyComponent._status) { + case 1: + return lazyComponent._result; + case 2: + throw lazyComponent._result; + } + lazyComponent._result = result; + throw result; } - return prevState; } -function processUpdateQueue( +var emptyRefsObject = new React.Component().refs; +function applyDerivedStateFromProps( workInProgress, - queue, - props, - instance, - renderExpirationTime -) { - hasForceUpdate = !1; - queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); - for ( - var newBaseState = queue.baseState, - newFirstUpdate = null, - newExpirationTime = 0, - update = queue.firstUpdate, - resultState = newBaseState; - null !== update; - - ) { - var updateExpirationTime = update.expirationTime; - updateExpirationTime < renderExpirationTime - ? (null === newFirstUpdate && - ((newFirstUpdate = update), (newBaseState = resultState)), - newExpirationTime < updateExpirationTime && - (newExpirationTime = updateExpirationTime)) - : ((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; - _updateExpirationTime < renderExpirationTime - ? (null === updateExpirationTime && - ((updateExpirationTime = update), - null === newFirstUpdate && (newBaseState = resultState)), - newExpirationTime < _updateExpirationTime && - (newExpirationTime = _updateExpirationTime)) - : ((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; - workInProgress.expirationTime = newExpirationTime; - workInProgress.memoizedState = resultState; -} -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)); - commitUpdateEffects(finishedQueue.firstEffect, instance); - finishedQueue.firstEffect = finishedQueue.lastEffect = null; - commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); - finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; -} -function commitUpdateEffects(effect, instance) { - for (; null !== effect; ) { - var _callback3 = effect.callback; - if (null !== _callback3) { - effect.callback = null; - var context = instance; - invariant( - "function" === typeof _callback3, - "Invalid argument passed as callback. Expected a function. Instead received: %s", - _callback3 - ); - _callback3.call(context); - } - effect = effect.nextEffect; - } -} -function createCapturedValue(value, source) { - return { - value: value, - source: source, - stack: getStackByFiberInDevAndProd(source) - }; -} -var valueCursor = { current: null }, - currentlyRenderingFiber = null, - lastContextDependency = null, - lastContextWithAllBitsObserved = null; -function pushProvider(providerFiber, nextValue) { - var context = providerFiber.type._context; - push(valueCursor, context._currentValue, providerFiber); - context._currentValue = nextValue; -} -function popProvider(providerFiber) { - var currentValue = valueCursor.current; - pop(valueCursor, providerFiber); - providerFiber.type._context._currentValue = currentValue; -} -function prepareToReadContext(workInProgress) { - currentlyRenderingFiber = workInProgress; - lastContextWithAllBitsObserved = lastContextDependency = null; - workInProgress.firstContextDependency = null; -} -function readContext(context, observedBits) { - if ( - lastContextWithAllBitsObserved !== context && - !1 !== observedBits && - 0 !== observedBits - ) { - if ("number" !== typeof observedBits || 1073741823 === observedBits) - (lastContextWithAllBitsObserved = context), (observedBits = 1073741823); - observedBits = { context: context, observedBits: observedBits, next: null }; - null === lastContextDependency - ? (invariant( - null !== currentlyRenderingFiber, - "Context can only be read while React is rendering, e.g. inside the render method or getDerivedStateFromProps." - ), - (currentlyRenderingFiber.firstContextDependency = lastContextDependency = observedBits)) - : (lastContextDependency = lastContextDependency.next = observedBits); - } - return context._currentValue; -} -var NO_CONTEXT = {}, - contextStackCursor$1 = { current: NO_CONTEXT }, - contextFiberStackCursor = { current: NO_CONTEXT }, - rootInstanceStackCursor = { current: 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 pushHostContext(fiber) { - requiredContext(rootInstanceStackCursor.current); - var context = requiredContext(contextStackCursor$1.current); - var nextContext = fiber.type; - nextContext = - "AndroidTextInput" === nextContext || - "RCTMultilineTextInputView" === nextContext || - "RCTSinglelineTextInputView" === nextContext || - "RCTText" === nextContext || - "RCTVirtualText" === nextContext; - nextContext = - context.isInAParentText !== nextContext - ? { isInAParentText: nextContext } - : context; - context !== nextContext && - (push(contextFiberStackCursor, fiber, fiber), - push(contextStackCursor$1, nextContext, fiber)); -} -function popHostContext(fiber) { - contextFiberStackCursor.current === fiber && - (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); -} -var commitTime = 0, - profilerStartTime = -1; -function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) { - if (0 <= profilerStartTime) { - var elapsedTime = now$1() - profilerStartTime; - fiber.actualDuration += elapsedTime; - overrideBaseTime && (fiber.selfBaseDuration = elapsedTime); - profilerStartTime = -1; - } -} -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 resolveDefaultProps(Component, baseProps) { - if (Component && Component.defaultProps) { - baseProps = Object.assign({}, baseProps); - Component = Component.defaultProps; - for (var propName in Component) - void 0 === baseProps[propName] && - (baseProps[propName] = Component[propName]); - } - return baseProps; -} -function readLazyComponentType(lazyComponent) { - var result = lazyComponent._result; - switch (lazyComponent._status) { - case 1: - return result; - case 2: - throw result; - case 0: - throw result; - default: - throw ((lazyComponent._status = 0), - (result = lazyComponent._ctor), - (result = result()), - result.then( - function(moduleObject) { - 0 === lazyComponent._status && - ((moduleObject = moduleObject.default), - (lazyComponent._status = 1), - (lazyComponent._result = moduleObject)); - }, - function(error) { - 0 === lazyComponent._status && - ((lazyComponent._status = 2), (lazyComponent._result = error)); - } - ), - (lazyComponent._result = result), - result); - } -} -var ReactCurrentOwner$4 = ReactSharedInternals.ReactCurrentOwner, - emptyRefsObject = new React.Component().refs; -function applyDerivedStateFromProps( - workInProgress, - ctor, - getDerivedStateFromProps, - nextProps + ctor, + getDerivedStateFromProps, + nextProps ) { ctor = workInProgress.memoizedState; getDerivedStateFromProps = getDerivedStateFromProps(nextProps, ctor); @@ -2502,7 +2200,7 @@ var classComponentUpdater = { var currentTime = requestCurrentTime(); currentTime = computeExpirationForFiber(currentTime, inst); var update = createUpdate(currentTime); - update.tag = 1; + update.tag = ReplaceState; update.payload = payload; void 0 !== callback && null !== callback && (update.callback = callback); flushPassiveEffects(); @@ -2514,7 +2212,7 @@ var classComponentUpdater = { var currentTime = requestCurrentTime(); currentTime = computeExpirationForFiber(currentTime, inst); var update = createUpdate(currentTime); - update.tag = 2; + update.tag = ForceUpdate; void 0 !== callback && null !== callback && (update.callback = callback); flushPassiveEffects(); enqueueUpdate(inst, update); @@ -2542,7 +2240,7 @@ function constructClassInstance(workInProgress, ctor, props) { unmaskedContext = emptyContextObject; var context = ctor.contextType; "object" === typeof context && null !== context - ? (context = ReactCurrentOwner$4.currentDispatcher.readContext(context)) + ? (context = readContext(context)) : ((unmaskedContext = isContextProvider(ctor) ? previousContext : contextStackCursor.current), @@ -2589,9 +2287,7 @@ function mountClassInstance( instance.refs = emptyRefsObject; var contextType = ctor.contextType; "object" === typeof contextType && null !== contextType - ? (instance.context = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (instance.context = readContext(contextType)) : ((contextType = isContextProvider(ctor) ? previousContext : contextStackCursor.current), @@ -2646,7 +2342,10 @@ function coerceRef(returnFiber, current$$1, element) { element = element._owner; var inst = void 0; element && - (invariant(1 === element.tag, "Function components cannot have refs."), + (invariant( + 1 === element.tag, + "Function components cannot have refs. Did you mean to use React.forwardRef()?" + ), (inst = element.stateNode)); invariant( inst, @@ -3346,68 +3045,583 @@ function ChildReconciler(shouldTrackSideEffects) { } 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; - } + NO_CONTEXT = {}, + contextStackCursor$1 = { current: NO_CONTEXT }, + contextFiberStackCursor = { current: NO_CONTEXT }, + rootInstanceStackCursor = { current: 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 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 = createFiber(5, null, null, 0); - fiber.elementType = "DELETED"; - 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 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); } -var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner; -function reconcileChildren( - current$$1, - workInProgress, - nextChildren, - renderExpirationTime -) { - workInProgress.child = - null === current$$1 - ? mountChildFibers( +function popHostContainer(fiber) { + pop(contextStackCursor$1, fiber); + pop(contextFiberStackCursor, fiber); + pop(rootInstanceStackCursor, fiber); +} +function pushHostContext(fiber) { + requiredContext(rootInstanceStackCursor.current); + var context = requiredContext(contextStackCursor$1.current); + var nextContext = fiber.type; + nextContext = + "AndroidTextInput" === nextContext || + "RCTMultilineTextInputView" === nextContext || + "RCTSinglelineTextInputView" === nextContext || + "RCTText" === nextContext || + "RCTVirtualText" === nextContext; + nextContext = + context.isInAParentText !== nextContext + ? { isInAParentText: nextContext } + : context; + context !== nextContext && + (push(contextFiberStackCursor, fiber, fiber), + push(contextStackCursor$1, nextContext, fiber)); +} +function popHostContext(fiber) { + contextFiberStackCursor.current === fiber && + (pop(contextStackCursor$1, fiber), pop(contextFiberStackCursor, fiber)); +} +var NoEffect$1 = 0, + UnmountSnapshot = 2, + UnmountMutation = 4, + MountMutation = 8, + UnmountLayout = 16, + MountLayout = 32, + MountPassive = 64, + UnmountPassive = 128, + ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher, + renderExpirationTime = 0, + currentlyRenderingFiber$1 = null, + currentHook = null, + nextCurrentHook = null, + firstWorkInProgressHook = null, + workInProgressHook = null, + nextWorkInProgressHook = null, + remainingExpirationTime = 0, + componentUpdateQueue = null, + sideEffectTag = 0, + didScheduleRenderPhaseUpdate = !1, + renderPhaseUpdates = null, + numberOfReRenders = 0; +function throwInvalidHookError() { + invariant( + !1, + "Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)" + ); +} +function areHookInputsEqual(nextDeps, prevDeps) { + if (null === prevDeps) return !1; + for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) + if (!is(nextDeps[i], prevDeps[i])) return !1; + return !0; +} +function renderWithHooks( + current, + workInProgress, + Component, + props, + refOrContext, + nextRenderExpirationTime +) { + renderExpirationTime = nextRenderExpirationTime; + currentlyRenderingFiber$1 = workInProgress; + nextCurrentHook = null !== current ? current.memoizedState : null; + ReactCurrentDispatcher$1.current = + null === nextCurrentHook ? HooksDispatcherOnMount : HooksDispatcherOnUpdate; + workInProgress = Component(props, refOrContext); + if (didScheduleRenderPhaseUpdate) { + do + (didScheduleRenderPhaseUpdate = !1), + (numberOfReRenders += 1), + (nextCurrentHook = null !== current ? current.memoizedState : null), + (nextWorkInProgressHook = firstWorkInProgressHook), + (componentUpdateQueue = workInProgressHook = currentHook = null), + (ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdate), + (workInProgress = Component(props, refOrContext)); + while (didScheduleRenderPhaseUpdate); + renderPhaseUpdates = null; + numberOfReRenders = 0; + } + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + current = currentlyRenderingFiber$1; + current.memoizedState = firstWorkInProgressHook; + current.expirationTime = remainingExpirationTime; + current.updateQueue = componentUpdateQueue; + current.effectTag |= sideEffectTag; + current = null !== currentHook && null !== currentHook.next; + renderExpirationTime = 0; + nextWorkInProgressHook = workInProgressHook = firstWorkInProgressHook = nextCurrentHook = currentHook = currentlyRenderingFiber$1 = null; + remainingExpirationTime = 0; + componentUpdateQueue = null; + sideEffectTag = 0; + invariant( + !current, + "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." + ); + return workInProgress; +} +function resetHooks() { + ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; + renderExpirationTime = 0; + nextWorkInProgressHook = workInProgressHook = firstWorkInProgressHook = nextCurrentHook = currentHook = currentlyRenderingFiber$1 = null; + remainingExpirationTime = 0; + componentUpdateQueue = null; + sideEffectTag = 0; + didScheduleRenderPhaseUpdate = !1; + renderPhaseUpdates = null; + numberOfReRenders = 0; +} +function mountWorkInProgressHook() { + var hook = { + memoizedState: null, + baseState: null, + queue: null, + baseUpdate: null, + next: null + }; + null === workInProgressHook + ? (firstWorkInProgressHook = workInProgressHook = hook) + : (workInProgressHook = workInProgressHook.next = hook); + return workInProgressHook; +} +function updateWorkInProgressHook() { + if (null !== nextWorkInProgressHook) + (workInProgressHook = nextWorkInProgressHook), + (nextWorkInProgressHook = workInProgressHook.next), + (currentHook = nextCurrentHook), + (nextCurrentHook = null !== currentHook ? currentHook.next : null); + else { + invariant( + null !== nextCurrentHook, + "Rendered more hooks than during the previous render." + ); + currentHook = nextCurrentHook; + var newHook = { + memoizedState: currentHook.memoizedState, + baseState: currentHook.baseState, + queue: currentHook.queue, + baseUpdate: currentHook.baseUpdate, + next: null + }; + workInProgressHook = + null === workInProgressHook + ? (firstWorkInProgressHook = newHook) + : (workInProgressHook.next = newHook); + nextCurrentHook = currentHook.next; + } + return workInProgressHook; +} +function basicStateReducer(state, action) { + return "function" === typeof action ? action(state) : action; +} +function updateReducer(reducer) { + var hook = updateWorkInProgressHook(), + queue = hook.queue; + invariant( + null !== queue, + "Should have a queue. This is likely a bug in React. Please file an issue." + ); + if (0 < numberOfReRenders) { + var _dispatch = queue.dispatch; + if (null !== renderPhaseUpdates) { + var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue); + if (void 0 !== firstRenderPhaseUpdate) { + renderPhaseUpdates.delete(queue); + var newState = hook.memoizedState; + do + (newState = reducer(newState, firstRenderPhaseUpdate.action)), + (firstRenderPhaseUpdate = firstRenderPhaseUpdate.next); + while (null !== firstRenderPhaseUpdate); + is(newState, hook.memoizedState) || (didReceiveUpdate = !0); + hook.memoizedState = newState; + hook.baseUpdate === queue.last && (hook.baseState = newState); + return [newState, _dispatch]; + } + } + return [hook.memoizedState, _dispatch]; + } + _dispatch = queue.last; + var baseUpdate = hook.baseUpdate; + newState = hook.baseState; + null !== baseUpdate + ? (null !== _dispatch && (_dispatch.next = null), + (_dispatch = baseUpdate.next)) + : (_dispatch = null !== _dispatch ? _dispatch.next : null); + if (null !== _dispatch) { + var newBaseUpdate = (firstRenderPhaseUpdate = null), + _update = _dispatch, + didSkip = !1; + do { + var updateExpirationTime = _update.expirationTime; + updateExpirationTime < renderExpirationTime + ? (didSkip || + ((didSkip = !0), + (newBaseUpdate = baseUpdate), + (firstRenderPhaseUpdate = newState)), + updateExpirationTime > remainingExpirationTime && + (remainingExpirationTime = updateExpirationTime)) + : (newState = + _update.eagerReducer === reducer + ? _update.eagerState + : reducer(newState, _update.action)); + baseUpdate = _update; + _update = _update.next; + } while (null !== _update && _update !== _dispatch); + didSkip || + ((newBaseUpdate = baseUpdate), (firstRenderPhaseUpdate = newState)); + is(newState, hook.memoizedState) || (didReceiveUpdate = !0); + hook.memoizedState = newState; + hook.baseUpdate = newBaseUpdate; + hook.baseState = firstRenderPhaseUpdate; + queue.eagerReducer = reducer; + queue.eagerState = newState; + } + return [hook.memoizedState, queue.dispatch]; +} +function pushEffect(tag, create, destroy, deps) { + tag = { tag: tag, create: create, destroy: destroy, deps: deps, next: null }; + null === componentUpdateQueue + ? ((componentUpdateQueue = { lastEffect: null }), + (componentUpdateQueue.lastEffect = tag.next = tag)) + : ((create = componentUpdateQueue.lastEffect), + null === create + ? (componentUpdateQueue.lastEffect = tag.next = tag) + : ((destroy = create.next), + (create.next = tag), + (tag.next = destroy), + (componentUpdateQueue.lastEffect = tag))); + return tag; +} +function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = mountWorkInProgressHook(); + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect( + hookEffectTag, + create, + void 0, + void 0 === deps ? null : deps + ); +} +function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var destroy = void 0; + if (null !== currentHook) { + var prevEffect = currentHook.memoizedState; + destroy = prevEffect.destroy; + if (null !== deps && areHookInputsEqual(deps, prevEffect.deps)) { + pushEffect(NoEffect$1, create, destroy, deps); + return; + } + } + sideEffectTag |= fiberEffectTag; + hook.memoizedState = pushEffect(hookEffectTag, create, destroy, deps); +} +function imperativeHandleEffect(create, ref) { + if ("function" === typeof ref) + return ( + (create = create()), + ref(create), + function() { + ref(null); + } + ); + if (null !== ref && void 0 !== ref) + return ( + (create = create()), + (ref.current = create), + function() { + ref.current = null; + } + ); +} +function mountDebugValue() {} +function dispatchAction(fiber, queue, action) { + invariant( + 25 > numberOfReRenders, + "Too many re-renders. React limits the number of renders to prevent an infinite loop." + ); + var alternate = fiber.alternate; + if ( + fiber === currentlyRenderingFiber$1 || + (null !== alternate && alternate === currentlyRenderingFiber$1) + ) + if ( + ((didScheduleRenderPhaseUpdate = !0), + (fiber = { + expirationTime: renderExpirationTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }), + null === renderPhaseUpdates && (renderPhaseUpdates = new Map()), + (action = renderPhaseUpdates.get(queue)), + void 0 === action) + ) + renderPhaseUpdates.set(queue, fiber); + else { + for (queue = action; null !== queue.next; ) queue = queue.next; + queue.next = fiber; + } + else { + flushPassiveEffects(); + var currentTime = requestCurrentTime(); + currentTime = computeExpirationForFiber(currentTime, fiber); + var _update2 = { + expirationTime: currentTime, + action: action, + eagerReducer: null, + eagerState: null, + next: null + }, + _last = queue.last; + if (null === _last) _update2.next = _update2; + else { + var first = _last.next; + null !== first && (_update2.next = first); + _last.next = _update2; + } + queue.last = _update2; + if ( + 0 === fiber.expirationTime && + (null === alternate || 0 === alternate.expirationTime) && + ((alternate = queue.eagerReducer), null !== alternate) + ) + try { + var currentState = queue.eagerState, + _eagerState = alternate(currentState, action); + _update2.eagerReducer = alternate; + _update2.eagerState = _eagerState; + if (is(_eagerState, currentState)) return; + } catch (error) { + } finally { + } + scheduleWork(fiber, currentTime); + } +} +var ContextOnlyDispatcher = { + readContext: readContext, + useCallback: throwInvalidHookError, + useContext: throwInvalidHookError, + useEffect: throwInvalidHookError, + useImperativeHandle: throwInvalidHookError, + useLayoutEffect: throwInvalidHookError, + useMemo: throwInvalidHookError, + useReducer: throwInvalidHookError, + useRef: throwInvalidHookError, + useState: throwInvalidHookError, + useDebugValue: throwInvalidHookError + }, + HooksDispatcherOnMount = { + readContext: readContext, + useCallback: function(callback, deps) { + mountWorkInProgressHook().memoizedState = [ + callback, + void 0 === deps ? null : deps + ]; + return callback; + }, + useContext: readContext, + useEffect: function(create, deps) { + return mountEffectImpl(516, UnmountPassive | MountPassive, create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + deps = null !== deps && void 0 !== deps ? deps.concat([ref]) : [ref]; + return mountEffectImpl( + 4, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + deps + ); + }, + useLayoutEffect: function(create, deps) { + return mountEffectImpl(4, UnmountMutation | MountLayout, create, deps); + }, + useMemo: function(nextCreate, deps) { + var hook = mountWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + nextCreate = nextCreate(); + hook.memoizedState = [nextCreate, deps]; + return nextCreate; + }, + useReducer: function(reducer, initialArg, init) { + var hook = mountWorkInProgressHook(); + initialArg = void 0 !== init ? init(initialArg) : initialArg; + hook.memoizedState = hook.baseState = initialArg; + reducer = hook.queue = { + last: null, + dispatch: null, + eagerReducer: reducer, + eagerState: initialArg + }; + reducer = reducer.dispatch = dispatchAction.bind( + null, + currentlyRenderingFiber$1, + reducer + ); + return [hook.memoizedState, reducer]; + }, + useRef: function(initialValue) { + var hook = mountWorkInProgressHook(); + initialValue = { current: initialValue }; + return (hook.memoizedState = initialValue); + }, + useState: function(initialState) { + var hook = mountWorkInProgressHook(); + "function" === typeof initialState && (initialState = initialState()); + hook.memoizedState = hook.baseState = initialState; + initialState = hook.queue = { + last: null, + dispatch: null, + eagerReducer: basicStateReducer, + eagerState: initialState + }; + initialState = initialState.dispatch = dispatchAction.bind( + null, + currentlyRenderingFiber$1, + initialState + ); + return [hook.memoizedState, initialState]; + }, + useDebugValue: mountDebugValue + }, + HooksDispatcherOnUpdate = { + readContext: readContext, + useCallback: function(callback, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var prevState = hook.memoizedState; + if ( + null !== prevState && + null !== deps && + areHookInputsEqual(deps, prevState[1]) + ) + return prevState[0]; + hook.memoizedState = [callback, deps]; + return callback; + }, + useContext: readContext, + useEffect: function(create, deps) { + return updateEffectImpl(516, UnmountPassive | MountPassive, create, deps); + }, + useImperativeHandle: function(ref, create, deps) { + deps = null !== deps && void 0 !== deps ? deps.concat([ref]) : [ref]; + return updateEffectImpl( + 4, + UnmountMutation | MountLayout, + imperativeHandleEffect.bind(null, create, ref), + deps + ); + }, + useLayoutEffect: function(create, deps) { + return updateEffectImpl(4, UnmountMutation | MountLayout, create, deps); + }, + useMemo: function(nextCreate, deps) { + var hook = updateWorkInProgressHook(); + deps = void 0 === deps ? null : deps; + var prevState = hook.memoizedState; + if ( + null !== prevState && + null !== deps && + areHookInputsEqual(deps, prevState[1]) + ) + return prevState[0]; + nextCreate = nextCreate(); + hook.memoizedState = [nextCreate, deps]; + return nextCreate; + }, + useReducer: updateReducer, + useRef: function() { + return updateWorkInProgressHook().memoizedState; + }, + useState: function(initialState) { + return updateReducer(basicStateReducer, initialState); + }, + useDebugValue: mountDebugValue + }, + commitTime = 0, + profilerStartTime = -1; +function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) { + if (0 <= profilerStartTime) { + var elapsedTime = now$1() - profilerStartTime; + fiber.actualDuration += elapsedTime; + overrideBaseTime && (fiber.selfBaseDuration = elapsedTime); + profilerStartTime = -1; + } +} +var 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 = createFiber(5, null, null, 0); + fiber.elementType = "DELETED"; + 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); + } +} +var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner, + didReceiveUpdate = !1; +function reconcileChildren( + current$$1, + workInProgress, + nextChildren, + renderExpirationTime +) { + workInProgress.child = + null === current$$1 + ? mountChildFibers( workInProgress, null, nextChildren, @@ -3430,7 +3644,26 @@ function updateForwardRef( Component = Component.render; var ref = workInProgress.ref; prepareToReadContext(workInProgress, renderExpirationTime); - nextProps = Component(nextProps, ref); + nextProps = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + ref, + renderExpirationTime + ); + if (null !== current$$1 && !didReceiveUpdate) + return ( + (workInProgress.updateQueue = current$$1.updateQueue), + (workInProgress.effectTag &= -517), + current$$1.expirationTime <= renderExpirationTime && + (current$$1.expirationTime = 0), + bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ) + ); workInProgress.effectTag |= 1; reconcileChildren( current$$1, @@ -3510,9 +3743,9 @@ function updateSimpleMemoComponent( renderExpirationTime ) { return null !== current$$1 && - updateExpirationTime < renderExpirationTime && shallowEqual(current$$1.memoizedProps, nextProps) && - current$$1.ref === workInProgress.ref + current$$1.ref === workInProgress.ref && + ((didReceiveUpdate = !1), updateExpirationTime < renderExpirationTime) ? bailoutOnAlreadyFinishedWork( current$$1, workInProgress, @@ -3546,7 +3779,26 @@ function updateFunctionComponent( : contextStackCursor.current; unmaskedContext = getMaskedContext(workInProgress, unmaskedContext); prepareToReadContext(workInProgress, renderExpirationTime); - Component = Component(nextProps, unmaskedContext); + Component = renderWithHooks( + current$$1, + workInProgress, + Component, + nextProps, + unmaskedContext, + renderExpirationTime + ); + if (null !== current$$1 && !didReceiveUpdate) + return ( + (workInProgress.updateQueue = current$$1.updateQueue), + (workInProgress.effectTag &= -517), + current$$1.expirationTime <= renderExpirationTime && + (current$$1.expirationTime = 0), + bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ) + ); workInProgress.effectTag |= 1; reconcileChildren( current$$1, @@ -3593,9 +3845,7 @@ function updateClassComponent( var oldContext = instance.context, contextType = Component.contextType; "object" === typeof contextType && null !== contextType - ? (contextType = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (contextType = readContext(contextType)) : ((contextType = isContextProvider(Component) ? previousContext : contextStackCursor.current), @@ -3680,9 +3930,7 @@ function updateClassComponent( (oldContext = instance.context), (contextType = Component.contextType), "object" === typeof contextType && null !== contextType - ? (contextType = ReactCurrentOwner$4.currentDispatcher.readContext( - contextType - )) + ? (contextType = readContext(contextType)) : ((contextType = isContextProvider(Component) ? previousContext : contextStackCursor.current), @@ -3868,104 +4116,119 @@ function updateSuspenseComponent( (nextDidTimeout = !0), (workInProgress.effectTag &= -65); if (null === current$$1) - nextDidTimeout - ? ((nextDidTimeout = nextProps.fallback), - (nextProps = createFiberFromFragment(null, mode, 0, null)), - 0 === (workInProgress.mode & 1) && - (nextProps.child = - null !== workInProgress.memoizedState - ? workInProgress.child.child - : workInProgress.child), - (renderExpirationTime = createFiberFromFragment( - nextDidTimeout, - mode, - renderExpirationTime, - null - )), - (nextProps.sibling = renderExpirationTime), - (mode = nextProps), - (mode.return = renderExpirationTime.return = workInProgress)) - : (mode = renderExpirationTime = mountChildFibers( - workInProgress, - null, - nextProps.children, - renderExpirationTime - )); - else if (null !== current$$1.memoizedState) - if ( - ((current$$1 = current$$1.child), - (mode = current$$1.sibling), - nextDidTimeout) - ) { - nextProps = nextProps.fallback; - renderExpirationTime = createWorkInProgress( - current$$1, - current$$1.pendingProps, - 0 - ); + if (nextDidTimeout) { + var nextFallbackChildren = nextProps.fallback; + current$$1 = createFiberFromFragment(null, mode, 0, null); 0 === (workInProgress.mode & 1) && - ((nextDidTimeout = + (current$$1.child = null !== workInProgress.memoizedState ? workInProgress.child.child - : workInProgress.child), - nextDidTimeout !== current$$1.child && - (renderExpirationTime.child = nextDidTimeout)); - if (workInProgress.mode & 4) { - nextDidTimeout = 0; - for (current$$1 = renderExpirationTime.child; null !== current$$1; ) - (nextDidTimeout += current$$1.treeBaseDuration), - (current$$1 = current$$1.sibling); - renderExpirationTime.treeBaseDuration = nextDidTimeout; - } - nextProps = renderExpirationTime.sibling = createWorkInProgress( + : workInProgress.child); + renderExpirationTime = createFiberFromFragment( + nextFallbackChildren, mode, - nextProps, - mode.expirationTime + renderExpirationTime, + null ); - mode = renderExpirationTime; - renderExpirationTime.childExpirationTime = 0; - renderExpirationTime = nextProps; + current$$1.sibling = renderExpirationTime; + mode = current$$1; mode.return = renderExpirationTime.return = workInProgress; } else - mode = renderExpirationTime = reconcileChildFibers( + mode = renderExpirationTime = mountChildFibers( workInProgress, - current$$1.child, + null, nextProps.children, renderExpirationTime ); - else if (((current$$1 = current$$1.child), nextDidTimeout)) { - nextDidTimeout = nextProps.fallback; - nextProps = createFiberFromFragment(null, mode, 0, null); - nextProps.child = current$$1; - 0 === (workInProgress.mode & 1) && - (nextProps.child = - null !== workInProgress.memoizedState - ? workInProgress.child.child - : workInProgress.child); - if (workInProgress.mode & 4) { - current$$1 = 0; - for (var _hiddenChild = nextProps.child; null !== _hiddenChild; ) - (current$$1 += _hiddenChild.treeBaseDuration), - (_hiddenChild = _hiddenChild.sibling); - nextProps.treeBaseDuration = current$$1; + else { + if (null !== current$$1.memoizedState) + if ( + ((nextFallbackChildren = current$$1.child), + (mode = nextFallbackChildren.sibling), + nextDidTimeout) + ) { + nextProps = nextProps.fallback; + renderExpirationTime = createWorkInProgress( + nextFallbackChildren, + nextFallbackChildren.pendingProps, + 0 + ); + 0 === (workInProgress.mode & 1) && + ((nextDidTimeout = + null !== workInProgress.memoizedState + ? workInProgress.child.child + : workInProgress.child), + nextDidTimeout !== nextFallbackChildren.child && + (renderExpirationTime.child = nextDidTimeout)); + if (workInProgress.mode & 4) { + nextFallbackChildren = 0; + for ( + nextDidTimeout = renderExpirationTime.child; + null !== nextDidTimeout; + + ) + (nextFallbackChildren += nextDidTimeout.treeBaseDuration), + (nextDidTimeout = nextDidTimeout.sibling); + renderExpirationTime.treeBaseDuration = nextFallbackChildren; + } + nextFallbackChildren = renderExpirationTime.sibling = createWorkInProgress( + mode, + nextProps, + mode.expirationTime + ); + mode = renderExpirationTime; + renderExpirationTime.childExpirationTime = 0; + renderExpirationTime = nextFallbackChildren; + mode.return = renderExpirationTime.return = workInProgress; + } else + mode = renderExpirationTime = reconcileChildFibers( + workInProgress, + nextFallbackChildren.child, + nextProps.children, + renderExpirationTime + ); + else { + var _currentPrimaryChild = current$$1.child; + if (nextDidTimeout) { + nextProps = nextProps.fallback; + nextFallbackChildren = createFiberFromFragment(null, mode, 0, null); + nextFallbackChildren.child = _currentPrimaryChild; + 0 === (workInProgress.mode & 1) && + (nextFallbackChildren.child = + null !== workInProgress.memoizedState + ? workInProgress.child.child + : workInProgress.child); + if (workInProgress.mode & 4) { + nextDidTimeout = 0; + for ( + _currentPrimaryChild = nextFallbackChildren.child; + null !== _currentPrimaryChild; + + ) + (nextDidTimeout += _currentPrimaryChild.treeBaseDuration), + (_currentPrimaryChild = _currentPrimaryChild.sibling); + nextFallbackChildren.treeBaseDuration = nextDidTimeout; + } + renderExpirationTime = nextFallbackChildren.sibling = createFiberFromFragment( + nextProps, + mode, + renderExpirationTime, + null + ); + renderExpirationTime.effectTag |= 2; + mode = nextFallbackChildren; + nextFallbackChildren.childExpirationTime = 0; + mode.return = renderExpirationTime.return = workInProgress; + } else + renderExpirationTime = mode = reconcileChildFibers( + workInProgress, + _currentPrimaryChild, + nextProps.children, + renderExpirationTime + ); } - renderExpirationTime = nextProps.sibling = createFiberFromFragment( - nextDidTimeout, - mode, - renderExpirationTime, - null - ); - renderExpirationTime.effectTag |= 2; - mode = nextProps; - nextProps.childExpirationTime = 0; - mode.return = renderExpirationTime.return = workInProgress; - } else - renderExpirationTime = mode = reconcileChildFibers( - workInProgress, - current$$1, - nextProps.children, - renderExpirationTime - ); + workInProgress.stateNode = current$$1.stateNode; + } workInProgress.memoizedState = nextState; workInProgress.child = mode; return renderExpirationTime; @@ -3976,7 +4239,7 @@ function bailoutOnAlreadyFinishedWork( renderExpirationTime ) { null !== current$$1 && - (workInProgress.firstContextDependency = current$$1.firstContextDependency); + (workInProgress.contextDependencies = current$$1.contextDependencies); profilerStartTime = -1; if (workInProgress.childExpirationTime < renderExpirationTime) return null; invariant( @@ -4009,61 +4272,66 @@ function bailoutOnAlreadyFinishedWork( } function beginWork(current$$1, workInProgress, renderExpirationTime) { var updateExpirationTime = workInProgress.expirationTime; - if ( - null !== current$$1 && - current$$1.memoizedProps === workInProgress.pendingProps && - !didPerformWorkStackCursor.current && - updateExpirationTime < renderExpirationTime - ) { - switch (workInProgress.tag) { - case 3: - pushHostRootContext(workInProgress); - break; - case 5: - pushHostContext(workInProgress); - break; - case 1: - isContextProvider(workInProgress.type) && - pushContextProvider(workInProgress); - break; - case 4: - pushHostContainer( - workInProgress, - workInProgress.stateNode.containerInfo - ); - break; - case 10: - pushProvider(workInProgress, workInProgress.memoizedProps.value); - break; - case 12: - workInProgress.effectTag |= 4; - break; - case 13: - if (null !== workInProgress.memoizedState) { - updateExpirationTime = workInProgress.child.childExpirationTime; - if ( - 0 !== updateExpirationTime && - updateExpirationTime >= renderExpirationTime - ) - return updateSuspenseComponent( - current$$1, + if (null !== current$$1) + if ( + current$$1.memoizedProps !== workInProgress.pendingProps || + didPerformWorkStackCursor.current + ) + didReceiveUpdate = !0; + else { + if (updateExpirationTime < renderExpirationTime) { + didReceiveUpdate = !1; + switch (workInProgress.tag) { + case 3: + pushHostRootContext(workInProgress); + break; + case 5: + pushHostContext(workInProgress); + break; + case 1: + isContextProvider(workInProgress.type) && + pushContextProvider(workInProgress); + break; + case 4: + pushHostContainer( workInProgress, - renderExpirationTime + workInProgress.stateNode.containerInfo ); - workInProgress = bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); - return null !== workInProgress ? workInProgress.sibling : null; + break; + case 10: + pushProvider(workInProgress, workInProgress.memoizedProps.value); + break; + case 12: + workInProgress.effectTag |= 4; + break; + case 13: + if (null !== workInProgress.memoizedState) { + updateExpirationTime = workInProgress.child.childExpirationTime; + if ( + 0 !== updateExpirationTime && + updateExpirationTime >= renderExpirationTime + ) + return updateSuspenseComponent( + current$$1, + workInProgress, + renderExpirationTime + ); + workInProgress = bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + return null !== workInProgress ? workInProgress.sibling : null; + } } + return bailoutOnAlreadyFinishedWork( + current$$1, + workInProgress, + renderExpirationTime + ); + } } - return bailoutOnAlreadyFinishedWork( - current$$1, - workInProgress, - renderExpirationTime - ); - } + else didReceiveUpdate = !1; workInProgress.expirationTime = 0; switch (workInProgress.tag) { case 2: @@ -4078,7 +4346,14 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { contextStackCursor.current ); prepareToReadContext(workInProgress, renderExpirationTime); - context = updateExpirationTime(current$$1, context); + context = renderWithHooks( + null, + workInProgress, + updateExpirationTime, + current$$1, + context, + renderExpirationTime + ); workInProgress.effectTag |= 1; if ( "object" === typeof context && @@ -4087,6 +4362,7 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { void 0 === context.$$typeof ) { workInProgress.tag = 1; + resetHooks(); if (isContextProvider(updateExpirationTime)) { var hasContext = !0; pushContextProvider(workInProgress); @@ -4359,18 +4635,14 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { pushProvider(workInProgress, hasContext); if (null !== getDerivedStateFromProps) { var oldValue = getDerivedStateFromProps.value; - hasContext = - (oldValue === hasContext && - (0 !== oldValue || 1 / oldValue === 1 / hasContext)) || - (oldValue !== oldValue && hasContext !== hasContext) - ? 0 - : ("function" === - typeof updateExpirationTime._calculateChangedBits - ? updateExpirationTime._calculateChangedBits( - oldValue, - hasContext - ) - : 1073741823) | 0; + hasContext = is(oldValue, hasContext) + ? 0 + : ("function" === typeof updateExpirationTime._calculateChangedBits + ? updateExpirationTime._calculateChangedBits( + oldValue, + hasContext + ) + : 1073741823) | 0; if (0 === hasContext) { if ( getDerivedStateFromProps.children === context.children && @@ -4385,83 +4657,79 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { } } else for ( - getDerivedStateFromProps = workInProgress.child, - null !== getDerivedStateFromProps && - (getDerivedStateFromProps.return = workInProgress); - null !== getDerivedStateFromProps; + oldValue = workInProgress.child, + null !== oldValue && (oldValue.return = workInProgress); + null !== oldValue; ) { - oldValue = getDerivedStateFromProps.firstContextDependency; - if (null !== oldValue) { - do { + var list = oldValue.contextDependencies; + if (null !== list) { + getDerivedStateFromProps = oldValue.child; + for (var dependency = list.first; null !== dependency; ) { if ( - oldValue.context === updateExpirationTime && - 0 !== (oldValue.observedBits & hasContext) + dependency.context === updateExpirationTime && + 0 !== (dependency.observedBits & hasContext) ) { - if (1 === getDerivedStateFromProps.tag) { - var nextFiber = createUpdate(renderExpirationTime); - nextFiber.tag = 2; - enqueueUpdate(getDerivedStateFromProps, nextFiber); - } - getDerivedStateFromProps.expirationTime < - renderExpirationTime && - (getDerivedStateFromProps.expirationTime = renderExpirationTime); - nextFiber = getDerivedStateFromProps.alternate; - null !== nextFiber && - nextFiber.expirationTime < renderExpirationTime && - (nextFiber.expirationTime = renderExpirationTime); - for ( - var node = getDerivedStateFromProps.return; - null !== node; - - ) { - nextFiber = node.alternate; + 1 === oldValue.tag && + ((dependency = createUpdate(renderExpirationTime)), + (dependency.tag = ForceUpdate), + enqueueUpdate(oldValue, dependency)); + oldValue.expirationTime < renderExpirationTime && + (oldValue.expirationTime = renderExpirationTime); + dependency = oldValue.alternate; + null !== dependency && + dependency.expirationTime < renderExpirationTime && + (dependency.expirationTime = renderExpirationTime); + for (var node = oldValue.return; null !== node; ) { + dependency = node.alternate; if (node.childExpirationTime < renderExpirationTime) (node.childExpirationTime = renderExpirationTime), - null !== nextFiber && - nextFiber.childExpirationTime < + null !== dependency && + dependency.childExpirationTime < renderExpirationTime && - (nextFiber.childExpirationTime = renderExpirationTime); + (dependency.childExpirationTime = renderExpirationTime); else if ( - null !== nextFiber && - nextFiber.childExpirationTime < renderExpirationTime + null !== dependency && + dependency.childExpirationTime < renderExpirationTime ) - nextFiber.childExpirationTime = renderExpirationTime; + dependency.childExpirationTime = renderExpirationTime; else break; node = node.return; } + list.expirationTime < renderExpirationTime && + (list.expirationTime = renderExpirationTime); + break; } - nextFiber = getDerivedStateFromProps.child; - oldValue = oldValue.next; - } while (null !== oldValue); + dependency = dependency.next; + } } else - nextFiber = - 10 === getDerivedStateFromProps.tag - ? getDerivedStateFromProps.type === workInProgress.type + getDerivedStateFromProps = + 10 === oldValue.tag + ? oldValue.type === workInProgress.type ? null - : getDerivedStateFromProps.child - : getDerivedStateFromProps.child; - if (null !== nextFiber) - nextFiber.return = getDerivedStateFromProps; + : oldValue.child + : oldValue.child; + if (null !== getDerivedStateFromProps) + getDerivedStateFromProps.return = oldValue; else for ( - nextFiber = getDerivedStateFromProps; - null !== nextFiber; + getDerivedStateFromProps = oldValue; + null !== getDerivedStateFromProps; ) { - if (nextFiber === workInProgress) { - nextFiber = null; + if (getDerivedStateFromProps === workInProgress) { + getDerivedStateFromProps = null; break; } - getDerivedStateFromProps = nextFiber.sibling; - if (null !== getDerivedStateFromProps) { - getDerivedStateFromProps.return = nextFiber.return; - nextFiber = getDerivedStateFromProps; + oldValue = getDerivedStateFromProps.sibling; + if (null !== oldValue) { + oldValue.return = getDerivedStateFromProps.return; + getDerivedStateFromProps = oldValue; break; } - nextFiber = nextFiber.return; + getDerivedStateFromProps = getDerivedStateFromProps.return; } - getDerivedStateFromProps = nextFiber; + oldValue = getDerivedStateFromProps; } } reconcileChildren( @@ -4541,26 +4809,311 @@ function beginWork(current$$1, workInProgress, renderExpirationTime) { ), mountClassInstance( workInProgress, - updateExpirationTime, - context, - renderExpirationTime - ), - finishClassComponent( - null, + updateExpirationTime, + context, + renderExpirationTime + ), + finishClassComponent( + null, + workInProgress, + updateExpirationTime, + !0, + current$$1, + renderExpirationTime + ) + ); + default: + invariant( + !1, + "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + ); + } +} +var valueCursor = { current: null }, + currentlyRenderingFiber = null, + lastContextDependency = null, + lastContextWithAllBitsObserved = null; +function pushProvider(providerFiber, nextValue) { + var context = providerFiber.type._context; + push(valueCursor, context._currentValue, providerFiber); + context._currentValue = nextValue; +} +function popProvider(providerFiber) { + var currentValue = valueCursor.current; + pop(valueCursor, providerFiber); + providerFiber.type._context._currentValue = currentValue; +} +function prepareToReadContext(workInProgress, renderExpirationTime) { + currentlyRenderingFiber = workInProgress; + lastContextWithAllBitsObserved = lastContextDependency = null; + var currentDependencies = workInProgress.contextDependencies; + null !== currentDependencies && + currentDependencies.expirationTime >= renderExpirationTime && + (didReceiveUpdate = !0); + workInProgress.contextDependencies = null; +} +function readContext(context, observedBits) { + if ( + lastContextWithAllBitsObserved !== context && + !1 !== observedBits && + 0 !== observedBits + ) { + if ("number" !== typeof observedBits || 1073741823 === observedBits) + (lastContextWithAllBitsObserved = context), (observedBits = 1073741823); + observedBits = { context: context, observedBits: observedBits, next: null }; + null === lastContextDependency + ? (invariant( + null !== currentlyRenderingFiber, + "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()." + ), + (lastContextDependency = observedBits), + (currentlyRenderingFiber.contextDependencies = { + first: observedBits, + expirationTime: 0 + })) + : (lastContextDependency = lastContextDependency.next = observedBits); + } + return context._currentValue; +} +var UpdateState = 0, + ReplaceState = 1, + ForceUpdate = 2, + CaptureUpdate = 3, + hasForceUpdate = !1; +function createUpdateQueue(baseState) { + return { + baseState: baseState, + firstUpdate: null, + lastUpdate: null, + firstCapturedUpdate: null, + lastCapturedUpdate: null, + firstEffect: null, + lastEffect: null, + firstCapturedEffect: null, + lastCapturedEffect: null + }; +} +function cloneUpdateQueue(currentQueue) { + return { + 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: UpdateState, + payload: null, + callback: null, + next: null, + nextEffect: null + }; +} +function appendUpdateToQueue(queue, update) { + null === queue.lastUpdate + ? (queue.firstUpdate = queue.lastUpdate = update) + : ((queue.lastUpdate.next = update), (queue.lastUpdate = update)); +} +function enqueueUpdate(fiber, update) { + 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) + : null === queue1.lastUpdate || null === queue2.lastUpdate + ? (appendUpdateToQueue(queue1, update), + appendUpdateToQueue(queue2, update)) + : (appendUpdateToQueue(queue1, update), (queue2.lastUpdate = update)); +} +function enqueueCapturedUpdate(workInProgress, update) { + 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)); +} +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 ReplaceState: + return ( + (workInProgress = update.payload), + "function" === typeof workInProgress + ? workInProgress.call(instance, prevState, nextProps) + : workInProgress + ); + case CaptureUpdate: + workInProgress.effectTag = (workInProgress.effectTag & -2049) | 64; + case UpdateState: + 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 ForceUpdate: + hasForceUpdate = !0; + } + return prevState; +} +function processUpdateQueue( + workInProgress, + queue, + props, + instance, + renderExpirationTime +) { + hasForceUpdate = !1; + queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue); + for ( + var newBaseState = queue.baseState, + newFirstUpdate = null, + newExpirationTime = 0, + update = queue.firstUpdate, + resultState = newBaseState; + null !== update; + + ) { + var updateExpirationTime = update.expirationTime; + updateExpirationTime < renderExpirationTime + ? (null === newFirstUpdate && + ((newFirstUpdate = update), (newBaseState = resultState)), + newExpirationTime < updateExpirationTime && + (newExpirationTime = updateExpirationTime)) + : ((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; + _updateExpirationTime < renderExpirationTime + ? (null === updateExpirationTime && + ((updateExpirationTime = update), + null === newFirstUpdate && (newBaseState = resultState)), + newExpirationTime < _updateExpirationTime && + (newExpirationTime = _updateExpirationTime)) + : ((resultState = getStateFromUpdate( workInProgress, - updateExpirationTime, - !0, - current$$1, - renderExpirationTime - ) - ); - default: + 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; + workInProgress.expirationTime = newExpirationTime; + workInProgress.memoizedState = resultState; +} +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)); + commitUpdateEffects(finishedQueue.firstEffect, instance); + finishedQueue.firstEffect = finishedQueue.lastEffect = null; + commitUpdateEffects(finishedQueue.firstCapturedEffect, instance); + finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null; +} +function commitUpdateEffects(effect, instance) { + for (; null !== effect; ) { + var _callback3 = effect.callback; + if (null !== _callback3) { + effect.callback = null; + var context = instance; invariant( - !1, - "Unknown unit of work tag. This error is likely caused by a bug in React. Please file an issue." + "function" === typeof _callback3, + "Invalid argument passed as callback. Expected a function. Instead received: %s", + _callback3 ); + _callback3.call(context); + } + effect = effect.nextEffect; } } +function createCapturedValue(value, source) { + return { + value: value, + source: source, + stack: getStackByFiberInDevAndProd(source) + }; +} var appendAllChildren = void 0, updateHostContainer = void 0, updateHostComponent$1 = void 0, @@ -4611,6 +5164,7 @@ function logCapturedError(capturedError) { : Error("Unspecified error at:" + componentStack); ExceptionsManager.handleException(error, !1); } +var PossiblyWeakSet = "function" === typeof WeakSet ? WeakSet : Set; function logError(boundary, errorInfo) { var source = errorInfo.source, stack = errorInfo.stack; @@ -4651,6 +5205,81 @@ function safelyDetachRef(current$$1) { } else ref.current = null; } +function commitHookEffectList(unmountTag, mountTag, finishedWork) { + finishedWork = finishedWork.updateQueue; + finishedWork = null !== finishedWork ? finishedWork.lastEffect : null; + if (null !== finishedWork) { + var effect = (finishedWork = finishedWork.next); + do { + if ((effect.tag & unmountTag) !== NoEffect$1) { + var destroy = effect.destroy; + effect.destroy = void 0; + void 0 !== destroy && destroy(); + } + (effect.tag & mountTag) !== NoEffect$1 && + ((destroy = effect.create), (effect.destroy = destroy())); + effect = effect.next; + } while (effect !== finishedWork); + } +} +function hideOrUnhideAllChildren(finishedWork, isHidden) { + for (var node = finishedWork; ; ) { + if (5 === node.tag) { + var instance = node.stateNode; + if (isHidden) { + var viewConfig = instance.viewConfig; + var updatePayload = diffProperties( + null, + emptyObject, + { style: { display: "none" } }, + viewConfig.validAttributes + ); + UIManager.updateView( + instance._nativeTag, + viewConfig.uiViewClassName, + updatePayload + ); + } else { + instance = node.stateNode; + updatePayload = node.memoizedProps; + viewConfig = instance.viewConfig; + var prevProps = Object.assign({}, updatePayload, { + style: [updatePayload.style, { display: "none" }] + }); + updatePayload = diffProperties( + null, + prevProps, + updatePayload, + viewConfig.validAttributes + ); + UIManager.updateView( + instance._nativeTag, + viewConfig.uiViewClassName, + updatePayload + ); + } + } else { + if (6 === node.tag) throw Error("Not yet implemented."); + if (13 === node.tag && null !== node.memoizedState) { + instance = node.child.sibling; + instance.return = node; + node = instance; + continue; + } else if (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 commitUnmount(current$$1$jscomp$0) { "function" === typeof onCommitFiberUnmount && onCommitFiberUnmount(current$$1$jscomp$0); @@ -4667,7 +5296,7 @@ function commitUnmount(current$$1$jscomp$0) { var effect = (updateQueue = updateQueue.next); do { var destroy = effect.destroy; - if (null !== destroy) { + if (void 0 !== destroy) { var current$$1 = current$$1$jscomp$0; try { destroy(); @@ -4938,6 +5567,7 @@ function commitWork(current$$1, finishedWork) { case 11: case 14: case 15: + commitHookEffectList(UnmountMutation, MountMutation, finishedWork); break; case 1: break; @@ -4946,23 +5576,18 @@ function commitWork(current$$1, finishedWork) { if (null != instance) { var newProps = finishedWork.memoizedProps; current$$1 = null !== current$$1 ? current$$1.memoizedProps : newProps; - var updatePayload = finishedWork.updateQueue; + var type = finishedWork.type, + updatePayload = finishedWork.updateQueue; finishedWork.updateQueue = null; null !== updatePayload && - ((finishedWork = instance.viewConfig), - (instanceProps[instance._nativeTag] = newProps), - (newProps = diffProperties( - null, + commitUpdate( + instance, + updatePayload, + type, current$$1, newProps, - finishedWork.validAttributes - )), - null != newProps && - UIManager.updateView( - instance._nativeTag, - finishedWork.uiViewClassName, - newProps - )); + finishedWork + ); } break; case 6: @@ -4979,71 +5604,29 @@ function commitWork(current$$1, finishedWork) { case 12: break; case 13: - newProps = finishedWork.memoizedState; + instance = finishedWork.memoizedState; + newProps = void 0; current$$1 = finishedWork; - null === newProps - ? (instance = !1) - : ((instance = !0), + null === instance + ? (newProps = !1) + : ((newProps = !0), (current$$1 = finishedWork.child), - 0 === newProps.timedOutAt && - (newProps.timedOutAt = requestCurrentTime())); - if (null !== current$$1) - a: for (newProps = finishedWork = current$$1; ; ) { - if (5 === newProps.tag) - if (((current$$1 = newProps.stateNode), instance)) { - updatePayload = current$$1.viewConfig; - var updatePayload$jscomp$0 = diffProperties( - null, - emptyObject, - { style: { display: "none" } }, - updatePayload.validAttributes - ); - UIManager.updateView( - current$$1._nativeTag, - updatePayload.uiViewClassName, - updatePayload$jscomp$0 - ); - } else { - current$$1 = newProps.stateNode; - updatePayload$jscomp$0 = newProps.memoizedProps; - updatePayload = current$$1.viewConfig; - var prevProps = Object.assign({}, updatePayload$jscomp$0, { - style: [updatePayload$jscomp$0.style, { display: "none" }] - }); - updatePayload$jscomp$0 = diffProperties( - null, - prevProps, - updatePayload$jscomp$0, - updatePayload.validAttributes - ); - UIManager.updateView( - current$$1._nativeTag, - updatePayload.uiViewClassName, - updatePayload$jscomp$0 - ); - } - else { - if (6 === newProps.tag) throw Error("Not yet implemented."); - if (13 === newProps.tag && null !== newProps.memoizedState) { - current$$1 = newProps.child.sibling; - current$$1.return = newProps; - newProps = current$$1; - continue; - } else if (null !== newProps.child) { - newProps.child.return = newProps; - newProps = newProps.child; - continue; - } - } - if (newProps === finishedWork) break a; - for (; null === newProps.sibling; ) { - if (null === newProps.return || newProps.return === finishedWork) - break a; - newProps = newProps.return; - } - newProps.sibling.return = newProps.return; - newProps = newProps.sibling; - } + 0 === instance.timedOutAt && + (instance.timedOutAt = requestCurrentTime())); + null !== current$$1 && hideOrUnhideAllChildren(current$$1, newProps); + instance = finishedWork.updateQueue; + if (null !== instance) { + finishedWork.updateQueue = null; + var retryCache = finishedWork.stateNode; + null === retryCache && + (retryCache = finishedWork.stateNode = new PossiblyWeakSet()); + instance.forEach(function(thenable) { + var retry = retryTimedOutBoundary.bind(null, finishedWork, thenable); + retry = tracing.unstable_wrap(retry); + retryCache.has(thenable) || + (retryCache.add(thenable), thenable.then(retry, retry)); + }); + } break; case 17: break; @@ -5054,9 +5637,10 @@ function commitWork(current$$1, finishedWork) { ); } } +var PossiblyWeakMap = "function" === typeof WeakMap ? WeakMap : Map; function createRootErrorUpdate(fiber, errorInfo, expirationTime) { expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; + expirationTime.tag = CaptureUpdate; expirationTime.payload = { element: null }; var error = errorInfo.value; expirationTime.callback = function() { @@ -5067,7 +5651,7 @@ function createRootErrorUpdate(fiber, errorInfo, expirationTime) { } function createClassErrorUpdate(fiber, errorInfo, expirationTime) { expirationTime = createUpdate(expirationTime); - expirationTime.tag = 3; + expirationTime.tag = CaptureUpdate; var getDerivedStateFromError = fiber.type.getDerivedStateFromError; if ("function" === typeof getDerivedStateFromError) { var error$jscomp$0 = errorInfo.value; @@ -5136,24 +5720,43 @@ function throwException( ? !1 : null === value.memoizedState; if (current$$1) { - returnFiber = retrySuspendedRoot.bind( - null, - root, - value, - sourceFiber, - 0 === (value.mode & 1) ? 1073741823 : renderExpirationTime - ); - returnFiber = tracing.unstable_wrap(returnFiber); - thenable.then(returnFiber, returnFiber); + returnFiber = value.updateQueue; + null === returnFiber + ? ((returnFiber = new Set()), + returnFiber.add(thenable), + (value.updateQueue = returnFiber)) + : returnFiber.add(thenable); if (0 === (value.mode & 1)) { value.effectTag |= 64; sourceFiber.effectTag &= -1957; 1 === sourceFiber.tag && - null === sourceFiber.alternate && - (sourceFiber.tag = 17); - sourceFiber.expirationTime = renderExpirationTime; + (null === sourceFiber.alternate + ? (sourceFiber.tag = 17) + : ((renderExpirationTime = createUpdate(1073741823)), + (renderExpirationTime.tag = ForceUpdate), + enqueueUpdate(sourceFiber, renderExpirationTime))); + sourceFiber.expirationTime = 1073741823; return; } + sourceFiber = root.pingCache; + null === sourceFiber + ? ((sourceFiber = root.pingCache = new PossiblyWeakMap()), + (returnFiber = new Set()), + sourceFiber.set(thenable, returnFiber)) + : ((returnFiber = sourceFiber.get(thenable)), + void 0 === returnFiber && + ((returnFiber = new Set()), + sourceFiber.set(thenable, returnFiber))); + returnFiber.has(renderExpirationTime) || + (returnFiber.add(renderExpirationTime), + (sourceFiber = pingSuspendedRoot.bind( + null, + root, + thenable, + renderExpirationTime + )), + (sourceFiber = tracing.unstable_wrap(sourceFiber)), + thenable.then(sourceFiber, sourceFiber)); -1 === earliestTimeoutMs ? (root = 1073741823) : (-1 === startTimeMs && @@ -5187,33 +5790,32 @@ function throwException( do { switch (root.tag) { case 3: - sourceFiber = value; root.effectTag |= 2048; root.expirationTime = renderExpirationTime; renderExpirationTime = createRootErrorUpdate( root, - sourceFiber, + value, renderExpirationTime ); enqueueCapturedUpdate(root, renderExpirationTime); return; case 1: if ( - ((sourceFiber = value), - (returnFiber = root.type), - (thenable = root.stateNode), + ((thenable = value), + (earliestTimeoutMs = root.type), + (startTimeMs = root.stateNode), 0 === (root.effectTag & 64) && - ("function" === typeof returnFiber.getDerivedStateFromError || - (null !== thenable && - "function" === typeof thenable.componentDidCatch && + ("function" === typeof earliestTimeoutMs.getDerivedStateFromError || + (null !== startTimeMs && + "function" === typeof startTimeMs.componentDidCatch && (null === legacyErrorBoundariesThatAlreadyFailed || - !legacyErrorBoundariesThatAlreadyFailed.has(thenable))))) + !legacyErrorBoundariesThatAlreadyFailed.has(startTimeMs))))) ) { root.effectTag |= 2048; root.expirationTime = renderExpirationTime; renderExpirationTime = createClassErrorUpdate( root, - sourceFiber, + thenable, renderExpirationTime ); enqueueCapturedUpdate(root, renderExpirationTime); @@ -5262,7 +5864,7 @@ function unwindWork(workInProgress) { return null; } } -var DispatcherWithoutHooks = { readContext: readContext }, +var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher, ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner; invariant( null != tracing.__interactionsRef && @@ -5277,6 +5879,7 @@ var isWorking = !1, nextRenderDidError = !1, nextEffect = null, isCommitting$1 = !1, + rootWithPendingPassiveEffects = null, passiveEffectCallbackHandle = null, passiveEffectCallback = null, legacyErrorBoundariesThatAlreadyFailed = null; @@ -5369,6 +5972,7 @@ function commitBeforeMutationLifecycles() { case 0: case 11: case 15: + commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork); break a; case 1: if (finishedWork.effectTag & 256 && null !== current$$1) { @@ -5415,6 +6019,7 @@ function commitAllLifeCycles( case 0: case 11: case 15: + commitHookEffectList(UnmountLayout, MountLayout, finishedWork); break; case 1: finishedRoot = finishedWork.stateNode; @@ -5493,19 +6098,46 @@ function commitAllLifeCycles( } } effectTag & 128 && - ((effectTag = nextEffect.ref), - null !== effectTag && - ((finishedWork = nextEffect.stateNode), - "function" === typeof effectTag - ? effectTag(finishedWork) - : (effectTag.current = finishedWork))); + ((finishedWork = nextEffect.ref), + null !== finishedWork && + ((committedExpirationTime = nextEffect.stateNode), + "function" === typeof finishedWork + ? finishedWork(committedExpirationTime) + : (finishedWork.current = committedExpirationTime))); + effectTag & 512 && (rootWithPendingPassiveEffects = finishedRoot$jscomp$0); nextEffect = nextEffect.nextEffect; } } +function commitPassiveEffects(root, firstEffect) { + passiveEffectCallback = passiveEffectCallbackHandle = rootWithPendingPassiveEffects = null; + var previousIsRendering = isRendering; + isRendering = !0; + do { + if (firstEffect.effectTag & 512) { + var didError = !1, + error = void 0; + try { + var finishedWork = firstEffect; + commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork); + commitHookEffectList(NoEffect$1, MountPassive, finishedWork); + } catch (e) { + (didError = !0), (error = e); + } + didError && captureCommitPhaseError(firstEffect, error); + } + firstEffect = firstEffect.nextEffect; + } while (null !== firstEffect); + isRendering = previousIsRendering; + previousIsRendering = root.expirationTime; + 0 !== previousIsRendering && requestWork(root, previousIsRendering); +} function flushPassiveEffects() { - null !== passiveEffectCallback && - (scheduler.unstable_cancelCallback(passiveEffectCallbackHandle), - passiveEffectCallback()); + if (null !== passiveEffectCallbackHandle) { + var callbackID = passiveEffectCallbackHandle; + scheduledCallback = null; + clearTimeout(callbackID); + } + null !== passiveEffectCallback && passiveEffectCallback(); } function commitRoot(root, finishedWork) { isCommitting$1 = isWorking = !0; @@ -5573,21 +6205,39 @@ function commitRoot(root, finishedWork) { } root.current = finishedWork; for (nextEffect = childExpirationTimeBeforeCommit; null !== nextEffect; ) { - childExpirationTimeBeforeCommit = !1; - didError = void 0; + didError = !1; + error$jscomp$0 = void 0; try { commitAllLifeCycles(root, committedExpirationTime); } catch (e) { - (childExpirationTimeBeforeCommit = !0), (didError = e); + (didError = !0), (error$jscomp$0 = e); } - childExpirationTimeBeforeCommit && + didError && (invariant( null !== nextEffect, "Should have next effect. This error is likely caused by a bug in React. Please file an issue." ), - captureCommitPhaseError(nextEffect, didError), + captureCommitPhaseError(nextEffect, error$jscomp$0), null !== nextEffect && (nextEffect = nextEffect.nextEffect)); } + if ( + null !== childExpirationTimeBeforeCommit && + null !== rootWithPendingPassiveEffects + ) { + var callback = commitPassiveEffects.bind( + null, + root, + childExpirationTimeBeforeCommit + ); + callback = tracing.unstable_wrap(callback); + passiveEffectCallbackHandle = scheduler.unstable_runWithPriority( + scheduler.unstable_NormalPriority, + function() { + return scheduleDeferredCallback$1(callback); + } + ); + passiveEffectCallback = callback; + } isWorking = isCommitting$1 = !1; "function" === typeof onCommitFiberRoot && onCommitFiberRoot(finishedWork.stateNode); @@ -5779,11 +6429,7 @@ function completeUnitOfWork(workInProgress) { : ((current$$1.firstEffect = current$$1.lastEffect = type), (type.nextEffect = null)), (type.effectTag = 8))); - if ( - fiber !== renderExpirationTime || - (0 === (current$$1.effectTag & 1) && fiber) - ) - current$$1.effectTag |= 4; + if (fiber || renderExpirationTime) current$$1.effectTag |= 4; break; case 7: break; @@ -5911,7 +6557,8 @@ function renderRoot(root, isYieldy) { ); flushPassiveEffects(); isWorking = !0; - ReactCurrentOwner$2.currentDispatcher = DispatcherWithoutHooks; + var previousDispatcher = ReactCurrentDispatcher.current; + ReactCurrentDispatcher.current = ContextOnlyDispatcher; var expirationTime = root.nextExpirationTimeToWorkOn; if ( expirationTime !== nextRenderExpirationTime || @@ -5966,6 +6613,7 @@ function renderRoot(root, isYieldy) { } catch (thrownValue) { if ( ((lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = null), + resetHooks(), null === nextUnitOfWork) ) (threadID = !0), onUncaughtError(thrownValue); @@ -5996,27 +6644,35 @@ function renderRoot(root, isYieldy) { } while (1); tracing.__interactionsRef.current = subscriber; isWorking = !1; - lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = ReactCurrentOwner$2.currentDispatcher = null; + ReactCurrentDispatcher.current = previousDispatcher; + lastContextWithAllBitsObserved = lastContextDependency = currentlyRenderingFiber = null; + resetHooks(); if (threadID) (nextRoot = null), (root.finishedWork = null); else if (null !== nextUnitOfWork) root.finishedWork = null; else { - subscriber = root.current.alternate; + previousDispatcher = root.current.alternate; invariant( - null !== subscriber, + null !== previousDispatcher, "Finished root should have a work-in-progress. This error is likely caused by a bug in React. Please file an issue." ); nextRoot = null; if (nextRenderDidError) { if (hasLowerPriorityWork(root, expirationTime)) { markSuspendedPriorityLevel(root, expirationTime); - onSuspend(root, subscriber, expirationTime, root.expirationTime, -1); + onSuspend( + root, + previousDispatcher, + expirationTime, + root.expirationTime, + -1 + ); return; } if (!root.didError && isYieldy) { root.didError = !0; isYieldy = root.nextExpirationTimeToWorkOn = expirationTime; - threadID = root.expirationTime = 1073741823; - onSuspend(root, subscriber, isYieldy, threadID, -1); + subscriber = root.expirationTime = 1073741823; + onSuspend(root, previousDispatcher, isYieldy, subscriber, -1); return; } } @@ -6032,12 +6688,12 @@ function renderRoot(root, isYieldy) { (isYieldy = nextLatestAbsoluteTimeoutMs - isYieldy), onSuspend( root, - subscriber, + previousDispatcher, expirationTime, root.expirationTime, 0 > isYieldy ? 0 : isYieldy )) - : onComplete(root, subscriber, expirationTime); + : onComplete(root, previousDispatcher, expirationTime); } } function captureCommitPhaseError(sourceFiber, value) { @@ -6074,55 +6730,72 @@ function captureCommitPhaseError(sourceFiber, value) { scheduleWork(sourceFiber, 1073741823)); } function computeExpirationForFiber(currentTime, fiber) { - isWorking - ? (currentTime = isCommitting$1 ? 1073741823 : nextRenderExpirationTime) - : fiber.mode & 1 - ? ((currentTime = isBatchingInteractiveUpdates - ? 1073741822 - 10 * ((((1073741822 - currentTime + 15) / 10) | 0) + 1) - : 1073741822 - - 25 * ((((1073741822 - currentTime + 500) / 25) | 0) + 1)), - null !== nextRoot && - currentTime === nextRenderExpirationTime && - --currentTime) - : (currentTime = 1073741823); - isBatchingInteractiveUpdates && + var priorityLevel = scheduler.unstable_getCurrentPriorityLevel(), + expirationTime = void 0; + if (0 === (fiber.mode & 1)) expirationTime = 1073741823; + else if (isWorking && !isCommitting$1) + expirationTime = nextRenderExpirationTime; + else { + switch (priorityLevel) { + case scheduler.unstable_ImmediatePriority: + expirationTime = 1073741823; + break; + case scheduler.unstable_UserBlockingPriority: + expirationTime = + 1073741822 - 10 * ((((1073741822 - currentTime + 15) / 10) | 0) + 1); + break; + case scheduler.unstable_NormalPriority: + expirationTime = + 1073741822 - 25 * ((((1073741822 - currentTime + 500) / 25) | 0) + 1); + break; + case scheduler.unstable_LowPriority: + case scheduler.unstable_IdlePriority: + expirationTime = 1; + break; + default: + invariant( + !1, + "Unknown priority level. This error is likely caused by a bug in React. Please file an issue." + ); + } + null !== nextRoot && + expirationTime === nextRenderExpirationTime && + --expirationTime; + } + priorityLevel === scheduler.unstable_UserBlockingPriority && (0 === lowestPriorityPendingInteractiveExpirationTime || - currentTime < lowestPriorityPendingInteractiveExpirationTime) && - (lowestPriorityPendingInteractiveExpirationTime = currentTime); - return currentTime; + expirationTime < lowestPriorityPendingInteractiveExpirationTime) && + (lowestPriorityPendingInteractiveExpirationTime = expirationTime); + return expirationTime; } -function retrySuspendedRoot(root, boundaryFiber, sourceFiber, suspendedTime) { - var retryTime = root.earliestSuspendedTime; - var latestSuspendedTime = root.latestSuspendedTime; - if ( - 0 !== retryTime && - suspendedTime <= retryTime && - suspendedTime >= latestSuspendedTime +function pingSuspendedRoot(root, thenable, pingTime) { + var pingCache = root.pingCache; + null !== pingCache && pingCache.delete(thenable); + if (null !== nextRoot && nextRenderExpirationTime === pingTime) + nextRoot = null; + else if ( + ((thenable = root.earliestSuspendedTime), + (pingCache = root.latestSuspendedTime), + 0 !== thenable && pingTime <= thenable && pingTime >= pingCache) ) { - latestSuspendedTime = retryTime = suspendedTime; root.didError = !1; - var latestPingedTime = root.latestPingedTime; - if (0 === latestPingedTime || latestPingedTime > latestSuspendedTime) - root.latestPingedTime = latestSuspendedTime; - findNextExpirationTimeToWorkOn(latestSuspendedTime, root); - } else - (retryTime = requestCurrentTime()), - (retryTime = computeExpirationForFiber(retryTime, boundaryFiber)), - markPendingPriorityLevel(root, retryTime); - 0 !== (boundaryFiber.mode & 1) && - root === nextRoot && - nextRenderExpirationTime === suspendedTime && - (nextRoot = null); - scheduleWorkToRoot(boundaryFiber, retryTime); - 0 === (boundaryFiber.mode & 1) && - (scheduleWorkToRoot(sourceFiber, retryTime), - 1 === sourceFiber.tag && - null !== sourceFiber.stateNode && - ((boundaryFiber = createUpdate(retryTime)), - (boundaryFiber.tag = 2), - enqueueUpdate(sourceFiber, boundaryFiber))); - sourceFiber = root.expirationTime; - 0 !== sourceFiber && requestWork(root, sourceFiber); + thenable = root.latestPingedTime; + if (0 === thenable || thenable > pingTime) root.latestPingedTime = pingTime; + findNextExpirationTimeToWorkOn(pingTime, root); + pingTime = root.expirationTime; + 0 !== pingTime && requestWork(root, pingTime); + } +} +function retryTimedOutBoundary(boundaryFiber, thenable) { + var retryCache = boundaryFiber.stateNode; + null !== retryCache && retryCache.delete(thenable); + thenable = requestCurrentTime(); + thenable = computeExpirationForFiber(thenable, boundaryFiber); + boundaryFiber = scheduleWorkToRoot(boundaryFiber, thenable); + null !== boundaryFiber && + (markPendingPriorityLevel(boundaryFiber, thenable), + (thenable = boundaryFiber.expirationTime), + 0 !== thenable && requestWork(boundaryFiber, thenable)); } function scheduleWorkToRoot(fiber, expirationTime) { fiber.expirationTime < expirationTime && @@ -6201,7 +6874,6 @@ var firstScheduledRoot = null, unhandledError = null, isBatchingUpdates = !1, isUnbatchingUpdates = !1, - isBatchingInteractiveUpdates = !1, completedBatches = null, originalStartTimeMs = now$1(), currentRendererTime = 1073741822 - ((originalStartTimeMs / 10) | 0), @@ -6220,9 +6892,10 @@ function scheduleCallbackWithExpirationTime(root, expirationTime) { ((root = callbackID), (scheduledCallback = null), clearTimeout(root)); } callbackExpirationTime = expirationTime; - now$1(); - scheduledCallback = performAsyncWork; - callbackID = setTimeout(setTimeoutCallback, 1); + root = now$1() - originalStartTimeMs; + callbackID = scheduleDeferredCallback$1(performAsyncWork, { + timeout: 10 * (1073741822 - expirationTime) - root + }); } function onComplete(root, finishedWork, expirationTime) { root.pendingCommitExpirationTime = expirationTime; @@ -6470,7 +7143,12 @@ function completeRoot(root, finishedWork, expirationTime) { root === lastCommittedRootDuringThisBatch ? nestedUpdateCount++ : ((lastCommittedRootDuringThisBatch = root), (nestedUpdateCount = 0)); - commitRoot(root, finishedWork); + scheduler.unstable_runWithPriority( + scheduler.unstable_ImmediatePriority, + function() { + commitRoot(root, finishedWork); + } + ); } function onUncaughtError(error) { invariant( @@ -6706,6 +7384,7 @@ var roots = new Map(), earliestSuspendedTime: 0, latestSuspendedTime: 0, latestPingedTime: 0, + pingCache: null, didError: !1, pendingCommitExpirationTime: 0, finishedWork: null, @@ -6819,6 +7498,8 @@ var roots = new Map(), var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance; return injectInternals( Object.assign({}, devToolsConfig, { + overrideProps: null, + currentDispatcherRef: ReactSharedInternals.ReactCurrentDispatcher, findHostInstanceByFiber: function(fiber) { fiber = findCurrentHostFiber(fiber); return null === fiber ? null : fiber.stateNode; @@ -6834,7 +7515,7 @@ var roots = new Map(), findFiberByHostInstance: getInstanceFromTag, getInspectorDataForViewTag: getInspectorDataForViewTag, bundleType: 0, - version: "16.6.1", + version: "16.8.1", rendererPackageName: "react-native-renderer" }); var ReactNativeRenderer$2 = { default: ReactNativeRenderer }, diff --git a/package.json b/package.json index 9451a62a25524f..265cc584e22a2e 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "test-ios-e2e": "detox test -c ios.sim.release" }, "peerDependencies": { - "react": "16.6.3" + "react": "16.8.1" }, "dependencies": { "@babel/runtime": "^7.0.0", @@ -229,9 +229,9 @@ "jest-junit": "5.2.0", "jscodeshift": "^0.6.2", "prettier": "1.13.6", - "react": "16.6.3", + "react": "16.8.1", "react-native-dummy": "0.2.0", - "react-test-renderer": "16.7.0-alpha.2", + "react-test-renderer": "16.8.1", "shelljs": "^0.7.8" }, "detox": { diff --git a/yarn.lock b/yarn.lock index 155523dc713b4e..c6ae89636bf12f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3015,12 +3015,13 @@ fbjs-scripts@^1.0.0: semver "^5.1.0" through2 "^2.0.0" -fbjs@^0.8.9: - version "0.8.17" - resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd" - integrity sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90= +fbjs@1.0.0, fbjs@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-1.0.0.tgz#52c215e0883a3c86af2a7a776ed51525ae8e0a5a" + integrity sha512-MUgcMEJaFhCaF1QtWGnmq9ZDRAzECTCRAF7O6UZIlAlkTs1SasiX9aP0Iw7wfD2mJ7wDTNfg2w7u5fSCwJk1OA== dependencies: - core-js "^1.0.0" + core-js "^2.4.1" + fbjs-css-vars "^1.0.0" isomorphic-fetch "^2.1.1" loose-envify "^1.0.0" object-assign "^4.1.0" @@ -3028,13 +3029,12 @@ fbjs@^0.8.9: setimmediate "^1.0.5" ua-parser-js "^0.7.18" -fbjs@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-1.0.0.tgz#52c215e0883a3c86af2a7a776ed51525ae8e0a5a" - integrity sha512-MUgcMEJaFhCaF1QtWGnmq9ZDRAzECTCRAF7O6UZIlAlkTs1SasiX9aP0Iw7wfD2mJ7wDTNfg2w7u5fSCwJk1OA== +fbjs@^0.8.9: + version "0.8.17" + resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd" + integrity sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90= dependencies: - core-js "^2.4.1" - fbjs-css-vars "^1.0.0" + core-js "^1.0.0" isomorphic-fetch "^2.1.1" loose-envify "^1.0.0" object-assign "^4.1.0" @@ -6079,10 +6079,10 @@ react-devtools-core@^3.6.0: shell-quote "^1.6.1" ws "^3.3.1" -react-is@^16.7.0-alpha.2: - version "16.7.0-alpha.2" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.7.0-alpha.2.tgz#0dd7f95d45ad5318b7f7bcb99dcb84da9385cb57" - integrity sha512-1Q3qN8nMWUfFcRz/bBC1f9zSL3il9OcSxMd9CNnpJbeFf4VCX0qYxL3TuwT4f+tFk1TkidwIL11yYgk4HjldYg== +react-is@^16.8.1: + version "16.8.1" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.1.tgz#a80141e246eb894824fb4f2901c0c50ef31d4cdb" + integrity sha512-ioMCzVDWvCvKD8eeT+iukyWrBGrA3DiFYkXfBsVYIRdaREZuBjENG+KjrikavCLasozqRWTwFUagU/O4vPpRMA== react-native-dummy@0.2.0: version "0.2.0" @@ -6097,15 +6097,15 @@ react-proxy@^1.1.7: lodash "^4.6.1" react-deep-force-update "^1.0.0" -react-test-renderer@16.7.0-alpha.2: - version "16.7.0-alpha.2" - resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.7.0-alpha.2.tgz#8606a5a82240c405539da0401d7b3572898b5611" - integrity sha512-taA9MrHMi7hEM/cKgvcvht+9cszhPirCaSP99yxkVQ2JwQxYSltGYq2gFf/UQBqGJMgmgEghN62rxziaL1EK+A== +react-test-renderer@16.8.1: + version "16.8.1" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.8.1.tgz#72845ad9269be526126e97853311982f781767be" + integrity sha512-Bd21TN3+YVl6GZwav6O0T6m5UwGfOj+2+xZH5VH93ToD6M5uclN/c+R1DGX49ueG413KZPUx7Kw3sOYz2aJgfg== dependencies: object-assign "^4.1.1" prop-types "^15.6.2" - react-is "^16.7.0-alpha.2" - scheduler "^0.12.0-alpha.2" + react-is "^16.8.1" + scheduler "^0.13.1" react-transform-hmr@^1.0.4: version "1.0.4" @@ -6115,15 +6115,15 @@ react-transform-hmr@^1.0.4: global "^4.3.0" react-proxy "^1.1.7" -react@16.6.3: - version "16.6.3" - resolved "https://registry.yarnpkg.com/react/-/react-16.6.3.tgz#25d77c91911d6bbdd23db41e70fb094cc1e0871c" - integrity sha512-zCvmH2vbEolgKxtqXL2wmGCUxUyNheYn/C+PD1YAjfxHC54+MhdruyhO7QieQrYsYeTxrn93PM2y0jRH1zEExw== +react@16.8.1: + version "16.8.1" + resolved "https://registry.yarnpkg.com/react/-/react-16.8.1.tgz#ae11831f6cb2a05d58603a976afc8a558e852c4a" + integrity sha512-wLw5CFGPdo7p/AgteFz7GblI2JPOos0+biSoxf1FPsGxWQZdN/pj6oToJs1crn61DL3Ln7mN86uZ4j74p31ELQ== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" prop-types "^15.6.2" - scheduler "^0.11.2" + scheduler "^0.13.1" read-pkg-up@^1.0.1: version "1.0.1" @@ -6516,18 +6516,10 @@ sax@~1.1.1: resolved "https://registry.yarnpkg.com/sax/-/sax-1.1.6.tgz#5d616be8a5e607d54e114afae55b7eaf2fcc3240" integrity sha1-XWFr6KXmB9VOEUr65Vt+ry/MMkA= -scheduler@^0.11.2: - version "0.11.2" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.11.2.tgz#a8db5399d06eba5abac51b705b7151d2319d33d3" - integrity sha512-+WCP3s3wOaW4S7C1tl3TEXp4l9lJn0ZK8G3W3WKRWmw77Z2cIFUW2MiNTMHn5sCjxN+t7N43HAOOgMjyAg5hlg== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - -scheduler@^0.12.0-alpha.2: - version "0.12.0-alpha.3" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.12.0-alpha.3.tgz#59afcaba1cb79e3e8bee91de94eb8f42c9152c2b" - integrity sha512-KADuBlOWSrT/DCt/oA+NgsNamRCsfz7wj+leaeGjGHipNClsqhjOPogKkJgem6WLAv/QzxW8bE7zlGc9OxiYSQ== +scheduler@^0.13.1: + version "0.13.1" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.1.tgz#1a217df1bfaabaf4f1b92a9127d5d732d85a9591" + integrity sha512-VJKOkiKIN2/6NOoexuypwSrybx13MY7NSy9RNt8wPvZDMRT1CW6qlpF5jXRToXNHz3uWzbm2elNpZfXfGPqP9A== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1"