UNPKG

631 kBJavaScriptView Raw
1/** @license React v16.10.0
2 * react-test-renderer.development.js
3 *
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10'use strict';
11
12(function (global, factory) {
13 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('scheduler/unstable_mock'), require('scheduler')) :
14 typeof define === 'function' && define.amd ? define(['react', 'scheduler/unstable_mock', 'scheduler'], factory) :
15 (global.ReactTestRenderer = factory(global.React,global.SchedulerMock,global.Scheduler));
16}(this, (function (React,Scheduler,Scheduler$1) { 'use strict';
17
18// Do not require this module directly! Use normal `invariant` calls with
19// template literal strings. The messages will be converted to ReactError during
20// build, and in production they will be minified.
21
22// Do not require this module directly! Use normal `invariant` calls with
23// template literal strings. The messages will be converted to ReactError during
24// build, and in production they will be minified.
25function ReactError(error) {
26 error.name = 'Invariant Violation';
27 return error;
28}
29
30function _defineProperties(target, props) {
31 for (var i = 0; i < props.length; i++) {
32 var descriptor = props[i];
33 descriptor.enumerable = descriptor.enumerable || false;
34 descriptor.configurable = true;
35 if ("value" in descriptor) descriptor.writable = true;
36 Object.defineProperty(target, descriptor.key, descriptor);
37 }
38}
39
40function _createClass(Constructor, protoProps, staticProps) {
41 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
42 if (staticProps) _defineProperties(Constructor, staticProps);
43 return Constructor;
44}
45
46function _objectWithoutPropertiesLoose(source, excluded) {
47 if (source == null) return {};
48 var target = {};
49 var sourceKeys = Object.keys(source);
50 var key, i;
51
52 for (i = 0; i < sourceKeys.length; i++) {
53 key = sourceKeys[i];
54 if (excluded.indexOf(key) >= 0) continue;
55 target[key] = source[key];
56 }
57
58 return target;
59}
60
61var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
62var _assign = ReactInternals.assign;
63
64var FunctionComponent = 0;
65var ClassComponent = 1;
66var IndeterminateComponent = 2; // Before we know whether it is function or class
67
68var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
69
70var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
71
72var HostComponent = 5;
73var HostText = 6;
74var Fragment = 7;
75var Mode = 8;
76var ContextConsumer = 9;
77var ContextProvider = 10;
78var ForwardRef = 11;
79var Profiler = 12;
80var SuspenseComponent = 13;
81var MemoComponent = 14;
82var SimpleMemoComponent = 15;
83var LazyComponent = 16;
84var IncompleteClassComponent = 17;
85var DehydratedFragment = 18;
86var SuspenseListComponent = 19;
87var FundamentalComponent = 20;
88var ScopeComponent = 21;
89
90/**
91 * Use invariant() to assert state which your program assumes to be true.
92 *
93 * Provide sprintf-style format (only %s is supported) and arguments
94 * to provide information about what broke and what you were
95 * expecting.
96 *
97 * The invariant message will be stripped in production, but the invariant
98 * will remain to ensure logic does not differ in production.
99 */
100
101/**
102 * Similar to invariant but only logs a warning if the condition is not met.
103 * This can be used to log issues in development environments in critical
104 * paths. Removing the logging code for production environments will keep the
105 * same logic and follow the same code paths.
106 */
107var warningWithoutStack = function () {};
108
109{
110 warningWithoutStack = function (condition, format) {
111 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
112 args[_key - 2] = arguments[_key];
113 }
114
115 if (format === undefined) {
116 throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
117 }
118
119 if (args.length > 8) {
120 // Check before the condition to catch violations early.
121 throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
122 }
123
124 if (condition) {
125 return;
126 }
127
128 if (typeof console !== 'undefined') {
129 var argsWithFormat = args.map(function (item) {
130 return '' + item;
131 });
132 argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
133 // breaks IE9: https://github.com/facebook/react/issues/13610
134
135 Function.prototype.apply.call(console.error, console, argsWithFormat);
136 }
137
138 try {
139 // --- Welcome to debugging React ---
140 // This error was thrown as a convenience so that you can use this stack
141 // to find the callsite that caused this warning to fire.
142 var argIndex = 0;
143 var message = 'Warning: ' + format.replace(/%s/g, function () {
144 return args[argIndex++];
145 });
146 throw new Error(message);
147 } catch (x) {}
148 };
149}
150
151var warningWithoutStack$1 = warningWithoutStack;
152
153/**
154 * `ReactInstanceMap` maintains a mapping from a public facing stateful
155 * instance (key) and the internal representation (value). This allows public
156 * methods to accept the user facing instance as an argument and map them back
157 * to internal methods.
158 *
159 * Note that this module is currently shared and assumed to be stateless.
160 * If this becomes an actual Map, that will break.
161 */
162
163/**
164 * This API should be called `delete` but we'd have to make sure to always
165 * transform these to strings for IE support. When this transform is fully
166 * supported we can rename it.
167 */
168
169function get(key) {
170 return key._reactInternalFiber;
171}
172
173function set$1(key, value) {
174 key._reactInternalFiber = value;
175}
176
177var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
178// Current owner and dispatcher used to share the same ref,
179// but PR #14548 split them out to better support the react-debug-tools package.
180
181if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
182 ReactSharedInternals.ReactCurrentDispatcher = {
183 current: null
184 };
185}
186
187if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
188 ReactSharedInternals.ReactCurrentBatchConfig = {
189 suspense: null
190 };
191}
192
193// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
194// nor polyfill, then a plain number is used for performance.
195var hasSymbol = typeof Symbol === 'function' && Symbol.for;
196var REACT_ELEMENT_TYPE$1 = hasSymbol ? Symbol.for('react.element') : 0xeac7;
197var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
198var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
199var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
200var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
201var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
202var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
203// (unstable) APIs that have been removed. Can we remove the symbols?
204
205
206var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
207var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
208var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
209var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
210var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
211var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
212var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
213var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
214var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
215var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
216var FAUX_ITERATOR_SYMBOL = '@@iterator';
217function getIteratorFn(maybeIterable) {
218 if (maybeIterable === null || typeof maybeIterable !== 'object') {
219 return null;
220 }
221
222 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
223
224 if (typeof maybeIterator === 'function') {
225 return maybeIterator;
226 }
227
228 return null;
229}
230
231/**
232 * Similar to invariant but only logs a warning if the condition is not met.
233 * This can be used to log issues in development environments in critical
234 * paths. Removing the logging code for production environments will keep the
235 * same logic and follow the same code paths.
236 */
237
238var warning = warningWithoutStack$1;
239
240{
241 warning = function (condition, format) {
242 if (condition) {
243 return;
244 }
245
246 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
247 var stack = ReactDebugCurrentFrame.getStackAddendum(); // eslint-disable-next-line react-internal/warning-and-invariant-args
248
249 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
250 args[_key - 2] = arguments[_key];
251 }
252
253 warningWithoutStack$1.apply(void 0, [false, format + '%s'].concat(args, [stack]));
254 };
255}
256
257var warning$1 = warning;
258
259var Uninitialized = -1;
260var Pending = 0;
261var Resolved = 1;
262var Rejected = 2;
263function refineResolvedLazyComponent(lazyComponent) {
264 return lazyComponent._status === Resolved ? lazyComponent._result : null;
265}
266function initializeLazyComponentType(lazyComponent) {
267 if (lazyComponent._status === Uninitialized) {
268 lazyComponent._status = Pending;
269 var ctor = lazyComponent._ctor;
270 var thenable = ctor();
271 lazyComponent._result = thenable;
272 thenable.then(function (moduleObject) {
273 if (lazyComponent._status === Pending) {
274 var defaultExport = moduleObject.default;
275
276 {
277 if (defaultExport === undefined) {
278 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);
279 }
280 }
281
282 lazyComponent._status = Resolved;
283 lazyComponent._result = defaultExport;
284 }
285 }, function (error) {
286 if (lazyComponent._status === Pending) {
287 lazyComponent._status = Rejected;
288 lazyComponent._result = error;
289 }
290 });
291 }
292}
293
294function getWrappedName(outerType, innerType, wrapperName) {
295 var functionName = innerType.displayName || innerType.name || '';
296 return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
297}
298
299function getComponentName(type) {
300 if (type == null) {
301 // Host root, text node or just invalid type.
302 return null;
303 }
304
305 {
306 if (typeof type.tag === 'number') {
307 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
308 }
309 }
310
311 if (typeof type === 'function') {
312 return type.displayName || type.name || null;
313 }
314
315 if (typeof type === 'string') {
316 return type;
317 }
318
319 switch (type) {
320 case REACT_FRAGMENT_TYPE:
321 return 'Fragment';
322
323 case REACT_PORTAL_TYPE:
324 return 'Portal';
325
326 case REACT_PROFILER_TYPE:
327 return "Profiler";
328
329 case REACT_STRICT_MODE_TYPE:
330 return 'StrictMode';
331
332 case REACT_SUSPENSE_TYPE:
333 return 'Suspense';
334
335 case REACT_SUSPENSE_LIST_TYPE:
336 return 'SuspenseList';
337 }
338
339 if (typeof type === 'object') {
340 switch (type.$$typeof) {
341 case REACT_CONTEXT_TYPE:
342 return 'Context.Consumer';
343
344 case REACT_PROVIDER_TYPE:
345 return 'Context.Provider';
346
347 case REACT_FORWARD_REF_TYPE:
348 return getWrappedName(type, type.render, 'ForwardRef');
349
350 case REACT_MEMO_TYPE:
351 return getComponentName(type.type);
352
353 case REACT_LAZY_TYPE:
354 {
355 var thenable = type;
356 var resolvedThenable = refineResolvedLazyComponent(thenable);
357
358 if (resolvedThenable) {
359 return getComponentName(resolvedThenable);
360 }
361
362 break;
363 }
364 }
365 }
366
367 return null;
368}
369
370// Don't change these two values. They're used by React Dev Tools.
371var NoEffect =
372/* */
3730;
374var PerformedWork =
375/* */
3761; // You can change the rest (and add more).
377
378var Placement =
379/* */
3802;
381var Update =
382/* */
3834;
384var PlacementAndUpdate =
385/* */
3866;
387var Deletion =
388/* */
3898;
390var ContentReset =
391/* */
39216;
393var Callback =
394/* */
39532;
396var DidCapture =
397/* */
39864;
399var Ref =
400/* */
401128;
402var Snapshot =
403/* */
404256;
405var Passive =
406/* */
407512;
408var Hydrating =
409/* */
4101024;
411var HydratingAndUpdate =
412/* */
4131028; // Passive & Update & Callback & Ref & Snapshot
414
415var LifecycleEffectMask =
416/* */
417932; // Union of all host effects
418
419var HostEffectMask =
420/* */
4212047;
422var Incomplete =
423/* */
4242048;
425var ShouldCapture =
426/* */
4274096;
428
429var debugRenderPhaseSideEffects = false;
430var debugRenderPhaseSideEffectsForStrictMode = false;
431var enableUserTimingAPI = true;
432var warnAboutDeprecatedLifecycles = true;
433var replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
434var enableProfilerTimer = true;
435var enableSchedulerTracing = true;
436var enableSuspenseServerRenderer = false;
437
438
439
440
441
442
443
444var enableFlareAPI = false;
445var enableFundamentalAPI = false;
446var enableScopeAPI = false;
447
448var warnAboutUnmockedScheduler = false;
449var flushSuspenseFallbacksInTests = true;
450
451var enableSuspenseCallback = false;
452var warnAboutDefaultPropsOnFunctionComponents = false;
453var warnAboutStringRefs = false;
454var disableLegacyContext = false;
455var disableSchedulerTimeoutBasedOnReactExpirationTime = false;
456 // Only used in www builds.
457
458 // Flow magic to verify the exports of this file match the original version.
459
460var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
461function getNearestMountedFiber(fiber) {
462 var node = fiber;
463 var nearestMounted = fiber;
464
465 if (!fiber.alternate) {
466 // If there is no alternate, this might be a new tree that isn't inserted
467 // yet. If it is, then it will have a pending insertion effect on it.
468 var nextNode = node;
469
470 do {
471 node = nextNode;
472
473 if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
474 // This is an insertion or in-progress hydration. The nearest possible
475 // mounted fiber is the parent but we need to continue to figure out
476 // if that one is still mounted.
477 nearestMounted = node.return;
478 }
479
480 nextNode = node.return;
481 } while (nextNode);
482 } else {
483 while (node.return) {
484 node = node.return;
485 }
486 }
487
488 if (node.tag === HostRoot) {
489 // TODO: Check if this was a nested HostRoot when used with
490 // renderContainerIntoSubtree.
491 return nearestMounted;
492 } // If we didn't hit the root, that means that we're in an disconnected tree
493 // that has been unmounted.
494
495
496 return null;
497}
498
499
500function isFiberMounted(fiber) {
501 return getNearestMountedFiber(fiber) === fiber;
502}
503function isMounted(component) {
504 {
505 var owner = ReactCurrentOwner.current;
506
507 if (owner !== null && owner.tag === ClassComponent) {
508 var ownerFiber = owner;
509 var instance = ownerFiber.stateNode;
510 !instance._warnedAboutRefsInRender ? warningWithoutStack$1(false, '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(ownerFiber.type) || 'A component') : void 0;
511 instance._warnedAboutRefsInRender = true;
512 }
513 }
514
515 var fiber = get(component);
516
517 if (!fiber) {
518 return false;
519 }
520
521 return getNearestMountedFiber(fiber) === fiber;
522}
523
524function assertIsMounted(fiber) {
525 (function () {
526 if (!(getNearestMountedFiber(fiber) === fiber)) {
527 {
528 throw ReactError(Error("Unable to find node on an unmounted component."));
529 }
530 }
531 })();
532}
533
534function findCurrentFiberUsingSlowPath(fiber) {
535 var alternate = fiber.alternate;
536
537 if (!alternate) {
538 // If there is no alternate, then we only need to check if it is mounted.
539 var nearestMounted = getNearestMountedFiber(fiber);
540
541 (function () {
542 if (!(nearestMounted !== null)) {
543 {
544 throw ReactError(Error("Unable to find node on an unmounted component."));
545 }
546 }
547 })();
548
549 if (nearestMounted !== fiber) {
550 return null;
551 }
552
553 return fiber;
554 } // If we have two possible branches, we'll walk backwards up to the root
555 // to see what path the root points to. On the way we may hit one of the
556 // special cases and we'll deal with them.
557
558
559 var a = fiber;
560 var b = alternate;
561
562 while (true) {
563 var parentA = a.return;
564
565 if (parentA === null) {
566 // We're at the root.
567 break;
568 }
569
570 var parentB = parentA.alternate;
571
572 if (parentB === null) {
573 // There is no alternate. This is an unusual case. Currently, it only
574 // happens when a Suspense component is hidden. An extra fragment fiber
575 // is inserted in between the Suspense fiber and its children. Skip
576 // over this extra fragment fiber and proceed to the next parent.
577 var nextParent = parentA.return;
578
579 if (nextParent !== null) {
580 a = b = nextParent;
581 continue;
582 } // If there's no parent, we're at the root.
583
584
585 break;
586 } // If both copies of the parent fiber point to the same child, we can
587 // assume that the child is current. This happens when we bailout on low
588 // priority: the bailed out fiber's child reuses the current child.
589
590
591 if (parentA.child === parentB.child) {
592 var child = parentA.child;
593
594 while (child) {
595 if (child === a) {
596 // We've determined that A is the current branch.
597 assertIsMounted(parentA);
598 return fiber;
599 }
600
601 if (child === b) {
602 // We've determined that B is the current branch.
603 assertIsMounted(parentA);
604 return alternate;
605 }
606
607 child = child.sibling;
608 } // We should never have an alternate for any mounting node. So the only
609 // way this could possibly happen is if this was unmounted, if at all.
610
611
612 (function () {
613 {
614 {
615 throw ReactError(Error("Unable to find node on an unmounted component."));
616 }
617 }
618 })();
619 }
620
621 if (a.return !== b.return) {
622 // The return pointer of A and the return pointer of B point to different
623 // fibers. We assume that return pointers never criss-cross, so A must
624 // belong to the child set of A.return, and B must belong to the child
625 // set of B.return.
626 a = parentA;
627 b = parentB;
628 } else {
629 // The return pointers point to the same fiber. We'll have to use the
630 // default, slow path: scan the child sets of each parent alternate to see
631 // which child belongs to which set.
632 //
633 // Search parent A's child set
634 var didFindChild = false;
635 var _child = parentA.child;
636
637 while (_child) {
638 if (_child === a) {
639 didFindChild = true;
640 a = parentA;
641 b = parentB;
642 break;
643 }
644
645 if (_child === b) {
646 didFindChild = true;
647 b = parentA;
648 a = parentB;
649 break;
650 }
651
652 _child = _child.sibling;
653 }
654
655 if (!didFindChild) {
656 // Search parent B's child set
657 _child = parentB.child;
658
659 while (_child) {
660 if (_child === a) {
661 didFindChild = true;
662 a = parentB;
663 b = parentA;
664 break;
665 }
666
667 if (_child === b) {
668 didFindChild = true;
669 b = parentB;
670 a = parentA;
671 break;
672 }
673
674 _child = _child.sibling;
675 }
676
677 (function () {
678 if (!didFindChild) {
679 {
680 throw ReactError(Error("Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue."));
681 }
682 }
683 })();
684 }
685 }
686
687 (function () {
688 if (!(a.alternate === b)) {
689 {
690 throw ReactError(Error("Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue."));
691 }
692 }
693 })();
694 } // If the root is not a host container, we're in a disconnected tree. I.e.
695 // unmounted.
696
697
698 (function () {
699 if (!(a.tag === HostRoot)) {
700 {
701 throw ReactError(Error("Unable to find node on an unmounted component."));
702 }
703 }
704 })();
705
706 if (a.stateNode.current === a) {
707 // We've determined that A is the current branch.
708 return fiber;
709 } // Otherwise B has to be current branch.
710
711
712 return alternate;
713}
714function findCurrentHostFiber(parent) {
715 var currentParent = findCurrentFiberUsingSlowPath(parent);
716
717 if (!currentParent) {
718 return null;
719 } // Next we'll drill down this component to find the first HostComponent/Text.
720
721
722 var node = currentParent;
723
724 while (true) {
725 if (node.tag === HostComponent || node.tag === HostText) {
726 return node;
727 } else if (node.child) {
728 node.child.return = node;
729 node = node.child;
730 continue;
731 }
732
733 if (node === currentParent) {
734 return null;
735 }
736
737 while (!node.sibling) {
738 if (!node.return || node.return === currentParent) {
739 return null;
740 }
741
742 node = node.return;
743 }
744
745 node.sibling.return = node.return;
746 node = node.sibling;
747 } // Flow needs the return null here, but ESLint complains about it.
748 // eslint-disable-next-line no-unreachable
749
750
751 return null;
752}
753
754// can re-export everything from this module.
755
756function shim() {
757 (function () {
758 {
759 {
760 throw ReactError(Error("The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue."));
761 }
762 }
763 })();
764} // Persistence (when unsupported)
765
766
767var supportsPersistence = false;
768var cloneInstance = shim;
769var cloneFundamentalInstance = shim;
770var createContainerChildSet = shim;
771var appendChildToContainerChildSet = shim;
772var finalizeContainerChildren = shim;
773var replaceContainerChildren = shim;
774var cloneHiddenInstance = shim;
775var cloneHiddenTextInstance = shim;
776
777// can re-export everything from this module.
778
779function shim$1() {
780 (function () {
781 {
782 {
783 throw ReactError(Error("The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue."));
784 }
785 }
786 })();
787} // Hydration (when unsupported)
788
789
790var supportsHydration = false;
791var canHydrateInstance = shim$1;
792var canHydrateTextInstance = shim$1;
793var canHydrateSuspenseInstance = shim$1;
794var isSuspenseInstancePending = shim$1;
795var isSuspenseInstanceFallback = shim$1;
796var registerSuspenseInstanceRetry = shim$1;
797var getNextHydratableSibling = shim$1;
798var getFirstHydratableChild = shim$1;
799var hydrateInstance = shim$1;
800var hydrateTextInstance = shim$1;
801var hydrateSuspenseInstance = shim$1;
802var getNextHydratableInstanceAfterSuspenseInstance = shim$1;
803var commitHydratedContainer = shim$1;
804var commitHydratedSuspenseInstance = shim$1;
805var clearSuspenseBoundary = shim$1;
806var clearSuspenseBoundaryFromContainer = shim$1;
807var didNotMatchHydratedContainerTextInstance = shim$1;
808var didNotMatchHydratedTextInstance = shim$1;
809var didNotHydrateContainerInstance = shim$1;
810var didNotHydrateInstance = shim$1;
811var didNotFindHydratableContainerInstance = shim$1;
812var didNotFindHydratableContainerTextInstance = shim$1;
813var didNotFindHydratableContainerSuspenseInstance = shim$1;
814var didNotFindHydratableInstance = shim$1;
815var didNotFindHydratableTextInstance = shim$1;
816var didNotFindHydratableSuspenseInstance = shim$1;
817
818var EVENT_COMPONENT_CONTEXT = {};
819var NO_CONTEXT = {};
820var UPDATE_SIGNAL = {};
821
822{
823 Object.freeze(NO_CONTEXT);
824 Object.freeze(UPDATE_SIGNAL);
825}
826
827function getPublicInstance(inst) {
828 switch (inst.tag) {
829 case 'INSTANCE':
830 var createNodeMock = inst.rootContainerInstance.createNodeMock;
831 return createNodeMock({
832 type: inst.type,
833 props: inst.props
834 });
835
836 default:
837 return inst;
838 }
839}
840function appendChild(parentInstance, child) {
841 {
842 !Array.isArray(parentInstance.children) ? warning$1(false, 'An invalid container has been provided. ' + 'This may indicate that another renderer is being used in addition to the test renderer. ' + '(For example, ReactDOM.createPortal inside of a ReactTestRenderer tree.) ' + 'This is not supported.') : void 0;
843 }
844
845 var index = parentInstance.children.indexOf(child);
846
847 if (index !== -1) {
848 parentInstance.children.splice(index, 1);
849 }
850
851 parentInstance.children.push(child);
852}
853function insertBefore(parentInstance, child, beforeChild) {
854 var index = parentInstance.children.indexOf(child);
855
856 if (index !== -1) {
857 parentInstance.children.splice(index, 1);
858 }
859
860 var beforeIndex = parentInstance.children.indexOf(beforeChild);
861 parentInstance.children.splice(beforeIndex, 0, child);
862}
863function removeChild(parentInstance, child) {
864 var index = parentInstance.children.indexOf(child);
865 parentInstance.children.splice(index, 1);
866}
867function getRootHostContext(rootContainerInstance) {
868 return NO_CONTEXT;
869}
870function getChildHostContext(parentHostContext, type, rootContainerInstance) {
871 return NO_CONTEXT;
872}
873function prepareForCommit(containerInfo) {// noop
874}
875function resetAfterCommit(containerInfo) {// noop
876}
877function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
878 var propsToUse = props;
879
880 if (enableFlareAPI) {
881 if (props.listeners != null) {
882 // We want to remove the "listeners" prop
883 // as we don't want it in the test renderer's
884 // instance props.
885 var listeners = props.listeners,
886 otherProps = _objectWithoutPropertiesLoose(props, ["listeners"]); // eslint-disable-line
887
888
889 propsToUse = otherProps;
890 }
891 }
892
893 return {
894 type: type,
895 props: propsToUse,
896 isHidden: false,
897 children: [],
898 rootContainerInstance: rootContainerInstance,
899 tag: 'INSTANCE'
900 };
901}
902function appendInitialChild(parentInstance, child) {
903 var index = parentInstance.children.indexOf(child);
904
905 if (index !== -1) {
906 parentInstance.children.splice(index, 1);
907 }
908
909 parentInstance.children.push(child);
910}
911function finalizeInitialChildren(testElement, type, props, rootContainerInstance, hostContext) {
912 return false;
913}
914function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
915 return UPDATE_SIGNAL;
916}
917function shouldSetTextContent(type, props) {
918 return false;
919}
920function shouldDeprioritizeSubtree(type, props) {
921 return false;
922}
923function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
924 if (true && enableFlareAPI) {
925 !(hostContext !== EVENT_COMPONENT_CONTEXT) ? warning$1(false, 'validateDOMNesting: React event components cannot have text DOM nodes as children. ' + 'Wrap the child text "%s" in an element.', text) : void 0;
926 }
927
928 return {
929 text: text,
930 isHidden: false,
931 tag: 'TEXT'
932 };
933}
934var isPrimaryRenderer = false;
935var warnsIfNotActing = true;
936var scheduleTimeout = setTimeout;
937var cancelTimeout = clearTimeout;
938var noTimeout = -1; // -------------------
939// Mutation
940// -------------------
941
942var supportsMutation = true;
943function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
944 instance.type = type;
945 instance.props = newProps;
946}
947
948function commitTextUpdate(textInstance, oldText, newText) {
949 textInstance.text = newText;
950}
951function resetTextContent(testElement) {// noop
952}
953var appendChildToContainer = appendChild;
954var insertInContainerBefore = insertBefore;
955var removeChildFromContainer = removeChild;
956function hideInstance(instance) {
957 instance.isHidden = true;
958}
959function hideTextInstance(textInstance) {
960 textInstance.isHidden = true;
961}
962function unhideInstance(instance, props) {
963 instance.isHidden = false;
964}
965function unhideTextInstance(textInstance, text) {
966 textInstance.isHidden = false;
967}
968
969
970function getFundamentalComponentInstance(fundamentalInstance) {
971 var impl = fundamentalInstance.impl,
972 props = fundamentalInstance.props,
973 state = fundamentalInstance.state;
974 return impl.getInstance(null, props, state);
975}
976function mountFundamentalComponent(fundamentalInstance) {
977 var impl = fundamentalInstance.impl,
978 instance = fundamentalInstance.instance,
979 props = fundamentalInstance.props,
980 state = fundamentalInstance.state;
981 var onMount = impl.onMount;
982
983 if (onMount !== undefined) {
984 onMount(null, instance, props, state);
985 }
986}
987function shouldUpdateFundamentalComponent(fundamentalInstance) {
988 var impl = fundamentalInstance.impl,
989 prevProps = fundamentalInstance.prevProps,
990 props = fundamentalInstance.props,
991 state = fundamentalInstance.state;
992 var shouldUpdate = impl.shouldUpdate;
993
994 if (shouldUpdate !== undefined) {
995 return shouldUpdate(null, prevProps, props, state);
996 }
997
998 return true;
999}
1000function updateFundamentalComponent(fundamentalInstance) {
1001 var impl = fundamentalInstance.impl,
1002 instance = fundamentalInstance.instance,
1003 prevProps = fundamentalInstance.prevProps,
1004 props = fundamentalInstance.props,
1005 state = fundamentalInstance.state;
1006 var onUpdate = impl.onUpdate;
1007
1008 if (onUpdate !== undefined) {
1009 onUpdate(null, instance, prevProps, props, state);
1010 }
1011}
1012function unmountFundamentalComponent(fundamentalInstance) {
1013 var impl = fundamentalInstance.impl,
1014 instance = fundamentalInstance.instance,
1015 props = fundamentalInstance.props,
1016 state = fundamentalInstance.state;
1017 var onUnmount = impl.onUnmount;
1018
1019 if (onUnmount !== undefined) {
1020 onUnmount(null, instance, props, state);
1021 }
1022}
1023
1024/**
1025 * Copyright (c) 2013-present, Facebook, Inc.
1026 *
1027 * This source code is licensed under the MIT license found in the
1028 * LICENSE file in the root directory of this source tree.
1029 */
1030
1031
1032
1033var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
1034
1035var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
1036
1037/**
1038 * Copyright (c) 2013-present, Facebook, Inc.
1039 *
1040 * This source code is licensed under the MIT license found in the
1041 * LICENSE file in the root directory of this source tree.
1042 */
1043
1044
1045
1046var printWarning = function() {};
1047
1048{
1049 var ReactPropTypesSecret = ReactPropTypesSecret_1;
1050 var loggedTypeFailures = {};
1051 var has$1 = Function.call.bind(Object.prototype.hasOwnProperty);
1052
1053 printWarning = function(text) {
1054 var message = 'Warning: ' + text;
1055 if (typeof console !== 'undefined') {
1056 console.error(message);
1057 }
1058 try {
1059 // --- Welcome to debugging React ---
1060 // This error was thrown as a convenience so that you can use this stack
1061 // to find the callsite that caused this warning to fire.
1062 throw new Error(message);
1063 } catch (x) {}
1064 };
1065}
1066
1067/**
1068 * Assert that the values match with the type specs.
1069 * Error messages are memorized and will only be shown once.
1070 *
1071 * @param {object} typeSpecs Map of name to a ReactPropType
1072 * @param {object} values Runtime values that need to be type-checked
1073 * @param {string} location e.g. "prop", "context", "child context"
1074 * @param {string} componentName Name of the component for error messages.
1075 * @param {?Function} getStack Returns the component stack.
1076 * @private
1077 */
1078function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
1079 {
1080 for (var typeSpecName in typeSpecs) {
1081 if (has$1(typeSpecs, typeSpecName)) {
1082 var error;
1083 // Prop type validation may throw. In case they do, we don't want to
1084 // fail the render phase where it didn't fail before. So we log it.
1085 // After these have been cleaned up, we'll let them throw.
1086 try {
1087 // This is intentionally an invariant that gets caught. It's the same
1088 // behavior as without this statement except with a better message.
1089 if (typeof typeSpecs[typeSpecName] !== 'function') {
1090 var err = Error(
1091 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
1092 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
1093 );
1094 err.name = 'Invariant Violation';
1095 throw err;
1096 }
1097 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
1098 } catch (ex) {
1099 error = ex;
1100 }
1101 if (error && !(error instanceof Error)) {
1102 printWarning(
1103 (componentName || 'React class') + ': type specification of ' +
1104 location + ' `' + typeSpecName + '` is invalid; the type checker ' +
1105 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
1106 'You may have forgotten to pass an argument to the type checker ' +
1107 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
1108 'shape all require an argument).'
1109 );
1110 }
1111 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
1112 // Only monitor this failure once because there tends to be a lot of the
1113 // same error.
1114 loggedTypeFailures[error.message] = true;
1115
1116 var stack = getStack ? getStack() : '';
1117
1118 printWarning(
1119 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
1120 );
1121 }
1122 }
1123 }
1124 }
1125}
1126
1127/**
1128 * Resets warning cache when testing.
1129 *
1130 * @private
1131 */
1132checkPropTypes.resetWarningCache = function() {
1133 {
1134 loggedTypeFailures = {};
1135 }
1136};
1137
1138var checkPropTypes_1 = checkPropTypes;
1139
1140var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
1141var describeComponentFrame = function (name, source, ownerName) {
1142 var sourceInfo = '';
1143
1144 if (source) {
1145 var path = source.fileName;
1146 var fileName = path.replace(BEFORE_SLASH_RE, '');
1147
1148 {
1149 // In DEV, include code for a common special case:
1150 // prefer "folder/index.js" instead of just "index.js".
1151 if (/^index\./.test(fileName)) {
1152 var match = path.match(BEFORE_SLASH_RE);
1153
1154 if (match) {
1155 var pathBeforeSlash = match[1];
1156
1157 if (pathBeforeSlash) {
1158 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
1159 fileName = folderName + '/' + fileName;
1160 }
1161 }
1162 }
1163 }
1164
1165 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
1166 } else if (ownerName) {
1167 sourceInfo = ' (created by ' + ownerName + ')';
1168 }
1169
1170 return '\n in ' + (name || 'Unknown') + sourceInfo;
1171};
1172
1173var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1174
1175function describeFiber(fiber) {
1176 switch (fiber.tag) {
1177 case HostRoot:
1178 case HostPortal:
1179 case HostText:
1180 case Fragment:
1181 case ContextProvider:
1182 case ContextConsumer:
1183 return '';
1184
1185 default:
1186 var owner = fiber._debugOwner;
1187 var source = fiber._debugSource;
1188 var name = getComponentName(fiber.type);
1189 var ownerName = null;
1190
1191 if (owner) {
1192 ownerName = getComponentName(owner.type);
1193 }
1194
1195 return describeComponentFrame(name, source, ownerName);
1196 }
1197}
1198
1199function getStackByFiberInDevAndProd(workInProgress) {
1200 var info = '';
1201 var node = workInProgress;
1202
1203 do {
1204 info += describeFiber(node);
1205 node = node.return;
1206 } while (node);
1207
1208 return info;
1209}
1210var current = null;
1211var phase = null;
1212function getCurrentFiberOwnerNameInDevOrNull() {
1213 {
1214 if (current === null) {
1215 return null;
1216 }
1217
1218 var owner = current._debugOwner;
1219
1220 if (owner !== null && typeof owner !== 'undefined') {
1221 return getComponentName(owner.type);
1222 }
1223 }
1224
1225 return null;
1226}
1227function getCurrentFiberStackInDev() {
1228 {
1229 if (current === null) {
1230 return '';
1231 } // Safe because if current fiber exists, we are reconciling,
1232 // and it is guaranteed to be the work-in-progress version.
1233
1234
1235 return getStackByFiberInDevAndProd(current);
1236 }
1237
1238 return '';
1239}
1240function resetCurrentFiber() {
1241 {
1242 ReactDebugCurrentFrame.getCurrentStack = null;
1243 current = null;
1244 phase = null;
1245 }
1246}
1247function setCurrentFiber(fiber) {
1248 {
1249 ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
1250 current = fiber;
1251 phase = null;
1252 }
1253}
1254function setCurrentPhase(lifeCyclePhase) {
1255 {
1256 phase = lifeCyclePhase;
1257 }
1258}
1259
1260// Prefix measurements so that it's possible to filter them.
1261// Longer prefixes are hard to read in DevTools.
1262var reactEmoji = "\u269B";
1263var warningEmoji = "\u26D4";
1264var supportsUserTiming = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function'; // Keep track of current fiber so that we know the path to unwind on pause.
1265// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
1266
1267var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
1268// Reusing `currentFiber` would be confusing for this because user code fiber
1269// can change during commit phase too, but we don't need to unwind it (since
1270// lifecycles in the commit phase don't resemble a tree).
1271
1272var currentPhase = null;
1273var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
1274// so we will keep track of it, and include it in the report.
1275// Track commits caused by cascading updates.
1276
1277var isCommitting = false;
1278var hasScheduledUpdateInCurrentCommit = false;
1279var hasScheduledUpdateInCurrentPhase = false;
1280var commitCountInCurrentWorkLoop = 0;
1281var effectCountInCurrentCommit = 0;
1282// to avoid stretch the commit phase with measurement overhead.
1283
1284var labelsInCurrentCommit = new Set();
1285
1286var formatMarkName = function (markName) {
1287 return reactEmoji + " " + markName;
1288};
1289
1290var formatLabel = function (label, warning) {
1291 var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
1292 var suffix = warning ? " Warning: " + warning : '';
1293 return "" + prefix + label + suffix;
1294};
1295
1296var beginMark = function (markName) {
1297 performance.mark(formatMarkName(markName));
1298};
1299
1300var clearMark = function (markName) {
1301 performance.clearMarks(formatMarkName(markName));
1302};
1303
1304var endMark = function (label, markName, warning) {
1305 var formattedMarkName = formatMarkName(markName);
1306 var formattedLabel = formatLabel(label, warning);
1307
1308 try {
1309 performance.measure(formattedLabel, formattedMarkName);
1310 } catch (err) {} // If previous mark was missing for some reason, this will throw.
1311 // This could only happen if React crashed in an unexpected place earlier.
1312 // Don't pile on with more errors.
1313 // Clear marks immediately to avoid growing buffer.
1314
1315
1316 performance.clearMarks(formattedMarkName);
1317 performance.clearMeasures(formattedLabel);
1318};
1319
1320var getFiberMarkName = function (label, debugID) {
1321 return label + " (#" + debugID + ")";
1322};
1323
1324var getFiberLabel = function (componentName, isMounted, phase) {
1325 if (phase === null) {
1326 // These are composite component total time measurements.
1327 return componentName + " [" + (isMounted ? 'update' : 'mount') + "]";
1328 } else {
1329 // Composite component methods.
1330 return componentName + "." + phase;
1331 }
1332};
1333
1334var beginFiberMark = function (fiber, phase) {
1335 var componentName = getComponentName(fiber.type) || 'Unknown';
1336 var debugID = fiber._debugID;
1337 var isMounted = fiber.alternate !== null;
1338 var label = getFiberLabel(componentName, isMounted, phase);
1339
1340 if (isCommitting && labelsInCurrentCommit.has(label)) {
1341 // During the commit phase, we don't show duplicate labels because
1342 // there is a fixed overhead for every measurement, and we don't
1343 // want to stretch the commit phase beyond necessary.
1344 return false;
1345 }
1346
1347 labelsInCurrentCommit.add(label);
1348 var markName = getFiberMarkName(label, debugID);
1349 beginMark(markName);
1350 return true;
1351};
1352
1353var clearFiberMark = function (fiber, phase) {
1354 var componentName = getComponentName(fiber.type) || 'Unknown';
1355 var debugID = fiber._debugID;
1356 var isMounted = fiber.alternate !== null;
1357 var label = getFiberLabel(componentName, isMounted, phase);
1358 var markName = getFiberMarkName(label, debugID);
1359 clearMark(markName);
1360};
1361
1362var endFiberMark = function (fiber, phase, warning) {
1363 var componentName = getComponentName(fiber.type) || 'Unknown';
1364 var debugID = fiber._debugID;
1365 var isMounted = fiber.alternate !== null;
1366 var label = getFiberLabel(componentName, isMounted, phase);
1367 var markName = getFiberMarkName(label, debugID);
1368 endMark(label, markName, warning);
1369};
1370
1371var shouldIgnoreFiber = function (fiber) {
1372 // Host components should be skipped in the timeline.
1373 // We could check typeof fiber.type, but does this work with RN?
1374 switch (fiber.tag) {
1375 case HostRoot:
1376 case HostComponent:
1377 case HostText:
1378 case HostPortal:
1379 case Fragment:
1380 case ContextProvider:
1381 case ContextConsumer:
1382 case Mode:
1383 return true;
1384
1385 default:
1386 return false;
1387 }
1388};
1389
1390var clearPendingPhaseMeasurement = function () {
1391 if (currentPhase !== null && currentPhaseFiber !== null) {
1392 clearFiberMark(currentPhaseFiber, currentPhase);
1393 }
1394
1395 currentPhaseFiber = null;
1396 currentPhase = null;
1397 hasScheduledUpdateInCurrentPhase = false;
1398};
1399
1400var pauseTimers = function () {
1401 // Stops all currently active measurements so that they can be resumed
1402 // if we continue in a later deferred loop from the same unit of work.
1403 var fiber = currentFiber;
1404
1405 while (fiber) {
1406 if (fiber._debugIsCurrentlyTiming) {
1407 endFiberMark(fiber, null, null);
1408 }
1409
1410 fiber = fiber.return;
1411 }
1412};
1413
1414var resumeTimersRecursively = function (fiber) {
1415 if (fiber.return !== null) {
1416 resumeTimersRecursively(fiber.return);
1417 }
1418
1419 if (fiber._debugIsCurrentlyTiming) {
1420 beginFiberMark(fiber, null);
1421 }
1422};
1423
1424var resumeTimers = function () {
1425 // Resumes all measurements that were active during the last deferred loop.
1426 if (currentFiber !== null) {
1427 resumeTimersRecursively(currentFiber);
1428 }
1429};
1430
1431function recordEffect() {
1432 if (enableUserTimingAPI) {
1433 effectCountInCurrentCommit++;
1434 }
1435}
1436function recordScheduleUpdate() {
1437 if (enableUserTimingAPI) {
1438 if (isCommitting) {
1439 hasScheduledUpdateInCurrentCommit = true;
1440 }
1441
1442 if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
1443 hasScheduledUpdateInCurrentPhase = true;
1444 }
1445 }
1446}
1447
1448
1449function startWorkTimer(fiber) {
1450 if (enableUserTimingAPI) {
1451 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1452 return;
1453 } // If we pause, this is the fiber to unwind from.
1454
1455
1456 currentFiber = fiber;
1457
1458 if (!beginFiberMark(fiber, null)) {
1459 return;
1460 }
1461
1462 fiber._debugIsCurrentlyTiming = true;
1463 }
1464}
1465function cancelWorkTimer(fiber) {
1466 if (enableUserTimingAPI) {
1467 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1468 return;
1469 } // Remember we shouldn't complete measurement for this fiber.
1470 // Otherwise flamechart will be deep even for small updates.
1471
1472
1473 fiber._debugIsCurrentlyTiming = false;
1474 clearFiberMark(fiber, null);
1475 }
1476}
1477function stopWorkTimer(fiber) {
1478 if (enableUserTimingAPI) {
1479 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1480 return;
1481 } // If we pause, its parent is the fiber to unwind from.
1482
1483
1484 currentFiber = fiber.return;
1485
1486 if (!fiber._debugIsCurrentlyTiming) {
1487 return;
1488 }
1489
1490 fiber._debugIsCurrentlyTiming = false;
1491 endFiberMark(fiber, null, null);
1492 }
1493}
1494function stopFailedWorkTimer(fiber) {
1495 if (enableUserTimingAPI) {
1496 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1497 return;
1498 } // If we pause, its parent is the fiber to unwind from.
1499
1500
1501 currentFiber = fiber.return;
1502
1503 if (!fiber._debugIsCurrentlyTiming) {
1504 return;
1505 }
1506
1507 fiber._debugIsCurrentlyTiming = false;
1508 var warning = fiber.tag === SuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
1509 endFiberMark(fiber, null, warning);
1510 }
1511}
1512function startPhaseTimer(fiber, phase) {
1513 if (enableUserTimingAPI) {
1514 if (!supportsUserTiming) {
1515 return;
1516 }
1517
1518 clearPendingPhaseMeasurement();
1519
1520 if (!beginFiberMark(fiber, phase)) {
1521 return;
1522 }
1523
1524 currentPhaseFiber = fiber;
1525 currentPhase = phase;
1526 }
1527}
1528function stopPhaseTimer() {
1529 if (enableUserTimingAPI) {
1530 if (!supportsUserTiming) {
1531 return;
1532 }
1533
1534 if (currentPhase !== null && currentPhaseFiber !== null) {
1535 var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
1536 endFiberMark(currentPhaseFiber, currentPhase, warning);
1537 }
1538
1539 currentPhase = null;
1540 currentPhaseFiber = null;
1541 }
1542}
1543function startWorkLoopTimer(nextUnitOfWork) {
1544 if (enableUserTimingAPI) {
1545 currentFiber = nextUnitOfWork;
1546
1547 if (!supportsUserTiming) {
1548 return;
1549 }
1550
1551 commitCountInCurrentWorkLoop = 0; // This is top level call.
1552 // Any other measurements are performed within.
1553
1554 beginMark('(React Tree Reconciliation)'); // Resume any measurements that were in progress during the last loop.
1555
1556 resumeTimers();
1557 }
1558}
1559function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
1560 if (enableUserTimingAPI) {
1561 if (!supportsUserTiming) {
1562 return;
1563 }
1564
1565 var warning = null;
1566
1567 if (interruptedBy !== null) {
1568 if (interruptedBy.tag === HostRoot) {
1569 warning = 'A top-level update interrupted the previous render';
1570 } else {
1571 var componentName = getComponentName(interruptedBy.type) || 'Unknown';
1572 warning = "An update to " + componentName + " interrupted the previous render";
1573 }
1574 } else if (commitCountInCurrentWorkLoop > 1) {
1575 warning = 'There were cascading updates';
1576 }
1577
1578 commitCountInCurrentWorkLoop = 0;
1579 var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)'; // Pause any measurements until the next loop.
1580
1581 pauseTimers();
1582 endMark(label, '(React Tree Reconciliation)', warning);
1583 }
1584}
1585function startCommitTimer() {
1586 if (enableUserTimingAPI) {
1587 if (!supportsUserTiming) {
1588 return;
1589 }
1590
1591 isCommitting = true;
1592 hasScheduledUpdateInCurrentCommit = false;
1593 labelsInCurrentCommit.clear();
1594 beginMark('(Committing Changes)');
1595 }
1596}
1597function stopCommitTimer() {
1598 if (enableUserTimingAPI) {
1599 if (!supportsUserTiming) {
1600 return;
1601 }
1602
1603 var warning = null;
1604
1605 if (hasScheduledUpdateInCurrentCommit) {
1606 warning = 'Lifecycle hook scheduled a cascading update';
1607 } else if (commitCountInCurrentWorkLoop > 0) {
1608 warning = 'Caused by a cascading update in earlier commit';
1609 }
1610
1611 hasScheduledUpdateInCurrentCommit = false;
1612 commitCountInCurrentWorkLoop++;
1613 isCommitting = false;
1614 labelsInCurrentCommit.clear();
1615 endMark('(Committing Changes)', '(Committing Changes)', warning);
1616 }
1617}
1618function startCommitSnapshotEffectsTimer() {
1619 if (enableUserTimingAPI) {
1620 if (!supportsUserTiming) {
1621 return;
1622 }
1623
1624 effectCountInCurrentCommit = 0;
1625 beginMark('(Committing Snapshot Effects)');
1626 }
1627}
1628function stopCommitSnapshotEffectsTimer() {
1629 if (enableUserTimingAPI) {
1630 if (!supportsUserTiming) {
1631 return;
1632 }
1633
1634 var count = effectCountInCurrentCommit;
1635 effectCountInCurrentCommit = 0;
1636 endMark("(Committing Snapshot Effects: " + count + " Total)", '(Committing Snapshot Effects)', null);
1637 }
1638}
1639function startCommitHostEffectsTimer() {
1640 if (enableUserTimingAPI) {
1641 if (!supportsUserTiming) {
1642 return;
1643 }
1644
1645 effectCountInCurrentCommit = 0;
1646 beginMark('(Committing Host Effects)');
1647 }
1648}
1649function stopCommitHostEffectsTimer() {
1650 if (enableUserTimingAPI) {
1651 if (!supportsUserTiming) {
1652 return;
1653 }
1654
1655 var count = effectCountInCurrentCommit;
1656 effectCountInCurrentCommit = 0;
1657 endMark("(Committing Host Effects: " + count + " Total)", '(Committing Host Effects)', null);
1658 }
1659}
1660function startCommitLifeCyclesTimer() {
1661 if (enableUserTimingAPI) {
1662 if (!supportsUserTiming) {
1663 return;
1664 }
1665
1666 effectCountInCurrentCommit = 0;
1667 beginMark('(Calling Lifecycle Methods)');
1668 }
1669}
1670function stopCommitLifeCyclesTimer() {
1671 if (enableUserTimingAPI) {
1672 if (!supportsUserTiming) {
1673 return;
1674 }
1675
1676 var count = effectCountInCurrentCommit;
1677 effectCountInCurrentCommit = 0;
1678 endMark("(Calling Lifecycle Methods: " + count + " Total)", '(Calling Lifecycle Methods)', null);
1679 }
1680}
1681
1682var valueStack = [];
1683var fiberStack;
1684
1685{
1686 fiberStack = [];
1687}
1688
1689var index = -1;
1690
1691function createCursor(defaultValue) {
1692 return {
1693 current: defaultValue
1694 };
1695}
1696
1697function pop(cursor, fiber) {
1698 if (index < 0) {
1699 {
1700 warningWithoutStack$1(false, 'Unexpected pop.');
1701 }
1702
1703 return;
1704 }
1705
1706 {
1707 if (fiber !== fiberStack[index]) {
1708 warningWithoutStack$1(false, 'Unexpected Fiber popped.');
1709 }
1710 }
1711
1712 cursor.current = valueStack[index];
1713 valueStack[index] = null;
1714
1715 {
1716 fiberStack[index] = null;
1717 }
1718
1719 index--;
1720}
1721
1722function push(cursor, value, fiber) {
1723 index++;
1724 valueStack[index] = cursor.current;
1725
1726 {
1727 fiberStack[index] = fiber;
1728 }
1729
1730 cursor.current = value;
1731}
1732
1733var warnedAboutMissingGetChildContext;
1734
1735{
1736 warnedAboutMissingGetChildContext = {};
1737}
1738
1739var emptyContextObject = {};
1740
1741{
1742 Object.freeze(emptyContextObject);
1743} // A cursor to the current merged context object on the stack.
1744
1745
1746var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
1747
1748var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
1749// We use this to get access to the parent context after we have already
1750// pushed the next context provider, and now need to merge their contexts.
1751
1752var previousContext = emptyContextObject;
1753
1754function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
1755 if (disableLegacyContext) {
1756 return emptyContextObject;
1757 } else {
1758 if (didPushOwnContextIfProvider && isContextProvider(Component)) {
1759 // If the fiber is a context provider itself, when we read its context
1760 // we may have already pushed its own child context on the stack. A context
1761 // provider should not "see" its own child context. Therefore we read the
1762 // previous (parent) context instead for a context provider.
1763 return previousContext;
1764 }
1765
1766 return contextStackCursor.current;
1767 }
1768}
1769
1770function cacheContext(workInProgress, unmaskedContext, maskedContext) {
1771 if (disableLegacyContext) {
1772 return;
1773 } else {
1774 var instance = workInProgress.stateNode;
1775 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
1776 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
1777 }
1778}
1779
1780function getMaskedContext(workInProgress, unmaskedContext) {
1781 if (disableLegacyContext) {
1782 return emptyContextObject;
1783 } else {
1784 var type = workInProgress.type;
1785 var contextTypes = type.contextTypes;
1786
1787 if (!contextTypes) {
1788 return emptyContextObject;
1789 } // Avoid recreating masked context unless unmasked context has changed.
1790 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
1791 // This may trigger infinite loops if componentWillReceiveProps calls setState.
1792
1793
1794 var instance = workInProgress.stateNode;
1795
1796 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
1797 return instance.__reactInternalMemoizedMaskedChildContext;
1798 }
1799
1800 var context = {};
1801
1802 for (var key in contextTypes) {
1803 context[key] = unmaskedContext[key];
1804 }
1805
1806 {
1807 var name = getComponentName(type) || 'Unknown';
1808 checkPropTypes_1(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
1809 } // Cache unmasked context so we can avoid recreating masked context unless necessary.
1810 // Context is created before the class component is instantiated so check for instance.
1811
1812
1813 if (instance) {
1814 cacheContext(workInProgress, unmaskedContext, context);
1815 }
1816
1817 return context;
1818 }
1819}
1820
1821function hasContextChanged() {
1822 if (disableLegacyContext) {
1823 return false;
1824 } else {
1825 return didPerformWorkStackCursor.current;
1826 }
1827}
1828
1829function isContextProvider(type) {
1830 if (disableLegacyContext) {
1831 return false;
1832 } else {
1833 var childContextTypes = type.childContextTypes;
1834 return childContextTypes !== null && childContextTypes !== undefined;
1835 }
1836}
1837
1838function popContext(fiber) {
1839 if (disableLegacyContext) {
1840 return;
1841 } else {
1842 pop(didPerformWorkStackCursor, fiber);
1843 pop(contextStackCursor, fiber);
1844 }
1845}
1846
1847function popTopLevelContextObject(fiber) {
1848 if (disableLegacyContext) {
1849 return;
1850 } else {
1851 pop(didPerformWorkStackCursor, fiber);
1852 pop(contextStackCursor, fiber);
1853 }
1854}
1855
1856function pushTopLevelContextObject(fiber, context, didChange) {
1857 if (disableLegacyContext) {
1858 return;
1859 } else {
1860 (function () {
1861 if (!(contextStackCursor.current === emptyContextObject)) {
1862 {
1863 throw ReactError(Error("Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."));
1864 }
1865 }
1866 })();
1867
1868 push(contextStackCursor, context, fiber);
1869 push(didPerformWorkStackCursor, didChange, fiber);
1870 }
1871}
1872
1873function processChildContext(fiber, type, parentContext) {
1874 if (disableLegacyContext) {
1875 return parentContext;
1876 } else {
1877 var instance = fiber.stateNode;
1878 var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
1879 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
1880
1881 if (typeof instance.getChildContext !== 'function') {
1882 {
1883 var componentName = getComponentName(type) || 'Unknown';
1884
1885 if (!warnedAboutMissingGetChildContext[componentName]) {
1886 warnedAboutMissingGetChildContext[componentName] = true;
1887 warningWithoutStack$1(false, '%s.childContextTypes is specified but there is no getChildContext() method ' + 'on the instance. You can either define getChildContext() on %s or remove ' + 'childContextTypes from it.', componentName, componentName);
1888 }
1889 }
1890
1891 return parentContext;
1892 }
1893
1894 var childContext;
1895
1896 {
1897 setCurrentPhase('getChildContext');
1898 }
1899
1900 startPhaseTimer(fiber, 'getChildContext');
1901 childContext = instance.getChildContext();
1902 stopPhaseTimer();
1903
1904 {
1905 setCurrentPhase(null);
1906 }
1907
1908 for (var contextKey in childContext) {
1909 (function () {
1910 if (!(contextKey in childContextTypes)) {
1911 {
1912 throw ReactError(Error((getComponentName(type) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes."));
1913 }
1914 }
1915 })();
1916 }
1917
1918 {
1919 var name = getComponentName(type) || 'Unknown';
1920 checkPropTypes_1(childContextTypes, childContext, 'child context', name, // In practice, there is one case in which we won't get a stack. It's when
1921 // somebody calls unstable_renderSubtreeIntoContainer() and we process
1922 // context from the parent component instance. The stack will be missing
1923 // because it's outside of the reconciliation, and so the pointer has not
1924 // been set. This is rare and doesn't matter. We'll also remove that API.
1925 getCurrentFiberStackInDev);
1926 }
1927
1928 return _assign({}, parentContext, {}, childContext);
1929 }
1930}
1931
1932function pushContextProvider(workInProgress) {
1933 if (disableLegacyContext) {
1934 return false;
1935 } else {
1936 var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
1937 // If the instance does not exist yet, we will push null at first,
1938 // and replace it on the stack later when invalidating the context.
1939
1940 var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject; // Remember the parent context so we can merge with it later.
1941 // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
1942
1943 previousContext = contextStackCursor.current;
1944 push(contextStackCursor, memoizedMergedChildContext, workInProgress);
1945 push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
1946 return true;
1947 }
1948}
1949
1950function invalidateContextProvider(workInProgress, type, didChange) {
1951 if (disableLegacyContext) {
1952 return;
1953 } else {
1954 var instance = workInProgress.stateNode;
1955
1956 (function () {
1957 if (!instance) {
1958 {
1959 throw ReactError(Error("Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."));
1960 }
1961 }
1962 })();
1963
1964 if (didChange) {
1965 // Merge parent and own context.
1966 // Skip this if we're not updating due to sCU.
1967 // This avoids unnecessarily recomputing memoized values.
1968 var mergedContext = processChildContext(workInProgress, type, previousContext);
1969 instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
1970 // It is important to unwind the context in the reverse order.
1971
1972 pop(didPerformWorkStackCursor, workInProgress);
1973 pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
1974
1975 push(contextStackCursor, mergedContext, workInProgress);
1976 push(didPerformWorkStackCursor, didChange, workInProgress);
1977 } else {
1978 pop(didPerformWorkStackCursor, workInProgress);
1979 push(didPerformWorkStackCursor, didChange, workInProgress);
1980 }
1981 }
1982}
1983
1984function findCurrentUnmaskedContext(fiber) {
1985 if (disableLegacyContext) {
1986 return emptyContextObject;
1987 } else {
1988 // Currently this is only used with renderSubtreeIntoContainer; not sure if it
1989 // makes sense elsewhere
1990 (function () {
1991 if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
1992 {
1993 throw ReactError(Error("Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."));
1994 }
1995 }
1996 })();
1997
1998 var node = fiber;
1999
2000 do {
2001 switch (node.tag) {
2002 case HostRoot:
2003 return node.stateNode.context;
2004
2005 case ClassComponent:
2006 {
2007 var Component = node.type;
2008
2009 if (isContextProvider(Component)) {
2010 return node.stateNode.__reactInternalMemoizedMergedChildContext;
2011 }
2012
2013 break;
2014 }
2015 }
2016
2017 node = node.return;
2018 } while (node !== null);
2019
2020 (function () {
2021 {
2022 {
2023 throw ReactError(Error("Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."));
2024 }
2025 }
2026 })();
2027 }
2028}
2029
2030var LegacyRoot = 0;
2031var BatchedRoot = 1;
2032var ConcurrentRoot = 2;
2033
2034var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2035var _ReactInternals$Sched = ReactInternals$1.SchedulerTracing;
2036var __interactionsRef = _ReactInternals$Sched.__interactionsRef;
2037var __subscriberRef = _ReactInternals$Sched.__subscriberRef;
2038var unstable_clear = _ReactInternals$Sched.unstable_clear;
2039var unstable_getCurrent = _ReactInternals$Sched.unstable_getCurrent;
2040var unstable_getThreadID = _ReactInternals$Sched.unstable_getThreadID;
2041var unstable_subscribe = _ReactInternals$Sched.unstable_subscribe;
2042var unstable_trace = _ReactInternals$Sched.unstable_trace;
2043var unstable_unsubscribe = _ReactInternals$Sched.unstable_unsubscribe;
2044var unstable_wrap = _ReactInternals$Sched.unstable_wrap;
2045
2046// Intentionally not named imports because Rollup would use dynamic dispatch for
2047// CommonJS interop named imports.
2048var Scheduler_runWithPriority = Scheduler$1.unstable_runWithPriority;
2049var Scheduler_scheduleCallback = Scheduler$1.unstable_scheduleCallback;
2050var Scheduler_cancelCallback = Scheduler$1.unstable_cancelCallback;
2051var Scheduler_shouldYield = Scheduler$1.unstable_shouldYield;
2052var Scheduler_requestPaint = Scheduler$1.unstable_requestPaint;
2053var Scheduler_now = Scheduler$1.unstable_now;
2054var Scheduler_getCurrentPriorityLevel = Scheduler$1.unstable_getCurrentPriorityLevel;
2055var Scheduler_ImmediatePriority = Scheduler$1.unstable_ImmediatePriority;
2056var Scheduler_UserBlockingPriority = Scheduler$1.unstable_UserBlockingPriority;
2057var Scheduler_NormalPriority = Scheduler$1.unstable_NormalPriority;
2058var Scheduler_LowPriority = Scheduler$1.unstable_LowPriority;
2059var Scheduler_IdlePriority = Scheduler$1.unstable_IdlePriority;
2060
2061if (enableSchedulerTracing) {
2062 // Provide explicit error message when production+profiling bundle of e.g.
2063 // react-dom is used with production (non-profiling) bundle of
2064 // scheduler/tracing
2065 (function () {
2066 if (!(__interactionsRef != null && __interactionsRef.current != null)) {
2067 {
2068 throw ReactError(Error("It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `scheduler/tracing` module with `scheduler/tracing-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at http://fb.me/react-profiling"));
2069 }
2070 }
2071 })();
2072}
2073
2074var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
2075// ascending numbers so we can compare them like numbers. They start at 90 to
2076// avoid clashing with Scheduler's priorities.
2077
2078var ImmediatePriority = 99;
2079var UserBlockingPriority = 98;
2080var NormalPriority = 97;
2081var LowPriority = 96;
2082var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
2083
2084var NoPriority = 90;
2085var shouldYield = Scheduler_shouldYield;
2086var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
2087Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function () {};
2088var syncQueue = null;
2089var immediateQueueCallbackNode = null;
2090var isFlushingSyncQueue = false;
2091var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
2092// This will be the case for modern browsers that support `performance.now`. In
2093// older browsers, Scheduler falls back to `Date.now`, which returns a Unix
2094// timestamp. In that case, subtract the module initialization time to simulate
2095// the behavior of performance.now and keep our times small enough to fit
2096// within 32 bits.
2097// TODO: Consider lifting this into Scheduler.
2098
2099var now = initialTimeMs < 10000 ? Scheduler_now : function () {
2100 return Scheduler_now() - initialTimeMs;
2101};
2102function getCurrentPriorityLevel() {
2103 switch (Scheduler_getCurrentPriorityLevel()) {
2104 case Scheduler_ImmediatePriority:
2105 return ImmediatePriority;
2106
2107 case Scheduler_UserBlockingPriority:
2108 return UserBlockingPriority;
2109
2110 case Scheduler_NormalPriority:
2111 return NormalPriority;
2112
2113 case Scheduler_LowPriority:
2114 return LowPriority;
2115
2116 case Scheduler_IdlePriority:
2117 return IdlePriority;
2118
2119 default:
2120 (function () {
2121 {
2122 {
2123 throw ReactError(Error("Unknown priority level."));
2124 }
2125 }
2126 })();
2127
2128 }
2129}
2130
2131function reactPriorityToSchedulerPriority(reactPriorityLevel) {
2132 switch (reactPriorityLevel) {
2133 case ImmediatePriority:
2134 return Scheduler_ImmediatePriority;
2135
2136 case UserBlockingPriority:
2137 return Scheduler_UserBlockingPriority;
2138
2139 case NormalPriority:
2140 return Scheduler_NormalPriority;
2141
2142 case LowPriority:
2143 return Scheduler_LowPriority;
2144
2145 case IdlePriority:
2146 return Scheduler_IdlePriority;
2147
2148 default:
2149 (function () {
2150 {
2151 {
2152 throw ReactError(Error("Unknown priority level."));
2153 }
2154 }
2155 })();
2156
2157 }
2158}
2159
2160function runWithPriority(reactPriorityLevel, fn) {
2161 var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
2162 return Scheduler_runWithPriority(priorityLevel, fn);
2163}
2164function scheduleCallback(reactPriorityLevel, callback, options) {
2165 var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
2166 return Scheduler_scheduleCallback(priorityLevel, callback, options);
2167}
2168function scheduleSyncCallback(callback) {
2169 // Push this callback into an internal queue. We'll flush these either in
2170 // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
2171 if (syncQueue === null) {
2172 syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
2173
2174 immediateQueueCallbackNode = Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueueImpl);
2175 } else {
2176 // Push onto existing queue. Don't need to schedule a callback because
2177 // we already scheduled one when we created the queue.
2178 syncQueue.push(callback);
2179 }
2180
2181 return fakeCallbackNode;
2182}
2183function cancelCallback(callbackNode) {
2184 if (callbackNode !== fakeCallbackNode) {
2185 Scheduler_cancelCallback(callbackNode);
2186 }
2187}
2188function flushSyncCallbackQueue() {
2189 if (immediateQueueCallbackNode !== null) {
2190 var node = immediateQueueCallbackNode;
2191 immediateQueueCallbackNode = null;
2192 Scheduler_cancelCallback(node);
2193 }
2194
2195 flushSyncCallbackQueueImpl();
2196}
2197
2198function flushSyncCallbackQueueImpl() {
2199 if (!isFlushingSyncQueue && syncQueue !== null) {
2200 // Prevent re-entrancy.
2201 isFlushingSyncQueue = true;
2202 var i = 0;
2203
2204 try {
2205 var _isSync = true;
2206 var queue = syncQueue;
2207 runWithPriority(ImmediatePriority, function () {
2208 for (; i < queue.length; i++) {
2209 var callback = queue[i];
2210
2211 do {
2212 callback = callback(_isSync);
2213 } while (callback !== null);
2214 }
2215 });
2216 syncQueue = null;
2217 } catch (error) {
2218 // If something throws, leave the remaining callbacks on the queue.
2219 if (syncQueue !== null) {
2220 syncQueue = syncQueue.slice(i + 1);
2221 } // Resume flushing in the next tick
2222
2223
2224 Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueue);
2225 throw error;
2226 } finally {
2227 isFlushingSyncQueue = false;
2228 }
2229 }
2230}
2231
2232var NoMode = 0;
2233var StrictMode = 1; // TODO: Remove BatchedMode and ConcurrentMode by reading from the root
2234// tag instead
2235
2236var BatchedMode = 2;
2237var ConcurrentMode = 4;
2238var ProfileMode = 8;
2239
2240// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
2241// Math.pow(2, 30) - 1
2242// 0b111111111111111111111111111111
2243var MAX_SIGNED_31_BIT_INT = 1073741823;
2244
2245var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
2246// Never work can be committed in an inconsistent state without tearing the UI.
2247// The main example is offscreen content, like a hidden subtree. So one possible
2248// name is Offscreen. However, it also includes dehydrated Suspense boundaries,
2249// which are inconsistent in the sense that they haven't finished yet, but
2250// aren't visibly inconsistent because the server rendered HTML matches what the
2251// hydrated tree would look like.
2252
2253var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
2254// order to be consistent.
2255
2256var Idle = 2;
2257var Sync = MAX_SIGNED_31_BIT_INT;
2258var Batched = Sync - 1;
2259var UNIT_SIZE = 10;
2260var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
2261
2262function msToExpirationTime(ms) {
2263 // Always add an offset so that we don't clash with the magic number for NoWork.
2264 return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
2265}
2266function expirationTimeToMs(expirationTime) {
2267 return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
2268}
2269
2270function ceiling(num, precision) {
2271 return ((num / precision | 0) + 1) * precision;
2272}
2273
2274function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
2275 return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
2276} // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
2277// the names to reflect.
2278
2279
2280var LOW_PRIORITY_EXPIRATION = 5000;
2281var LOW_PRIORITY_BATCH_SIZE = 250;
2282function computeAsyncExpiration(currentTime) {
2283 return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
2284}
2285function computeSuspenseExpiration(currentTime, timeoutMs) {
2286 // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
2287 return computeExpirationBucket(currentTime, timeoutMs, LOW_PRIORITY_BATCH_SIZE);
2288} // We intentionally set a higher expiration time for interactive updates in
2289// dev than in production.
2290//
2291// If the main thread is being blocked so long that you hit the expiration,
2292// it's a problem that could be solved with better scheduling.
2293//
2294// People will be more likely to notice this and fix it with the long
2295// expiration time in development.
2296//
2297// In production we opt for better UX at the risk of masking scheduling
2298// problems, by expiring fast.
2299
2300var HIGH_PRIORITY_EXPIRATION = 500;
2301var HIGH_PRIORITY_BATCH_SIZE = 100;
2302function computeInteractiveExpiration(currentTime) {
2303 return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
2304}
2305function inferPriorityFromExpirationTime(currentTime, expirationTime) {
2306 if (expirationTime === Sync) {
2307 return ImmediatePriority;
2308 }
2309
2310 if (expirationTime === Never || expirationTime === Idle) {
2311 return IdlePriority;
2312 }
2313
2314 var msUntil = expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
2315
2316 if (msUntil <= 0) {
2317 return ImmediatePriority;
2318 }
2319
2320 if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
2321 return UserBlockingPriority;
2322 }
2323
2324 if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
2325 return NormalPriority;
2326 } // TODO: Handle LowPriority
2327 // Assume anything lower has idle priority
2328
2329
2330 return IdlePriority;
2331}
2332
2333/**
2334 * inlined Object.is polyfill to avoid requiring consumers ship their own
2335 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
2336 */
2337function is(x, y) {
2338 return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
2339 ;
2340}
2341
2342var is$1 = typeof Object.is === 'function' ? Object.is : is;
2343
2344var hasOwnProperty = Object.prototype.hasOwnProperty;
2345/**
2346 * Performs equality by iterating through keys on an object and returning false
2347 * when any key has values which are not strictly equal between the arguments.
2348 * Returns true when the values of all keys are strictly equal.
2349 */
2350
2351function shallowEqual(objA, objB) {
2352 if (is$1(objA, objB)) {
2353 return true;
2354 }
2355
2356 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
2357 return false;
2358 }
2359
2360 var keysA = Object.keys(objA);
2361 var keysB = Object.keys(objB);
2362
2363 if (keysA.length !== keysB.length) {
2364 return false;
2365 } // Test for A's keys different from B.
2366
2367
2368 for (var i = 0; i < keysA.length; i++) {
2369 if (!hasOwnProperty.call(objB, keysA[i]) || !is$1(objA[keysA[i]], objB[keysA[i]])) {
2370 return false;
2371 }
2372 }
2373
2374 return true;
2375}
2376
2377/**
2378 * Forked from fbjs/warning:
2379 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
2380 *
2381 * Only change is we use console.warn instead of console.error,
2382 * and do nothing when 'console' is not supported.
2383 * This really simplifies the code.
2384 * ---
2385 * Similar to invariant but only logs a warning if the condition is not met.
2386 * This can be used to log issues in development environments in critical
2387 * paths. Removing the logging code for production environments will keep the
2388 * same logic and follow the same code paths.
2389 */
2390var lowPriorityWarningWithoutStack = function () {};
2391
2392{
2393 var printWarning$1 = function (format) {
2394 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2395 args[_key - 1] = arguments[_key];
2396 }
2397
2398 var argIndex = 0;
2399 var message = 'Warning: ' + format.replace(/%s/g, function () {
2400 return args[argIndex++];
2401 });
2402
2403 if (typeof console !== 'undefined') {
2404 console.warn(message);
2405 }
2406
2407 try {
2408 // --- Welcome to debugging React ---
2409 // This error was thrown as a convenience so that you can use this stack
2410 // to find the callsite that caused this warning to fire.
2411 throw new Error(message);
2412 } catch (x) {}
2413 };
2414
2415 lowPriorityWarningWithoutStack = function (condition, format) {
2416 if (format === undefined) {
2417 throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
2418 }
2419
2420 if (!condition) {
2421 for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2422 args[_key2 - 2] = arguments[_key2];
2423 }
2424
2425 printWarning$1.apply(void 0, [format].concat(args));
2426 }
2427 };
2428}
2429
2430var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack;
2431
2432var ReactStrictModeWarnings = {
2433 recordUnsafeLifecycleWarnings: function (fiber, instance) {},
2434 flushPendingUnsafeLifecycleWarnings: function () {},
2435 recordLegacyContextWarning: function (fiber, instance) {},
2436 flushLegacyContextWarning: function () {},
2437 discardPendingWarnings: function () {}
2438};
2439
2440{
2441 var findStrictRoot = function (fiber) {
2442 var maybeStrictRoot = null;
2443 var node = fiber;
2444
2445 while (node !== null) {
2446 if (node.mode & StrictMode) {
2447 maybeStrictRoot = node;
2448 }
2449
2450 node = node.return;
2451 }
2452
2453 return maybeStrictRoot;
2454 };
2455
2456 var setToSortedString = function (set) {
2457 var array = [];
2458 set.forEach(function (value) {
2459 array.push(value);
2460 });
2461 return array.sort().join(', ');
2462 };
2463
2464 var pendingComponentWillMountWarnings = [];
2465 var pendingUNSAFE_ComponentWillMountWarnings = [];
2466 var pendingComponentWillReceivePropsWarnings = [];
2467 var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2468 var pendingComponentWillUpdateWarnings = [];
2469 var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
2470
2471 var didWarnAboutUnsafeLifecycles = new Set();
2472
2473 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
2474 // Dedup strategy: Warn once per component.
2475 if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
2476 return;
2477 }
2478
2479 if (typeof instance.componentWillMount === 'function' && // Don't warn about react-lifecycles-compat polyfilled components.
2480 instance.componentWillMount.__suppressDeprecationWarning !== true) {
2481 pendingComponentWillMountWarnings.push(fiber);
2482 }
2483
2484 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillMount === 'function') {
2485 pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
2486 }
2487
2488 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
2489 pendingComponentWillReceivePropsWarnings.push(fiber);
2490 }
2491
2492 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
2493 pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
2494 }
2495
2496 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
2497 pendingComponentWillUpdateWarnings.push(fiber);
2498 }
2499
2500 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillUpdate === 'function') {
2501 pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
2502 }
2503 };
2504
2505 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
2506 // We do an initial pass to gather component names
2507 var componentWillMountUniqueNames = new Set();
2508
2509 if (pendingComponentWillMountWarnings.length > 0) {
2510 pendingComponentWillMountWarnings.forEach(function (fiber) {
2511 componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
2512 didWarnAboutUnsafeLifecycles.add(fiber.type);
2513 });
2514 pendingComponentWillMountWarnings = [];
2515 }
2516
2517 var UNSAFE_componentWillMountUniqueNames = new Set();
2518
2519 if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
2520 pendingUNSAFE_ComponentWillMountWarnings.forEach(function (fiber) {
2521 UNSAFE_componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
2522 didWarnAboutUnsafeLifecycles.add(fiber.type);
2523 });
2524 pendingUNSAFE_ComponentWillMountWarnings = [];
2525 }
2526
2527 var componentWillReceivePropsUniqueNames = new Set();
2528
2529 if (pendingComponentWillReceivePropsWarnings.length > 0) {
2530 pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
2531 componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
2532 didWarnAboutUnsafeLifecycles.add(fiber.type);
2533 });
2534 pendingComponentWillReceivePropsWarnings = [];
2535 }
2536
2537 var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
2538
2539 if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
2540 pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function (fiber) {
2541 UNSAFE_componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
2542 didWarnAboutUnsafeLifecycles.add(fiber.type);
2543 });
2544 pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2545 }
2546
2547 var componentWillUpdateUniqueNames = new Set();
2548
2549 if (pendingComponentWillUpdateWarnings.length > 0) {
2550 pendingComponentWillUpdateWarnings.forEach(function (fiber) {
2551 componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
2552 didWarnAboutUnsafeLifecycles.add(fiber.type);
2553 });
2554 pendingComponentWillUpdateWarnings = [];
2555 }
2556
2557 var UNSAFE_componentWillUpdateUniqueNames = new Set();
2558
2559 if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
2560 pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function (fiber) {
2561 UNSAFE_componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
2562 didWarnAboutUnsafeLifecycles.add(fiber.type);
2563 });
2564 pendingUNSAFE_ComponentWillUpdateWarnings = [];
2565 } // Finally, we flush all the warnings
2566 // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
2567
2568
2569 if (UNSAFE_componentWillMountUniqueNames.size > 0) {
2570 var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
2571 warningWithoutStack$1(false, 'Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' + '\nPlease update the following components: %s', sortedNames);
2572 }
2573
2574 if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
2575 var _sortedNames = setToSortedString(UNSAFE_componentWillReceivePropsUniqueNames);
2576
2577 warningWithoutStack$1(false, 'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + "* If you're updating state whenever props change, " + 'refactor your code to use memoization techniques or move it to ' + 'static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n' + '\nPlease update the following components: %s', _sortedNames);
2578 }
2579
2580 if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
2581 var _sortedNames2 = setToSortedString(UNSAFE_componentWillUpdateUniqueNames);
2582
2583 warningWithoutStack$1(false, 'Using UNSAFE_componentWillUpdate in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + '\nPlease update the following components: %s', _sortedNames2);
2584 }
2585
2586 if (componentWillMountUniqueNames.size > 0) {
2587 var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
2588
2589 lowPriorityWarningWithoutStack$1(false, 'componentWillMount has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' + '* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' + 'this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames3);
2590 }
2591
2592 if (componentWillReceivePropsUniqueNames.size > 0) {
2593 var _sortedNames4 = setToSortedString(componentWillReceivePropsUniqueNames);
2594
2595 lowPriorityWarningWithoutStack$1(false, 'componentWillReceiveProps has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + "* If you're updating state whenever props change, refactor your " + 'code to use memoization techniques or move it to ' + 'static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n' + '* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' + 'this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames4);
2596 }
2597
2598 if (componentWillUpdateUniqueNames.size > 0) {
2599 var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
2600
2601 lowPriorityWarningWithoutStack$1(false, 'componentWillUpdate has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + '* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' + 'this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames5);
2602 }
2603 };
2604
2605 var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
2606
2607 var didWarnAboutLegacyContext = new Set();
2608
2609 ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
2610 var strictRoot = findStrictRoot(fiber);
2611
2612 if (strictRoot === null) {
2613 warningWithoutStack$1(false, 'Expected to find a StrictMode component in a strict mode tree. ' + 'This error is likely caused by a bug in React. Please file an issue.');
2614 return;
2615 } // Dedup strategy: Warn once per component.
2616
2617
2618 if (didWarnAboutLegacyContext.has(fiber.type)) {
2619 return;
2620 }
2621
2622 var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
2623
2624 if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
2625 if (warningsForRoot === undefined) {
2626 warningsForRoot = [];
2627 pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
2628 }
2629
2630 warningsForRoot.push(fiber);
2631 }
2632 };
2633
2634 ReactStrictModeWarnings.flushLegacyContextWarning = function () {
2635 pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
2636 var uniqueNames = new Set();
2637 fiberArray.forEach(function (fiber) {
2638 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2639 didWarnAboutLegacyContext.add(fiber.type);
2640 });
2641 var sortedNames = setToSortedString(uniqueNames);
2642 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2643 warningWithoutStack$1(false, 'Legacy context API has been detected within a strict-mode tree.' + '\n\nThe old API will be supported in all 16.x releases, but applications ' + 'using it should migrate to the new version.' + '\n\nPlease update the following components: %s' + '\n\nLearn more about this warning here: https://fb.me/react-legacy-context' + '%s', sortedNames, strictRootComponentStack);
2644 });
2645 };
2646
2647 ReactStrictModeWarnings.discardPendingWarnings = function () {
2648 pendingComponentWillMountWarnings = [];
2649 pendingUNSAFE_ComponentWillMountWarnings = [];
2650 pendingComponentWillReceivePropsWarnings = [];
2651 pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2652 pendingComponentWillUpdateWarnings = [];
2653 pendingUNSAFE_ComponentWillUpdateWarnings = [];
2654 pendingLegacyContextWarning = new Map();
2655 };
2656}
2657
2658var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
2659
2660var failedBoundaries = null;
2661var setRefreshHandler = function (handler) {
2662 {
2663 resolveFamily = handler;
2664 }
2665};
2666function resolveFunctionForHotReloading(type) {
2667 {
2668 if (resolveFamily === null) {
2669 // Hot reloading is disabled.
2670 return type;
2671 }
2672
2673 var family = resolveFamily(type);
2674
2675 if (family === undefined) {
2676 return type;
2677 } // Use the latest known implementation.
2678
2679
2680 return family.current;
2681 }
2682}
2683function resolveClassForHotReloading(type) {
2684 // No implementation differences.
2685 return resolveFunctionForHotReloading(type);
2686}
2687function resolveForwardRefForHotReloading(type) {
2688 {
2689 if (resolveFamily === null) {
2690 // Hot reloading is disabled.
2691 return type;
2692 }
2693
2694 var family = resolveFamily(type);
2695
2696 if (family === undefined) {
2697 // Check if we're dealing with a real forwardRef. Don't want to crash early.
2698 if (type !== null && type !== undefined && typeof type.render === 'function') {
2699 // ForwardRef is special because its resolved .type is an object,
2700 // but it's possible that we only have its inner render function in the map.
2701 // If that inner render function is different, we'll build a new forwardRef type.
2702 var currentRender = resolveFunctionForHotReloading(type.render);
2703
2704 if (type.render !== currentRender) {
2705 var syntheticType = {
2706 $$typeof: REACT_FORWARD_REF_TYPE,
2707 render: currentRender
2708 };
2709
2710 if (type.displayName !== undefined) {
2711 syntheticType.displayName = type.displayName;
2712 }
2713
2714 return syntheticType;
2715 }
2716 }
2717
2718 return type;
2719 } // Use the latest known implementation.
2720
2721
2722 return family.current;
2723 }
2724}
2725function isCompatibleFamilyForHotReloading(fiber, element) {
2726 {
2727 if (resolveFamily === null) {
2728 // Hot reloading is disabled.
2729 return false;
2730 }
2731
2732 var prevType = fiber.elementType;
2733 var nextType = element.type; // If we got here, we know types aren't === equal.
2734
2735 var needsCompareFamilies = false;
2736 var $$typeofNextType = typeof nextType === 'object' && nextType !== null ? nextType.$$typeof : null;
2737
2738 switch (fiber.tag) {
2739 case ClassComponent:
2740 {
2741 if (typeof nextType === 'function') {
2742 needsCompareFamilies = true;
2743 }
2744
2745 break;
2746 }
2747
2748 case FunctionComponent:
2749 {
2750 if (typeof nextType === 'function') {
2751 needsCompareFamilies = true;
2752 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2753 // We don't know the inner type yet.
2754 // We're going to assume that the lazy inner type is stable,
2755 // and so it is sufficient to avoid reconciling it away.
2756 // We're not going to unwrap or actually use the new lazy type.
2757 needsCompareFamilies = true;
2758 }
2759
2760 break;
2761 }
2762
2763 case ForwardRef:
2764 {
2765 if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
2766 needsCompareFamilies = true;
2767 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2768 needsCompareFamilies = true;
2769 }
2770
2771 break;
2772 }
2773
2774 case MemoComponent:
2775 case SimpleMemoComponent:
2776 {
2777 if ($$typeofNextType === REACT_MEMO_TYPE) {
2778 // TODO: if it was but can no longer be simple,
2779 // we shouldn't set this.
2780 needsCompareFamilies = true;
2781 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2782 needsCompareFamilies = true;
2783 }
2784
2785 break;
2786 }
2787
2788 default:
2789 return false;
2790 } // Check if both types have a family and it's the same one.
2791
2792
2793 if (needsCompareFamilies) {
2794 // Note: memo() and forwardRef() we'll compare outer rather than inner type.
2795 // This means both of them need to be registered to preserve state.
2796 // If we unwrapped and compared the inner types for wrappers instead,
2797 // then we would risk falsely saying two separate memo(Foo)
2798 // calls are equivalent because they wrap the same Foo function.
2799 var prevFamily = resolveFamily(prevType);
2800
2801 if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
2802 return true;
2803 }
2804 }
2805
2806 return false;
2807 }
2808}
2809function markFailedErrorBoundaryForHotReloading(fiber) {
2810 {
2811 if (resolveFamily === null) {
2812 // Hot reloading is disabled.
2813 return;
2814 }
2815
2816 if (typeof WeakSet !== 'function') {
2817 return;
2818 }
2819
2820 if (failedBoundaries === null) {
2821 failedBoundaries = new WeakSet();
2822 }
2823
2824 failedBoundaries.add(fiber);
2825 }
2826}
2827var scheduleRefresh = function (root, update) {
2828 {
2829 if (resolveFamily === null) {
2830 // Hot reloading is disabled.
2831 return;
2832 }
2833
2834 var staleFamilies = update.staleFamilies,
2835 updatedFamilies = update.updatedFamilies;
2836 flushPassiveEffects();
2837 flushSync(function () {
2838 scheduleFibersWithFamiliesRecursively(root.current, updatedFamilies, staleFamilies);
2839 });
2840 }
2841};
2842var scheduleRoot = function (root, element) {
2843 {
2844 if (root.context !== emptyContextObject) {
2845 // Super edge case: root has a legacy _renderSubtree context
2846 // but we don't know the parentComponent so we can't pass it.
2847 // Just ignore. We'll delete this with _renderSubtree code path later.
2848 return;
2849 }
2850
2851 flushPassiveEffects();
2852 updateContainerAtExpirationTime(element, root, null, Sync, null);
2853 }
2854};
2855
2856function scheduleFibersWithFamiliesRecursively(fiber, updatedFamilies, staleFamilies) {
2857 {
2858 var alternate = fiber.alternate,
2859 child = fiber.child,
2860 sibling = fiber.sibling,
2861 tag = fiber.tag,
2862 type = fiber.type;
2863 var candidateType = null;
2864
2865 switch (tag) {
2866 case FunctionComponent:
2867 case SimpleMemoComponent:
2868 case ClassComponent:
2869 candidateType = type;
2870 break;
2871
2872 case ForwardRef:
2873 candidateType = type.render;
2874 break;
2875
2876 default:
2877 break;
2878 }
2879
2880 if (resolveFamily === null) {
2881 throw new Error('Expected resolveFamily to be set during hot reload.');
2882 }
2883
2884 var needsRender = false;
2885 var needsRemount = false;
2886
2887 if (candidateType !== null) {
2888 var family = resolveFamily(candidateType);
2889
2890 if (family !== undefined) {
2891 if (staleFamilies.has(family)) {
2892 needsRemount = true;
2893 } else if (updatedFamilies.has(family)) {
2894 if (tag === ClassComponent) {
2895 needsRemount = true;
2896 } else {
2897 needsRender = true;
2898 }
2899 }
2900 }
2901 }
2902
2903 if (failedBoundaries !== null) {
2904 if (failedBoundaries.has(fiber) || alternate !== null && failedBoundaries.has(alternate)) {
2905 needsRemount = true;
2906 }
2907 }
2908
2909 if (needsRemount) {
2910 fiber._debugNeedsRemount = true;
2911 }
2912
2913 if (needsRemount || needsRender) {
2914 scheduleWork(fiber, Sync);
2915 }
2916
2917 if (child !== null && !needsRemount) {
2918 scheduleFibersWithFamiliesRecursively(child, updatedFamilies, staleFamilies);
2919 }
2920
2921 if (sibling !== null) {
2922 scheduleFibersWithFamiliesRecursively(sibling, updatedFamilies, staleFamilies);
2923 }
2924 }
2925}
2926
2927var findHostInstancesForRefresh = function (root, families) {
2928 {
2929 var hostInstances = new Set();
2930 var types = new Set(families.map(function (family) {
2931 return family.current;
2932 }));
2933 findHostInstancesForMatchingFibersRecursively(root.current, types, hostInstances);
2934 return hostInstances;
2935 }
2936};
2937
2938function findHostInstancesForMatchingFibersRecursively(fiber, types, hostInstances) {
2939 {
2940 var child = fiber.child,
2941 sibling = fiber.sibling,
2942 tag = fiber.tag,
2943 type = fiber.type;
2944 var candidateType = null;
2945
2946 switch (tag) {
2947 case FunctionComponent:
2948 case SimpleMemoComponent:
2949 case ClassComponent:
2950 candidateType = type;
2951 break;
2952
2953 case ForwardRef:
2954 candidateType = type.render;
2955 break;
2956
2957 default:
2958 break;
2959 }
2960
2961 var didMatch = false;
2962
2963 if (candidateType !== null) {
2964 if (types.has(candidateType)) {
2965 didMatch = true;
2966 }
2967 }
2968
2969 if (didMatch) {
2970 // We have a match. This only drills down to the closest host components.
2971 // There's no need to search deeper because for the purpose of giving
2972 // visual feedback, "flashing" outermost parent rectangles is sufficient.
2973 findHostInstancesForFiberShallowly(fiber, hostInstances);
2974 } else {
2975 // If there's no match, maybe there will be one further down in the child tree.
2976 if (child !== null) {
2977 findHostInstancesForMatchingFibersRecursively(child, types, hostInstances);
2978 }
2979 }
2980
2981 if (sibling !== null) {
2982 findHostInstancesForMatchingFibersRecursively(sibling, types, hostInstances);
2983 }
2984 }
2985}
2986
2987function findHostInstancesForFiberShallowly(fiber, hostInstances) {
2988 {
2989 var foundHostInstances = findChildHostInstancesForFiberShallowly(fiber, hostInstances);
2990
2991 if (foundHostInstances) {
2992 return;
2993 } // If we didn't find any host children, fallback to closest host parent.
2994
2995
2996 var node = fiber;
2997
2998 while (true) {
2999 switch (node.tag) {
3000 case HostComponent:
3001 hostInstances.add(node.stateNode);
3002 return;
3003
3004 case HostPortal:
3005 hostInstances.add(node.stateNode.containerInfo);
3006 return;
3007
3008 case HostRoot:
3009 hostInstances.add(node.stateNode.containerInfo);
3010 return;
3011 }
3012
3013 if (node.return === null) {
3014 throw new Error('Expected to reach root first.');
3015 }
3016
3017 node = node.return;
3018 }
3019 }
3020}
3021
3022function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
3023 {
3024 var node = fiber;
3025 var foundHostInstances = false;
3026
3027 while (true) {
3028 if (node.tag === HostComponent) {
3029 // We got a match.
3030 foundHostInstances = true;
3031 hostInstances.add(node.stateNode); // There may still be more, so keep searching.
3032 } else if (node.child !== null) {
3033 node.child.return = node;
3034 node = node.child;
3035 continue;
3036 }
3037
3038 if (node === fiber) {
3039 return foundHostInstances;
3040 }
3041
3042 while (node.sibling === null) {
3043 if (node.return === null || node.return === fiber) {
3044 return foundHostInstances;
3045 }
3046
3047 node = node.return;
3048 }
3049
3050 node.sibling.return = node.return;
3051 node = node.sibling;
3052 }
3053 }
3054
3055 return false;
3056}
3057
3058function resolveDefaultProps(Component, baseProps) {
3059 if (Component && Component.defaultProps) {
3060 // Resolve default props. Taken from ReactElement
3061 var props = _assign({}, baseProps);
3062
3063 var defaultProps = Component.defaultProps;
3064
3065 for (var propName in defaultProps) {
3066 if (props[propName] === undefined) {
3067 props[propName] = defaultProps[propName];
3068 }
3069 }
3070
3071 return props;
3072 }
3073
3074 return baseProps;
3075}
3076function readLazyComponentType(lazyComponent) {
3077 initializeLazyComponentType(lazyComponent);
3078
3079 if (lazyComponent._status !== Resolved) {
3080 throw lazyComponent._result;
3081 }
3082
3083 return lazyComponent._result;
3084}
3085
3086var valueCursor = createCursor(null);
3087var rendererSigil;
3088
3089{
3090 // Use this to detect multiple renderers using the same context
3091 rendererSigil = {};
3092}
3093
3094var currentlyRenderingFiber = null;
3095var lastContextDependency = null;
3096var lastContextWithAllBitsObserved = null;
3097var isDisallowedContextReadInDEV = false;
3098function resetContextDependencies() {
3099 // This is called right before React yields execution, to ensure `readContext`
3100 // cannot be called outside the render phase.
3101 currentlyRenderingFiber = null;
3102 lastContextDependency = null;
3103 lastContextWithAllBitsObserved = null;
3104
3105 {
3106 isDisallowedContextReadInDEV = false;
3107 }
3108}
3109function enterDisallowedContextReadInDEV() {
3110 {
3111 isDisallowedContextReadInDEV = true;
3112 }
3113}
3114function exitDisallowedContextReadInDEV() {
3115 {
3116 isDisallowedContextReadInDEV = false;
3117 }
3118}
3119function pushProvider(providerFiber, nextValue) {
3120 var context = providerFiber.type._context;
3121
3122 if (isPrimaryRenderer) {
3123 push(valueCursor, context._currentValue, providerFiber);
3124 context._currentValue = nextValue;
3125
3126 {
3127 !(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;
3128 context._currentRenderer = rendererSigil;
3129 }
3130 } else {
3131 push(valueCursor, context._currentValue2, providerFiber);
3132 context._currentValue2 = nextValue;
3133
3134 {
3135 !(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;
3136 context._currentRenderer2 = rendererSigil;
3137 }
3138 }
3139}
3140function popProvider(providerFiber) {
3141 var currentValue = valueCursor.current;
3142 pop(valueCursor, providerFiber);
3143 var context = providerFiber.type._context;
3144
3145 if (isPrimaryRenderer) {
3146 context._currentValue = currentValue;
3147 } else {
3148 context._currentValue2 = currentValue;
3149 }
3150}
3151function calculateChangedBits(context, newValue, oldValue) {
3152 if (is$1(oldValue, newValue)) {
3153 // No change
3154 return 0;
3155 } else {
3156 var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
3157
3158 {
3159 !((changedBits & MAX_SIGNED_31_BIT_INT) === changedBits) ? warning$1(false, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits) : void 0;
3160 }
3161
3162 return changedBits | 0;
3163 }
3164}
3165function scheduleWorkOnParentPath(parent, renderExpirationTime) {
3166 // Update the child expiration time of all the ancestors, including
3167 // the alternates.
3168 var node = parent;
3169
3170 while (node !== null) {
3171 var alternate = node.alternate;
3172
3173 if (node.childExpirationTime < renderExpirationTime) {
3174 node.childExpirationTime = renderExpirationTime;
3175
3176 if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
3177 alternate.childExpirationTime = renderExpirationTime;
3178 }
3179 } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
3180 alternate.childExpirationTime = renderExpirationTime;
3181 } else {
3182 // Neither alternate was updated, which means the rest of the
3183 // ancestor path already has sufficient priority.
3184 break;
3185 }
3186
3187 node = node.return;
3188 }
3189}
3190function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
3191 var fiber = workInProgress.child;
3192
3193 if (fiber !== null) {
3194 // Set the return pointer of the child to the work-in-progress fiber.
3195 fiber.return = workInProgress;
3196 }
3197
3198 while (fiber !== null) {
3199 var nextFiber = void 0; // Visit this fiber.
3200
3201 var list = fiber.dependencies;
3202
3203 if (list !== null) {
3204 nextFiber = fiber.child;
3205 var dependency = list.firstContext;
3206
3207 while (dependency !== null) {
3208 // Check if the context matches.
3209 if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
3210 // Match! Schedule an update on this fiber.
3211 if (fiber.tag === ClassComponent) {
3212 // Schedule a force update on the work-in-progress.
3213 var update = createUpdate(renderExpirationTime, null);
3214 update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
3215 // update to the current fiber, too, which means it will persist even if
3216 // this render is thrown away. Since it's a race condition, not sure it's
3217 // worth fixing.
3218
3219 enqueueUpdate(fiber, update);
3220 }
3221
3222 if (fiber.expirationTime < renderExpirationTime) {
3223 fiber.expirationTime = renderExpirationTime;
3224 }
3225
3226 var alternate = fiber.alternate;
3227
3228 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
3229 alternate.expirationTime = renderExpirationTime;
3230 }
3231
3232 scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
3233
3234 if (list.expirationTime < renderExpirationTime) {
3235 list.expirationTime = renderExpirationTime;
3236 } // Since we already found a match, we can stop traversing the
3237 // dependency list.
3238
3239
3240 break;
3241 }
3242
3243 dependency = dependency.next;
3244 }
3245 } else if (fiber.tag === ContextProvider) {
3246 // Don't scan deeper if this is a matching provider
3247 nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
3248 } else if (enableSuspenseServerRenderer && fiber.tag === DehydratedFragment) {
3249 // If a dehydrated suspense bounudary is in this subtree, we don't know
3250 // if it will have any context consumers in it. The best we can do is
3251 // mark it as having updates.
3252 var parentSuspense = fiber.return;
3253
3254 (function () {
3255 if (!(parentSuspense !== null)) {
3256 {
3257 throw ReactError(Error("We just came from a parent so we must have had a parent. This is a bug in React."));
3258 }
3259 }
3260 })();
3261
3262 if (parentSuspense.expirationTime < renderExpirationTime) {
3263 parentSuspense.expirationTime = renderExpirationTime;
3264 }
3265
3266 var _alternate = parentSuspense.alternate;
3267
3268 if (_alternate !== null && _alternate.expirationTime < renderExpirationTime) {
3269 _alternate.expirationTime = renderExpirationTime;
3270 } // This is intentionally passing this fiber as the parent
3271 // because we want to schedule this fiber as having work
3272 // on its children. We'll use the childExpirationTime on
3273 // this fiber to indicate that a context has changed.
3274
3275
3276 scheduleWorkOnParentPath(parentSuspense, renderExpirationTime);
3277 nextFiber = fiber.sibling;
3278 } else {
3279 // Traverse down.
3280 nextFiber = fiber.child;
3281 }
3282
3283 if (nextFiber !== null) {
3284 // Set the return pointer of the child to the work-in-progress fiber.
3285 nextFiber.return = fiber;
3286 } else {
3287 // No child. Traverse to next sibling.
3288 nextFiber = fiber;
3289
3290 while (nextFiber !== null) {
3291 if (nextFiber === workInProgress) {
3292 // We're back to the root of this subtree. Exit.
3293 nextFiber = null;
3294 break;
3295 }
3296
3297 var sibling = nextFiber.sibling;
3298
3299 if (sibling !== null) {
3300 // Set the return pointer of the sibling to the work-in-progress fiber.
3301 sibling.return = nextFiber.return;
3302 nextFiber = sibling;
3303 break;
3304 } // No more siblings. Traverse up.
3305
3306
3307 nextFiber = nextFiber.return;
3308 }
3309 }
3310
3311 fiber = nextFiber;
3312 }
3313}
3314function prepareToReadContext(workInProgress, renderExpirationTime) {
3315 currentlyRenderingFiber = workInProgress;
3316 lastContextDependency = null;
3317 lastContextWithAllBitsObserved = null;
3318 var dependencies = workInProgress.dependencies;
3319
3320 if (dependencies !== null) {
3321 var firstContext = dependencies.firstContext;
3322
3323 if (firstContext !== null) {
3324 if (dependencies.expirationTime >= renderExpirationTime) {
3325 // Context list has a pending update. Mark that this fiber performed work.
3326 markWorkInProgressReceivedUpdate();
3327 } // Reset the work-in-progress list
3328
3329
3330 dependencies.firstContext = null;
3331 }
3332 }
3333}
3334function readContext(context, observedBits) {
3335 {
3336 // This warning would fire if you read context inside a Hook like useMemo.
3337 // Unlike the class check below, it's not enforced in production for perf.
3338 !!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;
3339 }
3340
3341 if (lastContextWithAllBitsObserved === context) {// Nothing to do. We already observe everything in this context.
3342 } else if (observedBits === false || observedBits === 0) {// Do not observe any updates.
3343 } else {
3344 var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
3345
3346 if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
3347 // Observe all updates.
3348 lastContextWithAllBitsObserved = context;
3349 resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
3350 } else {
3351 resolvedObservedBits = observedBits;
3352 }
3353
3354 var contextItem = {
3355 context: context,
3356 observedBits: resolvedObservedBits,
3357 next: null
3358 };
3359
3360 if (lastContextDependency === null) {
3361 (function () {
3362 if (!(currentlyRenderingFiber !== null)) {
3363 {
3364 throw ReactError(Error("Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()."));
3365 }
3366 }
3367 })(); // This is the first dependency for this component. Create a new list.
3368
3369
3370 lastContextDependency = contextItem;
3371 currentlyRenderingFiber.dependencies = {
3372 expirationTime: NoWork,
3373 firstContext: contextItem,
3374 responders: null
3375 };
3376 } else {
3377 // Append a new context item.
3378 lastContextDependency = lastContextDependency.next = contextItem;
3379 }
3380 }
3381
3382 return isPrimaryRenderer ? context._currentValue : context._currentValue2;
3383}
3384
3385// UpdateQueue is a linked list of prioritized updates.
3386//
3387// Like fibers, update queues come in pairs: a current queue, which represents
3388// the visible state of the screen, and a work-in-progress queue, which can be
3389// mutated and processed asynchronously before it is committed — a form of
3390// double buffering. If a work-in-progress render is discarded before finishing,
3391// we create a new work-in-progress by cloning the current queue.
3392//
3393// Both queues share a persistent, singly-linked list structure. To schedule an
3394// update, we append it to the end of both queues. Each queue maintains a
3395// pointer to first update in the persistent list that hasn't been processed.
3396// The work-in-progress pointer always has a position equal to or greater than
3397// the current queue, since we always work on that one. The current queue's
3398// pointer is only updated during the commit phase, when we swap in the
3399// work-in-progress.
3400//
3401// For example:
3402//
3403// Current pointer: A - B - C - D - E - F
3404// Work-in-progress pointer: D - E - F
3405// ^
3406// The work-in-progress queue has
3407// processed more updates than current.
3408//
3409// The reason we append to both queues is because otherwise we might drop
3410// updates without ever processing them. For example, if we only add updates to
3411// the work-in-progress queue, some updates could be lost whenever a work-in
3412// -progress render restarts by cloning from current. Similarly, if we only add
3413// updates to the current queue, the updates will be lost whenever an already
3414// in-progress queue commits and swaps with the current queue. However, by
3415// adding to both queues, we guarantee that the update will be part of the next
3416// work-in-progress. (And because the work-in-progress queue becomes the
3417// current queue once it commits, there's no danger of applying the same
3418// update twice.)
3419//
3420// Prioritization
3421// --------------
3422//
3423// Updates are not sorted by priority, but by insertion; new updates are always
3424// appended to the end of the list.
3425//
3426// The priority is still important, though. When processing the update queue
3427// during the render phase, only the updates with sufficient priority are
3428// included in the result. If we skip an update because it has insufficient
3429// priority, it remains in the queue to be processed later, during a lower
3430// priority render. Crucially, all updates subsequent to a skipped update also
3431// remain in the queue *regardless of their priority*. That means high priority
3432// updates are sometimes processed twice, at two separate priorities. We also
3433// keep track of a base state, that represents the state before the first
3434// update in the queue is applied.
3435//
3436// For example:
3437//
3438// Given a base state of '', and the following queue of updates
3439//
3440// A1 - B2 - C1 - D2
3441//
3442// where the number indicates the priority, and the update is applied to the
3443// previous state by appending a letter, React will process these updates as
3444// two separate renders, one per distinct priority level:
3445//
3446// First render, at priority 1:
3447// Base state: ''
3448// Updates: [A1, C1]
3449// Result state: 'AC'
3450//
3451// Second render, at priority 2:
3452// Base state: 'A' <- The base state does not include C1,
3453// because B2 was skipped.
3454// Updates: [B2, C1, D2] <- C1 was rebased on top of B2
3455// Result state: 'ABCD'
3456//
3457// Because we process updates in insertion order, and rebase high priority
3458// updates when preceding updates are skipped, the final result is deterministic
3459// regardless of priority. Intermediate state may vary according to system
3460// resources, but the final state is always the same.
3461var UpdateState = 0;
3462var ReplaceState = 1;
3463var ForceUpdate = 2;
3464var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
3465// It should only be read right after calling `processUpdateQueue`, via
3466// `checkHasForceUpdateAfterProcessing`.
3467
3468var hasForceUpdate = false;
3469var didWarnUpdateInsideUpdate;
3470var currentlyProcessingQueue;
3471
3472
3473{
3474 didWarnUpdateInsideUpdate = false;
3475 currentlyProcessingQueue = null;
3476
3477
3478}
3479
3480function createUpdateQueue(baseState) {
3481 var queue = {
3482 baseState: baseState,
3483 firstUpdate: null,
3484 lastUpdate: null,
3485 firstCapturedUpdate: null,
3486 lastCapturedUpdate: null,
3487 firstEffect: null,
3488 lastEffect: null,
3489 firstCapturedEffect: null,
3490 lastCapturedEffect: null
3491 };
3492 return queue;
3493}
3494
3495function cloneUpdateQueue(currentQueue) {
3496 var queue = {
3497 baseState: currentQueue.baseState,
3498 firstUpdate: currentQueue.firstUpdate,
3499 lastUpdate: currentQueue.lastUpdate,
3500 // TODO: With resuming, if we bail out and resuse the child tree, we should
3501 // keep these effects.
3502 firstCapturedUpdate: null,
3503 lastCapturedUpdate: null,
3504 firstEffect: null,
3505 lastEffect: null,
3506 firstCapturedEffect: null,
3507 lastCapturedEffect: null
3508 };
3509 return queue;
3510}
3511
3512function createUpdate(expirationTime, suspenseConfig) {
3513 var update = {
3514 expirationTime: expirationTime,
3515 suspenseConfig: suspenseConfig,
3516 tag: UpdateState,
3517 payload: null,
3518 callback: null,
3519 next: null,
3520 nextEffect: null
3521 };
3522
3523 {
3524 update.priority = getCurrentPriorityLevel();
3525 }
3526
3527 return update;
3528}
3529
3530function appendUpdateToQueue(queue, update) {
3531 // Append the update to the end of the list.
3532 if (queue.lastUpdate === null) {
3533 // Queue is empty
3534 queue.firstUpdate = queue.lastUpdate = update;
3535 } else {
3536 queue.lastUpdate.next = update;
3537 queue.lastUpdate = update;
3538 }
3539}
3540
3541function enqueueUpdate(fiber, update) {
3542 // Update queues are created lazily.
3543 var alternate = fiber.alternate;
3544 var queue1;
3545 var queue2;
3546
3547 if (alternate === null) {
3548 // There's only one fiber.
3549 queue1 = fiber.updateQueue;
3550 queue2 = null;
3551
3552 if (queue1 === null) {
3553 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
3554 }
3555 } else {
3556 // There are two owners.
3557 queue1 = fiber.updateQueue;
3558 queue2 = alternate.updateQueue;
3559
3560 if (queue1 === null) {
3561 if (queue2 === null) {
3562 // Neither fiber has an update queue. Create new ones.
3563 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
3564 queue2 = alternate.updateQueue = createUpdateQueue(alternate.memoizedState);
3565 } else {
3566 // Only one fiber has an update queue. Clone to create a new one.
3567 queue1 = fiber.updateQueue = cloneUpdateQueue(queue2);
3568 }
3569 } else {
3570 if (queue2 === null) {
3571 // Only one fiber has an update queue. Clone to create a new one.
3572 queue2 = alternate.updateQueue = cloneUpdateQueue(queue1);
3573 } else {// Both owners have an update queue.
3574 }
3575 }
3576 }
3577
3578 if (queue2 === null || queue1 === queue2) {
3579 // There's only a single queue.
3580 appendUpdateToQueue(queue1, update);
3581 } else {
3582 // There are two queues. We need to append the update to both queues,
3583 // while accounting for the persistent structure of the list — we don't
3584 // want the same update to be added multiple times.
3585 if (queue1.lastUpdate === null || queue2.lastUpdate === null) {
3586 // One of the queues is not empty. We must add the update to both queues.
3587 appendUpdateToQueue(queue1, update);
3588 appendUpdateToQueue(queue2, update);
3589 } else {
3590 // Both queues are non-empty. The last update is the same in both lists,
3591 // because of structural sharing. So, only append to one of the lists.
3592 appendUpdateToQueue(queue1, update); // But we still need to update the `lastUpdate` pointer of queue2.
3593
3594 queue2.lastUpdate = update;
3595 }
3596 }
3597
3598 {
3599 if (fiber.tag === ClassComponent && (currentlyProcessingQueue === queue1 || queue2 !== null && currentlyProcessingQueue === queue2) && !didWarnUpdateInsideUpdate) {
3600 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.');
3601 didWarnUpdateInsideUpdate = true;
3602 }
3603 }
3604}
3605function enqueueCapturedUpdate(workInProgress, update) {
3606 // Captured updates go into a separate list, and only on the work-in-
3607 // progress queue.
3608 var workInProgressQueue = workInProgress.updateQueue;
3609
3610 if (workInProgressQueue === null) {
3611 workInProgressQueue = workInProgress.updateQueue = createUpdateQueue(workInProgress.memoizedState);
3612 } else {
3613 // TODO: I put this here rather than createWorkInProgress so that we don't
3614 // clone the queue unnecessarily. There's probably a better way to
3615 // structure this.
3616 workInProgressQueue = ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue);
3617 } // Append the update to the end of the list.
3618
3619
3620 if (workInProgressQueue.lastCapturedUpdate === null) {
3621 // This is the first render phase update
3622 workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update;
3623 } else {
3624 workInProgressQueue.lastCapturedUpdate.next = update;
3625 workInProgressQueue.lastCapturedUpdate = update;
3626 }
3627}
3628
3629function ensureWorkInProgressQueueIsAClone(workInProgress, queue) {
3630 var current = workInProgress.alternate;
3631
3632 if (current !== null) {
3633 // If the work-in-progress queue is equal to the current queue,
3634 // we need to clone it first.
3635 if (queue === current.updateQueue) {
3636 queue = workInProgress.updateQueue = cloneUpdateQueue(queue);
3637 }
3638 }
3639
3640 return queue;
3641}
3642
3643function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
3644 switch (update.tag) {
3645 case ReplaceState:
3646 {
3647 var payload = update.payload;
3648
3649 if (typeof payload === 'function') {
3650 // Updater function
3651 {
3652 enterDisallowedContextReadInDEV();
3653
3654 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3655 payload.call(instance, prevState, nextProps);
3656 }
3657 }
3658
3659 var nextState = payload.call(instance, prevState, nextProps);
3660
3661 {
3662 exitDisallowedContextReadInDEV();
3663 }
3664
3665 return nextState;
3666 } // State object
3667
3668
3669 return payload;
3670 }
3671
3672 case CaptureUpdate:
3673 {
3674 workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
3675 }
3676 // Intentional fallthrough
3677
3678 case UpdateState:
3679 {
3680 var _payload = update.payload;
3681 var partialState;
3682
3683 if (typeof _payload === 'function') {
3684 // Updater function
3685 {
3686 enterDisallowedContextReadInDEV();
3687
3688 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3689 _payload.call(instance, prevState, nextProps);
3690 }
3691 }
3692
3693 partialState = _payload.call(instance, prevState, nextProps);
3694
3695 {
3696 exitDisallowedContextReadInDEV();
3697 }
3698 } else {
3699 // Partial state object
3700 partialState = _payload;
3701 }
3702
3703 if (partialState === null || partialState === undefined) {
3704 // Null and undefined are treated as no-ops.
3705 return prevState;
3706 } // Merge the partial state and the previous state.
3707
3708
3709 return _assign({}, prevState, partialState);
3710 }
3711
3712 case ForceUpdate:
3713 {
3714 hasForceUpdate = true;
3715 return prevState;
3716 }
3717 }
3718
3719 return prevState;
3720}
3721
3722function processUpdateQueue(workInProgress, queue, props, instance, renderExpirationTime) {
3723 hasForceUpdate = false;
3724 queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue);
3725
3726 {
3727 currentlyProcessingQueue = queue;
3728 } // These values may change as we process the queue.
3729
3730
3731 var newBaseState = queue.baseState;
3732 var newFirstUpdate = null;
3733 var newExpirationTime = NoWork; // Iterate through the list of updates to compute the result.
3734
3735 var update = queue.firstUpdate;
3736 var resultState = newBaseState;
3737
3738 while (update !== null) {
3739 var updateExpirationTime = update.expirationTime;
3740
3741 if (updateExpirationTime < renderExpirationTime) {
3742 // This update does not have sufficient priority. Skip it.
3743 if (newFirstUpdate === null) {
3744 // This is the first skipped update. It will be the first update in
3745 // the new list.
3746 newFirstUpdate = update; // Since this is the first update that was skipped, the current result
3747 // is the new base state.
3748
3749 newBaseState = resultState;
3750 } // Since this update will remain in the list, update the remaining
3751 // expiration time.
3752
3753
3754 if (newExpirationTime < updateExpirationTime) {
3755 newExpirationTime = updateExpirationTime;
3756 }
3757 } else {
3758 // This update does have sufficient priority.
3759 // Mark the event time of this update as relevant to this render pass.
3760 // TODO: This should ideally use the true event time of this update rather than
3761 // its priority which is a derived and not reverseable value.
3762 // TODO: We should skip this update if it was already committed but currently
3763 // we have no way of detecting the difference between a committed and suspended
3764 // update here.
3765 markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process it and compute a new result.
3766
3767 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
3768 var callback = update.callback;
3769
3770 if (callback !== null) {
3771 workInProgress.effectTag |= Callback; // Set this to null, in case it was mutated during an aborted render.
3772
3773 update.nextEffect = null;
3774
3775 if (queue.lastEffect === null) {
3776 queue.firstEffect = queue.lastEffect = update;
3777 } else {
3778 queue.lastEffect.nextEffect = update;
3779 queue.lastEffect = update;
3780 }
3781 }
3782 } // Continue to the next update.
3783
3784
3785 update = update.next;
3786 } // Separately, iterate though the list of captured updates.
3787
3788
3789 var newFirstCapturedUpdate = null;
3790 update = queue.firstCapturedUpdate;
3791
3792 while (update !== null) {
3793 var _updateExpirationTime = update.expirationTime;
3794
3795 if (_updateExpirationTime < renderExpirationTime) {
3796 // This update does not have sufficient priority. Skip it.
3797 if (newFirstCapturedUpdate === null) {
3798 // This is the first skipped captured update. It will be the first
3799 // update in the new list.
3800 newFirstCapturedUpdate = update; // If this is the first update that was skipped, the current result is
3801 // the new base state.
3802
3803 if (newFirstUpdate === null) {
3804 newBaseState = resultState;
3805 }
3806 } // Since this update will remain in the list, update the remaining
3807 // expiration time.
3808
3809
3810 if (newExpirationTime < _updateExpirationTime) {
3811 newExpirationTime = _updateExpirationTime;
3812 }
3813 } else {
3814 // This update does have sufficient priority. Process it and compute
3815 // a new result.
3816 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
3817 var _callback = update.callback;
3818
3819 if (_callback !== null) {
3820 workInProgress.effectTag |= Callback; // Set this to null, in case it was mutated during an aborted render.
3821
3822 update.nextEffect = null;
3823
3824 if (queue.lastCapturedEffect === null) {
3825 queue.firstCapturedEffect = queue.lastCapturedEffect = update;
3826 } else {
3827 queue.lastCapturedEffect.nextEffect = update;
3828 queue.lastCapturedEffect = update;
3829 }
3830 }
3831 }
3832
3833 update = update.next;
3834 }
3835
3836 if (newFirstUpdate === null) {
3837 queue.lastUpdate = null;
3838 }
3839
3840 if (newFirstCapturedUpdate === null) {
3841 queue.lastCapturedUpdate = null;
3842 } else {
3843 workInProgress.effectTag |= Callback;
3844 }
3845
3846 if (newFirstUpdate === null && newFirstCapturedUpdate === null) {
3847 // We processed every update, without skipping. That means the new base
3848 // state is the same as the result state.
3849 newBaseState = resultState;
3850 }
3851
3852 queue.baseState = newBaseState;
3853 queue.firstUpdate = newFirstUpdate;
3854 queue.firstCapturedUpdate = newFirstCapturedUpdate; // Set the remaining expiration time to be whatever is remaining in the queue.
3855 // This should be fine because the only two other things that contribute to
3856 // expiration time are props and context. We're already in the middle of the
3857 // begin phase by the time we start processing the queue, so we've already
3858 // dealt with the props. Context in components that specify
3859 // shouldComponentUpdate is tricky; but we'll have to account for
3860 // that regardless.
3861
3862 markUnprocessedUpdateTime(newExpirationTime);
3863 workInProgress.expirationTime = newExpirationTime;
3864 workInProgress.memoizedState = resultState;
3865
3866 {
3867 currentlyProcessingQueue = null;
3868 }
3869}
3870
3871function callCallback(callback, context) {
3872 (function () {
3873 if (!(typeof callback === 'function')) {
3874 {
3875 throw ReactError(Error("Invalid argument passed as callback. Expected a function. Instead received: " + callback));
3876 }
3877 }
3878 })();
3879
3880 callback.call(context);
3881}
3882
3883function resetHasForceUpdateBeforeProcessing() {
3884 hasForceUpdate = false;
3885}
3886function checkHasForceUpdateAfterProcessing() {
3887 return hasForceUpdate;
3888}
3889function commitUpdateQueue(finishedWork, finishedQueue, instance, renderExpirationTime) {
3890 // If the finished render included captured updates, and there are still
3891 // lower priority updates left over, we need to keep the captured updates
3892 // in the queue so that they are rebased and not dropped once we process the
3893 // queue again at the lower priority.
3894 if (finishedQueue.firstCapturedUpdate !== null) {
3895 // Join the captured update list to the end of the normal list.
3896 if (finishedQueue.lastUpdate !== null) {
3897 finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate;
3898 finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate;
3899 } // Clear the list of captured updates.
3900
3901
3902 finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null;
3903 } // Commit the effects
3904
3905
3906 commitUpdateEffects(finishedQueue.firstEffect, instance);
3907 finishedQueue.firstEffect = finishedQueue.lastEffect = null;
3908 commitUpdateEffects(finishedQueue.firstCapturedEffect, instance);
3909 finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null;
3910}
3911
3912function commitUpdateEffects(effect, instance) {
3913 while (effect !== null) {
3914 var callback = effect.callback;
3915
3916 if (callback !== null) {
3917 effect.callback = null;
3918 callCallback(callback, instance);
3919 }
3920
3921 effect = effect.nextEffect;
3922 }
3923}
3924
3925var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
3926function requestCurrentSuspenseConfig() {
3927 return ReactCurrentBatchConfig.suspense;
3928}
3929
3930var fakeInternalInstance = {};
3931var isArray$1 = Array.isArray; // React.Component uses a shared frozen object by default.
3932// We'll use it to determine whether we need to initialize legacy refs.
3933
3934var emptyRefsObject = new React.Component().refs;
3935var didWarnAboutStateAssignmentForComponent;
3936var didWarnAboutUninitializedState;
3937var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
3938var didWarnAboutLegacyLifecyclesAndDerivedState;
3939var didWarnAboutUndefinedDerivedState;
3940var warnOnUndefinedDerivedState;
3941var warnOnInvalidCallback;
3942var didWarnAboutDirectlyAssigningPropsToState;
3943var didWarnAboutContextTypeAndContextTypes;
3944var didWarnAboutInvalidateContextType;
3945
3946{
3947 didWarnAboutStateAssignmentForComponent = new Set();
3948 didWarnAboutUninitializedState = new Set();
3949 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
3950 didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
3951 didWarnAboutDirectlyAssigningPropsToState = new Set();
3952 didWarnAboutUndefinedDerivedState = new Set();
3953 didWarnAboutContextTypeAndContextTypes = new Set();
3954 didWarnAboutInvalidateContextType = new Set();
3955 var didWarnOnInvalidCallback = new Set();
3956
3957 warnOnInvalidCallback = function (callback, callerName) {
3958 if (callback === null || typeof callback === 'function') {
3959 return;
3960 }
3961
3962 var key = callerName + "_" + callback;
3963
3964 if (!didWarnOnInvalidCallback.has(key)) {
3965 didWarnOnInvalidCallback.add(key);
3966 warningWithoutStack$1(false, '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
3967 }
3968 };
3969
3970 warnOnUndefinedDerivedState = function (type, partialState) {
3971 if (partialState === undefined) {
3972 var componentName = getComponentName(type) || 'Component';
3973
3974 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
3975 didWarnAboutUndefinedDerivedState.add(componentName);
3976 warningWithoutStack$1(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
3977 }
3978 }
3979 }; // This is so gross but it's at least non-critical and can be removed if
3980 // it causes problems. This is meant to give a nicer error message for
3981 // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
3982 // ...)) which otherwise throws a "_processChildContext is not a function"
3983 // exception.
3984
3985
3986 Object.defineProperty(fakeInternalInstance, '_processChildContext', {
3987 enumerable: false,
3988 value: function () {
3989 (function () {
3990 {
3991 {
3992 throw ReactError(Error("_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)."));
3993 }
3994 }
3995 })();
3996 }
3997 });
3998 Object.freeze(fakeInternalInstance);
3999}
4000
4001function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
4002 var prevState = workInProgress.memoizedState;
4003
4004 {
4005 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
4006 // Invoke the function an extra time to help detect side-effects.
4007 getDerivedStateFromProps(nextProps, prevState);
4008 }
4009 }
4010
4011 var partialState = getDerivedStateFromProps(nextProps, prevState);
4012
4013 {
4014 warnOnUndefinedDerivedState(ctor, partialState);
4015 } // Merge the partial state and the previous state.
4016
4017
4018 var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
4019 workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
4020 // base state.
4021
4022 var updateQueue = workInProgress.updateQueue;
4023
4024 if (updateQueue !== null && workInProgress.expirationTime === NoWork) {
4025 updateQueue.baseState = memoizedState;
4026 }
4027}
4028var classComponentUpdater = {
4029 isMounted: isMounted,
4030 enqueueSetState: function (inst, payload, callback) {
4031 var fiber = get(inst);
4032 var currentTime = requestCurrentTime();
4033 var suspenseConfig = requestCurrentSuspenseConfig();
4034 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4035 var update = createUpdate(expirationTime, suspenseConfig);
4036 update.payload = payload;
4037
4038 if (callback !== undefined && callback !== null) {
4039 {
4040 warnOnInvalidCallback(callback, 'setState');
4041 }
4042
4043 update.callback = callback;
4044 }
4045
4046 enqueueUpdate(fiber, update);
4047 scheduleWork(fiber, expirationTime);
4048 },
4049 enqueueReplaceState: function (inst, payload, callback) {
4050 var fiber = get(inst);
4051 var currentTime = requestCurrentTime();
4052 var suspenseConfig = requestCurrentSuspenseConfig();
4053 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4054 var update = createUpdate(expirationTime, suspenseConfig);
4055 update.tag = ReplaceState;
4056 update.payload = payload;
4057
4058 if (callback !== undefined && callback !== null) {
4059 {
4060 warnOnInvalidCallback(callback, 'replaceState');
4061 }
4062
4063 update.callback = callback;
4064 }
4065
4066 enqueueUpdate(fiber, update);
4067 scheduleWork(fiber, expirationTime);
4068 },
4069 enqueueForceUpdate: function (inst, callback) {
4070 var fiber = get(inst);
4071 var currentTime = requestCurrentTime();
4072 var suspenseConfig = requestCurrentSuspenseConfig();
4073 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4074 var update = createUpdate(expirationTime, suspenseConfig);
4075 update.tag = ForceUpdate;
4076
4077 if (callback !== undefined && callback !== null) {
4078 {
4079 warnOnInvalidCallback(callback, 'forceUpdate');
4080 }
4081
4082 update.callback = callback;
4083 }
4084
4085 enqueueUpdate(fiber, update);
4086 scheduleWork(fiber, expirationTime);
4087 }
4088};
4089
4090function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
4091 var instance = workInProgress.stateNode;
4092
4093 if (typeof instance.shouldComponentUpdate === 'function') {
4094 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
4095 var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
4096 stopPhaseTimer();
4097
4098 {
4099 !(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;
4100 }
4101
4102 return shouldUpdate;
4103 }
4104
4105 if (ctor.prototype && ctor.prototype.isPureReactComponent) {
4106 return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
4107 }
4108
4109 return true;
4110}
4111
4112function checkClassInstance(workInProgress, ctor, newProps) {
4113 var instance = workInProgress.stateNode;
4114
4115 {
4116 var name = getComponentName(ctor) || 'Component';
4117 var renderPresent = instance.render;
4118
4119 if (!renderPresent) {
4120 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
4121 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
4122 } else {
4123 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
4124 }
4125 }
4126
4127 var noGetInitialStateOnES6 = !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state;
4128 !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;
4129 var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved;
4130 !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;
4131 var noInstancePropTypes = !instance.propTypes;
4132 !noInstancePropTypes ? warningWithoutStack$1(false, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name) : void 0;
4133 var noInstanceContextType = !instance.contextType;
4134 !noInstanceContextType ? warningWithoutStack$1(false, 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name) : void 0;
4135
4136 if (disableLegacyContext) {
4137 if (ctor.childContextTypes) {
4138 warningWithoutStack$1(false, '%s uses the legacy childContextTypes API which is no longer supported. ' + 'Use React.createContext() instead.', name);
4139 }
4140
4141 if (ctor.contextTypes) {
4142 warningWithoutStack$1(false, '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with static contextType instead.', name);
4143 }
4144 } else {
4145 var noInstanceContextTypes = !instance.contextTypes;
4146 !noInstanceContextTypes ? warningWithoutStack$1(false, 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name) : void 0;
4147
4148 if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
4149 didWarnAboutContextTypeAndContextTypes.add(ctor);
4150 warningWithoutStack$1(false, '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
4151 }
4152 }
4153
4154 var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== 'function';
4155 !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;
4156
4157 if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
4158 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');
4159 }
4160
4161 var noComponentDidUnmount = typeof instance.componentDidUnmount !== 'function';
4162 !noComponentDidUnmount ? warningWithoutStack$1(false, '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name) : void 0;
4163 var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== 'function';
4164 !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;
4165 var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== 'function';
4166 !noComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name) : void 0;
4167 var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
4168 !noUnsafeComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name) : void 0;
4169 var hasMutatedProps = instance.props !== newProps;
4170 !(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;
4171 var noInstanceDefaultProps = !instance.defaultProps;
4172 !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;
4173
4174 if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
4175 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
4176 warningWithoutStack$1(false, '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
4177 }
4178
4179 var noInstanceGetDerivedStateFromProps = typeof instance.getDerivedStateFromProps !== 'function';
4180 !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;
4181 var noInstanceGetDerivedStateFromCatch = typeof instance.getDerivedStateFromError !== 'function';
4182 !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;
4183 var noStaticGetSnapshotBeforeUpdate = typeof ctor.getSnapshotBeforeUpdate !== 'function';
4184 !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;
4185 var _state = instance.state;
4186
4187 if (_state && (typeof _state !== 'object' || isArray$1(_state))) {
4188 warningWithoutStack$1(false, '%s.state: must be set to an object or null', name);
4189 }
4190
4191 if (typeof instance.getChildContext === 'function') {
4192 !(typeof ctor.childContextTypes === 'object') ? warningWithoutStack$1(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name) : void 0;
4193 }
4194 }
4195}
4196
4197function adoptClassInstance(workInProgress, instance) {
4198 instance.updater = classComponentUpdater;
4199 workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
4200
4201 set$1(instance, workInProgress);
4202
4203 {
4204 instance._reactInternalInstance = fakeInternalInstance;
4205 }
4206}
4207
4208function constructClassInstance(workInProgress, ctor, props, renderExpirationTime) {
4209 var isLegacyContextConsumer = false;
4210 var unmaskedContext = emptyContextObject;
4211 var context = emptyContextObject;
4212 var contextType = ctor.contextType;
4213
4214 {
4215 if ('contextType' in ctor) {
4216 var isValid = // Allow null for conditional declaration
4217 contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
4218
4219 if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
4220 didWarnAboutInvalidateContextType.add(ctor);
4221 var addendum = '';
4222
4223 if (contextType === undefined) {
4224 addendum = ' However, it is set to undefined. ' + 'This can be caused by a typo or by mixing up named and default imports. ' + 'This can also happen due to a circular dependency, so ' + 'try moving the createContext() call to a separate file.';
4225 } else if (typeof contextType !== 'object') {
4226 addendum = ' However, it is set to a ' + typeof contextType + '.';
4227 } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
4228 addendum = ' Did you accidentally pass the Context.Provider instead?';
4229 } else if (contextType._context !== undefined) {
4230 // <Context.Consumer>
4231 addendum = ' Did you accidentally pass the Context.Consumer instead?';
4232 } else {
4233 addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
4234 }
4235
4236 warningWithoutStack$1(false, '%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum);
4237 }
4238 }
4239 }
4240
4241 if (typeof contextType === 'object' && contextType !== null) {
4242 context = readContext(contextType);
4243 } else if (!disableLegacyContext) {
4244 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4245 var contextTypes = ctor.contextTypes;
4246 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
4247 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
4248 } // Instantiate twice to help detect side-effects.
4249
4250
4251 {
4252 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
4253 new ctor(props, context); // eslint-disable-line no-new
4254 }
4255 }
4256
4257 var instance = new ctor(props, context);
4258 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
4259 adoptClassInstance(workInProgress, instance);
4260
4261 {
4262 if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
4263 var componentName = getComponentName(ctor) || 'Component';
4264
4265 if (!didWarnAboutUninitializedState.has(componentName)) {
4266 didWarnAboutUninitializedState.add(componentName);
4267 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);
4268 }
4269 } // If new component APIs are defined, "unsafe" lifecycles won't be called.
4270 // Warn about these lifecycles if they are present.
4271 // Don't warn about react-lifecycles-compat polyfilled methods though.
4272
4273
4274 if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
4275 var foundWillMountName = null;
4276 var foundWillReceivePropsName = null;
4277 var foundWillUpdateName = null;
4278
4279 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
4280 foundWillMountName = 'componentWillMount';
4281 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
4282 foundWillMountName = 'UNSAFE_componentWillMount';
4283 }
4284
4285 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
4286 foundWillReceivePropsName = 'componentWillReceiveProps';
4287 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
4288 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
4289 }
4290
4291 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
4292 foundWillUpdateName = 'componentWillUpdate';
4293 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
4294 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
4295 }
4296
4297 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
4298 var _componentName = getComponentName(ctor) || 'Component';
4299
4300 var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
4301
4302 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
4303 didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
4304 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-unsafe-component-lifecycles', _componentName, newApiName, foundWillMountName !== null ? "\n " + foundWillMountName : '', foundWillReceivePropsName !== null ? "\n " + foundWillReceivePropsName : '', foundWillUpdateName !== null ? "\n " + foundWillUpdateName : '');
4305 }
4306 }
4307 }
4308 } // Cache unmasked context so we can avoid recreating masked context unless necessary.
4309 // ReactFiberContext usually updates this cache but can't for newly-created instances.
4310
4311
4312 if (isLegacyContextConsumer) {
4313 cacheContext(workInProgress, unmaskedContext, context);
4314 }
4315
4316 return instance;
4317}
4318
4319function callComponentWillMount(workInProgress, instance) {
4320 startPhaseTimer(workInProgress, 'componentWillMount');
4321 var oldState = instance.state;
4322
4323 if (typeof instance.componentWillMount === 'function') {
4324 instance.componentWillMount();
4325 }
4326
4327 if (typeof instance.UNSAFE_componentWillMount === 'function') {
4328 instance.UNSAFE_componentWillMount();
4329 }
4330
4331 stopPhaseTimer();
4332
4333 if (oldState !== instance.state) {
4334 {
4335 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');
4336 }
4337
4338 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
4339 }
4340}
4341
4342function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
4343 var oldState = instance.state;
4344 startPhaseTimer(workInProgress, 'componentWillReceiveProps');
4345
4346 if (typeof instance.componentWillReceiveProps === 'function') {
4347 instance.componentWillReceiveProps(newProps, nextContext);
4348 }
4349
4350 if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
4351 instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
4352 }
4353
4354 stopPhaseTimer();
4355
4356 if (instance.state !== oldState) {
4357 {
4358 var componentName = getComponentName(workInProgress.type) || 'Component';
4359
4360 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
4361 didWarnAboutStateAssignmentForComponent.add(componentName);
4362 warningWithoutStack$1(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
4363 }
4364 }
4365
4366 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
4367 }
4368} // Invokes the mount life-cycles on a previously never rendered instance.
4369
4370
4371function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
4372 {
4373 checkClassInstance(workInProgress, ctor, newProps);
4374 }
4375
4376 var instance = workInProgress.stateNode;
4377 instance.props = newProps;
4378 instance.state = workInProgress.memoizedState;
4379 instance.refs = emptyRefsObject;
4380 var contextType = ctor.contextType;
4381
4382 if (typeof contextType === 'object' && contextType !== null) {
4383 instance.context = readContext(contextType);
4384 } else if (disableLegacyContext) {
4385 instance.context = emptyContextObject;
4386 } else {
4387 var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4388 instance.context = getMaskedContext(workInProgress, unmaskedContext);
4389 }
4390
4391 {
4392 if (instance.state === newProps) {
4393 var componentName = getComponentName(ctor) || 'Component';
4394
4395 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
4396 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
4397 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);
4398 }
4399 }
4400
4401 if (workInProgress.mode & StrictMode) {
4402 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
4403 }
4404
4405 if (warnAboutDeprecatedLifecycles) {
4406 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
4407 }
4408 }
4409
4410 var updateQueue = workInProgress.updateQueue;
4411
4412 if (updateQueue !== null) {
4413 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4414 instance.state = workInProgress.memoizedState;
4415 }
4416
4417 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4418
4419 if (typeof getDerivedStateFromProps === 'function') {
4420 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4421 instance.state = workInProgress.memoizedState;
4422 } // In order to support react-lifecycles-compat polyfilled components,
4423 // Unsafe lifecycles should not be invoked for components using the new APIs.
4424
4425
4426 if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
4427 callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
4428 // process them now.
4429
4430 updateQueue = workInProgress.updateQueue;
4431
4432 if (updateQueue !== null) {
4433 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4434 instance.state = workInProgress.memoizedState;
4435 }
4436 }
4437
4438 if (typeof instance.componentDidMount === 'function') {
4439 workInProgress.effectTag |= Update;
4440 }
4441}
4442
4443function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
4444 var instance = workInProgress.stateNode;
4445 var oldProps = workInProgress.memoizedProps;
4446 instance.props = oldProps;
4447 var oldContext = instance.context;
4448 var contextType = ctor.contextType;
4449 var nextContext = emptyContextObject;
4450
4451 if (typeof contextType === 'object' && contextType !== null) {
4452 nextContext = readContext(contextType);
4453 } else if (!disableLegacyContext) {
4454 var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4455 nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
4456 }
4457
4458 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4459 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
4460 // ever the previously attempted to render - not the "current". However,
4461 // during componentDidUpdate we pass the "current" props.
4462 // In order to support react-lifecycles-compat polyfilled components,
4463 // Unsafe lifecycles should not be invoked for components using the new APIs.
4464
4465 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
4466 if (oldProps !== newProps || oldContext !== nextContext) {
4467 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
4468 }
4469 }
4470
4471 resetHasForceUpdateBeforeProcessing();
4472 var oldState = workInProgress.memoizedState;
4473 var newState = instance.state = oldState;
4474 var updateQueue = workInProgress.updateQueue;
4475
4476 if (updateQueue !== null) {
4477 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4478 newState = workInProgress.memoizedState;
4479 }
4480
4481 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
4482 // If an update was already in progress, we should schedule an Update
4483 // effect even though we're bailing out, so that cWU/cDU are called.
4484 if (typeof instance.componentDidMount === 'function') {
4485 workInProgress.effectTag |= Update;
4486 }
4487
4488 return false;
4489 }
4490
4491 if (typeof getDerivedStateFromProps === 'function') {
4492 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4493 newState = workInProgress.memoizedState;
4494 }
4495
4496 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
4497
4498 if (shouldUpdate) {
4499 // In order to support react-lifecycles-compat polyfilled components,
4500 // Unsafe lifecycles should not be invoked for components using the new APIs.
4501 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
4502 startPhaseTimer(workInProgress, 'componentWillMount');
4503
4504 if (typeof instance.componentWillMount === 'function') {
4505 instance.componentWillMount();
4506 }
4507
4508 if (typeof instance.UNSAFE_componentWillMount === 'function') {
4509 instance.UNSAFE_componentWillMount();
4510 }
4511
4512 stopPhaseTimer();
4513 }
4514
4515 if (typeof instance.componentDidMount === 'function') {
4516 workInProgress.effectTag |= Update;
4517 }
4518 } else {
4519 // If an update was already in progress, we should schedule an Update
4520 // effect even though we're bailing out, so that cWU/cDU are called.
4521 if (typeof instance.componentDidMount === 'function') {
4522 workInProgress.effectTag |= Update;
4523 } // If shouldComponentUpdate returned false, we should still update the
4524 // memoized state to indicate that this work can be reused.
4525
4526
4527 workInProgress.memoizedProps = newProps;
4528 workInProgress.memoizedState = newState;
4529 } // Update the existing instance's state, props, and context pointers even
4530 // if shouldComponentUpdate returns false.
4531
4532
4533 instance.props = newProps;
4534 instance.state = newState;
4535 instance.context = nextContext;
4536 return shouldUpdate;
4537} // Invokes the update life-cycles and returns false if it shouldn't rerender.
4538
4539
4540function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
4541 var instance = workInProgress.stateNode;
4542 var oldProps = workInProgress.memoizedProps;
4543 instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
4544 var oldContext = instance.context;
4545 var contextType = ctor.contextType;
4546 var nextContext = emptyContextObject;
4547
4548 if (typeof contextType === 'object' && contextType !== null) {
4549 nextContext = readContext(contextType);
4550 } else if (!disableLegacyContext) {
4551 var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4552 nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
4553 }
4554
4555 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4556 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
4557 // ever the previously attempted to render - not the "current". However,
4558 // during componentDidUpdate we pass the "current" props.
4559 // In order to support react-lifecycles-compat polyfilled components,
4560 // Unsafe lifecycles should not be invoked for components using the new APIs.
4561
4562 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
4563 if (oldProps !== newProps || oldContext !== nextContext) {
4564 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
4565 }
4566 }
4567
4568 resetHasForceUpdateBeforeProcessing();
4569 var oldState = workInProgress.memoizedState;
4570 var newState = instance.state = oldState;
4571 var updateQueue = workInProgress.updateQueue;
4572
4573 if (updateQueue !== null) {
4574 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4575 newState = workInProgress.memoizedState;
4576 }
4577
4578 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
4579 // If an update was already in progress, we should schedule an Update
4580 // effect even though we're bailing out, so that cWU/cDU are called.
4581 if (typeof instance.componentDidUpdate === 'function') {
4582 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4583 workInProgress.effectTag |= Update;
4584 }
4585 }
4586
4587 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4588 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4589 workInProgress.effectTag |= Snapshot;
4590 }
4591 }
4592
4593 return false;
4594 }
4595
4596 if (typeof getDerivedStateFromProps === 'function') {
4597 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4598 newState = workInProgress.memoizedState;
4599 }
4600
4601 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
4602
4603 if (shouldUpdate) {
4604 // In order to support react-lifecycles-compat polyfilled components,
4605 // Unsafe lifecycles should not be invoked for components using the new APIs.
4606 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
4607 startPhaseTimer(workInProgress, 'componentWillUpdate');
4608
4609 if (typeof instance.componentWillUpdate === 'function') {
4610 instance.componentWillUpdate(newProps, newState, nextContext);
4611 }
4612
4613 if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
4614 instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
4615 }
4616
4617 stopPhaseTimer();
4618 }
4619
4620 if (typeof instance.componentDidUpdate === 'function') {
4621 workInProgress.effectTag |= Update;
4622 }
4623
4624 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4625 workInProgress.effectTag |= Snapshot;
4626 }
4627 } else {
4628 // If an update was already in progress, we should schedule an Update
4629 // effect even though we're bailing out, so that cWU/cDU are called.
4630 if (typeof instance.componentDidUpdate === 'function') {
4631 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4632 workInProgress.effectTag |= Update;
4633 }
4634 }
4635
4636 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4637 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4638 workInProgress.effectTag |= Snapshot;
4639 }
4640 } // If shouldComponentUpdate returned false, we should still update the
4641 // memoized props/state to indicate that this work can be reused.
4642
4643
4644 workInProgress.memoizedProps = newProps;
4645 workInProgress.memoizedState = newState;
4646 } // Update the existing instance's state, props, and context pointers even
4647 // if shouldComponentUpdate returns false.
4648
4649
4650 instance.props = newProps;
4651 instance.state = newState;
4652 instance.context = nextContext;
4653 return shouldUpdate;
4654}
4655
4656var didWarnAboutMaps;
4657var didWarnAboutGenerators;
4658var didWarnAboutStringRefs;
4659var ownerHasKeyUseWarning;
4660var ownerHasFunctionTypeWarning;
4661
4662var warnForMissingKey = function (child) {};
4663
4664{
4665 didWarnAboutMaps = false;
4666 didWarnAboutGenerators = false;
4667 didWarnAboutStringRefs = {};
4668 /**
4669 * Warn if there's no key explicitly set on dynamic arrays of children or
4670 * object keys are not valid. This allows us to keep track of children between
4671 * updates.
4672 */
4673
4674 ownerHasKeyUseWarning = {};
4675 ownerHasFunctionTypeWarning = {};
4676
4677 warnForMissingKey = function (child) {
4678 if (child === null || typeof child !== 'object') {
4679 return;
4680 }
4681
4682 if (!child._store || child._store.validated || child.key != null) {
4683 return;
4684 }
4685
4686 (function () {
4687 if (!(typeof child._store === 'object')) {
4688 {
4689 throw ReactError(Error("React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue."));
4690 }
4691 }
4692 })();
4693
4694 child._store.validated = true;
4695 var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
4696
4697 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
4698 return;
4699 }
4700
4701 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
4702 warning$1(false, 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
4703 };
4704}
4705
4706var isArray = Array.isArray;
4707
4708function coerceRef(returnFiber, current$$1, element) {
4709 var mixedRef = element.ref;
4710
4711 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
4712 {
4713 // TODO: Clean this up once we turn on the string ref warning for
4714 // everyone, because the strict mode case will no longer be relevant
4715 if (returnFiber.mode & StrictMode || warnAboutStringRefs) {
4716 var componentName = getComponentName(returnFiber.type) || 'Component';
4717
4718 if (!didWarnAboutStringRefs[componentName]) {
4719 if (warnAboutStringRefs) {
4720 warningWithoutStack$1(false, 'Component "%s" contains the string ref "%s". Support for string refs ' + 'will be removed in a future major release. We recommend using ' + 'useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://fb.me/react-strict-mode-string-ref%s', componentName, mixedRef, getStackByFiberInDevAndProd(returnFiber));
4721 } else {
4722 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 useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://fb.me/react-strict-mode-string-ref%s', mixedRef, getStackByFiberInDevAndProd(returnFiber));
4723 }
4724
4725 didWarnAboutStringRefs[componentName] = true;
4726 }
4727 }
4728 }
4729
4730 if (element._owner) {
4731 var owner = element._owner;
4732 var inst;
4733
4734 if (owner) {
4735 var ownerFiber = owner;
4736
4737 (function () {
4738 if (!(ownerFiber.tag === ClassComponent)) {
4739 {
4740 throw ReactError(Error("Function components cannot have refs. Did you mean to use React.forwardRef()?"));
4741 }
4742 }
4743 })();
4744
4745 inst = ownerFiber.stateNode;
4746 }
4747
4748 (function () {
4749 if (!inst) {
4750 {
4751 throw ReactError(Error("Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue."));
4752 }
4753 }
4754 })();
4755
4756 var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
4757
4758 if (current$$1 !== null && current$$1.ref !== null && typeof current$$1.ref === 'function' && current$$1.ref._stringRef === stringRef) {
4759 return current$$1.ref;
4760 }
4761
4762 var ref = function (value) {
4763 var refs = inst.refs;
4764
4765 if (refs === emptyRefsObject) {
4766 // This is a lazy pooled frozen object, so we need to initialize.
4767 refs = inst.refs = {};
4768 }
4769
4770 if (value === null) {
4771 delete refs[stringRef];
4772 } else {
4773 refs[stringRef] = value;
4774 }
4775 };
4776
4777 ref._stringRef = stringRef;
4778 return ref;
4779 } else {
4780 (function () {
4781 if (!(typeof mixedRef === 'string')) {
4782 {
4783 throw ReactError(Error("Expected ref to be a function, a string, an object returned by React.createRef(), or null."));
4784 }
4785 }
4786 })();
4787
4788 (function () {
4789 if (!element._owner) {
4790 {
4791 throw ReactError(Error("Element ref was specified as a string (" + mixedRef + ") but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a function component\n2. You may be adding a ref to a component that was not created inside a component's render method\n3. You have multiple copies of React loaded\nSee https://fb.me/react-refs-must-have-owner for more information."));
4792 }
4793 }
4794 })();
4795 }
4796 }
4797
4798 return mixedRef;
4799}
4800
4801function throwOnInvalidObjectType(returnFiber, newChild) {
4802 if (returnFiber.type !== 'textarea') {
4803 var addendum = '';
4804
4805 {
4806 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
4807 }
4808
4809 (function () {
4810 {
4811 {
4812 throw ReactError(Error("Objects are not valid as a React child (found: " + (Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild) + ")." + addendum));
4813 }
4814 }
4815 })();
4816 }
4817}
4818
4819function warnOnFunctionType() {
4820 var currentComponentErrorInfo = 'Functions are not valid as a React child. This may happen if ' + 'you return a Component instead of <Component /> from render. ' + 'Or maybe you meant to call this function rather than return it.' + getCurrentFiberStackInDev();
4821
4822 if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
4823 return;
4824 }
4825
4826 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
4827 warning$1(false, 'Functions are not valid as a React child. This may happen if ' + 'you return a Component instead of <Component /> from render. ' + 'Or maybe you meant to call this function rather than return it.');
4828} // This wrapper function exists because I expect to clone the code in each path
4829// to be able to optimize each path individually by branching early. This needs
4830// a compiler or we can do it manually. Helpers that don't need this branching
4831// live outside of this function.
4832
4833
4834function ChildReconciler(shouldTrackSideEffects) {
4835 function deleteChild(returnFiber, childToDelete) {
4836 if (!shouldTrackSideEffects) {
4837 // Noop.
4838 return;
4839 } // Deletions are added in reversed order so we add it to the front.
4840 // At this point, the return fiber's effect list is empty except for
4841 // deletions, so we can just append the deletion to the list. The remaining
4842 // effects aren't added until the complete phase. Once we implement
4843 // resuming, this may not be true.
4844
4845
4846 var last = returnFiber.lastEffect;
4847
4848 if (last !== null) {
4849 last.nextEffect = childToDelete;
4850 returnFiber.lastEffect = childToDelete;
4851 } else {
4852 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
4853 }
4854
4855 childToDelete.nextEffect = null;
4856 childToDelete.effectTag = Deletion;
4857 }
4858
4859 function deleteRemainingChildren(returnFiber, currentFirstChild) {
4860 if (!shouldTrackSideEffects) {
4861 // Noop.
4862 return null;
4863 } // TODO: For the shouldClone case, this could be micro-optimized a bit by
4864 // assuming that after the first child we've already added everything.
4865
4866
4867 var childToDelete = currentFirstChild;
4868
4869 while (childToDelete !== null) {
4870 deleteChild(returnFiber, childToDelete);
4871 childToDelete = childToDelete.sibling;
4872 }
4873
4874 return null;
4875 }
4876
4877 function mapRemainingChildren(returnFiber, currentFirstChild) {
4878 // Add the remaining children to a temporary map so that we can find them by
4879 // keys quickly. Implicit (null) keys get added to this set with their index
4880 // instead.
4881 var existingChildren = new Map();
4882 var existingChild = currentFirstChild;
4883
4884 while (existingChild !== null) {
4885 if (existingChild.key !== null) {
4886 existingChildren.set(existingChild.key, existingChild);
4887 } else {
4888 existingChildren.set(existingChild.index, existingChild);
4889 }
4890
4891 existingChild = existingChild.sibling;
4892 }
4893
4894 return existingChildren;
4895 }
4896
4897 function useFiber(fiber, pendingProps, expirationTime) {
4898 // We currently set sibling to null and index to 0 here because it is easy
4899 // to forget to do before returning it. E.g. for the single child case.
4900 var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
4901 clone.index = 0;
4902 clone.sibling = null;
4903 return clone;
4904 }
4905
4906 function placeChild(newFiber, lastPlacedIndex, newIndex) {
4907 newFiber.index = newIndex;
4908
4909 if (!shouldTrackSideEffects) {
4910 // Noop.
4911 return lastPlacedIndex;
4912 }
4913
4914 var current$$1 = newFiber.alternate;
4915
4916 if (current$$1 !== null) {
4917 var oldIndex = current$$1.index;
4918
4919 if (oldIndex < lastPlacedIndex) {
4920 // This is a move.
4921 newFiber.effectTag = Placement;
4922 return lastPlacedIndex;
4923 } else {
4924 // This item can stay in place.
4925 return oldIndex;
4926 }
4927 } else {
4928 // This is an insertion.
4929 newFiber.effectTag = Placement;
4930 return lastPlacedIndex;
4931 }
4932 }
4933
4934 function placeSingleChild(newFiber) {
4935 // This is simpler for the single child case. We only need to do a
4936 // placement for inserting new children.
4937 if (shouldTrackSideEffects && newFiber.alternate === null) {
4938 newFiber.effectTag = Placement;
4939 }
4940
4941 return newFiber;
4942 }
4943
4944 function updateTextNode(returnFiber, current$$1, textContent, expirationTime) {
4945 if (current$$1 === null || current$$1.tag !== HostText) {
4946 // Insert
4947 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4948 created.return = returnFiber;
4949 return created;
4950 } else {
4951 // Update
4952 var existing = useFiber(current$$1, textContent, expirationTime);
4953 existing.return = returnFiber;
4954 return existing;
4955 }
4956 }
4957
4958 function updateElement(returnFiber, current$$1, element, expirationTime) {
4959 if (current$$1 !== null && (current$$1.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
4960 isCompatibleFamilyForHotReloading(current$$1, element)))) {
4961 // Move based on index
4962 var existing = useFiber(current$$1, element.props, expirationTime);
4963 existing.ref = coerceRef(returnFiber, current$$1, element);
4964 existing.return = returnFiber;
4965
4966 {
4967 existing._debugSource = element._source;
4968 existing._debugOwner = element._owner;
4969 }
4970
4971 return existing;
4972 } else {
4973 // Insert
4974 var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
4975 created.ref = coerceRef(returnFiber, current$$1, element);
4976 created.return = returnFiber;
4977 return created;
4978 }
4979 }
4980
4981 function updatePortal(returnFiber, current$$1, portal, expirationTime) {
4982 if (current$$1 === null || current$$1.tag !== HostPortal || current$$1.stateNode.containerInfo !== portal.containerInfo || current$$1.stateNode.implementation !== portal.implementation) {
4983 // Insert
4984 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4985 created.return = returnFiber;
4986 return created;
4987 } else {
4988 // Update
4989 var existing = useFiber(current$$1, portal.children || [], expirationTime);
4990 existing.return = returnFiber;
4991 return existing;
4992 }
4993 }
4994
4995 function updateFragment(returnFiber, current$$1, fragment, expirationTime, key) {
4996 if (current$$1 === null || current$$1.tag !== Fragment) {
4997 // Insert
4998 var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
4999 created.return = returnFiber;
5000 return created;
5001 } else {
5002 // Update
5003 var existing = useFiber(current$$1, fragment, expirationTime);
5004 existing.return = returnFiber;
5005 return existing;
5006 }
5007 }
5008
5009 function createChild(returnFiber, newChild, expirationTime) {
5010 if (typeof newChild === 'string' || typeof newChild === 'number') {
5011 // Text nodes don't have keys. If the previous node is implicitly keyed
5012 // we can continue to replace it without aborting even if it is not a text
5013 // node.
5014 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
5015 created.return = returnFiber;
5016 return created;
5017 }
5018
5019 if (typeof newChild === 'object' && newChild !== null) {
5020 switch (newChild.$$typeof) {
5021 case REACT_ELEMENT_TYPE$1:
5022 {
5023 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
5024
5025 _created.ref = coerceRef(returnFiber, null, newChild);
5026 _created.return = returnFiber;
5027 return _created;
5028 }
5029
5030 case REACT_PORTAL_TYPE:
5031 {
5032 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
5033
5034 _created2.return = returnFiber;
5035 return _created2;
5036 }
5037 }
5038
5039 if (isArray(newChild) || getIteratorFn(newChild)) {
5040 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
5041
5042 _created3.return = returnFiber;
5043 return _created3;
5044 }
5045
5046 throwOnInvalidObjectType(returnFiber, newChild);
5047 }
5048
5049 {
5050 if (typeof newChild === 'function') {
5051 warnOnFunctionType();
5052 }
5053 }
5054
5055 return null;
5056 }
5057
5058 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
5059 // Update the fiber if the keys match, otherwise return null.
5060 var key = oldFiber !== null ? oldFiber.key : null;
5061
5062 if (typeof newChild === 'string' || typeof newChild === 'number') {
5063 // Text nodes don't have keys. If the previous node is implicitly keyed
5064 // we can continue to replace it without aborting even if it is not a text
5065 // node.
5066 if (key !== null) {
5067 return null;
5068 }
5069
5070 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
5071 }
5072
5073 if (typeof newChild === 'object' && newChild !== null) {
5074 switch (newChild.$$typeof) {
5075 case REACT_ELEMENT_TYPE$1:
5076 {
5077 if (newChild.key === key) {
5078 if (newChild.type === REACT_FRAGMENT_TYPE) {
5079 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
5080 }
5081
5082 return updateElement(returnFiber, oldFiber, newChild, expirationTime);
5083 } else {
5084 return null;
5085 }
5086 }
5087
5088 case REACT_PORTAL_TYPE:
5089 {
5090 if (newChild.key === key) {
5091 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
5092 } else {
5093 return null;
5094 }
5095 }
5096 }
5097
5098 if (isArray(newChild) || getIteratorFn(newChild)) {
5099 if (key !== null) {
5100 return null;
5101 }
5102
5103 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
5104 }
5105
5106 throwOnInvalidObjectType(returnFiber, newChild);
5107 }
5108
5109 {
5110 if (typeof newChild === 'function') {
5111 warnOnFunctionType();
5112 }
5113 }
5114
5115 return null;
5116 }
5117
5118 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
5119 if (typeof newChild === 'string' || typeof newChild === 'number') {
5120 // Text nodes don't have keys, so we neither have to check the old nor
5121 // new node for the key. If both are text nodes, they match.
5122 var matchedFiber = existingChildren.get(newIdx) || null;
5123 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
5124 }
5125
5126 if (typeof newChild === 'object' && newChild !== null) {
5127 switch (newChild.$$typeof) {
5128 case REACT_ELEMENT_TYPE$1:
5129 {
5130 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
5131
5132 if (newChild.type === REACT_FRAGMENT_TYPE) {
5133 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
5134 }
5135
5136 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
5137 }
5138
5139 case REACT_PORTAL_TYPE:
5140 {
5141 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
5142
5143 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
5144 }
5145 }
5146
5147 if (isArray(newChild) || getIteratorFn(newChild)) {
5148 var _matchedFiber3 = existingChildren.get(newIdx) || null;
5149
5150 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
5151 }
5152
5153 throwOnInvalidObjectType(returnFiber, newChild);
5154 }
5155
5156 {
5157 if (typeof newChild === 'function') {
5158 warnOnFunctionType();
5159 }
5160 }
5161
5162 return null;
5163 }
5164 /**
5165 * Warns if there is a duplicate or missing key
5166 */
5167
5168
5169 function warnOnInvalidKey(child, knownKeys) {
5170 {
5171 if (typeof child !== 'object' || child === null) {
5172 return knownKeys;
5173 }
5174
5175 switch (child.$$typeof) {
5176 case REACT_ELEMENT_TYPE$1:
5177 case REACT_PORTAL_TYPE:
5178 warnForMissingKey(child);
5179 var key = child.key;
5180
5181 if (typeof key !== 'string') {
5182 break;
5183 }
5184
5185 if (knownKeys === null) {
5186 knownKeys = new Set();
5187 knownKeys.add(key);
5188 break;
5189 }
5190
5191 if (!knownKeys.has(key)) {
5192 knownKeys.add(key);
5193 break;
5194 }
5195
5196 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);
5197 break;
5198
5199 default:
5200 break;
5201 }
5202 }
5203
5204 return knownKeys;
5205 }
5206
5207 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
5208 // This algorithm can't optimize by searching from both ends since we
5209 // don't have backpointers on fibers. I'm trying to see how far we can get
5210 // with that model. If it ends up not being worth the tradeoffs, we can
5211 // add it later.
5212 // Even with a two ended optimization, we'd want to optimize for the case
5213 // where there are few changes and brute force the comparison instead of
5214 // going for the Map. It'd like to explore hitting that path first in
5215 // forward-only mode and only go for the Map once we notice that we need
5216 // lots of look ahead. This doesn't handle reversal as well as two ended
5217 // search but that's unusual. Besides, for the two ended optimization to
5218 // work on Iterables, we'd need to copy the whole set.
5219 // In this first iteration, we'll just live with hitting the bad case
5220 // (adding everything to a Map) in for every insert/move.
5221 // If you change this code, also update reconcileChildrenIterator() which
5222 // uses the same algorithm.
5223 {
5224 // First, validate keys.
5225 var knownKeys = null;
5226
5227 for (var i = 0; i < newChildren.length; i++) {
5228 var child = newChildren[i];
5229 knownKeys = warnOnInvalidKey(child, knownKeys);
5230 }
5231 }
5232
5233 var resultingFirstChild = null;
5234 var previousNewFiber = null;
5235 var oldFiber = currentFirstChild;
5236 var lastPlacedIndex = 0;
5237 var newIdx = 0;
5238 var nextOldFiber = null;
5239
5240 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
5241 if (oldFiber.index > newIdx) {
5242 nextOldFiber = oldFiber;
5243 oldFiber = null;
5244 } else {
5245 nextOldFiber = oldFiber.sibling;
5246 }
5247
5248 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
5249
5250 if (newFiber === null) {
5251 // TODO: This breaks on empty slots like null children. That's
5252 // unfortunate because it triggers the slow path all the time. We need
5253 // a better way to communicate whether this was a miss or null,
5254 // boolean, undefined, etc.
5255 if (oldFiber === null) {
5256 oldFiber = nextOldFiber;
5257 }
5258
5259 break;
5260 }
5261
5262 if (shouldTrackSideEffects) {
5263 if (oldFiber && newFiber.alternate === null) {
5264 // We matched the slot, but we didn't reuse the existing fiber, so we
5265 // need to delete the existing child.
5266 deleteChild(returnFiber, oldFiber);
5267 }
5268 }
5269
5270 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
5271
5272 if (previousNewFiber === null) {
5273 // TODO: Move out of the loop. This only happens for the first run.
5274 resultingFirstChild = newFiber;
5275 } else {
5276 // TODO: Defer siblings if we're not at the right index for this slot.
5277 // I.e. if we had null values before, then we want to defer this
5278 // for each null value. However, we also don't want to call updateSlot
5279 // with the previous one.
5280 previousNewFiber.sibling = newFiber;
5281 }
5282
5283 previousNewFiber = newFiber;
5284 oldFiber = nextOldFiber;
5285 }
5286
5287 if (newIdx === newChildren.length) {
5288 // We've reached the end of the new children. We can delete the rest.
5289 deleteRemainingChildren(returnFiber, oldFiber);
5290 return resultingFirstChild;
5291 }
5292
5293 if (oldFiber === null) {
5294 // If we don't have any more existing children we can choose a fast path
5295 // since the rest will all be insertions.
5296 for (; newIdx < newChildren.length; newIdx++) {
5297 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
5298
5299 if (_newFiber === null) {
5300 continue;
5301 }
5302
5303 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
5304
5305 if (previousNewFiber === null) {
5306 // TODO: Move out of the loop. This only happens for the first run.
5307 resultingFirstChild = _newFiber;
5308 } else {
5309 previousNewFiber.sibling = _newFiber;
5310 }
5311
5312 previousNewFiber = _newFiber;
5313 }
5314
5315 return resultingFirstChild;
5316 } // Add all children to a key map for quick lookups.
5317
5318
5319 var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
5320
5321 for (; newIdx < newChildren.length; newIdx++) {
5322 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
5323
5324 if (_newFiber2 !== null) {
5325 if (shouldTrackSideEffects) {
5326 if (_newFiber2.alternate !== null) {
5327 // The new fiber is a work in progress, but if there exists a
5328 // current, that means that we reused the fiber. We need to delete
5329 // it from the child list so that we don't add it to the deletion
5330 // list.
5331 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
5332 }
5333 }
5334
5335 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
5336
5337 if (previousNewFiber === null) {
5338 resultingFirstChild = _newFiber2;
5339 } else {
5340 previousNewFiber.sibling = _newFiber2;
5341 }
5342
5343 previousNewFiber = _newFiber2;
5344 }
5345 }
5346
5347 if (shouldTrackSideEffects) {
5348 // Any existing children that weren't consumed above were deleted. We need
5349 // to add them to the deletion list.
5350 existingChildren.forEach(function (child) {
5351 return deleteChild(returnFiber, child);
5352 });
5353 }
5354
5355 return resultingFirstChild;
5356 }
5357
5358 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
5359 // This is the same implementation as reconcileChildrenArray(),
5360 // but using the iterator instead.
5361 var iteratorFn = getIteratorFn(newChildrenIterable);
5362
5363 (function () {
5364 if (!(typeof iteratorFn === 'function')) {
5365 {
5366 throw ReactError(Error("An object is not an iterable. This error is likely caused by a bug in React. Please file an issue."));
5367 }
5368 }
5369 })();
5370
5371 {
5372 // We don't support rendering Generators because it's a mutation.
5373 // See https://github.com/facebook/react/issues/12995
5374 if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
5375 newChildrenIterable[Symbol.toStringTag] === 'Generator') {
5376 !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;
5377 didWarnAboutGenerators = true;
5378 } // Warn about using Maps as children
5379
5380
5381 if (newChildrenIterable.entries === iteratorFn) {
5382 !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;
5383 didWarnAboutMaps = true;
5384 } // First, validate keys.
5385 // We'll get a different iterator later for the main pass.
5386
5387
5388 var _newChildren = iteratorFn.call(newChildrenIterable);
5389
5390 if (_newChildren) {
5391 var knownKeys = null;
5392
5393 var _step = _newChildren.next();
5394
5395 for (; !_step.done; _step = _newChildren.next()) {
5396 var child = _step.value;
5397 knownKeys = warnOnInvalidKey(child, knownKeys);
5398 }
5399 }
5400 }
5401
5402 var newChildren = iteratorFn.call(newChildrenIterable);
5403
5404 (function () {
5405 if (!(newChildren != null)) {
5406 {
5407 throw ReactError(Error("An iterable object provided no iterator."));
5408 }
5409 }
5410 })();
5411
5412 var resultingFirstChild = null;
5413 var previousNewFiber = null;
5414 var oldFiber = currentFirstChild;
5415 var lastPlacedIndex = 0;
5416 var newIdx = 0;
5417 var nextOldFiber = null;
5418 var step = newChildren.next();
5419
5420 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
5421 if (oldFiber.index > newIdx) {
5422 nextOldFiber = oldFiber;
5423 oldFiber = null;
5424 } else {
5425 nextOldFiber = oldFiber.sibling;
5426 }
5427
5428 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
5429
5430 if (newFiber === null) {
5431 // TODO: This breaks on empty slots like null children. That's
5432 // unfortunate because it triggers the slow path all the time. We need
5433 // a better way to communicate whether this was a miss or null,
5434 // boolean, undefined, etc.
5435 if (oldFiber === null) {
5436 oldFiber = nextOldFiber;
5437 }
5438
5439 break;
5440 }
5441
5442 if (shouldTrackSideEffects) {
5443 if (oldFiber && newFiber.alternate === null) {
5444 // We matched the slot, but we didn't reuse the existing fiber, so we
5445 // need to delete the existing child.
5446 deleteChild(returnFiber, oldFiber);
5447 }
5448 }
5449
5450 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
5451
5452 if (previousNewFiber === null) {
5453 // TODO: Move out of the loop. This only happens for the first run.
5454 resultingFirstChild = newFiber;
5455 } else {
5456 // TODO: Defer siblings if we're not at the right index for this slot.
5457 // I.e. if we had null values before, then we want to defer this
5458 // for each null value. However, we also don't want to call updateSlot
5459 // with the previous one.
5460 previousNewFiber.sibling = newFiber;
5461 }
5462
5463 previousNewFiber = newFiber;
5464 oldFiber = nextOldFiber;
5465 }
5466
5467 if (step.done) {
5468 // We've reached the end of the new children. We can delete the rest.
5469 deleteRemainingChildren(returnFiber, oldFiber);
5470 return resultingFirstChild;
5471 }
5472
5473 if (oldFiber === null) {
5474 // If we don't have any more existing children we can choose a fast path
5475 // since the rest will all be insertions.
5476 for (; !step.done; newIdx++, step = newChildren.next()) {
5477 var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
5478
5479 if (_newFiber3 === null) {
5480 continue;
5481 }
5482
5483 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
5484
5485 if (previousNewFiber === null) {
5486 // TODO: Move out of the loop. This only happens for the first run.
5487 resultingFirstChild = _newFiber3;
5488 } else {
5489 previousNewFiber.sibling = _newFiber3;
5490 }
5491
5492 previousNewFiber = _newFiber3;
5493 }
5494
5495 return resultingFirstChild;
5496 } // Add all children to a key map for quick lookups.
5497
5498
5499 var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
5500
5501 for (; !step.done; newIdx++, step = newChildren.next()) {
5502 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
5503
5504 if (_newFiber4 !== null) {
5505 if (shouldTrackSideEffects) {
5506 if (_newFiber4.alternate !== null) {
5507 // The new fiber is a work in progress, but if there exists a
5508 // current, that means that we reused the fiber. We need to delete
5509 // it from the child list so that we don't add it to the deletion
5510 // list.
5511 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
5512 }
5513 }
5514
5515 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
5516
5517 if (previousNewFiber === null) {
5518 resultingFirstChild = _newFiber4;
5519 } else {
5520 previousNewFiber.sibling = _newFiber4;
5521 }
5522
5523 previousNewFiber = _newFiber4;
5524 }
5525 }
5526
5527 if (shouldTrackSideEffects) {
5528 // Any existing children that weren't consumed above were deleted. We need
5529 // to add them to the deletion list.
5530 existingChildren.forEach(function (child) {
5531 return deleteChild(returnFiber, child);
5532 });
5533 }
5534
5535 return resultingFirstChild;
5536 }
5537
5538 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
5539 // There's no need to check for keys on text nodes since we don't have a
5540 // way to define them.
5541 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
5542 // We already have an existing node so let's just update it and delete
5543 // the rest.
5544 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
5545 var existing = useFiber(currentFirstChild, textContent, expirationTime);
5546 existing.return = returnFiber;
5547 return existing;
5548 } // The existing first child is not a text node so we need to create one
5549 // and delete the existing ones.
5550
5551
5552 deleteRemainingChildren(returnFiber, currentFirstChild);
5553 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
5554 created.return = returnFiber;
5555 return created;
5556 }
5557
5558 function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
5559 var key = element.key;
5560 var child = currentFirstChild;
5561
5562 while (child !== null) {
5563 // TODO: If key === null and child.key === null, then this only applies to
5564 // the first item in the list.
5565 if (child.key === key) {
5566 if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
5567 isCompatibleFamilyForHotReloading(child, element))) {
5568 deleteRemainingChildren(returnFiber, child.sibling);
5569 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);
5570 existing.ref = coerceRef(returnFiber, child, element);
5571 existing.return = returnFiber;
5572
5573 {
5574 existing._debugSource = element._source;
5575 existing._debugOwner = element._owner;
5576 }
5577
5578 return existing;
5579 } else {
5580 deleteRemainingChildren(returnFiber, child);
5581 break;
5582 }
5583 } else {
5584 deleteChild(returnFiber, child);
5585 }
5586
5587 child = child.sibling;
5588 }
5589
5590 if (element.type === REACT_FRAGMENT_TYPE) {
5591 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
5592 created.return = returnFiber;
5593 return created;
5594 } else {
5595 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
5596
5597 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
5598 _created4.return = returnFiber;
5599 return _created4;
5600 }
5601 }
5602
5603 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
5604 var key = portal.key;
5605 var child = currentFirstChild;
5606
5607 while (child !== null) {
5608 // TODO: If key === null and child.key === null, then this only applies to
5609 // the first item in the list.
5610 if (child.key === key) {
5611 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
5612 deleteRemainingChildren(returnFiber, child.sibling);
5613 var existing = useFiber(child, portal.children || [], expirationTime);
5614 existing.return = returnFiber;
5615 return existing;
5616 } else {
5617 deleteRemainingChildren(returnFiber, child);
5618 break;
5619 }
5620 } else {
5621 deleteChild(returnFiber, child);
5622 }
5623
5624 child = child.sibling;
5625 }
5626
5627 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
5628 created.return = returnFiber;
5629 return created;
5630 } // This API will tag the children with the side-effect of the reconciliation
5631 // itself. They will be added to the side-effect list as we pass through the
5632 // children and the parent.
5633
5634
5635 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
5636 // This function is not recursive.
5637 // If the top level item is an array, we treat it as a set of children,
5638 // not as a fragment. Nested arrays on the other hand will be treated as
5639 // fragment nodes. Recursion happens at the normal flow.
5640 // Handle top level unkeyed fragments as if they were arrays.
5641 // This leads to an ambiguity between <>{[...]}</> and <>...</>.
5642 // We treat the ambiguous cases above the same.
5643 var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
5644
5645 if (isUnkeyedTopLevelFragment) {
5646 newChild = newChild.props.children;
5647 } // Handle object types
5648
5649
5650 var isObject = typeof newChild === 'object' && newChild !== null;
5651
5652 if (isObject) {
5653 switch (newChild.$$typeof) {
5654 case REACT_ELEMENT_TYPE$1:
5655 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
5656
5657 case REACT_PORTAL_TYPE:
5658 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
5659 }
5660 }
5661
5662 if (typeof newChild === 'string' || typeof newChild === 'number') {
5663 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
5664 }
5665
5666 if (isArray(newChild)) {
5667 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
5668 }
5669
5670 if (getIteratorFn(newChild)) {
5671 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
5672 }
5673
5674 if (isObject) {
5675 throwOnInvalidObjectType(returnFiber, newChild);
5676 }
5677
5678 {
5679 if (typeof newChild === 'function') {
5680 warnOnFunctionType();
5681 }
5682 }
5683
5684 if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
5685 // If the new child is undefined, and the return fiber is a composite
5686 // component, throw an error. If Fiber return types are disabled,
5687 // we already threw above.
5688 switch (returnFiber.tag) {
5689 case ClassComponent:
5690 {
5691 {
5692 var instance = returnFiber.stateNode;
5693
5694 if (instance.render._isMockFunction) {
5695 // We allow auto-mocks to proceed as if they're returning null.
5696 break;
5697 }
5698 }
5699 }
5700 // Intentionally fall through to the next case, which handles both
5701 // functions and classes
5702 // eslint-disable-next-lined no-fallthrough
5703
5704 case FunctionComponent:
5705 {
5706 var Component = returnFiber.type;
5707
5708 (function () {
5709 {
5710 {
5711 throw ReactError(Error((Component.displayName || Component.name || 'Component') + "(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null."));
5712 }
5713 }
5714 })();
5715 }
5716 }
5717 } // Remaining cases are all treated as empty.
5718
5719
5720 return deleteRemainingChildren(returnFiber, currentFirstChild);
5721 }
5722
5723 return reconcileChildFibers;
5724}
5725
5726var reconcileChildFibers = ChildReconciler(true);
5727var mountChildFibers = ChildReconciler(false);
5728function cloneChildFibers(current$$1, workInProgress) {
5729 (function () {
5730 if (!(current$$1 === null || workInProgress.child === current$$1.child)) {
5731 {
5732 throw ReactError(Error("Resuming work not yet implemented."));
5733 }
5734 }
5735 })();
5736
5737 if (workInProgress.child === null) {
5738 return;
5739 }
5740
5741 var currentChild = workInProgress.child;
5742 var newChild = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
5743 workInProgress.child = newChild;
5744 newChild.return = workInProgress;
5745
5746 while (currentChild.sibling !== null) {
5747 currentChild = currentChild.sibling;
5748 newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
5749 newChild.return = workInProgress;
5750 }
5751
5752 newChild.sibling = null;
5753} // Reset a workInProgress child set to prepare it for a second pass.
5754
5755function resetChildFibers(workInProgress, renderExpirationTime) {
5756 var child = workInProgress.child;
5757
5758 while (child !== null) {
5759 resetWorkInProgress(child, renderExpirationTime);
5760 child = child.sibling;
5761 }
5762}
5763
5764var NO_CONTEXT$1 = {};
5765var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
5766var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
5767var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
5768
5769function requiredContext(c) {
5770 (function () {
5771 if (!(c !== NO_CONTEXT$1)) {
5772 {
5773 throw ReactError(Error("Expected host context to exist. This error is likely caused by a bug in React. Please file an issue."));
5774 }
5775 }
5776 })();
5777
5778 return c;
5779}
5780
5781function getRootHostContainer() {
5782 var rootInstance = requiredContext(rootInstanceStackCursor.current);
5783 return rootInstance;
5784}
5785
5786function pushHostContainer(fiber, nextRootInstance) {
5787 // Push current root instance onto the stack;
5788 // This allows us to reset root when portals are popped.
5789 push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
5790 // This enables us to pop only Fibers that provide unique contexts.
5791
5792 push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
5793 // However, we can't just call getRootHostContext() and push it because
5794 // we'd have a different number of entries on the stack depending on
5795 // whether getRootHostContext() throws somewhere in renderer code or not.
5796 // So we push an empty value first. This lets us safely unwind on errors.
5797
5798 push(contextStackCursor$1, NO_CONTEXT$1, fiber);
5799 var nextRootContext = getRootHostContext(nextRootInstance); // Now that we know this function doesn't throw, replace it.
5800
5801 pop(contextStackCursor$1, fiber);
5802 push(contextStackCursor$1, nextRootContext, fiber);
5803}
5804
5805function popHostContainer(fiber) {
5806 pop(contextStackCursor$1, fiber);
5807 pop(contextFiberStackCursor, fiber);
5808 pop(rootInstanceStackCursor, fiber);
5809}
5810
5811function getHostContext() {
5812 var context = requiredContext(contextStackCursor$1.current);
5813 return context;
5814}
5815
5816function pushHostContext(fiber) {
5817 var rootInstance = requiredContext(rootInstanceStackCursor.current);
5818 var context = requiredContext(contextStackCursor$1.current);
5819 var nextContext = getChildHostContext(context, fiber.type, rootInstance); // Don't push this Fiber's context unless it's unique.
5820
5821 if (context === nextContext) {
5822 return;
5823 } // Track the context and the Fiber that provided it.
5824 // This enables us to pop only Fibers that provide unique contexts.
5825
5826
5827 push(contextFiberStackCursor, fiber, fiber);
5828 push(contextStackCursor$1, nextContext, fiber);
5829}
5830
5831function popHostContext(fiber) {
5832 // Do not pop unless this Fiber provided the current context.
5833 // pushHostContext() only pushes Fibers that provide unique contexts.
5834 if (contextFiberStackCursor.current !== fiber) {
5835 return;
5836 }
5837
5838 pop(contextStackCursor$1, fiber);
5839 pop(contextFiberStackCursor, fiber);
5840}
5841
5842var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
5843// inherited deeply down the subtree. The upper bits only affect
5844// this immediate suspense boundary and gets reset each new
5845// boundary or suspense list.
5846
5847var SubtreeSuspenseContextMask = 1; // Subtree Flags:
5848// InvisibleParentSuspenseContext indicates that one of our parent Suspense
5849// boundaries is not currently showing visible main content.
5850// Either because it is already showing a fallback or is not mounted at all.
5851// We can use this to determine if it is desirable to trigger a fallback at
5852// the parent. If not, then we might need to trigger undesirable boundaries
5853// and/or suspend the commit to avoid hiding the parent content.
5854
5855var InvisibleParentSuspenseContext = 1; // Shallow Flags:
5856// ForceSuspenseFallback can be used by SuspenseList to force newly added
5857// items into their fallback state during one of the render passes.
5858
5859var ForceSuspenseFallback = 2;
5860var suspenseStackCursor = createCursor(DefaultSuspenseContext);
5861function hasSuspenseContext(parentContext, flag) {
5862 return (parentContext & flag) !== 0;
5863}
5864function setDefaultShallowSuspenseContext(parentContext) {
5865 return parentContext & SubtreeSuspenseContextMask;
5866}
5867function setShallowSuspenseContext(parentContext, shallowContext) {
5868 return parentContext & SubtreeSuspenseContextMask | shallowContext;
5869}
5870function addSubtreeSuspenseContext(parentContext, subtreeContext) {
5871 return parentContext | subtreeContext;
5872}
5873function pushSuspenseContext(fiber, newContext) {
5874 push(suspenseStackCursor, newContext, fiber);
5875}
5876function popSuspenseContext(fiber) {
5877 pop(suspenseStackCursor, fiber);
5878}
5879
5880function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
5881 // If it was the primary children that just suspended, capture and render the
5882 // fallback. Otherwise, don't capture and bubble to the next boundary.
5883 var nextState = workInProgress.memoizedState;
5884
5885 if (nextState !== null) {
5886 if (nextState.dehydrated !== null) {
5887 // A dehydrated boundary always captures.
5888 return true;
5889 }
5890
5891 return false;
5892 }
5893
5894 var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
5895
5896 if (props.fallback === undefined) {
5897 return false;
5898 } // Regular boundaries always capture.
5899
5900
5901 if (props.unstable_avoidThisFallback !== true) {
5902 return true;
5903 } // If it's a boundary we should avoid, then we prefer to bubble up to the
5904 // parent boundary if it is currently invisible.
5905
5906
5907 if (hasInvisibleParent) {
5908 return false;
5909 } // If the parent is not able to handle it, we must handle it.
5910
5911
5912 return true;
5913}
5914function findFirstSuspended(row) {
5915 var node = row;
5916
5917 while (node !== null) {
5918 if (node.tag === SuspenseComponent) {
5919 var state = node.memoizedState;
5920
5921 if (state !== null) {
5922 var dehydrated = state.dehydrated;
5923
5924 if (dehydrated === null || isSuspenseInstancePending(dehydrated) || isSuspenseInstanceFallback(dehydrated)) {
5925 return node;
5926 }
5927 }
5928 } else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
5929 // keep track of whether it suspended or not.
5930 node.memoizedProps.revealOrder !== undefined) {
5931 var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
5932
5933 if (didSuspend) {
5934 return node;
5935 }
5936 } else if (node.child !== null) {
5937 node.child.return = node;
5938 node = node.child;
5939 continue;
5940 }
5941
5942 if (node === row) {
5943 return null;
5944 }
5945
5946 while (node.sibling === null) {
5947 if (node.return === null || node.return === row) {
5948 return null;
5949 }
5950
5951 node = node.return;
5952 }
5953
5954 node.sibling.return = node.return;
5955 node = node.sibling;
5956 }
5957
5958 return null;
5959}
5960
5961var emptyObject = {};
5962var isArray$2 = Array.isArray;
5963function createResponderInstance(responder, responderProps, responderState, fiber) {
5964 return {
5965 fiber: fiber,
5966 props: responderProps,
5967 responder: responder,
5968 rootEventTypes: null,
5969 state: responderState
5970 };
5971}
5972
5973function mountEventResponder(responder, responderProps, fiber, respondersMap, rootContainerInstance) {
5974 var responderState = emptyObject;
5975 var getInitialState = responder.getInitialState;
5976
5977 if (getInitialState !== null) {
5978 responderState = getInitialState(responderProps);
5979 }
5980
5981 var responderInstance = createResponderInstance(responder, responderProps, responderState, fiber);
5982
5983 if (!rootContainerInstance) {
5984 var node = fiber;
5985
5986 while (node !== null) {
5987 var tag = node.tag;
5988
5989 if (tag === HostComponent) {
5990 rootContainerInstance = node.stateNode;
5991 break;
5992 } else if (tag === HostRoot) {
5993 rootContainerInstance = node.stateNode.containerInfo;
5994 break;
5995 }
5996
5997 node = node.return;
5998 }
5999 }
6000
6001 respondersMap.set(responder, responderInstance);
6002}
6003
6004function updateEventListener(listener, fiber, visistedResponders, respondersMap, rootContainerInstance) {
6005 var responder;
6006 var props;
6007
6008 if (listener) {
6009 responder = listener.responder;
6010 props = listener.props;
6011 }
6012
6013 (function () {
6014 if (!(responder && responder.$$typeof === REACT_RESPONDER_TYPE)) {
6015 {
6016 throw ReactError(Error("An invalid value was used as an event listener. Expect one or many event listeners created via React.unstable_useResponder()."));
6017 }
6018 }
6019 })();
6020
6021 var listenerProps = props;
6022
6023 if (visistedResponders.has(responder)) {
6024 // show warning
6025 {
6026 warning$1(false, 'Duplicate event responder "%s" found in event listeners. ' + 'Event listeners passed to elements cannot use the same event responder more than once.', responder.displayName);
6027 }
6028
6029 return;
6030 }
6031
6032 visistedResponders.add(responder);
6033 var responderInstance = respondersMap.get(responder);
6034
6035 if (responderInstance === undefined) {
6036 // Mount (happens in either complete or commit phase)
6037 mountEventResponder(responder, listenerProps, fiber, respondersMap, rootContainerInstance);
6038 } else {
6039 // Update (happens during commit phase only)
6040 responderInstance.props = listenerProps;
6041 responderInstance.fiber = fiber;
6042 }
6043}
6044
6045function updateEventListeners(listeners, fiber, rootContainerInstance) {
6046 var visistedResponders = new Set();
6047 var dependencies = fiber.dependencies;
6048
6049 if (listeners != null) {
6050 if (dependencies === null) {
6051 dependencies = fiber.dependencies = {
6052 expirationTime: NoWork,
6053 firstContext: null,
6054 responders: new Map()
6055 };
6056 }
6057
6058 var respondersMap = dependencies.responders;
6059
6060 if (respondersMap === null) {
6061 respondersMap = new Map();
6062 }
6063
6064 if (isArray$2(listeners)) {
6065 for (var i = 0, length = listeners.length; i < length; i++) {
6066 var listener = listeners[i];
6067 updateEventListener(listener, fiber, visistedResponders, respondersMap, rootContainerInstance);
6068 }
6069 } else {
6070 updateEventListener(listeners, fiber, visistedResponders, respondersMap, rootContainerInstance);
6071 }
6072 }
6073
6074 if (dependencies !== null) {
6075 var _respondersMap = dependencies.responders;
6076
6077 if (_respondersMap !== null) {
6078 // Unmount
6079 var mountedResponders = Array.from(_respondersMap.keys());
6080
6081 for (var _i = 0, _length = mountedResponders.length; _i < _length; _i++) {
6082 var mountedResponder = mountedResponders[_i];
6083
6084 if (!visistedResponders.has(mountedResponder)) {
6085 var responderInstance = _respondersMap.get(mountedResponder);
6086
6087 _respondersMap.delete(mountedResponder);
6088 }
6089 }
6090 }
6091 }
6092}
6093function createResponderListener(responder, props) {
6094 var eventResponderListener = {
6095 responder: responder,
6096 props: props
6097 };
6098
6099 {
6100 Object.freeze(eventResponderListener);
6101 }
6102
6103 return eventResponderListener;
6104}
6105
6106var NoEffect$1 =
6107/* */
61080;
6109var UnmountSnapshot =
6110/* */
61112;
6112var UnmountMutation =
6113/* */
61144;
6115var MountMutation =
6116/* */
61178;
6118var UnmountLayout =
6119/* */
612016;
6121var MountLayout =
6122/* */
612332;
6124var MountPassive =
6125/* */
612664;
6127var UnmountPassive =
6128/* */
6129128;
6130
6131var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
6132var didWarnAboutMismatchedHooksForComponent;
6133
6134{
6135 didWarnAboutMismatchedHooksForComponent = new Set();
6136}
6137
6138// These are set right before calling the component.
6139var renderExpirationTime$1 = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
6140// the work-in-progress hook.
6141
6142var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
6143// current hook list is the list that belongs to the current fiber. The
6144// work-in-progress hook list is a new list that will be added to the
6145// work-in-progress fiber.
6146
6147var currentHook = null;
6148var nextCurrentHook = null;
6149var firstWorkInProgressHook = null;
6150var workInProgressHook = null;
6151var nextWorkInProgressHook = null;
6152var remainingExpirationTime = NoWork;
6153var componentUpdateQueue = null;
6154var sideEffectTag = 0; // Updates scheduled during render will trigger an immediate re-render at the
6155// end of the current pass. We can't store these updates on the normal queue,
6156// because if the work is aborted, they should be discarded. Because this is
6157// a relatively rare case, we also don't want to add an additional field to
6158// either the hook or queue object types. So we store them in a lazily create
6159// map of queue -> render-phase updates, which are discarded once the component
6160// completes without re-rendering.
6161// Whether an update was scheduled during the currently executing render pass.
6162
6163var didScheduleRenderPhaseUpdate = false; // Lazily created map of render-phase updates
6164
6165var renderPhaseUpdates = null; // Counter to prevent infinite loops.
6166
6167var numberOfReRenders = 0;
6168var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
6169
6170var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
6171// The list stores the order of hooks used during the initial render (mount).
6172// Subsequent renders (updates) reference this list.
6173
6174var hookTypesDev = null;
6175var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
6176// the dependencies for Hooks that need them (e.g. useEffect or useMemo).
6177// When true, such Hooks will always be "remounted". Only used during hot reload.
6178
6179var ignorePreviousDependencies = false;
6180
6181function mountHookTypesDev() {
6182 {
6183 var hookName = currentHookNameInDev;
6184
6185 if (hookTypesDev === null) {
6186 hookTypesDev = [hookName];
6187 } else {
6188 hookTypesDev.push(hookName);
6189 }
6190 }
6191}
6192
6193function updateHookTypesDev() {
6194 {
6195 var hookName = currentHookNameInDev;
6196
6197 if (hookTypesDev !== null) {
6198 hookTypesUpdateIndexDev++;
6199
6200 if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
6201 warnOnHookMismatchInDev(hookName);
6202 }
6203 }
6204 }
6205}
6206
6207function checkDepsAreArrayDev(deps) {
6208 {
6209 if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
6210 // Verify deps, but only on mount to avoid extra checks.
6211 // It's unlikely their type would change as usually you define them inline.
6212 warning$1(false, '%s received a final argument that is not an array (instead, received `%s`). When ' + 'specified, the final argument must be an array.', currentHookNameInDev, typeof deps);
6213 }
6214 }
6215}
6216
6217function warnOnHookMismatchInDev(currentHookName) {
6218 {
6219 var componentName = getComponentName(currentlyRenderingFiber$1.type);
6220
6221 if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
6222 didWarnAboutMismatchedHooksForComponent.add(componentName);
6223
6224 if (hookTypesDev !== null) {
6225 var table = '';
6226 var secondColumnStart = 30;
6227
6228 for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
6229 var oldHookName = hookTypesDev[i];
6230 var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
6231 var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
6232 // lol @ IE not supporting String#repeat
6233
6234 while (row.length < secondColumnStart) {
6235 row += ' ';
6236 }
6237
6238 row += newHookName + '\n';
6239 table += row;
6240 }
6241
6242 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);
6243 }
6244 }
6245 }
6246}
6247
6248function throwInvalidHookError() {
6249 (function () {
6250 {
6251 {
6252 throw ReactError(Error("Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem."));
6253 }
6254 }
6255 })();
6256}
6257
6258function areHookInputsEqual(nextDeps, prevDeps) {
6259 {
6260 if (ignorePreviousDependencies) {
6261 // Only true when this component is being hot reloaded.
6262 return false;
6263 }
6264 }
6265
6266 if (prevDeps === null) {
6267 {
6268 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);
6269 }
6270
6271 return false;
6272 }
6273
6274 {
6275 // Don't bother comparing lengths in prod because these arrays should be
6276 // passed inline.
6277 if (nextDeps.length !== prevDeps.length) {
6278 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, "[" + prevDeps.join(', ') + "]", "[" + nextDeps.join(', ') + "]");
6279 }
6280 }
6281
6282 for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
6283 if (is$1(nextDeps[i], prevDeps[i])) {
6284 continue;
6285 }
6286
6287 return false;
6288 }
6289
6290 return true;
6291}
6292
6293function renderWithHooks(current, workInProgress, Component, props, refOrContext, nextRenderExpirationTime) {
6294 renderExpirationTime$1 = nextRenderExpirationTime;
6295 currentlyRenderingFiber$1 = workInProgress;
6296 nextCurrentHook = current !== null ? current.memoizedState : null;
6297
6298 {
6299 hookTypesDev = current !== null ? current._debugHookTypes : null;
6300 hookTypesUpdateIndexDev = -1; // Used for hot reloading:
6301
6302 ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
6303 } // The following should have already been reset
6304 // currentHook = null;
6305 // workInProgressHook = null;
6306 // remainingExpirationTime = NoWork;
6307 // componentUpdateQueue = null;
6308 // didScheduleRenderPhaseUpdate = false;
6309 // renderPhaseUpdates = null;
6310 // numberOfReRenders = 0;
6311 // sideEffectTag = 0;
6312 // TODO Warn if no hooks are used at all during mount, then some are used during update.
6313 // Currently we will identify the update render as a mount because nextCurrentHook === null.
6314 // This is tricky because it's valid for certain types of components (e.g. React.lazy)
6315 // Using nextCurrentHook to differentiate between mount/update only works if at least one stateful hook is used.
6316 // Non-stateful hooks (e.g. context) don't get added to memoizedState,
6317 // so nextCurrentHook would be null during updates and mounts.
6318
6319
6320 {
6321 if (nextCurrentHook !== null) {
6322 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
6323 } else if (hookTypesDev !== null) {
6324 // This dispatcher handles an edge case where a component is updating,
6325 // but no stateful hooks have been used.
6326 // We want to match the production code behavior (which will use HooksDispatcherOnMount),
6327 // but with the extra DEV validation to ensure hooks ordering hasn't changed.
6328 // This dispatcher does that.
6329 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountWithHookTypesInDEV;
6330 } else {
6331 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountInDEV;
6332 }
6333 }
6334
6335 var children = Component(props, refOrContext);
6336
6337 if (didScheduleRenderPhaseUpdate) {
6338 do {
6339 didScheduleRenderPhaseUpdate = false;
6340 numberOfReRenders += 1;
6341
6342 {
6343 // Even when hot reloading, allow dependencies to stabilize
6344 // after first render to prevent infinite render phase updates.
6345 ignorePreviousDependencies = false;
6346 } // Start over from the beginning of the list
6347
6348
6349 nextCurrentHook = current !== null ? current.memoizedState : null;
6350 nextWorkInProgressHook = firstWorkInProgressHook;
6351 currentHook = null;
6352 workInProgressHook = null;
6353 componentUpdateQueue = null;
6354
6355 {
6356 // Also validate hook order for cascading updates.
6357 hookTypesUpdateIndexDev = -1;
6358 }
6359
6360 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
6361 children = Component(props, refOrContext);
6362 } while (didScheduleRenderPhaseUpdate);
6363
6364 renderPhaseUpdates = null;
6365 numberOfReRenders = 0;
6366 } // We can assume the previous dispatcher is always this one, since we set it
6367 // at the beginning of the render phase and there's no re-entrancy.
6368
6369
6370 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
6371 var renderedWork = currentlyRenderingFiber$1;
6372 renderedWork.memoizedState = firstWorkInProgressHook;
6373 renderedWork.expirationTime = remainingExpirationTime;
6374 renderedWork.updateQueue = componentUpdateQueue;
6375 renderedWork.effectTag |= sideEffectTag;
6376
6377 {
6378 renderedWork._debugHookTypes = hookTypesDev;
6379 } // This check uses currentHook so that it works the same in DEV and prod bundles.
6380 // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
6381
6382
6383 var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
6384 renderExpirationTime$1 = NoWork;
6385 currentlyRenderingFiber$1 = null;
6386 currentHook = null;
6387 nextCurrentHook = null;
6388 firstWorkInProgressHook = null;
6389 workInProgressHook = null;
6390 nextWorkInProgressHook = null;
6391
6392 {
6393 currentHookNameInDev = null;
6394 hookTypesDev = null;
6395 hookTypesUpdateIndexDev = -1;
6396 }
6397
6398 remainingExpirationTime = NoWork;
6399 componentUpdateQueue = null;
6400 sideEffectTag = 0; // These were reset above
6401 // didScheduleRenderPhaseUpdate = false;
6402 // renderPhaseUpdates = null;
6403 // numberOfReRenders = 0;
6404
6405 (function () {
6406 if (!!didRenderTooFewHooks) {
6407 {
6408 throw ReactError(Error("Rendered fewer hooks than expected. This may be caused by an accidental early return statement."));
6409 }
6410 }
6411 })();
6412
6413 return children;
6414}
6415function bailoutHooks(current, workInProgress, expirationTime) {
6416 workInProgress.updateQueue = current.updateQueue;
6417 workInProgress.effectTag &= ~(Passive | Update);
6418
6419 if (current.expirationTime <= expirationTime) {
6420 current.expirationTime = NoWork;
6421 }
6422}
6423function resetHooks() {
6424 // We can assume the previous dispatcher is always this one, since we set it
6425 // at the beginning of the render phase and there's no re-entrancy.
6426 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; // This is used to reset the state of this module when a component throws.
6427 // It's also called inside mountIndeterminateComponent if we determine the
6428 // component is a module-style component.
6429
6430 renderExpirationTime$1 = NoWork;
6431 currentlyRenderingFiber$1 = null;
6432 currentHook = null;
6433 nextCurrentHook = null;
6434 firstWorkInProgressHook = null;
6435 workInProgressHook = null;
6436 nextWorkInProgressHook = null;
6437
6438 {
6439 hookTypesDev = null;
6440 hookTypesUpdateIndexDev = -1;
6441 currentHookNameInDev = null;
6442 }
6443
6444 remainingExpirationTime = NoWork;
6445 componentUpdateQueue = null;
6446 sideEffectTag = 0;
6447 didScheduleRenderPhaseUpdate = false;
6448 renderPhaseUpdates = null;
6449 numberOfReRenders = 0;
6450}
6451
6452function mountWorkInProgressHook() {
6453 var hook = {
6454 memoizedState: null,
6455 baseState: null,
6456 queue: null,
6457 baseUpdate: null,
6458 next: null
6459 };
6460
6461 if (workInProgressHook === null) {
6462 // This is the first hook in the list
6463 firstWorkInProgressHook = workInProgressHook = hook;
6464 } else {
6465 // Append to the end of the list
6466 workInProgressHook = workInProgressHook.next = hook;
6467 }
6468
6469 return workInProgressHook;
6470}
6471
6472function updateWorkInProgressHook() {
6473 // This function is used both for updates and for re-renders triggered by a
6474 // render phase update. It assumes there is either a current hook we can
6475 // clone, or a work-in-progress hook from a previous render pass that we can
6476 // use as a base. When we reach the end of the base list, we must switch to
6477 // the dispatcher used for mounts.
6478 if (nextWorkInProgressHook !== null) {
6479 // There's already a work-in-progress. Reuse it.
6480 workInProgressHook = nextWorkInProgressHook;
6481 nextWorkInProgressHook = workInProgressHook.next;
6482 currentHook = nextCurrentHook;
6483 nextCurrentHook = currentHook !== null ? currentHook.next : null;
6484 } else {
6485 // Clone from the current hook.
6486 (function () {
6487 if (!(nextCurrentHook !== null)) {
6488 {
6489 throw ReactError(Error("Rendered more hooks than during the previous render."));
6490 }
6491 }
6492 })();
6493
6494 currentHook = nextCurrentHook;
6495 var newHook = {
6496 memoizedState: currentHook.memoizedState,
6497 baseState: currentHook.baseState,
6498 queue: currentHook.queue,
6499 baseUpdate: currentHook.baseUpdate,
6500 next: null
6501 };
6502
6503 if (workInProgressHook === null) {
6504 // This is the first hook in the list.
6505 workInProgressHook = firstWorkInProgressHook = newHook;
6506 } else {
6507 // Append to the end of the list.
6508 workInProgressHook = workInProgressHook.next = newHook;
6509 }
6510
6511 nextCurrentHook = currentHook.next;
6512 }
6513
6514 return workInProgressHook;
6515}
6516
6517function createFunctionComponentUpdateQueue() {
6518 return {
6519 lastEffect: null
6520 };
6521}
6522
6523function basicStateReducer(state, action) {
6524 return typeof action === 'function' ? action(state) : action;
6525}
6526
6527function mountReducer(reducer, initialArg, init) {
6528 var hook = mountWorkInProgressHook();
6529 var initialState;
6530
6531 if (init !== undefined) {
6532 initialState = init(initialArg);
6533 } else {
6534 initialState = initialArg;
6535 }
6536
6537 hook.memoizedState = hook.baseState = initialState;
6538 var queue = hook.queue = {
6539 last: null,
6540 dispatch: null,
6541 lastRenderedReducer: reducer,
6542 lastRenderedState: initialState
6543 };
6544 var dispatch = queue.dispatch = dispatchAction.bind(null, // Flow doesn't know this is non-null, but we do.
6545 currentlyRenderingFiber$1, queue);
6546 return [hook.memoizedState, dispatch];
6547}
6548
6549function updateReducer(reducer, initialArg, init) {
6550 var hook = updateWorkInProgressHook();
6551 var queue = hook.queue;
6552
6553 (function () {
6554 if (!(queue !== null)) {
6555 {
6556 throw ReactError(Error("Should have a queue. This is likely a bug in React. Please file an issue."));
6557 }
6558 }
6559 })();
6560
6561 queue.lastRenderedReducer = reducer;
6562
6563 if (numberOfReRenders > 0) {
6564 // This is a re-render. Apply the new render phase updates to the previous
6565 // work-in-progress hook.
6566 var _dispatch = queue.dispatch;
6567
6568 if (renderPhaseUpdates !== null) {
6569 // Render phase updates are stored in a map of queue -> linked list
6570 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
6571
6572 if (firstRenderPhaseUpdate !== undefined) {
6573 renderPhaseUpdates.delete(queue);
6574 var newState = hook.memoizedState;
6575 var update = firstRenderPhaseUpdate;
6576
6577 do {
6578 // Process this render phase update. We don't have to check the
6579 // priority because it will always be the same as the current
6580 // render's.
6581 var action = update.action;
6582 newState = reducer(newState, action);
6583 update = update.next;
6584 } while (update !== null); // Mark that the fiber performed work, but only if the new state is
6585 // different from the current state.
6586
6587
6588 if (!is$1(newState, hook.memoizedState)) {
6589 markWorkInProgressReceivedUpdate();
6590 }
6591
6592 hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
6593 // the base state unless the queue is empty.
6594 // TODO: Not sure if this is the desired semantics, but it's what we
6595 // do for gDSFP. I can't remember why.
6596
6597 if (hook.baseUpdate === queue.last) {
6598 hook.baseState = newState;
6599 }
6600
6601 queue.lastRenderedState = newState;
6602 return [newState, _dispatch];
6603 }
6604 }
6605
6606 return [hook.memoizedState, _dispatch];
6607 } // The last update in the entire queue
6608
6609
6610 var last = queue.last; // The last update that is part of the base state.
6611
6612 var baseUpdate = hook.baseUpdate;
6613 var baseState = hook.baseState; // Find the first unprocessed update.
6614
6615 var first;
6616
6617 if (baseUpdate !== null) {
6618 if (last !== null) {
6619 // For the first update, the queue is a circular linked list where
6620 // `queue.last.next = queue.first`. Once the first update commits, and
6621 // the `baseUpdate` is no longer empty, we can unravel the list.
6622 last.next = null;
6623 }
6624
6625 first = baseUpdate.next;
6626 } else {
6627 first = last !== null ? last.next : null;
6628 }
6629
6630 if (first !== null) {
6631 var _newState = baseState;
6632 var newBaseState = null;
6633 var newBaseUpdate = null;
6634 var prevUpdate = baseUpdate;
6635 var _update = first;
6636 var didSkip = false;
6637
6638 do {
6639 var updateExpirationTime = _update.expirationTime;
6640
6641 if (updateExpirationTime < renderExpirationTime$1) {
6642 // Priority is insufficient. Skip this update. If this is the first
6643 // skipped update, the previous update/state is the new base
6644 // update/state.
6645 if (!didSkip) {
6646 didSkip = true;
6647 newBaseUpdate = prevUpdate;
6648 newBaseState = _newState;
6649 } // Update the remaining priority in the queue.
6650
6651
6652 if (updateExpirationTime > remainingExpirationTime) {
6653 remainingExpirationTime = updateExpirationTime;
6654 markUnprocessedUpdateTime(remainingExpirationTime);
6655 }
6656 } else {
6657 // This update does have sufficient priority.
6658 // Mark the event time of this update as relevant to this render pass.
6659 // TODO: This should ideally use the true event time of this update rather than
6660 // its priority which is a derived and not reverseable value.
6661 // TODO: We should skip this update if it was already committed but currently
6662 // we have no way of detecting the difference between a committed and suspended
6663 // update here.
6664 markRenderEventTimeAndConfig(updateExpirationTime, _update.suspenseConfig); // Process this update.
6665
6666 if (_update.eagerReducer === reducer) {
6667 // If this update was processed eagerly, and its reducer matches the
6668 // current reducer, we can use the eagerly computed state.
6669 _newState = _update.eagerState;
6670 } else {
6671 var _action = _update.action;
6672 _newState = reducer(_newState, _action);
6673 }
6674 }
6675
6676 prevUpdate = _update;
6677 _update = _update.next;
6678 } while (_update !== null && _update !== first);
6679
6680 if (!didSkip) {
6681 newBaseUpdate = prevUpdate;
6682 newBaseState = _newState;
6683 } // Mark that the fiber performed work, but only if the new state is
6684 // different from the current state.
6685
6686
6687 if (!is$1(_newState, hook.memoizedState)) {
6688 markWorkInProgressReceivedUpdate();
6689 }
6690
6691 hook.memoizedState = _newState;
6692 hook.baseUpdate = newBaseUpdate;
6693 hook.baseState = newBaseState;
6694 queue.lastRenderedState = _newState;
6695 }
6696
6697 var dispatch = queue.dispatch;
6698 return [hook.memoizedState, dispatch];
6699}
6700
6701function mountState(initialState) {
6702 var hook = mountWorkInProgressHook();
6703
6704 if (typeof initialState === 'function') {
6705 initialState = initialState();
6706 }
6707
6708 hook.memoizedState = hook.baseState = initialState;
6709 var queue = hook.queue = {
6710 last: null,
6711 dispatch: null,
6712 lastRenderedReducer: basicStateReducer,
6713 lastRenderedState: initialState
6714 };
6715 var dispatch = queue.dispatch = dispatchAction.bind(null, // Flow doesn't know this is non-null, but we do.
6716 currentlyRenderingFiber$1, queue);
6717 return [hook.memoizedState, dispatch];
6718}
6719
6720function updateState(initialState) {
6721 return updateReducer(basicStateReducer, initialState);
6722}
6723
6724function pushEffect(tag, create, destroy, deps) {
6725 var effect = {
6726 tag: tag,
6727 create: create,
6728 destroy: destroy,
6729 deps: deps,
6730 // Circular
6731 next: null
6732 };
6733
6734 if (componentUpdateQueue === null) {
6735 componentUpdateQueue = createFunctionComponentUpdateQueue();
6736 componentUpdateQueue.lastEffect = effect.next = effect;
6737 } else {
6738 var lastEffect = componentUpdateQueue.lastEffect;
6739
6740 if (lastEffect === null) {
6741 componentUpdateQueue.lastEffect = effect.next = effect;
6742 } else {
6743 var firstEffect = lastEffect.next;
6744 lastEffect.next = effect;
6745 effect.next = firstEffect;
6746 componentUpdateQueue.lastEffect = effect;
6747 }
6748 }
6749
6750 return effect;
6751}
6752
6753function mountRef(initialValue) {
6754 var hook = mountWorkInProgressHook();
6755 var ref = {
6756 current: initialValue
6757 };
6758
6759 {
6760 Object.seal(ref);
6761 }
6762
6763 hook.memoizedState = ref;
6764 return ref;
6765}
6766
6767function updateRef(initialValue) {
6768 var hook = updateWorkInProgressHook();
6769 return hook.memoizedState;
6770}
6771
6772function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
6773 var hook = mountWorkInProgressHook();
6774 var nextDeps = deps === undefined ? null : deps;
6775 sideEffectTag |= fiberEffectTag;
6776 hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps);
6777}
6778
6779function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
6780 var hook = updateWorkInProgressHook();
6781 var nextDeps = deps === undefined ? null : deps;
6782 var destroy = undefined;
6783
6784 if (currentHook !== null) {
6785 var prevEffect = currentHook.memoizedState;
6786 destroy = prevEffect.destroy;
6787
6788 if (nextDeps !== null) {
6789 var prevDeps = prevEffect.deps;
6790
6791 if (areHookInputsEqual(nextDeps, prevDeps)) {
6792 pushEffect(NoEffect$1, create, destroy, nextDeps);
6793 return;
6794 }
6795 }
6796 }
6797
6798 sideEffectTag |= fiberEffectTag;
6799 hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps);
6800}
6801
6802function mountEffect(create, deps) {
6803 {
6804 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
6805 if ('undefined' !== typeof jest) {
6806 warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
6807 }
6808 }
6809
6810 return mountEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
6811}
6812
6813function updateEffect(create, deps) {
6814 {
6815 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
6816 if ('undefined' !== typeof jest) {
6817 warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
6818 }
6819 }
6820
6821 return updateEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
6822}
6823
6824function mountLayoutEffect(create, deps) {
6825 return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
6826}
6827
6828function updateLayoutEffect(create, deps) {
6829 return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
6830}
6831
6832function imperativeHandleEffect(create, ref) {
6833 if (typeof ref === 'function') {
6834 var refCallback = ref;
6835
6836 var _inst = create();
6837
6838 refCallback(_inst);
6839 return function () {
6840 refCallback(null);
6841 };
6842 } else if (ref !== null && ref !== undefined) {
6843 var refObject = ref;
6844
6845 {
6846 !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;
6847 }
6848
6849 var _inst2 = create();
6850
6851 refObject.current = _inst2;
6852 return function () {
6853 refObject.current = null;
6854 };
6855 }
6856}
6857
6858function mountImperativeHandle(ref, create, deps) {
6859 {
6860 !(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;
6861 } // TODO: If deps are provided, should we skip comparing the ref itself?
6862
6863
6864 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
6865 return mountEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
6866}
6867
6868function updateImperativeHandle(ref, create, deps) {
6869 {
6870 !(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;
6871 } // TODO: If deps are provided, should we skip comparing the ref itself?
6872
6873
6874 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
6875 return updateEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
6876}
6877
6878function mountDebugValue(value, formatterFn) {// This hook is normally a no-op.
6879 // The react-debug-hooks package injects its own implementation
6880 // so that e.g. DevTools can display custom hook values.
6881}
6882
6883var updateDebugValue = mountDebugValue;
6884
6885function mountCallback(callback, deps) {
6886 var hook = mountWorkInProgressHook();
6887 var nextDeps = deps === undefined ? null : deps;
6888 hook.memoizedState = [callback, nextDeps];
6889 return callback;
6890}
6891
6892function updateCallback(callback, deps) {
6893 var hook = updateWorkInProgressHook();
6894 var nextDeps = deps === undefined ? null : deps;
6895 var prevState = hook.memoizedState;
6896
6897 if (prevState !== null) {
6898 if (nextDeps !== null) {
6899 var prevDeps = prevState[1];
6900
6901 if (areHookInputsEqual(nextDeps, prevDeps)) {
6902 return prevState[0];
6903 }
6904 }
6905 }
6906
6907 hook.memoizedState = [callback, nextDeps];
6908 return callback;
6909}
6910
6911function mountMemo(nextCreate, deps) {
6912 var hook = mountWorkInProgressHook();
6913 var nextDeps = deps === undefined ? null : deps;
6914 var nextValue = nextCreate();
6915 hook.memoizedState = [nextValue, nextDeps];
6916 return nextValue;
6917}
6918
6919function updateMemo(nextCreate, deps) {
6920 var hook = updateWorkInProgressHook();
6921 var nextDeps = deps === undefined ? null : deps;
6922 var prevState = hook.memoizedState;
6923
6924 if (prevState !== null) {
6925 // Assume these are defined. If they're not, areHookInputsEqual will warn.
6926 if (nextDeps !== null) {
6927 var prevDeps = prevState[1];
6928
6929 if (areHookInputsEqual(nextDeps, prevDeps)) {
6930 return prevState[0];
6931 }
6932 }
6933 }
6934
6935 var nextValue = nextCreate();
6936 hook.memoizedState = [nextValue, nextDeps];
6937 return nextValue;
6938}
6939
6940function dispatchAction(fiber, queue, action) {
6941 (function () {
6942 if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
6943 {
6944 throw ReactError(Error("Too many re-renders. React limits the number of renders to prevent an infinite loop."));
6945 }
6946 }
6947 })();
6948
6949 {
6950 !(typeof arguments[3] !== 'function') ? 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;
6951 }
6952
6953 var alternate = fiber.alternate;
6954
6955 if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
6956 // This is a render phase update. Stash it in a lazily-created map of
6957 // queue -> linked list of updates. After this render pass, we'll restart
6958 // and apply the stashed updates on top of the work-in-progress hook.
6959 didScheduleRenderPhaseUpdate = true;
6960 var update = {
6961 expirationTime: renderExpirationTime$1,
6962 suspenseConfig: null,
6963 action: action,
6964 eagerReducer: null,
6965 eagerState: null,
6966 next: null
6967 };
6968
6969 {
6970 update.priority = getCurrentPriorityLevel();
6971 }
6972
6973 if (renderPhaseUpdates === null) {
6974 renderPhaseUpdates = new Map();
6975 }
6976
6977 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
6978
6979 if (firstRenderPhaseUpdate === undefined) {
6980 renderPhaseUpdates.set(queue, update);
6981 } else {
6982 // Append the update to the end of the list.
6983 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
6984
6985 while (lastRenderPhaseUpdate.next !== null) {
6986 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
6987 }
6988
6989 lastRenderPhaseUpdate.next = update;
6990 }
6991 } else {
6992 var currentTime = requestCurrentTime();
6993 var suspenseConfig = requestCurrentSuspenseConfig();
6994 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
6995 var _update2 = {
6996 expirationTime: expirationTime,
6997 suspenseConfig: suspenseConfig,
6998 action: action,
6999 eagerReducer: null,
7000 eagerState: null,
7001 next: null
7002 };
7003
7004 {
7005 _update2.priority = getCurrentPriorityLevel();
7006 } // Append the update to the end of the list.
7007
7008
7009 var last = queue.last;
7010
7011 if (last === null) {
7012 // This is the first update. Create a circular list.
7013 _update2.next = _update2;
7014 } else {
7015 var first = last.next;
7016
7017 if (first !== null) {
7018 // Still circular.
7019 _update2.next = first;
7020 }
7021
7022 last.next = _update2;
7023 }
7024
7025 queue.last = _update2;
7026
7027 if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
7028 // The queue is currently empty, which means we can eagerly compute the
7029 // next state before entering the render phase. If the new state is the
7030 // same as the current state, we may be able to bail out entirely.
7031 var lastRenderedReducer = queue.lastRenderedReducer;
7032
7033 if (lastRenderedReducer !== null) {
7034 var prevDispatcher;
7035
7036 {
7037 prevDispatcher = ReactCurrentDispatcher$1.current;
7038 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7039 }
7040
7041 try {
7042 var currentState = queue.lastRenderedState;
7043 var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
7044 // it, on the update object. If the reducer hasn't changed by the
7045 // time we enter the render phase, then the eager state can be used
7046 // without calling the reducer again.
7047
7048 _update2.eagerReducer = lastRenderedReducer;
7049 _update2.eagerState = eagerState;
7050
7051 if (is$1(eagerState, currentState)) {
7052 // Fast path. We can bail out without scheduling React to re-render.
7053 // It's still possible that we'll need to rebase this update later,
7054 // if the component re-renders for a different reason and by that
7055 // time the reducer has changed.
7056 return;
7057 }
7058 } catch (error) {// Suppress the error. It will throw again in the render phase.
7059 } finally {
7060 {
7061 ReactCurrentDispatcher$1.current = prevDispatcher;
7062 }
7063 }
7064 }
7065 }
7066
7067 {
7068 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
7069 if ('undefined' !== typeof jest) {
7070 warnIfNotScopedWithMatchingAct(fiber);
7071 warnIfNotCurrentlyActingUpdatesInDev(fiber);
7072 }
7073 }
7074
7075 scheduleWork(fiber, expirationTime);
7076 }
7077}
7078
7079var ContextOnlyDispatcher = {
7080 readContext: readContext,
7081 useCallback: throwInvalidHookError,
7082 useContext: throwInvalidHookError,
7083 useEffect: throwInvalidHookError,
7084 useImperativeHandle: throwInvalidHookError,
7085 useLayoutEffect: throwInvalidHookError,
7086 useMemo: throwInvalidHookError,
7087 useReducer: throwInvalidHookError,
7088 useRef: throwInvalidHookError,
7089 useState: throwInvalidHookError,
7090 useDebugValue: throwInvalidHookError,
7091 useResponder: throwInvalidHookError
7092};
7093var HooksDispatcherOnMountInDEV = null;
7094var HooksDispatcherOnMountWithHookTypesInDEV = null;
7095var HooksDispatcherOnUpdateInDEV = null;
7096var InvalidNestedHooksDispatcherOnMountInDEV = null;
7097var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
7098
7099{
7100 var warnInvalidContextAccess = function () {
7101 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().');
7102 };
7103
7104 var warnInvalidHookAccess = function () {
7105 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');
7106 };
7107
7108 HooksDispatcherOnMountInDEV = {
7109 readContext: function (context, observedBits) {
7110 return readContext(context, observedBits);
7111 },
7112 useCallback: function (callback, deps) {
7113 currentHookNameInDev = 'useCallback';
7114 mountHookTypesDev();
7115 checkDepsAreArrayDev(deps);
7116 return mountCallback(callback, deps);
7117 },
7118 useContext: function (context, observedBits) {
7119 currentHookNameInDev = 'useContext';
7120 mountHookTypesDev();
7121 return readContext(context, observedBits);
7122 },
7123 useEffect: function (create, deps) {
7124 currentHookNameInDev = 'useEffect';
7125 mountHookTypesDev();
7126 checkDepsAreArrayDev(deps);
7127 return mountEffect(create, deps);
7128 },
7129 useImperativeHandle: function (ref, create, deps) {
7130 currentHookNameInDev = 'useImperativeHandle';
7131 mountHookTypesDev();
7132 checkDepsAreArrayDev(deps);
7133 return mountImperativeHandle(ref, create, deps);
7134 },
7135 useLayoutEffect: function (create, deps) {
7136 currentHookNameInDev = 'useLayoutEffect';
7137 mountHookTypesDev();
7138 checkDepsAreArrayDev(deps);
7139 return mountLayoutEffect(create, deps);
7140 },
7141 useMemo: function (create, deps) {
7142 currentHookNameInDev = 'useMemo';
7143 mountHookTypesDev();
7144 checkDepsAreArrayDev(deps);
7145 var prevDispatcher = ReactCurrentDispatcher$1.current;
7146 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7147
7148 try {
7149 return mountMemo(create, deps);
7150 } finally {
7151 ReactCurrentDispatcher$1.current = prevDispatcher;
7152 }
7153 },
7154 useReducer: function (reducer, initialArg, init) {
7155 currentHookNameInDev = 'useReducer';
7156 mountHookTypesDev();
7157 var prevDispatcher = ReactCurrentDispatcher$1.current;
7158 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7159
7160 try {
7161 return mountReducer(reducer, initialArg, init);
7162 } finally {
7163 ReactCurrentDispatcher$1.current = prevDispatcher;
7164 }
7165 },
7166 useRef: function (initialValue) {
7167 currentHookNameInDev = 'useRef';
7168 mountHookTypesDev();
7169 return mountRef(initialValue);
7170 },
7171 useState: function (initialState) {
7172 currentHookNameInDev = 'useState';
7173 mountHookTypesDev();
7174 var prevDispatcher = ReactCurrentDispatcher$1.current;
7175 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7176
7177 try {
7178 return mountState(initialState);
7179 } finally {
7180 ReactCurrentDispatcher$1.current = prevDispatcher;
7181 }
7182 },
7183 useDebugValue: function (value, formatterFn) {
7184 currentHookNameInDev = 'useDebugValue';
7185 mountHookTypesDev();
7186 return mountDebugValue(value, formatterFn);
7187 },
7188 useResponder: function (responder, props) {
7189 currentHookNameInDev = 'useResponder';
7190 mountHookTypesDev();
7191 return createResponderListener(responder, props);
7192 }
7193 };
7194 HooksDispatcherOnMountWithHookTypesInDEV = {
7195 readContext: function (context, observedBits) {
7196 return readContext(context, observedBits);
7197 },
7198 useCallback: function (callback, deps) {
7199 currentHookNameInDev = 'useCallback';
7200 updateHookTypesDev();
7201 return mountCallback(callback, deps);
7202 },
7203 useContext: function (context, observedBits) {
7204 currentHookNameInDev = 'useContext';
7205 updateHookTypesDev();
7206 return readContext(context, observedBits);
7207 },
7208 useEffect: function (create, deps) {
7209 currentHookNameInDev = 'useEffect';
7210 updateHookTypesDev();
7211 return mountEffect(create, deps);
7212 },
7213 useImperativeHandle: function (ref, create, deps) {
7214 currentHookNameInDev = 'useImperativeHandle';
7215 updateHookTypesDev();
7216 return mountImperativeHandle(ref, create, deps);
7217 },
7218 useLayoutEffect: function (create, deps) {
7219 currentHookNameInDev = 'useLayoutEffect';
7220 updateHookTypesDev();
7221 return mountLayoutEffect(create, deps);
7222 },
7223 useMemo: function (create, deps) {
7224 currentHookNameInDev = 'useMemo';
7225 updateHookTypesDev();
7226 var prevDispatcher = ReactCurrentDispatcher$1.current;
7227 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7228
7229 try {
7230 return mountMemo(create, deps);
7231 } finally {
7232 ReactCurrentDispatcher$1.current = prevDispatcher;
7233 }
7234 },
7235 useReducer: function (reducer, initialArg, init) {
7236 currentHookNameInDev = 'useReducer';
7237 updateHookTypesDev();
7238 var prevDispatcher = ReactCurrentDispatcher$1.current;
7239 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7240
7241 try {
7242 return mountReducer(reducer, initialArg, init);
7243 } finally {
7244 ReactCurrentDispatcher$1.current = prevDispatcher;
7245 }
7246 },
7247 useRef: function (initialValue) {
7248 currentHookNameInDev = 'useRef';
7249 updateHookTypesDev();
7250 return mountRef(initialValue);
7251 },
7252 useState: function (initialState) {
7253 currentHookNameInDev = 'useState';
7254 updateHookTypesDev();
7255 var prevDispatcher = ReactCurrentDispatcher$1.current;
7256 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7257
7258 try {
7259 return mountState(initialState);
7260 } finally {
7261 ReactCurrentDispatcher$1.current = prevDispatcher;
7262 }
7263 },
7264 useDebugValue: function (value, formatterFn) {
7265 currentHookNameInDev = 'useDebugValue';
7266 updateHookTypesDev();
7267 return mountDebugValue(value, formatterFn);
7268 },
7269 useResponder: function (responder, props) {
7270 currentHookNameInDev = 'useResponder';
7271 updateHookTypesDev();
7272 return createResponderListener(responder, props);
7273 }
7274 };
7275 HooksDispatcherOnUpdateInDEV = {
7276 readContext: function (context, observedBits) {
7277 return readContext(context, observedBits);
7278 },
7279 useCallback: function (callback, deps) {
7280 currentHookNameInDev = 'useCallback';
7281 updateHookTypesDev();
7282 return updateCallback(callback, deps);
7283 },
7284 useContext: function (context, observedBits) {
7285 currentHookNameInDev = 'useContext';
7286 updateHookTypesDev();
7287 return readContext(context, observedBits);
7288 },
7289 useEffect: function (create, deps) {
7290 currentHookNameInDev = 'useEffect';
7291 updateHookTypesDev();
7292 return updateEffect(create, deps);
7293 },
7294 useImperativeHandle: function (ref, create, deps) {
7295 currentHookNameInDev = 'useImperativeHandle';
7296 updateHookTypesDev();
7297 return updateImperativeHandle(ref, create, deps);
7298 },
7299 useLayoutEffect: function (create, deps) {
7300 currentHookNameInDev = 'useLayoutEffect';
7301 updateHookTypesDev();
7302 return updateLayoutEffect(create, deps);
7303 },
7304 useMemo: function (create, deps) {
7305 currentHookNameInDev = 'useMemo';
7306 updateHookTypesDev();
7307 var prevDispatcher = ReactCurrentDispatcher$1.current;
7308 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7309
7310 try {
7311 return updateMemo(create, deps);
7312 } finally {
7313 ReactCurrentDispatcher$1.current = prevDispatcher;
7314 }
7315 },
7316 useReducer: function (reducer, initialArg, init) {
7317 currentHookNameInDev = 'useReducer';
7318 updateHookTypesDev();
7319 var prevDispatcher = ReactCurrentDispatcher$1.current;
7320 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7321
7322 try {
7323 return updateReducer(reducer, initialArg, init);
7324 } finally {
7325 ReactCurrentDispatcher$1.current = prevDispatcher;
7326 }
7327 },
7328 useRef: function (initialValue) {
7329 currentHookNameInDev = 'useRef';
7330 updateHookTypesDev();
7331 return updateRef(initialValue);
7332 },
7333 useState: function (initialState) {
7334 currentHookNameInDev = 'useState';
7335 updateHookTypesDev();
7336 var prevDispatcher = ReactCurrentDispatcher$1.current;
7337 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7338
7339 try {
7340 return updateState(initialState);
7341 } finally {
7342 ReactCurrentDispatcher$1.current = prevDispatcher;
7343 }
7344 },
7345 useDebugValue: function (value, formatterFn) {
7346 currentHookNameInDev = 'useDebugValue';
7347 updateHookTypesDev();
7348 return updateDebugValue(value, formatterFn);
7349 },
7350 useResponder: function (responder, props) {
7351 currentHookNameInDev = 'useResponder';
7352 updateHookTypesDev();
7353 return createResponderListener(responder, props);
7354 }
7355 };
7356 InvalidNestedHooksDispatcherOnMountInDEV = {
7357 readContext: function (context, observedBits) {
7358 warnInvalidContextAccess();
7359 return readContext(context, observedBits);
7360 },
7361 useCallback: function (callback, deps) {
7362 currentHookNameInDev = 'useCallback';
7363 warnInvalidHookAccess();
7364 mountHookTypesDev();
7365 return mountCallback(callback, deps);
7366 },
7367 useContext: function (context, observedBits) {
7368 currentHookNameInDev = 'useContext';
7369 warnInvalidHookAccess();
7370 mountHookTypesDev();
7371 return readContext(context, observedBits);
7372 },
7373 useEffect: function (create, deps) {
7374 currentHookNameInDev = 'useEffect';
7375 warnInvalidHookAccess();
7376 mountHookTypesDev();
7377 return mountEffect(create, deps);
7378 },
7379 useImperativeHandle: function (ref, create, deps) {
7380 currentHookNameInDev = 'useImperativeHandle';
7381 warnInvalidHookAccess();
7382 mountHookTypesDev();
7383 return mountImperativeHandle(ref, create, deps);
7384 },
7385 useLayoutEffect: function (create, deps) {
7386 currentHookNameInDev = 'useLayoutEffect';
7387 warnInvalidHookAccess();
7388 mountHookTypesDev();
7389 return mountLayoutEffect(create, deps);
7390 },
7391 useMemo: function (create, deps) {
7392 currentHookNameInDev = 'useMemo';
7393 warnInvalidHookAccess();
7394 mountHookTypesDev();
7395 var prevDispatcher = ReactCurrentDispatcher$1.current;
7396 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7397
7398 try {
7399 return mountMemo(create, deps);
7400 } finally {
7401 ReactCurrentDispatcher$1.current = prevDispatcher;
7402 }
7403 },
7404 useReducer: function (reducer, initialArg, init) {
7405 currentHookNameInDev = 'useReducer';
7406 warnInvalidHookAccess();
7407 mountHookTypesDev();
7408 var prevDispatcher = ReactCurrentDispatcher$1.current;
7409 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7410
7411 try {
7412 return mountReducer(reducer, initialArg, init);
7413 } finally {
7414 ReactCurrentDispatcher$1.current = prevDispatcher;
7415 }
7416 },
7417 useRef: function (initialValue) {
7418 currentHookNameInDev = 'useRef';
7419 warnInvalidHookAccess();
7420 mountHookTypesDev();
7421 return mountRef(initialValue);
7422 },
7423 useState: function (initialState) {
7424 currentHookNameInDev = 'useState';
7425 warnInvalidHookAccess();
7426 mountHookTypesDev();
7427 var prevDispatcher = ReactCurrentDispatcher$1.current;
7428 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7429
7430 try {
7431 return mountState(initialState);
7432 } finally {
7433 ReactCurrentDispatcher$1.current = prevDispatcher;
7434 }
7435 },
7436 useDebugValue: function (value, formatterFn) {
7437 currentHookNameInDev = 'useDebugValue';
7438 warnInvalidHookAccess();
7439 mountHookTypesDev();
7440 return mountDebugValue(value, formatterFn);
7441 },
7442 useResponder: function (responder, props) {
7443 currentHookNameInDev = 'useResponder';
7444 warnInvalidHookAccess();
7445 mountHookTypesDev();
7446 return createResponderListener(responder, props);
7447 }
7448 };
7449 InvalidNestedHooksDispatcherOnUpdateInDEV = {
7450 readContext: function (context, observedBits) {
7451 warnInvalidContextAccess();
7452 return readContext(context, observedBits);
7453 },
7454 useCallback: function (callback, deps) {
7455 currentHookNameInDev = 'useCallback';
7456 warnInvalidHookAccess();
7457 updateHookTypesDev();
7458 return updateCallback(callback, deps);
7459 },
7460 useContext: function (context, observedBits) {
7461 currentHookNameInDev = 'useContext';
7462 warnInvalidHookAccess();
7463 updateHookTypesDev();
7464 return readContext(context, observedBits);
7465 },
7466 useEffect: function (create, deps) {
7467 currentHookNameInDev = 'useEffect';
7468 warnInvalidHookAccess();
7469 updateHookTypesDev();
7470 return updateEffect(create, deps);
7471 },
7472 useImperativeHandle: function (ref, create, deps) {
7473 currentHookNameInDev = 'useImperativeHandle';
7474 warnInvalidHookAccess();
7475 updateHookTypesDev();
7476 return updateImperativeHandle(ref, create, deps);
7477 },
7478 useLayoutEffect: function (create, deps) {
7479 currentHookNameInDev = 'useLayoutEffect';
7480 warnInvalidHookAccess();
7481 updateHookTypesDev();
7482 return updateLayoutEffect(create, deps);
7483 },
7484 useMemo: function (create, deps) {
7485 currentHookNameInDev = 'useMemo';
7486 warnInvalidHookAccess();
7487 updateHookTypesDev();
7488 var prevDispatcher = ReactCurrentDispatcher$1.current;
7489 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7490
7491 try {
7492 return updateMemo(create, deps);
7493 } finally {
7494 ReactCurrentDispatcher$1.current = prevDispatcher;
7495 }
7496 },
7497 useReducer: function (reducer, initialArg, init) {
7498 currentHookNameInDev = 'useReducer';
7499 warnInvalidHookAccess();
7500 updateHookTypesDev();
7501 var prevDispatcher = ReactCurrentDispatcher$1.current;
7502 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7503
7504 try {
7505 return updateReducer(reducer, initialArg, init);
7506 } finally {
7507 ReactCurrentDispatcher$1.current = prevDispatcher;
7508 }
7509 },
7510 useRef: function (initialValue) {
7511 currentHookNameInDev = 'useRef';
7512 warnInvalidHookAccess();
7513 updateHookTypesDev();
7514 return updateRef(initialValue);
7515 },
7516 useState: function (initialState) {
7517 currentHookNameInDev = 'useState';
7518 warnInvalidHookAccess();
7519 updateHookTypesDev();
7520 var prevDispatcher = ReactCurrentDispatcher$1.current;
7521 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7522
7523 try {
7524 return updateState(initialState);
7525 } finally {
7526 ReactCurrentDispatcher$1.current = prevDispatcher;
7527 }
7528 },
7529 useDebugValue: function (value, formatterFn) {
7530 currentHookNameInDev = 'useDebugValue';
7531 warnInvalidHookAccess();
7532 updateHookTypesDev();
7533 return updateDebugValue(value, formatterFn);
7534 },
7535 useResponder: function (responder, props) {
7536 currentHookNameInDev = 'useResponder';
7537 warnInvalidHookAccess();
7538 updateHookTypesDev();
7539 return createResponderListener(responder, props);
7540 }
7541 };
7542}
7543
7544// CommonJS interop named imports.
7545
7546var now$1 = Scheduler$1.unstable_now;
7547var commitTime = 0;
7548var profilerStartTime = -1;
7549
7550function getCommitTime() {
7551 return commitTime;
7552}
7553
7554function recordCommitTime() {
7555 if (!enableProfilerTimer) {
7556 return;
7557 }
7558
7559 commitTime = now$1();
7560}
7561
7562function startProfilerTimer(fiber) {
7563 if (!enableProfilerTimer) {
7564 return;
7565 }
7566
7567 profilerStartTime = now$1();
7568
7569 if (fiber.actualStartTime < 0) {
7570 fiber.actualStartTime = now$1();
7571 }
7572}
7573
7574function stopProfilerTimerIfRunning(fiber) {
7575 if (!enableProfilerTimer) {
7576 return;
7577 }
7578
7579 profilerStartTime = -1;
7580}
7581
7582function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
7583 if (!enableProfilerTimer) {
7584 return;
7585 }
7586
7587 if (profilerStartTime >= 0) {
7588 var elapsedTime = now$1() - profilerStartTime;
7589 fiber.actualDuration += elapsedTime;
7590
7591 if (overrideBaseTime) {
7592 fiber.selfBaseDuration = elapsedTime;
7593 }
7594
7595 profilerStartTime = -1;
7596 }
7597}
7598
7599// This may have been an insertion or a hydration.
7600
7601var hydrationParentFiber = null;
7602var nextHydratableInstance = null;
7603var isHydrating = false;
7604
7605function warnIfHydrating() {
7606 {
7607 !!isHydrating ? warning$1(false, 'We should not be hydrating here. This is a bug in React. Please file a bug.') : void 0;
7608 }
7609}
7610
7611function enterHydrationState(fiber) {
7612 if (!supportsHydration) {
7613 return false;
7614 }
7615
7616 var parentInstance = fiber.stateNode.containerInfo;
7617 nextHydratableInstance = getFirstHydratableChild(parentInstance);
7618 hydrationParentFiber = fiber;
7619 isHydrating = true;
7620 return true;
7621}
7622
7623function reenterHydrationStateFromDehydratedSuspenseInstance(fiber, suspenseInstance) {
7624 if (!supportsHydration) {
7625 return false;
7626 }
7627
7628 nextHydratableInstance = getNextHydratableSibling(suspenseInstance);
7629 popToNextHostParent(fiber);
7630 isHydrating = true;
7631 return true;
7632}
7633
7634function deleteHydratableInstance(returnFiber, instance) {
7635 {
7636 switch (returnFiber.tag) {
7637 case HostRoot:
7638 didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
7639 break;
7640
7641 case HostComponent:
7642 didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
7643 break;
7644 }
7645 }
7646
7647 var childToDelete = createFiberFromHostInstanceForDeletion();
7648 childToDelete.stateNode = instance;
7649 childToDelete.return = returnFiber;
7650 childToDelete.effectTag = Deletion; // This might seem like it belongs on progressedFirstDeletion. However,
7651 // these children are not part of the reconciliation list of children.
7652 // Even if we abort and rereconcile the children, that will try to hydrate
7653 // again and the nodes are still in the host tree so these will be
7654 // recreated.
7655
7656 if (returnFiber.lastEffect !== null) {
7657 returnFiber.lastEffect.nextEffect = childToDelete;
7658 returnFiber.lastEffect = childToDelete;
7659 } else {
7660 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
7661 }
7662}
7663
7664function insertNonHydratedInstance(returnFiber, fiber) {
7665 fiber.effectTag = fiber.effectTag & ~Hydrating | Placement;
7666
7667 {
7668 switch (returnFiber.tag) {
7669 case HostRoot:
7670 {
7671 var parentContainer = returnFiber.stateNode.containerInfo;
7672
7673 switch (fiber.tag) {
7674 case HostComponent:
7675 var type = fiber.type;
7676 var props = fiber.pendingProps;
7677 didNotFindHydratableContainerInstance(parentContainer, type, props);
7678 break;
7679
7680 case HostText:
7681 var text = fiber.pendingProps;
7682 didNotFindHydratableContainerTextInstance(parentContainer, text);
7683 break;
7684
7685 case SuspenseComponent:
7686 didNotFindHydratableContainerSuspenseInstance(parentContainer);
7687 break;
7688 }
7689
7690 break;
7691 }
7692
7693 case HostComponent:
7694 {
7695 var parentType = returnFiber.type;
7696 var parentProps = returnFiber.memoizedProps;
7697 var parentInstance = returnFiber.stateNode;
7698
7699 switch (fiber.tag) {
7700 case HostComponent:
7701 var _type = fiber.type;
7702 var _props = fiber.pendingProps;
7703 didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props);
7704 break;
7705
7706 case HostText:
7707 var _text = fiber.pendingProps;
7708 didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
7709 break;
7710
7711 case SuspenseComponent:
7712 didNotFindHydratableSuspenseInstance(parentType, parentProps, parentInstance);
7713 break;
7714 }
7715
7716 break;
7717 }
7718
7719 default:
7720 return;
7721 }
7722 }
7723}
7724
7725function tryHydrate(fiber, nextInstance) {
7726 switch (fiber.tag) {
7727 case HostComponent:
7728 {
7729 var type = fiber.type;
7730 var props = fiber.pendingProps;
7731 var instance = canHydrateInstance(nextInstance, type, props);
7732
7733 if (instance !== null) {
7734 fiber.stateNode = instance;
7735 return true;
7736 }
7737
7738 return false;
7739 }
7740
7741 case HostText:
7742 {
7743 var text = fiber.pendingProps;
7744 var textInstance = canHydrateTextInstance(nextInstance, text);
7745
7746 if (textInstance !== null) {
7747 fiber.stateNode = textInstance;
7748 return true;
7749 }
7750
7751 return false;
7752 }
7753
7754 case SuspenseComponent:
7755 {
7756 if (enableSuspenseServerRenderer) {
7757 var suspenseInstance = canHydrateSuspenseInstance(nextInstance);
7758
7759 if (suspenseInstance !== null) {
7760 var suspenseState = {
7761 dehydrated: suspenseInstance,
7762 retryTime: Never
7763 };
7764 fiber.memoizedState = suspenseState; // Store the dehydrated fragment as a child fiber.
7765 // This simplifies the code for getHostSibling and deleting nodes,
7766 // since it doesn't have to consider all Suspense boundaries and
7767 // check if they're dehydrated ones or not.
7768
7769 var dehydratedFragment = createFiberFromDehydratedFragment(suspenseInstance);
7770 dehydratedFragment.return = fiber;
7771 fiber.child = dehydratedFragment;
7772 return true;
7773 }
7774 }
7775
7776 return false;
7777 }
7778
7779 default:
7780 return false;
7781 }
7782}
7783
7784function tryToClaimNextHydratableInstance(fiber) {
7785 if (!isHydrating) {
7786 return;
7787 }
7788
7789 var nextInstance = nextHydratableInstance;
7790
7791 if (!nextInstance) {
7792 // Nothing to hydrate. Make it an insertion.
7793 insertNonHydratedInstance(hydrationParentFiber, fiber);
7794 isHydrating = false;
7795 hydrationParentFiber = fiber;
7796 return;
7797 }
7798
7799 var firstAttemptedInstance = nextInstance;
7800
7801 if (!tryHydrate(fiber, nextInstance)) {
7802 // If we can't hydrate this instance let's try the next one.
7803 // We use this as a heuristic. It's based on intuition and not data so it
7804 // might be flawed or unnecessary.
7805 nextInstance = getNextHydratableSibling(firstAttemptedInstance);
7806
7807 if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
7808 // Nothing to hydrate. Make it an insertion.
7809 insertNonHydratedInstance(hydrationParentFiber, fiber);
7810 isHydrating = false;
7811 hydrationParentFiber = fiber;
7812 return;
7813 } // We matched the next one, we'll now assume that the first one was
7814 // superfluous and we'll delete it. Since we can't eagerly delete it
7815 // we'll have to schedule a deletion. To do that, this node needs a dummy
7816 // fiber associated with it.
7817
7818
7819 deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
7820 }
7821
7822 hydrationParentFiber = fiber;
7823 nextHydratableInstance = getFirstHydratableChild(nextInstance);
7824}
7825
7826function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
7827 if (!supportsHydration) {
7828 (function () {
7829 {
7830 {
7831 throw ReactError(Error("Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."));
7832 }
7833 }
7834 })();
7835 }
7836
7837 var instance = fiber.stateNode;
7838 var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber); // TODO: Type this specific to this type of component.
7839
7840 fiber.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
7841 // is a new ref we mark this as an update.
7842
7843 if (updatePayload !== null) {
7844 return true;
7845 }
7846
7847 return false;
7848}
7849
7850function prepareToHydrateHostTextInstance(fiber) {
7851 if (!supportsHydration) {
7852 (function () {
7853 {
7854 {
7855 throw ReactError(Error("Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."));
7856 }
7857 }
7858 })();
7859 }
7860
7861 var textInstance = fiber.stateNode;
7862 var textContent = fiber.memoizedProps;
7863 var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
7864
7865 {
7866 if (shouldUpdate) {
7867 // We assume that prepareToHydrateHostTextInstance is called in a context where the
7868 // hydration parent is the parent host component of this host text.
7869 var returnFiber = hydrationParentFiber;
7870
7871 if (returnFiber !== null) {
7872 switch (returnFiber.tag) {
7873 case HostRoot:
7874 {
7875 var parentContainer = returnFiber.stateNode.containerInfo;
7876 didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
7877 break;
7878 }
7879
7880 case HostComponent:
7881 {
7882 var parentType = returnFiber.type;
7883 var parentProps = returnFiber.memoizedProps;
7884 var parentInstance = returnFiber.stateNode;
7885 didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
7886 break;
7887 }
7888 }
7889 }
7890 }
7891 }
7892
7893 return shouldUpdate;
7894}
7895
7896function prepareToHydrateHostSuspenseInstance(fiber) {
7897 if (!supportsHydration) {
7898 (function () {
7899 {
7900 {
7901 throw ReactError(Error("Expected prepareToHydrateHostSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."));
7902 }
7903 }
7904 })();
7905 }
7906
7907 var suspenseState = fiber.memoizedState;
7908 var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
7909
7910 (function () {
7911 if (!suspenseInstance) {
7912 {
7913 throw ReactError(Error("Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue."));
7914 }
7915 }
7916 })();
7917
7918 hydrateSuspenseInstance(suspenseInstance, fiber);
7919}
7920
7921function skipPastDehydratedSuspenseInstance(fiber) {
7922 if (!supportsHydration) {
7923 (function () {
7924 {
7925 {
7926 throw ReactError(Error("Expected skipPastDehydratedSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."));
7927 }
7928 }
7929 })();
7930 }
7931
7932 var suspenseState = fiber.memoizedState;
7933 var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
7934
7935 (function () {
7936 if (!suspenseInstance) {
7937 {
7938 throw ReactError(Error("Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue."));
7939 }
7940 }
7941 })();
7942
7943 return getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
7944}
7945
7946function popToNextHostParent(fiber) {
7947 var parent = fiber.return;
7948
7949 while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== SuspenseComponent) {
7950 parent = parent.return;
7951 }
7952
7953 hydrationParentFiber = parent;
7954}
7955
7956function popHydrationState(fiber) {
7957 if (!supportsHydration) {
7958 return false;
7959 }
7960
7961 if (fiber !== hydrationParentFiber) {
7962 // We're deeper than the current hydration context, inside an inserted
7963 // tree.
7964 return false;
7965 }
7966
7967 if (!isHydrating) {
7968 // If we're not currently hydrating but we're in a hydration context, then
7969 // we were an insertion and now need to pop up reenter hydration of our
7970 // siblings.
7971 popToNextHostParent(fiber);
7972 isHydrating = true;
7973 return false;
7974 }
7975
7976 var type = fiber.type; // If we have any remaining hydratable nodes, we need to delete them now.
7977 // We only do this deeper than head and body since they tend to have random
7978 // other nodes in them. We also ignore components with pure text content in
7979 // side of them.
7980 // TODO: Better heuristic.
7981
7982 if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
7983 var nextInstance = nextHydratableInstance;
7984
7985 while (nextInstance) {
7986 deleteHydratableInstance(fiber, nextInstance);
7987 nextInstance = getNextHydratableSibling(nextInstance);
7988 }
7989 }
7990
7991 popToNextHostParent(fiber);
7992
7993 if (fiber.tag === SuspenseComponent) {
7994 nextHydratableInstance = skipPastDehydratedSuspenseInstance(fiber);
7995 } else {
7996 nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
7997 }
7998
7999 return true;
8000}
8001
8002function resetHydrationState() {
8003 if (!supportsHydration) {
8004 return;
8005 }
8006
8007 hydrationParentFiber = null;
8008 nextHydratableInstance = null;
8009 isHydrating = false;
8010}
8011
8012var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner;
8013var didReceiveUpdate = false;
8014var didWarnAboutBadClass;
8015var didWarnAboutModulePatternComponent;
8016var didWarnAboutContextTypeOnFunctionComponent;
8017var didWarnAboutGetDerivedStateOnFunctionComponent;
8018var didWarnAboutFunctionRefs;
8019var didWarnAboutReassigningProps;
8020var didWarnAboutMaxDuration;
8021var didWarnAboutRevealOrder;
8022var didWarnAboutTailOptions;
8023var didWarnAboutDefaultPropsOnFunctionComponent;
8024
8025{
8026 didWarnAboutBadClass = {};
8027 didWarnAboutModulePatternComponent = {};
8028 didWarnAboutContextTypeOnFunctionComponent = {};
8029 didWarnAboutGetDerivedStateOnFunctionComponent = {};
8030 didWarnAboutFunctionRefs = {};
8031 didWarnAboutReassigningProps = false;
8032 didWarnAboutMaxDuration = false;
8033 didWarnAboutRevealOrder = {};
8034 didWarnAboutTailOptions = {};
8035 didWarnAboutDefaultPropsOnFunctionComponent = {};
8036}
8037
8038function reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime) {
8039 if (current$$1 === null) {
8040 // If this is a fresh new component that hasn't been rendered yet, we
8041 // won't update its child set by applying minimal side-effects. Instead,
8042 // we will add them all to the child before it gets rendered. That means
8043 // we can optimize this reconciliation pass by not tracking side-effects.
8044 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8045 } else {
8046 // If the current child is the same as the work in progress, it means that
8047 // we haven't yet started any work on these children. Therefore, we use
8048 // the clone algorithm to create a copy of all the current children.
8049 // If we had any progressed work already, that is invalid at this point so
8050 // let's throw it out.
8051 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, nextChildren, renderExpirationTime);
8052 }
8053}
8054
8055function forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime) {
8056 // This function is fork of reconcileChildren. It's used in cases where we
8057 // want to reconcile without matching against the existing set. This has the
8058 // effect of all current children being unmounted; even if the type and key
8059 // are the same, the old child is unmounted and a new child is created.
8060 //
8061 // To do this, we're going to go through the reconcile algorithm twice. In
8062 // the first pass, we schedule a deletion for all the current children by
8063 // passing null.
8064 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime); // In the second pass, we mount the new children. The trick here is that we
8065 // pass null in place of where we usually pass the current child set. This has
8066 // the effect of remounting all children regardless of whether their their
8067 // identity matches.
8068
8069 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8070}
8071
8072function updateForwardRef(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8073 // TODO: current can be non-null here even if the component
8074 // hasn't yet mounted. This happens after the first render suspends.
8075 // We'll need to figure out if this is fine or can cause issues.
8076 {
8077 if (workInProgress.type !== workInProgress.elementType) {
8078 // Lazy component props can't be validated in createElement
8079 // because they're only guaranteed to be resolved here.
8080 var innerPropTypes = Component.propTypes;
8081
8082 if (innerPropTypes) {
8083 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
8084 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8085 }
8086 }
8087 }
8088
8089 var render = Component.render;
8090 var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
8091
8092 var nextChildren;
8093 prepareToReadContext(workInProgress, renderExpirationTime);
8094
8095 {
8096 ReactCurrentOwner$2.current = workInProgress;
8097 setCurrentPhase('render');
8098 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
8099
8100 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8101 // Only double-render components with Hooks
8102 if (workInProgress.memoizedState !== null) {
8103 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
8104 }
8105 }
8106
8107 setCurrentPhase(null);
8108 }
8109
8110 if (current$$1 !== null && !didReceiveUpdate) {
8111 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
8112 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8113 } // React DevTools reads this flag.
8114
8115
8116 workInProgress.effectTag |= PerformedWork;
8117 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8118 return workInProgress.child;
8119}
8120
8121function updateMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
8122 if (current$$1 === null) {
8123 var type = Component.type;
8124
8125 if (isSimpleFunctionComponent(type) && Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
8126 Component.defaultProps === undefined) {
8127 var resolvedType = type;
8128
8129 {
8130 resolvedType = resolveFunctionForHotReloading(type);
8131 } // If this is a plain function component without default props,
8132 // and with only the default shallow comparison, we upgrade it
8133 // to a SimpleMemoComponent to allow fast path updates.
8134
8135
8136 workInProgress.tag = SimpleMemoComponent;
8137 workInProgress.type = resolvedType;
8138
8139 {
8140 validateFunctionComponentInDev(workInProgress, type);
8141 }
8142
8143 return updateSimpleMemoComponent(current$$1, workInProgress, resolvedType, nextProps, updateExpirationTime, renderExpirationTime);
8144 }
8145
8146 {
8147 var innerPropTypes = type.propTypes;
8148
8149 if (innerPropTypes) {
8150 // Inner memo component props aren't currently validated in createElement.
8151 // We could move it there, but we'd still need this for lazy code path.
8152 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
8153 'prop', getComponentName(type), getCurrentFiberStackInDev);
8154 }
8155 }
8156
8157 var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
8158 child.ref = workInProgress.ref;
8159 child.return = workInProgress;
8160 workInProgress.child = child;
8161 return child;
8162 }
8163
8164 {
8165 var _type = Component.type;
8166 var _innerPropTypes = _type.propTypes;
8167
8168 if (_innerPropTypes) {
8169 // Inner memo component props aren't currently validated in createElement.
8170 // We could move it there, but we'd still need this for lazy code path.
8171 checkPropTypes_1(_innerPropTypes, nextProps, // Resolved props
8172 'prop', getComponentName(_type), getCurrentFiberStackInDev);
8173 }
8174 }
8175
8176 var currentChild = current$$1.child; // This is always exactly one child
8177
8178 if (updateExpirationTime < renderExpirationTime) {
8179 // This will be the props with resolved defaultProps,
8180 // unlike current.memoizedProps which will be the unresolved ones.
8181 var prevProps = currentChild.memoizedProps; // Default to shallow comparison
8182
8183 var compare = Component.compare;
8184 compare = compare !== null ? compare : shallowEqual;
8185
8186 if (compare(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
8187 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8188 }
8189 } // React DevTools reads this flag.
8190
8191
8192 workInProgress.effectTag |= PerformedWork;
8193 var newChild = createWorkInProgress(currentChild, nextProps, renderExpirationTime);
8194 newChild.ref = workInProgress.ref;
8195 newChild.return = workInProgress;
8196 workInProgress.child = newChild;
8197 return newChild;
8198}
8199
8200function updateSimpleMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
8201 // TODO: current can be non-null here even if the component
8202 // hasn't yet mounted. This happens when the inner render suspends.
8203 // We'll need to figure out if this is fine or can cause issues.
8204 {
8205 if (workInProgress.type !== workInProgress.elementType) {
8206 // Lazy component props can't be validated in createElement
8207 // because they're only guaranteed to be resolved here.
8208 var outerMemoType = workInProgress.elementType;
8209
8210 if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
8211 // We warn when you define propTypes on lazy()
8212 // so let's just skip over it to find memo() outer wrapper.
8213 // Inner props for memo are validated later.
8214 outerMemoType = refineResolvedLazyComponent(outerMemoType);
8215 }
8216
8217 var outerPropTypes = outerMemoType && outerMemoType.propTypes;
8218
8219 if (outerPropTypes) {
8220 checkPropTypes_1(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
8221 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
8222 } // Inner propTypes will be validated in the function component path.
8223
8224 }
8225 }
8226
8227 if (current$$1 !== null) {
8228 var prevProps = current$$1.memoizedProps;
8229
8230 if (shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref && ( // Prevent bailout if the implementation changed due to hot reload:
8231 workInProgress.type === current$$1.type)) {
8232 didReceiveUpdate = false;
8233
8234 if (updateExpirationTime < renderExpirationTime) {
8235 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8236 }
8237 }
8238 }
8239
8240 return updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
8241}
8242
8243function updateFragment(current$$1, workInProgress, renderExpirationTime) {
8244 var nextChildren = workInProgress.pendingProps;
8245 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8246 return workInProgress.child;
8247}
8248
8249function updateMode(current$$1, workInProgress, renderExpirationTime) {
8250 var nextChildren = workInProgress.pendingProps.children;
8251 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8252 return workInProgress.child;
8253}
8254
8255function updateProfiler(current$$1, workInProgress, renderExpirationTime) {
8256 if (enableProfilerTimer) {
8257 workInProgress.effectTag |= Update;
8258 }
8259
8260 var nextProps = workInProgress.pendingProps;
8261 var nextChildren = nextProps.children;
8262 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8263 return workInProgress.child;
8264}
8265
8266function markRef(current$$1, workInProgress) {
8267 var ref = workInProgress.ref;
8268
8269 if (current$$1 === null && ref !== null || current$$1 !== null && current$$1.ref !== ref) {
8270 // Schedule a Ref effect
8271 workInProgress.effectTag |= Ref;
8272 }
8273}
8274
8275function updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8276 {
8277 if (workInProgress.type !== workInProgress.elementType) {
8278 // Lazy component props can't be validated in createElement
8279 // because they're only guaranteed to be resolved here.
8280 var innerPropTypes = Component.propTypes;
8281
8282 if (innerPropTypes) {
8283 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
8284 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8285 }
8286 }
8287 }
8288
8289 var context;
8290
8291 if (!disableLegacyContext) {
8292 var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
8293 context = getMaskedContext(workInProgress, unmaskedContext);
8294 }
8295
8296 var nextChildren;
8297 prepareToReadContext(workInProgress, renderExpirationTime);
8298
8299 {
8300 ReactCurrentOwner$2.current = workInProgress;
8301 setCurrentPhase('render');
8302 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
8303
8304 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8305 // Only double-render components with Hooks
8306 if (workInProgress.memoizedState !== null) {
8307 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
8308 }
8309 }
8310
8311 setCurrentPhase(null);
8312 }
8313
8314 if (current$$1 !== null && !didReceiveUpdate) {
8315 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
8316 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8317 } // React DevTools reads this flag.
8318
8319
8320 workInProgress.effectTag |= PerformedWork;
8321 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8322 return workInProgress.child;
8323}
8324
8325function updateClassComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8326 {
8327 if (workInProgress.type !== workInProgress.elementType) {
8328 // Lazy component props can't be validated in createElement
8329 // because they're only guaranteed to be resolved here.
8330 var innerPropTypes = Component.propTypes;
8331
8332 if (innerPropTypes) {
8333 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
8334 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8335 }
8336 }
8337 } // Push context providers early to prevent context stack mismatches.
8338 // During mounting we don't know the child context yet as the instance doesn't exist.
8339 // We will invalidate the child context in finishClassComponent() right after rendering.
8340
8341
8342 var hasContext;
8343
8344 if (isContextProvider(Component)) {
8345 hasContext = true;
8346 pushContextProvider(workInProgress);
8347 } else {
8348 hasContext = false;
8349 }
8350
8351 prepareToReadContext(workInProgress, renderExpirationTime);
8352 var instance = workInProgress.stateNode;
8353 var shouldUpdate;
8354
8355 if (instance === null) {
8356 if (current$$1 !== null) {
8357 // An class component without an instance only mounts if it suspended
8358 // inside a non- concurrent tree, in an inconsistent state. We want to
8359 // tree it like a new mount, even though an empty version of it already
8360 // committed. Disconnect the alternate pointers.
8361 current$$1.alternate = null;
8362 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8363
8364 workInProgress.effectTag |= Placement;
8365 } // In the initial pass we might need to construct the instance.
8366
8367
8368 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8369 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8370 shouldUpdate = true;
8371 } else if (current$$1 === null) {
8372 // In a resume, we'll already have an instance we can reuse.
8373 shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8374 } else {
8375 shouldUpdate = updateClassInstance(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
8376 }
8377
8378 var nextUnitOfWork = finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
8379
8380 {
8381 var inst = workInProgress.stateNode;
8382
8383 if (inst.props !== nextProps) {
8384 !didWarnAboutReassigningProps ? warning$1(false, 'It looks like %s is reassigning its own `this.props` while rendering. ' + 'This is not supported and can lead to confusing bugs.', getComponentName(workInProgress.type) || 'a component') : void 0;
8385 didWarnAboutReassigningProps = true;
8386 }
8387 }
8388
8389 return nextUnitOfWork;
8390}
8391
8392function finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
8393 // Refs should update even if shouldComponentUpdate returns false
8394 markRef(current$$1, workInProgress);
8395 var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
8396
8397 if (!shouldUpdate && !didCaptureError) {
8398 // Context providers should defer to sCU for rendering
8399 if (hasContext) {
8400 invalidateContextProvider(workInProgress, Component, false);
8401 }
8402
8403 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8404 }
8405
8406 var instance = workInProgress.stateNode; // Rerender
8407
8408 ReactCurrentOwner$2.current = workInProgress;
8409 var nextChildren;
8410
8411 if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
8412 // If we captured an error, but getDerivedStateFrom catch is not defined,
8413 // unmount all the children. componentDidCatch will schedule an update to
8414 // re-render a fallback. This is temporary until we migrate everyone to
8415 // the new API.
8416 // TODO: Warn in a future release.
8417 nextChildren = null;
8418
8419 if (enableProfilerTimer) {
8420 stopProfilerTimerIfRunning(workInProgress);
8421 }
8422 } else {
8423 {
8424 setCurrentPhase('render');
8425 nextChildren = instance.render();
8426
8427 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8428 instance.render();
8429 }
8430
8431 setCurrentPhase(null);
8432 }
8433 } // React DevTools reads this flag.
8434
8435
8436 workInProgress.effectTag |= PerformedWork;
8437
8438 if (current$$1 !== null && didCaptureError) {
8439 // If we're recovering from an error, reconcile without reusing any of
8440 // the existing children. Conceptually, the normal children and the children
8441 // that are shown on error are two different sets, so we shouldn't reuse
8442 // normal children even if their identities match.
8443 forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime);
8444 } else {
8445 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8446 } // Memoize state using the values we just used to render.
8447 // TODO: Restructure so we never read values from the instance.
8448
8449
8450 workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
8451
8452 if (hasContext) {
8453 invalidateContextProvider(workInProgress, Component, true);
8454 }
8455
8456 return workInProgress.child;
8457}
8458
8459function pushHostRootContext(workInProgress) {
8460 var root = workInProgress.stateNode;
8461
8462 if (root.pendingContext) {
8463 pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
8464 } else if (root.context) {
8465 // Should always be set
8466 pushTopLevelContextObject(workInProgress, root.context, false);
8467 }
8468
8469 pushHostContainer(workInProgress, root.containerInfo);
8470}
8471
8472function updateHostRoot(current$$1, workInProgress, renderExpirationTime) {
8473 pushHostRootContext(workInProgress);
8474 var updateQueue = workInProgress.updateQueue;
8475
8476 (function () {
8477 if (!(updateQueue !== null)) {
8478 {
8479 throw ReactError(Error("If the root does not have an updateQueue, we should have already bailed out. This error is likely caused by a bug in React. Please file an issue."));
8480 }
8481 }
8482 })();
8483
8484 var nextProps = workInProgress.pendingProps;
8485 var prevState = workInProgress.memoizedState;
8486 var prevChildren = prevState !== null ? prevState.element : null;
8487 processUpdateQueue(workInProgress, updateQueue, nextProps, null, renderExpirationTime);
8488 var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
8489 // being called "element".
8490
8491 var nextChildren = nextState.element;
8492
8493 if (nextChildren === prevChildren) {
8494 // If the state is the same as before, that's a bailout because we had
8495 // no work that expires at this time.
8496 resetHydrationState();
8497 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8498 }
8499
8500 var root = workInProgress.stateNode;
8501
8502 if (root.hydrate && enterHydrationState(workInProgress)) {
8503 // If we don't have any current children this might be the first pass.
8504 // We always try to hydrate. If this isn't a hydration pass there won't
8505 // be any children to hydrate which is effectively the same thing as
8506 // not hydrating.
8507 var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8508 workInProgress.child = child;
8509 var node = child;
8510
8511 while (node) {
8512 // Mark each child as hydrating. This is a fast path to know whether this
8513 // tree is part of a hydrating tree. This is used to determine if a child
8514 // node has fully mounted yet, and for scheduling event replaying.
8515 // Conceptually this is similar to Placement in that a new subtree is
8516 // inserted into the React tree here. It just happens to not need DOM
8517 // mutations because it already exists.
8518 node.effectTag = node.effectTag & ~Placement | Hydrating;
8519 node = node.sibling;
8520 }
8521 } else {
8522 // Otherwise reset hydration state in case we aborted and resumed another
8523 // root.
8524 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8525 resetHydrationState();
8526 }
8527
8528 return workInProgress.child;
8529}
8530
8531function updateHostComponent(current$$1, workInProgress, renderExpirationTime) {
8532 pushHostContext(workInProgress);
8533
8534 if (current$$1 === null) {
8535 tryToClaimNextHydratableInstance(workInProgress);
8536 }
8537
8538 var type = workInProgress.type;
8539 var nextProps = workInProgress.pendingProps;
8540 var prevProps = current$$1 !== null ? current$$1.memoizedProps : null;
8541 var nextChildren = nextProps.children;
8542 var isDirectTextChild = shouldSetTextContent(type, nextProps);
8543
8544 if (isDirectTextChild) {
8545 // We special case a direct text child of a host node. This is a common
8546 // case. We won't handle it as a reified child. We will instead handle
8547 // this in the host environment that also have access to this prop. That
8548 // avoids allocating another HostText fiber and traversing it.
8549 nextChildren = null;
8550 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
8551 // If we're switching from a direct text child to a normal child, or to
8552 // empty, we need to schedule the text content to be reset.
8553 workInProgress.effectTag |= ContentReset;
8554 }
8555
8556 markRef(current$$1, workInProgress); // Check the host config to see if the children are offscreen/hidden.
8557
8558 if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(type, nextProps)) {
8559 if (enableSchedulerTracing) {
8560 markSpawnedWork(Never);
8561 } // Schedule this fiber to re-render at offscreen priority. Then bailout.
8562
8563
8564 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
8565 return null;
8566 }
8567
8568 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8569 return workInProgress.child;
8570}
8571
8572function updateHostText(current$$1, workInProgress) {
8573 if (current$$1 === null) {
8574 tryToClaimNextHydratableInstance(workInProgress);
8575 } // Nothing to do here. This is terminal. We'll do the completion step
8576 // immediately after.
8577
8578
8579 return null;
8580}
8581
8582function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
8583 if (_current !== null) {
8584 // An lazy component only mounts if it suspended inside a non-
8585 // concurrent tree, in an inconsistent state. We want to treat it like
8586 // a new mount, even though an empty version of it already committed.
8587 // Disconnect the alternate pointers.
8588 _current.alternate = null;
8589 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8590
8591 workInProgress.effectTag |= Placement;
8592 }
8593
8594 var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
8595 // Cancel and resume right after we know the tag.
8596
8597 cancelWorkTimer(workInProgress);
8598 var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
8599
8600 workInProgress.type = Component;
8601 var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
8602 startWorkTimer(workInProgress);
8603 var resolvedProps = resolveDefaultProps(Component, props);
8604 var child;
8605
8606 switch (resolvedTag) {
8607 case FunctionComponent:
8608 {
8609 {
8610 validateFunctionComponentInDev(workInProgress, Component);
8611 workInProgress.type = Component = resolveFunctionForHotReloading(Component);
8612 }
8613
8614 child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8615 break;
8616 }
8617
8618 case ClassComponent:
8619 {
8620 {
8621 workInProgress.type = Component = resolveClassForHotReloading(Component);
8622 }
8623
8624 child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8625 break;
8626 }
8627
8628 case ForwardRef:
8629 {
8630 {
8631 workInProgress.type = Component = resolveForwardRefForHotReloading(Component);
8632 }
8633
8634 child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8635 break;
8636 }
8637
8638 case MemoComponent:
8639 {
8640 {
8641 if (workInProgress.type !== workInProgress.elementType) {
8642 var outerPropTypes = Component.propTypes;
8643
8644 if (outerPropTypes) {
8645 checkPropTypes_1(outerPropTypes, resolvedProps, // Resolved for outer only
8646 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8647 }
8648 }
8649 }
8650
8651 child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
8652 updateExpirationTime, renderExpirationTime);
8653 break;
8654 }
8655
8656 default:
8657 {
8658 var hint = '';
8659
8660 {
8661 if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
8662 hint = ' Did you wrap a component in React.lazy() more than once?';
8663 }
8664 } // This message intentionally doesn't mention ForwardRef or MemoComponent
8665 // because the fact that it's a separate type of work is an
8666 // implementation detail.
8667
8668
8669 (function () {
8670 {
8671 {
8672 throw ReactError(Error("Element type is invalid. Received a promise that resolves to: " + Component + ". Lazy element type must resolve to a class or function." + hint));
8673 }
8674 }
8675 })();
8676 }
8677 }
8678
8679 return child;
8680}
8681
8682function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
8683 if (_current !== null) {
8684 // An incomplete component only mounts if it suspended inside a non-
8685 // concurrent tree, in an inconsistent state. We want to treat it like
8686 // a new mount, even though an empty version of it already committed.
8687 // Disconnect the alternate pointers.
8688 _current.alternate = null;
8689 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8690
8691 workInProgress.effectTag |= Placement;
8692 } // Promote the fiber to a class and try rendering again.
8693
8694
8695 workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
8696 // Push context providers early to prevent context stack mismatches.
8697 // During mounting we don't know the child context yet as the instance doesn't exist.
8698 // We will invalidate the child context in finishClassComponent() right after rendering.
8699
8700 var hasContext;
8701
8702 if (isContextProvider(Component)) {
8703 hasContext = true;
8704 pushContextProvider(workInProgress);
8705 } else {
8706 hasContext = false;
8707 }
8708
8709 prepareToReadContext(workInProgress, renderExpirationTime);
8710 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8711 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8712 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
8713}
8714
8715function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
8716 if (_current !== null) {
8717 // An indeterminate component only mounts if it suspended inside a non-
8718 // concurrent tree, in an inconsistent state. We want to treat it like
8719 // a new mount, even though an empty version of it already committed.
8720 // Disconnect the alternate pointers.
8721 _current.alternate = null;
8722 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8723
8724 workInProgress.effectTag |= Placement;
8725 }
8726
8727 var props = workInProgress.pendingProps;
8728 var context;
8729
8730 if (!disableLegacyContext) {
8731 var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
8732 context = getMaskedContext(workInProgress, unmaskedContext);
8733 }
8734
8735 prepareToReadContext(workInProgress, renderExpirationTime);
8736 var value;
8737
8738 {
8739 if (Component.prototype && typeof Component.prototype.render === 'function') {
8740 var componentName = getComponentName(Component) || 'Unknown';
8741
8742 if (!didWarnAboutBadClass[componentName]) {
8743 warningWithoutStack$1(false, "The <%s /> component appears to have a render method, but doesn't extend React.Component. " + 'This is likely to cause errors. Change %s to extend React.Component instead.', componentName, componentName);
8744 didWarnAboutBadClass[componentName] = true;
8745 }
8746 }
8747
8748 if (workInProgress.mode & StrictMode) {
8749 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
8750 }
8751
8752 ReactCurrentOwner$2.current = workInProgress;
8753 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
8754 } // React DevTools reads this flag.
8755
8756
8757 workInProgress.effectTag |= PerformedWork;
8758
8759 if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
8760 {
8761 var _componentName = getComponentName(Component) || 'Unknown';
8762
8763 if (!didWarnAboutModulePatternComponent[_componentName]) {
8764 warningWithoutStack$1(false, 'The <%s /> component appears to be a function component that returns a class instance. ' + 'Change %s to a class that extends React.Component instead. ' + "If you can't use a class try assigning the prototype on the function as a workaround. " + "`%s.prototype = React.Component.prototype`. Don't use an arrow function since it " + 'cannot be called with `new` by React.', _componentName, _componentName, _componentName);
8765 didWarnAboutModulePatternComponent[_componentName] = true;
8766 }
8767 } // Proceed under the assumption that this is a class instance
8768
8769
8770 workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
8771
8772 resetHooks(); // Push context providers early to prevent context stack mismatches.
8773 // During mounting we don't know the child context yet as the instance doesn't exist.
8774 // We will invalidate the child context in finishClassComponent() right after rendering.
8775
8776 var hasContext = false;
8777
8778 if (isContextProvider(Component)) {
8779 hasContext = true;
8780 pushContextProvider(workInProgress);
8781 } else {
8782 hasContext = false;
8783 }
8784
8785 workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
8786 var getDerivedStateFromProps = Component.getDerivedStateFromProps;
8787
8788 if (typeof getDerivedStateFromProps === 'function') {
8789 applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
8790 }
8791
8792 adoptClassInstance(workInProgress, value);
8793 mountClassInstance(workInProgress, Component, props, renderExpirationTime);
8794 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
8795 } else {
8796 // Proceed under the assumption that this is a function component
8797 workInProgress.tag = FunctionComponent;
8798
8799 {
8800 if (disableLegacyContext && Component.contextTypes) {
8801 warningWithoutStack$1(false, '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with React.useContext() instead.', getComponentName(Component) || 'Unknown');
8802 }
8803
8804 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8805 // Only double-render components with Hooks
8806 if (workInProgress.memoizedState !== null) {
8807 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
8808 }
8809 }
8810 }
8811
8812 reconcileChildren(null, workInProgress, value, renderExpirationTime);
8813
8814 {
8815 validateFunctionComponentInDev(workInProgress, Component);
8816 }
8817
8818 return workInProgress.child;
8819 }
8820}
8821
8822function validateFunctionComponentInDev(workInProgress, Component) {
8823 if (Component) {
8824 !!Component.childContextTypes ? warningWithoutStack$1(false, '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component') : void 0;
8825 }
8826
8827 if (workInProgress.ref !== null) {
8828 var info = '';
8829 var ownerName = getCurrentFiberOwnerNameInDevOrNull();
8830
8831 if (ownerName) {
8832 info += '\n\nCheck the render method of `' + ownerName + '`.';
8833 }
8834
8835 var warningKey = ownerName || workInProgress._debugID || '';
8836 var debugSource = workInProgress._debugSource;
8837
8838 if (debugSource) {
8839 warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
8840 }
8841
8842 if (!didWarnAboutFunctionRefs[warningKey]) {
8843 didWarnAboutFunctionRefs[warningKey] = true;
8844 warning$1(false, 'Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info);
8845 }
8846 }
8847
8848 if (warnAboutDefaultPropsOnFunctionComponents && Component.defaultProps !== undefined) {
8849 var componentName = getComponentName(Component) || 'Unknown';
8850
8851 if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {
8852 warningWithoutStack$1(false, '%s: Support for defaultProps will be removed from function components ' + 'in a future major release. Use JavaScript default parameters instead.', componentName);
8853 didWarnAboutDefaultPropsOnFunctionComponent[componentName] = true;
8854 }
8855 }
8856
8857 if (typeof Component.getDerivedStateFromProps === 'function') {
8858 var _componentName2 = getComponentName(Component) || 'Unknown';
8859
8860 if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
8861 warningWithoutStack$1(false, '%s: Function components do not support getDerivedStateFromProps.', _componentName2);
8862 didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
8863 }
8864 }
8865
8866 if (typeof Component.contextType === 'object' && Component.contextType !== null) {
8867 var _componentName3 = getComponentName(Component) || 'Unknown';
8868
8869 if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
8870 warningWithoutStack$1(false, '%s: Function components do not support contextType.', _componentName3);
8871 didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
8872 }
8873 }
8874}
8875
8876var SUSPENDED_MARKER = {
8877 dehydrated: null,
8878 retryTime: Never
8879};
8880
8881function shouldRemainOnFallback(suspenseContext, current$$1, workInProgress) {
8882 // If the context is telling us that we should show a fallback, and we're not
8883 // already showing content, then we should show the fallback instead.
8884 return hasSuspenseContext(suspenseContext, ForceSuspenseFallback) && (current$$1 === null || current$$1.memoizedState !== null);
8885}
8886
8887function updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
8888 var mode = workInProgress.mode;
8889 var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
8890
8891 {
8892 if (shouldSuspend(workInProgress)) {
8893 workInProgress.effectTag |= DidCapture;
8894 }
8895 }
8896
8897 var suspenseContext = suspenseStackCursor.current;
8898 var nextDidTimeout = false;
8899 var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
8900
8901 if (didSuspend || shouldRemainOnFallback(suspenseContext, current$$1, workInProgress)) {
8902 // Something in this boundary's subtree already suspended. Switch to
8903 // rendering the fallback children.
8904 nextDidTimeout = true;
8905 workInProgress.effectTag &= ~DidCapture;
8906 } else {
8907 // Attempting the main content
8908 if (current$$1 === null || current$$1.memoizedState !== null) {
8909 // This is a new mount or this boundary is already showing a fallback state.
8910 // Mark this subtree context as having at least one invisible parent that could
8911 // handle the fallback state.
8912 // Boundaries without fallbacks or should be avoided are not considered since
8913 // they cannot handle preferred fallback states.
8914 if (nextProps.fallback !== undefined && nextProps.unstable_avoidThisFallback !== true) {
8915 suspenseContext = addSubtreeSuspenseContext(suspenseContext, InvisibleParentSuspenseContext);
8916 }
8917 }
8918 }
8919
8920 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
8921 pushSuspenseContext(workInProgress, suspenseContext);
8922
8923 {
8924 if ('maxDuration' in nextProps) {
8925 if (!didWarnAboutMaxDuration) {
8926 didWarnAboutMaxDuration = true;
8927 warning$1(false, 'maxDuration has been removed from React. ' + 'Remove the maxDuration prop.');
8928 }
8929 }
8930 } // This next part is a bit confusing. If the children timeout, we switch to
8931 // showing the fallback children in place of the "primary" children.
8932 // However, we don't want to delete the primary children because then their
8933 // state will be lost (both the React state and the host state, e.g.
8934 // uncontrolled form inputs). Instead we keep them mounted and hide them.
8935 // Both the fallback children AND the primary children are rendered at the
8936 // same time. Once the primary children are un-suspended, we can delete
8937 // the fallback children — don't need to preserve their state.
8938 //
8939 // The two sets of children are siblings in the host environment, but
8940 // semantically, for purposes of reconciliation, they are two separate sets.
8941 // So we store them using two fragment fibers.
8942 //
8943 // However, we want to avoid allocating extra fibers for every placeholder.
8944 // They're only necessary when the children time out, because that's the
8945 // only time when both sets are mounted.
8946 //
8947 // So, the extra fragment fibers are only used if the children time out.
8948 // Otherwise, we render the primary children directly. This requires some
8949 // custom reconciliation logic to preserve the state of the primary
8950 // children. It's essentially a very basic form of re-parenting.
8951
8952
8953 if (current$$1 === null) {
8954 if (enableSuspenseServerRenderer) {
8955 // If we're currently hydrating, try to hydrate this boundary.
8956 // But only if this has a fallback.
8957 if (nextProps.fallback !== undefined) {
8958 tryToClaimNextHydratableInstance(workInProgress); // This could've been a dehydrated suspense component.
8959
8960 var suspenseState = workInProgress.memoizedState;
8961
8962 if (suspenseState !== null) {
8963 var dehydrated = suspenseState.dehydrated;
8964
8965 if (dehydrated !== null) {
8966 return mountDehydratedSuspenseComponent(workInProgress, dehydrated, renderExpirationTime);
8967 }
8968 }
8969 }
8970 } // This is the initial mount. This branch is pretty simple because there's
8971 // no previous state that needs to be preserved.
8972
8973
8974 if (nextDidTimeout) {
8975 // Mount separate fragments for primary and fallback children.
8976 var nextFallbackChildren = nextProps.fallback;
8977 var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
8978 primaryChildFragment.return = workInProgress;
8979
8980 if ((workInProgress.mode & BatchedMode) === NoMode) {
8981 // Outside of batched mode, we commit the effects from the
8982 // partially completed, timed-out tree, too.
8983 var progressedState = workInProgress.memoizedState;
8984 var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
8985 primaryChildFragment.child = progressedPrimaryChild;
8986 var progressedChild = progressedPrimaryChild;
8987
8988 while (progressedChild !== null) {
8989 progressedChild.return = primaryChildFragment;
8990 progressedChild = progressedChild.sibling;
8991 }
8992 }
8993
8994 var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
8995 fallbackChildFragment.return = workInProgress;
8996 primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
8997 // fallback children.
8998
8999 workInProgress.memoizedState = SUSPENDED_MARKER;
9000 workInProgress.child = primaryChildFragment;
9001 return fallbackChildFragment;
9002 } else {
9003 // Mount the primary children without an intermediate fragment fiber.
9004 var nextPrimaryChildren = nextProps.children;
9005 workInProgress.memoizedState = null;
9006 return workInProgress.child = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
9007 }
9008 } else {
9009 // This is an update. This branch is more complicated because we need to
9010 // ensure the state of the primary children is preserved.
9011 var prevState = current$$1.memoizedState;
9012
9013 if (prevState !== null) {
9014 if (enableSuspenseServerRenderer) {
9015 var _dehydrated = prevState.dehydrated;
9016
9017 if (_dehydrated !== null) {
9018 if (!didSuspend) {
9019 return updateDehydratedSuspenseComponent(current$$1, workInProgress, _dehydrated, prevState, renderExpirationTime);
9020 } else if (workInProgress.memoizedState !== null) {
9021 // Something suspended and we should still be in dehydrated mode.
9022 // Leave the existing child in place.
9023 workInProgress.child = current$$1.child; // The dehydrated completion pass expects this flag to be there
9024 // but the normal suspense pass doesn't.
9025
9026 workInProgress.effectTag |= DidCapture;
9027 return null;
9028 } else {
9029 // Suspended but we should no longer be in dehydrated mode.
9030 // Therefore we now have to render the fallback. Wrap the children
9031 // in a fragment fiber to keep them separate from the fallback
9032 // children.
9033 var _nextFallbackChildren = nextProps.fallback;
9034
9035 var _primaryChildFragment = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
9036 // going to render this fragment.
9037 null, mode, NoWork, null);
9038
9039 _primaryChildFragment.return = workInProgress; // This is always null since we never want the previous child
9040 // that we're not going to hydrate.
9041
9042 _primaryChildFragment.child = null;
9043
9044 if ((workInProgress.mode & BatchedMode) === NoMode) {
9045 // Outside of batched mode, we commit the effects from the
9046 // partially completed, timed-out tree, too.
9047 var _progressedChild = _primaryChildFragment.child = workInProgress.child;
9048
9049 while (_progressedChild !== null) {
9050 _progressedChild.return = _primaryChildFragment;
9051 _progressedChild = _progressedChild.sibling;
9052 }
9053 } else {
9054 // We will have dropped the effect list which contains the deletion.
9055 // We need to reconcile to delete the current child.
9056 reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime);
9057 } // Because primaryChildFragment is a new fiber that we're inserting as the
9058 // parent of a new tree, we need to set its treeBaseDuration.
9059
9060
9061 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9062 // treeBaseDuration is the sum of all the child tree base durations.
9063 var treeBaseDuration = 0;
9064 var hiddenChild = _primaryChildFragment.child;
9065
9066 while (hiddenChild !== null) {
9067 treeBaseDuration += hiddenChild.treeBaseDuration;
9068 hiddenChild = hiddenChild.sibling;
9069 }
9070
9071 _primaryChildFragment.treeBaseDuration = treeBaseDuration;
9072 } // Create a fragment from the fallback children, too.
9073
9074
9075 var _fallbackChildFragment = createFiberFromFragment(_nextFallbackChildren, mode, renderExpirationTime, null);
9076
9077 _fallbackChildFragment.return = workInProgress;
9078 _primaryChildFragment.sibling = _fallbackChildFragment;
9079 _fallbackChildFragment.effectTag |= Placement;
9080 _primaryChildFragment.childExpirationTime = NoWork;
9081 workInProgress.memoizedState = SUSPENDED_MARKER;
9082 workInProgress.child = _primaryChildFragment; // Skip the primary children, and continue working on the
9083 // fallback children.
9084
9085 return _fallbackChildFragment;
9086 }
9087 }
9088 } // The current tree already timed out. That means each child set is
9089 // wrapped in a fragment fiber.
9090
9091
9092 var currentPrimaryChildFragment = current$$1.child;
9093 var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
9094
9095 if (nextDidTimeout) {
9096 // Still timed out. Reuse the current primary children by cloning
9097 // its fragment. We're going to skip over these entirely.
9098 var _nextFallbackChildren2 = nextProps.fallback;
9099
9100 var _primaryChildFragment2 = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps, NoWork);
9101
9102 _primaryChildFragment2.return = workInProgress;
9103
9104 if ((workInProgress.mode & BatchedMode) === NoMode) {
9105 // Outside of batched mode, we commit the effects from the
9106 // partially completed, timed-out tree, too.
9107 var _progressedState = workInProgress.memoizedState;
9108
9109 var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
9110
9111 if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
9112 _primaryChildFragment2.child = _progressedPrimaryChild;
9113 var _progressedChild2 = _progressedPrimaryChild;
9114
9115 while (_progressedChild2 !== null) {
9116 _progressedChild2.return = _primaryChildFragment2;
9117 _progressedChild2 = _progressedChild2.sibling;
9118 }
9119 }
9120 } // Because primaryChildFragment is a new fiber that we're inserting as the
9121 // parent of a new tree, we need to set its treeBaseDuration.
9122
9123
9124 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9125 // treeBaseDuration is the sum of all the child tree base durations.
9126 var _treeBaseDuration = 0;
9127 var _hiddenChild = _primaryChildFragment2.child;
9128
9129 while (_hiddenChild !== null) {
9130 _treeBaseDuration += _hiddenChild.treeBaseDuration;
9131 _hiddenChild = _hiddenChild.sibling;
9132 }
9133
9134 _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
9135 } // Clone the fallback child fragment, too. These we'll continue
9136 // working on.
9137
9138
9139 var _fallbackChildFragment2 = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren2, currentFallbackChildFragment.expirationTime);
9140
9141 _fallbackChildFragment2.return = workInProgress;
9142 _primaryChildFragment2.sibling = _fallbackChildFragment2;
9143 _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
9144 // fallback children.
9145
9146 workInProgress.memoizedState = SUSPENDED_MARKER;
9147 workInProgress.child = _primaryChildFragment2;
9148 return _fallbackChildFragment2;
9149 } else {
9150 // No longer suspended. Switch back to showing the primary children,
9151 // and remove the intermediate fragment fiber.
9152 var _nextPrimaryChildren = nextProps.children;
9153 var currentPrimaryChild = currentPrimaryChildFragment.child;
9154 var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime); // If this render doesn't suspend, we need to delete the fallback
9155 // children. Wait until the complete phase, after we've confirmed the
9156 // fallback is no longer needed.
9157 // TODO: Would it be better to store the fallback fragment on
9158 // the stateNode?
9159 // Continue rendering the children, like we normally do.
9160
9161 workInProgress.memoizedState = null;
9162 return workInProgress.child = primaryChild;
9163 }
9164 } else {
9165 // The current tree has not already timed out. That means the primary
9166 // children are not wrapped in a fragment fiber.
9167 var _currentPrimaryChild = current$$1.child;
9168
9169 if (nextDidTimeout) {
9170 // Timed out. Wrap the children in a fragment fiber to keep them
9171 // separate from the fallback children.
9172 var _nextFallbackChildren3 = nextProps.fallback;
9173
9174 var _primaryChildFragment3 = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
9175 // going to render this fragment.
9176 null, mode, NoWork, null);
9177
9178 _primaryChildFragment3.return = workInProgress;
9179 _primaryChildFragment3.child = _currentPrimaryChild;
9180
9181 if (_currentPrimaryChild !== null) {
9182 _currentPrimaryChild.return = _primaryChildFragment3;
9183 } // Even though we're creating a new fiber, there are no new children,
9184 // because we're reusing an already mounted tree. So we don't need to
9185 // schedule a placement.
9186 // primaryChildFragment.effectTag |= Placement;
9187
9188
9189 if ((workInProgress.mode & BatchedMode) === NoMode) {
9190 // Outside of batched mode, we commit the effects from the
9191 // partially completed, timed-out tree, too.
9192 var _progressedState2 = workInProgress.memoizedState;
9193
9194 var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
9195
9196 _primaryChildFragment3.child = _progressedPrimaryChild2;
9197 var _progressedChild3 = _progressedPrimaryChild2;
9198
9199 while (_progressedChild3 !== null) {
9200 _progressedChild3.return = _primaryChildFragment3;
9201 _progressedChild3 = _progressedChild3.sibling;
9202 }
9203 } // Because primaryChildFragment is a new fiber that we're inserting as the
9204 // parent of a new tree, we need to set its treeBaseDuration.
9205
9206
9207 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9208 // treeBaseDuration is the sum of all the child tree base durations.
9209 var _treeBaseDuration2 = 0;
9210 var _hiddenChild2 = _primaryChildFragment3.child;
9211
9212 while (_hiddenChild2 !== null) {
9213 _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
9214 _hiddenChild2 = _hiddenChild2.sibling;
9215 }
9216
9217 _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
9218 } // Create a fragment from the fallback children, too.
9219
9220
9221 var _fallbackChildFragment3 = createFiberFromFragment(_nextFallbackChildren3, mode, renderExpirationTime, null);
9222
9223 _fallbackChildFragment3.return = workInProgress;
9224 _primaryChildFragment3.sibling = _fallbackChildFragment3;
9225 _fallbackChildFragment3.effectTag |= Placement;
9226 _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
9227 // fallback children.
9228
9229 workInProgress.memoizedState = SUSPENDED_MARKER;
9230 workInProgress.child = _primaryChildFragment3;
9231 return _fallbackChildFragment3;
9232 } else {
9233 // Still haven't timed out. Continue rendering the children, like we
9234 // normally do.
9235 workInProgress.memoizedState = null;
9236 var _nextPrimaryChildren2 = nextProps.children;
9237 return workInProgress.child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
9238 }
9239 }
9240 }
9241}
9242
9243function retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime) {
9244 // We're now not suspended nor dehydrated.
9245 workInProgress.memoizedState = null; // Retry with the full children.
9246
9247 var nextProps = workInProgress.pendingProps;
9248 var nextChildren = nextProps.children; // This will ensure that the children get Placement effects and
9249 // that the old child gets a Deletion effect.
9250 // We could also call forceUnmountCurrentAndReconcile.
9251
9252 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9253 return workInProgress.child;
9254}
9255
9256function mountDehydratedSuspenseComponent(workInProgress, suspenseInstance, renderExpirationTime) {
9257 // During the first pass, we'll bail out and not drill into the children.
9258 // Instead, we'll leave the content in place and try to hydrate it later.
9259 if ((workInProgress.mode & BatchedMode) === NoMode) {
9260 {
9261 warning$1(false, 'Cannot hydrate Suspense in legacy mode. Switch from ' + 'ReactDOM.hydrate(element, container) to ' + 'ReactDOM.unstable_createSyncRoot(container, { hydrate: true })' + '.render(element) or remove the Suspense components from ' + 'the server rendered components.');
9262 }
9263
9264 workInProgress.expirationTime = Sync;
9265 } else if (isSuspenseInstanceFallback(suspenseInstance)) {
9266 // This is a client-only boundary. Since we won't get any content from the server
9267 // for this, we need to schedule that at a higher priority based on when it would
9268 // have timed out. In theory we could render it in this pass but it would have the
9269 // wrong priority associated with it and will prevent hydration of parent path.
9270 // Instead, we'll leave work left on it to render it in a separate commit.
9271 // TODO This time should be the time at which the server rendered response that is
9272 // a parent to this boundary was displayed. However, since we currently don't have
9273 // a protocol to transfer that time, we'll just estimate it by using the current
9274 // time. This will mean that Suspense timeouts are slightly shifted to later than
9275 // they should be.
9276 var serverDisplayTime = requestCurrentTime(); // Schedule a normal pri update to render this content.
9277
9278 var newExpirationTime = computeAsyncExpiration(serverDisplayTime);
9279
9280 if (enableSchedulerTracing) {
9281 markSpawnedWork(newExpirationTime);
9282 }
9283
9284 workInProgress.expirationTime = newExpirationTime;
9285 } else {
9286 // We'll continue hydrating the rest at offscreen priority since we'll already
9287 // be showing the right content coming from the server, it is no rush.
9288 workInProgress.expirationTime = Never;
9289
9290 if (enableSchedulerTracing) {
9291 markSpawnedWork(Never);
9292 }
9293 }
9294
9295 return null;
9296}
9297
9298function updateDehydratedSuspenseComponent(current$$1, workInProgress, suspenseInstance, suspenseState, renderExpirationTime) {
9299 // We should never be hydrating at this point because it is the first pass,
9300 // but after we've already committed once.
9301 warnIfHydrating();
9302
9303 if ((workInProgress.mode & BatchedMode) === NoMode) {
9304 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9305 }
9306
9307 if (isSuspenseInstanceFallback(suspenseInstance)) {
9308 // This boundary is in a permanent fallback state. In this case, we'll never
9309 // get an update and we'll never be able to hydrate the final content. Let's just try the
9310 // client side render instead.
9311 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9312 } // We use childExpirationTime to indicate that a child might depend on context, so if
9313 // any context has changed, we need to treat is as if the input might have changed.
9314
9315
9316 var hasContextChanged$$1 = current$$1.childExpirationTime >= renderExpirationTime;
9317
9318 if (didReceiveUpdate || hasContextChanged$$1) {
9319 // This boundary has changed since the first render. This means that we are now unable to
9320 // hydrate it. We might still be able to hydrate it using an earlier expiration time, if
9321 // we are rendering at lower expiration than sync.
9322 if (renderExpirationTime < Sync) {
9323 if (suspenseState.retryTime <= renderExpirationTime) {
9324 // This render is even higher pri than we've seen before, let's try again
9325 // at even higher pri.
9326 var attemptHydrationAtExpirationTime = renderExpirationTime + 1;
9327 suspenseState.retryTime = attemptHydrationAtExpirationTime;
9328 scheduleWork(current$$1, attemptHydrationAtExpirationTime); // TODO: Early abort this render.
9329 } else {// We have already tried to ping at a higher priority than we're rendering with
9330 // so if we got here, we must have failed to hydrate at those levels. We must
9331 // now give up. Instead, we're going to delete the whole subtree and instead inject
9332 // a new real Suspense boundary to take its place, which may render content
9333 // or fallback. This might suspend for a while and if it does we might still have
9334 // an opportunity to hydrate before this pass commits.
9335 }
9336 } // If we have scheduled higher pri work above, this will probably just abort the render
9337 // since we now have higher priority work, but in case it doesn't, we need to prepare to
9338 // render something, if we time out. Even if that requires us to delete everything and
9339 // skip hydration.
9340 // Delay having to do this as long as the suspense timeout allows us.
9341
9342
9343 renderDidSuspendDelayIfPossible();
9344 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9345 } else if (isSuspenseInstancePending(suspenseInstance)) {
9346 // This component is still pending more data from the server, so we can't hydrate its
9347 // content. We treat it as if this component suspended itself. It might seem as if
9348 // we could just try to render it client-side instead. However, this will perform a
9349 // lot of unnecessary work and is unlikely to complete since it often will suspend
9350 // on missing data anyway. Additionally, the server might be able to render more
9351 // than we can on the client yet. In that case we'd end up with more fallback states
9352 // on the client than if we just leave it alone. If the server times out or errors
9353 // these should update this boundary to the permanent Fallback state instead.
9354 // Mark it as having captured (i.e. suspended).
9355 workInProgress.effectTag |= DidCapture; // Leave the child in place. I.e. the dehydrated fragment.
9356
9357 workInProgress.child = current$$1.child; // Register a callback to retry this boundary once the server has sent the result.
9358
9359 registerSuspenseInstanceRetry(suspenseInstance, retryDehydratedSuspenseBoundary.bind(null, current$$1));
9360 return null;
9361 } else {
9362 // This is the first attempt.
9363 reenterHydrationStateFromDehydratedSuspenseInstance(workInProgress, suspenseInstance);
9364 var nextProps = workInProgress.pendingProps;
9365 var nextChildren = nextProps.children;
9366 var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
9367 var node = child;
9368
9369 while (node) {
9370 // Mark each child as hydrating. This is a fast path to know whether this
9371 // tree is part of a hydrating tree. This is used to determine if a child
9372 // node has fully mounted yet, and for scheduling event replaying.
9373 // Conceptually this is similar to Placement in that a new subtree is
9374 // inserted into the React tree here. It just happens to not need DOM
9375 // mutations because it already exists.
9376 node.effectTag |= Hydrating;
9377 node = node.sibling;
9378 }
9379
9380 workInProgress.child = child;
9381 return workInProgress.child;
9382 }
9383}
9384
9385function propagateSuspenseContextChange(workInProgress, firstChild, renderExpirationTime) {
9386 // Mark any Suspense boundaries with fallbacks as having work to do.
9387 // If they were previously forced into fallbacks, they may now be able
9388 // to unblock.
9389 var node = firstChild;
9390
9391 while (node !== null) {
9392 if (node.tag === SuspenseComponent) {
9393 var state = node.memoizedState;
9394
9395 if (state !== null) {
9396 if (node.expirationTime < renderExpirationTime) {
9397 node.expirationTime = renderExpirationTime;
9398 }
9399
9400 var alternate = node.alternate;
9401
9402 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
9403 alternate.expirationTime = renderExpirationTime;
9404 }
9405
9406 scheduleWorkOnParentPath(node.return, renderExpirationTime);
9407 }
9408 } else if (node.child !== null) {
9409 node.child.return = node;
9410 node = node.child;
9411 continue;
9412 }
9413
9414 if (node === workInProgress) {
9415 return;
9416 }
9417
9418 while (node.sibling === null) {
9419 if (node.return === null || node.return === workInProgress) {
9420 return;
9421 }
9422
9423 node = node.return;
9424 }
9425
9426 node.sibling.return = node.return;
9427 node = node.sibling;
9428 }
9429}
9430
9431function findLastContentRow(firstChild) {
9432 // This is going to find the last row among these children that is already
9433 // showing content on the screen, as opposed to being in fallback state or
9434 // new. If a row has multiple Suspense boundaries, any of them being in the
9435 // fallback state, counts as the whole row being in a fallback state.
9436 // Note that the "rows" will be workInProgress, but any nested children
9437 // will still be current since we haven't rendered them yet. The mounted
9438 // order may not be the same as the new order. We use the new order.
9439 var row = firstChild;
9440 var lastContentRow = null;
9441
9442 while (row !== null) {
9443 var currentRow = row.alternate; // New rows can't be content rows.
9444
9445 if (currentRow !== null && findFirstSuspended(currentRow) === null) {
9446 lastContentRow = row;
9447 }
9448
9449 row = row.sibling;
9450 }
9451
9452 return lastContentRow;
9453}
9454
9455function validateRevealOrder(revealOrder) {
9456 {
9457 if (revealOrder !== undefined && revealOrder !== 'forwards' && revealOrder !== 'backwards' && revealOrder !== 'together' && !didWarnAboutRevealOrder[revealOrder]) {
9458 didWarnAboutRevealOrder[revealOrder] = true;
9459
9460 if (typeof revealOrder === 'string') {
9461 switch (revealOrder.toLowerCase()) {
9462 case 'together':
9463 case 'forwards':
9464 case 'backwards':
9465 {
9466 warning$1(false, '"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'Use lowercase "%s" instead.', revealOrder, revealOrder.toLowerCase());
9467 break;
9468 }
9469
9470 case 'forward':
9471 case 'backward':
9472 {
9473 warning$1(false, '"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'React uses the -s suffix in the spelling. Use "%ss" instead.', revealOrder, revealOrder.toLowerCase());
9474 break;
9475 }
9476
9477 default:
9478 warning$1(false, '"%s" is not a supported revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
9479 break;
9480 }
9481 } else {
9482 warning$1(false, '%s is not a supported value for revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
9483 }
9484 }
9485 }
9486}
9487
9488function validateTailOptions(tailMode, revealOrder) {
9489 {
9490 if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
9491 if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
9492 didWarnAboutTailOptions[tailMode] = true;
9493 warning$1(false, '"%s" is not a supported value for tail on <SuspenseList />. ' + 'Did you mean "collapsed" or "hidden"?', tailMode);
9494 } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
9495 didWarnAboutTailOptions[tailMode] = true;
9496 warning$1(false, '<SuspenseList tail="%s" /> is only valid if revealOrder is ' + '"forwards" or "backwards". ' + 'Did you mean to specify revealOrder="forwards"?', tailMode);
9497 }
9498 }
9499 }
9500}
9501
9502function validateSuspenseListNestedChild(childSlot, index) {
9503 {
9504 var isArray = Array.isArray(childSlot);
9505 var isIterable = !isArray && typeof getIteratorFn(childSlot) === 'function';
9506
9507 if (isArray || isIterable) {
9508 var type = isArray ? 'array' : 'iterable';
9509 warning$1(false, 'A nested %s was passed to row #%s in <SuspenseList />. Wrap it in ' + 'an additional SuspenseList to configure its revealOrder: ' + '<SuspenseList revealOrder=...> ... ' + '<SuspenseList revealOrder=...>{%s}</SuspenseList> ... ' + '</SuspenseList>', type, index, type);
9510 return false;
9511 }
9512 }
9513
9514 return true;
9515}
9516
9517function validateSuspenseListChildren(children, revealOrder) {
9518 {
9519 if ((revealOrder === 'forwards' || revealOrder === 'backwards') && children !== undefined && children !== null && children !== false) {
9520 if (Array.isArray(children)) {
9521 for (var i = 0; i < children.length; i++) {
9522 if (!validateSuspenseListNestedChild(children[i], i)) {
9523 return;
9524 }
9525 }
9526 } else {
9527 var iteratorFn = getIteratorFn(children);
9528
9529 if (typeof iteratorFn === 'function') {
9530 var childrenIterator = iteratorFn.call(children);
9531
9532 if (childrenIterator) {
9533 var step = childrenIterator.next();
9534 var _i = 0;
9535
9536 for (; !step.done; step = childrenIterator.next()) {
9537 if (!validateSuspenseListNestedChild(step.value, _i)) {
9538 return;
9539 }
9540
9541 _i++;
9542 }
9543 }
9544 } else {
9545 warning$1(false, 'A single row was passed to a <SuspenseList revealOrder="%s" />. ' + 'This is not useful since it needs multiple rows. ' + 'Did you mean to pass multiple children or an array?', revealOrder);
9546 }
9547 }
9548 }
9549 }
9550}
9551
9552function initSuspenseListRenderState(workInProgress, isBackwards, tail, lastContentRow, tailMode) {
9553 var renderState = workInProgress.memoizedState;
9554
9555 if (renderState === null) {
9556 workInProgress.memoizedState = {
9557 isBackwards: isBackwards,
9558 rendering: null,
9559 last: lastContentRow,
9560 tail: tail,
9561 tailExpiration: 0,
9562 tailMode: tailMode
9563 };
9564 } else {
9565 // We can reuse the existing object from previous renders.
9566 renderState.isBackwards = isBackwards;
9567 renderState.rendering = null;
9568 renderState.last = lastContentRow;
9569 renderState.tail = tail;
9570 renderState.tailExpiration = 0;
9571 renderState.tailMode = tailMode;
9572 }
9573} // This can end up rendering this component multiple passes.
9574// The first pass splits the children fibers into two sets. A head and tail.
9575// We first render the head. If anything is in fallback state, we do another
9576// pass through beginWork to rerender all children (including the tail) with
9577// the force suspend context. If the first render didn't have anything in
9578// in fallback state. Then we render each row in the tail one-by-one.
9579// That happens in the completeWork phase without going back to beginWork.
9580
9581
9582function updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime) {
9583 var nextProps = workInProgress.pendingProps;
9584 var revealOrder = nextProps.revealOrder;
9585 var tailMode = nextProps.tail;
9586 var newChildren = nextProps.children;
9587 validateRevealOrder(revealOrder);
9588 validateTailOptions(tailMode, revealOrder);
9589 validateSuspenseListChildren(newChildren, revealOrder);
9590 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9591 var suspenseContext = suspenseStackCursor.current;
9592 var shouldForceFallback = hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
9593
9594 if (shouldForceFallback) {
9595 suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
9596 workInProgress.effectTag |= DidCapture;
9597 } else {
9598 var didSuspendBefore = current$$1 !== null && (current$$1.effectTag & DidCapture) !== NoEffect;
9599
9600 if (didSuspendBefore) {
9601 // If we previously forced a fallback, we need to schedule work
9602 // on any nested boundaries to let them know to try to render
9603 // again. This is the same as context updating.
9604 propagateSuspenseContextChange(workInProgress, workInProgress.child, renderExpirationTime);
9605 }
9606
9607 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
9608 }
9609
9610 pushSuspenseContext(workInProgress, suspenseContext);
9611
9612 if ((workInProgress.mode & BatchedMode) === NoMode) {
9613 // Outside of batched mode, SuspenseList doesn't work so we just
9614 // use make it a noop by treating it as the default revealOrder.
9615 workInProgress.memoizedState = null;
9616 } else {
9617 switch (revealOrder) {
9618 case 'forwards':
9619 {
9620 var lastContentRow = findLastContentRow(workInProgress.child);
9621 var tail;
9622
9623 if (lastContentRow === null) {
9624 // The whole list is part of the tail.
9625 // TODO: We could fast path by just rendering the tail now.
9626 tail = workInProgress.child;
9627 workInProgress.child = null;
9628 } else {
9629 // Disconnect the tail rows after the content row.
9630 // We're going to render them separately later.
9631 tail = lastContentRow.sibling;
9632 lastContentRow.sibling = null;
9633 }
9634
9635 initSuspenseListRenderState(workInProgress, false, // isBackwards
9636 tail, lastContentRow, tailMode);
9637 break;
9638 }
9639
9640 case 'backwards':
9641 {
9642 // We're going to find the first row that has existing content.
9643 // At the same time we're going to reverse the list of everything
9644 // we pass in the meantime. That's going to be our tail in reverse
9645 // order.
9646 var _tail = null;
9647 var row = workInProgress.child;
9648 workInProgress.child = null;
9649
9650 while (row !== null) {
9651 var currentRow = row.alternate; // New rows can't be content rows.
9652
9653 if (currentRow !== null && findFirstSuspended(currentRow) === null) {
9654 // This is the beginning of the main content.
9655 workInProgress.child = row;
9656 break;
9657 }
9658
9659 var nextRow = row.sibling;
9660 row.sibling = _tail;
9661 _tail = row;
9662 row = nextRow;
9663 } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
9664
9665
9666 initSuspenseListRenderState(workInProgress, true, // isBackwards
9667 _tail, null, // last
9668 tailMode);
9669 break;
9670 }
9671
9672 case 'together':
9673 {
9674 initSuspenseListRenderState(workInProgress, false, // isBackwards
9675 null, // tail
9676 null, // last
9677 undefined);
9678 break;
9679 }
9680
9681 default:
9682 {
9683 // The default reveal order is the same as not having
9684 // a boundary.
9685 workInProgress.memoizedState = null;
9686 }
9687 }
9688 }
9689
9690 return workInProgress.child;
9691}
9692
9693function updatePortalComponent(current$$1, workInProgress, renderExpirationTime) {
9694 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
9695 var nextChildren = workInProgress.pendingProps;
9696
9697 if (current$$1 === null) {
9698 // Portals are special because we don't append the children during mount
9699 // but at commit. Therefore we need to track insertions which the normal
9700 // flow doesn't do during mount. This doesn't happen at the root because
9701 // the root always starts with a "current" with a null child.
9702 // TODO: Consider unifying this with how the root works.
9703 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
9704 } else {
9705 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9706 }
9707
9708 return workInProgress.child;
9709}
9710
9711function updateContextProvider(current$$1, workInProgress, renderExpirationTime) {
9712 var providerType = workInProgress.type;
9713 var context = providerType._context;
9714 var newProps = workInProgress.pendingProps;
9715 var oldProps = workInProgress.memoizedProps;
9716 var newValue = newProps.value;
9717
9718 {
9719 var providerPropTypes = workInProgress.type.propTypes;
9720
9721 if (providerPropTypes) {
9722 checkPropTypes_1(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
9723 }
9724 }
9725
9726 pushProvider(workInProgress, newValue);
9727
9728 if (oldProps !== null) {
9729 var oldValue = oldProps.value;
9730 var changedBits = calculateChangedBits(context, newValue, oldValue);
9731
9732 if (changedBits === 0) {
9733 // No change. Bailout early if children are the same.
9734 if (oldProps.children === newProps.children && !hasContextChanged()) {
9735 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
9736 }
9737 } else {
9738 // The context value changed. Search for matching consumers and schedule
9739 // them to update.
9740 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
9741 }
9742 }
9743
9744 var newChildren = newProps.children;
9745 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9746 return workInProgress.child;
9747}
9748
9749var hasWarnedAboutUsingContextAsConsumer = false;
9750
9751function updateContextConsumer(current$$1, workInProgress, renderExpirationTime) {
9752 var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
9753 // DEV mode, we create a separate object for Context.Consumer that acts
9754 // like a proxy to Context. This proxy object adds unnecessary code in PROD
9755 // so we use the old behaviour (Context.Consumer references Context) to
9756 // reduce size and overhead. The separate object references context via
9757 // a property called "_context", which also gives us the ability to check
9758 // in DEV mode if this property exists or not and warn if it does not.
9759
9760 {
9761 if (context._context === undefined) {
9762 // This may be because it's a Context (rather than a Consumer).
9763 // Or it may be because it's older React where they're the same thing.
9764 // We only want to warn if we're sure it's a new React.
9765 if (context !== context.Consumer) {
9766 if (!hasWarnedAboutUsingContextAsConsumer) {
9767 hasWarnedAboutUsingContextAsConsumer = true;
9768 warning$1(false, 'Rendering <Context> directly is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
9769 }
9770 }
9771 } else {
9772 context = context._context;
9773 }
9774 }
9775
9776 var newProps = workInProgress.pendingProps;
9777 var render = newProps.children;
9778
9779 {
9780 !(typeof render === 'function') ? warningWithoutStack$1(false, 'A context consumer was rendered with multiple children, or a child ' + "that isn't a function. A context consumer expects a single child " + 'that is a function. If you did pass a function, make sure there ' + 'is no trailing or leading whitespace around it.') : void 0;
9781 }
9782
9783 prepareToReadContext(workInProgress, renderExpirationTime);
9784 var newValue = readContext(context, newProps.unstable_observedBits);
9785 var newChildren;
9786
9787 {
9788 ReactCurrentOwner$2.current = workInProgress;
9789 setCurrentPhase('render');
9790 newChildren = render(newValue);
9791 setCurrentPhase(null);
9792 } // React DevTools reads this flag.
9793
9794
9795 workInProgress.effectTag |= PerformedWork;
9796 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9797 return workInProgress.child;
9798}
9799
9800function updateFundamentalComponent$1(current$$1, workInProgress, renderExpirationTime) {
9801 var fundamentalImpl = workInProgress.type.impl;
9802
9803 if (fundamentalImpl.reconcileChildren === false) {
9804 return null;
9805 }
9806
9807 var nextProps = workInProgress.pendingProps;
9808 var nextChildren = nextProps.children;
9809 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9810 return workInProgress.child;
9811}
9812
9813function updateScopeComponent(current$$1, workInProgress, renderExpirationTime) {
9814 var nextProps = workInProgress.pendingProps;
9815 var nextChildren = nextProps.children;
9816 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9817 return workInProgress.child;
9818}
9819
9820function markWorkInProgressReceivedUpdate() {
9821 didReceiveUpdate = true;
9822}
9823
9824function bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime) {
9825 cancelWorkTimer(workInProgress);
9826
9827 if (current$$1 !== null) {
9828 // Reuse previous dependencies
9829 workInProgress.dependencies = current$$1.dependencies;
9830 }
9831
9832 if (enableProfilerTimer) {
9833 // Don't update "base" render times for bailouts.
9834 stopProfilerTimerIfRunning(workInProgress);
9835 }
9836
9837 var updateExpirationTime = workInProgress.expirationTime;
9838
9839 if (updateExpirationTime !== NoWork) {
9840 markUnprocessedUpdateTime(updateExpirationTime);
9841 } // Check if the children have any pending work.
9842
9843
9844 var childExpirationTime = workInProgress.childExpirationTime;
9845
9846 if (childExpirationTime < renderExpirationTime) {
9847 // The children don't have any work either. We can skip them.
9848 // TODO: Once we add back resuming, we should check if the children are
9849 // a work-in-progress set. If so, we need to transfer their effects.
9850 return null;
9851 } else {
9852 // This fiber doesn't have work, but its subtree does. Clone the child
9853 // fibers and continue.
9854 cloneChildFibers(current$$1, workInProgress);
9855 return workInProgress.child;
9856 }
9857}
9858
9859function remountFiber(current$$1, oldWorkInProgress, newWorkInProgress) {
9860 {
9861 var returnFiber = oldWorkInProgress.return;
9862
9863 if (returnFiber === null) {
9864 throw new Error('Cannot swap the root fiber.');
9865 } // Disconnect from the old current.
9866 // It will get deleted.
9867
9868
9869 current$$1.alternate = null;
9870 oldWorkInProgress.alternate = null; // Connect to the new tree.
9871
9872 newWorkInProgress.index = oldWorkInProgress.index;
9873 newWorkInProgress.sibling = oldWorkInProgress.sibling;
9874 newWorkInProgress.return = oldWorkInProgress.return;
9875 newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
9876
9877 if (oldWorkInProgress === returnFiber.child) {
9878 returnFiber.child = newWorkInProgress;
9879 } else {
9880 var prevSibling = returnFiber.child;
9881
9882 if (prevSibling === null) {
9883 throw new Error('Expected parent to have a child.');
9884 }
9885
9886 while (prevSibling.sibling !== oldWorkInProgress) {
9887 prevSibling = prevSibling.sibling;
9888
9889 if (prevSibling === null) {
9890 throw new Error('Expected to find the previous sibling.');
9891 }
9892 }
9893
9894 prevSibling.sibling = newWorkInProgress;
9895 } // Delete the old fiber and place the new one.
9896 // Since the old fiber is disconnected, we have to schedule it manually.
9897
9898
9899 var last = returnFiber.lastEffect;
9900
9901 if (last !== null) {
9902 last.nextEffect = current$$1;
9903 returnFiber.lastEffect = current$$1;
9904 } else {
9905 returnFiber.firstEffect = returnFiber.lastEffect = current$$1;
9906 }
9907
9908 current$$1.nextEffect = null;
9909 current$$1.effectTag = Deletion;
9910 newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
9911
9912 return newWorkInProgress;
9913 }
9914}
9915
9916function beginWork$1(current$$1, workInProgress, renderExpirationTime) {
9917 var updateExpirationTime = workInProgress.expirationTime;
9918
9919 {
9920 if (workInProgress._debugNeedsRemount && current$$1 !== null) {
9921 // This will restart the begin phase with a new fiber.
9922 return remountFiber(current$$1, workInProgress, createFiberFromTypeAndProps(workInProgress.type, workInProgress.key, workInProgress.pendingProps, workInProgress._debugOwner || null, workInProgress.mode, workInProgress.expirationTime));
9923 }
9924 }
9925
9926 if (current$$1 !== null) {
9927 var oldProps = current$$1.memoizedProps;
9928 var newProps = workInProgress.pendingProps;
9929
9930 if (oldProps !== newProps || hasContextChanged() || ( // Force a re-render if the implementation changed due to hot reload:
9931 workInProgress.type !== current$$1.type)) {
9932 // If props or context changed, mark the fiber as having performed work.
9933 // This may be unset if the props are determined to be equal later (memo).
9934 didReceiveUpdate = true;
9935 } else if (updateExpirationTime < renderExpirationTime) {
9936 didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
9937 // the begin phase. There's still some bookkeeping we that needs to be done
9938 // in this optimized path, mostly pushing stuff onto the stack.
9939
9940 switch (workInProgress.tag) {
9941 case HostRoot:
9942 pushHostRootContext(workInProgress);
9943 resetHydrationState();
9944 break;
9945
9946 case HostComponent:
9947 pushHostContext(workInProgress);
9948
9949 if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(workInProgress.type, newProps)) {
9950 if (enableSchedulerTracing) {
9951 markSpawnedWork(Never);
9952 } // Schedule this fiber to re-render at offscreen priority. Then bailout.
9953
9954
9955 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
9956 return null;
9957 }
9958
9959 break;
9960
9961 case ClassComponent:
9962 {
9963 var Component = workInProgress.type;
9964
9965 if (isContextProvider(Component)) {
9966 pushContextProvider(workInProgress);
9967 }
9968
9969 break;
9970 }
9971
9972 case HostPortal:
9973 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
9974 break;
9975
9976 case ContextProvider:
9977 {
9978 var newValue = workInProgress.memoizedProps.value;
9979 pushProvider(workInProgress, newValue);
9980 break;
9981 }
9982
9983 case Profiler:
9984 if (enableProfilerTimer) {
9985 workInProgress.effectTag |= Update;
9986 }
9987
9988 break;
9989
9990 case SuspenseComponent:
9991 {
9992 var state = workInProgress.memoizedState;
9993
9994 if (state !== null) {
9995 if (enableSuspenseServerRenderer) {
9996 if (state.dehydrated !== null) {
9997 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // We know that this component will suspend again because if it has
9998 // been unsuspended it has committed as a resolved Suspense component.
9999 // If it needs to be retried, it should have work scheduled on it.
10000
10001 workInProgress.effectTag |= DidCapture;
10002 break;
10003 }
10004 } // If this boundary is currently timed out, we need to decide
10005 // whether to retry the primary children, or to skip over it and
10006 // go straight to the fallback. Check the priority of the primary
10007 // child fragment.
10008
10009
10010 var primaryChildFragment = workInProgress.child;
10011 var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
10012
10013 if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
10014 // The primary children have pending work. Use the normal path
10015 // to attempt to render the primary children again.
10016 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
10017 } else {
10018 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // The primary children do not have pending work with sufficient
10019 // priority. Bailout.
10020
10021 var child = bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
10022
10023 if (child !== null) {
10024 // The fallback children have pending work. Skip over the
10025 // primary children and work on the fallback.
10026 return child.sibling;
10027 } else {
10028 return null;
10029 }
10030 }
10031 } else {
10032 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current));
10033 }
10034
10035 break;
10036 }
10037
10038 case SuspenseListComponent:
10039 {
10040 var didSuspendBefore = (current$$1.effectTag & DidCapture) !== NoEffect;
10041 var hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
10042
10043 if (didSuspendBefore) {
10044 if (hasChildWork) {
10045 // If something was in fallback state last time, and we have all the
10046 // same children then we're still in progressive loading state.
10047 // Something might get unblocked by state updates or retries in the
10048 // tree which will affect the tail. So we need to use the normal
10049 // path to compute the correct tail.
10050 return updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime);
10051 } // If none of the children had any work, that means that none of
10052 // them got retried so they'll still be blocked in the same way
10053 // as before. We can fast bail out.
10054
10055
10056 workInProgress.effectTag |= DidCapture;
10057 } // If nothing suspended before and we're rendering the same children,
10058 // then the tail doesn't matter. Anything new that suspends will work
10059 // in the "together" mode, so we can continue from the state we had.
10060
10061
10062 var renderState = workInProgress.memoizedState;
10063
10064 if (renderState !== null) {
10065 // Reset to the "together" mode in case we've started a different
10066 // update in the past but didn't complete it.
10067 renderState.rendering = null;
10068 renderState.tail = null;
10069 }
10070
10071 pushSuspenseContext(workInProgress, suspenseStackCursor.current);
10072
10073 if (hasChildWork) {
10074 break;
10075 } else {
10076 // If none of the children had any work, that means that none of
10077 // them got retried so they'll still be blocked in the same way
10078 // as before. We can fast bail out.
10079 return null;
10080 }
10081 }
10082 }
10083
10084 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
10085 } else {
10086 // An update was scheduled on this fiber, but there are no new props
10087 // nor legacy context. Set this to false. If an update queue or context
10088 // consumer produces a changed value, it will set this to true. Otherwise,
10089 // the component will assume the children have not changed and bail out.
10090 didReceiveUpdate = false;
10091 }
10092 } else {
10093 didReceiveUpdate = false;
10094 } // Before entering the begin phase, clear the expiration time.
10095
10096
10097 workInProgress.expirationTime = NoWork;
10098
10099 switch (workInProgress.tag) {
10100 case IndeterminateComponent:
10101 {
10102 return mountIndeterminateComponent(current$$1, workInProgress, workInProgress.type, renderExpirationTime);
10103 }
10104
10105 case LazyComponent:
10106 {
10107 var elementType = workInProgress.elementType;
10108 return mountLazyComponent(current$$1, workInProgress, elementType, updateExpirationTime, renderExpirationTime);
10109 }
10110
10111 case FunctionComponent:
10112 {
10113 var _Component = workInProgress.type;
10114 var unresolvedProps = workInProgress.pendingProps;
10115 var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
10116 return updateFunctionComponent(current$$1, workInProgress, _Component, resolvedProps, renderExpirationTime);
10117 }
10118
10119 case ClassComponent:
10120 {
10121 var _Component2 = workInProgress.type;
10122 var _unresolvedProps = workInProgress.pendingProps;
10123
10124 var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
10125
10126 return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
10127 }
10128
10129 case HostRoot:
10130 return updateHostRoot(current$$1, workInProgress, renderExpirationTime);
10131
10132 case HostComponent:
10133 return updateHostComponent(current$$1, workInProgress, renderExpirationTime);
10134
10135 case HostText:
10136 return updateHostText(current$$1, workInProgress);
10137
10138 case SuspenseComponent:
10139 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
10140
10141 case HostPortal:
10142 return updatePortalComponent(current$$1, workInProgress, renderExpirationTime);
10143
10144 case ForwardRef:
10145 {
10146 var type = workInProgress.type;
10147 var _unresolvedProps2 = workInProgress.pendingProps;
10148
10149 var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
10150
10151 return updateForwardRef(current$$1, workInProgress, type, _resolvedProps2, renderExpirationTime);
10152 }
10153
10154 case Fragment:
10155 return updateFragment(current$$1, workInProgress, renderExpirationTime);
10156
10157 case Mode:
10158 return updateMode(current$$1, workInProgress, renderExpirationTime);
10159
10160 case Profiler:
10161 return updateProfiler(current$$1, workInProgress, renderExpirationTime);
10162
10163 case ContextProvider:
10164 return updateContextProvider(current$$1, workInProgress, renderExpirationTime);
10165
10166 case ContextConsumer:
10167 return updateContextConsumer(current$$1, workInProgress, renderExpirationTime);
10168
10169 case MemoComponent:
10170 {
10171 var _type2 = workInProgress.type;
10172 var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
10173
10174 var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
10175
10176 {
10177 if (workInProgress.type !== workInProgress.elementType) {
10178 var outerPropTypes = _type2.propTypes;
10179
10180 if (outerPropTypes) {
10181 checkPropTypes_1(outerPropTypes, _resolvedProps3, // Resolved for outer only
10182 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
10183 }
10184 }
10185 }
10186
10187 _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
10188 return updateMemoComponent(current$$1, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
10189 }
10190
10191 case SimpleMemoComponent:
10192 {
10193 return updateSimpleMemoComponent(current$$1, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
10194 }
10195
10196 case IncompleteClassComponent:
10197 {
10198 var _Component3 = workInProgress.type;
10199 var _unresolvedProps4 = workInProgress.pendingProps;
10200
10201 var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
10202
10203 return mountIncompleteClassComponent(current$$1, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
10204 }
10205
10206 case SuspenseListComponent:
10207 {
10208 return updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime);
10209 }
10210
10211 case FundamentalComponent:
10212 {
10213 if (enableFundamentalAPI) {
10214 return updateFundamentalComponent$1(current$$1, workInProgress, renderExpirationTime);
10215 }
10216
10217 break;
10218 }
10219
10220 case ScopeComponent:
10221 {
10222 if (enableScopeAPI) {
10223 return updateScopeComponent(current$$1, workInProgress, renderExpirationTime);
10224 }
10225
10226 break;
10227 }
10228 }
10229
10230 (function () {
10231 {
10232 {
10233 throw ReactError(Error("Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue."));
10234 }
10235 }
10236 })();
10237}
10238
10239function createFundamentalStateInstance(currentFiber, props, impl, state) {
10240 return {
10241 currentFiber: currentFiber,
10242 impl: impl,
10243 instance: null,
10244 prevProps: null,
10245 props: props,
10246 state: state
10247 };
10248}
10249
10250function isFiberSuspenseAndTimedOut(fiber) {
10251 return fiber.tag === SuspenseComponent && fiber.memoizedState !== null;
10252}
10253
10254function getSuspenseFallbackChild(fiber) {
10255 return fiber.child.sibling.child;
10256}
10257
10258function collectScopedNodes(node, fn, scopedNodes) {
10259 if (enableScopeAPI) {
10260 if (node.tag === HostComponent) {
10261 var _type = node.type,
10262 memoizedProps = node.memoizedProps;
10263
10264 if (fn(_type, memoizedProps) === true) {
10265 scopedNodes.push(getPublicInstance(node.stateNode));
10266 }
10267 }
10268
10269 var child = node.child;
10270
10271 if (isFiberSuspenseAndTimedOut(node)) {
10272 child = getSuspenseFallbackChild(node);
10273 }
10274
10275 if (child !== null) {
10276 collectScopedNodesFromChildren(child, fn, scopedNodes);
10277 }
10278 }
10279}
10280
10281function collectScopedNodesFromChildren(startingChild, fn, scopedNodes) {
10282 var child = startingChild;
10283
10284 while (child !== null) {
10285 collectScopedNodes(child, fn, scopedNodes);
10286 child = child.sibling;
10287 }
10288}
10289
10290function collectNearestScopeMethods(node, scope, childrenScopes) {
10291 if (isValidScopeNode(node, scope)) {
10292 childrenScopes.push(node.stateNode.methods);
10293 } else {
10294 var child = node.child;
10295
10296 if (isFiberSuspenseAndTimedOut(node)) {
10297 child = getSuspenseFallbackChild(node);
10298 }
10299
10300 if (child !== null) {
10301 collectNearestChildScopeMethods(child, scope, childrenScopes);
10302 }
10303 }
10304}
10305
10306function collectNearestChildScopeMethods(startingChild, scope, childrenScopes) {
10307 var child = startingChild;
10308
10309 while (child !== null) {
10310 collectNearestScopeMethods(child, scope, childrenScopes);
10311 child = child.sibling;
10312 }
10313}
10314
10315function isValidScopeNode(node, scope) {
10316 return node.tag === ScopeComponent && node.type === scope;
10317}
10318
10319function createScopeMethods(scope, instance) {
10320 var fn = scope.fn;
10321 return {
10322 getChildren: function () {
10323 var currentFiber = instance.fiber;
10324 var child = currentFiber.child;
10325 var childrenScopes = [];
10326
10327 if (child !== null) {
10328 collectNearestChildScopeMethods(child, scope, childrenScopes);
10329 }
10330
10331 return childrenScopes.length === 0 ? null : childrenScopes;
10332 },
10333 getChildrenFromRoot: function () {
10334 var currentFiber = instance.fiber;
10335 var node = currentFiber;
10336
10337 while (node !== null) {
10338 var parent = node.return;
10339
10340 if (parent === null) {
10341 break;
10342 }
10343
10344 node = parent;
10345
10346 if (node.tag === ScopeComponent && node.type === scope) {
10347 break;
10348 }
10349 }
10350
10351 var childrenScopes = [];
10352 collectNearestChildScopeMethods(node.child, scope, childrenScopes);
10353 return childrenScopes.length === 0 ? null : childrenScopes;
10354 },
10355 getParent: function () {
10356 var node = instance.fiber.return;
10357
10358 while (node !== null) {
10359 if (node.tag === ScopeComponent && node.type === scope) {
10360 return node.stateNode.methods;
10361 }
10362
10363 node = node.return;
10364 }
10365
10366 return null;
10367 },
10368 getProps: function () {
10369 var currentFiber = instance.fiber;
10370 return currentFiber.memoizedProps;
10371 },
10372 getScopedNodes: function () {
10373 var currentFiber = instance.fiber;
10374 var child = currentFiber.child;
10375 var scopedNodes = [];
10376
10377 if (child !== null) {
10378 collectScopedNodesFromChildren(child, fn, scopedNodes);
10379 }
10380
10381 return scopedNodes.length === 0 ? null : scopedNodes;
10382 }
10383 };
10384}
10385
10386function markUpdate(workInProgress) {
10387 // Tag the fiber with an update effect. This turns a Placement into
10388 // a PlacementAndUpdate.
10389 workInProgress.effectTag |= Update;
10390}
10391
10392function markRef$1(workInProgress) {
10393 workInProgress.effectTag |= Ref;
10394}
10395
10396var appendAllChildren;
10397var updateHostContainer;
10398var updateHostComponent$1;
10399var updateHostText$1;
10400
10401if (supportsMutation) {
10402 // Mutation mode
10403 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
10404 // We only have the top Fiber that was created but we need recurse down its
10405 // children to find all the terminal nodes.
10406 var node = workInProgress.child;
10407
10408 while (node !== null) {
10409 if (node.tag === HostComponent || node.tag === HostText) {
10410 appendInitialChild(parent, node.stateNode);
10411 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10412 appendInitialChild(parent, node.stateNode.instance);
10413 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10414 // down its children. Instead, we'll get insertions from each child in
10415 // the portal directly.
10416 } else if (node.child !== null) {
10417 node.child.return = node;
10418 node = node.child;
10419 continue;
10420 }
10421
10422 if (node === workInProgress) {
10423 return;
10424 }
10425
10426 while (node.sibling === null) {
10427 if (node.return === null || node.return === workInProgress) {
10428 return;
10429 }
10430
10431 node = node.return;
10432 }
10433
10434 node.sibling.return = node.return;
10435 node = node.sibling;
10436 }
10437 };
10438
10439 updateHostContainer = function (workInProgress) {// Noop
10440 };
10441
10442 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
10443 // If we have an alternate, that means this is an update and we need to
10444 // schedule a side-effect to do the updates.
10445 var oldProps = current.memoizedProps;
10446
10447 if (oldProps === newProps) {
10448 // In mutation mode, this is sufficient for a bailout because
10449 // we won't touch this node even if children changed.
10450 return;
10451 } // If we get updated because one of our children updated, we don't
10452 // have newProps so we'll have to reuse them.
10453 // TODO: Split the update API as separate for the props vs. children.
10454 // Even better would be if children weren't special cased at all tho.
10455
10456
10457 var instance = workInProgress.stateNode;
10458 var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
10459 // component is hitting the resume path. Figure out why. Possibly
10460 // related to `hidden`.
10461
10462 var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext); // TODO: Type this specific to this type of component.
10463
10464 workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
10465 // is a new ref we mark this as an update. All the work is done in commitWork.
10466
10467 if (updatePayload) {
10468 markUpdate(workInProgress);
10469 }
10470 };
10471
10472 updateHostText$1 = function (current, workInProgress, oldText, newText) {
10473 // If the text differs, mark it as an update. All the work in done in commitWork.
10474 if (oldText !== newText) {
10475 markUpdate(workInProgress);
10476 }
10477 };
10478} else if (supportsPersistence) {
10479 // Persistent host tree mode
10480 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
10481 // We only have the top Fiber that was created but we need recurse down its
10482 // children to find all the terminal nodes.
10483 var node = workInProgress.child;
10484
10485 while (node !== null) {
10486 // eslint-disable-next-line no-labels
10487 branches: if (node.tag === HostComponent) {
10488 var instance = node.stateNode;
10489
10490 if (needsVisibilityToggle && isHidden) {
10491 // This child is inside a timed out tree. Hide it.
10492 var props = node.memoizedProps;
10493 var type = node.type;
10494 instance = cloneHiddenInstance(instance, type, props, node);
10495 }
10496
10497 appendInitialChild(parent, instance);
10498 } else if (node.tag === HostText) {
10499 var _instance = node.stateNode;
10500
10501 if (needsVisibilityToggle && isHidden) {
10502 // This child is inside a timed out tree. Hide it.
10503 var text = node.memoizedProps;
10504 _instance = cloneHiddenTextInstance(_instance, text, node);
10505 }
10506
10507 appendInitialChild(parent, _instance);
10508 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10509 var _instance2 = node.stateNode.instance;
10510
10511 if (needsVisibilityToggle && isHidden) {
10512 // This child is inside a timed out tree. Hide it.
10513 var _props = node.memoizedProps;
10514 var _type = node.type;
10515 _instance2 = cloneHiddenInstance(_instance2, _type, _props, node);
10516 }
10517
10518 appendInitialChild(parent, _instance2);
10519 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10520 // down its children. Instead, we'll get insertions from each child in
10521 // the portal directly.
10522 } else if (node.tag === SuspenseComponent) {
10523 if ((node.effectTag & Update) !== NoEffect) {
10524 // Need to toggle the visibility of the primary children.
10525 var newIsHidden = node.memoizedState !== null;
10526
10527 if (newIsHidden) {
10528 var primaryChildParent = node.child;
10529
10530 if (primaryChildParent !== null) {
10531 if (primaryChildParent.child !== null) {
10532 primaryChildParent.child.return = primaryChildParent;
10533 appendAllChildren(parent, primaryChildParent, true, newIsHidden);
10534 }
10535
10536 var fallbackChildParent = primaryChildParent.sibling;
10537
10538 if (fallbackChildParent !== null) {
10539 fallbackChildParent.return = node;
10540 node = fallbackChildParent;
10541 continue;
10542 }
10543 }
10544 }
10545 }
10546
10547 if (node.child !== null) {
10548 // Continue traversing like normal
10549 node.child.return = node;
10550 node = node.child;
10551 continue;
10552 }
10553 } else if (node.child !== null) {
10554 node.child.return = node;
10555 node = node.child;
10556 continue;
10557 } // $FlowFixMe This is correct but Flow is confused by the labeled break.
10558
10559
10560 node = node;
10561
10562 if (node === workInProgress) {
10563 return;
10564 }
10565
10566 while (node.sibling === null) {
10567 if (node.return === null || node.return === workInProgress) {
10568 return;
10569 }
10570
10571 node = node.return;
10572 }
10573
10574 node.sibling.return = node.return;
10575 node = node.sibling;
10576 }
10577 }; // An unfortunate fork of appendAllChildren because we have two different parent types.
10578
10579
10580 var appendAllChildrenToContainer = function (containerChildSet, workInProgress, needsVisibilityToggle, isHidden) {
10581 // We only have the top Fiber that was created but we need recurse down its
10582 // children to find all the terminal nodes.
10583 var node = workInProgress.child;
10584
10585 while (node !== null) {
10586 // eslint-disable-next-line no-labels
10587 branches: if (node.tag === HostComponent) {
10588 var instance = node.stateNode;
10589
10590 if (needsVisibilityToggle && isHidden) {
10591 // This child is inside a timed out tree. Hide it.
10592 var props = node.memoizedProps;
10593 var type = node.type;
10594 instance = cloneHiddenInstance(instance, type, props, node);
10595 }
10596
10597 appendChildToContainerChildSet(containerChildSet, instance);
10598 } else if (node.tag === HostText) {
10599 var _instance3 = node.stateNode;
10600
10601 if (needsVisibilityToggle && isHidden) {
10602 // This child is inside a timed out tree. Hide it.
10603 var text = node.memoizedProps;
10604 _instance3 = cloneHiddenTextInstance(_instance3, text, node);
10605 }
10606
10607 appendChildToContainerChildSet(containerChildSet, _instance3);
10608 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10609 var _instance4 = node.stateNode.instance;
10610
10611 if (needsVisibilityToggle && isHidden) {
10612 // This child is inside a timed out tree. Hide it.
10613 var _props2 = node.memoizedProps;
10614 var _type2 = node.type;
10615 _instance4 = cloneHiddenInstance(_instance4, _type2, _props2, node);
10616 }
10617
10618 appendChildToContainerChildSet(containerChildSet, _instance4);
10619 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10620 // down its children. Instead, we'll get insertions from each child in
10621 // the portal directly.
10622 } else if (node.tag === SuspenseComponent) {
10623 if ((node.effectTag & Update) !== NoEffect) {
10624 // Need to toggle the visibility of the primary children.
10625 var newIsHidden = node.memoizedState !== null;
10626
10627 if (newIsHidden) {
10628 var primaryChildParent = node.child;
10629
10630 if (primaryChildParent !== null) {
10631 if (primaryChildParent.child !== null) {
10632 primaryChildParent.child.return = primaryChildParent;
10633 appendAllChildrenToContainer(containerChildSet, primaryChildParent, true, newIsHidden);
10634 }
10635
10636 var fallbackChildParent = primaryChildParent.sibling;
10637
10638 if (fallbackChildParent !== null) {
10639 fallbackChildParent.return = node;
10640 node = fallbackChildParent;
10641 continue;
10642 }
10643 }
10644 }
10645 }
10646
10647 if (node.child !== null) {
10648 // Continue traversing like normal
10649 node.child.return = node;
10650 node = node.child;
10651 continue;
10652 }
10653 } else if (node.child !== null) {
10654 node.child.return = node;
10655 node = node.child;
10656 continue;
10657 } // $FlowFixMe This is correct but Flow is confused by the labeled break.
10658
10659
10660 node = node;
10661
10662 if (node === workInProgress) {
10663 return;
10664 }
10665
10666 while (node.sibling === null) {
10667 if (node.return === null || node.return === workInProgress) {
10668 return;
10669 }
10670
10671 node = node.return;
10672 }
10673
10674 node.sibling.return = node.return;
10675 node = node.sibling;
10676 }
10677 };
10678
10679 updateHostContainer = function (workInProgress) {
10680 var portalOrRoot = workInProgress.stateNode;
10681 var childrenUnchanged = workInProgress.firstEffect === null;
10682
10683 if (childrenUnchanged) {// No changes, just reuse the existing instance.
10684 } else {
10685 var container = portalOrRoot.containerInfo;
10686 var newChildSet = createContainerChildSet(container); // If children might have changed, we have to add them all to the set.
10687
10688 appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
10689 portalOrRoot.pendingChildren = newChildSet; // Schedule an update on the container to swap out the container.
10690
10691 markUpdate(workInProgress);
10692 finalizeContainerChildren(container, newChildSet);
10693 }
10694 };
10695
10696 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
10697 var currentInstance = current.stateNode;
10698 var oldProps = current.memoizedProps; // If there are no effects associated with this node, then none of our children had any updates.
10699 // This guarantees that we can reuse all of them.
10700
10701 var childrenUnchanged = workInProgress.firstEffect === null;
10702
10703 if (childrenUnchanged && oldProps === newProps) {
10704 // No changes, just reuse the existing instance.
10705 // Note that this might release a previous clone.
10706 workInProgress.stateNode = currentInstance;
10707 return;
10708 }
10709
10710 var recyclableInstance = workInProgress.stateNode;
10711 var currentHostContext = getHostContext();
10712 var updatePayload = null;
10713
10714 if (oldProps !== newProps) {
10715 updatePayload = prepareUpdate(recyclableInstance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
10716 }
10717
10718 if (childrenUnchanged && updatePayload === null) {
10719 // No changes, just reuse the existing instance.
10720 // Note that this might release a previous clone.
10721 workInProgress.stateNode = currentInstance;
10722 return;
10723 }
10724
10725 var newInstance = cloneInstance(currentInstance, updatePayload, type, oldProps, newProps, workInProgress, childrenUnchanged, recyclableInstance);
10726
10727 if (finalizeInitialChildren(newInstance, type, newProps, rootContainerInstance, currentHostContext)) {
10728 markUpdate(workInProgress);
10729 }
10730
10731 workInProgress.stateNode = newInstance;
10732
10733 if (childrenUnchanged) {
10734 // If there are no other effects in this tree, we need to flag this node as having one.
10735 // Even though we're not going to use it for anything.
10736 // Otherwise parents won't know that there are new children to propagate upwards.
10737 markUpdate(workInProgress);
10738 } else {
10739 // If children might have changed, we have to add them all to the set.
10740 appendAllChildren(newInstance, workInProgress, false, false);
10741 }
10742 };
10743
10744 updateHostText$1 = function (current, workInProgress, oldText, newText) {
10745 if (oldText !== newText) {
10746 // If the text content differs, we'll create a new text instance for it.
10747 var rootContainerInstance = getRootHostContainer();
10748 var currentHostContext = getHostContext();
10749 workInProgress.stateNode = createTextInstance(newText, rootContainerInstance, currentHostContext, workInProgress); // We'll have to mark it as having an effect, even though we won't use the effect for anything.
10750 // This lets the parents know that at least one of their children has changed.
10751
10752 markUpdate(workInProgress);
10753 }
10754 };
10755} else {
10756 // No host operations
10757 updateHostContainer = function (workInProgress) {// Noop
10758 };
10759
10760 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {// Noop
10761 };
10762
10763 updateHostText$1 = function (current, workInProgress, oldText, newText) {// Noop
10764 };
10765}
10766
10767function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
10768 switch (renderState.tailMode) {
10769 case 'hidden':
10770 {
10771 // Any insertions at the end of the tail list after this point
10772 // should be invisible. If there are already mounted boundaries
10773 // anything before them are not considered for collapsing.
10774 // Therefore we need to go through the whole tail to find if
10775 // there are any.
10776 var tailNode = renderState.tail;
10777 var lastTailNode = null;
10778
10779 while (tailNode !== null) {
10780 if (tailNode.alternate !== null) {
10781 lastTailNode = tailNode;
10782 }
10783
10784 tailNode = tailNode.sibling;
10785 } // Next we're simply going to delete all insertions after the
10786 // last rendered item.
10787
10788
10789 if (lastTailNode === null) {
10790 // All remaining items in the tail are insertions.
10791 renderState.tail = null;
10792 } else {
10793 // Detach the insertion after the last node that was already
10794 // inserted.
10795 lastTailNode.sibling = null;
10796 }
10797
10798 break;
10799 }
10800
10801 case 'collapsed':
10802 {
10803 // Any insertions at the end of the tail list after this point
10804 // should be invisible. If there are already mounted boundaries
10805 // anything before them are not considered for collapsing.
10806 // Therefore we need to go through the whole tail to find if
10807 // there are any.
10808 var _tailNode = renderState.tail;
10809 var _lastTailNode = null;
10810
10811 while (_tailNode !== null) {
10812 if (_tailNode.alternate !== null) {
10813 _lastTailNode = _tailNode;
10814 }
10815
10816 _tailNode = _tailNode.sibling;
10817 } // Next we're simply going to delete all insertions after the
10818 // last rendered item.
10819
10820
10821 if (_lastTailNode === null) {
10822 // All remaining items in the tail are insertions.
10823 if (!hasRenderedATailFallback && renderState.tail !== null) {
10824 // We suspended during the head. We want to show at least one
10825 // row at the tail. So we'll keep on and cut off the rest.
10826 renderState.tail.sibling = null;
10827 } else {
10828 renderState.tail = null;
10829 }
10830 } else {
10831 // Detach the insertion after the last node that was already
10832 // inserted.
10833 _lastTailNode.sibling = null;
10834 }
10835
10836 break;
10837 }
10838 }
10839}
10840
10841function completeWork(current, workInProgress, renderExpirationTime) {
10842 var newProps = workInProgress.pendingProps;
10843
10844 switch (workInProgress.tag) {
10845 case IndeterminateComponent:
10846 break;
10847
10848 case LazyComponent:
10849 break;
10850
10851 case SimpleMemoComponent:
10852 case FunctionComponent:
10853 break;
10854
10855 case ClassComponent:
10856 {
10857 var Component = workInProgress.type;
10858
10859 if (isContextProvider(Component)) {
10860 popContext(workInProgress);
10861 }
10862
10863 break;
10864 }
10865
10866 case HostRoot:
10867 {
10868 popHostContainer(workInProgress);
10869 popTopLevelContextObject(workInProgress);
10870 var fiberRoot = workInProgress.stateNode;
10871
10872 if (fiberRoot.pendingContext) {
10873 fiberRoot.context = fiberRoot.pendingContext;
10874 fiberRoot.pendingContext = null;
10875 }
10876
10877 if (current === null || current.child === null) {
10878 // If we hydrated, pop so that we can delete any remaining children
10879 // that weren't hydrated.
10880 var wasHydrated = popHydrationState(workInProgress);
10881
10882 if (wasHydrated) {
10883 // If we hydrated, then we'll need to schedule an update for
10884 // the commit side-effects on the root.
10885 markUpdate(workInProgress);
10886 }
10887 }
10888
10889 updateHostContainer(workInProgress);
10890 break;
10891 }
10892
10893 case HostComponent:
10894 {
10895 popHostContext(workInProgress);
10896 var rootContainerInstance = getRootHostContainer();
10897 var type = workInProgress.type;
10898
10899 if (current !== null && workInProgress.stateNode != null) {
10900 updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
10901
10902 if (enableFlareAPI) {
10903 var prevListeners = current.memoizedProps.listeners;
10904 var nextListeners = newProps.listeners;
10905
10906 if (prevListeners !== nextListeners) {
10907 markUpdate(workInProgress);
10908 }
10909 }
10910
10911 if (current.ref !== workInProgress.ref) {
10912 markRef$1(workInProgress);
10913 }
10914 } else {
10915 if (!newProps) {
10916 (function () {
10917 if (!(workInProgress.stateNode !== null)) {
10918 {
10919 throw ReactError(Error("We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."));
10920 }
10921 }
10922 })(); // This can happen when we abort work.
10923
10924
10925 break;
10926 }
10927
10928 var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
10929 // "stack" as the parent. Then append children as we go in beginWork
10930 // or completeWork depending on we want to add then top->down or
10931 // bottom->up. Top->down is faster in IE11.
10932
10933 var _wasHydrated = popHydrationState(workInProgress);
10934
10935 if (_wasHydrated) {
10936 // TODO: Move this and createInstance step into the beginPhase
10937 // to consolidate.
10938 if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
10939 // If changes to the hydrated node needs to be applied at the
10940 // commit-phase we mark this as such.
10941 markUpdate(workInProgress);
10942 }
10943
10944 if (enableFlareAPI) {
10945 var listeners = newProps.listeners;
10946
10947 if (listeners != null) {
10948 updateEventListeners(listeners, workInProgress, rootContainerInstance);
10949 }
10950 }
10951 } else {
10952 var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
10953 appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
10954
10955 workInProgress.stateNode = instance;
10956
10957 if (enableFlareAPI) {
10958 var _listeners = newProps.listeners;
10959
10960 if (_listeners != null) {
10961 updateEventListeners(_listeners, workInProgress, rootContainerInstance);
10962 }
10963 } // Certain renderers require commit-time effects for initial mount.
10964 // (eg DOM renderer supports auto-focus for certain elements).
10965 // Make sure such renderers get scheduled for later work.
10966
10967
10968 if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance, currentHostContext)) {
10969 markUpdate(workInProgress);
10970 }
10971 }
10972
10973 if (workInProgress.ref !== null) {
10974 // If there is a ref on a host node we need to schedule a callback
10975 markRef$1(workInProgress);
10976 }
10977 }
10978
10979 break;
10980 }
10981
10982 case HostText:
10983 {
10984 var newText = newProps;
10985
10986 if (current && workInProgress.stateNode != null) {
10987 var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
10988 // to schedule a side-effect to do the updates.
10989
10990 updateHostText$1(current, workInProgress, oldText, newText);
10991 } else {
10992 if (typeof newText !== 'string') {
10993 (function () {
10994 if (!(workInProgress.stateNode !== null)) {
10995 {
10996 throw ReactError(Error("We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."));
10997 }
10998 }
10999 })(); // This can happen when we abort work.
11000
11001 }
11002
11003 var _rootContainerInstance = getRootHostContainer();
11004
11005 var _currentHostContext = getHostContext();
11006
11007 var _wasHydrated2 = popHydrationState(workInProgress);
11008
11009 if (_wasHydrated2) {
11010 if (prepareToHydrateHostTextInstance(workInProgress)) {
11011 markUpdate(workInProgress);
11012 }
11013 } else {
11014 workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
11015 }
11016 }
11017
11018 break;
11019 }
11020
11021 case ForwardRef:
11022 break;
11023
11024 case SuspenseComponent:
11025 {
11026 popSuspenseContext(workInProgress);
11027 var nextState = workInProgress.memoizedState;
11028
11029 if (enableSuspenseServerRenderer) {
11030 if (nextState !== null && nextState.dehydrated !== null) {
11031 if (current === null) {
11032 var _wasHydrated3 = popHydrationState(workInProgress);
11033
11034 (function () {
11035 if (!_wasHydrated3) {
11036 {
11037 throw ReactError(Error("A dehydrated suspense component was completed without a hydrated node. This is probably a bug in React."));
11038 }
11039 }
11040 })();
11041
11042 prepareToHydrateHostSuspenseInstance(workInProgress);
11043
11044 if (enableSchedulerTracing) {
11045 markSpawnedWork(Never);
11046 }
11047
11048 return null;
11049 } else {
11050 // We should never have been in a hydration state if we didn't have a current.
11051 // However, in some of those paths, we might have reentered a hydration state
11052 // and then we might be inside a hydration state. In that case, we'll need to
11053 // exit out of it.
11054 resetHydrationState();
11055
11056 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
11057 // This boundary did not suspend so it's now hydrated and unsuspended.
11058 workInProgress.memoizedState = null;
11059 } // If nothing suspended, we need to schedule an effect to mark this boundary
11060 // as having hydrated so events know that they're free be invoked.
11061 // It's also a signal to replay events and the suspense callback.
11062 // If something suspended, schedule an effect to attach retry listeners.
11063 // So we might as well always mark this.
11064
11065
11066 workInProgress.effectTag |= Update;
11067 return null;
11068 }
11069 }
11070 }
11071
11072 if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
11073 // Something suspended. Re-render with the fallback children.
11074 workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
11075
11076 return workInProgress;
11077 }
11078
11079 var nextDidTimeout = nextState !== null;
11080 var prevDidTimeout = false;
11081
11082 if (current === null) {
11083 // In cases where we didn't find a suitable hydration boundary we never
11084 // put this in dehydrated mode, but we still need to pop the hydration
11085 // state since we might be inside the insertion tree.
11086 popHydrationState(workInProgress);
11087 } else {
11088 var prevState = current.memoizedState;
11089 prevDidTimeout = prevState !== null;
11090
11091 if (!nextDidTimeout && prevState !== null) {
11092 // We just switched from the fallback to the normal children.
11093 // Delete the fallback.
11094 // TODO: Would it be better to store the fallback fragment on
11095 // the stateNode during the begin phase?
11096 var currentFallbackChild = current.child.sibling;
11097
11098 if (currentFallbackChild !== null) {
11099 // Deletions go at the beginning of the return fiber's effect list
11100 var first = workInProgress.firstEffect;
11101
11102 if (first !== null) {
11103 workInProgress.firstEffect = currentFallbackChild;
11104 currentFallbackChild.nextEffect = first;
11105 } else {
11106 workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
11107 currentFallbackChild.nextEffect = null;
11108 }
11109
11110 currentFallbackChild.effectTag = Deletion;
11111 }
11112 }
11113 }
11114
11115 if (nextDidTimeout && !prevDidTimeout) {
11116 // If this subtreee is running in batched mode we can suspend,
11117 // otherwise we won't suspend.
11118 // TODO: This will still suspend a synchronous tree if anything
11119 // in the concurrent tree already suspended during this render.
11120 // This is a known bug.
11121 if ((workInProgress.mode & BatchedMode) !== NoMode) {
11122 // TODO: Move this back to throwException because this is too late
11123 // if this is a large tree which is common for initial loads. We
11124 // don't know if we should restart a render or not until we get
11125 // this marker, and this is too late.
11126 // If this render already had a ping or lower pri updates,
11127 // and this is the first time we know we're going to suspend we
11128 // should be able to immediately restart from within throwException.
11129 var hasInvisibleChildContext = current === null && workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
11130
11131 if (hasInvisibleChildContext || hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext)) {
11132 // If this was in an invisible tree or a new render, then showing
11133 // this boundary is ok.
11134 renderDidSuspend();
11135 } else {
11136 // Otherwise, we're going to have to hide content so we should
11137 // suspend for longer if possible.
11138 renderDidSuspendDelayIfPossible();
11139 }
11140 }
11141 }
11142
11143 if (supportsPersistence) {
11144 // TODO: Only schedule updates if not prevDidTimeout.
11145 if (nextDidTimeout) {
11146 // If this boundary just timed out, schedule an effect to attach a
11147 // retry listener to the proimse. This flag is also used to hide the
11148 // primary children.
11149 workInProgress.effectTag |= Update;
11150 }
11151 }
11152
11153 if (supportsMutation) {
11154 // TODO: Only schedule updates if these values are non equal, i.e. it changed.
11155 if (nextDidTimeout || prevDidTimeout) {
11156 // If this boundary just timed out, schedule an effect to attach a
11157 // retry listener to the proimse. This flag is also used to hide the
11158 // primary children. In mutation mode, we also need the flag to
11159 // *unhide* children that were previously hidden, so check if the
11160 // is currently timed out, too.
11161 workInProgress.effectTag |= Update;
11162 }
11163 }
11164
11165 if (enableSuspenseCallback && workInProgress.updateQueue !== null && workInProgress.memoizedProps.suspenseCallback != null) {
11166 // Always notify the callback
11167 workInProgress.effectTag |= Update;
11168 }
11169
11170 break;
11171 }
11172
11173 case Fragment:
11174 break;
11175
11176 case Mode:
11177 break;
11178
11179 case Profiler:
11180 break;
11181
11182 case HostPortal:
11183 popHostContainer(workInProgress);
11184 updateHostContainer(workInProgress);
11185 break;
11186
11187 case ContextProvider:
11188 // Pop provider fiber
11189 popProvider(workInProgress);
11190 break;
11191
11192 case ContextConsumer:
11193 break;
11194
11195 case MemoComponent:
11196 break;
11197
11198 case IncompleteClassComponent:
11199 {
11200 // Same as class component case. I put it down here so that the tags are
11201 // sequential to ensure this switch is compiled to a jump table.
11202 var _Component = workInProgress.type;
11203
11204 if (isContextProvider(_Component)) {
11205 popContext(workInProgress);
11206 }
11207
11208 break;
11209 }
11210
11211 case SuspenseListComponent:
11212 {
11213 popSuspenseContext(workInProgress);
11214 var renderState = workInProgress.memoizedState;
11215
11216 if (renderState === null) {
11217 // We're running in the default, "independent" mode. We don't do anything
11218 // in this mode.
11219 break;
11220 }
11221
11222 var didSuspendAlready = (workInProgress.effectTag & DidCapture) !== NoEffect;
11223 var renderedTail = renderState.rendering;
11224
11225 if (renderedTail === null) {
11226 // We just rendered the head.
11227 if (!didSuspendAlready) {
11228 // This is the first pass. We need to figure out if anything is still
11229 // suspended in the rendered set.
11230 // If new content unsuspended, but there's still some content that
11231 // didn't. Then we need to do a second pass that forces everything
11232 // to keep showing their fallbacks.
11233 // We might be suspended if something in this render pass suspended, or
11234 // something in the previous committed pass suspended. Otherwise,
11235 // there's no chance so we can skip the expensive call to
11236 // findFirstSuspended.
11237 var cannotBeSuspended = renderHasNotSuspendedYet() && (current === null || (current.effectTag & DidCapture) === NoEffect);
11238
11239 if (!cannotBeSuspended) {
11240 var row = workInProgress.child;
11241
11242 while (row !== null) {
11243 var suspended = findFirstSuspended(row);
11244
11245 if (suspended !== null) {
11246 didSuspendAlready = true;
11247 workInProgress.effectTag |= DidCapture;
11248 cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
11249 // part of the second pass. In that case nothing will subscribe to
11250 // its thennables. Instead, we'll transfer its thennables to the
11251 // SuspenseList so that it can retry if they resolve.
11252 // There might be multiple of these in the list but since we're
11253 // going to wait for all of them anyway, it doesn't really matter
11254 // which ones gets to ping. In theory we could get clever and keep
11255 // track of how many dependencies remain but it gets tricky because
11256 // in the meantime, we can add/remove/change items and dependencies.
11257 // We might bail out of the loop before finding any but that
11258 // doesn't matter since that means that the other boundaries that
11259 // we did find already has their listeners attached.
11260
11261 var newThennables = suspended.updateQueue;
11262
11263 if (newThennables !== null) {
11264 workInProgress.updateQueue = newThennables;
11265 workInProgress.effectTag |= Update;
11266 } // Rerender the whole list, but this time, we'll force fallbacks
11267 // to stay in place.
11268 // Reset the effect list before doing the second pass since that's now invalid.
11269
11270
11271 workInProgress.firstEffect = workInProgress.lastEffect = null; // Reset the child fibers to their original state.
11272
11273 resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
11274 // rerender the children.
11275
11276 pushSuspenseContext(workInProgress, setShallowSuspenseContext(suspenseStackCursor.current, ForceSuspenseFallback));
11277 return workInProgress.child;
11278 }
11279
11280 row = row.sibling;
11281 }
11282 }
11283 } else {
11284 cutOffTailIfNeeded(renderState, false);
11285 } // Next we're going to render the tail.
11286
11287 } else {
11288 // Append the rendered row to the child list.
11289 if (!didSuspendAlready) {
11290 var _suspended = findFirstSuspended(renderedTail);
11291
11292 if (_suspended !== null) {
11293 workInProgress.effectTag |= DidCapture;
11294 didSuspendAlready = true;
11295 cutOffTailIfNeeded(renderState, true); // This might have been modified.
11296
11297 if (renderState.tail === null && renderState.tailMode === 'hidden') {
11298 // We need to delete the row we just rendered.
11299 // Ensure we transfer the update queue to the parent.
11300 var _newThennables = _suspended.updateQueue;
11301
11302 if (_newThennables !== null) {
11303 workInProgress.updateQueue = _newThennables;
11304 workInProgress.effectTag |= Update;
11305 } // Reset the effect list to what it w as before we rendered this
11306 // child. The nested children have already appended themselves.
11307
11308
11309 var lastEffect = workInProgress.lastEffect = renderState.lastEffect; // Remove any effects that were appended after this point.
11310
11311 if (lastEffect !== null) {
11312 lastEffect.nextEffect = null;
11313 } // We're done.
11314
11315
11316 return null;
11317 }
11318 } else if (now() > renderState.tailExpiration && renderExpirationTime > Never) {
11319 // We have now passed our CPU deadline and we'll just give up further
11320 // attempts to render the main content and only render fallbacks.
11321 // The assumption is that this is usually faster.
11322 workInProgress.effectTag |= DidCapture;
11323 didSuspendAlready = true;
11324 cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
11325 // to get it started back up to attempt the next item. If we can show
11326 // them, then they really have the same priority as this render.
11327 // So we'll pick it back up the very next render pass once we've had
11328 // an opportunity to yield for paint.
11329
11330 var nextPriority = renderExpirationTime - 1;
11331 workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
11332
11333 if (enableSchedulerTracing) {
11334 markSpawnedWork(nextPriority);
11335 }
11336 }
11337 }
11338
11339 if (renderState.isBackwards) {
11340 // The effect list of the backwards tail will have been added
11341 // to the end. This breaks the guarantee that life-cycles fire in
11342 // sibling order but that isn't a strong guarantee promised by React.
11343 // Especially since these might also just pop in during future commits.
11344 // Append to the beginning of the list.
11345 renderedTail.sibling = workInProgress.child;
11346 workInProgress.child = renderedTail;
11347 } else {
11348 var previousSibling = renderState.last;
11349
11350 if (previousSibling !== null) {
11351 previousSibling.sibling = renderedTail;
11352 } else {
11353 workInProgress.child = renderedTail;
11354 }
11355
11356 renderState.last = renderedTail;
11357 }
11358 }
11359
11360 if (renderState.tail !== null) {
11361 // We still have tail rows to render.
11362 if (renderState.tailExpiration === 0) {
11363 // Heuristic for how long we're willing to spend rendering rows
11364 // until we just give up and show what we have so far.
11365 var TAIL_EXPIRATION_TIMEOUT_MS = 500;
11366 renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS;
11367 } // Pop a row.
11368
11369
11370 var next = renderState.tail;
11371 renderState.rendering = next;
11372 renderState.tail = next.sibling;
11373 renderState.lastEffect = workInProgress.lastEffect;
11374 next.sibling = null; // Restore the context.
11375 // TODO: We can probably just avoid popping it instead and only
11376 // setting it the first time we go from not suspended to suspended.
11377
11378 var suspenseContext = suspenseStackCursor.current;
11379
11380 if (didSuspendAlready) {
11381 suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
11382 } else {
11383 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
11384 }
11385
11386 pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
11387
11388 return next;
11389 }
11390
11391 break;
11392 }
11393
11394 case FundamentalComponent:
11395 {
11396 if (enableFundamentalAPI) {
11397 var fundamentalImpl = workInProgress.type.impl;
11398 var fundamentalInstance = workInProgress.stateNode;
11399
11400 if (fundamentalInstance === null) {
11401 var getInitialState = fundamentalImpl.getInitialState;
11402 var fundamentalState;
11403
11404 if (getInitialState !== undefined) {
11405 fundamentalState = getInitialState(newProps);
11406 }
11407
11408 fundamentalInstance = workInProgress.stateNode = createFundamentalStateInstance(workInProgress, newProps, fundamentalImpl, fundamentalState || {});
11409
11410 var _instance5 = getFundamentalComponentInstance(fundamentalInstance);
11411
11412 fundamentalInstance.instance = _instance5;
11413
11414 if (fundamentalImpl.reconcileChildren === false) {
11415 return null;
11416 }
11417
11418 appendAllChildren(_instance5, workInProgress, false, false);
11419 mountFundamentalComponent(fundamentalInstance);
11420 } else {
11421 // We fire update in commit phase
11422 var prevProps = fundamentalInstance.props;
11423 fundamentalInstance.prevProps = prevProps;
11424 fundamentalInstance.props = newProps;
11425 fundamentalInstance.currentFiber = workInProgress;
11426
11427 if (supportsPersistence) {
11428 var _instance6 = cloneFundamentalInstance(fundamentalInstance);
11429
11430 fundamentalInstance.instance = _instance6;
11431 appendAllChildren(_instance6, workInProgress, false, false);
11432 }
11433
11434 var shouldUpdate = shouldUpdateFundamentalComponent(fundamentalInstance);
11435
11436 if (shouldUpdate) {
11437 markUpdate(workInProgress);
11438 }
11439 }
11440 }
11441
11442 break;
11443 }
11444
11445 case ScopeComponent:
11446 {
11447 if (enableScopeAPI) {
11448 if (current === null) {
11449 var _type3 = workInProgress.type;
11450 var scopeInstance = {
11451 fiber: workInProgress,
11452 methods: null
11453 };
11454 workInProgress.stateNode = scopeInstance;
11455 scopeInstance.methods = createScopeMethods(_type3, scopeInstance);
11456
11457 if (enableFlareAPI) {
11458 var _listeners2 = newProps.listeners;
11459
11460 if (_listeners2 != null) {
11461 var _rootContainerInstance2 = getRootHostContainer();
11462
11463 updateEventListeners(_listeners2, workInProgress, _rootContainerInstance2);
11464 }
11465 }
11466
11467 if (workInProgress.ref !== null) {
11468 markRef$1(workInProgress);
11469 markUpdate(workInProgress);
11470 }
11471 } else {
11472 if (enableFlareAPI) {
11473 var _prevListeners = current.memoizedProps.listeners;
11474 var _nextListeners = newProps.listeners;
11475
11476 if (_prevListeners !== _nextListeners || workInProgress.ref !== null) {
11477 markUpdate(workInProgress);
11478 }
11479 } else {
11480 if (workInProgress.ref !== null) {
11481 markUpdate(workInProgress);
11482 }
11483 }
11484
11485 if (current.ref !== workInProgress.ref) {
11486 markRef$1(workInProgress);
11487 }
11488 }
11489 }
11490
11491 break;
11492 }
11493
11494 default:
11495 (function () {
11496 {
11497 {
11498 throw ReactError(Error("Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue."));
11499 }
11500 }
11501 })();
11502
11503 }
11504
11505 return null;
11506}
11507
11508function unwindWork(workInProgress, renderExpirationTime) {
11509 switch (workInProgress.tag) {
11510 case ClassComponent:
11511 {
11512 var Component = workInProgress.type;
11513
11514 if (isContextProvider(Component)) {
11515 popContext(workInProgress);
11516 }
11517
11518 var effectTag = workInProgress.effectTag;
11519
11520 if (effectTag & ShouldCapture) {
11521 workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
11522 return workInProgress;
11523 }
11524
11525 return null;
11526 }
11527
11528 case HostRoot:
11529 {
11530 popHostContainer(workInProgress);
11531 popTopLevelContextObject(workInProgress);
11532 var _effectTag = workInProgress.effectTag;
11533
11534 (function () {
11535 if (!((_effectTag & DidCapture) === NoEffect)) {
11536 {
11537 throw ReactError(Error("The root failed to unmount after an error. This is likely a bug in React. Please file an issue."));
11538 }
11539 }
11540 })();
11541
11542 workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
11543 return workInProgress;
11544 }
11545
11546 case HostComponent:
11547 {
11548 // TODO: popHydrationState
11549 popHostContext(workInProgress);
11550 return null;
11551 }
11552
11553 case SuspenseComponent:
11554 {
11555 popSuspenseContext(workInProgress);
11556
11557 if (enableSuspenseServerRenderer) {
11558 var suspenseState = workInProgress.memoizedState;
11559
11560 if (suspenseState !== null && suspenseState.dehydrated !== null) {
11561 (function () {
11562 if (!(workInProgress.alternate !== null)) {
11563 {
11564 throw ReactError(Error("Threw in newly mounted dehydrated component. This is likely a bug in React. Please file an issue."));
11565 }
11566 }
11567 })();
11568
11569 resetHydrationState();
11570 }
11571 }
11572
11573 var _effectTag2 = workInProgress.effectTag;
11574
11575 if (_effectTag2 & ShouldCapture) {
11576 workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture; // Captured a suspense effect. Re-render the boundary.
11577
11578 return workInProgress;
11579 }
11580
11581 return null;
11582 }
11583
11584 case SuspenseListComponent:
11585 {
11586 popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
11587 // caught by a nested boundary. If not, it should bubble through.
11588
11589 return null;
11590 }
11591
11592 case HostPortal:
11593 popHostContainer(workInProgress);
11594 return null;
11595
11596 case ContextProvider:
11597 popProvider(workInProgress);
11598 return null;
11599
11600 default:
11601 return null;
11602 }
11603}
11604
11605function unwindInterruptedWork(interruptedWork) {
11606 switch (interruptedWork.tag) {
11607 case ClassComponent:
11608 {
11609 var childContextTypes = interruptedWork.type.childContextTypes;
11610
11611 if (childContextTypes !== null && childContextTypes !== undefined) {
11612 popContext(interruptedWork);
11613 }
11614
11615 break;
11616 }
11617
11618 case HostRoot:
11619 {
11620 popHostContainer(interruptedWork);
11621 popTopLevelContextObject(interruptedWork);
11622 break;
11623 }
11624
11625 case HostComponent:
11626 {
11627 popHostContext(interruptedWork);
11628 break;
11629 }
11630
11631 case HostPortal:
11632 popHostContainer(interruptedWork);
11633 break;
11634
11635 case SuspenseComponent:
11636 popSuspenseContext(interruptedWork);
11637 break;
11638
11639 case SuspenseListComponent:
11640 popSuspenseContext(interruptedWork);
11641 break;
11642
11643 case ContextProvider:
11644 popProvider(interruptedWork);
11645 break;
11646
11647 default:
11648 break;
11649 }
11650}
11651
11652function createCapturedValue(value, source) {
11653 // If the value is an error, call this function immediately after it is thrown
11654 // so the stack is accurate.
11655 return {
11656 value: value,
11657 source: source,
11658 stack: getStackByFiberInDevAndProd(source)
11659 };
11660}
11661
11662var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
11663 var funcArgs = Array.prototype.slice.call(arguments, 3);
11664
11665 try {
11666 func.apply(context, funcArgs);
11667 } catch (error) {
11668 this.onError(error);
11669 }
11670};
11671
11672{
11673 // In DEV mode, we swap out invokeGuardedCallback for a special version
11674 // that plays more nicely with the browser's DevTools. The idea is to preserve
11675 // "Pause on exceptions" behavior. Because React wraps all user-provided
11676 // functions in invokeGuardedCallback, and the production version of
11677 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
11678 // like caught exceptions, and the DevTools won't pause unless the developer
11679 // takes the extra step of enabling pause on caught exceptions. This is
11680 // unintuitive, though, because even though React has caught the error, from
11681 // the developer's perspective, the error is uncaught.
11682 //
11683 // To preserve the expected "Pause on exceptions" behavior, we don't use a
11684 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
11685 // DOM node, and call the user-provided callback from inside an event handler
11686 // for that fake event. If the callback throws, the error is "captured" using
11687 // a global event handler. But because the error happens in a different
11688 // event loop context, it does not interrupt the normal program flow.
11689 // Effectively, this gives us try-catch behavior without actually using
11690 // try-catch. Neat!
11691 // Check that the browser supports the APIs we need to implement our special
11692 // DEV version of invokeGuardedCallback
11693 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
11694 var fakeNode = document.createElement('react');
11695
11696 var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
11697 // If document doesn't exist we know for sure we will crash in this method
11698 // when we call document.createEvent(). However this can cause confusing
11699 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
11700 // So we preemptively throw with a better message instead.
11701 (function () {
11702 if (!(typeof document !== 'undefined')) {
11703 {
11704 throw ReactError(Error("The `document` global was defined when React was initialized, but is not defined anymore. This can happen in a test environment if a component schedules an update from an asynchronous callback, but the test has already finished running. To solve this, you can either unmount the component at the end of your test (and ensure that any asynchronous operations get canceled in `componentWillUnmount`), or you can change the test itself to be asynchronous."));
11705 }
11706 }
11707 })();
11708
11709 var evt = document.createEvent('Event'); // Keeps track of whether the user-provided callback threw an error. We
11710 // set this to true at the beginning, then set it to false right after
11711 // calling the function. If the function errors, `didError` will never be
11712 // set to false. This strategy works even if the browser is flaky and
11713 // fails to call our global error handler, because it doesn't rely on
11714 // the error event at all.
11715
11716 var didError = true; // Keeps track of the value of window.event so that we can reset it
11717 // during the callback to let user code access window.event in the
11718 // browsers that support it.
11719
11720 var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
11721 // dispatching: https://github.com/facebook/react/issues/13688
11722
11723 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event'); // Create an event handler for our fake event. We will synchronously
11724 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
11725 // call the user-provided callback.
11726
11727 var funcArgs = Array.prototype.slice.call(arguments, 3);
11728
11729 function callCallback() {
11730 // We immediately remove the callback from event listeners so that
11731 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
11732 // nested call would trigger the fake event handlers of any call higher
11733 // in the stack.
11734 fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
11735 // window.event assignment in both IE <= 10 as they throw an error
11736 // "Member not found" in strict mode, and in Firefox which does not
11737 // support window.event.
11738
11739 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
11740 window.event = windowEvent;
11741 }
11742
11743 func.apply(context, funcArgs);
11744 didError = false;
11745 } // Create a global error event handler. We use this to capture the value
11746 // that was thrown. It's possible that this error handler will fire more
11747 // than once; for example, if non-React code also calls `dispatchEvent`
11748 // and a handler for that event throws. We should be resilient to most of
11749 // those cases. Even if our error event handler fires more than once, the
11750 // last error event is always used. If the callback actually does error,
11751 // we know that the last error event is the correct one, because it's not
11752 // possible for anything else to have happened in between our callback
11753 // erroring and the code that follows the `dispatchEvent` call below. If
11754 // the callback doesn't error, but the error event was fired, we know to
11755 // ignore it because `didError` will be false, as described above.
11756
11757
11758 var error; // Use this to track whether the error event is ever called.
11759
11760 var didSetError = false;
11761 var isCrossOriginError = false;
11762
11763 function handleWindowError(event) {
11764 error = event.error;
11765 didSetError = true;
11766
11767 if (error === null && event.colno === 0 && event.lineno === 0) {
11768 isCrossOriginError = true;
11769 }
11770
11771 if (event.defaultPrevented) {
11772 // Some other error handler has prevented default.
11773 // Browsers silence the error report if this happens.
11774 // We'll remember this to later decide whether to log it or not.
11775 if (error != null && typeof error === 'object') {
11776 try {
11777 error._suppressLogging = true;
11778 } catch (inner) {// Ignore.
11779 }
11780 }
11781 }
11782 } // Create a fake event type.
11783
11784
11785 var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
11786
11787 window.addEventListener('error', handleWindowError);
11788 fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
11789 // errors, it will trigger our global error handler.
11790
11791 evt.initEvent(evtType, false, false);
11792 fakeNode.dispatchEvent(evt);
11793
11794 if (windowEventDescriptor) {
11795 Object.defineProperty(window, 'event', windowEventDescriptor);
11796 }
11797
11798 if (didError) {
11799 if (!didSetError) {
11800 // The callback errored, but the error event never fired.
11801 error = new Error('An error was thrown inside one of your components, but React ' + "doesn't know what it was. This is likely due to browser " + 'flakiness. React does its best to preserve the "Pause on ' + 'exceptions" behavior of the DevTools, which requires some ' + "DEV-mode only tricks. It's possible that these don't work in " + 'your browser. Try triggering the error in production mode, ' + 'or switching to a modern browser. If you suspect that this is ' + 'actually an issue with React, please file an issue.');
11802 } else if (isCrossOriginError) {
11803 error = new Error("A cross-origin error was thrown. React doesn't have access to " + 'the actual error object in development. ' + 'See https://fb.me/react-crossorigin-error for more information.');
11804 }
11805
11806 this.onError(error);
11807 } // Remove our event listeners
11808
11809
11810 window.removeEventListener('error', handleWindowError);
11811 };
11812
11813 invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
11814 }
11815}
11816
11817var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
11818
11819var hasError = false;
11820var caughtError = null; // Used by event system to capture/rethrow the first error.
11821
11822var reporter = {
11823 onError: function (error) {
11824 hasError = true;
11825 caughtError = error;
11826 }
11827};
11828/**
11829 * Call a function while guarding against errors that happens within it.
11830 * Returns an error if it throws, otherwise null.
11831 *
11832 * In production, this is implemented using a try-catch. The reason we don't
11833 * use a try-catch directly is so that we can swap out a different
11834 * implementation in DEV mode.
11835 *
11836 * @param {String} name of the guard to use for logging or debugging
11837 * @param {Function} func The function to invoke
11838 * @param {*} context The context to use when calling the function
11839 * @param {...*} args Arguments for function
11840 */
11841
11842function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
11843 hasError = false;
11844 caughtError = null;
11845 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
11846}
11847/**
11848 * Same as invokeGuardedCallback, but instead of returning an error, it stores
11849 * it in a global so it can be rethrown by `rethrowCaughtError` later.
11850 * TODO: See if caughtError and rethrowError can be unified.
11851 *
11852 * @param {String} name of the guard to use for logging or debugging
11853 * @param {Function} func The function to invoke
11854 * @param {*} context The context to use when calling the function
11855 * @param {...*} args Arguments for function
11856 */
11857
11858
11859/**
11860 * During execution of guarded functions we will capture the first error which
11861 * we will rethrow to be handled by the top level error handler.
11862 */
11863
11864
11865function hasCaughtError() {
11866 return hasError;
11867}
11868function clearCaughtError() {
11869 if (hasError) {
11870 var error = caughtError;
11871 hasError = false;
11872 caughtError = null;
11873 return error;
11874 } else {
11875 (function () {
11876 {
11877 {
11878 throw ReactError(Error("clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue."));
11879 }
11880 }
11881 })();
11882 }
11883}
11884
11885// This module is forked in different environments.
11886// By default, return `true` to log errors to the console.
11887// Forks can return `false` if this isn't desirable.
11888function showErrorDialog(capturedError) {
11889 return true;
11890}
11891
11892function logCapturedError(capturedError) {
11893 var logError = showErrorDialog(capturedError); // Allow injected showErrorDialog() to prevent default console.error logging.
11894 // This enables renderers like ReactNative to better manage redbox behavior.
11895
11896 if (logError === false) {
11897 return;
11898 }
11899
11900 var error = capturedError.error;
11901
11902 {
11903 var componentName = capturedError.componentName,
11904 componentStack = capturedError.componentStack,
11905 errorBoundaryName = capturedError.errorBoundaryName,
11906 errorBoundaryFound = capturedError.errorBoundaryFound,
11907 willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
11908 // `preventDefault()` in window `error` handler.
11909 // We record this information as an expando on the error.
11910
11911 if (error != null && error._suppressLogging) {
11912 if (errorBoundaryFound && willRetry) {
11913 // The error is recoverable and was silenced.
11914 // Ignore it and don't print the stack addendum.
11915 // This is handy for testing error boundaries without noise.
11916 return;
11917 } // The error is fatal. Since the silencing might have
11918 // been accidental, we'll surface it anyway.
11919 // However, the browser would have silenced the original error
11920 // so we'll print it first, and then print the stack addendum.
11921
11922
11923 console.error(error); // For a more detailed description of this block, see:
11924 // https://github.com/facebook/react/pull/13384
11925 }
11926
11927 var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:';
11928 var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
11929
11930 if (errorBoundaryFound && errorBoundaryName) {
11931 if (willRetry) {
11932 errorBoundaryMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + errorBoundaryName + ".");
11933 } else {
11934 errorBoundaryMessage = "This error was initially handled by the error boundary " + errorBoundaryName + ".\n" + "Recreating the tree from scratch failed so React will unmount the tree.";
11935 }
11936 } else {
11937 errorBoundaryMessage = 'Consider adding an error boundary to your tree to customize error handling behavior.\n' + 'Visit https://fb.me/react-error-boundaries to learn more about error boundaries.';
11938 }
11939
11940 var combinedMessage = "" + componentNameMessage + componentStack + "\n\n" + ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
11941 // We don't include the original error message and JS stack because the browser
11942 // has already printed it. Even if the application swallows the error, it is still
11943 // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
11944
11945 console.error(combinedMessage);
11946 }
11947}
11948
11949var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
11950
11951{
11952 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
11953}
11954
11955var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
11956function logError(boundary, errorInfo) {
11957 var source = errorInfo.source;
11958 var stack = errorInfo.stack;
11959
11960 if (stack === null && source !== null) {
11961 stack = getStackByFiberInDevAndProd(source);
11962 }
11963
11964 var capturedError = {
11965 componentName: source !== null ? getComponentName(source.type) : null,
11966 componentStack: stack !== null ? stack : '',
11967 error: errorInfo.value,
11968 errorBoundary: null,
11969 errorBoundaryName: null,
11970 errorBoundaryFound: false,
11971 willRetry: false
11972 };
11973
11974 if (boundary !== null && boundary.tag === ClassComponent) {
11975 capturedError.errorBoundary = boundary.stateNode;
11976 capturedError.errorBoundaryName = getComponentName(boundary.type);
11977 capturedError.errorBoundaryFound = true;
11978 capturedError.willRetry = true;
11979 }
11980
11981 try {
11982 logCapturedError(capturedError);
11983 } catch (e) {
11984 // This method must not throw, or React internal state will get messed up.
11985 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
11986 // we want to report this error outside of the normal stack as a last resort.
11987 // https://github.com/facebook/react/issues/13188
11988 setTimeout(function () {
11989 throw e;
11990 });
11991 }
11992}
11993
11994var callComponentWillUnmountWithTimer = function (current$$1, instance) {
11995 startPhaseTimer(current$$1, 'componentWillUnmount');
11996 instance.props = current$$1.memoizedProps;
11997 instance.state = current$$1.memoizedState;
11998 instance.componentWillUnmount();
11999 stopPhaseTimer();
12000}; // Capture errors so they don't interrupt unmounting.
12001
12002
12003function safelyCallComponentWillUnmount(current$$1, instance) {
12004 {
12005 invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current$$1, instance);
12006
12007 if (hasCaughtError()) {
12008 var unmountError = clearCaughtError();
12009 captureCommitPhaseError(current$$1, unmountError);
12010 }
12011 }
12012}
12013
12014function safelyDetachRef(current$$1) {
12015 var ref = current$$1.ref;
12016
12017 if (ref !== null) {
12018 if (typeof ref === 'function') {
12019 {
12020 invokeGuardedCallback(null, ref, null, null);
12021
12022 if (hasCaughtError()) {
12023 var refError = clearCaughtError();
12024 captureCommitPhaseError(current$$1, refError);
12025 }
12026 }
12027 } else {
12028 ref.current = null;
12029 }
12030 }
12031}
12032
12033function safelyCallDestroy(current$$1, destroy) {
12034 {
12035 invokeGuardedCallback(null, destroy, null);
12036
12037 if (hasCaughtError()) {
12038 var error = clearCaughtError();
12039 captureCommitPhaseError(current$$1, error);
12040 }
12041 }
12042}
12043
12044function commitBeforeMutationLifeCycles(current$$1, finishedWork) {
12045 switch (finishedWork.tag) {
12046 case FunctionComponent:
12047 case ForwardRef:
12048 case SimpleMemoComponent:
12049 {
12050 commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork);
12051 return;
12052 }
12053
12054 case ClassComponent:
12055 {
12056 if (finishedWork.effectTag & Snapshot) {
12057 if (current$$1 !== null) {
12058 var prevProps = current$$1.memoizedProps;
12059 var prevState = current$$1.memoizedState;
12060 startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
12061 var instance = finishedWork.stateNode; // We could update instance props and state here,
12062 // but instead we rely on them being set during last render.
12063 // TODO: revisit this when we implement resuming.
12064
12065 {
12066 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12067 !(instance.props === finishedWork.memoizedProps) ? warning$1(false, 'Expected %s props to match memoized props before ' + 'getSnapshotBeforeUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance') : void 0;
12068 !(instance.state === finishedWork.memoizedState) ? warning$1(false, 'Expected %s state to match memoized state before ' + 'getSnapshotBeforeUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance') : void 0;
12069 }
12070 }
12071
12072 var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
12073
12074 {
12075 var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
12076
12077 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
12078 didWarnSet.add(finishedWork.type);
12079 warningWithoutStack$1(false, '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
12080 }
12081 }
12082
12083 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
12084 stopPhaseTimer();
12085 }
12086 }
12087
12088 return;
12089 }
12090
12091 case HostRoot:
12092 case HostComponent:
12093 case HostText:
12094 case HostPortal:
12095 case IncompleteClassComponent:
12096 // Nothing to do for these component types
12097 return;
12098
12099 default:
12100 {
12101 (function () {
12102 {
12103 {
12104 throw ReactError(Error("This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."));
12105 }
12106 }
12107 })();
12108 }
12109 }
12110}
12111
12112function commitHookEffectList(unmountTag, mountTag, finishedWork) {
12113 var updateQueue = finishedWork.updateQueue;
12114 var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
12115
12116 if (lastEffect !== null) {
12117 var firstEffect = lastEffect.next;
12118 var effect = firstEffect;
12119
12120 do {
12121 if ((effect.tag & unmountTag) !== NoEffect$1) {
12122 // Unmount
12123 var destroy = effect.destroy;
12124 effect.destroy = undefined;
12125
12126 if (destroy !== undefined) {
12127 destroy();
12128 }
12129 }
12130
12131 if ((effect.tag & mountTag) !== NoEffect$1) {
12132 // Mount
12133 var create = effect.create;
12134 effect.destroy = create();
12135
12136 {
12137 var _destroy = effect.destroy;
12138
12139 if (_destroy !== undefined && typeof _destroy !== 'function') {
12140 var addendum = void 0;
12141
12142 if (_destroy === null) {
12143 addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
12144 } else if (typeof _destroy.then === 'function') {
12145 addendum = '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + "}, [someId]); // Or [] if effect doesn't need props or state\n\n" + 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching';
12146 } else {
12147 addendum = ' You returned: ' + _destroy;
12148 }
12149
12150 warningWithoutStack$1(false, 'An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
12151 }
12152 }
12153 }
12154
12155 effect = effect.next;
12156 } while (effect !== firstEffect);
12157 }
12158}
12159
12160function commitPassiveHookEffects(finishedWork) {
12161 if ((finishedWork.effectTag & Passive) !== NoEffect) {
12162 switch (finishedWork.tag) {
12163 case FunctionComponent:
12164 case ForwardRef:
12165 case SimpleMemoComponent:
12166 {
12167 commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork);
12168 commitHookEffectList(NoEffect$1, MountPassive, finishedWork);
12169 break;
12170 }
12171
12172 default:
12173 break;
12174 }
12175 }
12176}
12177
12178function commitLifeCycles(finishedRoot, current$$1, finishedWork, committedExpirationTime) {
12179 switch (finishedWork.tag) {
12180 case FunctionComponent:
12181 case ForwardRef:
12182 case SimpleMemoComponent:
12183 {
12184 commitHookEffectList(UnmountLayout, MountLayout, finishedWork);
12185 break;
12186 }
12187
12188 case ClassComponent:
12189 {
12190 var instance = finishedWork.stateNode;
12191
12192 if (finishedWork.effectTag & Update) {
12193 if (current$$1 === null) {
12194 startPhaseTimer(finishedWork, 'componentDidMount'); // We could update instance props and state here,
12195 // but instead we rely on them being set during last render.
12196 // TODO: revisit this when we implement resuming.
12197
12198 {
12199 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12200 !(instance.props === finishedWork.memoizedProps) ? warning$1(false, 'Expected %s props to match memoized props before ' + 'componentDidMount. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance') : void 0;
12201 !(instance.state === finishedWork.memoizedState) ? warning$1(false, 'Expected %s state to match memoized state before ' + 'componentDidMount. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance') : void 0;
12202 }
12203 }
12204
12205 instance.componentDidMount();
12206 stopPhaseTimer();
12207 } else {
12208 var prevProps = finishedWork.elementType === finishedWork.type ? current$$1.memoizedProps : resolveDefaultProps(finishedWork.type, current$$1.memoizedProps);
12209 var prevState = current$$1.memoizedState;
12210 startPhaseTimer(finishedWork, 'componentDidUpdate'); // We could update instance props and state here,
12211 // but instead we rely on them being set during last render.
12212 // TODO: revisit this when we implement resuming.
12213
12214 {
12215 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12216 !(instance.props === finishedWork.memoizedProps) ? warning$1(false, 'Expected %s props to match memoized props before ' + 'componentDidUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance') : void 0;
12217 !(instance.state === finishedWork.memoizedState) ? warning$1(false, 'Expected %s state to match memoized state before ' + 'componentDidUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance') : void 0;
12218 }
12219 }
12220
12221 instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
12222 stopPhaseTimer();
12223 }
12224 }
12225
12226 var updateQueue = finishedWork.updateQueue;
12227
12228 if (updateQueue !== null) {
12229 {
12230 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12231 !(instance.props === finishedWork.memoizedProps) ? warning$1(false, 'Expected %s props to match memoized props before ' + 'processing the update queue. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance') : void 0;
12232 !(instance.state === finishedWork.memoizedState) ? warning$1(false, 'Expected %s state to match memoized state before ' + 'processing the update queue. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance') : void 0;
12233 }
12234 } // We could update instance props and state here,
12235 // but instead we rely on them being set during last render.
12236 // TODO: revisit this when we implement resuming.
12237
12238
12239 commitUpdateQueue(finishedWork, updateQueue, instance, committedExpirationTime);
12240 }
12241
12242 return;
12243 }
12244
12245 case HostRoot:
12246 {
12247 var _updateQueue = finishedWork.updateQueue;
12248
12249 if (_updateQueue !== null) {
12250 var _instance = null;
12251
12252 if (finishedWork.child !== null) {
12253 switch (finishedWork.child.tag) {
12254 case HostComponent:
12255 _instance = getPublicInstance(finishedWork.child.stateNode);
12256 break;
12257
12258 case ClassComponent:
12259 _instance = finishedWork.child.stateNode;
12260 break;
12261 }
12262 }
12263
12264 commitUpdateQueue(finishedWork, _updateQueue, _instance, committedExpirationTime);
12265 }
12266
12267 return;
12268 }
12269
12270 case HostComponent:
12271 {
12272 var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
12273 // (eg DOM renderer may schedule auto-focus for inputs and form controls).
12274 // These effects should only be committed when components are first mounted,
12275 // aka when there is no current/alternate.
12276
12277 if (current$$1 === null && finishedWork.effectTag & Update) {
12278 var type = finishedWork.type;
12279 var props = finishedWork.memoizedProps;
12280
12281 }
12282
12283 return;
12284 }
12285
12286 case HostText:
12287 {
12288 // We have no life-cycles associated with text.
12289 return;
12290 }
12291
12292 case HostPortal:
12293 {
12294 // We have no life-cycles associated with portals.
12295 return;
12296 }
12297
12298 case Profiler:
12299 {
12300 if (enableProfilerTimer) {
12301 var onRender = finishedWork.memoizedProps.onRender;
12302
12303 if (typeof onRender === 'function') {
12304 if (enableSchedulerTracing) {
12305 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
12306 } else {
12307 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime());
12308 }
12309 }
12310 }
12311
12312 return;
12313 }
12314
12315 case SuspenseComponent:
12316 {
12317 commitSuspenseHydrationCallbacks(finishedRoot, finishedWork);
12318 return;
12319 }
12320
12321 case SuspenseListComponent:
12322 case IncompleteClassComponent:
12323 case FundamentalComponent:
12324 case ScopeComponent:
12325 return;
12326
12327 default:
12328 {
12329 (function () {
12330 {
12331 {
12332 throw ReactError(Error("This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."));
12333 }
12334 }
12335 })();
12336 }
12337 }
12338}
12339
12340function hideOrUnhideAllChildren(finishedWork, isHidden) {
12341 if (supportsMutation) {
12342 // We only have the top Fiber that was inserted but we need to recurse down its
12343 // children to find all the terminal nodes.
12344 var node = finishedWork;
12345
12346 while (true) {
12347 if (node.tag === HostComponent) {
12348 var instance = node.stateNode;
12349
12350 if (isHidden) {
12351 hideInstance(instance);
12352 } else {
12353 unhideInstance(node.stateNode, node.memoizedProps);
12354 }
12355 } else if (node.tag === HostText) {
12356 var _instance3 = node.stateNode;
12357
12358 if (isHidden) {
12359 hideTextInstance(_instance3);
12360 } else {
12361 unhideTextInstance(_instance3, node.memoizedProps);
12362 }
12363 } else if (node.tag === SuspenseComponent && node.memoizedState !== null && node.memoizedState.dehydrated === null) {
12364 // Found a nested Suspense component that timed out. Skip over the
12365 // primary child fragment, which should remain hidden.
12366 var fallbackChildFragment = node.child.sibling;
12367 fallbackChildFragment.return = node;
12368 node = fallbackChildFragment;
12369 continue;
12370 } else if (node.child !== null) {
12371 node.child.return = node;
12372 node = node.child;
12373 continue;
12374 }
12375
12376 if (node === finishedWork) {
12377 return;
12378 }
12379
12380 while (node.sibling === null) {
12381 if (node.return === null || node.return === finishedWork) {
12382 return;
12383 }
12384
12385 node = node.return;
12386 }
12387
12388 node.sibling.return = node.return;
12389 node = node.sibling;
12390 }
12391 }
12392}
12393
12394function commitAttachRef(finishedWork) {
12395 var ref = finishedWork.ref;
12396
12397 if (ref !== null) {
12398 var instance = finishedWork.stateNode;
12399 var instanceToUse;
12400
12401 switch (finishedWork.tag) {
12402 case HostComponent:
12403 instanceToUse = getPublicInstance(instance);
12404 break;
12405
12406 default:
12407 instanceToUse = instance;
12408 } // Moved outside to ensure DCE works with this flag
12409
12410
12411 if (enableScopeAPI && finishedWork.tag === ScopeComponent) {
12412 instanceToUse = instance.methods;
12413 }
12414
12415 if (typeof ref === 'function') {
12416 ref(instanceToUse);
12417 } else {
12418 {
12419 if (!ref.hasOwnProperty('current')) {
12420 warningWithoutStack$1(false, 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
12421 }
12422 }
12423
12424 ref.current = instanceToUse;
12425 }
12426 }
12427}
12428
12429function commitDetachRef(current$$1) {
12430 var currentRef = current$$1.ref;
12431
12432 if (currentRef !== null) {
12433 if (typeof currentRef === 'function') {
12434 currentRef(null);
12435 } else {
12436 currentRef.current = null;
12437 }
12438 }
12439} // User-originating errors (lifecycles and refs) should not interrupt
12440// deletion, so don't let them throw. Host-originating errors should
12441// interrupt deletion, so it's okay
12442
12443
12444function commitUnmount(finishedRoot, current$$1, renderPriorityLevel) {
12445 onCommitUnmount(current$$1);
12446
12447 switch (current$$1.tag) {
12448 case FunctionComponent:
12449 case ForwardRef:
12450 case MemoComponent:
12451 case SimpleMemoComponent:
12452 {
12453 var updateQueue = current$$1.updateQueue;
12454
12455 if (updateQueue !== null) {
12456 var lastEffect = updateQueue.lastEffect;
12457
12458 if (lastEffect !== null) {
12459 var firstEffect = lastEffect.next; // When the owner fiber is deleted, the destroy function of a passive
12460 // effect hook is called during the synchronous commit phase. This is
12461 // a concession to implementation complexity. Calling it in the
12462 // passive effect phase (like they usually are, when dependencies
12463 // change during an update) would require either traversing the
12464 // children of the deleted fiber again, or including unmount effects
12465 // as part of the fiber effect list.
12466 //
12467 // Because this is during the sync commit phase, we need to change
12468 // the priority.
12469 //
12470 // TODO: Reconsider this implementation trade off.
12471
12472 var priorityLevel = renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel;
12473 runWithPriority(priorityLevel, function () {
12474 var effect = firstEffect;
12475
12476 do {
12477 var destroy = effect.destroy;
12478
12479 if (destroy !== undefined) {
12480 safelyCallDestroy(current$$1, destroy);
12481 }
12482
12483 effect = effect.next;
12484 } while (effect !== firstEffect);
12485 });
12486 }
12487 }
12488
12489 break;
12490 }
12491
12492 case ClassComponent:
12493 {
12494 safelyDetachRef(current$$1);
12495 var instance = current$$1.stateNode;
12496
12497 if (typeof instance.componentWillUnmount === 'function') {
12498 safelyCallComponentWillUnmount(current$$1, instance);
12499 }
12500
12501 return;
12502 }
12503
12504 case HostComponent:
12505 {
12506 if (enableFlareAPI) {
12507 var dependencies = current$$1.dependencies;
12508
12509 if (dependencies !== null) {
12510 var respondersMap = dependencies.responders;
12511
12512 if (respondersMap !== null) {
12513 var responderInstances = Array.from(respondersMap.values());
12514
12515 for (var i = 0, length = responderInstances.length; i < length; i++) {
12516 var responderInstance = responderInstances[i];
12517
12518 }
12519
12520 dependencies.responders = null;
12521 }
12522 }
12523 }
12524
12525 safelyDetachRef(current$$1);
12526 return;
12527 }
12528
12529 case HostPortal:
12530 {
12531 // TODO: this is recursive.
12532 // We are also not using this parent because
12533 // the portal will get pushed immediately.
12534 if (supportsMutation) {
12535 unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel);
12536 } else if (supportsPersistence) {
12537 emptyPortalContainer(current$$1);
12538 }
12539
12540 return;
12541 }
12542
12543 case FundamentalComponent:
12544 {
12545 if (enableFundamentalAPI) {
12546 var fundamentalInstance = current$$1.stateNode;
12547
12548 if (fundamentalInstance !== null) {
12549 unmountFundamentalComponent(fundamentalInstance);
12550 current$$1.stateNode = null;
12551 }
12552 }
12553
12554 return;
12555 }
12556
12557 case DehydratedFragment:
12558 {
12559 if (enableSuspenseCallback) {
12560 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
12561
12562 if (hydrationCallbacks !== null) {
12563 var onDeleted = hydrationCallbacks.onDeleted;
12564
12565 if (onDeleted) {
12566 onDeleted(current$$1.stateNode);
12567 }
12568 }
12569 }
12570
12571 return;
12572 }
12573
12574 case ScopeComponent:
12575 {
12576 if (enableScopeAPI) {
12577 safelyDetachRef(current$$1);
12578 }
12579 }
12580 }
12581}
12582
12583function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
12584 // While we're inside a removed host node we don't want to call
12585 // removeChild on the inner nodes because they're removed by the top
12586 // call anyway. We also want to call componentWillUnmount on all
12587 // composites before this host node is removed from the tree. Therefore
12588 // we do an inner loop while we're still inside the host node.
12589 var node = root;
12590
12591 while (true) {
12592 commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
12593 // Skip portals because commitUnmount() currently visits them recursively.
12594
12595 if (node.child !== null && ( // If we use mutation we drill down into portals using commitUnmount above.
12596 // If we don't use mutation we drill down into portals here instead.
12597 !supportsMutation || node.tag !== HostPortal)) {
12598 node.child.return = node;
12599 node = node.child;
12600 continue;
12601 }
12602
12603 if (node === root) {
12604 return;
12605 }
12606
12607 while (node.sibling === null) {
12608 if (node.return === null || node.return === root) {
12609 return;
12610 }
12611
12612 node = node.return;
12613 }
12614
12615 node.sibling.return = node.return;
12616 node = node.sibling;
12617 }
12618}
12619
12620function detachFiber(current$$1) {
12621 var alternate = current$$1.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
12622 // should clear the child pointer of the parent alternate to let this
12623 // get GC:ed but we don't know which for sure which parent is the current
12624 // one so we'll settle for GC:ing the subtree of this child. This child
12625 // itself will be GC:ed when the parent updates the next time.
12626
12627 current$$1.return = null;
12628 current$$1.child = null;
12629 current$$1.memoizedState = null;
12630 current$$1.updateQueue = null;
12631 current$$1.dependencies = null;
12632 current$$1.alternate = null;
12633 current$$1.firstEffect = null;
12634 current$$1.lastEffect = null;
12635 current$$1.pendingProps = null;
12636 current$$1.memoizedProps = null;
12637
12638 if (alternate !== null) {
12639 detachFiber(alternate);
12640 }
12641}
12642
12643function emptyPortalContainer(current$$1) {
12644 if (!supportsPersistence) {
12645 return;
12646 }
12647
12648 var portal = current$$1.stateNode;
12649 var containerInfo = portal.containerInfo;
12650 var emptyChildSet = createContainerChildSet(containerInfo);
12651 replaceContainerChildren(containerInfo, emptyChildSet);
12652}
12653
12654function commitContainer(finishedWork) {
12655 if (!supportsPersistence) {
12656 return;
12657 }
12658
12659 switch (finishedWork.tag) {
12660 case ClassComponent:
12661 case HostComponent:
12662 case HostText:
12663 case FundamentalComponent:
12664 {
12665 return;
12666 }
12667
12668 case HostRoot:
12669 case HostPortal:
12670 {
12671 var portalOrRoot = finishedWork.stateNode;
12672 var containerInfo = portalOrRoot.containerInfo,
12673 pendingChildren = portalOrRoot.pendingChildren;
12674 replaceContainerChildren(containerInfo, pendingChildren);
12675 return;
12676 }
12677
12678 default:
12679 {
12680 (function () {
12681 {
12682 {
12683 throw ReactError(Error("This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."));
12684 }
12685 }
12686 })();
12687 }
12688 }
12689}
12690
12691function getHostParentFiber(fiber) {
12692 var parent = fiber.return;
12693
12694 while (parent !== null) {
12695 if (isHostParent(parent)) {
12696 return parent;
12697 }
12698
12699 parent = parent.return;
12700 }
12701
12702 (function () {
12703 {
12704 {
12705 throw ReactError(Error("Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue."));
12706 }
12707 }
12708 })();
12709}
12710
12711function isHostParent(fiber) {
12712 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
12713}
12714
12715function getHostSibling(fiber) {
12716 // We're going to search forward into the tree until we find a sibling host
12717 // node. Unfortunately, if multiple insertions are done in a row we have to
12718 // search past them. This leads to exponential search for the next sibling.
12719 // TODO: Find a more efficient way to do this.
12720 var node = fiber;
12721
12722 siblings: while (true) {
12723 // If we didn't find anything, let's try the next sibling.
12724 while (node.sibling === null) {
12725 if (node.return === null || isHostParent(node.return)) {
12726 // If we pop out of the root or hit the parent the fiber we are the
12727 // last sibling.
12728 return null;
12729 }
12730
12731 node = node.return;
12732 }
12733
12734 node.sibling.return = node.return;
12735 node = node.sibling;
12736
12737 while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {
12738 // If it is not host node and, we might have a host node inside it.
12739 // Try to search down until we find one.
12740 if (node.effectTag & Placement) {
12741 // If we don't have a child, try the siblings instead.
12742 continue siblings;
12743 } // If we don't have a child, try the siblings instead.
12744 // We also skip portals because they are not part of this host tree.
12745
12746
12747 if (node.child === null || node.tag === HostPortal) {
12748 continue siblings;
12749 } else {
12750 node.child.return = node;
12751 node = node.child;
12752 }
12753 } // Check if this host node is stable or about to be placed.
12754
12755
12756 if (!(node.effectTag & Placement)) {
12757 // Found it!
12758 return node.stateNode;
12759 }
12760 }
12761}
12762
12763function commitPlacement(finishedWork) {
12764 if (!supportsMutation) {
12765 return;
12766 } // Recursively insert all host nodes into the parent.
12767
12768
12769 var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
12770
12771 var parent;
12772 var isContainer;
12773 var parentStateNode = parentFiber.stateNode;
12774
12775 switch (parentFiber.tag) {
12776 case HostComponent:
12777 parent = parentStateNode;
12778 isContainer = false;
12779 break;
12780
12781 case HostRoot:
12782 parent = parentStateNode.containerInfo;
12783 isContainer = true;
12784 break;
12785
12786 case HostPortal:
12787 parent = parentStateNode.containerInfo;
12788 isContainer = true;
12789 break;
12790
12791 case FundamentalComponent:
12792 if (enableFundamentalAPI) {
12793 parent = parentStateNode.instance;
12794 isContainer = false;
12795 }
12796
12797 // eslint-disable-next-line-no-fallthrough
12798
12799 default:
12800 (function () {
12801 {
12802 {
12803 throw ReactError(Error("Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue."));
12804 }
12805 }
12806 })();
12807
12808 }
12809
12810 if (parentFiber.effectTag & ContentReset) {
12811 // Reset the text content of the parent before doing any insertions
12812 parentFiber.effectTag &= ~ContentReset;
12813 }
12814
12815 var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
12816 // children to find all the terminal nodes.
12817
12818 var node = finishedWork;
12819
12820 while (true) {
12821 var isHost = node.tag === HostComponent || node.tag === HostText;
12822
12823 if (isHost || enableFundamentalAPI && node.tag === FundamentalComponent) {
12824 var stateNode = isHost ? node.stateNode : node.stateNode.instance;
12825
12826 if (before) {
12827 if (isContainer) {
12828 insertInContainerBefore(parent, stateNode, before);
12829 } else {
12830 insertBefore(parent, stateNode, before);
12831 }
12832 } else {
12833 if (isContainer) {
12834 appendChildToContainer(parent, stateNode);
12835 } else {
12836 appendChild(parent, stateNode);
12837 }
12838 }
12839 } else if (node.tag === HostPortal) {// If the insertion itself is a portal, then we don't want to traverse
12840 // down its children. Instead, we'll get insertions from each child in
12841 // the portal directly.
12842 } else if (node.child !== null) {
12843 node.child.return = node;
12844 node = node.child;
12845 continue;
12846 }
12847
12848 if (node === finishedWork) {
12849 return;
12850 }
12851
12852 while (node.sibling === null) {
12853 if (node.return === null || node.return === finishedWork) {
12854 return;
12855 }
12856
12857 node = node.return;
12858 }
12859
12860 node.sibling.return = node.return;
12861 node = node.sibling;
12862 }
12863}
12864
12865function unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel) {
12866 // We only have the top Fiber that was deleted but we need to recurse down its
12867 // children to find all the terminal nodes.
12868 var node = current$$1; // Each iteration, currentParent is populated with node's host parent if not
12869 // currentParentIsValid.
12870
12871 var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
12872
12873 var currentParent;
12874 var currentParentIsContainer;
12875
12876 while (true) {
12877 if (!currentParentIsValid) {
12878 var parent = node.return;
12879
12880 findParent: while (true) {
12881 (function () {
12882 if (!(parent !== null)) {
12883 {
12884 throw ReactError(Error("Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue."));
12885 }
12886 }
12887 })();
12888
12889 var parentStateNode = parent.stateNode;
12890
12891 switch (parent.tag) {
12892 case HostComponent:
12893 currentParent = parentStateNode;
12894 currentParentIsContainer = false;
12895 break findParent;
12896
12897 case HostRoot:
12898 currentParent = parentStateNode.containerInfo;
12899 currentParentIsContainer = true;
12900 break findParent;
12901
12902 case HostPortal:
12903 currentParent = parentStateNode.containerInfo;
12904 currentParentIsContainer = true;
12905 break findParent;
12906
12907 case FundamentalComponent:
12908 if (enableFundamentalAPI) {
12909 currentParent = parentStateNode.instance;
12910 currentParentIsContainer = false;
12911 }
12912
12913 }
12914
12915 parent = parent.return;
12916 }
12917
12918 currentParentIsValid = true;
12919 }
12920
12921 if (node.tag === HostComponent || node.tag === HostText) {
12922 commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
12923 // node from the tree.
12924
12925 if (currentParentIsContainer) {
12926 removeChildFromContainer(currentParent, node.stateNode);
12927 } else {
12928 removeChild(currentParent, node.stateNode);
12929 } // Don't visit children because we already visited them.
12930
12931 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
12932 var fundamentalNode = node.stateNode.instance;
12933 commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
12934 // node from the tree.
12935
12936 if (currentParentIsContainer) {
12937 removeChildFromContainer(currentParent, fundamentalNode);
12938 } else {
12939 removeChild(currentParent, fundamentalNode);
12940 }
12941 } else if (enableSuspenseServerRenderer && node.tag === DehydratedFragment) {
12942 if (enableSuspenseCallback) {
12943 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
12944
12945 if (hydrationCallbacks !== null) {
12946 var onDeleted = hydrationCallbacks.onDeleted;
12947
12948 if (onDeleted) {
12949 onDeleted(node.stateNode);
12950 }
12951 }
12952 } // Delete the dehydrated suspense boundary and all of its content.
12953
12954
12955 if (currentParentIsContainer) {
12956 clearSuspenseBoundaryFromContainer(currentParent, node.stateNode);
12957 } else {
12958 clearSuspenseBoundary(currentParent, node.stateNode);
12959 }
12960 } else if (node.tag === HostPortal) {
12961 if (node.child !== null) {
12962 // When we go into a portal, it becomes the parent to remove from.
12963 // We will reassign it back when we pop the portal on the way up.
12964 currentParent = node.stateNode.containerInfo;
12965 currentParentIsContainer = true; // Visit children because portals might contain host components.
12966
12967 node.child.return = node;
12968 node = node.child;
12969 continue;
12970 }
12971 } else {
12972 commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because we may find more host components below.
12973
12974 if (node.child !== null) {
12975 node.child.return = node;
12976 node = node.child;
12977 continue;
12978 }
12979 }
12980
12981 if (node === current$$1) {
12982 return;
12983 }
12984
12985 while (node.sibling === null) {
12986 if (node.return === null || node.return === current$$1) {
12987 return;
12988 }
12989
12990 node = node.return;
12991
12992 if (node.tag === HostPortal) {
12993 // When we go out of the portal, we need to restore the parent.
12994 // Since we don't keep a stack of them, we will search for it.
12995 currentParentIsValid = false;
12996 }
12997 }
12998
12999 node.sibling.return = node.return;
13000 node = node.sibling;
13001 }
13002}
13003
13004function commitDeletion(finishedRoot, current$$1, renderPriorityLevel) {
13005 if (supportsMutation) {
13006 // Recursively delete all host nodes from the parent.
13007 // Detach refs and call componentWillUnmount() on the whole subtree.
13008 unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel);
13009 } else {
13010 // Detach refs and call componentWillUnmount() on the whole subtree.
13011 commitNestedUnmounts(finishedRoot, current$$1, renderPriorityLevel);
13012 }
13013
13014 detachFiber(current$$1);
13015}
13016
13017function commitWork(current$$1, finishedWork) {
13018 if (!supportsMutation) {
13019 switch (finishedWork.tag) {
13020 case FunctionComponent:
13021 case ForwardRef:
13022 case MemoComponent:
13023 case SimpleMemoComponent:
13024 {
13025 // Note: We currently never use MountMutation, but useLayout uses
13026 // UnmountMutation.
13027 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
13028 return;
13029 }
13030
13031 case Profiler:
13032 {
13033 return;
13034 }
13035
13036 case SuspenseComponent:
13037 {
13038 commitSuspenseComponent(finishedWork);
13039 attachSuspenseRetryListeners(finishedWork);
13040 return;
13041 }
13042
13043 case SuspenseListComponent:
13044 {
13045 attachSuspenseRetryListeners(finishedWork);
13046 return;
13047 }
13048
13049 case HostRoot:
13050 {
13051 if (supportsHydration) {
13052 var root = finishedWork.stateNode;
13053
13054 if (root.hydrate) {
13055 // We've just hydrated. No need to hydrate again.
13056 root.hydrate = false;
13057 commitHydratedContainer(root.containerInfo);
13058 }
13059 }
13060
13061 break;
13062 }
13063 }
13064
13065 commitContainer(finishedWork);
13066 return;
13067 }
13068
13069 switch (finishedWork.tag) {
13070 case FunctionComponent:
13071 case ForwardRef:
13072 case MemoComponent:
13073 case SimpleMemoComponent:
13074 {
13075 // Note: We currently never use MountMutation, but useLayout uses
13076 // UnmountMutation.
13077 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
13078 return;
13079 }
13080
13081 case ClassComponent:
13082 {
13083 return;
13084 }
13085
13086 case HostComponent:
13087 {
13088 var instance = finishedWork.stateNode;
13089
13090 if (instance != null) {
13091 // Commit the work prepared earlier.
13092 var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
13093 // as the newProps. The updatePayload will contain the real change in
13094 // this case.
13095
13096 var oldProps = current$$1 !== null ? current$$1.memoizedProps : newProps;
13097 var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
13098
13099 var updatePayload = finishedWork.updateQueue;
13100 finishedWork.updateQueue = null;
13101
13102 if (updatePayload !== null) {
13103 commitUpdate(instance, updatePayload, type, oldProps, newProps, finishedWork);
13104 }
13105
13106 if (enableFlareAPI) {
13107 var prevListeners = oldProps.listeners;
13108 var nextListeners = newProps.listeners;
13109
13110 if (prevListeners !== nextListeners) {
13111 updateEventListeners(nextListeners, finishedWork, null);
13112 }
13113 }
13114 }
13115
13116 return;
13117 }
13118
13119 case HostText:
13120 {
13121 (function () {
13122 if (!(finishedWork.stateNode !== null)) {
13123 {
13124 throw ReactError(Error("This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue."));
13125 }
13126 }
13127 })();
13128
13129 var textInstance = finishedWork.stateNode;
13130 var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
13131 // as the newProps. The updatePayload will contain the real change in
13132 // this case.
13133
13134 var oldText = current$$1 !== null ? current$$1.memoizedProps : newText;
13135 commitTextUpdate(textInstance, oldText, newText);
13136 return;
13137 }
13138
13139 case HostRoot:
13140 {
13141 if (supportsHydration) {
13142 var _root = finishedWork.stateNode;
13143
13144 if (_root.hydrate) {
13145 // We've just hydrated. No need to hydrate again.
13146 _root.hydrate = false;
13147 commitHydratedContainer(_root.containerInfo);
13148 }
13149 }
13150
13151 return;
13152 }
13153
13154 case Profiler:
13155 {
13156 return;
13157 }
13158
13159 case SuspenseComponent:
13160 {
13161 commitSuspenseComponent(finishedWork);
13162 attachSuspenseRetryListeners(finishedWork);
13163 return;
13164 }
13165
13166 case SuspenseListComponent:
13167 {
13168 attachSuspenseRetryListeners(finishedWork);
13169 return;
13170 }
13171
13172 case IncompleteClassComponent:
13173 {
13174 return;
13175 }
13176
13177 case FundamentalComponent:
13178 {
13179 if (enableFundamentalAPI) {
13180 var fundamentalInstance = finishedWork.stateNode;
13181 updateFundamentalComponent(fundamentalInstance);
13182 }
13183
13184 return;
13185 }
13186
13187 case ScopeComponent:
13188 {
13189 if (enableScopeAPI) {
13190 var scopeInstance = finishedWork.stateNode;
13191 scopeInstance.fiber = finishedWork;
13192
13193 if (enableFlareAPI) {
13194 var _newProps = finishedWork.memoizedProps;
13195
13196 var _oldProps = current$$1 !== null ? current$$1.memoizedProps : _newProps;
13197
13198 var _prevListeners = _oldProps.listeners;
13199 var _nextListeners = _newProps.listeners;
13200
13201 if (_prevListeners !== _nextListeners) {
13202 updateEventListeners(_nextListeners, finishedWork, null);
13203 }
13204 }
13205 }
13206
13207 return;
13208 }
13209
13210 default:
13211 {
13212 (function () {
13213 {
13214 {
13215 throw ReactError(Error("This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."));
13216 }
13217 }
13218 })();
13219 }
13220 }
13221}
13222
13223function commitSuspenseComponent(finishedWork) {
13224 var newState = finishedWork.memoizedState;
13225 var newDidTimeout;
13226 var primaryChildParent = finishedWork;
13227
13228 if (newState === null) {
13229 newDidTimeout = false;
13230 } else {
13231 newDidTimeout = true;
13232 primaryChildParent = finishedWork.child;
13233 markCommitTimeOfFallback();
13234 }
13235
13236 if (supportsMutation && primaryChildParent !== null) {
13237 hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
13238 }
13239
13240 if (enableSuspenseCallback && newState !== null) {
13241 var suspenseCallback = finishedWork.memoizedProps.suspenseCallback;
13242
13243 if (typeof suspenseCallback === 'function') {
13244 var thenables = finishedWork.updateQueue;
13245
13246 if (thenables !== null) {
13247 suspenseCallback(new Set(thenables));
13248 }
13249 } else {
13250 if (suspenseCallback !== undefined) {
13251 warning$1(false, 'Unexpected type for suspenseCallback.');
13252 }
13253 }
13254 }
13255}
13256
13257function commitSuspenseHydrationCallbacks(finishedRoot, finishedWork) {
13258 if (!supportsHydration) {
13259 return;
13260 }
13261
13262 var newState = finishedWork.memoizedState;
13263
13264 if (newState === null) {
13265 var current$$1 = finishedWork.alternate;
13266
13267 if (current$$1 !== null) {
13268 var prevState = current$$1.memoizedState;
13269
13270 if (prevState !== null) {
13271 var suspenseInstance = prevState.dehydrated;
13272
13273 if (suspenseInstance !== null) {
13274 commitHydratedSuspenseInstance(suspenseInstance);
13275
13276 if (enableSuspenseCallback) {
13277 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
13278
13279 if (hydrationCallbacks !== null) {
13280 var onHydrated = hydrationCallbacks.onHydrated;
13281
13282 if (onHydrated) {
13283 onHydrated(suspenseInstance);
13284 }
13285 }
13286 }
13287 }
13288 }
13289 }
13290 }
13291}
13292
13293function attachSuspenseRetryListeners(finishedWork) {
13294 // If this boundary just timed out, then it will have a set of thenables.
13295 // For each thenable, attach a listener so that when it resolves, React
13296 // attempts to re-render the boundary in the primary (pre-timeout) state.
13297 var thenables = finishedWork.updateQueue;
13298
13299 if (thenables !== null) {
13300 finishedWork.updateQueue = null;
13301 var retryCache = finishedWork.stateNode;
13302
13303 if (retryCache === null) {
13304 retryCache = finishedWork.stateNode = new PossiblyWeakSet();
13305 }
13306
13307 thenables.forEach(function (thenable) {
13308 // Memoize using the boundary fiber to prevent redundant listeners.
13309 var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
13310
13311 if (!retryCache.has(thenable)) {
13312 if (enableSchedulerTracing) {
13313 if (thenable.__reactDoNotTraceInteractions !== true) {
13314 retry = unstable_wrap(retry);
13315 }
13316 }
13317
13318 retryCache.add(thenable);
13319 thenable.then(retry, retry);
13320 }
13321 });
13322 }
13323}
13324
13325function commitResetTextContent(current$$1) {
13326 if (!supportsMutation) {
13327 return;
13328 }
13329
13330 resetTextContent(current$$1.stateNode);
13331}
13332
13333var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
13334
13335function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
13336 var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
13337
13338 update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
13339 // being called "element".
13340
13341 update.payload = {
13342 element: null
13343 };
13344 var error = errorInfo.value;
13345
13346 update.callback = function () {
13347 onUncaughtError(error);
13348 logError(fiber, errorInfo);
13349 };
13350
13351 return update;
13352}
13353
13354function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
13355 var update = createUpdate(expirationTime, null);
13356 update.tag = CaptureUpdate;
13357 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
13358
13359 if (typeof getDerivedStateFromError === 'function') {
13360 var error = errorInfo.value;
13361
13362 update.payload = function () {
13363 logError(fiber, errorInfo);
13364 return getDerivedStateFromError(error);
13365 };
13366 }
13367
13368 var inst = fiber.stateNode;
13369
13370 if (inst !== null && typeof inst.componentDidCatch === 'function') {
13371 update.callback = function callback() {
13372 {
13373 markFailedErrorBoundaryForHotReloading(fiber);
13374 }
13375
13376 if (typeof getDerivedStateFromError !== 'function') {
13377 // To preserve the preexisting retry behavior of error boundaries,
13378 // we keep track of which ones already failed during this batch.
13379 // This gets reset before we yield back to the browser.
13380 // TODO: Warn in strict mode if getDerivedStateFromError is
13381 // not defined.
13382 markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
13383
13384 logError(fiber, errorInfo);
13385 }
13386
13387 var error = errorInfo.value;
13388 var stack = errorInfo.stack;
13389 this.componentDidCatch(error, {
13390 componentStack: stack !== null ? stack : ''
13391 });
13392
13393 {
13394 if (typeof getDerivedStateFromError !== 'function') {
13395 // If componentDidCatch is the only error boundary method defined,
13396 // then it needs to call setState to recover from errors.
13397 // If no state update is scheduled then the boundary will swallow the error.
13398 !(fiber.expirationTime === Sync) ? warningWithoutStack$1(false, '%s: Error boundaries should implement getDerivedStateFromError(). ' + 'In that method, return a state update to display an error message or fallback UI.', getComponentName(fiber.type) || 'Unknown') : void 0;
13399 }
13400 }
13401 };
13402 } else {
13403 update.callback = function () {
13404 markFailedErrorBoundaryForHotReloading(fiber);
13405 };
13406 }
13407
13408 return update;
13409}
13410
13411function attachPingListener(root, renderExpirationTime, thenable) {
13412 // Attach a listener to the promise to "ping" the root and retry. But
13413 // only if one does not already exist for the current render expiration
13414 // time (which acts like a "thread ID" here).
13415 var pingCache = root.pingCache;
13416 var threadIDs;
13417
13418 if (pingCache === null) {
13419 pingCache = root.pingCache = new PossiblyWeakMap();
13420 threadIDs = new Set();
13421 pingCache.set(thenable, threadIDs);
13422 } else {
13423 threadIDs = pingCache.get(thenable);
13424
13425 if (threadIDs === undefined) {
13426 threadIDs = new Set();
13427 pingCache.set(thenable, threadIDs);
13428 }
13429 }
13430
13431 if (!threadIDs.has(renderExpirationTime)) {
13432 // Memoize using the thread ID to prevent redundant listeners.
13433 threadIDs.add(renderExpirationTime);
13434 var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
13435 thenable.then(ping, ping);
13436 }
13437}
13438
13439function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
13440 // The source fiber did not complete.
13441 sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
13442
13443 sourceFiber.firstEffect = sourceFiber.lastEffect = null;
13444
13445 if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
13446 // This is a thenable.
13447 var thenable = value;
13448 checkForWrongSuspensePriorityInDEV(sourceFiber);
13449 var hasInvisibleParentBoundary = hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext); // Schedule the nearest Suspense to re-render the timed out view.
13450
13451 var _workInProgress = returnFiber;
13452
13453 do {
13454 if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)) {
13455 // Found the nearest boundary.
13456 // Stash the promise on the boundary fiber. If the boundary times out, we'll
13457 // attach another listener to flip the boundary back to its normal state.
13458 var thenables = _workInProgress.updateQueue;
13459
13460 if (thenables === null) {
13461 var updateQueue = new Set();
13462 updateQueue.add(thenable);
13463 _workInProgress.updateQueue = updateQueue;
13464 } else {
13465 thenables.add(thenable);
13466 } // If the boundary is outside of batched mode, we should *not*
13467 // suspend the commit. Pretend as if the suspended component rendered
13468 // null and keep rendering. In the commit phase, we'll schedule a
13469 // subsequent synchronous update to re-render the Suspense.
13470 //
13471 // Note: It doesn't matter whether the component that suspended was
13472 // inside a batched mode tree. If the Suspense is outside of it, we
13473 // should *not* suspend the commit.
13474
13475
13476 if ((_workInProgress.mode & BatchedMode) === NoMode) {
13477 _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
13478 // But we shouldn't call any lifecycle methods or callbacks. Remove
13479 // all lifecycle effect tags.
13480
13481 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
13482
13483 if (sourceFiber.tag === ClassComponent) {
13484 var currentSourceFiber = sourceFiber.alternate;
13485
13486 if (currentSourceFiber === null) {
13487 // This is a new mount. Change the tag so it's not mistaken for a
13488 // completed class component. For example, we should not call
13489 // componentWillUnmount if it is deleted.
13490 sourceFiber.tag = IncompleteClassComponent;
13491 } else {
13492 // When we try rendering again, we should not reuse the current fiber,
13493 // since it's known to be in an inconsistent state. Use a force update to
13494 // prevent a bail out.
13495 var update = createUpdate(Sync, null);
13496 update.tag = ForceUpdate;
13497 enqueueUpdate(sourceFiber, update);
13498 }
13499 } // The source fiber did not complete. Mark it with Sync priority to
13500 // indicate that it still has pending work.
13501
13502
13503 sourceFiber.expirationTime = Sync; // Exit without suspending.
13504
13505 return;
13506 } // Confirmed that the boundary is in a concurrent mode tree. Continue
13507 // with the normal suspend path.
13508 //
13509 // After this we'll use a set of heuristics to determine whether this
13510 // render pass will run to completion or restart or "suspend" the commit.
13511 // The actual logic for this is spread out in different places.
13512 //
13513 // This first principle is that if we're going to suspend when we complete
13514 // a root, then we should also restart if we get an update or ping that
13515 // might unsuspend it, and vice versa. The only reason to suspend is
13516 // because you think you might want to restart before committing. However,
13517 // it doesn't make sense to restart only while in the period we're suspended.
13518 //
13519 // Restarting too aggressively is also not good because it starves out any
13520 // intermediate loading state. So we use heuristics to determine when.
13521 // Suspense Heuristics
13522 //
13523 // If nothing threw a Promise or all the same fallbacks are already showing,
13524 // then don't suspend/restart.
13525 //
13526 // If this is an initial render of a new tree of Suspense boundaries and
13527 // those trigger a fallback, then don't suspend/restart. We want to ensure
13528 // that we can show the initial loading state as quickly as possible.
13529 //
13530 // If we hit a "Delayed" case, such as when we'd switch from content back into
13531 // a fallback, then we should always suspend/restart. SuspenseConfig applies to
13532 // this case. If none is defined, JND is used instead.
13533 //
13534 // If we're already showing a fallback and it gets "retried", allowing us to show
13535 // another level, but there's still an inner boundary that would show a fallback,
13536 // then we suspend/restart for 500ms since the last time we showed a fallback
13537 // anywhere in the tree. This effectively throttles progressive loading into a
13538 // consistent train of commits. This also gives us an opportunity to restart to
13539 // get to the completed state slightly earlier.
13540 //
13541 // If there's ambiguity due to batching it's resolved in preference of:
13542 // 1) "delayed", 2) "initial render", 3) "retry".
13543 //
13544 // We want to ensure that a "busy" state doesn't get force committed. We want to
13545 // ensure that new initial loading states can commit as soon as possible.
13546
13547
13548 attachPingListener(root, renderExpirationTime, thenable);
13549 _workInProgress.effectTag |= ShouldCapture;
13550 _workInProgress.expirationTime = renderExpirationTime;
13551 return;
13552 } // This boundary already captured during this render. Continue to the next
13553 // boundary.
13554
13555
13556 _workInProgress = _workInProgress.return;
13557 } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
13558 // TODO: Use invariant so the message is stripped in prod?
13559
13560
13561 value = new Error((getComponentName(sourceFiber.type) || 'A React component') + ' suspended while rendering, but no fallback UI was specified.\n' + '\n' + 'Add a <Suspense fallback=...> component higher in the tree to ' + 'provide a loading indicator or placeholder to display.' + getStackByFiberInDevAndProd(sourceFiber));
13562 } // We didn't find a boundary that could handle this type of exception. Start
13563 // over and traverse parent path again, this time treating the exception
13564 // as an error.
13565
13566
13567 renderDidError();
13568 value = createCapturedValue(value, sourceFiber);
13569 var workInProgress = returnFiber;
13570
13571 do {
13572 switch (workInProgress.tag) {
13573 case HostRoot:
13574 {
13575 var _errorInfo = value;
13576 workInProgress.effectTag |= ShouldCapture;
13577 workInProgress.expirationTime = renderExpirationTime;
13578
13579 var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
13580
13581 enqueueCapturedUpdate(workInProgress, _update);
13582 return;
13583 }
13584
13585 case ClassComponent:
13586 // Capture and retry
13587 var errorInfo = value;
13588 var ctor = workInProgress.type;
13589 var instance = workInProgress.stateNode;
13590
13591 if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
13592 workInProgress.effectTag |= ShouldCapture;
13593 workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
13594
13595 var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
13596
13597 enqueueCapturedUpdate(workInProgress, _update2);
13598 return;
13599 }
13600
13601 break;
13602
13603 default:
13604 break;
13605 }
13606
13607 workInProgress = workInProgress.return;
13608 } while (workInProgress !== null);
13609}
13610
13611var ceil = Math.ceil;
13612var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
13613var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
13614var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
13615var NoContext =
13616/* */
136170;
13618var BatchedContext =
13619/* */
136201;
13621var DiscreteEventContext =
13622/* */
136234;
13624var LegacyUnbatchedContext =
13625/* */
136268;
13627var RenderContext =
13628/* */
1362916;
13630var CommitContext =
13631/* */
1363232;
13633var RootIncomplete = 0;
13634var RootFatalErrored = 1;
13635var RootErrored = 2;
13636var RootSuspended = 3;
13637var RootSuspendedWithDelay = 4;
13638var RootCompleted = 5;
13639var RootLocked = 6;
13640// Describes where we are in the React execution stack
13641var executionContext = NoContext; // The root we're working on
13642
13643var workInProgressRoot = null; // The fiber we're working on
13644
13645var workInProgress = null; // The expiration time we're rendering
13646
13647var renderExpirationTime = NoWork; // Whether to root completed, errored, suspended, etc.
13648
13649var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
13650
13651var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
13652// This is conceptually a time stamp but expressed in terms of an ExpirationTime
13653// because we deal mostly with expiration times in the hot path, so this avoids
13654// the conversion happening in the hot path.
13655
13656var workInProgressRootLatestProcessedExpirationTime = Sync;
13657var workInProgressRootLatestSuspenseTimeout = Sync;
13658var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
13659// includes unprocessed updates, not work in bailed out children.
13660
13661var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
13662// This flag determines if it might be worthwhile to restart if an opportunity
13663// happens latere.
13664
13665var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
13666// model where we don't commit new loading states in too quick succession.
13667
13668var globalMostRecentFallbackTime = 0;
13669var FALLBACK_THROTTLE_MS = 500;
13670var nextEffect = null;
13671var hasUncaughtError = false;
13672var firstUncaughtError = null;
13673var legacyErrorBoundariesThatAlreadyFailed = null;
13674var rootDoesHavePassiveEffects = false;
13675var rootWithPendingPassiveEffects = null;
13676var pendingPassiveEffectsRenderPriority = NoPriority;
13677var pendingPassiveEffectsExpirationTime = NoWork;
13678var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
13679
13680var NESTED_UPDATE_LIMIT = 50;
13681var nestedUpdateCount = 0;
13682var rootWithNestedUpdates = null;
13683var NESTED_PASSIVE_UPDATE_LIMIT = 50;
13684var nestedPassiveUpdateCount = 0;
13685var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
13686// during the commit phase. This enables them to be traced across components
13687// that spawn new work during render. E.g. hidden boundaries, suspended SSR
13688// hydration or SuspenseList.
13689
13690var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
13691// time). However, if two updates are scheduled within the same event, we
13692// should treat their start times as simultaneous, even if the actual clock
13693// time has advanced between the first and second call.
13694// In other words, because expiration times determine how updates are batched,
13695// we want all updates of like priority that occur within the same event to
13696// receive the same expiration time. Otherwise we get tearing.
13697
13698var currentEventTime = NoWork;
13699function requestCurrentTime() {
13700 if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
13701 // We're inside React, so it's fine to read the actual time.
13702 return msToExpirationTime(now());
13703 } // We're not inside React, so we may be in the middle of a browser event.
13704
13705
13706 if (currentEventTime !== NoWork) {
13707 // Use the same start time for all updates until we enter React again.
13708 return currentEventTime;
13709 } // This is the first update since React yielded. Compute a new start time.
13710
13711
13712 currentEventTime = msToExpirationTime(now());
13713 return currentEventTime;
13714}
13715function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
13716 var mode = fiber.mode;
13717
13718 if ((mode & BatchedMode) === NoMode) {
13719 return Sync;
13720 }
13721
13722 var priorityLevel = getCurrentPriorityLevel();
13723
13724 if ((mode & ConcurrentMode) === NoMode) {
13725 return priorityLevel === ImmediatePriority ? Sync : Batched;
13726 }
13727
13728 if ((executionContext & RenderContext) !== NoContext) {
13729 // Use whatever time we're already rendering
13730 // TODO: Should there be a way to opt out, like with `runWithPriority`?
13731 return renderExpirationTime;
13732 }
13733
13734 var expirationTime;
13735
13736 if (suspenseConfig !== null) {
13737 // Compute an expiration time based on the Suspense timeout.
13738 expirationTime = computeSuspenseExpiration(currentTime, suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
13739 } else {
13740 // Compute an expiration time based on the Scheduler priority.
13741 switch (priorityLevel) {
13742 case ImmediatePriority:
13743 expirationTime = Sync;
13744 break;
13745
13746 case UserBlockingPriority:
13747 // TODO: Rename this to computeUserBlockingExpiration
13748 expirationTime = computeInteractiveExpiration(currentTime);
13749 break;
13750
13751 case NormalPriority:
13752 case LowPriority:
13753 // TODO: Handle LowPriority
13754 // TODO: Rename this to... something better.
13755 expirationTime = computeAsyncExpiration(currentTime);
13756 break;
13757
13758 case IdlePriority:
13759 expirationTime = Idle;
13760 break;
13761
13762 default:
13763 (function () {
13764 {
13765 {
13766 throw ReactError(Error("Expected a valid priority level"));
13767 }
13768 }
13769 })();
13770
13771 }
13772 } // If we're in the middle of rendering a tree, do not update at the same
13773 // expiration time that is already rendering.
13774 // TODO: We shouldn't have to do this if the update is on a different root.
13775 // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
13776 // the root when we check for this condition.
13777
13778
13779 if (workInProgressRoot !== null && expirationTime === renderExpirationTime) {
13780 // This is a trick to move this update into a separate batch
13781 expirationTime -= 1;
13782 }
13783
13784 return expirationTime;
13785}
13786
13787function scheduleUpdateOnFiber(fiber, expirationTime) {
13788 checkForNestedUpdates();
13789 warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber);
13790 var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
13791
13792 if (root === null) {
13793 warnAboutUpdateOnUnmountedFiberInDEV(fiber);
13794 return;
13795 }
13796
13797 checkForInterruption(fiber, expirationTime);
13798 recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
13799 // priority as an argument to that function and this one.
13800
13801 var priorityLevel = getCurrentPriorityLevel();
13802
13803 if (expirationTime === Sync) {
13804 if ( // Check if we're inside unbatchedUpdates
13805 (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
13806 (executionContext & (RenderContext | CommitContext)) === NoContext) {
13807 // Register pending interactions on the root to avoid losing traced interaction data.
13808 schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
13809 // root inside of batchedUpdates should be synchronous, but layout updates
13810 // should be deferred until the end of the batch.
13811
13812 performSyncWorkOnRoot(root);
13813 } else {
13814 ensureRootIsScheduled(root);
13815 schedulePendingInteractions(root, expirationTime);
13816
13817 if (executionContext === NoContext) {
13818 // Flush the synchronous work now, unless we're already working or inside
13819 // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
13820 // scheduleCallbackForFiber to preserve the ability to schedule a callback
13821 // without immediately flushing it. We only do this for user-initiated
13822 // updates, to preserve historical behavior of sync mode.
13823 flushSyncCallbackQueue();
13824 }
13825 }
13826 } else {
13827 ensureRootIsScheduled(root);
13828 schedulePendingInteractions(root, expirationTime);
13829 }
13830
13831 if ((executionContext & DiscreteEventContext) !== NoContext && ( // Only updates at user-blocking priority or greater are considered
13832 // discrete, even inside a discrete event.
13833 priorityLevel === UserBlockingPriority || priorityLevel === ImmediatePriority)) {
13834 // This is the result of a discrete event. Track the lowest priority
13835 // discrete update per root so we can flush them early, if needed.
13836 if (rootsWithPendingDiscreteUpdates === null) {
13837 rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
13838 } else {
13839 var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
13840
13841 if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
13842 rootsWithPendingDiscreteUpdates.set(root, expirationTime);
13843 }
13844 }
13845 }
13846}
13847var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
13848// work without treating it as a typical update that originates from an event;
13849// e.g. retrying a Suspense boundary isn't an update, but it does schedule work
13850// on a fiber.
13851
13852function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
13853 // Update the source fiber's expiration time
13854 if (fiber.expirationTime < expirationTime) {
13855 fiber.expirationTime = expirationTime;
13856 }
13857
13858 var alternate = fiber.alternate;
13859
13860 if (alternate !== null && alternate.expirationTime < expirationTime) {
13861 alternate.expirationTime = expirationTime;
13862 } // Walk the parent path to the root and update the child expiration time.
13863
13864
13865 var node = fiber.return;
13866 var root = null;
13867
13868 if (node === null && fiber.tag === HostRoot) {
13869 root = fiber.stateNode;
13870 } else {
13871 while (node !== null) {
13872 alternate = node.alternate;
13873
13874 if (node.childExpirationTime < expirationTime) {
13875 node.childExpirationTime = expirationTime;
13876
13877 if (alternate !== null && alternate.childExpirationTime < expirationTime) {
13878 alternate.childExpirationTime = expirationTime;
13879 }
13880 } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
13881 alternate.childExpirationTime = expirationTime;
13882 }
13883
13884 if (node.return === null && node.tag === HostRoot) {
13885 root = node.stateNode;
13886 break;
13887 }
13888
13889 node = node.return;
13890 }
13891 }
13892
13893 if (root !== null) {
13894 if (workInProgressRoot === root) {
13895 // Received an update to a tree that's in the middle of rendering. Mark
13896 // that's unprocessed work on this root.
13897 markUnprocessedUpdateTime(expirationTime);
13898
13899 if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
13900 // The root already suspended with a delay, which means this render
13901 // definitely won't finish. Since we have a new update, let's mark it as
13902 // suspended now, right before marking the incoming update. This has the
13903 // effect of interrupting the current render and switching to the update.
13904 // TODO: This happens to work when receiving an update during the render
13905 // phase, because of the trick inside computeExpirationForFiber to
13906 // subtract 1 from `renderExpirationTime` to move it into a
13907 // separate bucket. But we should probably model it with an exception,
13908 // using the same mechanism we use to force hydration of a subtree.
13909 // TODO: This does not account for low pri updates that were already
13910 // scheduled before the root started rendering. Need to track the next
13911 // pending expiration time (perhaps by backtracking the return path) and
13912 // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
13913 markRootSuspendedAtTime(root, renderExpirationTime);
13914 }
13915 } // Mark that the root has a pending update.
13916
13917
13918 markRootUpdatedAtTime(root, expirationTime);
13919 }
13920
13921 return root;
13922}
13923
13924function getNextRootExpirationTimeToWorkOn(root) {
13925 // Determines the next expiration time that the root should render, taking
13926 // into account levels that may be suspended, or levels that may have
13927 // received a ping.
13928 var lastExpiredTime = root.lastExpiredTime;
13929
13930 if (lastExpiredTime !== NoWork) {
13931 return lastExpiredTime;
13932 } // "Pending" refers to any update that hasn't committed yet, including if it
13933 // suspended. The "suspended" range is therefore a subset.
13934
13935
13936 var firstPendingTime = root.firstPendingTime;
13937
13938 if (!isRootSuspendedAtTime(root, firstPendingTime)) {
13939 // The highest priority pending time is not suspended. Let's work on that.
13940 return firstPendingTime;
13941 } // If the first pending time is suspended, check if there's a lower priority
13942 // pending level that we know about. Or check if we received a ping. Work
13943 // on whichever is higher priority.
13944
13945
13946 var lastPingedTime = root.lastPingedTime;
13947 var nextKnownPendingLevel = root.nextKnownPendingLevel;
13948 return lastPingedTime > nextKnownPendingLevel ? lastPingedTime : nextKnownPendingLevel;
13949} // Use this function to schedule a task for a root. There's only one task per
13950// root; if a task was already scheduled, we'll check to make sure the
13951// expiration time of the existing task is the same as the expiration time of
13952// the next level that the root has work on. This function is called on every
13953// update, and right before exiting a task.
13954
13955
13956function ensureRootIsScheduled(root) {
13957 var lastExpiredTime = root.lastExpiredTime;
13958
13959 if (lastExpiredTime !== NoWork) {
13960 // Special case: Expired work should flush synchronously.
13961 root.callbackExpirationTime = Sync;
13962 root.callbackPriority = ImmediatePriority;
13963 root.callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
13964 return;
13965 }
13966
13967 var expirationTime = getNextRootExpirationTimeToWorkOn(root);
13968 var existingCallbackNode = root.callbackNode;
13969
13970 if (expirationTime === NoWork) {
13971 // There's nothing to work on.
13972 if (existingCallbackNode !== null) {
13973 root.callbackNode = null;
13974 root.callbackExpirationTime = NoWork;
13975 root.callbackPriority = NoPriority;
13976 }
13977
13978 return;
13979 } // TODO: If this is an update, we already read the current time. Pass the
13980 // time as an argument.
13981
13982
13983 var currentTime = requestCurrentTime();
13984 var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime); // If there's an existing render task, confirm it has the correct priority and
13985 // expiration time. Otherwise, we'll cancel it and schedule a new one.
13986
13987 if (existingCallbackNode !== null) {
13988 var existingCallbackPriority = root.callbackPriority;
13989 var existingCallbackExpirationTime = root.callbackExpirationTime;
13990
13991 if ( // Callback must have the exact same expiration time.
13992 existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
13993 existingCallbackPriority >= priorityLevel) {
13994 // Existing callback is sufficient.
13995 return;
13996 } // Need to schedule a new task.
13997 // TODO: Instead of scheduling a new task, we should be able to change the
13998 // priority of the existing one.
13999
14000
14001 cancelCallback(existingCallbackNode);
14002 }
14003
14004 root.callbackExpirationTime = expirationTime;
14005 root.callbackPriority = priorityLevel;
14006 var callbackNode;
14007
14008 if (expirationTime === Sync) {
14009 // Sync React callbacks are scheduled on a special internal queue
14010 callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
14011 } else if (disableSchedulerTimeoutBasedOnReactExpirationTime) {
14012 callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root));
14013 } else {
14014 callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
14015 // ordering because tasks are processed in timeout order.
14016 {
14017 timeout: expirationTimeToMs(expirationTime) - now()
14018 });
14019 }
14020
14021 root.callbackNode = callbackNode;
14022} // This is the entry point for every concurrent task, i.e. anything that
14023// goes through Scheduler.
14024
14025
14026function performConcurrentWorkOnRoot(root, didTimeout) {
14027 // Since we know we're in a React event, we can clear the current
14028 // event time. The next update will compute a new event time.
14029 currentEventTime = NoWork;
14030
14031 if (didTimeout) {
14032 // The render task took too long to complete. Mark the current time as
14033 // expired to synchronously render all expired work in a single batch.
14034 var currentTime = requestCurrentTime();
14035 markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
14036
14037 ensureRootIsScheduled(root);
14038 return null;
14039 } // Determine the next expiration time to work on, using the fields stored
14040 // on the root.
14041
14042
14043 var expirationTime = getNextRootExpirationTimeToWorkOn(root);
14044
14045 if (expirationTime !== NoWork) {
14046 var originalCallbackNode = root.callbackNode;
14047
14048 (function () {
14049 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
14050 {
14051 throw ReactError(Error("Should not already be working."));
14052 }
14053 }
14054 })();
14055
14056 flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
14057 // and prepare a fresh one. Otherwise we'll continue where we left off.
14058
14059 if (root !== workInProgressRoot || expirationTime !== renderExpirationTime) {
14060 prepareFreshStack(root, expirationTime);
14061 startWorkOnPendingInteractions(root, expirationTime);
14062 } // If we have a work-in-progress fiber, it means there's still work to do
14063 // in this root.
14064
14065
14066 if (workInProgress !== null) {
14067 var prevExecutionContext = executionContext;
14068 executionContext |= RenderContext;
14069 var prevDispatcher = pushDispatcher(root);
14070 var prevInteractions = pushInteractions(root);
14071 startWorkLoopTimer(workInProgress);
14072
14073 do {
14074 try {
14075 workLoopConcurrent();
14076 break;
14077 } catch (thrownValue) {
14078 handleError(root, thrownValue);
14079 }
14080 } while (true);
14081
14082 resetContextDependencies();
14083 executionContext = prevExecutionContext;
14084 popDispatcher(prevDispatcher);
14085
14086 if (enableSchedulerTracing) {
14087 popInteractions(prevInteractions);
14088 }
14089
14090 if (workInProgressRootExitStatus === RootFatalErrored) {
14091 var fatalError = workInProgressRootFatalError;
14092 stopInterruptedWorkLoopTimer();
14093 prepareFreshStack(root, expirationTime);
14094 markRootSuspendedAtTime(root, expirationTime);
14095 ensureRootIsScheduled(root);
14096 throw fatalError;
14097 }
14098
14099 if (workInProgress !== null) {
14100 // There's still work left over. Exit without committing.
14101 stopInterruptedWorkLoopTimer();
14102 } else {
14103 // We now have a consistent tree. The next step is either to commit it,
14104 // or, if something suspended, wait to commit it after a timeout.
14105 stopFinishedWorkLoopTimer();
14106 var finishedWork = root.finishedWork = root.current.alternate;
14107 root.finishedExpirationTime = expirationTime;
14108 resolveLocksOnRoot(root, expirationTime);
14109 finishConcurrentRender(root, finishedWork, workInProgressRootExitStatus, expirationTime);
14110 }
14111
14112 ensureRootIsScheduled(root);
14113
14114 if (root.callbackNode === originalCallbackNode) {
14115 // The task node scheduled for this root is the same one that's
14116 // currently executed. Need to return a continuation.
14117 return performConcurrentWorkOnRoot.bind(null, root);
14118 }
14119 }
14120 }
14121
14122 return null;
14123}
14124
14125function finishConcurrentRender(root, finishedWork, exitStatus, expirationTime) {
14126 // Set this to null to indicate there's no in-progress render.
14127 workInProgressRoot = null;
14128
14129 switch (exitStatus) {
14130 case RootIncomplete:
14131 case RootFatalErrored:
14132 {
14133 (function () {
14134 {
14135 {
14136 throw ReactError(Error("Root did not complete. This is a bug in React."));
14137 }
14138 }
14139 })();
14140 }
14141 // Flow knows about invariant, so it complains if I add a break
14142 // statement, but eslint doesn't know about invariant, so it complains
14143 // if I do. eslint-disable-next-line no-fallthrough
14144
14145 case RootErrored:
14146 {
14147 if (expirationTime !== Idle) {
14148 // If this was an async render, the error may have happened due to
14149 // a mutation in a concurrent event. Try rendering one more time,
14150 // synchronously, to see if the error goes away. If there are
14151 // lower priority updates, let's include those, too, in case they
14152 // fix the inconsistency. Render at Idle to include all updates.
14153 markRootExpiredAtTime(root, Idle);
14154 break;
14155 } // Commit the root in its errored state.
14156
14157
14158 commitRoot(root);
14159 break;
14160 }
14161
14162 case RootSuspended:
14163 {
14164 markRootSuspendedAtTime(root, expirationTime);
14165 var lastSuspendedTime = root.lastSuspendedTime;
14166
14167 if (expirationTime === lastSuspendedTime) {
14168 root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
14169 }
14170
14171 flushSuspensePriorityWarningInDEV(); // We have an acceptable loading state. We need to figure out if we
14172 // should immediately commit it or wait a bit.
14173 // If we have processed new updates during this render, we may now
14174 // have a new loading state ready. We want to ensure that we commit
14175 // that as soon as possible.
14176
14177 var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync;
14178
14179 if (hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
14180 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current)) {
14181 // If we have not processed any new updates during this pass, then
14182 // this is either a retry of an existing fallback state or a
14183 // hidden tree. Hidden trees shouldn't be batched with other work
14184 // and after that's fixed it can only be a retry. We're going to
14185 // throttle committing retries so that we don't show too many
14186 // loading states too quickly.
14187 var msUntilTimeout = globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
14188
14189 if (msUntilTimeout > 10) {
14190 if (workInProgressRootHasPendingPing) {
14191 var lastPingedTime = root.lastPingedTime;
14192
14193 if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
14194 // This render was pinged but we didn't get to restart
14195 // earlier so try restarting now instead.
14196 root.lastPingedTime = expirationTime;
14197 prepareFreshStack(root, expirationTime);
14198 break;
14199 }
14200 }
14201
14202 var nextTime = getNextRootExpirationTimeToWorkOn(root);
14203
14204 if (nextTime !== NoWork && nextTime !== expirationTime) {
14205 // There's additional work on this root.
14206 break;
14207 }
14208
14209 if (lastSuspendedTime !== NoWork && lastSuspendedTime !== expirationTime) {
14210 // We should prefer to render the fallback of at the last
14211 // suspended level. Ping the last suspended level to try
14212 // rendering it again.
14213 root.lastPingedTime = lastSuspendedTime;
14214 break;
14215 } // The render is suspended, it hasn't timed out, and there's no
14216 // lower priority work to do. Instead of committing the fallback
14217 // immediately, wait for more data to arrive.
14218
14219
14220 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), msUntilTimeout);
14221 break;
14222 }
14223 } // The work expired. Commit immediately.
14224
14225
14226 commitRoot(root);
14227 break;
14228 }
14229
14230 case RootSuspendedWithDelay:
14231 {
14232 markRootSuspendedAtTime(root, expirationTime);
14233 var _lastSuspendedTime = root.lastSuspendedTime;
14234
14235 if (expirationTime === _lastSuspendedTime) {
14236 root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
14237 }
14238
14239 flushSuspensePriorityWarningInDEV();
14240
14241 if ( // do not delay if we're inside an act() scope
14242 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current)) {
14243 // We're suspended in a state that should be avoided. We'll try to
14244 // avoid committing it for as long as the timeouts let us.
14245 if (workInProgressRootHasPendingPing) {
14246 var _lastPingedTime = root.lastPingedTime;
14247
14248 if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
14249 // This render was pinged but we didn't get to restart earlier
14250 // so try restarting now instead.
14251 root.lastPingedTime = expirationTime;
14252 prepareFreshStack(root, expirationTime);
14253 break;
14254 }
14255 }
14256
14257 var _nextTime = getNextRootExpirationTimeToWorkOn(root);
14258
14259 if (_nextTime !== NoWork && _nextTime !== expirationTime) {
14260 // There's additional work on this root.
14261 break;
14262 }
14263
14264 if (_lastSuspendedTime !== NoWork && _lastSuspendedTime !== expirationTime) {
14265 // We should prefer to render the fallback of at the last
14266 // suspended level. Ping the last suspended level to try
14267 // rendering it again.
14268 root.lastPingedTime = _lastSuspendedTime;
14269 break;
14270 }
14271
14272 var _msUntilTimeout;
14273
14274 if (workInProgressRootLatestSuspenseTimeout !== Sync) {
14275 // We have processed a suspense config whose expiration time we
14276 // can use as the timeout.
14277 _msUntilTimeout = expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
14278 } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
14279 // This should never normally happen because only new updates
14280 // cause delayed states, so we should have processed something.
14281 // However, this could also happen in an offscreen tree.
14282 _msUntilTimeout = 0;
14283 } else {
14284 // If we don't have a suspense config, we're going to use a
14285 // heuristic to determine how long we can suspend.
14286 var eventTimeMs = inferTimeFromExpirationTime(workInProgressRootLatestProcessedExpirationTime);
14287 var currentTimeMs = now();
14288 var timeUntilExpirationMs = expirationTimeToMs(expirationTime) - currentTimeMs;
14289 var timeElapsed = currentTimeMs - eventTimeMs;
14290
14291 if (timeElapsed < 0) {
14292 // We get this wrong some time since we estimate the time.
14293 timeElapsed = 0;
14294 }
14295
14296 _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
14297 // event time is exact instead of inferred from expiration time
14298 // we don't need this.
14299
14300 if (timeUntilExpirationMs < _msUntilTimeout) {
14301 _msUntilTimeout = timeUntilExpirationMs;
14302 }
14303 } // Don't bother with a very short suspense time.
14304
14305
14306 if (_msUntilTimeout > 10) {
14307 // The render is suspended, it hasn't timed out, and there's no
14308 // lower priority work to do. Instead of committing the fallback
14309 // immediately, wait for more data to arrive.
14310 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout);
14311 break;
14312 }
14313 } // The work expired. Commit immediately.
14314
14315
14316 commitRoot(root);
14317 break;
14318 }
14319
14320 case RootCompleted:
14321 {
14322 // The work completed. Ready to commit.
14323 if ( // do not delay if we're inside an act() scope
14324 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null) {
14325 // If we have exceeded the minimum loading delay, which probably
14326 // means we have shown a spinner already, we might have to suspend
14327 // a bit longer to ensure that the spinner is shown for
14328 // enough time.
14329 var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(workInProgressRootLatestProcessedExpirationTime, expirationTime, workInProgressRootCanSuspendUsingConfig);
14330
14331 if (_msUntilTimeout2 > 10) {
14332 markRootSuspendedAtTime(root, expirationTime);
14333 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout2);
14334 break;
14335 }
14336 }
14337
14338 commitRoot(root);
14339 break;
14340 }
14341
14342 case RootLocked:
14343 {
14344 // This root has a lock that prevents it from committing. Exit. If
14345 // we begin work on the root again, without any intervening updates,
14346 // it will finish without doing additional work.
14347 markRootSuspendedAtTime(root, expirationTime);
14348 break;
14349 }
14350
14351 default:
14352 {
14353 (function () {
14354 {
14355 {
14356 throw ReactError(Error("Unknown root exit status."));
14357 }
14358 }
14359 })();
14360 }
14361 }
14362} // This is the entry point for synchronous tasks that don't go
14363// through Scheduler
14364
14365
14366function performSyncWorkOnRoot(root) {
14367 // Check if there's expired work on this root. Otherwise, render at Sync.
14368 var lastExpiredTime = root.lastExpiredTime;
14369 var expirationTime = lastExpiredTime !== NoWork ? lastExpiredTime : Sync;
14370
14371 if (root.finishedExpirationTime === expirationTime) {
14372 // There's already a pending commit at this expiration time.
14373 // TODO: This is poorly factored. This case only exists for the
14374 // batch.commit() API.
14375 commitRoot(root);
14376 } else {
14377 (function () {
14378 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
14379 {
14380 throw ReactError(Error("Should not already be working."));
14381 }
14382 }
14383 })();
14384
14385 flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
14386 // and prepare a fresh one. Otherwise we'll continue where we left off.
14387
14388 if (root !== workInProgressRoot || expirationTime !== renderExpirationTime) {
14389 prepareFreshStack(root, expirationTime);
14390 startWorkOnPendingInteractions(root, expirationTime);
14391 } // If we have a work-in-progress fiber, it means there's still work to do
14392 // in this root.
14393
14394
14395 if (workInProgress !== null) {
14396 var prevExecutionContext = executionContext;
14397 executionContext |= RenderContext;
14398 var prevDispatcher = pushDispatcher(root);
14399 var prevInteractions = pushInteractions(root);
14400 startWorkLoopTimer(workInProgress);
14401
14402 do {
14403 try {
14404 workLoopSync();
14405 break;
14406 } catch (thrownValue) {
14407 handleError(root, thrownValue);
14408 }
14409 } while (true);
14410
14411 resetContextDependencies();
14412 executionContext = prevExecutionContext;
14413 popDispatcher(prevDispatcher);
14414
14415 if (enableSchedulerTracing) {
14416 popInteractions(prevInteractions);
14417 }
14418
14419 if (workInProgressRootExitStatus === RootFatalErrored) {
14420 var fatalError = workInProgressRootFatalError;
14421 stopInterruptedWorkLoopTimer();
14422 prepareFreshStack(root, expirationTime);
14423 markRootSuspendedAtTime(root, expirationTime);
14424 ensureRootIsScheduled(root);
14425 throw fatalError;
14426 }
14427
14428 if (workInProgress !== null) {
14429 // This is a sync render, so we should have finished the whole tree.
14430 (function () {
14431 {
14432 {
14433 throw ReactError(Error("Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue."));
14434 }
14435 }
14436 })();
14437 } else {
14438 // We now have a consistent tree. Because this is a sync render, we
14439 // will commit it even if something suspended. The only exception is
14440 // if the root is locked (using the unstable_createBatch API).
14441 stopFinishedWorkLoopTimer();
14442 root.finishedWork = root.current.alternate;
14443 root.finishedExpirationTime = expirationTime;
14444 resolveLocksOnRoot(root, expirationTime);
14445 finishSyncRender(root, workInProgressRootExitStatus, expirationTime);
14446 } // Before exiting, make sure there's a callback scheduled for the next
14447 // pending level.
14448
14449
14450 ensureRootIsScheduled(root);
14451 }
14452 }
14453
14454 return null;
14455}
14456
14457function finishSyncRender(root, exitStatus, expirationTime) {
14458 if (exitStatus === RootLocked) {
14459 // This root has a lock that prevents it from committing. Exit. If we
14460 // begin work on the root again, without any intervening updates, it
14461 // will finish without doing additional work.
14462 markRootSuspendedAtTime(root, expirationTime);
14463 } else {
14464 // Set this to null to indicate there's no in-progress render.
14465 workInProgressRoot = null;
14466
14467 {
14468 if (exitStatus === RootSuspended || exitStatus === RootSuspendedWithDelay) {
14469 flushSuspensePriorityWarningInDEV();
14470 }
14471 }
14472
14473 commitRoot(root);
14474 }
14475}
14476
14477
14478
14479
14480function resolveLocksOnRoot(root, expirationTime) {
14481 var firstBatch = root.firstBatch;
14482
14483 if (firstBatch !== null && firstBatch._defer && firstBatch._expirationTime >= expirationTime) {
14484 scheduleCallback(NormalPriority, function () {
14485 firstBatch._onComplete();
14486
14487 return null;
14488 });
14489 workInProgressRootExitStatus = RootLocked;
14490 }
14491}
14492
14493
14494
14495
14496function batchedUpdates(fn, a) {
14497 var prevExecutionContext = executionContext;
14498 executionContext |= BatchedContext;
14499
14500 try {
14501 return fn(a);
14502 } finally {
14503 executionContext = prevExecutionContext;
14504
14505 if (executionContext === NoContext) {
14506 // Flush the immediate callbacks that were scheduled during this batch
14507 flushSyncCallbackQueue();
14508 }
14509 }
14510}
14511
14512
14513
14514function flushSync(fn, a) {
14515 if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
14516 (function () {
14517 {
14518 {
14519 throw ReactError(Error("flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering."));
14520 }
14521 }
14522 })();
14523 }
14524
14525 var prevExecutionContext = executionContext;
14526 executionContext |= BatchedContext;
14527
14528 try {
14529 return runWithPriority(ImmediatePriority, fn.bind(null, a));
14530 } finally {
14531 executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
14532 // Note that this will happen even if batchedUpdates is higher up
14533 // the stack.
14534
14535 flushSyncCallbackQueue();
14536 }
14537}
14538
14539
14540function prepareFreshStack(root, expirationTime) {
14541 root.finishedWork = null;
14542 root.finishedExpirationTime = NoWork;
14543 var timeoutHandle = root.timeoutHandle;
14544
14545 if (timeoutHandle !== noTimeout) {
14546 // The root previous suspended and scheduled a timeout to commit a fallback
14547 // state. Now that we have additional work, cancel the timeout.
14548 root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
14549
14550 cancelTimeout(timeoutHandle);
14551 }
14552
14553 if (workInProgress !== null) {
14554 var interruptedWork = workInProgress.return;
14555
14556 while (interruptedWork !== null) {
14557 unwindInterruptedWork(interruptedWork);
14558 interruptedWork = interruptedWork.return;
14559 }
14560 }
14561
14562 workInProgressRoot = root;
14563 workInProgress = createWorkInProgress(root.current, null, expirationTime);
14564 renderExpirationTime = expirationTime;
14565 workInProgressRootExitStatus = RootIncomplete;
14566 workInProgressRootFatalError = null;
14567 workInProgressRootLatestProcessedExpirationTime = Sync;
14568 workInProgressRootLatestSuspenseTimeout = Sync;
14569 workInProgressRootCanSuspendUsingConfig = null;
14570 workInProgressRootNextUnprocessedUpdateTime = NoWork;
14571 workInProgressRootHasPendingPing = false;
14572
14573 if (enableSchedulerTracing) {
14574 spawnedWorkDuringRender = null;
14575 }
14576
14577 {
14578 ReactStrictModeWarnings.discardPendingWarnings();
14579 componentsThatTriggeredHighPriSuspend = null;
14580 }
14581}
14582
14583function handleError(root, thrownValue) {
14584 do {
14585 try {
14586 // Reset module-level state that was set during the render phase.
14587 resetContextDependencies();
14588 resetHooks();
14589
14590 if (workInProgress === null || workInProgress.return === null) {
14591 // Expected to be working on a non-root fiber. This is a fatal error
14592 // because there's no ancestor that can handle it; the root is
14593 // supposed to capture all errors that weren't caught by an error
14594 // boundary.
14595 workInProgressRootExitStatus = RootFatalErrored;
14596 workInProgressRootFatalError = thrownValue;
14597 return null;
14598 }
14599
14600 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
14601 // Record the time spent rendering before an error was thrown. This
14602 // avoids inaccurate Profiler durations in the case of a
14603 // suspended render.
14604 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
14605 }
14606
14607 throwException(root, workInProgress.return, workInProgress, thrownValue, renderExpirationTime);
14608 workInProgress = completeUnitOfWork(workInProgress);
14609 } catch (yetAnotherThrownValue) {
14610 // Something in the return path also threw.
14611 thrownValue = yetAnotherThrownValue;
14612 continue;
14613 } // Return to the normal work loop.
14614
14615
14616 return;
14617 } while (true);
14618}
14619
14620function pushDispatcher(root) {
14621 var prevDispatcher = ReactCurrentDispatcher.current;
14622 ReactCurrentDispatcher.current = ContextOnlyDispatcher;
14623
14624 if (prevDispatcher === null) {
14625 // The React isomorphic package does not include a default dispatcher.
14626 // Instead the first renderer will lazily attach one, in order to give
14627 // nicer error messages.
14628 return ContextOnlyDispatcher;
14629 } else {
14630 return prevDispatcher;
14631 }
14632}
14633
14634function popDispatcher(prevDispatcher) {
14635 ReactCurrentDispatcher.current = prevDispatcher;
14636}
14637
14638function pushInteractions(root) {
14639 if (enableSchedulerTracing) {
14640 var prevInteractions = __interactionsRef.current;
14641 __interactionsRef.current = root.memoizedInteractions;
14642 return prevInteractions;
14643 }
14644
14645 return null;
14646}
14647
14648function popInteractions(prevInteractions) {
14649 if (enableSchedulerTracing) {
14650 __interactionsRef.current = prevInteractions;
14651 }
14652}
14653
14654function markCommitTimeOfFallback() {
14655 globalMostRecentFallbackTime = now();
14656}
14657function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
14658 if (expirationTime < workInProgressRootLatestProcessedExpirationTime && expirationTime > Idle) {
14659 workInProgressRootLatestProcessedExpirationTime = expirationTime;
14660 }
14661
14662 if (suspenseConfig !== null) {
14663 if (expirationTime < workInProgressRootLatestSuspenseTimeout && expirationTime > Idle) {
14664 workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
14665
14666 workInProgressRootCanSuspendUsingConfig = suspenseConfig;
14667 }
14668 }
14669}
14670function markUnprocessedUpdateTime(expirationTime) {
14671 if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
14672 workInProgressRootNextUnprocessedUpdateTime = expirationTime;
14673 }
14674}
14675function renderDidSuspend() {
14676 if (workInProgressRootExitStatus === RootIncomplete) {
14677 workInProgressRootExitStatus = RootSuspended;
14678 }
14679}
14680function renderDidSuspendDelayIfPossible() {
14681 if (workInProgressRootExitStatus === RootIncomplete || workInProgressRootExitStatus === RootSuspended) {
14682 workInProgressRootExitStatus = RootSuspendedWithDelay;
14683 } // Check if there's a lower priority update somewhere else in the tree.
14684
14685
14686 if (workInProgressRootNextUnprocessedUpdateTime !== NoWork && workInProgressRoot !== null) {
14687 // Mark the current render as suspended, and then mark that there's a
14688 // pending update.
14689 // TODO: This should immediately interrupt the current render, instead
14690 // of waiting until the next time we yield.
14691 markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime);
14692 markRootUpdatedAtTime(workInProgressRoot, workInProgressRootNextUnprocessedUpdateTime);
14693 }
14694}
14695function renderDidError() {
14696 if (workInProgressRootExitStatus !== RootCompleted) {
14697 workInProgressRootExitStatus = RootErrored;
14698 }
14699} // Called during render to determine if anything has suspended.
14700// Returns false if we're not sure.
14701
14702function renderHasNotSuspendedYet() {
14703 // If something errored or completed, we can't really be sure,
14704 // so those are false.
14705 return workInProgressRootExitStatus === RootIncomplete;
14706}
14707
14708function inferTimeFromExpirationTime(expirationTime) {
14709 // We don't know exactly when the update was scheduled, but we can infer an
14710 // approximate start time from the expiration time.
14711 var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
14712 return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
14713}
14714
14715function inferTimeFromExpirationTimeWithSuspenseConfig(expirationTime, suspenseConfig) {
14716 // We don't know exactly when the update was scheduled, but we can infer an
14717 // approximate start time from the expiration time by subtracting the timeout
14718 // that was added to the event time.
14719 var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
14720 return earliestExpirationTimeMs - (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
14721} // The work loop is an extremely hot path. Tell Closure not to inline it.
14722
14723/** @noinline */
14724
14725
14726function workLoopSync() {
14727 // Already timed out, so perform work without checking if we need to yield.
14728 while (workInProgress !== null) {
14729 workInProgress = performUnitOfWork(workInProgress);
14730 }
14731}
14732/** @noinline */
14733
14734
14735function workLoopConcurrent() {
14736 // Perform work until Scheduler asks us to yield
14737 while (workInProgress !== null && !shouldYield()) {
14738 workInProgress = performUnitOfWork(workInProgress);
14739 }
14740}
14741
14742function performUnitOfWork(unitOfWork) {
14743 // The current, flushed, state of this fiber is the alternate. Ideally
14744 // nothing should rely on this, but relying on it here means that we don't
14745 // need an additional field on the work in progress.
14746 var current$$1 = unitOfWork.alternate;
14747 startWorkTimer(unitOfWork);
14748 setCurrentFiber(unitOfWork);
14749 var next;
14750
14751 if (enableProfilerTimer && (unitOfWork.mode & ProfileMode) !== NoMode) {
14752 startProfilerTimer(unitOfWork);
14753 next = beginWork$$1(current$$1, unitOfWork, renderExpirationTime);
14754 stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
14755 } else {
14756 next = beginWork$$1(current$$1, unitOfWork, renderExpirationTime);
14757 }
14758
14759 resetCurrentFiber();
14760 unitOfWork.memoizedProps = unitOfWork.pendingProps;
14761
14762 if (next === null) {
14763 // If this doesn't spawn new work, complete the current work.
14764 next = completeUnitOfWork(unitOfWork);
14765 }
14766
14767 ReactCurrentOwner$1.current = null;
14768 return next;
14769}
14770
14771function completeUnitOfWork(unitOfWork) {
14772 // Attempt to complete the current unit of work, then move to the next
14773 // sibling. If there are no more siblings, return to the parent fiber.
14774 workInProgress = unitOfWork;
14775
14776 do {
14777 // The current, flushed, state of this fiber is the alternate. Ideally
14778 // nothing should rely on this, but relying on it here means that we don't
14779 // need an additional field on the work in progress.
14780 var current$$1 = workInProgress.alternate;
14781 var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
14782
14783 if ((workInProgress.effectTag & Incomplete) === NoEffect) {
14784 setCurrentFiber(workInProgress);
14785 var next = void 0;
14786
14787 if (!enableProfilerTimer || (workInProgress.mode & ProfileMode) === NoMode) {
14788 next = completeWork(current$$1, workInProgress, renderExpirationTime);
14789 } else {
14790 startProfilerTimer(workInProgress);
14791 next = completeWork(current$$1, workInProgress, renderExpirationTime); // Update render duration assuming we didn't error.
14792
14793 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
14794 }
14795
14796 stopWorkTimer(workInProgress);
14797 resetCurrentFiber();
14798 resetChildExpirationTime(workInProgress);
14799
14800 if (next !== null) {
14801 // Completing this fiber spawned new work. Work on that next.
14802 return next;
14803 }
14804
14805 if (returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
14806 (returnFiber.effectTag & Incomplete) === NoEffect) {
14807 // Append all the effects of the subtree and this fiber onto the effect
14808 // list of the parent. The completion order of the children affects the
14809 // side-effect order.
14810 if (returnFiber.firstEffect === null) {
14811 returnFiber.firstEffect = workInProgress.firstEffect;
14812 }
14813
14814 if (workInProgress.lastEffect !== null) {
14815 if (returnFiber.lastEffect !== null) {
14816 returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
14817 }
14818
14819 returnFiber.lastEffect = workInProgress.lastEffect;
14820 } // If this fiber had side-effects, we append it AFTER the children's
14821 // side-effects. We can perform certain side-effects earlier if needed,
14822 // by doing multiple passes over the effect list. We don't want to
14823 // schedule our own side-effect on our own list because if end up
14824 // reusing children we'll schedule this effect onto itself since we're
14825 // at the end.
14826
14827
14828 var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
14829 // list. PerformedWork effect is read by React DevTools but shouldn't be
14830 // committed.
14831
14832 if (effectTag > PerformedWork) {
14833 if (returnFiber.lastEffect !== null) {
14834 returnFiber.lastEffect.nextEffect = workInProgress;
14835 } else {
14836 returnFiber.firstEffect = workInProgress;
14837 }
14838
14839 returnFiber.lastEffect = workInProgress;
14840 }
14841 }
14842 } else {
14843 // This fiber did not complete because something threw. Pop values off
14844 // the stack without entering the complete phase. If this is a boundary,
14845 // capture values if possible.
14846 var _next = unwindWork(workInProgress, renderExpirationTime); // Because this fiber did not complete, don't reset its expiration time.
14847
14848
14849 if (enableProfilerTimer && (workInProgress.mode & ProfileMode) !== NoMode) {
14850 // Record the render duration for the fiber that errored.
14851 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
14852
14853 var actualDuration = workInProgress.actualDuration;
14854 var child = workInProgress.child;
14855
14856 while (child !== null) {
14857 actualDuration += child.actualDuration;
14858 child = child.sibling;
14859 }
14860
14861 workInProgress.actualDuration = actualDuration;
14862 }
14863
14864 if (_next !== null) {
14865 // If completing this work spawned new work, do that next. We'll come
14866 // back here again.
14867 // Since we're restarting, remove anything that is not a host effect
14868 // from the effect tag.
14869 // TODO: The name stopFailedWorkTimer is misleading because Suspense
14870 // also captures and restarts.
14871 stopFailedWorkTimer(workInProgress);
14872 _next.effectTag &= HostEffectMask;
14873 return _next;
14874 }
14875
14876 stopWorkTimer(workInProgress);
14877
14878 if (returnFiber !== null) {
14879 // Mark the parent fiber as incomplete and clear its effect list.
14880 returnFiber.firstEffect = returnFiber.lastEffect = null;
14881 returnFiber.effectTag |= Incomplete;
14882 }
14883 }
14884
14885 var siblingFiber = workInProgress.sibling;
14886
14887 if (siblingFiber !== null) {
14888 // If there is more work to do in this returnFiber, do that next.
14889 return siblingFiber;
14890 } // Otherwise, return to the parent
14891
14892
14893 workInProgress = returnFiber;
14894 } while (workInProgress !== null); // We've reached the root.
14895
14896
14897 if (workInProgressRootExitStatus === RootIncomplete) {
14898 workInProgressRootExitStatus = RootCompleted;
14899 }
14900
14901 return null;
14902}
14903
14904function getRemainingExpirationTime(fiber) {
14905 var updateExpirationTime = fiber.expirationTime;
14906 var childExpirationTime = fiber.childExpirationTime;
14907 return updateExpirationTime > childExpirationTime ? updateExpirationTime : childExpirationTime;
14908}
14909
14910function resetChildExpirationTime(completedWork) {
14911 if (renderExpirationTime !== Never && completedWork.childExpirationTime === Never) {
14912 // The children of this component are hidden. Don't bubble their
14913 // expiration times.
14914 return;
14915 }
14916
14917 var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
14918
14919 if (enableProfilerTimer && (completedWork.mode & ProfileMode) !== NoMode) {
14920 // In profiling mode, resetChildExpirationTime is also used to reset
14921 // profiler durations.
14922 var actualDuration = completedWork.actualDuration;
14923 var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
14924 // only be updated if work is done on the fiber (i.e. it doesn't bailout).
14925 // When work is done, it should bubble to the parent's actualDuration. If
14926 // the fiber has not been cloned though, (meaning no work was done), then
14927 // this value will reflect the amount of time spent working on a previous
14928 // render. In that case it should not bubble. We determine whether it was
14929 // cloned by comparing the child pointer.
14930
14931 var shouldBubbleActualDurations = completedWork.alternate === null || completedWork.child !== completedWork.alternate.child;
14932 var child = completedWork.child;
14933
14934 while (child !== null) {
14935 var childUpdateExpirationTime = child.expirationTime;
14936 var childChildExpirationTime = child.childExpirationTime;
14937
14938 if (childUpdateExpirationTime > newChildExpirationTime) {
14939 newChildExpirationTime = childUpdateExpirationTime;
14940 }
14941
14942 if (childChildExpirationTime > newChildExpirationTime) {
14943 newChildExpirationTime = childChildExpirationTime;
14944 }
14945
14946 if (shouldBubbleActualDurations) {
14947 actualDuration += child.actualDuration;
14948 }
14949
14950 treeBaseDuration += child.treeBaseDuration;
14951 child = child.sibling;
14952 }
14953
14954 completedWork.actualDuration = actualDuration;
14955 completedWork.treeBaseDuration = treeBaseDuration;
14956 } else {
14957 var _child = completedWork.child;
14958
14959 while (_child !== null) {
14960 var _childUpdateExpirationTime = _child.expirationTime;
14961 var _childChildExpirationTime = _child.childExpirationTime;
14962
14963 if (_childUpdateExpirationTime > newChildExpirationTime) {
14964 newChildExpirationTime = _childUpdateExpirationTime;
14965 }
14966
14967 if (_childChildExpirationTime > newChildExpirationTime) {
14968 newChildExpirationTime = _childChildExpirationTime;
14969 }
14970
14971 _child = _child.sibling;
14972 }
14973 }
14974
14975 completedWork.childExpirationTime = newChildExpirationTime;
14976}
14977
14978function commitRoot(root) {
14979 var renderPriorityLevel = getCurrentPriorityLevel();
14980 runWithPriority(ImmediatePriority, commitRootImpl.bind(null, root, renderPriorityLevel));
14981 return null;
14982}
14983
14984function commitRootImpl(root, renderPriorityLevel) {
14985 flushPassiveEffects();
14986 flushRenderPhaseStrictModeWarningsInDEV();
14987
14988 (function () {
14989 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
14990 {
14991 throw ReactError(Error("Should not already be working."));
14992 }
14993 }
14994 })();
14995
14996 var finishedWork = root.finishedWork;
14997 var expirationTime = root.finishedExpirationTime;
14998
14999 if (finishedWork === null) {
15000 return null;
15001 }
15002
15003 root.finishedWork = null;
15004 root.finishedExpirationTime = NoWork;
15005
15006 (function () {
15007 if (!(finishedWork !== root.current)) {
15008 {
15009 throw ReactError(Error("Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue."));
15010 }
15011 }
15012 })(); // commitRoot never returns a continuation; it always finishes synchronously.
15013 // So we can clear these now to allow a new callback to be scheduled.
15014
15015
15016 root.callbackNode = null;
15017 root.callbackExpirationTime = NoWork;
15018 root.callbackPriority = NoPriority;
15019 root.nextKnownPendingLevel = NoWork;
15020 startCommitTimer(); // Update the first and last pending times on this root. The new first
15021 // pending time is whatever is left on the root fiber.
15022
15023 var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(finishedWork);
15024 markRootFinishedAtTime(root, expirationTime, remainingExpirationTimeBeforeCommit);
15025
15026 if (root === workInProgressRoot) {
15027 // We can reset these now that they are finished.
15028 workInProgressRoot = null;
15029 workInProgress = null;
15030 renderExpirationTime = NoWork;
15031 } else {} // This indicates that the last root we worked on is not the same one that
15032 // we're committing now. This most commonly happens when a suspended root
15033 // times out.
15034 // Get the list of effects.
15035
15036
15037 var firstEffect;
15038
15039 if (finishedWork.effectTag > PerformedWork) {
15040 // A fiber's effect list consists only of its children, not itself. So if
15041 // the root has an effect, we need to add it to the end of the list. The
15042 // resulting list is the set that would belong to the root's parent, if it
15043 // had one; that is, all the effects in the tree including the root.
15044 if (finishedWork.lastEffect !== null) {
15045 finishedWork.lastEffect.nextEffect = finishedWork;
15046 firstEffect = finishedWork.firstEffect;
15047 } else {
15048 firstEffect = finishedWork;
15049 }
15050 } else {
15051 // There is no effect on the root.
15052 firstEffect = finishedWork.firstEffect;
15053 }
15054
15055 if (firstEffect !== null) {
15056 var prevExecutionContext = executionContext;
15057 executionContext |= CommitContext;
15058 var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
15059
15060 ReactCurrentOwner$1.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
15061 // of the effect list for each phase: all mutation effects come before all
15062 // layout effects, and so on.
15063 // The first phase a "before mutation" phase. We use this phase to read the
15064 // state of the host tree right before we mutate it. This is where
15065 // getSnapshotBeforeUpdate is called.
15066
15067 startCommitSnapshotEffectsTimer();
15068 prepareForCommit(root.containerInfo);
15069 nextEffect = firstEffect;
15070
15071 do {
15072 {
15073 invokeGuardedCallback(null, commitBeforeMutationEffects, null);
15074
15075 if (hasCaughtError()) {
15076 (function () {
15077 if (!(nextEffect !== null)) {
15078 {
15079 throw ReactError(Error("Should be working on an effect."));
15080 }
15081 }
15082 })();
15083
15084 var error = clearCaughtError();
15085 captureCommitPhaseError(nextEffect, error);
15086 nextEffect = nextEffect.nextEffect;
15087 }
15088 }
15089 } while (nextEffect !== null);
15090
15091 stopCommitSnapshotEffectsTimer();
15092
15093 if (enableProfilerTimer) {
15094 // Mark the current commit time to be shared by all Profilers in this
15095 // batch. This enables them to be grouped later.
15096 recordCommitTime();
15097 } // The next phase is the mutation phase, where we mutate the host tree.
15098
15099
15100 startCommitHostEffectsTimer();
15101 nextEffect = firstEffect;
15102
15103 do {
15104 {
15105 invokeGuardedCallback(null, commitMutationEffects, null, root, renderPriorityLevel);
15106
15107 if (hasCaughtError()) {
15108 (function () {
15109 if (!(nextEffect !== null)) {
15110 {
15111 throw ReactError(Error("Should be working on an effect."));
15112 }
15113 }
15114 })();
15115
15116 var _error = clearCaughtError();
15117
15118 captureCommitPhaseError(nextEffect, _error);
15119 nextEffect = nextEffect.nextEffect;
15120 }
15121 }
15122 } while (nextEffect !== null);
15123
15124 stopCommitHostEffectsTimer();
15125 resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
15126 // the mutation phase, so that the previous tree is still current during
15127 // componentWillUnmount, but before the layout phase, so that the finished
15128 // work is current during componentDidMount/Update.
15129
15130 root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
15131 // the host tree after it's been mutated. The idiomatic use case for this is
15132 // layout, but class component lifecycles also fire here for legacy reasons.
15133
15134 startCommitLifeCyclesTimer();
15135 nextEffect = firstEffect;
15136
15137 do {
15138 {
15139 invokeGuardedCallback(null, commitLayoutEffects, null, root, expirationTime);
15140
15141 if (hasCaughtError()) {
15142 (function () {
15143 if (!(nextEffect !== null)) {
15144 {
15145 throw ReactError(Error("Should be working on an effect."));
15146 }
15147 }
15148 })();
15149
15150 var _error2 = clearCaughtError();
15151
15152 captureCommitPhaseError(nextEffect, _error2);
15153 nextEffect = nextEffect.nextEffect;
15154 }
15155 }
15156 } while (nextEffect !== null);
15157
15158 stopCommitLifeCyclesTimer();
15159 nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
15160 // opportunity to paint.
15161
15162 requestPaint();
15163
15164 if (enableSchedulerTracing) {
15165 popInteractions(prevInteractions);
15166 }
15167
15168 executionContext = prevExecutionContext;
15169 } else {
15170 // No effects.
15171 root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
15172 // no effects.
15173 // TODO: Maybe there's a better way to report this.
15174
15175 startCommitSnapshotEffectsTimer();
15176 stopCommitSnapshotEffectsTimer();
15177
15178 if (enableProfilerTimer) {
15179 recordCommitTime();
15180 }
15181
15182 startCommitHostEffectsTimer();
15183 stopCommitHostEffectsTimer();
15184 startCommitLifeCyclesTimer();
15185 stopCommitLifeCyclesTimer();
15186 }
15187
15188 stopCommitTimer();
15189 var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
15190
15191 if (rootDoesHavePassiveEffects) {
15192 // This commit has passive effects. Stash a reference to them. But don't
15193 // schedule a callback until after flushing layout work.
15194 rootDoesHavePassiveEffects = false;
15195 rootWithPendingPassiveEffects = root;
15196 pendingPassiveEffectsExpirationTime = expirationTime;
15197 pendingPassiveEffectsRenderPriority = renderPriorityLevel;
15198 } else {
15199 // We are done with the effect chain at this point so let's clear the
15200 // nextEffect pointers to assist with GC. If we have passive effects, we'll
15201 // clear this in flushPassiveEffects.
15202 nextEffect = firstEffect;
15203
15204 while (nextEffect !== null) {
15205 var nextNextEffect = nextEffect.nextEffect;
15206 nextEffect.nextEffect = null;
15207 nextEffect = nextNextEffect;
15208 }
15209 } // Check if there's remaining work on this root
15210
15211
15212 var remainingExpirationTime = root.firstPendingTime;
15213
15214 if (remainingExpirationTime !== NoWork) {
15215 if (enableSchedulerTracing) {
15216 if (spawnedWorkDuringRender !== null) {
15217 var expirationTimes = spawnedWorkDuringRender;
15218 spawnedWorkDuringRender = null;
15219
15220 for (var i = 0; i < expirationTimes.length; i++) {
15221 scheduleInteractions(root, expirationTimes[i], root.memoizedInteractions);
15222 }
15223 }
15224
15225 schedulePendingInteractions(root, remainingExpirationTime);
15226 }
15227 } else {
15228 // If there's no remaining work, we can clear the set of already failed
15229 // error boundaries.
15230 legacyErrorBoundariesThatAlreadyFailed = null;
15231 }
15232
15233 if (enableSchedulerTracing) {
15234 if (!rootDidHavePassiveEffects) {
15235 // If there are no passive effects, then we can complete the pending interactions.
15236 // Otherwise, we'll wait until after the passive effects are flushed.
15237 // Wait to do this until after remaining work has been scheduled,
15238 // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
15239 finishPendingInteractions(root, expirationTime);
15240 }
15241 }
15242
15243 if (remainingExpirationTime === Sync) {
15244 // Count the number of times the root synchronously re-renders without
15245 // finishing. If there are too many, it indicates an infinite update loop.
15246 if (root === rootWithNestedUpdates) {
15247 nestedUpdateCount++;
15248 } else {
15249 nestedUpdateCount = 0;
15250 rootWithNestedUpdates = root;
15251 }
15252 } else {
15253 nestedUpdateCount = 0;
15254 }
15255
15256 onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
15257 // additional work on this root is scheduled.
15258
15259 ensureRootIsScheduled(root);
15260
15261 if (hasUncaughtError) {
15262 hasUncaughtError = false;
15263 var _error3 = firstUncaughtError;
15264 firstUncaughtError = null;
15265 throw _error3;
15266 }
15267
15268 if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
15269 // This is a legacy edge case. We just committed the initial mount of
15270 // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
15271 // synchronously, but layout updates should be deferred until the end
15272 // of the batch.
15273 return null;
15274 } // If layout work was scheduled, flush it now.
15275
15276
15277 flushSyncCallbackQueue();
15278 return null;
15279}
15280
15281function commitBeforeMutationEffects() {
15282 while (nextEffect !== null) {
15283 var effectTag = nextEffect.effectTag;
15284
15285 if ((effectTag & Snapshot) !== NoEffect) {
15286 setCurrentFiber(nextEffect);
15287 recordEffect();
15288 var current$$1 = nextEffect.alternate;
15289 commitBeforeMutationLifeCycles(current$$1, nextEffect);
15290 resetCurrentFiber();
15291 }
15292
15293 if ((effectTag & Passive) !== NoEffect) {
15294 // If there are passive effects, schedule a callback to flush at
15295 // the earliest opportunity.
15296 if (!rootDoesHavePassiveEffects) {
15297 rootDoesHavePassiveEffects = true;
15298 scheduleCallback(NormalPriority, function () {
15299 flushPassiveEffects();
15300 return null;
15301 });
15302 }
15303 }
15304
15305 nextEffect = nextEffect.nextEffect;
15306 }
15307}
15308
15309function commitMutationEffects(root, renderPriorityLevel) {
15310 // TODO: Should probably move the bulk of this function to commitWork.
15311 while (nextEffect !== null) {
15312 setCurrentFiber(nextEffect);
15313 var effectTag = nextEffect.effectTag;
15314
15315 if (effectTag & ContentReset) {
15316 commitResetTextContent(nextEffect);
15317 }
15318
15319 if (effectTag & Ref) {
15320 var current$$1 = nextEffect.alternate;
15321
15322 if (current$$1 !== null) {
15323 commitDetachRef(current$$1);
15324 }
15325 } // The following switch statement is only concerned about placement,
15326 // updates, and deletions. To avoid needing to add a case for every possible
15327 // bitmap value, we remove the secondary effects from the effect tag and
15328 // switch on that value.
15329
15330
15331 var primaryEffectTag = effectTag & (Placement | Update | Deletion | Hydrating);
15332
15333 switch (primaryEffectTag) {
15334 case Placement:
15335 {
15336 commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
15337 // inserted, before any life-cycles like componentDidMount gets called.
15338 // TODO: findDOMNode doesn't rely on this any more but isMounted does
15339 // and isMounted is deprecated anyway so we should be able to kill this.
15340
15341 nextEffect.effectTag &= ~Placement;
15342 break;
15343 }
15344
15345 case PlacementAndUpdate:
15346 {
15347 // Placement
15348 commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
15349 // inserted, before any life-cycles like componentDidMount gets called.
15350
15351 nextEffect.effectTag &= ~Placement; // Update
15352
15353 var _current = nextEffect.alternate;
15354 commitWork(_current, nextEffect);
15355 break;
15356 }
15357
15358 case Hydrating:
15359 {
15360 nextEffect.effectTag &= ~Hydrating;
15361 break;
15362 }
15363
15364 case HydratingAndUpdate:
15365 {
15366 nextEffect.effectTag &= ~Hydrating; // Update
15367
15368 var _current2 = nextEffect.alternate;
15369 commitWork(_current2, nextEffect);
15370 break;
15371 }
15372
15373 case Update:
15374 {
15375 var _current3 = nextEffect.alternate;
15376 commitWork(_current3, nextEffect);
15377 break;
15378 }
15379
15380 case Deletion:
15381 {
15382 commitDeletion(root, nextEffect, renderPriorityLevel);
15383 break;
15384 }
15385 } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
15386
15387
15388 recordEffect();
15389 resetCurrentFiber();
15390 nextEffect = nextEffect.nextEffect;
15391 }
15392}
15393
15394function commitLayoutEffects(root, committedExpirationTime) {
15395 // TODO: Should probably move the bulk of this function to commitWork.
15396 while (nextEffect !== null) {
15397 setCurrentFiber(nextEffect);
15398 var effectTag = nextEffect.effectTag;
15399
15400 if (effectTag & (Update | Callback)) {
15401 recordEffect();
15402 var current$$1 = nextEffect.alternate;
15403 commitLifeCycles(root, current$$1, nextEffect, committedExpirationTime);
15404 }
15405
15406 if (effectTag & Ref) {
15407 recordEffect();
15408 commitAttachRef(nextEffect);
15409 }
15410
15411 resetCurrentFiber();
15412 nextEffect = nextEffect.nextEffect;
15413 }
15414}
15415
15416function flushPassiveEffects() {
15417 if (pendingPassiveEffectsRenderPriority !== NoPriority) {
15418 var priorityLevel = pendingPassiveEffectsRenderPriority > NormalPriority ? NormalPriority : pendingPassiveEffectsRenderPriority;
15419 pendingPassiveEffectsRenderPriority = NoPriority;
15420 return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
15421 }
15422}
15423
15424function flushPassiveEffectsImpl() {
15425 if (rootWithPendingPassiveEffects === null) {
15426 return false;
15427 }
15428
15429 var root = rootWithPendingPassiveEffects;
15430 var expirationTime = pendingPassiveEffectsExpirationTime;
15431 rootWithPendingPassiveEffects = null;
15432 pendingPassiveEffectsExpirationTime = NoWork;
15433
15434 (function () {
15435 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
15436 {
15437 throw ReactError(Error("Cannot flush passive effects while already rendering."));
15438 }
15439 }
15440 })();
15441
15442 var prevExecutionContext = executionContext;
15443 executionContext |= CommitContext;
15444 var prevInteractions = pushInteractions(root); // Note: This currently assumes there are no passive effects on the root
15445 // fiber, because the root is not part of its own effect list. This could
15446 // change in the future.
15447
15448 var effect = root.current.firstEffect;
15449
15450 while (effect !== null) {
15451 {
15452 setCurrentFiber(effect);
15453 invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
15454
15455 if (hasCaughtError()) {
15456 (function () {
15457 if (!(effect !== null)) {
15458 {
15459 throw ReactError(Error("Should be working on an effect."));
15460 }
15461 }
15462 })();
15463
15464 var error = clearCaughtError();
15465 captureCommitPhaseError(effect, error);
15466 }
15467
15468 resetCurrentFiber();
15469 }
15470
15471 var nextNextEffect = effect.nextEffect; // Remove nextEffect pointer to assist GC
15472
15473 effect.nextEffect = null;
15474 effect = nextNextEffect;
15475 }
15476
15477 if (enableSchedulerTracing) {
15478 popInteractions(prevInteractions);
15479 finishPendingInteractions(root, expirationTime);
15480 }
15481
15482 executionContext = prevExecutionContext;
15483 flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
15484 // exceeds the limit, we'll fire a warning.
15485
15486 nestedPassiveUpdateCount = rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
15487 return true;
15488}
15489
15490function isAlreadyFailedLegacyErrorBoundary(instance) {
15491 return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
15492}
15493function markLegacyErrorBoundaryAsFailed(instance) {
15494 if (legacyErrorBoundariesThatAlreadyFailed === null) {
15495 legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
15496 } else {
15497 legacyErrorBoundariesThatAlreadyFailed.add(instance);
15498 }
15499}
15500
15501function prepareToThrowUncaughtError(error) {
15502 if (!hasUncaughtError) {
15503 hasUncaughtError = true;
15504 firstUncaughtError = error;
15505 }
15506}
15507
15508var onUncaughtError = prepareToThrowUncaughtError;
15509
15510function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
15511 var errorInfo = createCapturedValue(error, sourceFiber);
15512 var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
15513 enqueueUpdate(rootFiber, update);
15514 var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
15515
15516 if (root !== null) {
15517 ensureRootIsScheduled(root);
15518 schedulePendingInteractions(root, Sync);
15519 }
15520}
15521
15522function captureCommitPhaseError(sourceFiber, error) {
15523 if (sourceFiber.tag === HostRoot) {
15524 // Error was thrown at the root. There is no parent, so the root
15525 // itself should capture it.
15526 captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
15527 return;
15528 }
15529
15530 var fiber = sourceFiber.return;
15531
15532 while (fiber !== null) {
15533 if (fiber.tag === HostRoot) {
15534 captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
15535 return;
15536 } else if (fiber.tag === ClassComponent) {
15537 var ctor = fiber.type;
15538 var instance = fiber.stateNode;
15539
15540 if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
15541 var errorInfo = createCapturedValue(error, sourceFiber);
15542 var update = createClassErrorUpdate(fiber, errorInfo, // TODO: This is always sync
15543 Sync);
15544 enqueueUpdate(fiber, update);
15545 var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
15546
15547 if (root !== null) {
15548 ensureRootIsScheduled(root);
15549 schedulePendingInteractions(root, Sync);
15550 }
15551
15552 return;
15553 }
15554 }
15555
15556 fiber = fiber.return;
15557 }
15558}
15559function pingSuspendedRoot(root, thenable, suspendedTime) {
15560 var pingCache = root.pingCache;
15561
15562 if (pingCache !== null) {
15563 // The thenable resolved, so we no longer need to memoize, because it will
15564 // never be thrown again.
15565 pingCache.delete(thenable);
15566 }
15567
15568 if (workInProgressRoot === root && renderExpirationTime === suspendedTime) {
15569 // Received a ping at the same priority level at which we're currently
15570 // rendering. We might want to restart this render. This should mirror
15571 // the logic of whether or not a root suspends once it completes.
15572 // TODO: If we're rendering sync either due to Sync, Batched or expired,
15573 // we should probably never restart.
15574 // If we're suspended with delay, we'll always suspend so we can always
15575 // restart. If we're suspended without any updates, it might be a retry.
15576 // If it's early in the retry we can restart. We can't know for sure
15577 // whether we'll eventually process an update during this render pass,
15578 // but it's somewhat unlikely that we get to a ping before that, since
15579 // getting to the root most update is usually very fast.
15580 if (workInProgressRootExitStatus === RootSuspendedWithDelay || workInProgressRootExitStatus === RootSuspended && workInProgressRootLatestProcessedExpirationTime === Sync && now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS) {
15581 // Restart from the root. Don't need to schedule a ping because
15582 // we're already working on this tree.
15583 prepareFreshStack(root, renderExpirationTime);
15584 } else {
15585 // Even though we can't restart right now, we might get an
15586 // opportunity later. So we mark this render as having a ping.
15587 workInProgressRootHasPendingPing = true;
15588 }
15589
15590 return;
15591 }
15592
15593 if (!isRootSuspendedAtTime(root, suspendedTime)) {
15594 // The root is no longer suspended at this time.
15595 return;
15596 }
15597
15598 var lastPingedTime = root.lastPingedTime;
15599
15600 if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
15601 // There's already a lower priority ping scheduled.
15602 return;
15603 } // Mark the time at which this ping was scheduled.
15604
15605
15606 root.lastPingedTime = suspendedTime;
15607
15608 if (root.finishedExpirationTime === suspendedTime) {
15609 // If there's a pending fallback waiting to commit, throw it away.
15610 root.finishedExpirationTime = NoWork;
15611 root.finishedWork = null;
15612 }
15613
15614 ensureRootIsScheduled(root);
15615 schedulePendingInteractions(root, suspendedTime);
15616}
15617
15618function retryTimedOutBoundary(boundaryFiber, retryTime) {
15619 // The boundary fiber (a Suspense component or SuspenseList component)
15620 // previously was rendered in its fallback state. One of the promises that
15621 // suspended it has resolved, which means at least part of the tree was
15622 // likely unblocked. Try rendering again, at a new expiration time.
15623 if (retryTime === Never) {
15624 var suspenseConfig = null; // Retries don't carry over the already committed update.
15625
15626 var currentTime = requestCurrentTime();
15627 retryTime = computeExpirationForFiber(currentTime, boundaryFiber, suspenseConfig);
15628 } // TODO: Special case idle priority?
15629
15630
15631 var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
15632
15633 if (root !== null) {
15634 ensureRootIsScheduled(root);
15635 schedulePendingInteractions(root, retryTime);
15636 }
15637}
15638
15639function retryDehydratedSuspenseBoundary(boundaryFiber) {
15640 var suspenseState = boundaryFiber.memoizedState;
15641 var retryTime = Never;
15642
15643 if (suspenseState !== null) {
15644 retryTime = suspenseState.retryTime;
15645 }
15646
15647 retryTimedOutBoundary(boundaryFiber, retryTime);
15648}
15649function resolveRetryThenable(boundaryFiber, thenable) {
15650 var retryTime = Never; // Default
15651
15652 var retryCache;
15653
15654 if (enableSuspenseServerRenderer) {
15655 switch (boundaryFiber.tag) {
15656 case SuspenseComponent:
15657 retryCache = boundaryFiber.stateNode;
15658 var suspenseState = boundaryFiber.memoizedState;
15659
15660 if (suspenseState !== null) {
15661 retryTime = suspenseState.retryTime;
15662 }
15663
15664 break;
15665
15666 case SuspenseListComponent:
15667 retryCache = boundaryFiber.stateNode;
15668 break;
15669
15670 default:
15671 (function () {
15672 {
15673 {
15674 throw ReactError(Error("Pinged unknown suspense boundary type. This is probably a bug in React."));
15675 }
15676 }
15677 })();
15678
15679 }
15680 } else {
15681 retryCache = boundaryFiber.stateNode;
15682 }
15683
15684 if (retryCache !== null) {
15685 // The thenable resolved, so we no longer need to memoize, because it will
15686 // never be thrown again.
15687 retryCache.delete(thenable);
15688 }
15689
15690 retryTimedOutBoundary(boundaryFiber, retryTime);
15691} // Computes the next Just Noticeable Difference (JND) boundary.
15692// The theory is that a person can't tell the difference between small differences in time.
15693// Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
15694// difference in the experience. However, waiting for longer might mean that we can avoid
15695// showing an intermediate loading state. The longer we have already waited, the harder it
15696// is to tell small differences in time. Therefore, the longer we've already waited,
15697// the longer we can wait additionally. At some point we have to give up though.
15698// We pick a train model where the next boundary commits at a consistent schedule.
15699// These particular numbers are vague estimates. We expect to adjust them based on research.
15700
15701function jnd(timeElapsed) {
15702 return timeElapsed < 120 ? 120 : timeElapsed < 480 ? 480 : timeElapsed < 1080 ? 1080 : timeElapsed < 1920 ? 1920 : timeElapsed < 3000 ? 3000 : timeElapsed < 4320 ? 4320 : ceil(timeElapsed / 1960) * 1960;
15703}
15704
15705function computeMsUntilSuspenseLoadingDelay(mostRecentEventTime, committedExpirationTime, suspenseConfig) {
15706 var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
15707
15708 if (busyMinDurationMs <= 0) {
15709 return 0;
15710 }
15711
15712 var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
15713
15714 var currentTimeMs = now();
15715 var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(mostRecentEventTime, suspenseConfig);
15716 var timeElapsed = currentTimeMs - eventTimeMs;
15717
15718 if (timeElapsed <= busyDelayMs) {
15719 // If we haven't yet waited longer than the initial delay, we don't
15720 // have to wait any additional time.
15721 return 0;
15722 }
15723
15724 var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
15725
15726 return msUntilTimeout;
15727}
15728
15729function checkForNestedUpdates() {
15730 if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
15731 nestedUpdateCount = 0;
15732 rootWithNestedUpdates = null;
15733
15734 (function () {
15735 {
15736 {
15737 throw ReactError(Error("Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops."));
15738 }
15739 }
15740 })();
15741 }
15742
15743 {
15744 if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
15745 nestedPassiveUpdateCount = 0;
15746 warning$1(false, 'Maximum update depth exceeded. This can happen when a component ' + "calls setState inside useEffect, but useEffect either doesn't " + 'have a dependency array, or one of the dependencies changes on ' + 'every render.');
15747 }
15748 }
15749}
15750
15751function flushRenderPhaseStrictModeWarningsInDEV() {
15752 {
15753 ReactStrictModeWarnings.flushLegacyContextWarning();
15754
15755 if (warnAboutDeprecatedLifecycles) {
15756 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
15757 }
15758 }
15759}
15760
15761function stopFinishedWorkLoopTimer() {
15762 var didCompleteRoot = true;
15763 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
15764 interruptedBy = null;
15765}
15766
15767function stopInterruptedWorkLoopTimer() {
15768 // TODO: Track which fiber caused the interruption.
15769 var didCompleteRoot = false;
15770 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
15771 interruptedBy = null;
15772}
15773
15774function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
15775 if (enableUserTimingAPI && workInProgressRoot !== null && updateExpirationTime > renderExpirationTime) {
15776 interruptedBy = fiberThatReceivedUpdate;
15777 }
15778}
15779
15780var didWarnStateUpdateForUnmountedComponent = null;
15781
15782function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
15783 {
15784 var tag = fiber.tag;
15785
15786 if (tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent) {
15787 // Only warn for user-defined components, not internal ones like Suspense.
15788 return;
15789 } // We show the whole stack but dedupe on the top component's name because
15790 // the problematic code almost always lies inside that component.
15791
15792
15793 var componentName = getComponentName(fiber.type) || 'ReactComponent';
15794
15795 if (didWarnStateUpdateForUnmountedComponent !== null) {
15796 if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
15797 return;
15798 }
15799
15800 didWarnStateUpdateForUnmountedComponent.add(componentName);
15801 } else {
15802 didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
15803 }
15804
15805 warningWithoutStack$1(false, "Can't perform a React state update on an unmounted component. This " + 'is a no-op, but it indicates a memory leak in your application. To ' + 'fix, cancel all subscriptions and asynchronous tasks in %s.%s', tag === ClassComponent ? 'the componentWillUnmount method' : 'a useEffect cleanup function', getStackByFiberInDevAndProd(fiber));
15806 }
15807}
15808
15809var beginWork$$1;
15810
15811if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
15812 var dummyFiber = null;
15813
15814 beginWork$$1 = function (current$$1, unitOfWork, expirationTime) {
15815 // If a component throws an error, we replay it again in a synchronously
15816 // dispatched event, so that the debugger will treat it as an uncaught
15817 // error See ReactErrorUtils for more information.
15818 // Before entering the begin phase, copy the work-in-progress onto a dummy
15819 // fiber. If beginWork throws, we'll use this to reset the state.
15820 var originalWorkInProgressCopy = assignFiberPropertiesInDEV(dummyFiber, unitOfWork);
15821
15822 try {
15823 return beginWork$1(current$$1, unitOfWork, expirationTime);
15824 } catch (originalError) {
15825 if (originalError !== null && typeof originalError === 'object' && typeof originalError.then === 'function') {
15826 // Don't replay promises. Treat everything else like an error.
15827 throw originalError;
15828 } // Keep this code in sync with renderRoot; any changes here must have
15829 // corresponding changes there.
15830
15831
15832 resetContextDependencies();
15833 resetHooks(); // Unwind the failed stack frame
15834
15835 unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
15836
15837 assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
15838
15839 if (enableProfilerTimer && unitOfWork.mode & ProfileMode) {
15840 // Reset the profiler timer.
15841 startProfilerTimer(unitOfWork);
15842 } // Run beginWork again.
15843
15844
15845 invokeGuardedCallback(null, beginWork$1, null, current$$1, unitOfWork, expirationTime);
15846
15847 if (hasCaughtError()) {
15848 var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
15849 // Rethrow this error instead of the original one.
15850
15851 throw replayError;
15852 } else {
15853 // This branch is reachable if the render phase is impure.
15854 throw originalError;
15855 }
15856 }
15857 };
15858} else {
15859 beginWork$$1 = beginWork$1;
15860}
15861
15862var didWarnAboutUpdateInRender = false;
15863var didWarnAboutUpdateInGetChildContext = false;
15864
15865function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) {
15866 {
15867 if (fiber.tag === ClassComponent) {
15868 switch (phase) {
15869 case 'getChildContext':
15870 if (didWarnAboutUpdateInGetChildContext) {
15871 return;
15872 }
15873
15874 warningWithoutStack$1(false, 'setState(...): Cannot call setState() inside getChildContext()');
15875 didWarnAboutUpdateInGetChildContext = true;
15876 break;
15877
15878 case 'render':
15879 if (didWarnAboutUpdateInRender) {
15880 return;
15881 }
15882
15883 warningWithoutStack$1(false, 'Cannot update during an existing state transition (such as ' + 'within `render`). Render methods should be a pure function of ' + 'props and state.');
15884 didWarnAboutUpdateInRender = true;
15885 break;
15886 }
15887 }
15888 }
15889} // a 'shared' variable that changes when act() opens/closes in tests.
15890
15891
15892var IsThisRendererActing = {
15893 current: false
15894};
15895function warnIfNotScopedWithMatchingAct(fiber) {
15896 {
15897 if (warnsIfNotActing === true && IsSomeRendererActing.current === true && IsThisRendererActing.current !== true) {
15898 warningWithoutStack$1(false, "It looks like you're using the wrong act() around your test interactions.\n" + 'Be sure to use the matching version of act() corresponding to your renderer:\n\n' + '// for react-dom:\n' + "import {act} from 'react-dom/test-utils';\n" + '// ...\n' + 'act(() => ...);\n\n' + '// for react-test-renderer:\n' + "import TestRenderer from 'react-test-renderer';\n" + 'const {act} = TestRenderer;\n' + '// ...\n' + 'act(() => ...);' + '%s', getStackByFiberInDevAndProd(fiber));
15899 }
15900 }
15901}
15902function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
15903 {
15904 if (warnsIfNotActing === true && (fiber.mode & StrictMode) !== NoMode && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
15905 warningWithoutStack$1(false, 'An update to %s ran an effect, but 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' + '%s', getComponentName(fiber.type), getStackByFiberInDevAndProd(fiber));
15906 }
15907 }
15908}
15909
15910function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
15911 {
15912 if (warnsIfNotActing === true && executionContext === NoContext && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
15913 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' + '%s', getComponentName(fiber.type), getStackByFiberInDevAndProd(fiber));
15914 }
15915 }
15916}
15917
15918var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
15919
15920var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
15921// scheduler is the actual recommendation. The alternative could be a testing build,
15922// a new lib, or whatever; we dunno just yet. This message is for early adopters
15923// to get their tests right.
15924
15925function warnIfUnmockedScheduler(fiber) {
15926 {
15927 if (didWarnAboutUnmockedScheduler === false && Scheduler$1.unstable_flushAllWithoutAsserting === undefined) {
15928 if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) {
15929 didWarnAboutUnmockedScheduler = true;
15930 warningWithoutStack$1(false, 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' + 'to guarantee consistent behaviour across tests and browsers. ' + 'For example, with jest: \n' + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + 'For more info, visit https://fb.me/react-mock-scheduler');
15931 } else if (warnAboutUnmockedScheduler === true) {
15932 didWarnAboutUnmockedScheduler = true;
15933 warningWithoutStack$1(false, 'Starting from React v17, the "scheduler" module will need to be mocked ' + 'to guarantee consistent behaviour across tests and browsers. ' + 'For example, with jest: \n' + "jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" + 'For more info, visit https://fb.me/react-mock-scheduler');
15934 }
15935 }
15936 }
15937}
15938var componentsThatTriggeredHighPriSuspend = null;
15939function checkForWrongSuspensePriorityInDEV(sourceFiber) {
15940 {
15941 var currentPriorityLevel = getCurrentPriorityLevel();
15942
15943 if ((sourceFiber.mode & ConcurrentMode) !== NoEffect && (currentPriorityLevel === UserBlockingPriority || currentPriorityLevel === ImmediatePriority)) {
15944 var workInProgressNode = sourceFiber;
15945
15946 while (workInProgressNode !== null) {
15947 // Add the component that triggered the suspense
15948 var current$$1 = workInProgressNode.alternate;
15949
15950 if (current$$1 !== null) {
15951 // TODO: warn component that triggers the high priority
15952 // suspend is the HostRoot
15953 switch (workInProgressNode.tag) {
15954 case ClassComponent:
15955 // Loop through the component's update queue and see whether the component
15956 // has triggered any high priority updates
15957 var updateQueue = current$$1.updateQueue;
15958
15959 if (updateQueue !== null) {
15960 var update = updateQueue.firstUpdate;
15961
15962 while (update !== null) {
15963 var priorityLevel = update.priority;
15964
15965 if (priorityLevel === UserBlockingPriority || priorityLevel === ImmediatePriority) {
15966 if (componentsThatTriggeredHighPriSuspend === null) {
15967 componentsThatTriggeredHighPriSuspend = new Set([getComponentName(workInProgressNode.type)]);
15968 } else {
15969 componentsThatTriggeredHighPriSuspend.add(getComponentName(workInProgressNode.type));
15970 }
15971
15972 break;
15973 }
15974
15975 update = update.next;
15976 }
15977 }
15978
15979 break;
15980
15981 case FunctionComponent:
15982 case ForwardRef:
15983 case SimpleMemoComponent:
15984 if (workInProgressNode.memoizedState !== null && workInProgressNode.memoizedState.baseUpdate !== null) {
15985 var _update = workInProgressNode.memoizedState.baseUpdate; // Loop through the functional component's memoized state to see whether
15986 // the component has triggered any high pri updates
15987
15988 while (_update !== null) {
15989 var priority = _update.priority;
15990
15991 if (priority === UserBlockingPriority || priority === ImmediatePriority) {
15992 if (componentsThatTriggeredHighPriSuspend === null) {
15993 componentsThatTriggeredHighPriSuspend = new Set([getComponentName(workInProgressNode.type)]);
15994 } else {
15995 componentsThatTriggeredHighPriSuspend.add(getComponentName(workInProgressNode.type));
15996 }
15997
15998 break;
15999 }
16000
16001 if (_update.next === workInProgressNode.memoizedState.baseUpdate) {
16002 break;
16003 }
16004
16005 _update = _update.next;
16006 }
16007 }
16008
16009 break;
16010
16011 default:
16012 break;
16013 }
16014 }
16015
16016 workInProgressNode = workInProgressNode.return;
16017 }
16018 }
16019 }
16020}
16021
16022function flushSuspensePriorityWarningInDEV() {
16023 {
16024 if (componentsThatTriggeredHighPriSuspend !== null) {
16025 var componentNames = [];
16026 componentsThatTriggeredHighPriSuspend.forEach(function (name) {
16027 return componentNames.push(name);
16028 });
16029 componentsThatTriggeredHighPriSuspend = null;
16030
16031 if (componentNames.length > 0) {
16032 warningWithoutStack$1(false, '%s triggered a user-blocking update that suspended.' + '\n\n' + 'The fix is to split the update into multiple parts: a user-blocking ' + 'update to provide immediate feedback, and another update that ' + 'triggers the bulk of the changes.' + '\n\n' + 'Refer to the documentation for useSuspenseTransition to learn how ' + 'to implement this pattern.', // TODO: Add link to React docs with more information, once it exists
16033 componentNames.sort().join(', '));
16034 }
16035 }
16036 }
16037}
16038
16039function computeThreadID(root, expirationTime) {
16040 // Interaction threads are unique per root and expiration time.
16041 return expirationTime * 1000 + root.interactionThreadID;
16042}
16043
16044function markSpawnedWork(expirationTime) {
16045 if (!enableSchedulerTracing) {
16046 return;
16047 }
16048
16049 if (spawnedWorkDuringRender === null) {
16050 spawnedWorkDuringRender = [expirationTime];
16051 } else {
16052 spawnedWorkDuringRender.push(expirationTime);
16053 }
16054}
16055
16056function scheduleInteractions(root, expirationTime, interactions) {
16057 if (!enableSchedulerTracing) {
16058 return;
16059 }
16060
16061 if (interactions.size > 0) {
16062 var pendingInteractionMap = root.pendingInteractionMap;
16063 var pendingInteractions = pendingInteractionMap.get(expirationTime);
16064
16065 if (pendingInteractions != null) {
16066 interactions.forEach(function (interaction) {
16067 if (!pendingInteractions.has(interaction)) {
16068 // Update the pending async work count for previously unscheduled interaction.
16069 interaction.__count++;
16070 }
16071
16072 pendingInteractions.add(interaction);
16073 });
16074 } else {
16075 pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
16076
16077 interactions.forEach(function (interaction) {
16078 interaction.__count++;
16079 });
16080 }
16081
16082 var subscriber = __subscriberRef.current;
16083
16084 if (subscriber !== null) {
16085 var threadID = computeThreadID(root, expirationTime);
16086 subscriber.onWorkScheduled(interactions, threadID);
16087 }
16088 }
16089}
16090
16091function schedulePendingInteractions(root, expirationTime) {
16092 // This is called when work is scheduled on a root.
16093 // It associates the current interactions with the newly-scheduled expiration.
16094 // They will be restored when that expiration is later committed.
16095 if (!enableSchedulerTracing) {
16096 return;
16097 }
16098
16099 scheduleInteractions(root, expirationTime, __interactionsRef.current);
16100}
16101
16102function startWorkOnPendingInteractions(root, expirationTime) {
16103 // This is called when new work is started on a root.
16104 if (!enableSchedulerTracing) {
16105 return;
16106 } // Determine which interactions this batch of work currently includes, So that
16107 // we can accurately attribute time spent working on it, And so that cascading
16108 // work triggered during the render phase will be associated with it.
16109
16110
16111 var interactions = new Set();
16112 root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
16113 if (scheduledExpirationTime >= expirationTime) {
16114 scheduledInteractions.forEach(function (interaction) {
16115 return interactions.add(interaction);
16116 });
16117 }
16118 }); // Store the current set of interactions on the FiberRoot for a few reasons:
16119 // We can re-use it in hot functions like renderRoot() without having to
16120 // recalculate it. We will also use it in commitWork() to pass to any Profiler
16121 // onRender() hooks. This also provides DevTools with a way to access it when
16122 // the onCommitRoot() hook is called.
16123
16124 root.memoizedInteractions = interactions;
16125
16126 if (interactions.size > 0) {
16127 var subscriber = __subscriberRef.current;
16128
16129 if (subscriber !== null) {
16130 var threadID = computeThreadID(root, expirationTime);
16131
16132 try {
16133 subscriber.onWorkStarted(interactions, threadID);
16134 } catch (error) {
16135 // If the subscriber throws, rethrow it in a separate task
16136 scheduleCallback(ImmediatePriority, function () {
16137 throw error;
16138 });
16139 }
16140 }
16141 }
16142}
16143
16144function finishPendingInteractions(root, committedExpirationTime) {
16145 if (!enableSchedulerTracing) {
16146 return;
16147 }
16148
16149 var earliestRemainingTimeAfterCommit = root.firstPendingTime;
16150 var subscriber;
16151
16152 try {
16153 subscriber = __subscriberRef.current;
16154
16155 if (subscriber !== null && root.memoizedInteractions.size > 0) {
16156 var threadID = computeThreadID(root, committedExpirationTime);
16157 subscriber.onWorkStopped(root.memoizedInteractions, threadID);
16158 }
16159 } catch (error) {
16160 // If the subscriber throws, rethrow it in a separate task
16161 scheduleCallback(ImmediatePriority, function () {
16162 throw error;
16163 });
16164 } finally {
16165 // Clear completed interactions from the pending Map.
16166 // Unless the render was suspended or cascading work was scheduled,
16167 // In which case– leave pending interactions until the subsequent render.
16168 var pendingInteractionMap = root.pendingInteractionMap;
16169 pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
16170 // Only decrement the pending interaction count if we're done.
16171 // If there's still work at the current priority,
16172 // That indicates that we are waiting for suspense data.
16173 if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
16174 pendingInteractionMap.delete(scheduledExpirationTime);
16175 scheduledInteractions.forEach(function (interaction) {
16176 interaction.__count--;
16177
16178 if (subscriber !== null && interaction.__count === 0) {
16179 try {
16180 subscriber.onInteractionScheduledWorkCompleted(interaction);
16181 } catch (error) {
16182 // If the subscriber throws, rethrow it in a separate task
16183 scheduleCallback(ImmediatePriority, function () {
16184 throw error;
16185 });
16186 }
16187 }
16188 });
16189 }
16190 });
16191 }
16192}
16193
16194var onCommitFiberRoot = null;
16195var onCommitFiberUnmount = null;
16196var hasLoggedError = false;
16197var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
16198function injectInternals(internals) {
16199 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
16200 // No DevTools
16201 return false;
16202 }
16203
16204 var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
16205
16206 if (hook.isDisabled) {
16207 // This isn't a real property on the hook, but it can be set to opt out
16208 // of DevTools integration and associated warnings and logs.
16209 // https://github.com/facebook/react/issues/3877
16210 return true;
16211 }
16212
16213 if (!hook.supportsFiber) {
16214 {
16215 warningWithoutStack$1(false, 'The installed version of React DevTools is too old and will not work ' + 'with the current version of React. Please update React DevTools. ' + 'https://fb.me/react-devtools');
16216 } // DevTools exists, even though it doesn't support Fiber.
16217
16218
16219 return true;
16220 }
16221
16222 try {
16223 var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
16224
16225 onCommitFiberRoot = function (root, expirationTime) {
16226 try {
16227 var didError = (root.current.effectTag & DidCapture) === DidCapture;
16228
16229 if (enableProfilerTimer) {
16230 var currentTime = requestCurrentTime();
16231 var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime);
16232 hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
16233 } else {
16234 hook.onCommitFiberRoot(rendererID, root, undefined, didError);
16235 }
16236 } catch (err) {
16237 if (true && !hasLoggedError) {
16238 hasLoggedError = true;
16239 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
16240 }
16241 }
16242 };
16243
16244 onCommitFiberUnmount = function (fiber) {
16245 try {
16246 hook.onCommitFiberUnmount(rendererID, fiber);
16247 } catch (err) {
16248 if (true && !hasLoggedError) {
16249 hasLoggedError = true;
16250 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
16251 }
16252 }
16253 };
16254 } catch (err) {
16255 // Catch all errors because it is unsafe to throw during initialization.
16256 {
16257 warningWithoutStack$1(false, 'React DevTools encountered an error: %s.', err);
16258 }
16259 } // DevTools exists
16260
16261
16262 return true;
16263}
16264function onCommitRoot(root, expirationTime) {
16265 if (typeof onCommitFiberRoot === 'function') {
16266 onCommitFiberRoot(root, expirationTime);
16267 }
16268}
16269function onCommitUnmount(fiber) {
16270 if (typeof onCommitFiberUnmount === 'function') {
16271 onCommitFiberUnmount(fiber);
16272 }
16273}
16274
16275var hasBadMapPolyfill;
16276
16277{
16278 hasBadMapPolyfill = false;
16279
16280 try {
16281 var nonExtensibleObject = Object.preventExtensions({});
16282 var testMap = new Map([[nonExtensibleObject, null]]);
16283 var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
16284 // https://github.com/rollup/rollup/issues/1771
16285 // TODO: we can remove these if Rollup fixes the bug.
16286
16287 testMap.set(0, 0);
16288 testSet.add(0);
16289 } catch (e) {
16290 // TODO: Consider warning about bad polyfills
16291 hasBadMapPolyfill = true;
16292 }
16293}
16294
16295var debugCounter = 1;
16296
16297function FiberNode(tag, pendingProps, key, mode) {
16298 // Instance
16299 this.tag = tag;
16300 this.key = key;
16301 this.elementType = null;
16302 this.type = null;
16303 this.stateNode = null; // Fiber
16304
16305 this.return = null;
16306 this.child = null;
16307 this.sibling = null;
16308 this.index = 0;
16309 this.ref = null;
16310 this.pendingProps = pendingProps;
16311 this.memoizedProps = null;
16312 this.updateQueue = null;
16313 this.memoizedState = null;
16314 this.dependencies = null;
16315 this.mode = mode; // Effects
16316
16317 this.effectTag = NoEffect;
16318 this.nextEffect = null;
16319 this.firstEffect = null;
16320 this.lastEffect = null;
16321 this.expirationTime = NoWork;
16322 this.childExpirationTime = NoWork;
16323 this.alternate = null;
16324
16325 if (enableProfilerTimer) {
16326 // Note: The following is done to avoid a v8 performance cliff.
16327 //
16328 // Initializing the fields below to smis and later updating them with
16329 // double values will cause Fibers to end up having separate shapes.
16330 // This behavior/bug has something to do with Object.preventExtension().
16331 // Fortunately this only impacts DEV builds.
16332 // Unfortunately it makes React unusably slow for some applications.
16333 // To work around this, initialize the fields below with doubles.
16334 //
16335 // Learn more about this here:
16336 // https://github.com/facebook/react/issues/14365
16337 // https://bugs.chromium.org/p/v8/issues/detail?id=8538
16338 this.actualDuration = Number.NaN;
16339 this.actualStartTime = Number.NaN;
16340 this.selfBaseDuration = Number.NaN;
16341 this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
16342 // This won't trigger the performance cliff mentioned above,
16343 // and it simplifies other profiler code (including DevTools).
16344
16345 this.actualDuration = 0;
16346 this.actualStartTime = -1;
16347 this.selfBaseDuration = 0;
16348 this.treeBaseDuration = 0;
16349 } // This is normally DEV-only except www when it adds listeners.
16350 // TODO: remove the User Timing integration in favor of Root Events.
16351
16352
16353 if (enableUserTimingAPI) {
16354 this._debugID = debugCounter++;
16355 this._debugIsCurrentlyTiming = false;
16356 }
16357
16358 {
16359 this._debugSource = null;
16360 this._debugOwner = null;
16361 this._debugNeedsRemount = false;
16362 this._debugHookTypes = null;
16363
16364 if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
16365 Object.preventExtensions(this);
16366 }
16367 }
16368} // This is a constructor function, rather than a POJO constructor, still
16369// please ensure we do the following:
16370// 1) Nobody should add any instance methods on this. Instance methods can be
16371// more difficult to predict when they get optimized and they are almost
16372// never inlined properly in static compilers.
16373// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
16374// always know when it is a fiber.
16375// 3) We might want to experiment with using numeric keys since they are easier
16376// to optimize in a non-JIT environment.
16377// 4) We can easily go from a constructor to a createFiber object literal if that
16378// is faster.
16379// 5) It should be easy to port this to a C struct and keep a C implementation
16380// compatible.
16381
16382
16383var createFiber = function (tag, pendingProps, key, mode) {
16384 // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
16385 return new FiberNode(tag, pendingProps, key, mode);
16386};
16387
16388function shouldConstruct(Component) {
16389 var prototype = Component.prototype;
16390 return !!(prototype && prototype.isReactComponent);
16391}
16392
16393function isSimpleFunctionComponent(type) {
16394 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
16395}
16396function resolveLazyComponentTag(Component) {
16397 if (typeof Component === 'function') {
16398 return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
16399 } else if (Component !== undefined && Component !== null) {
16400 var $$typeof = Component.$$typeof;
16401
16402 if ($$typeof === REACT_FORWARD_REF_TYPE) {
16403 return ForwardRef;
16404 }
16405
16406 if ($$typeof === REACT_MEMO_TYPE) {
16407 return MemoComponent;
16408 }
16409 }
16410
16411 return IndeterminateComponent;
16412} // This is used to create an alternate fiber to do work on.
16413
16414function createWorkInProgress(current, pendingProps, expirationTime) {
16415 var workInProgress = current.alternate;
16416
16417 if (workInProgress === null) {
16418 // We use a double buffering pooling technique because we know that we'll
16419 // only ever need at most two versions of a tree. We pool the "other" unused
16420 // node that we're free to reuse. This is lazily created to avoid allocating
16421 // extra objects for things that are never updated. It also allow us to
16422 // reclaim the extra memory if needed.
16423 workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
16424 workInProgress.elementType = current.elementType;
16425 workInProgress.type = current.type;
16426 workInProgress.stateNode = current.stateNode;
16427
16428 {
16429 // DEV-only fields
16430 workInProgress._debugID = current._debugID;
16431 workInProgress._debugSource = current._debugSource;
16432 workInProgress._debugOwner = current._debugOwner;
16433 workInProgress._debugHookTypes = current._debugHookTypes;
16434 }
16435
16436 workInProgress.alternate = current;
16437 current.alternate = workInProgress;
16438 } else {
16439 workInProgress.pendingProps = pendingProps; // We already have an alternate.
16440 // Reset the effect tag.
16441
16442 workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
16443
16444 workInProgress.nextEffect = null;
16445 workInProgress.firstEffect = null;
16446 workInProgress.lastEffect = null;
16447
16448 if (enableProfilerTimer) {
16449 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
16450 // This prevents time from endlessly accumulating in new commits.
16451 // This has the downside of resetting values for different priority renders,
16452 // But works for yielding (the common case) and should support resuming.
16453 workInProgress.actualDuration = 0;
16454 workInProgress.actualStartTime = -1;
16455 }
16456 }
16457
16458 workInProgress.childExpirationTime = current.childExpirationTime;
16459 workInProgress.expirationTime = current.expirationTime;
16460 workInProgress.child = current.child;
16461 workInProgress.memoizedProps = current.memoizedProps;
16462 workInProgress.memoizedState = current.memoizedState;
16463 workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
16464 // it cannot be shared with the current fiber.
16465
16466 var currentDependencies = current.dependencies;
16467 workInProgress.dependencies = currentDependencies === null ? null : {
16468 expirationTime: currentDependencies.expirationTime,
16469 firstContext: currentDependencies.firstContext,
16470 responders: currentDependencies.responders
16471 }; // These will be overridden during the parent's reconciliation
16472
16473 workInProgress.sibling = current.sibling;
16474 workInProgress.index = current.index;
16475 workInProgress.ref = current.ref;
16476
16477 if (enableProfilerTimer) {
16478 workInProgress.selfBaseDuration = current.selfBaseDuration;
16479 workInProgress.treeBaseDuration = current.treeBaseDuration;
16480 }
16481
16482 {
16483 workInProgress._debugNeedsRemount = current._debugNeedsRemount;
16484
16485 switch (workInProgress.tag) {
16486 case IndeterminateComponent:
16487 case FunctionComponent:
16488 case SimpleMemoComponent:
16489 workInProgress.type = resolveFunctionForHotReloading(current.type);
16490 break;
16491
16492 case ClassComponent:
16493 workInProgress.type = resolveClassForHotReloading(current.type);
16494 break;
16495
16496 case ForwardRef:
16497 workInProgress.type = resolveForwardRefForHotReloading(current.type);
16498 break;
16499
16500 default:
16501 break;
16502 }
16503 }
16504
16505 return workInProgress;
16506} // Used to reuse a Fiber for a second pass.
16507
16508function resetWorkInProgress(workInProgress, renderExpirationTime) {
16509 // This resets the Fiber to what createFiber or createWorkInProgress would
16510 // have set the values to before during the first pass. Ideally this wouldn't
16511 // be necessary but unfortunately many code paths reads from the workInProgress
16512 // when they should be reading from current and writing to workInProgress.
16513 // We assume pendingProps, index, key, ref, return are still untouched to
16514 // avoid doing another reconciliation.
16515 // Reset the effect tag but keep any Placement tags, since that's something
16516 // that child fiber is setting, not the reconciliation.
16517 workInProgress.effectTag &= Placement; // The effect list is no longer valid.
16518
16519 workInProgress.nextEffect = null;
16520 workInProgress.firstEffect = null;
16521 workInProgress.lastEffect = null;
16522 var current = workInProgress.alternate;
16523
16524 if (current === null) {
16525 // Reset to createFiber's initial values.
16526 workInProgress.childExpirationTime = NoWork;
16527 workInProgress.expirationTime = renderExpirationTime;
16528 workInProgress.child = null;
16529 workInProgress.memoizedProps = null;
16530 workInProgress.memoizedState = null;
16531 workInProgress.updateQueue = null;
16532 workInProgress.dependencies = null;
16533
16534 if (enableProfilerTimer) {
16535 // Note: We don't reset the actualTime counts. It's useful to accumulate
16536 // actual time across multiple render passes.
16537 workInProgress.selfBaseDuration = 0;
16538 workInProgress.treeBaseDuration = 0;
16539 }
16540 } else {
16541 // Reset to the cloned values that createWorkInProgress would've.
16542 workInProgress.childExpirationTime = current.childExpirationTime;
16543 workInProgress.expirationTime = current.expirationTime;
16544 workInProgress.child = current.child;
16545 workInProgress.memoizedProps = current.memoizedProps;
16546 workInProgress.memoizedState = current.memoizedState;
16547 workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
16548 // it cannot be shared with the current fiber.
16549
16550 var currentDependencies = current.dependencies;
16551 workInProgress.dependencies = currentDependencies === null ? null : {
16552 expirationTime: currentDependencies.expirationTime,
16553 firstContext: currentDependencies.firstContext,
16554 responders: currentDependencies.responders
16555 };
16556
16557 if (enableProfilerTimer) {
16558 // Note: We don't reset the actualTime counts. It's useful to accumulate
16559 // actual time across multiple render passes.
16560 workInProgress.selfBaseDuration = current.selfBaseDuration;
16561 workInProgress.treeBaseDuration = current.treeBaseDuration;
16562 }
16563 }
16564
16565 return workInProgress;
16566}
16567function createHostRootFiber(tag) {
16568 var mode;
16569
16570 if (tag === ConcurrentRoot) {
16571 mode = ConcurrentMode | BatchedMode | StrictMode;
16572 } else if (tag === BatchedRoot) {
16573 mode = BatchedMode | StrictMode;
16574 } else {
16575 mode = NoMode;
16576 }
16577
16578 if (enableProfilerTimer && isDevToolsPresent) {
16579 // Always collect profile timings when DevTools are present.
16580 // This enables DevTools to start capturing timing at any point–
16581 // Without some nodes in the tree having empty base times.
16582 mode |= ProfileMode;
16583 }
16584
16585 return createFiber(HostRoot, null, null, mode);
16586}
16587function createFiberFromTypeAndProps(type, // React$ElementType
16588key, pendingProps, owner, mode, expirationTime) {
16589 var fiber;
16590 var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
16591
16592 var resolvedType = type;
16593
16594 if (typeof type === 'function') {
16595 if (shouldConstruct(type)) {
16596 fiberTag = ClassComponent;
16597
16598 {
16599 resolvedType = resolveClassForHotReloading(resolvedType);
16600 }
16601 } else {
16602 {
16603 resolvedType = resolveFunctionForHotReloading(resolvedType);
16604 }
16605 }
16606 } else if (typeof type === 'string') {
16607 fiberTag = HostComponent;
16608 } else {
16609 getTag: switch (type) {
16610 case REACT_FRAGMENT_TYPE:
16611 return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
16612
16613 case REACT_CONCURRENT_MODE_TYPE:
16614 fiberTag = Mode;
16615 mode |= ConcurrentMode | BatchedMode | StrictMode;
16616 break;
16617
16618 case REACT_STRICT_MODE_TYPE:
16619 fiberTag = Mode;
16620 mode |= StrictMode;
16621 break;
16622
16623 case REACT_PROFILER_TYPE:
16624 return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
16625
16626 case REACT_SUSPENSE_TYPE:
16627 return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
16628
16629 case REACT_SUSPENSE_LIST_TYPE:
16630 return createFiberFromSuspenseList(pendingProps, mode, expirationTime, key);
16631
16632 default:
16633 {
16634 if (typeof type === 'object' && type !== null) {
16635 switch (type.$$typeof) {
16636 case REACT_PROVIDER_TYPE:
16637 fiberTag = ContextProvider;
16638 break getTag;
16639
16640 case REACT_CONTEXT_TYPE:
16641 // This is a consumer
16642 fiberTag = ContextConsumer;
16643 break getTag;
16644
16645 case REACT_FORWARD_REF_TYPE:
16646 fiberTag = ForwardRef;
16647
16648 {
16649 resolvedType = resolveForwardRefForHotReloading(resolvedType);
16650 }
16651
16652 break getTag;
16653
16654 case REACT_MEMO_TYPE:
16655 fiberTag = MemoComponent;
16656 break getTag;
16657
16658 case REACT_LAZY_TYPE:
16659 fiberTag = LazyComponent;
16660 resolvedType = null;
16661 break getTag;
16662
16663 case REACT_FUNDAMENTAL_TYPE:
16664 if (enableFundamentalAPI) {
16665 return createFiberFromFundamental(type, pendingProps, mode, expirationTime, key);
16666 }
16667
16668 break;
16669
16670 case REACT_SCOPE_TYPE:
16671 if (enableScopeAPI) {
16672 return createFiberFromScope(type, pendingProps, mode, expirationTime, key);
16673 }
16674
16675 }
16676 }
16677
16678 var info = '';
16679
16680 {
16681 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
16682 info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and " + 'named imports.';
16683 }
16684
16685 var ownerName = owner ? getComponentName(owner.type) : null;
16686
16687 if (ownerName) {
16688 info += '\n\nCheck the render method of `' + ownerName + '`.';
16689 }
16690 }
16691
16692 (function () {
16693 {
16694 {
16695 throw ReactError(Error("Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: " + (type == null ? type : typeof type) + "." + info));
16696 }
16697 }
16698 })();
16699 }
16700 }
16701 }
16702
16703 fiber = createFiber(fiberTag, pendingProps, key, mode);
16704 fiber.elementType = type;
16705 fiber.type = resolvedType;
16706 fiber.expirationTime = expirationTime;
16707 return fiber;
16708}
16709function createFiberFromElement(element, mode, expirationTime) {
16710 var owner = null;
16711
16712 {
16713 owner = element._owner;
16714 }
16715
16716 var type = element.type;
16717 var key = element.key;
16718 var pendingProps = element.props;
16719 var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
16720
16721 {
16722 fiber._debugSource = element._source;
16723 fiber._debugOwner = element._owner;
16724 }
16725
16726 return fiber;
16727}
16728function createFiberFromFragment(elements, mode, expirationTime, key) {
16729 var fiber = createFiber(Fragment, elements, key, mode);
16730 fiber.expirationTime = expirationTime;
16731 return fiber;
16732}
16733function createFiberFromFundamental(fundamentalComponent, pendingProps, mode, expirationTime, key) {
16734 var fiber = createFiber(FundamentalComponent, pendingProps, key, mode);
16735 fiber.elementType = fundamentalComponent;
16736 fiber.type = fundamentalComponent;
16737 fiber.expirationTime = expirationTime;
16738 return fiber;
16739}
16740
16741function createFiberFromScope(scope, pendingProps, mode, expirationTime, key) {
16742 var fiber = createFiber(ScopeComponent, pendingProps, key, mode);
16743 fiber.type = scope;
16744 fiber.elementType = scope;
16745 fiber.expirationTime = expirationTime;
16746 return fiber;
16747}
16748
16749function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
16750 {
16751 if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
16752 warningWithoutStack$1(false, 'Profiler must specify an "id" string and "onRender" function as props');
16753 }
16754 }
16755
16756 var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
16757
16758 fiber.elementType = REACT_PROFILER_TYPE;
16759 fiber.type = REACT_PROFILER_TYPE;
16760 fiber.expirationTime = expirationTime;
16761 return fiber;
16762}
16763
16764function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
16765 var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
16766 // This needs to be fixed in getComponentName so that it relies on the tag
16767 // instead.
16768
16769 fiber.type = REACT_SUSPENSE_TYPE;
16770 fiber.elementType = REACT_SUSPENSE_TYPE;
16771 fiber.expirationTime = expirationTime;
16772 return fiber;
16773}
16774function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
16775 var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
16776
16777 {
16778 // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
16779 // This needs to be fixed in getComponentName so that it relies on the tag
16780 // instead.
16781 fiber.type = REACT_SUSPENSE_LIST_TYPE;
16782 }
16783
16784 fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
16785 fiber.expirationTime = expirationTime;
16786 return fiber;
16787}
16788function createFiberFromText(content, mode, expirationTime) {
16789 var fiber = createFiber(HostText, content, null, mode);
16790 fiber.expirationTime = expirationTime;
16791 return fiber;
16792}
16793function createFiberFromHostInstanceForDeletion() {
16794 var fiber = createFiber(HostComponent, null, null, NoMode); // TODO: These should not need a type.
16795
16796 fiber.elementType = 'DELETED';
16797 fiber.type = 'DELETED';
16798 return fiber;
16799}
16800function createFiberFromDehydratedFragment(dehydratedNode) {
16801 var fiber = createFiber(DehydratedFragment, null, null, NoMode);
16802 fiber.stateNode = dehydratedNode;
16803 return fiber;
16804}
16805function createFiberFromPortal(portal, mode, expirationTime) {
16806 var pendingProps = portal.children !== null ? portal.children : [];
16807 var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
16808 fiber.expirationTime = expirationTime;
16809 fiber.stateNode = {
16810 containerInfo: portal.containerInfo,
16811 pendingChildren: null,
16812 // Used by persistent updates
16813 implementation: portal.implementation
16814 };
16815 return fiber;
16816} // Used for stashing WIP properties to replay failed work in DEV.
16817
16818function assignFiberPropertiesInDEV(target, source) {
16819 if (target === null) {
16820 // This Fiber's initial properties will always be overwritten.
16821 // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
16822 target = createFiber(IndeterminateComponent, null, null, NoMode);
16823 } // This is intentionally written as a list of all properties.
16824 // We tried to use Object.assign() instead but this is called in
16825 // the hottest path, and Object.assign() was too slow:
16826 // https://github.com/facebook/react/issues/12502
16827 // This code is DEV-only so size is not a concern.
16828
16829
16830 target.tag = source.tag;
16831 target.key = source.key;
16832 target.elementType = source.elementType;
16833 target.type = source.type;
16834 target.stateNode = source.stateNode;
16835 target.return = source.return;
16836 target.child = source.child;
16837 target.sibling = source.sibling;
16838 target.index = source.index;
16839 target.ref = source.ref;
16840 target.pendingProps = source.pendingProps;
16841 target.memoizedProps = source.memoizedProps;
16842 target.updateQueue = source.updateQueue;
16843 target.memoizedState = source.memoizedState;
16844 target.dependencies = source.dependencies;
16845 target.mode = source.mode;
16846 target.effectTag = source.effectTag;
16847 target.nextEffect = source.nextEffect;
16848 target.firstEffect = source.firstEffect;
16849 target.lastEffect = source.lastEffect;
16850 target.expirationTime = source.expirationTime;
16851 target.childExpirationTime = source.childExpirationTime;
16852 target.alternate = source.alternate;
16853
16854 if (enableProfilerTimer) {
16855 target.actualDuration = source.actualDuration;
16856 target.actualStartTime = source.actualStartTime;
16857 target.selfBaseDuration = source.selfBaseDuration;
16858 target.treeBaseDuration = source.treeBaseDuration;
16859 }
16860
16861 target._debugID = source._debugID;
16862 target._debugSource = source._debugSource;
16863 target._debugOwner = source._debugOwner;
16864 target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
16865 target._debugNeedsRemount = source._debugNeedsRemount;
16866 target._debugHookTypes = source._debugHookTypes;
16867 return target;
16868}
16869
16870function FiberRootNode(containerInfo, tag, hydrate) {
16871 this.tag = tag;
16872 this.current = null;
16873 this.containerInfo = containerInfo;
16874 this.pendingChildren = null;
16875 this.pingCache = null;
16876 this.finishedExpirationTime = NoWork;
16877 this.finishedWork = null;
16878 this.timeoutHandle = noTimeout;
16879 this.context = null;
16880 this.pendingContext = null;
16881 this.hydrate = hydrate;
16882 this.firstBatch = null;
16883 this.callbackNode = null;
16884 this.callbackPriority = NoPriority;
16885 this.firstPendingTime = NoWork;
16886 this.firstSuspendedTime = NoWork;
16887 this.lastSuspendedTime = NoWork;
16888 this.nextKnownPendingLevel = NoWork;
16889 this.lastPingedTime = NoWork;
16890 this.lastExpiredTime = NoWork;
16891
16892 if (enableSchedulerTracing) {
16893 this.interactionThreadID = unstable_getThreadID();
16894 this.memoizedInteractions = new Set();
16895 this.pendingInteractionMap = new Map();
16896 }
16897
16898 if (enableSuspenseCallback) {
16899 this.hydrationCallbacks = null;
16900 }
16901}
16902
16903function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
16904 var root = new FiberRootNode(containerInfo, tag, hydrate);
16905
16906 if (enableSuspenseCallback) {
16907 root.hydrationCallbacks = hydrationCallbacks;
16908 } // Cyclic construction. This cheats the type system right now because
16909 // stateNode is any.
16910
16911
16912 var uninitializedFiber = createHostRootFiber(tag);
16913 root.current = uninitializedFiber;
16914 uninitializedFiber.stateNode = root;
16915 return root;
16916}
16917function isRootSuspendedAtTime(root, expirationTime) {
16918 var firstSuspendedTime = root.firstSuspendedTime;
16919 var lastSuspendedTime = root.lastSuspendedTime;
16920 return firstSuspendedTime !== NoWork && firstSuspendedTime >= expirationTime && lastSuspendedTime <= expirationTime;
16921}
16922function markRootSuspendedAtTime(root, expirationTime) {
16923 var firstSuspendedTime = root.firstSuspendedTime;
16924 var lastSuspendedTime = root.lastSuspendedTime;
16925
16926 if (firstSuspendedTime < expirationTime) {
16927 root.firstSuspendedTime = expirationTime;
16928 }
16929
16930 if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
16931 root.lastSuspendedTime = expirationTime;
16932 }
16933
16934 if (expirationTime <= root.lastPingedTime) {
16935 root.lastPingedTime = NoWork;
16936 }
16937
16938 if (expirationTime <= root.lastExpiredTime) {
16939 root.lastExpiredTime = NoWork;
16940 }
16941}
16942function markRootUpdatedAtTime(root, expirationTime) {
16943 // Update the range of pending times
16944 var firstPendingTime = root.firstPendingTime;
16945
16946 if (expirationTime > firstPendingTime) {
16947 root.firstPendingTime = expirationTime;
16948 } // Update the range of suspended times. Treat everything lower priority or
16949 // equal to this update as unsuspended.
16950
16951
16952 var firstSuspendedTime = root.firstSuspendedTime;
16953
16954 if (firstSuspendedTime !== NoWork) {
16955 if (expirationTime >= firstSuspendedTime) {
16956 // The entire suspended range is now unsuspended.
16957 root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
16958 } else if (expirationTime >= root.lastSuspendedTime) {
16959 root.lastSuspendedTime = expirationTime + 1;
16960 } // This is a pending level. Check if it's higher priority than the next
16961 // known pending level.
16962
16963
16964 if (expirationTime > root.nextKnownPendingLevel) {
16965 root.nextKnownPendingLevel = expirationTime;
16966 }
16967 }
16968}
16969function markRootFinishedAtTime(root, finishedExpirationTime, remainingExpirationTime) {
16970 // Update the range of pending times
16971 root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
16972 // equal to this update as unsuspended.
16973
16974 if (finishedExpirationTime <= root.lastSuspendedTime) {
16975 // The entire suspended range is now unsuspended.
16976 root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
16977 } else if (finishedExpirationTime <= root.firstSuspendedTime) {
16978 // Part of the suspended range is now unsuspended. Narrow the range to
16979 // include everything between the unsuspended time (non-inclusive) and the
16980 // last suspended time.
16981 root.firstSuspendedTime = finishedExpirationTime - 1;
16982 }
16983
16984 if (finishedExpirationTime <= root.lastPingedTime) {
16985 // Clear the pinged time
16986 root.lastPingedTime = NoWork;
16987 }
16988
16989 if (finishedExpirationTime <= root.lastExpiredTime) {
16990 // Clear the expired time
16991 root.lastExpiredTime = NoWork;
16992 }
16993}
16994function markRootExpiredAtTime(root, expirationTime) {
16995 var lastExpiredTime = root.lastExpiredTime;
16996
16997 if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
16998 root.lastExpiredTime = expirationTime;
16999 }
17000}
17001
17002// This lets us hook into Fiber to debug what it's doing.
17003// See https://github.com/facebook/react/pull/8033.
17004// This is not part of the public API, not even for React DevTools.
17005// You may only inject a debugTool if you work on React Fiber itself.
17006var ReactFiberInstrumentation = {
17007 debugTool: null
17008};
17009var ReactFiberInstrumentation_1 = ReactFiberInstrumentation;
17010
17011var didWarnAboutNestedUpdates;
17012{
17013 didWarnAboutNestedUpdates = false;
17014
17015}
17016
17017function getContextForSubtree(parentComponent) {
17018 if (!parentComponent) {
17019 return emptyContextObject;
17020 }
17021
17022 var fiber = get(parentComponent);
17023 var parentContext = findCurrentUnmaskedContext(fiber);
17024
17025 if (fiber.tag === ClassComponent) {
17026 var Component = fiber.type;
17027
17028 if (isContextProvider(Component)) {
17029 return processChildContext(fiber, Component, parentContext);
17030 }
17031 }
17032
17033 return parentContext;
17034}
17035
17036function scheduleRootUpdate(current$$1, element, expirationTime, suspenseConfig, callback) {
17037 {
17038 if (phase === 'render' && current !== null && !didWarnAboutNestedUpdates) {
17039 didWarnAboutNestedUpdates = true;
17040 warningWithoutStack$1(false, 'Render methods should be a pure function of props and state; ' + 'triggering nested component updates from render is not allowed. ' + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + 'Check the render method of %s.', getComponentName(current.type) || 'Unknown');
17041 }
17042 }
17043
17044 var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
17045 // being called "element".
17046
17047 update.payload = {
17048 element: element
17049 };
17050 callback = callback === undefined ? null : callback;
17051
17052 if (callback !== null) {
17053 !(typeof callback === 'function') ? warningWithoutStack$1(false, 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0;
17054 update.callback = callback;
17055 }
17056
17057 enqueueUpdate(current$$1, update);
17058 scheduleWork(current$$1, expirationTime);
17059 return expirationTime;
17060}
17061
17062function updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, suspenseConfig, callback) {
17063 // TODO: If this is a nested container, this won't be the root.
17064 var current$$1 = container.current;
17065
17066 {
17067 if (ReactFiberInstrumentation_1.debugTool) {
17068 if (current$$1.alternate === null) {
17069 ReactFiberInstrumentation_1.debugTool.onMountContainer(container);
17070 } else if (element === null) {
17071 ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container);
17072 } else {
17073 ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container);
17074 }
17075 }
17076 }
17077
17078 var context = getContextForSubtree(parentComponent);
17079
17080 if (container.context === null) {
17081 container.context = context;
17082 } else {
17083 container.pendingContext = context;
17084 }
17085
17086 return scheduleRootUpdate(current$$1, element, expirationTime, suspenseConfig, callback);
17087}
17088
17089function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
17090 return createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks);
17091}
17092function updateContainer(element, container, parentComponent, callback) {
17093 var current$$1 = container.current;
17094 var currentTime = requestCurrentTime();
17095
17096 {
17097 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
17098 if ('undefined' !== typeof jest) {
17099 warnIfUnmockedScheduler(current$$1);
17100 warnIfNotScopedWithMatchingAct(current$$1);
17101 }
17102 }
17103
17104 var suspenseConfig = requestCurrentSuspenseConfig();
17105 var expirationTime = computeExpirationForFiber(currentTime, current$$1, suspenseConfig);
17106 return updateContainerAtExpirationTime(element, container, parentComponent, expirationTime, suspenseConfig, callback);
17107}
17108function getPublicRootInstance(container) {
17109 var containerFiber = container.current;
17110
17111 if (!containerFiber.child) {
17112 return null;
17113 }
17114
17115 switch (containerFiber.child.tag) {
17116 case HostComponent:
17117 return getPublicInstance(containerFiber.child.stateNode);
17118
17119 default:
17120 return containerFiber.child.stateNode;
17121 }
17122}
17123
17124
17125
17126var shouldSuspendImpl = function (fiber) {
17127 return false;
17128};
17129
17130function shouldSuspend(fiber) {
17131 return shouldSuspendImpl(fiber);
17132}
17133var overrideHookState = null;
17134var overrideProps = null;
17135var scheduleUpdate = null;
17136var setSuspenseHandler = null;
17137
17138{
17139 var copyWithSetImpl = function (obj, path, idx, value) {
17140 if (idx >= path.length) {
17141 return value;
17142 }
17143
17144 var key = path[idx];
17145 var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj); // $FlowFixMe number or string is fine here
17146
17147 updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
17148 return updated;
17149 };
17150
17151 var copyWithSet = function (obj, path, value) {
17152 return copyWithSetImpl(obj, path, 0, value);
17153 }; // Support DevTools editable values for useState and useReducer.
17154
17155
17156 overrideHookState = function (fiber, id, path, value) {
17157 // For now, the "id" of stateful hooks is just the stateful hook index.
17158 // This may change in the future with e.g. nested hooks.
17159 var currentHook = fiber.memoizedState;
17160
17161 while (currentHook !== null && id > 0) {
17162 currentHook = currentHook.next;
17163 id--;
17164 }
17165
17166 if (currentHook !== null) {
17167 var newState = copyWithSet(currentHook.memoizedState, path, value);
17168 currentHook.memoizedState = newState;
17169 currentHook.baseState = newState; // We aren't actually adding an update to the queue,
17170 // because there is no update we can add for useReducer hooks that won't trigger an error.
17171 // (There's no appropriate action type for DevTools overrides.)
17172 // As a result though, React will see the scheduled update as a noop and bailout.
17173 // Shallow cloning props works as a workaround for now to bypass the bailout check.
17174
17175 fiber.memoizedProps = _assign({}, fiber.memoizedProps);
17176 scheduleWork(fiber, Sync);
17177 }
17178 }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
17179
17180
17181 overrideProps = function (fiber, path, value) {
17182 fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
17183
17184 if (fiber.alternate) {
17185 fiber.alternate.pendingProps = fiber.pendingProps;
17186 }
17187
17188 scheduleWork(fiber, Sync);
17189 };
17190
17191 scheduleUpdate = function (fiber) {
17192 scheduleWork(fiber, Sync);
17193 };
17194
17195 setSuspenseHandler = function (newShouldSuspendImpl) {
17196 shouldSuspendImpl = newShouldSuspendImpl;
17197 };
17198}
17199
17200function injectIntoDevTools(devToolsConfig) {
17201 var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
17202 var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
17203 return injectInternals(_assign({}, devToolsConfig, {
17204 overrideHookState: overrideHookState,
17205 overrideProps: overrideProps,
17206 setSuspenseHandler: setSuspenseHandler,
17207 scheduleUpdate: scheduleUpdate,
17208 currentDispatcherRef: ReactCurrentDispatcher,
17209 findHostInstanceByFiber: function (fiber) {
17210 var hostFiber = findCurrentHostFiber(fiber);
17211
17212 if (hostFiber === null) {
17213 return null;
17214 }
17215
17216 return hostFiber.stateNode;
17217 },
17218 findFiberByHostInstance: function (instance) {
17219 if (!findFiberByHostInstance) {
17220 // Might not be implemented by the renderer.
17221 return null;
17222 }
17223
17224 return findFiberByHostInstance(instance);
17225 },
17226 // React Refresh
17227 findHostInstancesForRefresh: findHostInstancesForRefresh,
17228 scheduleRefresh: scheduleRefresh,
17229 scheduleRoot: scheduleRoot,
17230 setRefreshHandler: setRefreshHandler,
17231 // Enables DevTools to append owner stacks to error messages in DEV mode.
17232 getCurrentFiber: function () {
17233 return current;
17234 }
17235 }));
17236}
17237
17238// This file intentionally does *not* have the Flow annotation.
17239// Don't add it. See `./inline-typed.js` for an explanation.
17240
17241// TODO: this is special because it gets imported during build.
17242
17243var ReactVersion = '16.10.0';
17244
17245var didWarnAboutMessageChannel = false;
17246var enqueueTask;
17247
17248try {
17249 // read require off the module object to get around the bundlers.
17250 // we don't want them to detect a require and bundle a Node polyfill.
17251 var requireString = ('require' + Math.random()).slice(0, 7);
17252 var nodeRequire = module && module[requireString]; // assuming we're in node, let's try to get node's
17253 // version of setImmediate, bypassing fake timers if any.
17254
17255 enqueueTask = nodeRequire('timers').setImmediate;
17256} catch (_err) {
17257 // we're in a browser
17258 // we can't use regular timers because they may still be faked
17259 // so we try MessageChannel+postMessage instead
17260 enqueueTask = function (callback) {
17261 {
17262 if (didWarnAboutMessageChannel === false) {
17263 didWarnAboutMessageChannel = true;
17264 !(typeof MessageChannel !== 'undefined') ? warningWithoutStack$1(false, 'This browser does not have a MessageChannel implementation, ' + 'so enqueuing tasks via await act(async () => ...) will fail. ' + 'Please file an issue at https://github.com/facebook/react/issues ' + 'if you encounter this warning.') : void 0;
17265 }
17266 }
17267
17268 var channel = new MessageChannel();
17269 channel.port1.onmessage = callback;
17270 channel.port2.postMessage(undefined);
17271 };
17272}
17273
17274var enqueueTask$1 = enqueueTask;
17275
17276var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
17277// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js
17278
17279var isSchedulerMocked = typeof Scheduler$1.unstable_flushAllWithoutAsserting === 'function';
17280
17281var flushWork = Scheduler$1.unstable_flushAllWithoutAsserting || function () {
17282 var didFlushWork = false;
17283
17284 while (flushPassiveEffects()) {
17285 didFlushWork = true;
17286 }
17287
17288 return didFlushWork;
17289};
17290
17291function flushWorkAndMicroTasks(onDone) {
17292 try {
17293 flushWork();
17294 enqueueTask$1(function () {
17295 if (flushWork()) {
17296 flushWorkAndMicroTasks(onDone);
17297 } else {
17298 onDone();
17299 }
17300 });
17301 } catch (err) {
17302 onDone(err);
17303 }
17304} // we track the 'depth' of the act() calls with this counter,
17305// so we can tell if any async act() calls try to run in parallel.
17306
17307
17308var actingUpdatesScopeDepth = 0;
17309function act(callback) {
17310 var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
17311 var previousIsSomeRendererActing;
17312 var previousIsThisRendererActing;
17313 actingUpdatesScopeDepth++;
17314 previousIsSomeRendererActing = IsSomeRendererActing$1.current;
17315 previousIsThisRendererActing = IsThisRendererActing.current;
17316 IsSomeRendererActing$1.current = true;
17317 IsThisRendererActing.current = true;
17318
17319 function onDone() {
17320 actingUpdatesScopeDepth--;
17321 IsSomeRendererActing$1.current = previousIsSomeRendererActing;
17322 IsThisRendererActing.current = previousIsThisRendererActing;
17323
17324 {
17325 if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
17326 // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
17327 warningWithoutStack$1(false, 'You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ');
17328 }
17329 }
17330 }
17331
17332 var result;
17333
17334 try {
17335 result = batchedUpdates(callback);
17336 } catch (error) {
17337 // on sync errors, we still want to 'cleanup' and decrement actingUpdatesScopeDepth
17338 onDone();
17339 throw error;
17340 }
17341
17342 if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
17343 // setup a boolean that gets set to true only
17344 // once this act() call is await-ed
17345 var called = false;
17346
17347 {
17348 if (typeof Promise !== 'undefined') {
17349 //eslint-disable-next-line no-undef
17350 Promise.resolve().then(function () {}).then(function () {
17351 if (called === false) {
17352 warningWithoutStack$1(false, 'You called act(async () => ...) without await. ' + 'This could lead to unexpected testing behaviour, interleaving multiple act ' + 'calls and mixing their scopes. You should - await act(async () => ...);');
17353 }
17354 });
17355 }
17356 } // in the async case, the returned thenable runs the callback, flushes
17357 // effects and microtasks in a loop until flushPassiveEffects() === false,
17358 // and cleans up
17359
17360
17361 return {
17362 then: function (resolve, reject) {
17363 called = true;
17364 result.then(function () {
17365 if (actingUpdatesScopeDepth > 1 || isSchedulerMocked === true && previousIsSomeRendererActing === true) {
17366 onDone();
17367 resolve();
17368 return;
17369 } // we're about to exit the act() scope,
17370 // now's the time to flush tasks/effects
17371
17372
17373 flushWorkAndMicroTasks(function (err) {
17374 onDone();
17375
17376 if (err) {
17377 reject(err);
17378 } else {
17379 resolve();
17380 }
17381 });
17382 }, function (err) {
17383 onDone();
17384 reject(err);
17385 });
17386 }
17387 };
17388 } else {
17389 {
17390 !(result === undefined) ? warningWithoutStack$1(false, 'The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result) : void 0;
17391 } // flush effects until none remain, and cleanup
17392
17393
17394 try {
17395 if (actingUpdatesScopeDepth === 1 && (isSchedulerMocked === false || previousIsSomeRendererActing === false)) {
17396 // we're about to exit the act() scope,
17397 // now's the time to flush effects
17398 flushWork();
17399 }
17400
17401 onDone();
17402 } catch (err) {
17403 onDone();
17404 throw err;
17405 } // in the sync case, the returned thenable only warns *if* await-ed
17406
17407
17408 return {
17409 then: function (resolve) {
17410 {
17411 warningWithoutStack$1(false, 'Do not await the result of calling act(...) with sync logic, it is not a Promise.');
17412 }
17413
17414 resolve();
17415 }
17416 };
17417 }
17418}
17419
17420var defaultTestOptions = {
17421 createNodeMock: function () {
17422 return null;
17423 }
17424};
17425
17426function toJSON(inst) {
17427 if (inst.isHidden) {
17428 // Omit timed out children from output entirely. This seems like the least
17429 // surprising behavior. We could perhaps add a separate API that includes
17430 // them, if it turns out people need it.
17431 return null;
17432 }
17433
17434 switch (inst.tag) {
17435 case 'TEXT':
17436 return inst.text;
17437
17438 case 'INSTANCE':
17439 {
17440 /* eslint-disable no-unused-vars */
17441 // We don't include the `children` prop in JSON.
17442 // Instead, we will include the actual rendered children.
17443 var _inst$props = inst.props,
17444 children = _inst$props.children,
17445 props = _objectWithoutPropertiesLoose(_inst$props, ["children"]);
17446 /* eslint-enable */
17447
17448
17449 var renderedChildren = null;
17450
17451 if (inst.children && inst.children.length) {
17452 for (var i = 0; i < inst.children.length; i++) {
17453 var renderedChild = toJSON(inst.children[i]);
17454
17455 if (renderedChild !== null) {
17456 if (renderedChildren === null) {
17457 renderedChildren = [renderedChild];
17458 } else {
17459 renderedChildren.push(renderedChild);
17460 }
17461 }
17462 }
17463 }
17464
17465 var json = {
17466 type: inst.type,
17467 props: props,
17468 children: renderedChildren
17469 };
17470 Object.defineProperty(json, '$$typeof', {
17471 value: Symbol.for('react.test.json')
17472 });
17473 return json;
17474 }
17475
17476 default:
17477 throw new Error("Unexpected node type in toJSON: " + inst.tag);
17478 }
17479}
17480
17481function childrenToTree(node) {
17482 if (!node) {
17483 return null;
17484 }
17485
17486 var children = nodeAndSiblingsArray(node);
17487
17488 if (children.length === 0) {
17489 return null;
17490 } else if (children.length === 1) {
17491 return toTree(children[0]);
17492 }
17493
17494 return flatten(children.map(toTree));
17495}
17496
17497function nodeAndSiblingsArray(nodeWithSibling) {
17498 var array = [];
17499 var node = nodeWithSibling;
17500
17501 while (node != null) {
17502 array.push(node);
17503 node = node.sibling;
17504 }
17505
17506 return array;
17507}
17508
17509function flatten(arr) {
17510 var result = [];
17511 var stack = [{
17512 i: 0,
17513 array: arr
17514 }];
17515
17516 while (stack.length) {
17517 var n = stack.pop();
17518
17519 while (n.i < n.array.length) {
17520 var el = n.array[n.i];
17521 n.i += 1;
17522
17523 if (Array.isArray(el)) {
17524 stack.push(n);
17525 stack.push({
17526 i: 0,
17527 array: el
17528 });
17529 break;
17530 }
17531
17532 result.push(el);
17533 }
17534 }
17535
17536 return result;
17537}
17538
17539function toTree(node) {
17540 if (node == null) {
17541 return null;
17542 }
17543
17544 switch (node.tag) {
17545 case HostRoot:
17546 return childrenToTree(node.child);
17547
17548 case HostPortal:
17549 return childrenToTree(node.child);
17550
17551 case ClassComponent:
17552 return {
17553 nodeType: 'component',
17554 type: node.type,
17555 props: _assign({}, node.memoizedProps),
17556 instance: node.stateNode,
17557 rendered: childrenToTree(node.child)
17558 };
17559
17560 case FunctionComponent:
17561 case SimpleMemoComponent:
17562 return {
17563 nodeType: 'component',
17564 type: node.type,
17565 props: _assign({}, node.memoizedProps),
17566 instance: null,
17567 rendered: childrenToTree(node.child)
17568 };
17569
17570 case HostComponent:
17571 {
17572 return {
17573 nodeType: 'host',
17574 type: node.type,
17575 props: _assign({}, node.memoizedProps),
17576 instance: null,
17577 // TODO: use createNodeMock here somehow?
17578 rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
17579 };
17580 }
17581
17582 case HostText:
17583 return node.stateNode.text;
17584
17585 case Fragment:
17586 case ContextProvider:
17587 case ContextConsumer:
17588 case Mode:
17589 case Profiler:
17590 case ForwardRef:
17591 case MemoComponent:
17592 case IncompleteClassComponent:
17593 case ScopeComponent:
17594 return childrenToTree(node.child);
17595
17596 default:
17597 (function () {
17598 {
17599 {
17600 throw ReactError(Error("toTree() does not yet know how to handle nodes with tag=" + node.tag));
17601 }
17602 }
17603 })();
17604
17605 }
17606}
17607
17608var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent, // Normally skipped, but used when there's more than one root child.
17609HostRoot]);
17610
17611function getChildren(parent) {
17612 var children = [];
17613 var startingNode = parent;
17614 var node = startingNode;
17615
17616 if (node.child === null) {
17617 return children;
17618 }
17619
17620 node.child.return = node;
17621 node = node.child;
17622
17623 outer: while (true) {
17624 var descend = false;
17625
17626 if (validWrapperTypes.has(node.tag)) {
17627 children.push(wrapFiber(node));
17628 } else if (node.tag === HostText) {
17629 children.push('' + node.memoizedProps);
17630 } else {
17631 descend = true;
17632 }
17633
17634 if (descend && node.child !== null) {
17635 node.child.return = node;
17636 node = node.child;
17637 continue;
17638 }
17639
17640 while (node.sibling === null) {
17641 if (node.return === startingNode) {
17642 break outer;
17643 }
17644
17645 node = node.return;
17646 }
17647
17648 node.sibling.return = node.return;
17649 node = node.sibling;
17650 }
17651
17652 return children;
17653}
17654
17655var ReactTestInstance =
17656/*#__PURE__*/
17657function () {
17658 var _proto = ReactTestInstance.prototype;
17659
17660 _proto._currentFiber = function _currentFiber() {
17661 // Throws if this component has been unmounted.
17662 var fiber = findCurrentFiberUsingSlowPath(this._fiber);
17663
17664 (function () {
17665 if (!(fiber !== null)) {
17666 {
17667 throw ReactError(Error("Can't read from currently-mounting component. This error is likely caused by a bug in React. Please file an issue."));
17668 }
17669 }
17670 })();
17671
17672 return fiber;
17673 };
17674
17675 function ReactTestInstance(fiber) {
17676 (function () {
17677 if (!validWrapperTypes.has(fiber.tag)) {
17678 {
17679 throw ReactError(Error("Unexpected object passed to ReactTestInstance constructor (tag: " + fiber.tag + "). This is probably a bug in React."));
17680 }
17681 }
17682 })();
17683
17684 this._fiber = fiber;
17685 }
17686
17687 // Custom search functions
17688 _proto.find = function find(predicate) {
17689 return expectOne(this.findAll(predicate, {
17690 deep: false
17691 }), "matching custom predicate: " + predicate.toString());
17692 };
17693
17694 _proto.findByType = function findByType(type) {
17695 return expectOne(this.findAllByType(type, {
17696 deep: false
17697 }), "with node type: \"" + (type.displayName || type.name) + "\"");
17698 };
17699
17700 _proto.findByProps = function findByProps(props) {
17701 return expectOne(this.findAllByProps(props, {
17702 deep: false
17703 }), "with props: " + JSON.stringify(props));
17704 };
17705
17706 _proto.findAll = function findAll(predicate) {
17707 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
17708 return _findAll(this, predicate, options);
17709 };
17710
17711 _proto.findAllByType = function findAllByType(type) {
17712 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
17713 return _findAll(this, function (node) {
17714 return node.type === type;
17715 }, options);
17716 };
17717
17718 _proto.findAllByProps = function findAllByProps(props) {
17719 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
17720 return _findAll(this, function (node) {
17721 return node.props && propsMatch(node.props, props);
17722 }, options);
17723 };
17724
17725 _createClass(ReactTestInstance, [{
17726 key: "instance",
17727 get: function () {
17728 if (this._fiber.tag === HostComponent) {
17729 return getPublicInstance(this._fiber.stateNode);
17730 } else {
17731 return this._fiber.stateNode;
17732 }
17733 }
17734 }, {
17735 key: "type",
17736 get: function () {
17737 return this._fiber.type;
17738 }
17739 }, {
17740 key: "props",
17741 get: function () {
17742 return this._currentFiber().memoizedProps;
17743 }
17744 }, {
17745 key: "parent",
17746 get: function () {
17747 var parent = this._fiber.return;
17748
17749 while (parent !== null) {
17750 if (validWrapperTypes.has(parent.tag)) {
17751 if (parent.tag === HostRoot) {
17752 // Special case: we only "materialize" instances for roots
17753 // if they have more than a single child. So we'll check that now.
17754 if (getChildren(parent).length < 2) {
17755 return null;
17756 }
17757 }
17758
17759 return wrapFiber(parent);
17760 }
17761
17762 parent = parent.return;
17763 }
17764
17765 return null;
17766 }
17767 }, {
17768 key: "children",
17769 get: function () {
17770 return getChildren(this._currentFiber());
17771 }
17772 }]);
17773
17774 return ReactTestInstance;
17775}();
17776
17777function _findAll(root, predicate, options) {
17778 var deep = options ? options.deep : true;
17779 var results = [];
17780
17781 if (predicate(root)) {
17782 results.push(root);
17783
17784 if (!deep) {
17785 return results;
17786 }
17787 }
17788
17789 root.children.forEach(function (child) {
17790 if (typeof child === 'string') {
17791 return;
17792 }
17793
17794 results.push.apply(results, _findAll(child, predicate, options));
17795 });
17796 return results;
17797}
17798
17799function expectOne(all, message) {
17800 if (all.length === 1) {
17801 return all[0];
17802 }
17803
17804 var prefix = all.length === 0 ? 'No instances found ' : "Expected 1 but found " + all.length + " instances ";
17805 throw new Error(prefix + message);
17806}
17807
17808function propsMatch(props, filter) {
17809 for (var key in filter) {
17810 if (props[key] !== filter[key]) {
17811 return false;
17812 }
17813 }
17814
17815 return true;
17816}
17817
17818var ReactTestRendererFiber = {
17819 _Scheduler: Scheduler,
17820 create: function (element, options) {
17821 var createNodeMock = defaultTestOptions.createNodeMock;
17822 var isConcurrent = false;
17823
17824 if (typeof options === 'object' && options !== null) {
17825 if (typeof options.createNodeMock === 'function') {
17826 createNodeMock = options.createNodeMock;
17827 }
17828
17829 if (options.unstable_isConcurrent === true) {
17830 isConcurrent = true;
17831 }
17832 }
17833
17834 var container = {
17835 children: [],
17836 createNodeMock: createNodeMock,
17837 tag: 'CONTAINER'
17838 };
17839 var root = createContainer(container, isConcurrent ? ConcurrentRoot : LegacyRoot, false, null);
17840
17841 (function () {
17842 if (!(root != null)) {
17843 {
17844 throw ReactError(Error("something went wrong"));
17845 }
17846 }
17847 })();
17848
17849 updateContainer(element, root, null, null);
17850 var entry = {
17851 _Scheduler: Scheduler,
17852 root: undefined,
17853 // makes flow happy
17854 // we define a 'getter' for 'root' below using 'Object.defineProperty'
17855 toJSON: function () {
17856 if (root == null || root.current == null || container == null) {
17857 return null;
17858 }
17859
17860 if (container.children.length === 0) {
17861 return null;
17862 }
17863
17864 if (container.children.length === 1) {
17865 return toJSON(container.children[0]);
17866 }
17867
17868 if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
17869 // Omit timed out children from output entirely, including the fact that we
17870 // temporarily wrap fallback and timed out children in an array.
17871 return toJSON(container.children[1]);
17872 }
17873
17874 var renderedChildren = null;
17875
17876 if (container.children && container.children.length) {
17877 for (var i = 0; i < container.children.length; i++) {
17878 var renderedChild = toJSON(container.children[i]);
17879
17880 if (renderedChild !== null) {
17881 if (renderedChildren === null) {
17882 renderedChildren = [renderedChild];
17883 } else {
17884 renderedChildren.push(renderedChild);
17885 }
17886 }
17887 }
17888 }
17889
17890 return renderedChildren;
17891 },
17892 toTree: function () {
17893 if (root == null || root.current == null) {
17894 return null;
17895 }
17896
17897 return toTree(root.current);
17898 },
17899 update: function (newElement) {
17900 if (root == null || root.current == null) {
17901 return;
17902 }
17903
17904 updateContainer(newElement, root, null, null);
17905 },
17906 unmount: function () {
17907 if (root == null || root.current == null) {
17908 return;
17909 }
17910
17911 updateContainer(null, root, null, null);
17912 container = null;
17913 root = null;
17914 },
17915 getInstance: function () {
17916 if (root == null || root.current == null) {
17917 return null;
17918 }
17919
17920 return getPublicRootInstance(root);
17921 },
17922 unstable_flushSync: function (fn) {
17923 return flushSync(fn);
17924 }
17925 };
17926 Object.defineProperty(entry, 'root', {
17927 configurable: true,
17928 enumerable: true,
17929 get: function () {
17930 if (root === null) {
17931 throw new Error("Can't access .root on unmounted test renderer");
17932 }
17933
17934 var children = getChildren(root.current);
17935
17936 if (children.length === 0) {
17937 throw new Error("Can't access .root on unmounted test renderer");
17938 } else if (children.length === 1) {
17939 // Normally, we skip the root and just give you the child.
17940 return children[0];
17941 } else {
17942 // However, we give you the root if there's more than one root child.
17943 // We could make this the behavior for all cases but it would be a breaking change.
17944 return wrapFiber(root.current);
17945 }
17946 }
17947 });
17948 return entry;
17949 },
17950
17951 /* eslint-disable-next-line camelcase */
17952 unstable_batchedUpdates: batchedUpdates,
17953 act: act
17954};
17955var fiberToWrapper = new WeakMap();
17956
17957function wrapFiber(fiber) {
17958 var wrapper = fiberToWrapper.get(fiber);
17959
17960 if (wrapper === undefined && fiber.alternate !== null) {
17961 wrapper = fiberToWrapper.get(fiber.alternate);
17962 }
17963
17964 if (wrapper === undefined) {
17965 wrapper = new ReactTestInstance(fiber);
17966 fiberToWrapper.set(fiber, wrapper);
17967 }
17968
17969 return wrapper;
17970} // Enable ReactTestRenderer to be used to test DevTools integration.
17971
17972
17973injectIntoDevTools({
17974 findFiberByHostInstance: function () {
17975 throw new Error('TestRenderer does not support findFiberByHostInstance()');
17976 },
17977 bundleType: 1,
17978 version: ReactVersion,
17979 rendererPackageName: 'react-test-renderer'
17980});
17981
17982
17983var ReactTestRenderer = Object.freeze({
17984 default: ReactTestRendererFiber
17985});
17986
17987var ReactTestRenderer$1 = ( ReactTestRenderer && ReactTestRendererFiber ) || ReactTestRenderer;
17988
17989// TODO: decide on the top-level export form.
17990// This is hacky but makes it work with both Rollup and Jest.
17991
17992
17993var reactTestRenderer = ReactTestRenderer$1.default || ReactTestRenderer$1;
17994
17995return reactTestRenderer;
17996
17997})));