UNPKG

633 kBJavaScriptView Raw
1/** @license React v16.12.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 replaced with error codes
20// during build.
21
22function _defineProperties(target, props) {
23 for (var i = 0; i < props.length; i++) {
24 var descriptor = props[i];
25 descriptor.enumerable = descriptor.enumerable || false;
26 descriptor.configurable = true;
27 if ("value" in descriptor) descriptor.writable = true;
28 Object.defineProperty(target, descriptor.key, descriptor);
29 }
30}
31
32function _createClass(Constructor, protoProps, staticProps) {
33 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
34 if (staticProps) _defineProperties(Constructor, staticProps);
35 return Constructor;
36}
37
38function _objectWithoutPropertiesLoose(source, excluded) {
39 if (source == null) return {};
40 var target = {};
41 var sourceKeys = Object.keys(source);
42 var key, i;
43
44 for (i = 0; i < sourceKeys.length; i++) {
45 key = sourceKeys[i];
46 if (excluded.indexOf(key) >= 0) continue;
47 target[key] = source[key];
48 }
49
50 return target;
51}
52
53var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
54var _assign = ReactInternals.assign;
55
56var FunctionComponent = 0;
57var ClassComponent = 1;
58var IndeterminateComponent = 2; // Before we know whether it is function or class
59
60var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
61
62var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
63
64var HostComponent = 5;
65var HostText = 6;
66var Fragment = 7;
67var Mode = 8;
68var ContextConsumer = 9;
69var ContextProvider = 10;
70var ForwardRef = 11;
71var Profiler = 12;
72var SuspenseComponent = 13;
73var MemoComponent = 14;
74var SimpleMemoComponent = 15;
75var LazyComponent = 16;
76var IncompleteClassComponent = 17;
77var DehydratedFragment = 18;
78var SuspenseListComponent = 19;
79var FundamentalComponent = 20;
80var ScopeComponent = 21;
81
82/**
83 * Use invariant() to assert state which your program assumes to be true.
84 *
85 * Provide sprintf-style format (only %s is supported) and arguments
86 * to provide information about what broke and what you were
87 * expecting.
88 *
89 * The invariant message will be stripped in production, but the invariant
90 * will remain to ensure logic does not differ in production.
91 */
92
93/**
94 * Similar to invariant but only logs a warning if the condition is not met.
95 * This can be used to log issues in development environments in critical
96 * paths. Removing the logging code for production environments will keep the
97 * same logic and follow the same code paths.
98 */
99var warningWithoutStack = function () {};
100
101{
102 warningWithoutStack = function (condition, format) {
103 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
104 args[_key - 2] = arguments[_key];
105 }
106
107 if (format === undefined) {
108 throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
109 }
110
111 if (args.length > 8) {
112 // Check before the condition to catch violations early.
113 throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
114 }
115
116 if (condition) {
117 return;
118 }
119
120 if (typeof console !== 'undefined') {
121 var argsWithFormat = args.map(function (item) {
122 return '' + item;
123 });
124 argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
125 // breaks IE9: https://github.com/facebook/react/issues/13610
126
127 Function.prototype.apply.call(console.error, console, argsWithFormat);
128 }
129
130 try {
131 // --- Welcome to debugging React ---
132 // This error was thrown as a convenience so that you can use this stack
133 // to find the callsite that caused this warning to fire.
134 var argIndex = 0;
135 var message = 'Warning: ' + format.replace(/%s/g, function () {
136 return args[argIndex++];
137 });
138 throw new Error(message);
139 } catch (x) {}
140 };
141}
142
143var warningWithoutStack$1 = warningWithoutStack;
144
145/**
146 * `ReactInstanceMap` maintains a mapping from a public facing stateful
147 * instance (key) and the internal representation (value). This allows public
148 * methods to accept the user facing instance as an argument and map them back
149 * to internal methods.
150 *
151 * Note that this module is currently shared and assumed to be stateless.
152 * If this becomes an actual Map, that will break.
153 */
154
155/**
156 * This API should be called `delete` but we'd have to make sure to always
157 * transform these to strings for IE support. When this transform is fully
158 * supported we can rename it.
159 */
160
161function get(key) {
162 return key._reactInternalFiber;
163}
164
165function set$1(key, value) {
166 key._reactInternalFiber = value;
167}
168
169var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
170// Current owner and dispatcher used to share the same ref,
171// but PR #14548 split them out to better support the react-debug-tools package.
172
173if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
174 ReactSharedInternals.ReactCurrentDispatcher = {
175 current: null
176 };
177}
178
179if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
180 ReactSharedInternals.ReactCurrentBatchConfig = {
181 suspense: null
182 };
183}
184
185// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
186// nor polyfill, then a plain number is used for performance.
187var hasSymbol = typeof Symbol === 'function' && Symbol.for;
188var REACT_ELEMENT_TYPE$1 = hasSymbol ? Symbol.for('react.element') : 0xeac7;
189var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
190var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
191var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
192var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
193var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
194var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
195// (unstable) APIs that have been removed. Can we remove the symbols?
196
197
198var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
199var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
200var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
201var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
202var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
203var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
204var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
205var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
206var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
207var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
208var FAUX_ITERATOR_SYMBOL = '@@iterator';
209function getIteratorFn(maybeIterable) {
210 if (maybeIterable === null || typeof maybeIterable !== 'object') {
211 return null;
212 }
213
214 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
215
216 if (typeof maybeIterator === 'function') {
217 return maybeIterator;
218 }
219
220 return null;
221}
222
223/**
224 * Similar to invariant but only logs a warning if the condition is not met.
225 * This can be used to log issues in development environments in critical
226 * paths. Removing the logging code for production environments will keep the
227 * same logic and follow the same code paths.
228 */
229
230var warning = warningWithoutStack$1;
231
232{
233 warning = function (condition, format) {
234 if (condition) {
235 return;
236 }
237
238 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
239 var stack = ReactDebugCurrentFrame.getStackAddendum(); // eslint-disable-next-line react-internal/warning-and-invariant-args
240
241 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
242 args[_key - 2] = arguments[_key];
243 }
244
245 warningWithoutStack$1.apply(void 0, [false, format + '%s'].concat(args, [stack]));
246 };
247}
248
249var warning$1 = warning;
250
251var Uninitialized = -1;
252var Pending = 0;
253var Resolved = 1;
254var Rejected = 2;
255function refineResolvedLazyComponent(lazyComponent) {
256 return lazyComponent._status === Resolved ? lazyComponent._result : null;
257}
258function initializeLazyComponentType(lazyComponent) {
259 if (lazyComponent._status === Uninitialized) {
260 lazyComponent._status = Pending;
261 var ctor = lazyComponent._ctor;
262 var thenable = ctor();
263 lazyComponent._result = thenable;
264 thenable.then(function (moduleObject) {
265 if (lazyComponent._status === Pending) {
266 var defaultExport = moduleObject.default;
267
268 {
269 if (defaultExport === undefined) {
270 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);
271 }
272 }
273
274 lazyComponent._status = Resolved;
275 lazyComponent._result = defaultExport;
276 }
277 }, function (error) {
278 if (lazyComponent._status === Pending) {
279 lazyComponent._status = Rejected;
280 lazyComponent._result = error;
281 }
282 });
283 }
284}
285
286function getWrappedName(outerType, innerType, wrapperName) {
287 var functionName = innerType.displayName || innerType.name || '';
288 return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
289}
290
291function getComponentName(type) {
292 if (type == null) {
293 // Host root, text node or just invalid type.
294 return null;
295 }
296
297 {
298 if (typeof type.tag === 'number') {
299 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
300 }
301 }
302
303 if (typeof type === 'function') {
304 return type.displayName || type.name || null;
305 }
306
307 if (typeof type === 'string') {
308 return type;
309 }
310
311 switch (type) {
312 case REACT_FRAGMENT_TYPE:
313 return 'Fragment';
314
315 case REACT_PORTAL_TYPE:
316 return 'Portal';
317
318 case REACT_PROFILER_TYPE:
319 return "Profiler";
320
321 case REACT_STRICT_MODE_TYPE:
322 return 'StrictMode';
323
324 case REACT_SUSPENSE_TYPE:
325 return 'Suspense';
326
327 case REACT_SUSPENSE_LIST_TYPE:
328 return 'SuspenseList';
329 }
330
331 if (typeof type === 'object') {
332 switch (type.$$typeof) {
333 case REACT_CONTEXT_TYPE:
334 return 'Context.Consumer';
335
336 case REACT_PROVIDER_TYPE:
337 return 'Context.Provider';
338
339 case REACT_FORWARD_REF_TYPE:
340 return getWrappedName(type, type.render, 'ForwardRef');
341
342 case REACT_MEMO_TYPE:
343 return getComponentName(type.type);
344
345 case REACT_LAZY_TYPE:
346 {
347 var thenable = type;
348 var resolvedThenable = refineResolvedLazyComponent(thenable);
349
350 if (resolvedThenable) {
351 return getComponentName(resolvedThenable);
352 }
353
354 break;
355 }
356 }
357 }
358
359 return null;
360}
361
362// Don't change these two values. They're used by React Dev Tools.
363var NoEffect =
364/* */
3650;
366var PerformedWork =
367/* */
3681; // You can change the rest (and add more).
369
370var Placement =
371/* */
3722;
373var Update =
374/* */
3754;
376var PlacementAndUpdate =
377/* */
3786;
379var Deletion =
380/* */
3818;
382var ContentReset =
383/* */
38416;
385var Callback =
386/* */
38732;
388var DidCapture =
389/* */
39064;
391var Ref =
392/* */
393128;
394var Snapshot =
395/* */
396256;
397var Passive =
398/* */
399512;
400var Hydrating =
401/* */
4021024;
403var HydratingAndUpdate =
404/* */
4051028; // Passive & Update & Callback & Ref & Snapshot
406
407var LifecycleEffectMask =
408/* */
409932; // Union of all host effects
410
411var HostEffectMask =
412/* */
4132047;
414var Incomplete =
415/* */
4162048;
417var ShouldCapture =
418/* */
4194096;
420
421var debugRenderPhaseSideEffectsForStrictMode = false;
422var enableUserTimingAPI = true;
423var warnAboutDeprecatedLifecycles = true;
424var replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
425var enableProfilerTimer = true;
426var enableSchedulerTracing = true;
427var enableSuspenseServerRenderer = false;
428
429
430
431
432
433
434var enableFlareAPI = false;
435var enableFundamentalAPI = false;
436var enableScopeAPI = false;
437
438var warnAboutUnmockedScheduler = false;
439var flushSuspenseFallbacksInTests = true;
440var enableSuspenseCallback = false;
441var warnAboutDefaultPropsOnFunctionComponents = false;
442var warnAboutStringRefs = false;
443var disableLegacyContext = false;
444var disableSchedulerTimeoutBasedOnReactExpirationTime = false;
445
446 // Only used in www builds.
447
448 // Flow magic to verify the exports of this file match the original version.
449
450var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
451function getNearestMountedFiber(fiber) {
452 var node = fiber;
453 var nearestMounted = fiber;
454
455 if (!fiber.alternate) {
456 // If there is no alternate, this might be a new tree that isn't inserted
457 // yet. If it is, then it will have a pending insertion effect on it.
458 var nextNode = node;
459
460 do {
461 node = nextNode;
462
463 if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
464 // This is an insertion or in-progress hydration. The nearest possible
465 // mounted fiber is the parent but we need to continue to figure out
466 // if that one is still mounted.
467 nearestMounted = node.return;
468 }
469
470 nextNode = node.return;
471 } while (nextNode);
472 } else {
473 while (node.return) {
474 node = node.return;
475 }
476 }
477
478 if (node.tag === HostRoot) {
479 // TODO: Check if this was a nested HostRoot when used with
480 // renderContainerIntoSubtree.
481 return nearestMounted;
482 } // If we didn't hit the root, that means that we're in an disconnected tree
483 // that has been unmounted.
484
485
486 return null;
487}
488
489
490function isFiberMounted(fiber) {
491 return getNearestMountedFiber(fiber) === fiber;
492}
493function isMounted(component) {
494 {
495 var owner = ReactCurrentOwner.current;
496
497 if (owner !== null && owner.tag === ClassComponent) {
498 var ownerFiber = owner;
499 var instance = ownerFiber.stateNode;
500 !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;
501 instance._warnedAboutRefsInRender = true;
502 }
503 }
504
505 var fiber = get(component);
506
507 if (!fiber) {
508 return false;
509 }
510
511 return getNearestMountedFiber(fiber) === fiber;
512}
513
514function assertIsMounted(fiber) {
515 if (!(getNearestMountedFiber(fiber) === fiber)) {
516 {
517 throw Error("Unable to find node on an unmounted component.");
518 }
519 }
520}
521
522function findCurrentFiberUsingSlowPath(fiber) {
523 var alternate = fiber.alternate;
524
525 if (!alternate) {
526 // If there is no alternate, then we only need to check if it is mounted.
527 var nearestMounted = getNearestMountedFiber(fiber);
528
529 if (!(nearestMounted !== null)) {
530 {
531 throw Error("Unable to find node on an unmounted component.");
532 }
533 }
534
535 if (nearestMounted !== fiber) {
536 return null;
537 }
538
539 return fiber;
540 } // If we have two possible branches, we'll walk backwards up to the root
541 // to see what path the root points to. On the way we may hit one of the
542 // special cases and we'll deal with them.
543
544
545 var a = fiber;
546 var b = alternate;
547
548 while (true) {
549 var parentA = a.return;
550
551 if (parentA === null) {
552 // We're at the root.
553 break;
554 }
555
556 var parentB = parentA.alternate;
557
558 if (parentB === null) {
559 // There is no alternate. This is an unusual case. Currently, it only
560 // happens when a Suspense component is hidden. An extra fragment fiber
561 // is inserted in between the Suspense fiber and its children. Skip
562 // over this extra fragment fiber and proceed to the next parent.
563 var nextParent = parentA.return;
564
565 if (nextParent !== null) {
566 a = b = nextParent;
567 continue;
568 } // If there's no parent, we're at the root.
569
570
571 break;
572 } // If both copies of the parent fiber point to the same child, we can
573 // assume that the child is current. This happens when we bailout on low
574 // priority: the bailed out fiber's child reuses the current child.
575
576
577 if (parentA.child === parentB.child) {
578 var child = parentA.child;
579
580 while (child) {
581 if (child === a) {
582 // We've determined that A is the current branch.
583 assertIsMounted(parentA);
584 return fiber;
585 }
586
587 if (child === b) {
588 // We've determined that B is the current branch.
589 assertIsMounted(parentA);
590 return alternate;
591 }
592
593 child = child.sibling;
594 } // We should never have an alternate for any mounting node. So the only
595 // way this could possibly happen is if this was unmounted, if at all.
596
597
598 {
599 {
600 throw Error("Unable to find node on an unmounted component.");
601 }
602 }
603 }
604
605 if (a.return !== b.return) {
606 // The return pointer of A and the return pointer of B point to different
607 // fibers. We assume that return pointers never criss-cross, so A must
608 // belong to the child set of A.return, and B must belong to the child
609 // set of B.return.
610 a = parentA;
611 b = parentB;
612 } else {
613 // The return pointers point to the same fiber. We'll have to use the
614 // default, slow path: scan the child sets of each parent alternate to see
615 // which child belongs to which set.
616 //
617 // Search parent A's child set
618 var didFindChild = false;
619 var _child = parentA.child;
620
621 while (_child) {
622 if (_child === a) {
623 didFindChild = true;
624 a = parentA;
625 b = parentB;
626 break;
627 }
628
629 if (_child === b) {
630 didFindChild = true;
631 b = parentA;
632 a = parentB;
633 break;
634 }
635
636 _child = _child.sibling;
637 }
638
639 if (!didFindChild) {
640 // Search parent B's child set
641 _child = parentB.child;
642
643 while (_child) {
644 if (_child === a) {
645 didFindChild = true;
646 a = parentB;
647 b = parentA;
648 break;
649 }
650
651 if (_child === b) {
652 didFindChild = true;
653 b = parentB;
654 a = parentA;
655 break;
656 }
657
658 _child = _child.sibling;
659 }
660
661 if (!didFindChild) {
662 {
663 throw Error("Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue.");
664 }
665 }
666 }
667 }
668
669 if (!(a.alternate === b)) {
670 {
671 throw Error("Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue.");
672 }
673 }
674 } // If the root is not a host container, we're in a disconnected tree. I.e.
675 // unmounted.
676
677
678 if (!(a.tag === HostRoot)) {
679 {
680 throw Error("Unable to find node on an unmounted component.");
681 }
682 }
683
684 if (a.stateNode.current === a) {
685 // We've determined that A is the current branch.
686 return fiber;
687 } // Otherwise B has to be current branch.
688
689
690 return alternate;
691}
692function findCurrentHostFiber(parent) {
693 var currentParent = findCurrentFiberUsingSlowPath(parent);
694
695 if (!currentParent) {
696 return null;
697 } // Next we'll drill down this component to find the first HostComponent/Text.
698
699
700 var node = currentParent;
701
702 while (true) {
703 if (node.tag === HostComponent || node.tag === HostText) {
704 return node;
705 } else if (node.child) {
706 node.child.return = node;
707 node = node.child;
708 continue;
709 }
710
711 if (node === currentParent) {
712 return null;
713 }
714
715 while (!node.sibling) {
716 if (!node.return || node.return === currentParent) {
717 return null;
718 }
719
720 node = node.return;
721 }
722
723 node.sibling.return = node.return;
724 node = node.sibling;
725 } // Flow needs the return null here, but ESLint complains about it.
726 // eslint-disable-next-line no-unreachable
727
728
729 return null;
730}
731
732// can re-export everything from this module.
733
734function shim() {
735 {
736 {
737 throw Error("The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue.");
738 }
739 }
740} // Persistence (when unsupported)
741
742
743var supportsPersistence = false;
744var cloneInstance = shim;
745var cloneFundamentalInstance = shim;
746var createContainerChildSet = shim;
747var appendChildToContainerChildSet = shim;
748var finalizeContainerChildren = shim;
749var replaceContainerChildren = shim;
750var cloneHiddenInstance = shim;
751var cloneHiddenTextInstance = shim;
752
753// can re-export everything from this module.
754
755function shim$1() {
756 {
757 {
758 throw Error("The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue.");
759 }
760 }
761} // Hydration (when unsupported)
762
763
764var supportsHydration = false;
765var canHydrateInstance = shim$1;
766var canHydrateTextInstance = shim$1;
767var canHydrateSuspenseInstance = shim$1;
768var isSuspenseInstancePending = shim$1;
769var isSuspenseInstanceFallback = shim$1;
770var registerSuspenseInstanceRetry = shim$1;
771var getNextHydratableSibling = shim$1;
772var getFirstHydratableChild = shim$1;
773var hydrateInstance = shim$1;
774var hydrateTextInstance = shim$1;
775var hydrateSuspenseInstance = shim$1;
776var getNextHydratableInstanceAfterSuspenseInstance = shim$1;
777var commitHydratedContainer = shim$1;
778var commitHydratedSuspenseInstance = shim$1;
779var clearSuspenseBoundary = shim$1;
780var clearSuspenseBoundaryFromContainer = shim$1;
781var didNotMatchHydratedContainerTextInstance = shim$1;
782var didNotMatchHydratedTextInstance = shim$1;
783var didNotHydrateContainerInstance = shim$1;
784var didNotHydrateInstance = shim$1;
785var didNotFindHydratableContainerInstance = shim$1;
786var didNotFindHydratableContainerTextInstance = shim$1;
787var didNotFindHydratableContainerSuspenseInstance = shim$1;
788var didNotFindHydratableInstance = shim$1;
789var didNotFindHydratableTextInstance = shim$1;
790var didNotFindHydratableSuspenseInstance = shim$1;
791
792var EVENT_COMPONENT_CONTEXT = {};
793var NO_CONTEXT = {};
794var UPDATE_SIGNAL = {};
795var nodeToInstanceMap = new WeakMap();
796
797{
798 Object.freeze(NO_CONTEXT);
799 Object.freeze(UPDATE_SIGNAL);
800}
801
802function getPublicInstance(inst) {
803 switch (inst.tag) {
804 case 'INSTANCE':
805 var createNodeMock = inst.rootContainerInstance.createNodeMock;
806 var mockNode = createNodeMock({
807 type: inst.type,
808 props: inst.props
809 });
810
811 if (typeof mockNode === 'object' && mockNode !== null) {
812 nodeToInstanceMap.set(mockNode, inst);
813 }
814
815 return mockNode;
816
817 default:
818 return inst;
819 }
820}
821function appendChild(parentInstance, child) {
822 {
823 !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;
824 }
825
826 var index = parentInstance.children.indexOf(child);
827
828 if (index !== -1) {
829 parentInstance.children.splice(index, 1);
830 }
831
832 parentInstance.children.push(child);
833}
834function insertBefore(parentInstance, child, beforeChild) {
835 var index = parentInstance.children.indexOf(child);
836
837 if (index !== -1) {
838 parentInstance.children.splice(index, 1);
839 }
840
841 var beforeIndex = parentInstance.children.indexOf(beforeChild);
842 parentInstance.children.splice(beforeIndex, 0, child);
843}
844function removeChild(parentInstance, child) {
845 var index = parentInstance.children.indexOf(child);
846 parentInstance.children.splice(index, 1);
847}
848function getRootHostContext(rootContainerInstance) {
849 return NO_CONTEXT;
850}
851function getChildHostContext(parentHostContext, type, rootContainerInstance) {
852 return NO_CONTEXT;
853}
854function prepareForCommit(containerInfo) {// noop
855}
856function resetAfterCommit(containerInfo) {// noop
857}
858function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
859 var propsToUse = props;
860
861 if (enableFlareAPI) {
862 if (props.listeners != null) {
863 // We want to remove the "listeners" prop
864 // as we don't want it in the test renderer's
865 // instance props.
866 var listeners = props.listeners,
867 otherProps = _objectWithoutPropertiesLoose(props, ["listeners"]); // eslint-disable-line
868
869
870 propsToUse = otherProps;
871 }
872 }
873
874 return {
875 type: type,
876 props: propsToUse,
877 isHidden: false,
878 children: [],
879 internalInstanceHandle: internalInstanceHandle,
880 rootContainerInstance: rootContainerInstance,
881 tag: 'INSTANCE'
882 };
883}
884function appendInitialChild(parentInstance, child) {
885 var index = parentInstance.children.indexOf(child);
886
887 if (index !== -1) {
888 parentInstance.children.splice(index, 1);
889 }
890
891 parentInstance.children.push(child);
892}
893function finalizeInitialChildren(testElement, type, props, rootContainerInstance, hostContext) {
894 return false;
895}
896function prepareUpdate(testElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
897 return UPDATE_SIGNAL;
898}
899function shouldSetTextContent(type, props) {
900 return false;
901}
902function shouldDeprioritizeSubtree(type, props) {
903 return false;
904}
905function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
906 if (true && enableFlareAPI) {
907 !(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;
908 }
909
910 return {
911 text: text,
912 isHidden: false,
913 tag: 'TEXT'
914 };
915}
916var isPrimaryRenderer = false;
917var warnsIfNotActing = true;
918var scheduleTimeout = setTimeout;
919var cancelTimeout = clearTimeout;
920var noTimeout = -1; // -------------------
921// Mutation
922// -------------------
923
924var supportsMutation = true;
925function commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
926 instance.type = type;
927 instance.props = newProps;
928}
929
930function commitTextUpdate(textInstance, oldText, newText) {
931 textInstance.text = newText;
932}
933function resetTextContent(testElement) {// noop
934}
935var appendChildToContainer = appendChild;
936var insertInContainerBefore = insertBefore;
937var removeChildFromContainer = removeChild;
938function hideInstance(instance) {
939 instance.isHidden = true;
940}
941function hideTextInstance(textInstance) {
942 textInstance.isHidden = true;
943}
944function unhideInstance(instance, props) {
945 instance.isHidden = false;
946}
947function unhideTextInstance(textInstance, text) {
948 textInstance.isHidden = false;
949}
950
951
952function getFundamentalComponentInstance(fundamentalInstance) {
953 var impl = fundamentalInstance.impl,
954 props = fundamentalInstance.props,
955 state = fundamentalInstance.state;
956 return impl.getInstance(null, props, state);
957}
958function mountFundamentalComponent(fundamentalInstance) {
959 var impl = fundamentalInstance.impl,
960 instance = fundamentalInstance.instance,
961 props = fundamentalInstance.props,
962 state = fundamentalInstance.state;
963 var onMount = impl.onMount;
964
965 if (onMount !== undefined) {
966 onMount(null, instance, props, state);
967 }
968}
969function shouldUpdateFundamentalComponent(fundamentalInstance) {
970 var impl = fundamentalInstance.impl,
971 prevProps = fundamentalInstance.prevProps,
972 props = fundamentalInstance.props,
973 state = fundamentalInstance.state;
974 var shouldUpdate = impl.shouldUpdate;
975
976 if (shouldUpdate !== undefined) {
977 return shouldUpdate(null, prevProps, props, state);
978 }
979
980 return true;
981}
982function updateFundamentalComponent(fundamentalInstance) {
983 var impl = fundamentalInstance.impl,
984 instance = fundamentalInstance.instance,
985 prevProps = fundamentalInstance.prevProps,
986 props = fundamentalInstance.props,
987 state = fundamentalInstance.state;
988 var onUpdate = impl.onUpdate;
989
990 if (onUpdate !== undefined) {
991 onUpdate(null, instance, prevProps, props, state);
992 }
993}
994function unmountFundamentalComponent(fundamentalInstance) {
995 var impl = fundamentalInstance.impl,
996 instance = fundamentalInstance.instance,
997 props = fundamentalInstance.props,
998 state = fundamentalInstance.state;
999 var onUnmount = impl.onUnmount;
1000
1001 if (onUnmount !== undefined) {
1002 onUnmount(null, instance, props, state);
1003 }
1004}
1005function getInstanceFromNode(mockNode) {
1006 var instance = nodeToInstanceMap.get(mockNode);
1007
1008 if (instance !== undefined) {
1009 return instance.internalInstanceHandle;
1010 }
1011
1012 return null;
1013}
1014
1015/**
1016 * Copyright (c) 2013-present, Facebook, Inc.
1017 *
1018 * This source code is licensed under the MIT license found in the
1019 * LICENSE file in the root directory of this source tree.
1020 */
1021
1022
1023
1024var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
1025
1026var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
1027
1028/**
1029 * Copyright (c) 2013-present, Facebook, Inc.
1030 *
1031 * This source code is licensed under the MIT license found in the
1032 * LICENSE file in the root directory of this source tree.
1033 */
1034
1035
1036
1037var printWarning = function() {};
1038
1039{
1040 var ReactPropTypesSecret = ReactPropTypesSecret_1;
1041 var loggedTypeFailures = {};
1042 var has$1 = Function.call.bind(Object.prototype.hasOwnProperty);
1043
1044 printWarning = function(text) {
1045 var message = 'Warning: ' + text;
1046 if (typeof console !== 'undefined') {
1047 console.error(message);
1048 }
1049 try {
1050 // --- Welcome to debugging React ---
1051 // This error was thrown as a convenience so that you can use this stack
1052 // to find the callsite that caused this warning to fire.
1053 throw new Error(message);
1054 } catch (x) {}
1055 };
1056}
1057
1058/**
1059 * Assert that the values match with the type specs.
1060 * Error messages are memorized and will only be shown once.
1061 *
1062 * @param {object} typeSpecs Map of name to a ReactPropType
1063 * @param {object} values Runtime values that need to be type-checked
1064 * @param {string} location e.g. "prop", "context", "child context"
1065 * @param {string} componentName Name of the component for error messages.
1066 * @param {?Function} getStack Returns the component stack.
1067 * @private
1068 */
1069function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
1070 {
1071 for (var typeSpecName in typeSpecs) {
1072 if (has$1(typeSpecs, typeSpecName)) {
1073 var error;
1074 // Prop type validation may throw. In case they do, we don't want to
1075 // fail the render phase where it didn't fail before. So we log it.
1076 // After these have been cleaned up, we'll let them throw.
1077 try {
1078 // This is intentionally an invariant that gets caught. It's the same
1079 // behavior as without this statement except with a better message.
1080 if (typeof typeSpecs[typeSpecName] !== 'function') {
1081 var err = Error(
1082 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
1083 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
1084 );
1085 err.name = 'Invariant Violation';
1086 throw err;
1087 }
1088 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
1089 } catch (ex) {
1090 error = ex;
1091 }
1092 if (error && !(error instanceof Error)) {
1093 printWarning(
1094 (componentName || 'React class') + ': type specification of ' +
1095 location + ' `' + typeSpecName + '` is invalid; the type checker ' +
1096 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
1097 'You may have forgotten to pass an argument to the type checker ' +
1098 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
1099 'shape all require an argument).'
1100 );
1101 }
1102 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
1103 // Only monitor this failure once because there tends to be a lot of the
1104 // same error.
1105 loggedTypeFailures[error.message] = true;
1106
1107 var stack = getStack ? getStack() : '';
1108
1109 printWarning(
1110 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
1111 );
1112 }
1113 }
1114 }
1115 }
1116}
1117
1118/**
1119 * Resets warning cache when testing.
1120 *
1121 * @private
1122 */
1123checkPropTypes.resetWarningCache = function() {
1124 {
1125 loggedTypeFailures = {};
1126 }
1127};
1128
1129var checkPropTypes_1 = checkPropTypes;
1130
1131var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
1132var describeComponentFrame = function (name, source, ownerName) {
1133 var sourceInfo = '';
1134
1135 if (source) {
1136 var path = source.fileName;
1137 var fileName = path.replace(BEFORE_SLASH_RE, '');
1138
1139 {
1140 // In DEV, include code for a common special case:
1141 // prefer "folder/index.js" instead of just "index.js".
1142 if (/^index\./.test(fileName)) {
1143 var match = path.match(BEFORE_SLASH_RE);
1144
1145 if (match) {
1146 var pathBeforeSlash = match[1];
1147
1148 if (pathBeforeSlash) {
1149 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
1150 fileName = folderName + '/' + fileName;
1151 }
1152 }
1153 }
1154 }
1155
1156 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
1157 } else if (ownerName) {
1158 sourceInfo = ' (created by ' + ownerName + ')';
1159 }
1160
1161 return '\n in ' + (name || 'Unknown') + sourceInfo;
1162};
1163
1164var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1165
1166function describeFiber(fiber) {
1167 switch (fiber.tag) {
1168 case HostRoot:
1169 case HostPortal:
1170 case HostText:
1171 case Fragment:
1172 case ContextProvider:
1173 case ContextConsumer:
1174 return '';
1175
1176 default:
1177 var owner = fiber._debugOwner;
1178 var source = fiber._debugSource;
1179 var name = getComponentName(fiber.type);
1180 var ownerName = null;
1181
1182 if (owner) {
1183 ownerName = getComponentName(owner.type);
1184 }
1185
1186 return describeComponentFrame(name, source, ownerName);
1187 }
1188}
1189
1190function getStackByFiberInDevAndProd(workInProgress) {
1191 var info = '';
1192 var node = workInProgress;
1193
1194 do {
1195 info += describeFiber(node);
1196 node = node.return;
1197 } while (node);
1198
1199 return info;
1200}
1201var current = null;
1202var phase = null;
1203function getCurrentFiberOwnerNameInDevOrNull() {
1204 {
1205 if (current === null) {
1206 return null;
1207 }
1208
1209 var owner = current._debugOwner;
1210
1211 if (owner !== null && typeof owner !== 'undefined') {
1212 return getComponentName(owner.type);
1213 }
1214 }
1215
1216 return null;
1217}
1218function getCurrentFiberStackInDev() {
1219 {
1220 if (current === null) {
1221 return '';
1222 } // Safe because if current fiber exists, we are reconciling,
1223 // and it is guaranteed to be the work-in-progress version.
1224
1225
1226 return getStackByFiberInDevAndProd(current);
1227 }
1228
1229 return '';
1230}
1231function resetCurrentFiber() {
1232 {
1233 ReactDebugCurrentFrame.getCurrentStack = null;
1234 current = null;
1235 phase = null;
1236 }
1237}
1238function setCurrentFiber(fiber) {
1239 {
1240 ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
1241 current = fiber;
1242 phase = null;
1243 }
1244}
1245function setCurrentPhase(lifeCyclePhase) {
1246 {
1247 phase = lifeCyclePhase;
1248 }
1249}
1250
1251// Prefix measurements so that it's possible to filter them.
1252// Longer prefixes are hard to read in DevTools.
1253var reactEmoji = "\u269B";
1254var warningEmoji = "\u26D4";
1255var 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.
1256// TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
1257
1258var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
1259// Reusing `currentFiber` would be confusing for this because user code fiber
1260// can change during commit phase too, but we don't need to unwind it (since
1261// lifecycles in the commit phase don't resemble a tree).
1262
1263var currentPhase = null;
1264var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
1265// so we will keep track of it, and include it in the report.
1266// Track commits caused by cascading updates.
1267
1268var isCommitting = false;
1269var hasScheduledUpdateInCurrentCommit = false;
1270var hasScheduledUpdateInCurrentPhase = false;
1271var commitCountInCurrentWorkLoop = 0;
1272var effectCountInCurrentCommit = 0;
1273// to avoid stretch the commit phase with measurement overhead.
1274
1275var labelsInCurrentCommit = new Set();
1276
1277var formatMarkName = function (markName) {
1278 return reactEmoji + " " + markName;
1279};
1280
1281var formatLabel = function (label, warning) {
1282 var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
1283 var suffix = warning ? " Warning: " + warning : '';
1284 return "" + prefix + label + suffix;
1285};
1286
1287var beginMark = function (markName) {
1288 performance.mark(formatMarkName(markName));
1289};
1290
1291var clearMark = function (markName) {
1292 performance.clearMarks(formatMarkName(markName));
1293};
1294
1295var endMark = function (label, markName, warning) {
1296 var formattedMarkName = formatMarkName(markName);
1297 var formattedLabel = formatLabel(label, warning);
1298
1299 try {
1300 performance.measure(formattedLabel, formattedMarkName);
1301 } catch (err) {} // If previous mark was missing for some reason, this will throw.
1302 // This could only happen if React crashed in an unexpected place earlier.
1303 // Don't pile on with more errors.
1304 // Clear marks immediately to avoid growing buffer.
1305
1306
1307 performance.clearMarks(formattedMarkName);
1308 performance.clearMeasures(formattedLabel);
1309};
1310
1311var getFiberMarkName = function (label, debugID) {
1312 return label + " (#" + debugID + ")";
1313};
1314
1315var getFiberLabel = function (componentName, isMounted, phase) {
1316 if (phase === null) {
1317 // These are composite component total time measurements.
1318 return componentName + " [" + (isMounted ? 'update' : 'mount') + "]";
1319 } else {
1320 // Composite component methods.
1321 return componentName + "." + phase;
1322 }
1323};
1324
1325var beginFiberMark = function (fiber, phase) {
1326 var componentName = getComponentName(fiber.type) || 'Unknown';
1327 var debugID = fiber._debugID;
1328 var isMounted = fiber.alternate !== null;
1329 var label = getFiberLabel(componentName, isMounted, phase);
1330
1331 if (isCommitting && labelsInCurrentCommit.has(label)) {
1332 // During the commit phase, we don't show duplicate labels because
1333 // there is a fixed overhead for every measurement, and we don't
1334 // want to stretch the commit phase beyond necessary.
1335 return false;
1336 }
1337
1338 labelsInCurrentCommit.add(label);
1339 var markName = getFiberMarkName(label, debugID);
1340 beginMark(markName);
1341 return true;
1342};
1343
1344var clearFiberMark = function (fiber, phase) {
1345 var componentName = getComponentName(fiber.type) || 'Unknown';
1346 var debugID = fiber._debugID;
1347 var isMounted = fiber.alternate !== null;
1348 var label = getFiberLabel(componentName, isMounted, phase);
1349 var markName = getFiberMarkName(label, debugID);
1350 clearMark(markName);
1351};
1352
1353var endFiberMark = function (fiber, phase, warning) {
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 endMark(label, markName, warning);
1360};
1361
1362var shouldIgnoreFiber = function (fiber) {
1363 // Host components should be skipped in the timeline.
1364 // We could check typeof fiber.type, but does this work with RN?
1365 switch (fiber.tag) {
1366 case HostRoot:
1367 case HostComponent:
1368 case HostText:
1369 case HostPortal:
1370 case Fragment:
1371 case ContextProvider:
1372 case ContextConsumer:
1373 case Mode:
1374 return true;
1375
1376 default:
1377 return false;
1378 }
1379};
1380
1381var clearPendingPhaseMeasurement = function () {
1382 if (currentPhase !== null && currentPhaseFiber !== null) {
1383 clearFiberMark(currentPhaseFiber, currentPhase);
1384 }
1385
1386 currentPhaseFiber = null;
1387 currentPhase = null;
1388 hasScheduledUpdateInCurrentPhase = false;
1389};
1390
1391var pauseTimers = function () {
1392 // Stops all currently active measurements so that they can be resumed
1393 // if we continue in a later deferred loop from the same unit of work.
1394 var fiber = currentFiber;
1395
1396 while (fiber) {
1397 if (fiber._debugIsCurrentlyTiming) {
1398 endFiberMark(fiber, null, null);
1399 }
1400
1401 fiber = fiber.return;
1402 }
1403};
1404
1405var resumeTimersRecursively = function (fiber) {
1406 if (fiber.return !== null) {
1407 resumeTimersRecursively(fiber.return);
1408 }
1409
1410 if (fiber._debugIsCurrentlyTiming) {
1411 beginFiberMark(fiber, null);
1412 }
1413};
1414
1415var resumeTimers = function () {
1416 // Resumes all measurements that were active during the last deferred loop.
1417 if (currentFiber !== null) {
1418 resumeTimersRecursively(currentFiber);
1419 }
1420};
1421
1422function recordEffect() {
1423 if (enableUserTimingAPI) {
1424 effectCountInCurrentCommit++;
1425 }
1426}
1427function recordScheduleUpdate() {
1428 if (enableUserTimingAPI) {
1429 if (isCommitting) {
1430 hasScheduledUpdateInCurrentCommit = true;
1431 }
1432
1433 if (currentPhase !== null && currentPhase !== 'componentWillMount' && currentPhase !== 'componentWillReceiveProps') {
1434 hasScheduledUpdateInCurrentPhase = true;
1435 }
1436 }
1437}
1438
1439
1440function startWorkTimer(fiber) {
1441 if (enableUserTimingAPI) {
1442 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1443 return;
1444 } // If we pause, this is the fiber to unwind from.
1445
1446
1447 currentFiber = fiber;
1448
1449 if (!beginFiberMark(fiber, null)) {
1450 return;
1451 }
1452
1453 fiber._debugIsCurrentlyTiming = true;
1454 }
1455}
1456function cancelWorkTimer(fiber) {
1457 if (enableUserTimingAPI) {
1458 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1459 return;
1460 } // Remember we shouldn't complete measurement for this fiber.
1461 // Otherwise flamechart will be deep even for small updates.
1462
1463
1464 fiber._debugIsCurrentlyTiming = false;
1465 clearFiberMark(fiber, null);
1466 }
1467}
1468function stopWorkTimer(fiber) {
1469 if (enableUserTimingAPI) {
1470 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1471 return;
1472 } // If we pause, its parent is the fiber to unwind from.
1473
1474
1475 currentFiber = fiber.return;
1476
1477 if (!fiber._debugIsCurrentlyTiming) {
1478 return;
1479 }
1480
1481 fiber._debugIsCurrentlyTiming = false;
1482 endFiberMark(fiber, null, null);
1483 }
1484}
1485function stopFailedWorkTimer(fiber) {
1486 if (enableUserTimingAPI) {
1487 if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
1488 return;
1489 } // If we pause, its parent is the fiber to unwind from.
1490
1491
1492 currentFiber = fiber.return;
1493
1494 if (!fiber._debugIsCurrentlyTiming) {
1495 return;
1496 }
1497
1498 fiber._debugIsCurrentlyTiming = false;
1499 var warning = fiber.tag === SuspenseComponent ? 'Rendering was suspended' : 'An error was thrown inside this error boundary';
1500 endFiberMark(fiber, null, warning);
1501 }
1502}
1503function startPhaseTimer(fiber, phase) {
1504 if (enableUserTimingAPI) {
1505 if (!supportsUserTiming) {
1506 return;
1507 }
1508
1509 clearPendingPhaseMeasurement();
1510
1511 if (!beginFiberMark(fiber, phase)) {
1512 return;
1513 }
1514
1515 currentPhaseFiber = fiber;
1516 currentPhase = phase;
1517 }
1518}
1519function stopPhaseTimer() {
1520 if (enableUserTimingAPI) {
1521 if (!supportsUserTiming) {
1522 return;
1523 }
1524
1525 if (currentPhase !== null && currentPhaseFiber !== null) {
1526 var warning = hasScheduledUpdateInCurrentPhase ? 'Scheduled a cascading update' : null;
1527 endFiberMark(currentPhaseFiber, currentPhase, warning);
1528 }
1529
1530 currentPhase = null;
1531 currentPhaseFiber = null;
1532 }
1533}
1534function startWorkLoopTimer(nextUnitOfWork) {
1535 if (enableUserTimingAPI) {
1536 currentFiber = nextUnitOfWork;
1537
1538 if (!supportsUserTiming) {
1539 return;
1540 }
1541
1542 commitCountInCurrentWorkLoop = 0; // This is top level call.
1543 // Any other measurements are performed within.
1544
1545 beginMark('(React Tree Reconciliation)'); // Resume any measurements that were in progress during the last loop.
1546
1547 resumeTimers();
1548 }
1549}
1550function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
1551 if (enableUserTimingAPI) {
1552 if (!supportsUserTiming) {
1553 return;
1554 }
1555
1556 var warning = null;
1557
1558 if (interruptedBy !== null) {
1559 if (interruptedBy.tag === HostRoot) {
1560 warning = 'A top-level update interrupted the previous render';
1561 } else {
1562 var componentName = getComponentName(interruptedBy.type) || 'Unknown';
1563 warning = "An update to " + componentName + " interrupted the previous render";
1564 }
1565 } else if (commitCountInCurrentWorkLoop > 1) {
1566 warning = 'There were cascading updates';
1567 }
1568
1569 commitCountInCurrentWorkLoop = 0;
1570 var label = didCompleteRoot ? '(React Tree Reconciliation: Completed Root)' : '(React Tree Reconciliation: Yielded)'; // Pause any measurements until the next loop.
1571
1572 pauseTimers();
1573 endMark(label, '(React Tree Reconciliation)', warning);
1574 }
1575}
1576function startCommitTimer() {
1577 if (enableUserTimingAPI) {
1578 if (!supportsUserTiming) {
1579 return;
1580 }
1581
1582 isCommitting = true;
1583 hasScheduledUpdateInCurrentCommit = false;
1584 labelsInCurrentCommit.clear();
1585 beginMark('(Committing Changes)');
1586 }
1587}
1588function stopCommitTimer() {
1589 if (enableUserTimingAPI) {
1590 if (!supportsUserTiming) {
1591 return;
1592 }
1593
1594 var warning = null;
1595
1596 if (hasScheduledUpdateInCurrentCommit) {
1597 warning = 'Lifecycle hook scheduled a cascading update';
1598 } else if (commitCountInCurrentWorkLoop > 0) {
1599 warning = 'Caused by a cascading update in earlier commit';
1600 }
1601
1602 hasScheduledUpdateInCurrentCommit = false;
1603 commitCountInCurrentWorkLoop++;
1604 isCommitting = false;
1605 labelsInCurrentCommit.clear();
1606 endMark('(Committing Changes)', '(Committing Changes)', warning);
1607 }
1608}
1609function startCommitSnapshotEffectsTimer() {
1610 if (enableUserTimingAPI) {
1611 if (!supportsUserTiming) {
1612 return;
1613 }
1614
1615 effectCountInCurrentCommit = 0;
1616 beginMark('(Committing Snapshot Effects)');
1617 }
1618}
1619function stopCommitSnapshotEffectsTimer() {
1620 if (enableUserTimingAPI) {
1621 if (!supportsUserTiming) {
1622 return;
1623 }
1624
1625 var count = effectCountInCurrentCommit;
1626 effectCountInCurrentCommit = 0;
1627 endMark("(Committing Snapshot Effects: " + count + " Total)", '(Committing Snapshot Effects)', null);
1628 }
1629}
1630function startCommitHostEffectsTimer() {
1631 if (enableUserTimingAPI) {
1632 if (!supportsUserTiming) {
1633 return;
1634 }
1635
1636 effectCountInCurrentCommit = 0;
1637 beginMark('(Committing Host Effects)');
1638 }
1639}
1640function stopCommitHostEffectsTimer() {
1641 if (enableUserTimingAPI) {
1642 if (!supportsUserTiming) {
1643 return;
1644 }
1645
1646 var count = effectCountInCurrentCommit;
1647 effectCountInCurrentCommit = 0;
1648 endMark("(Committing Host Effects: " + count + " Total)", '(Committing Host Effects)', null);
1649 }
1650}
1651function startCommitLifeCyclesTimer() {
1652 if (enableUserTimingAPI) {
1653 if (!supportsUserTiming) {
1654 return;
1655 }
1656
1657 effectCountInCurrentCommit = 0;
1658 beginMark('(Calling Lifecycle Methods)');
1659 }
1660}
1661function stopCommitLifeCyclesTimer() {
1662 if (enableUserTimingAPI) {
1663 if (!supportsUserTiming) {
1664 return;
1665 }
1666
1667 var count = effectCountInCurrentCommit;
1668 effectCountInCurrentCommit = 0;
1669 endMark("(Calling Lifecycle Methods: " + count + " Total)", '(Calling Lifecycle Methods)', null);
1670 }
1671}
1672
1673var valueStack = [];
1674var fiberStack;
1675
1676{
1677 fiberStack = [];
1678}
1679
1680var index = -1;
1681
1682function createCursor(defaultValue) {
1683 return {
1684 current: defaultValue
1685 };
1686}
1687
1688function pop(cursor, fiber) {
1689 if (index < 0) {
1690 {
1691 warningWithoutStack$1(false, 'Unexpected pop.');
1692 }
1693
1694 return;
1695 }
1696
1697 {
1698 if (fiber !== fiberStack[index]) {
1699 warningWithoutStack$1(false, 'Unexpected Fiber popped.');
1700 }
1701 }
1702
1703 cursor.current = valueStack[index];
1704 valueStack[index] = null;
1705
1706 {
1707 fiberStack[index] = null;
1708 }
1709
1710 index--;
1711}
1712
1713function push(cursor, value, fiber) {
1714 index++;
1715 valueStack[index] = cursor.current;
1716
1717 {
1718 fiberStack[index] = fiber;
1719 }
1720
1721 cursor.current = value;
1722}
1723
1724var warnedAboutMissingGetChildContext;
1725
1726{
1727 warnedAboutMissingGetChildContext = {};
1728}
1729
1730var emptyContextObject = {};
1731
1732{
1733 Object.freeze(emptyContextObject);
1734} // A cursor to the current merged context object on the stack.
1735
1736
1737var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
1738
1739var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
1740// We use this to get access to the parent context after we have already
1741// pushed the next context provider, and now need to merge their contexts.
1742
1743var previousContext = emptyContextObject;
1744
1745function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
1746 if (disableLegacyContext) {
1747 return emptyContextObject;
1748 } else {
1749 if (didPushOwnContextIfProvider && isContextProvider(Component)) {
1750 // If the fiber is a context provider itself, when we read its context
1751 // we may have already pushed its own child context on the stack. A context
1752 // provider should not "see" its own child context. Therefore we read the
1753 // previous (parent) context instead for a context provider.
1754 return previousContext;
1755 }
1756
1757 return contextStackCursor.current;
1758 }
1759}
1760
1761function cacheContext(workInProgress, unmaskedContext, maskedContext) {
1762 if (disableLegacyContext) {
1763 return;
1764 } else {
1765 var instance = workInProgress.stateNode;
1766 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
1767 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
1768 }
1769}
1770
1771function getMaskedContext(workInProgress, unmaskedContext) {
1772 if (disableLegacyContext) {
1773 return emptyContextObject;
1774 } else {
1775 var type = workInProgress.type;
1776 var contextTypes = type.contextTypes;
1777
1778 if (!contextTypes) {
1779 return emptyContextObject;
1780 } // Avoid recreating masked context unless unmasked context has changed.
1781 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
1782 // This may trigger infinite loops if componentWillReceiveProps calls setState.
1783
1784
1785 var instance = workInProgress.stateNode;
1786
1787 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
1788 return instance.__reactInternalMemoizedMaskedChildContext;
1789 }
1790
1791 var context = {};
1792
1793 for (var key in contextTypes) {
1794 context[key] = unmaskedContext[key];
1795 }
1796
1797 {
1798 var name = getComponentName(type) || 'Unknown';
1799 checkPropTypes_1(contextTypes, context, 'context', name, getCurrentFiberStackInDev);
1800 } // Cache unmasked context so we can avoid recreating masked context unless necessary.
1801 // Context is created before the class component is instantiated so check for instance.
1802
1803
1804 if (instance) {
1805 cacheContext(workInProgress, unmaskedContext, context);
1806 }
1807
1808 return context;
1809 }
1810}
1811
1812function hasContextChanged() {
1813 if (disableLegacyContext) {
1814 return false;
1815 } else {
1816 return didPerformWorkStackCursor.current;
1817 }
1818}
1819
1820function isContextProvider(type) {
1821 if (disableLegacyContext) {
1822 return false;
1823 } else {
1824 var childContextTypes = type.childContextTypes;
1825 return childContextTypes !== null && childContextTypes !== undefined;
1826 }
1827}
1828
1829function popContext(fiber) {
1830 if (disableLegacyContext) {
1831 return;
1832 } else {
1833 pop(didPerformWorkStackCursor, fiber);
1834 pop(contextStackCursor, fiber);
1835 }
1836}
1837
1838function popTopLevelContextObject(fiber) {
1839 if (disableLegacyContext) {
1840 return;
1841 } else {
1842 pop(didPerformWorkStackCursor, fiber);
1843 pop(contextStackCursor, fiber);
1844 }
1845}
1846
1847function pushTopLevelContextObject(fiber, context, didChange) {
1848 if (disableLegacyContext) {
1849 return;
1850 } else {
1851 if (!(contextStackCursor.current === emptyContextObject)) {
1852 {
1853 throw Error("Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue.");
1854 }
1855 }
1856
1857 push(contextStackCursor, context, fiber);
1858 push(didPerformWorkStackCursor, didChange, fiber);
1859 }
1860}
1861
1862function processChildContext(fiber, type, parentContext) {
1863 if (disableLegacyContext) {
1864 return parentContext;
1865 } else {
1866 var instance = fiber.stateNode;
1867 var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
1868 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
1869
1870 if (typeof instance.getChildContext !== 'function') {
1871 {
1872 var componentName = getComponentName(type) || 'Unknown';
1873
1874 if (!warnedAboutMissingGetChildContext[componentName]) {
1875 warnedAboutMissingGetChildContext[componentName] = true;
1876 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);
1877 }
1878 }
1879
1880 return parentContext;
1881 }
1882
1883 var childContext;
1884
1885 {
1886 setCurrentPhase('getChildContext');
1887 }
1888
1889 startPhaseTimer(fiber, 'getChildContext');
1890 childContext = instance.getChildContext();
1891 stopPhaseTimer();
1892
1893 {
1894 setCurrentPhase(null);
1895 }
1896
1897 for (var contextKey in childContext) {
1898 if (!(contextKey in childContextTypes)) {
1899 {
1900 throw Error((getComponentName(type) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes.");
1901 }
1902 }
1903 }
1904
1905 {
1906 var name = getComponentName(type) || 'Unknown';
1907 checkPropTypes_1(childContextTypes, childContext, 'child context', name, // In practice, there is one case in which we won't get a stack. It's when
1908 // somebody calls unstable_renderSubtreeIntoContainer() and we process
1909 // context from the parent component instance. The stack will be missing
1910 // because it's outside of the reconciliation, and so the pointer has not
1911 // been set. This is rare and doesn't matter. We'll also remove that API.
1912 getCurrentFiberStackInDev);
1913 }
1914
1915 return _assign({}, parentContext, {}, childContext);
1916 }
1917}
1918
1919function pushContextProvider(workInProgress) {
1920 if (disableLegacyContext) {
1921 return false;
1922 } else {
1923 var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
1924 // If the instance does not exist yet, we will push null at first,
1925 // and replace it on the stack later when invalidating the context.
1926
1927 var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject; // Remember the parent context so we can merge with it later.
1928 // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
1929
1930 previousContext = contextStackCursor.current;
1931 push(contextStackCursor, memoizedMergedChildContext, workInProgress);
1932 push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
1933 return true;
1934 }
1935}
1936
1937function invalidateContextProvider(workInProgress, type, didChange) {
1938 if (disableLegacyContext) {
1939 return;
1940 } else {
1941 var instance = workInProgress.stateNode;
1942
1943 if (!instance) {
1944 {
1945 throw Error("Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue.");
1946 }
1947 }
1948
1949 if (didChange) {
1950 // Merge parent and own context.
1951 // Skip this if we're not updating due to sCU.
1952 // This avoids unnecessarily recomputing memoized values.
1953 var mergedContext = processChildContext(workInProgress, type, previousContext);
1954 instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
1955 // It is important to unwind the context in the reverse order.
1956
1957 pop(didPerformWorkStackCursor, workInProgress);
1958 pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
1959
1960 push(contextStackCursor, mergedContext, workInProgress);
1961 push(didPerformWorkStackCursor, didChange, workInProgress);
1962 } else {
1963 pop(didPerformWorkStackCursor, workInProgress);
1964 push(didPerformWorkStackCursor, didChange, workInProgress);
1965 }
1966 }
1967}
1968
1969function findCurrentUnmaskedContext(fiber) {
1970 if (disableLegacyContext) {
1971 return emptyContextObject;
1972 } else {
1973 // Currently this is only used with renderSubtreeIntoContainer; not sure if it
1974 // makes sense elsewhere
1975 if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
1976 {
1977 throw Error("Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue.");
1978 }
1979 }
1980
1981 var node = fiber;
1982
1983 do {
1984 switch (node.tag) {
1985 case HostRoot:
1986 return node.stateNode.context;
1987
1988 case ClassComponent:
1989 {
1990 var Component = node.type;
1991
1992 if (isContextProvider(Component)) {
1993 return node.stateNode.__reactInternalMemoizedMergedChildContext;
1994 }
1995
1996 break;
1997 }
1998 }
1999
2000 node = node.return;
2001 } while (node !== null);
2002
2003 {
2004 {
2005 throw Error("Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue.");
2006 }
2007 }
2008 }
2009}
2010
2011var LegacyRoot = 0;
2012var BlockingRoot = 1;
2013var ConcurrentRoot = 2;
2014
2015var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2016var _ReactInternals$Sched = ReactInternals$1.SchedulerTracing;
2017var __interactionsRef = _ReactInternals$Sched.__interactionsRef;
2018var __subscriberRef = _ReactInternals$Sched.__subscriberRef;
2019var unstable_clear = _ReactInternals$Sched.unstable_clear;
2020var unstable_getCurrent = _ReactInternals$Sched.unstable_getCurrent;
2021var unstable_getThreadID = _ReactInternals$Sched.unstable_getThreadID;
2022var unstable_subscribe = _ReactInternals$Sched.unstable_subscribe;
2023var unstable_trace = _ReactInternals$Sched.unstable_trace;
2024var unstable_unsubscribe = _ReactInternals$Sched.unstable_unsubscribe;
2025var unstable_wrap = _ReactInternals$Sched.unstable_wrap;
2026
2027// Intentionally not named imports because Rollup would use dynamic dispatch for
2028// CommonJS interop named imports.
2029var Scheduler_runWithPriority = Scheduler$1.unstable_runWithPriority;
2030var Scheduler_scheduleCallback = Scheduler$1.unstable_scheduleCallback;
2031var Scheduler_cancelCallback = Scheduler$1.unstable_cancelCallback;
2032var Scheduler_shouldYield = Scheduler$1.unstable_shouldYield;
2033var Scheduler_requestPaint = Scheduler$1.unstable_requestPaint;
2034var Scheduler_now = Scheduler$1.unstable_now;
2035var Scheduler_getCurrentPriorityLevel = Scheduler$1.unstable_getCurrentPriorityLevel;
2036var Scheduler_ImmediatePriority = Scheduler$1.unstable_ImmediatePriority;
2037var Scheduler_UserBlockingPriority = Scheduler$1.unstable_UserBlockingPriority;
2038var Scheduler_NormalPriority = Scheduler$1.unstable_NormalPriority;
2039var Scheduler_LowPriority = Scheduler$1.unstable_LowPriority;
2040var Scheduler_IdlePriority = Scheduler$1.unstable_IdlePriority;
2041
2042if (enableSchedulerTracing) {
2043 // Provide explicit error message when production+profiling bundle of e.g.
2044 // react-dom is used with production (non-profiling) bundle of
2045 // scheduler/tracing
2046 if (!(__interactionsRef != null && __interactionsRef.current != null)) {
2047 {
2048 throw 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");
2049 }
2050 }
2051}
2052
2053var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
2054// ascending numbers so we can compare them like numbers. They start at 90 to
2055// avoid clashing with Scheduler's priorities.
2056
2057var ImmediatePriority = 99;
2058var UserBlockingPriority = 98;
2059var NormalPriority = 97;
2060var LowPriority = 96;
2061var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
2062
2063var NoPriority = 90;
2064var shouldYield = Scheduler_shouldYield;
2065var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
2066Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function () {};
2067var syncQueue = null;
2068var immediateQueueCallbackNode = null;
2069var isFlushingSyncQueue = false;
2070var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
2071// This will be the case for modern browsers that support `performance.now`. In
2072// older browsers, Scheduler falls back to `Date.now`, which returns a Unix
2073// timestamp. In that case, subtract the module initialization time to simulate
2074// the behavior of performance.now and keep our times small enough to fit
2075// within 32 bits.
2076// TODO: Consider lifting this into Scheduler.
2077
2078var now = initialTimeMs < 10000 ? Scheduler_now : function () {
2079 return Scheduler_now() - initialTimeMs;
2080};
2081function getCurrentPriorityLevel() {
2082 switch (Scheduler_getCurrentPriorityLevel()) {
2083 case Scheduler_ImmediatePriority:
2084 return ImmediatePriority;
2085
2086 case Scheduler_UserBlockingPriority:
2087 return UserBlockingPriority;
2088
2089 case Scheduler_NormalPriority:
2090 return NormalPriority;
2091
2092 case Scheduler_LowPriority:
2093 return LowPriority;
2094
2095 case Scheduler_IdlePriority:
2096 return IdlePriority;
2097
2098 default:
2099 {
2100 {
2101 throw Error("Unknown priority level.");
2102 }
2103 }
2104
2105 }
2106}
2107
2108function reactPriorityToSchedulerPriority(reactPriorityLevel) {
2109 switch (reactPriorityLevel) {
2110 case ImmediatePriority:
2111 return Scheduler_ImmediatePriority;
2112
2113 case UserBlockingPriority:
2114 return Scheduler_UserBlockingPriority;
2115
2116 case NormalPriority:
2117 return Scheduler_NormalPriority;
2118
2119 case LowPriority:
2120 return Scheduler_LowPriority;
2121
2122 case IdlePriority:
2123 return Scheduler_IdlePriority;
2124
2125 default:
2126 {
2127 {
2128 throw Error("Unknown priority level.");
2129 }
2130 }
2131
2132 }
2133}
2134
2135function runWithPriority(reactPriorityLevel, fn) {
2136 var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
2137 return Scheduler_runWithPriority(priorityLevel, fn);
2138}
2139function scheduleCallback(reactPriorityLevel, callback, options) {
2140 var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
2141 return Scheduler_scheduleCallback(priorityLevel, callback, options);
2142}
2143function scheduleSyncCallback(callback) {
2144 // Push this callback into an internal queue. We'll flush these either in
2145 // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
2146 if (syncQueue === null) {
2147 syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
2148
2149 immediateQueueCallbackNode = Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueueImpl);
2150 } else {
2151 // Push onto existing queue. Don't need to schedule a callback because
2152 // we already scheduled one when we created the queue.
2153 syncQueue.push(callback);
2154 }
2155
2156 return fakeCallbackNode;
2157}
2158function cancelCallback(callbackNode) {
2159 if (callbackNode !== fakeCallbackNode) {
2160 Scheduler_cancelCallback(callbackNode);
2161 }
2162}
2163function flushSyncCallbackQueue() {
2164 if (immediateQueueCallbackNode !== null) {
2165 var node = immediateQueueCallbackNode;
2166 immediateQueueCallbackNode = null;
2167 Scheduler_cancelCallback(node);
2168 }
2169
2170 flushSyncCallbackQueueImpl();
2171}
2172
2173function flushSyncCallbackQueueImpl() {
2174 if (!isFlushingSyncQueue && syncQueue !== null) {
2175 // Prevent re-entrancy.
2176 isFlushingSyncQueue = true;
2177 var i = 0;
2178
2179 try {
2180 var _isSync = true;
2181 var queue = syncQueue;
2182 runWithPriority(ImmediatePriority, function () {
2183 for (; i < queue.length; i++) {
2184 var callback = queue[i];
2185
2186 do {
2187 callback = callback(_isSync);
2188 } while (callback !== null);
2189 }
2190 });
2191 syncQueue = null;
2192 } catch (error) {
2193 // If something throws, leave the remaining callbacks on the queue.
2194 if (syncQueue !== null) {
2195 syncQueue = syncQueue.slice(i + 1);
2196 } // Resume flushing in the next tick
2197
2198
2199 Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueue);
2200 throw error;
2201 } finally {
2202 isFlushingSyncQueue = false;
2203 }
2204 }
2205}
2206
2207var NoMode = 0;
2208var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
2209// tag instead
2210
2211var BlockingMode = 2;
2212var ConcurrentMode = 4;
2213var ProfileMode = 8;
2214
2215// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
2216// Math.pow(2, 30) - 1
2217// 0b111111111111111111111111111111
2218var MAX_SIGNED_31_BIT_INT = 1073741823;
2219
2220var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
2221// Never work can be committed in an inconsistent state without tearing the UI.
2222// The main example is offscreen content, like a hidden subtree. So one possible
2223// name is Offscreen. However, it also includes dehydrated Suspense boundaries,
2224// which are inconsistent in the sense that they haven't finished yet, but
2225// aren't visibly inconsistent because the server rendered HTML matches what the
2226// hydrated tree would look like.
2227
2228var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
2229// order to be consistent.
2230
2231var Idle = 2; // Continuous Hydration is a moving priority. It is slightly higher than Idle
2232var Sync = MAX_SIGNED_31_BIT_INT;
2233var Batched = Sync - 1;
2234var UNIT_SIZE = 10;
2235var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
2236
2237function msToExpirationTime(ms) {
2238 // Always add an offset so that we don't clash with the magic number for NoWork.
2239 return MAGIC_NUMBER_OFFSET - (ms / UNIT_SIZE | 0);
2240}
2241function expirationTimeToMs(expirationTime) {
2242 return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
2243}
2244
2245function ceiling(num, precision) {
2246 return ((num / precision | 0) + 1) * precision;
2247}
2248
2249function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
2250 return MAGIC_NUMBER_OFFSET - ceiling(MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE, bucketSizeMs / UNIT_SIZE);
2251} // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
2252// the names to reflect.
2253
2254
2255var LOW_PRIORITY_EXPIRATION = 5000;
2256var LOW_PRIORITY_BATCH_SIZE = 250;
2257function computeAsyncExpiration(currentTime) {
2258 return computeExpirationBucket(currentTime, LOW_PRIORITY_EXPIRATION, LOW_PRIORITY_BATCH_SIZE);
2259}
2260function computeSuspenseExpiration(currentTime, timeoutMs) {
2261 // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
2262 return computeExpirationBucket(currentTime, timeoutMs, LOW_PRIORITY_BATCH_SIZE);
2263} // We intentionally set a higher expiration time for interactive updates in
2264// dev than in production.
2265//
2266// If the main thread is being blocked so long that you hit the expiration,
2267// it's a problem that could be solved with better scheduling.
2268//
2269// People will be more likely to notice this and fix it with the long
2270// expiration time in development.
2271//
2272// In production we opt for better UX at the risk of masking scheduling
2273// problems, by expiring fast.
2274
2275var HIGH_PRIORITY_EXPIRATION = 500;
2276var HIGH_PRIORITY_BATCH_SIZE = 100;
2277function computeInteractiveExpiration(currentTime) {
2278 return computeExpirationBucket(currentTime, HIGH_PRIORITY_EXPIRATION, HIGH_PRIORITY_BATCH_SIZE);
2279}
2280
2281function inferPriorityFromExpirationTime(currentTime, expirationTime) {
2282 if (expirationTime === Sync) {
2283 return ImmediatePriority;
2284 }
2285
2286 if (expirationTime === Never || expirationTime === Idle) {
2287 return IdlePriority;
2288 }
2289
2290 var msUntil = expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
2291
2292 if (msUntil <= 0) {
2293 return ImmediatePriority;
2294 }
2295
2296 if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
2297 return UserBlockingPriority;
2298 }
2299
2300 if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
2301 return NormalPriority;
2302 } // TODO: Handle LowPriority
2303 // Assume anything lower has idle priority
2304
2305
2306 return IdlePriority;
2307}
2308
2309/**
2310 * inlined Object.is polyfill to avoid requiring consumers ship their own
2311 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
2312 */
2313function is(x, y) {
2314 return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
2315 ;
2316}
2317
2318var is$1 = typeof Object.is === 'function' ? Object.is : is;
2319
2320var hasOwnProperty = Object.prototype.hasOwnProperty;
2321/**
2322 * Performs equality by iterating through keys on an object and returning false
2323 * when any key has values which are not strictly equal between the arguments.
2324 * Returns true when the values of all keys are strictly equal.
2325 */
2326
2327function shallowEqual(objA, objB) {
2328 if (is$1(objA, objB)) {
2329 return true;
2330 }
2331
2332 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
2333 return false;
2334 }
2335
2336 var keysA = Object.keys(objA);
2337 var keysB = Object.keys(objB);
2338
2339 if (keysA.length !== keysB.length) {
2340 return false;
2341 } // Test for A's keys different from B.
2342
2343
2344 for (var i = 0; i < keysA.length; i++) {
2345 if (!hasOwnProperty.call(objB, keysA[i]) || !is$1(objA[keysA[i]], objB[keysA[i]])) {
2346 return false;
2347 }
2348 }
2349
2350 return true;
2351}
2352
2353/**
2354 * Forked from fbjs/warning:
2355 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
2356 *
2357 * Only change is we use console.warn instead of console.error,
2358 * and do nothing when 'console' is not supported.
2359 * This really simplifies the code.
2360 * ---
2361 * Similar to invariant but only logs a warning if the condition is not met.
2362 * This can be used to log issues in development environments in critical
2363 * paths. Removing the logging code for production environments will keep the
2364 * same logic and follow the same code paths.
2365 */
2366var lowPriorityWarningWithoutStack = function () {};
2367
2368{
2369 var printWarning$1 = function (format) {
2370 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2371 args[_key - 1] = arguments[_key];
2372 }
2373
2374 var argIndex = 0;
2375 var message = 'Warning: ' + format.replace(/%s/g, function () {
2376 return args[argIndex++];
2377 });
2378
2379 if (typeof console !== 'undefined') {
2380 console.warn(message);
2381 }
2382
2383 try {
2384 // --- Welcome to debugging React ---
2385 // This error was thrown as a convenience so that you can use this stack
2386 // to find the callsite that caused this warning to fire.
2387 throw new Error(message);
2388 } catch (x) {}
2389 };
2390
2391 lowPriorityWarningWithoutStack = function (condition, format) {
2392 if (format === undefined) {
2393 throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
2394 }
2395
2396 if (!condition) {
2397 for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2398 args[_key2 - 2] = arguments[_key2];
2399 }
2400
2401 printWarning$1.apply(void 0, [format].concat(args));
2402 }
2403 };
2404}
2405
2406var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack;
2407
2408var ReactStrictModeWarnings = {
2409 recordUnsafeLifecycleWarnings: function (fiber, instance) {},
2410 flushPendingUnsafeLifecycleWarnings: function () {},
2411 recordLegacyContextWarning: function (fiber, instance) {},
2412 flushLegacyContextWarning: function () {},
2413 discardPendingWarnings: function () {}
2414};
2415
2416{
2417 var findStrictRoot = function (fiber) {
2418 var maybeStrictRoot = null;
2419 var node = fiber;
2420
2421 while (node !== null) {
2422 if (node.mode & StrictMode) {
2423 maybeStrictRoot = node;
2424 }
2425
2426 node = node.return;
2427 }
2428
2429 return maybeStrictRoot;
2430 };
2431
2432 var setToSortedString = function (set) {
2433 var array = [];
2434 set.forEach(function (value) {
2435 array.push(value);
2436 });
2437 return array.sort().join(', ');
2438 };
2439
2440 var pendingComponentWillMountWarnings = [];
2441 var pendingUNSAFE_ComponentWillMountWarnings = [];
2442 var pendingComponentWillReceivePropsWarnings = [];
2443 var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2444 var pendingComponentWillUpdateWarnings = [];
2445 var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
2446
2447 var didWarnAboutUnsafeLifecycles = new Set();
2448
2449 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
2450 // Dedup strategy: Warn once per component.
2451 if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
2452 return;
2453 }
2454
2455 if (typeof instance.componentWillMount === 'function' && // Don't warn about react-lifecycles-compat polyfilled components.
2456 instance.componentWillMount.__suppressDeprecationWarning !== true) {
2457 pendingComponentWillMountWarnings.push(fiber);
2458 }
2459
2460 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillMount === 'function') {
2461 pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
2462 }
2463
2464 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
2465 pendingComponentWillReceivePropsWarnings.push(fiber);
2466 }
2467
2468 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
2469 pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
2470 }
2471
2472 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
2473 pendingComponentWillUpdateWarnings.push(fiber);
2474 }
2475
2476 if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillUpdate === 'function') {
2477 pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
2478 }
2479 };
2480
2481 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
2482 // We do an initial pass to gather component names
2483 var componentWillMountUniqueNames = new Set();
2484
2485 if (pendingComponentWillMountWarnings.length > 0) {
2486 pendingComponentWillMountWarnings.forEach(function (fiber) {
2487 componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
2488 didWarnAboutUnsafeLifecycles.add(fiber.type);
2489 });
2490 pendingComponentWillMountWarnings = [];
2491 }
2492
2493 var UNSAFE_componentWillMountUniqueNames = new Set();
2494
2495 if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
2496 pendingUNSAFE_ComponentWillMountWarnings.forEach(function (fiber) {
2497 UNSAFE_componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
2498 didWarnAboutUnsafeLifecycles.add(fiber.type);
2499 });
2500 pendingUNSAFE_ComponentWillMountWarnings = [];
2501 }
2502
2503 var componentWillReceivePropsUniqueNames = new Set();
2504
2505 if (pendingComponentWillReceivePropsWarnings.length > 0) {
2506 pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
2507 componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
2508 didWarnAboutUnsafeLifecycles.add(fiber.type);
2509 });
2510 pendingComponentWillReceivePropsWarnings = [];
2511 }
2512
2513 var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
2514
2515 if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
2516 pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function (fiber) {
2517 UNSAFE_componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
2518 didWarnAboutUnsafeLifecycles.add(fiber.type);
2519 });
2520 pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2521 }
2522
2523 var componentWillUpdateUniqueNames = new Set();
2524
2525 if (pendingComponentWillUpdateWarnings.length > 0) {
2526 pendingComponentWillUpdateWarnings.forEach(function (fiber) {
2527 componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
2528 didWarnAboutUnsafeLifecycles.add(fiber.type);
2529 });
2530 pendingComponentWillUpdateWarnings = [];
2531 }
2532
2533 var UNSAFE_componentWillUpdateUniqueNames = new Set();
2534
2535 if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
2536 pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function (fiber) {
2537 UNSAFE_componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
2538 didWarnAboutUnsafeLifecycles.add(fiber.type);
2539 });
2540 pendingUNSAFE_ComponentWillUpdateWarnings = [];
2541 } // Finally, we flush all the warnings
2542 // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
2543
2544
2545 if (UNSAFE_componentWillMountUniqueNames.size > 0) {
2546 var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
2547 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);
2548 }
2549
2550 if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
2551 var _sortedNames = setToSortedString(UNSAFE_componentWillReceivePropsUniqueNames);
2552
2553 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);
2554 }
2555
2556 if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
2557 var _sortedNames2 = setToSortedString(UNSAFE_componentWillUpdateUniqueNames);
2558
2559 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);
2560 }
2561
2562 if (componentWillMountUniqueNames.size > 0) {
2563 var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
2564
2565 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);
2566 }
2567
2568 if (componentWillReceivePropsUniqueNames.size > 0) {
2569 var _sortedNames4 = setToSortedString(componentWillReceivePropsUniqueNames);
2570
2571 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);
2572 }
2573
2574 if (componentWillUpdateUniqueNames.size > 0) {
2575 var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
2576
2577 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);
2578 }
2579 };
2580
2581 var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
2582
2583 var didWarnAboutLegacyContext = new Set();
2584
2585 ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
2586 var strictRoot = findStrictRoot(fiber);
2587
2588 if (strictRoot === null) {
2589 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.');
2590 return;
2591 } // Dedup strategy: Warn once per component.
2592
2593
2594 if (didWarnAboutLegacyContext.has(fiber.type)) {
2595 return;
2596 }
2597
2598 var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
2599
2600 if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
2601 if (warningsForRoot === undefined) {
2602 warningsForRoot = [];
2603 pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
2604 }
2605
2606 warningsForRoot.push(fiber);
2607 }
2608 };
2609
2610 ReactStrictModeWarnings.flushLegacyContextWarning = function () {
2611 pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
2612 var uniqueNames = new Set();
2613 fiberArray.forEach(function (fiber) {
2614 uniqueNames.add(getComponentName(fiber.type) || 'Component');
2615 didWarnAboutLegacyContext.add(fiber.type);
2616 });
2617 var sortedNames = setToSortedString(uniqueNames);
2618 var strictRootComponentStack = getStackByFiberInDevAndProd(strictRoot);
2619 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);
2620 });
2621 };
2622
2623 ReactStrictModeWarnings.discardPendingWarnings = function () {
2624 pendingComponentWillMountWarnings = [];
2625 pendingUNSAFE_ComponentWillMountWarnings = [];
2626 pendingComponentWillReceivePropsWarnings = [];
2627 pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
2628 pendingComponentWillUpdateWarnings = [];
2629 pendingUNSAFE_ComponentWillUpdateWarnings = [];
2630 pendingLegacyContextWarning = new Map();
2631 };
2632}
2633
2634var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
2635
2636var failedBoundaries = null;
2637var setRefreshHandler = function (handler) {
2638 {
2639 resolveFamily = handler;
2640 }
2641};
2642function resolveFunctionForHotReloading(type) {
2643 {
2644 if (resolveFamily === null) {
2645 // Hot reloading is disabled.
2646 return type;
2647 }
2648
2649 var family = resolveFamily(type);
2650
2651 if (family === undefined) {
2652 return type;
2653 } // Use the latest known implementation.
2654
2655
2656 return family.current;
2657 }
2658}
2659function resolveClassForHotReloading(type) {
2660 // No implementation differences.
2661 return resolveFunctionForHotReloading(type);
2662}
2663function resolveForwardRefForHotReloading(type) {
2664 {
2665 if (resolveFamily === null) {
2666 // Hot reloading is disabled.
2667 return type;
2668 }
2669
2670 var family = resolveFamily(type);
2671
2672 if (family === undefined) {
2673 // Check if we're dealing with a real forwardRef. Don't want to crash early.
2674 if (type !== null && type !== undefined && typeof type.render === 'function') {
2675 // ForwardRef is special because its resolved .type is an object,
2676 // but it's possible that we only have its inner render function in the map.
2677 // If that inner render function is different, we'll build a new forwardRef type.
2678 var currentRender = resolveFunctionForHotReloading(type.render);
2679
2680 if (type.render !== currentRender) {
2681 var syntheticType = {
2682 $$typeof: REACT_FORWARD_REF_TYPE,
2683 render: currentRender
2684 };
2685
2686 if (type.displayName !== undefined) {
2687 syntheticType.displayName = type.displayName;
2688 }
2689
2690 return syntheticType;
2691 }
2692 }
2693
2694 return type;
2695 } // Use the latest known implementation.
2696
2697
2698 return family.current;
2699 }
2700}
2701function isCompatibleFamilyForHotReloading(fiber, element) {
2702 {
2703 if (resolveFamily === null) {
2704 // Hot reloading is disabled.
2705 return false;
2706 }
2707
2708 var prevType = fiber.elementType;
2709 var nextType = element.type; // If we got here, we know types aren't === equal.
2710
2711 var needsCompareFamilies = false;
2712 var $$typeofNextType = typeof nextType === 'object' && nextType !== null ? nextType.$$typeof : null;
2713
2714 switch (fiber.tag) {
2715 case ClassComponent:
2716 {
2717 if (typeof nextType === 'function') {
2718 needsCompareFamilies = true;
2719 }
2720
2721 break;
2722 }
2723
2724 case FunctionComponent:
2725 {
2726 if (typeof nextType === 'function') {
2727 needsCompareFamilies = true;
2728 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2729 // We don't know the inner type yet.
2730 // We're going to assume that the lazy inner type is stable,
2731 // and so it is sufficient to avoid reconciling it away.
2732 // We're not going to unwrap or actually use the new lazy type.
2733 needsCompareFamilies = true;
2734 }
2735
2736 break;
2737 }
2738
2739 case ForwardRef:
2740 {
2741 if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
2742 needsCompareFamilies = true;
2743 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2744 needsCompareFamilies = true;
2745 }
2746
2747 break;
2748 }
2749
2750 case MemoComponent:
2751 case SimpleMemoComponent:
2752 {
2753 if ($$typeofNextType === REACT_MEMO_TYPE) {
2754 // TODO: if it was but can no longer be simple,
2755 // we shouldn't set this.
2756 needsCompareFamilies = true;
2757 } else if ($$typeofNextType === REACT_LAZY_TYPE) {
2758 needsCompareFamilies = true;
2759 }
2760
2761 break;
2762 }
2763
2764 default:
2765 return false;
2766 } // Check if both types have a family and it's the same one.
2767
2768
2769 if (needsCompareFamilies) {
2770 // Note: memo() and forwardRef() we'll compare outer rather than inner type.
2771 // This means both of them need to be registered to preserve state.
2772 // If we unwrapped and compared the inner types for wrappers instead,
2773 // then we would risk falsely saying two separate memo(Foo)
2774 // calls are equivalent because they wrap the same Foo function.
2775 var prevFamily = resolveFamily(prevType);
2776
2777 if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
2778 return true;
2779 }
2780 }
2781
2782 return false;
2783 }
2784}
2785function markFailedErrorBoundaryForHotReloading(fiber) {
2786 {
2787 if (resolveFamily === null) {
2788 // Hot reloading is disabled.
2789 return;
2790 }
2791
2792 if (typeof WeakSet !== 'function') {
2793 return;
2794 }
2795
2796 if (failedBoundaries === null) {
2797 failedBoundaries = new WeakSet();
2798 }
2799
2800 failedBoundaries.add(fiber);
2801 }
2802}
2803var scheduleRefresh = function (root, update) {
2804 {
2805 if (resolveFamily === null) {
2806 // Hot reloading is disabled.
2807 return;
2808 }
2809
2810 var staleFamilies = update.staleFamilies,
2811 updatedFamilies = update.updatedFamilies;
2812 flushPassiveEffects();
2813 flushSync(function () {
2814 scheduleFibersWithFamiliesRecursively(root.current, updatedFamilies, staleFamilies);
2815 });
2816 }
2817};
2818var scheduleRoot = function (root, element) {
2819 {
2820 if (root.context !== emptyContextObject) {
2821 // Super edge case: root has a legacy _renderSubtree context
2822 // but we don't know the parentComponent so we can't pass it.
2823 // Just ignore. We'll delete this with _renderSubtree code path later.
2824 return;
2825 }
2826
2827 flushPassiveEffects();
2828 syncUpdates(function () {
2829 updateContainer(element, root, null, null);
2830 });
2831 }
2832};
2833
2834function scheduleFibersWithFamiliesRecursively(fiber, updatedFamilies, staleFamilies) {
2835 {
2836 var alternate = fiber.alternate,
2837 child = fiber.child,
2838 sibling = fiber.sibling,
2839 tag = fiber.tag,
2840 type = fiber.type;
2841 var candidateType = null;
2842
2843 switch (tag) {
2844 case FunctionComponent:
2845 case SimpleMemoComponent:
2846 case ClassComponent:
2847 candidateType = type;
2848 break;
2849
2850 case ForwardRef:
2851 candidateType = type.render;
2852 break;
2853
2854 default:
2855 break;
2856 }
2857
2858 if (resolveFamily === null) {
2859 throw new Error('Expected resolveFamily to be set during hot reload.');
2860 }
2861
2862 var needsRender = false;
2863 var needsRemount = false;
2864
2865 if (candidateType !== null) {
2866 var family = resolveFamily(candidateType);
2867
2868 if (family !== undefined) {
2869 if (staleFamilies.has(family)) {
2870 needsRemount = true;
2871 } else if (updatedFamilies.has(family)) {
2872 if (tag === ClassComponent) {
2873 needsRemount = true;
2874 } else {
2875 needsRender = true;
2876 }
2877 }
2878 }
2879 }
2880
2881 if (failedBoundaries !== null) {
2882 if (failedBoundaries.has(fiber) || alternate !== null && failedBoundaries.has(alternate)) {
2883 needsRemount = true;
2884 }
2885 }
2886
2887 if (needsRemount) {
2888 fiber._debugNeedsRemount = true;
2889 }
2890
2891 if (needsRemount || needsRender) {
2892 scheduleWork(fiber, Sync);
2893 }
2894
2895 if (child !== null && !needsRemount) {
2896 scheduleFibersWithFamiliesRecursively(child, updatedFamilies, staleFamilies);
2897 }
2898
2899 if (sibling !== null) {
2900 scheduleFibersWithFamiliesRecursively(sibling, updatedFamilies, staleFamilies);
2901 }
2902 }
2903}
2904
2905var findHostInstancesForRefresh = function (root, families) {
2906 {
2907 var hostInstances = new Set();
2908 var types = new Set(families.map(function (family) {
2909 return family.current;
2910 }));
2911 findHostInstancesForMatchingFibersRecursively(root.current, types, hostInstances);
2912 return hostInstances;
2913 }
2914};
2915
2916function findHostInstancesForMatchingFibersRecursively(fiber, types, hostInstances) {
2917 {
2918 var child = fiber.child,
2919 sibling = fiber.sibling,
2920 tag = fiber.tag,
2921 type = fiber.type;
2922 var candidateType = null;
2923
2924 switch (tag) {
2925 case FunctionComponent:
2926 case SimpleMemoComponent:
2927 case ClassComponent:
2928 candidateType = type;
2929 break;
2930
2931 case ForwardRef:
2932 candidateType = type.render;
2933 break;
2934
2935 default:
2936 break;
2937 }
2938
2939 var didMatch = false;
2940
2941 if (candidateType !== null) {
2942 if (types.has(candidateType)) {
2943 didMatch = true;
2944 }
2945 }
2946
2947 if (didMatch) {
2948 // We have a match. This only drills down to the closest host components.
2949 // There's no need to search deeper because for the purpose of giving
2950 // visual feedback, "flashing" outermost parent rectangles is sufficient.
2951 findHostInstancesForFiberShallowly(fiber, hostInstances);
2952 } else {
2953 // If there's no match, maybe there will be one further down in the child tree.
2954 if (child !== null) {
2955 findHostInstancesForMatchingFibersRecursively(child, types, hostInstances);
2956 }
2957 }
2958
2959 if (sibling !== null) {
2960 findHostInstancesForMatchingFibersRecursively(sibling, types, hostInstances);
2961 }
2962 }
2963}
2964
2965function findHostInstancesForFiberShallowly(fiber, hostInstances) {
2966 {
2967 var foundHostInstances = findChildHostInstancesForFiberShallowly(fiber, hostInstances);
2968
2969 if (foundHostInstances) {
2970 return;
2971 } // If we didn't find any host children, fallback to closest host parent.
2972
2973
2974 var node = fiber;
2975
2976 while (true) {
2977 switch (node.tag) {
2978 case HostComponent:
2979 hostInstances.add(node.stateNode);
2980 return;
2981
2982 case HostPortal:
2983 hostInstances.add(node.stateNode.containerInfo);
2984 return;
2985
2986 case HostRoot:
2987 hostInstances.add(node.stateNode.containerInfo);
2988 return;
2989 }
2990
2991 if (node.return === null) {
2992 throw new Error('Expected to reach root first.');
2993 }
2994
2995 node = node.return;
2996 }
2997 }
2998}
2999
3000function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
3001 {
3002 var node = fiber;
3003 var foundHostInstances = false;
3004
3005 while (true) {
3006 if (node.tag === HostComponent) {
3007 // We got a match.
3008 foundHostInstances = true;
3009 hostInstances.add(node.stateNode); // There may still be more, so keep searching.
3010 } else if (node.child !== null) {
3011 node.child.return = node;
3012 node = node.child;
3013 continue;
3014 }
3015
3016 if (node === fiber) {
3017 return foundHostInstances;
3018 }
3019
3020 while (node.sibling === null) {
3021 if (node.return === null || node.return === fiber) {
3022 return foundHostInstances;
3023 }
3024
3025 node = node.return;
3026 }
3027
3028 node.sibling.return = node.return;
3029 node = node.sibling;
3030 }
3031 }
3032
3033 return false;
3034}
3035
3036function resolveDefaultProps(Component, baseProps) {
3037 if (Component && Component.defaultProps) {
3038 // Resolve default props. Taken from ReactElement
3039 var props = _assign({}, baseProps);
3040
3041 var defaultProps = Component.defaultProps;
3042
3043 for (var propName in defaultProps) {
3044 if (props[propName] === undefined) {
3045 props[propName] = defaultProps[propName];
3046 }
3047 }
3048
3049 return props;
3050 }
3051
3052 return baseProps;
3053}
3054function readLazyComponentType(lazyComponent) {
3055 initializeLazyComponentType(lazyComponent);
3056
3057 if (lazyComponent._status !== Resolved) {
3058 throw lazyComponent._result;
3059 }
3060
3061 return lazyComponent._result;
3062}
3063
3064var valueCursor = createCursor(null);
3065var rendererSigil;
3066
3067{
3068 // Use this to detect multiple renderers using the same context
3069 rendererSigil = {};
3070}
3071
3072var currentlyRenderingFiber = null;
3073var lastContextDependency = null;
3074var lastContextWithAllBitsObserved = null;
3075var isDisallowedContextReadInDEV = false;
3076function resetContextDependencies() {
3077 // This is called right before React yields execution, to ensure `readContext`
3078 // cannot be called outside the render phase.
3079 currentlyRenderingFiber = null;
3080 lastContextDependency = null;
3081 lastContextWithAllBitsObserved = null;
3082
3083 {
3084 isDisallowedContextReadInDEV = false;
3085 }
3086}
3087function enterDisallowedContextReadInDEV() {
3088 {
3089 isDisallowedContextReadInDEV = true;
3090 }
3091}
3092function exitDisallowedContextReadInDEV() {
3093 {
3094 isDisallowedContextReadInDEV = false;
3095 }
3096}
3097function pushProvider(providerFiber, nextValue) {
3098 var context = providerFiber.type._context;
3099
3100 if (isPrimaryRenderer) {
3101 push(valueCursor, context._currentValue, providerFiber);
3102 context._currentValue = nextValue;
3103
3104 {
3105 !(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;
3106 context._currentRenderer = rendererSigil;
3107 }
3108 } else {
3109 push(valueCursor, context._currentValue2, providerFiber);
3110 context._currentValue2 = nextValue;
3111
3112 {
3113 !(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;
3114 context._currentRenderer2 = rendererSigil;
3115 }
3116 }
3117}
3118function popProvider(providerFiber) {
3119 var currentValue = valueCursor.current;
3120 pop(valueCursor, providerFiber);
3121 var context = providerFiber.type._context;
3122
3123 if (isPrimaryRenderer) {
3124 context._currentValue = currentValue;
3125 } else {
3126 context._currentValue2 = currentValue;
3127 }
3128}
3129function calculateChangedBits(context, newValue, oldValue) {
3130 if (is$1(oldValue, newValue)) {
3131 // No change
3132 return 0;
3133 } else {
3134 var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
3135
3136 {
3137 !((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;
3138 }
3139
3140 return changedBits | 0;
3141 }
3142}
3143function scheduleWorkOnParentPath(parent, renderExpirationTime) {
3144 // Update the child expiration time of all the ancestors, including
3145 // the alternates.
3146 var node = parent;
3147
3148 while (node !== null) {
3149 var alternate = node.alternate;
3150
3151 if (node.childExpirationTime < renderExpirationTime) {
3152 node.childExpirationTime = renderExpirationTime;
3153
3154 if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
3155 alternate.childExpirationTime = renderExpirationTime;
3156 }
3157 } else if (alternate !== null && alternate.childExpirationTime < renderExpirationTime) {
3158 alternate.childExpirationTime = renderExpirationTime;
3159 } else {
3160 // Neither alternate was updated, which means the rest of the
3161 // ancestor path already has sufficient priority.
3162 break;
3163 }
3164
3165 node = node.return;
3166 }
3167}
3168function propagateContextChange(workInProgress, context, changedBits, renderExpirationTime) {
3169 var fiber = workInProgress.child;
3170
3171 if (fiber !== null) {
3172 // Set the return pointer of the child to the work-in-progress fiber.
3173 fiber.return = workInProgress;
3174 }
3175
3176 while (fiber !== null) {
3177 var nextFiber = void 0; // Visit this fiber.
3178
3179 var list = fiber.dependencies;
3180
3181 if (list !== null) {
3182 nextFiber = fiber.child;
3183 var dependency = list.firstContext;
3184
3185 while (dependency !== null) {
3186 // Check if the context matches.
3187 if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
3188 // Match! Schedule an update on this fiber.
3189 if (fiber.tag === ClassComponent) {
3190 // Schedule a force update on the work-in-progress.
3191 var update = createUpdate(renderExpirationTime, null);
3192 update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
3193 // update to the current fiber, too, which means it will persist even if
3194 // this render is thrown away. Since it's a race condition, not sure it's
3195 // worth fixing.
3196
3197 enqueueUpdate(fiber, update);
3198 }
3199
3200 if (fiber.expirationTime < renderExpirationTime) {
3201 fiber.expirationTime = renderExpirationTime;
3202 }
3203
3204 var alternate = fiber.alternate;
3205
3206 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
3207 alternate.expirationTime = renderExpirationTime;
3208 }
3209
3210 scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
3211
3212 if (list.expirationTime < renderExpirationTime) {
3213 list.expirationTime = renderExpirationTime;
3214 } // Since we already found a match, we can stop traversing the
3215 // dependency list.
3216
3217
3218 break;
3219 }
3220
3221 dependency = dependency.next;
3222 }
3223 } else if (fiber.tag === ContextProvider) {
3224 // Don't scan deeper if this is a matching provider
3225 nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
3226 } else if (enableSuspenseServerRenderer && fiber.tag === DehydratedFragment) {
3227 // If a dehydrated suspense bounudary is in this subtree, we don't know
3228 // if it will have any context consumers in it. The best we can do is
3229 // mark it as having updates.
3230 var parentSuspense = fiber.return;
3231
3232 if (!(parentSuspense !== null)) {
3233 {
3234 throw Error("We just came from a parent so we must have had a parent. This is a bug in React.");
3235 }
3236 }
3237
3238 if (parentSuspense.expirationTime < renderExpirationTime) {
3239 parentSuspense.expirationTime = renderExpirationTime;
3240 }
3241
3242 var _alternate = parentSuspense.alternate;
3243
3244 if (_alternate !== null && _alternate.expirationTime < renderExpirationTime) {
3245 _alternate.expirationTime = renderExpirationTime;
3246 } // This is intentionally passing this fiber as the parent
3247 // because we want to schedule this fiber as having work
3248 // on its children. We'll use the childExpirationTime on
3249 // this fiber to indicate that a context has changed.
3250
3251
3252 scheduleWorkOnParentPath(parentSuspense, renderExpirationTime);
3253 nextFiber = fiber.sibling;
3254 } else {
3255 // Traverse down.
3256 nextFiber = fiber.child;
3257 }
3258
3259 if (nextFiber !== null) {
3260 // Set the return pointer of the child to the work-in-progress fiber.
3261 nextFiber.return = fiber;
3262 } else {
3263 // No child. Traverse to next sibling.
3264 nextFiber = fiber;
3265
3266 while (nextFiber !== null) {
3267 if (nextFiber === workInProgress) {
3268 // We're back to the root of this subtree. Exit.
3269 nextFiber = null;
3270 break;
3271 }
3272
3273 var sibling = nextFiber.sibling;
3274
3275 if (sibling !== null) {
3276 // Set the return pointer of the sibling to the work-in-progress fiber.
3277 sibling.return = nextFiber.return;
3278 nextFiber = sibling;
3279 break;
3280 } // No more siblings. Traverse up.
3281
3282
3283 nextFiber = nextFiber.return;
3284 }
3285 }
3286
3287 fiber = nextFiber;
3288 }
3289}
3290function prepareToReadContext(workInProgress, renderExpirationTime) {
3291 currentlyRenderingFiber = workInProgress;
3292 lastContextDependency = null;
3293 lastContextWithAllBitsObserved = null;
3294 var dependencies = workInProgress.dependencies;
3295
3296 if (dependencies !== null) {
3297 var firstContext = dependencies.firstContext;
3298
3299 if (firstContext !== null) {
3300 if (dependencies.expirationTime >= renderExpirationTime) {
3301 // Context list has a pending update. Mark that this fiber performed work.
3302 markWorkInProgressReceivedUpdate();
3303 } // Reset the work-in-progress list
3304
3305
3306 dependencies.firstContext = null;
3307 }
3308 }
3309}
3310function readContext(context, observedBits) {
3311 {
3312 // This warning would fire if you read context inside a Hook like useMemo.
3313 // Unlike the class check below, it's not enforced in production for perf.
3314 !!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;
3315 }
3316
3317 if (lastContextWithAllBitsObserved === context) {// Nothing to do. We already observe everything in this context.
3318 } else if (observedBits === false || observedBits === 0) {// Do not observe any updates.
3319 } else {
3320 var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
3321
3322 if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
3323 // Observe all updates.
3324 lastContextWithAllBitsObserved = context;
3325 resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
3326 } else {
3327 resolvedObservedBits = observedBits;
3328 }
3329
3330 var contextItem = {
3331 context: context,
3332 observedBits: resolvedObservedBits,
3333 next: null
3334 };
3335
3336 if (lastContextDependency === null) {
3337 if (!(currentlyRenderingFiber !== null)) {
3338 {
3339 throw 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().");
3340 }
3341 } // This is the first dependency for this component. Create a new list.
3342
3343
3344 lastContextDependency = contextItem;
3345 currentlyRenderingFiber.dependencies = {
3346 expirationTime: NoWork,
3347 firstContext: contextItem,
3348 responders: null
3349 };
3350 } else {
3351 // Append a new context item.
3352 lastContextDependency = lastContextDependency.next = contextItem;
3353 }
3354 }
3355
3356 return isPrimaryRenderer ? context._currentValue : context._currentValue2;
3357}
3358
3359// UpdateQueue is a linked list of prioritized updates.
3360//
3361// Like fibers, update queues come in pairs: a current queue, which represents
3362// the visible state of the screen, and a work-in-progress queue, which can be
3363// mutated and processed asynchronously before it is committed — a form of
3364// double buffering. If a work-in-progress render is discarded before finishing,
3365// we create a new work-in-progress by cloning the current queue.
3366//
3367// Both queues share a persistent, singly-linked list structure. To schedule an
3368// update, we append it to the end of both queues. Each queue maintains a
3369// pointer to first update in the persistent list that hasn't been processed.
3370// The work-in-progress pointer always has a position equal to or greater than
3371// the current queue, since we always work on that one. The current queue's
3372// pointer is only updated during the commit phase, when we swap in the
3373// work-in-progress.
3374//
3375// For example:
3376//
3377// Current pointer: A - B - C - D - E - F
3378// Work-in-progress pointer: D - E - F
3379// ^
3380// The work-in-progress queue has
3381// processed more updates than current.
3382//
3383// The reason we append to both queues is because otherwise we might drop
3384// updates without ever processing them. For example, if we only add updates to
3385// the work-in-progress queue, some updates could be lost whenever a work-in
3386// -progress render restarts by cloning from current. Similarly, if we only add
3387// updates to the current queue, the updates will be lost whenever an already
3388// in-progress queue commits and swaps with the current queue. However, by
3389// adding to both queues, we guarantee that the update will be part of the next
3390// work-in-progress. (And because the work-in-progress queue becomes the
3391// current queue once it commits, there's no danger of applying the same
3392// update twice.)
3393//
3394// Prioritization
3395// --------------
3396//
3397// Updates are not sorted by priority, but by insertion; new updates are always
3398// appended to the end of the list.
3399//
3400// The priority is still important, though. When processing the update queue
3401// during the render phase, only the updates with sufficient priority are
3402// included in the result. If we skip an update because it has insufficient
3403// priority, it remains in the queue to be processed later, during a lower
3404// priority render. Crucially, all updates subsequent to a skipped update also
3405// remain in the queue *regardless of their priority*. That means high priority
3406// updates are sometimes processed twice, at two separate priorities. We also
3407// keep track of a base state, that represents the state before the first
3408// update in the queue is applied.
3409//
3410// For example:
3411//
3412// Given a base state of '', and the following queue of updates
3413//
3414// A1 - B2 - C1 - D2
3415//
3416// where the number indicates the priority, and the update is applied to the
3417// previous state by appending a letter, React will process these updates as
3418// two separate renders, one per distinct priority level:
3419//
3420// First render, at priority 1:
3421// Base state: ''
3422// Updates: [A1, C1]
3423// Result state: 'AC'
3424//
3425// Second render, at priority 2:
3426// Base state: 'A' <- The base state does not include C1,
3427// because B2 was skipped.
3428// Updates: [B2, C1, D2] <- C1 was rebased on top of B2
3429// Result state: 'ABCD'
3430//
3431// Because we process updates in insertion order, and rebase high priority
3432// updates when preceding updates are skipped, the final result is deterministic
3433// regardless of priority. Intermediate state may vary according to system
3434// resources, but the final state is always the same.
3435var UpdateState = 0;
3436var ReplaceState = 1;
3437var ForceUpdate = 2;
3438var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
3439// It should only be read right after calling `processUpdateQueue`, via
3440// `checkHasForceUpdateAfterProcessing`.
3441
3442var hasForceUpdate = false;
3443var didWarnUpdateInsideUpdate;
3444var currentlyProcessingQueue;
3445
3446
3447{
3448 didWarnUpdateInsideUpdate = false;
3449 currentlyProcessingQueue = null;
3450
3451
3452}
3453
3454function createUpdateQueue(baseState) {
3455 var queue = {
3456 baseState: baseState,
3457 firstUpdate: null,
3458 lastUpdate: null,
3459 firstCapturedUpdate: null,
3460 lastCapturedUpdate: null,
3461 firstEffect: null,
3462 lastEffect: null,
3463 firstCapturedEffect: null,
3464 lastCapturedEffect: null
3465 };
3466 return queue;
3467}
3468
3469function cloneUpdateQueue(currentQueue) {
3470 var queue = {
3471 baseState: currentQueue.baseState,
3472 firstUpdate: currentQueue.firstUpdate,
3473 lastUpdate: currentQueue.lastUpdate,
3474 // TODO: With resuming, if we bail out and resuse the child tree, we should
3475 // keep these effects.
3476 firstCapturedUpdate: null,
3477 lastCapturedUpdate: null,
3478 firstEffect: null,
3479 lastEffect: null,
3480 firstCapturedEffect: null,
3481 lastCapturedEffect: null
3482 };
3483 return queue;
3484}
3485
3486function createUpdate(expirationTime, suspenseConfig) {
3487 var update = {
3488 expirationTime: expirationTime,
3489 suspenseConfig: suspenseConfig,
3490 tag: UpdateState,
3491 payload: null,
3492 callback: null,
3493 next: null,
3494 nextEffect: null
3495 };
3496
3497 {
3498 update.priority = getCurrentPriorityLevel();
3499 }
3500
3501 return update;
3502}
3503
3504function appendUpdateToQueue(queue, update) {
3505 // Append the update to the end of the list.
3506 if (queue.lastUpdate === null) {
3507 // Queue is empty
3508 queue.firstUpdate = queue.lastUpdate = update;
3509 } else {
3510 queue.lastUpdate.next = update;
3511 queue.lastUpdate = update;
3512 }
3513}
3514
3515function enqueueUpdate(fiber, update) {
3516 // Update queues are created lazily.
3517 var alternate = fiber.alternate;
3518 var queue1;
3519 var queue2;
3520
3521 if (alternate === null) {
3522 // There's only one fiber.
3523 queue1 = fiber.updateQueue;
3524 queue2 = null;
3525
3526 if (queue1 === null) {
3527 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
3528 }
3529 } else {
3530 // There are two owners.
3531 queue1 = fiber.updateQueue;
3532 queue2 = alternate.updateQueue;
3533
3534 if (queue1 === null) {
3535 if (queue2 === null) {
3536 // Neither fiber has an update queue. Create new ones.
3537 queue1 = fiber.updateQueue = createUpdateQueue(fiber.memoizedState);
3538 queue2 = alternate.updateQueue = createUpdateQueue(alternate.memoizedState);
3539 } else {
3540 // Only one fiber has an update queue. Clone to create a new one.
3541 queue1 = fiber.updateQueue = cloneUpdateQueue(queue2);
3542 }
3543 } else {
3544 if (queue2 === null) {
3545 // Only one fiber has an update queue. Clone to create a new one.
3546 queue2 = alternate.updateQueue = cloneUpdateQueue(queue1);
3547 } else {// Both owners have an update queue.
3548 }
3549 }
3550 }
3551
3552 if (queue2 === null || queue1 === queue2) {
3553 // There's only a single queue.
3554 appendUpdateToQueue(queue1, update);
3555 } else {
3556 // There are two queues. We need to append the update to both queues,
3557 // while accounting for the persistent structure of the list — we don't
3558 // want the same update to be added multiple times.
3559 if (queue1.lastUpdate === null || queue2.lastUpdate === null) {
3560 // One of the queues is not empty. We must add the update to both queues.
3561 appendUpdateToQueue(queue1, update);
3562 appendUpdateToQueue(queue2, update);
3563 } else {
3564 // Both queues are non-empty. The last update is the same in both lists,
3565 // because of structural sharing. So, only append to one of the lists.
3566 appendUpdateToQueue(queue1, update); // But we still need to update the `lastUpdate` pointer of queue2.
3567
3568 queue2.lastUpdate = update;
3569 }
3570 }
3571
3572 {
3573 if (fiber.tag === ClassComponent && (currentlyProcessingQueue === queue1 || queue2 !== null && currentlyProcessingQueue === queue2) && !didWarnUpdateInsideUpdate) {
3574 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.');
3575 didWarnUpdateInsideUpdate = true;
3576 }
3577 }
3578}
3579function enqueueCapturedUpdate(workInProgress, update) {
3580 // Captured updates go into a separate list, and only on the work-in-
3581 // progress queue.
3582 var workInProgressQueue = workInProgress.updateQueue;
3583
3584 if (workInProgressQueue === null) {
3585 workInProgressQueue = workInProgress.updateQueue = createUpdateQueue(workInProgress.memoizedState);
3586 } else {
3587 // TODO: I put this here rather than createWorkInProgress so that we don't
3588 // clone the queue unnecessarily. There's probably a better way to
3589 // structure this.
3590 workInProgressQueue = ensureWorkInProgressQueueIsAClone(workInProgress, workInProgressQueue);
3591 } // Append the update to the end of the list.
3592
3593
3594 if (workInProgressQueue.lastCapturedUpdate === null) {
3595 // This is the first render phase update
3596 workInProgressQueue.firstCapturedUpdate = workInProgressQueue.lastCapturedUpdate = update;
3597 } else {
3598 workInProgressQueue.lastCapturedUpdate.next = update;
3599 workInProgressQueue.lastCapturedUpdate = update;
3600 }
3601}
3602
3603function ensureWorkInProgressQueueIsAClone(workInProgress, queue) {
3604 var current = workInProgress.alternate;
3605
3606 if (current !== null) {
3607 // If the work-in-progress queue is equal to the current queue,
3608 // we need to clone it first.
3609 if (queue === current.updateQueue) {
3610 queue = workInProgress.updateQueue = cloneUpdateQueue(queue);
3611 }
3612 }
3613
3614 return queue;
3615}
3616
3617function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
3618 switch (update.tag) {
3619 case ReplaceState:
3620 {
3621 var payload = update.payload;
3622
3623 if (typeof payload === 'function') {
3624 // Updater function
3625 {
3626 enterDisallowedContextReadInDEV();
3627
3628 if (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3629 payload.call(instance, prevState, nextProps);
3630 }
3631 }
3632
3633 var nextState = payload.call(instance, prevState, nextProps);
3634
3635 {
3636 exitDisallowedContextReadInDEV();
3637 }
3638
3639 return nextState;
3640 } // State object
3641
3642
3643 return payload;
3644 }
3645
3646 case CaptureUpdate:
3647 {
3648 workInProgress.effectTag = workInProgress.effectTag & ~ShouldCapture | DidCapture;
3649 }
3650 // Intentional fallthrough
3651
3652 case UpdateState:
3653 {
3654 var _payload = update.payload;
3655 var partialState;
3656
3657 if (typeof _payload === 'function') {
3658 // Updater function
3659 {
3660 enterDisallowedContextReadInDEV();
3661
3662 if (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3663 _payload.call(instance, prevState, nextProps);
3664 }
3665 }
3666
3667 partialState = _payload.call(instance, prevState, nextProps);
3668
3669 {
3670 exitDisallowedContextReadInDEV();
3671 }
3672 } else {
3673 // Partial state object
3674 partialState = _payload;
3675 }
3676
3677 if (partialState === null || partialState === undefined) {
3678 // Null and undefined are treated as no-ops.
3679 return prevState;
3680 } // Merge the partial state and the previous state.
3681
3682
3683 return _assign({}, prevState, partialState);
3684 }
3685
3686 case ForceUpdate:
3687 {
3688 hasForceUpdate = true;
3689 return prevState;
3690 }
3691 }
3692
3693 return prevState;
3694}
3695
3696function processUpdateQueue(workInProgress, queue, props, instance, renderExpirationTime) {
3697 hasForceUpdate = false;
3698 queue = ensureWorkInProgressQueueIsAClone(workInProgress, queue);
3699
3700 {
3701 currentlyProcessingQueue = queue;
3702 } // These values may change as we process the queue.
3703
3704
3705 var newBaseState = queue.baseState;
3706 var newFirstUpdate = null;
3707 var newExpirationTime = NoWork; // Iterate through the list of updates to compute the result.
3708
3709 var update = queue.firstUpdate;
3710 var resultState = newBaseState;
3711
3712 while (update !== null) {
3713 var updateExpirationTime = update.expirationTime;
3714
3715 if (updateExpirationTime < renderExpirationTime) {
3716 // This update does not have sufficient priority. Skip it.
3717 if (newFirstUpdate === null) {
3718 // This is the first skipped update. It will be the first update in
3719 // the new list.
3720 newFirstUpdate = update; // Since this is the first update that was skipped, the current result
3721 // is the new base state.
3722
3723 newBaseState = resultState;
3724 } // Since this update will remain in the list, update the remaining
3725 // expiration time.
3726
3727
3728 if (newExpirationTime < updateExpirationTime) {
3729 newExpirationTime = updateExpirationTime;
3730 }
3731 } else {
3732 // This update does have sufficient priority.
3733 // Mark the event time of this update as relevant to this render pass.
3734 // TODO: This should ideally use the true event time of this update rather than
3735 // its priority which is a derived and not reverseable value.
3736 // TODO: We should skip this update if it was already committed but currently
3737 // we have no way of detecting the difference between a committed and suspended
3738 // update here.
3739 markRenderEventTimeAndConfig(updateExpirationTime, update.suspenseConfig); // Process it and compute a new result.
3740
3741 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
3742 var callback = update.callback;
3743
3744 if (callback !== null) {
3745 workInProgress.effectTag |= Callback; // Set this to null, in case it was mutated during an aborted render.
3746
3747 update.nextEffect = null;
3748
3749 if (queue.lastEffect === null) {
3750 queue.firstEffect = queue.lastEffect = update;
3751 } else {
3752 queue.lastEffect.nextEffect = update;
3753 queue.lastEffect = update;
3754 }
3755 }
3756 } // Continue to the next update.
3757
3758
3759 update = update.next;
3760 } // Separately, iterate though the list of captured updates.
3761
3762
3763 var newFirstCapturedUpdate = null;
3764 update = queue.firstCapturedUpdate;
3765
3766 while (update !== null) {
3767 var _updateExpirationTime = update.expirationTime;
3768
3769 if (_updateExpirationTime < renderExpirationTime) {
3770 // This update does not have sufficient priority. Skip it.
3771 if (newFirstCapturedUpdate === null) {
3772 // This is the first skipped captured update. It will be the first
3773 // update in the new list.
3774 newFirstCapturedUpdate = update; // If this is the first update that was skipped, the current result is
3775 // the new base state.
3776
3777 if (newFirstUpdate === null) {
3778 newBaseState = resultState;
3779 }
3780 } // Since this update will remain in the list, update the remaining
3781 // expiration time.
3782
3783
3784 if (newExpirationTime < _updateExpirationTime) {
3785 newExpirationTime = _updateExpirationTime;
3786 }
3787 } else {
3788 // This update does have sufficient priority. Process it and compute
3789 // a new result.
3790 resultState = getStateFromUpdate(workInProgress, queue, update, resultState, props, instance);
3791 var _callback = update.callback;
3792
3793 if (_callback !== null) {
3794 workInProgress.effectTag |= Callback; // Set this to null, in case it was mutated during an aborted render.
3795
3796 update.nextEffect = null;
3797
3798 if (queue.lastCapturedEffect === null) {
3799 queue.firstCapturedEffect = queue.lastCapturedEffect = update;
3800 } else {
3801 queue.lastCapturedEffect.nextEffect = update;
3802 queue.lastCapturedEffect = update;
3803 }
3804 }
3805 }
3806
3807 update = update.next;
3808 }
3809
3810 if (newFirstUpdate === null) {
3811 queue.lastUpdate = null;
3812 }
3813
3814 if (newFirstCapturedUpdate === null) {
3815 queue.lastCapturedUpdate = null;
3816 } else {
3817 workInProgress.effectTag |= Callback;
3818 }
3819
3820 if (newFirstUpdate === null && newFirstCapturedUpdate === null) {
3821 // We processed every update, without skipping. That means the new base
3822 // state is the same as the result state.
3823 newBaseState = resultState;
3824 }
3825
3826 queue.baseState = newBaseState;
3827 queue.firstUpdate = newFirstUpdate;
3828 queue.firstCapturedUpdate = newFirstCapturedUpdate; // Set the remaining expiration time to be whatever is remaining in the queue.
3829 // This should be fine because the only two other things that contribute to
3830 // expiration time are props and context. We're already in the middle of the
3831 // begin phase by the time we start processing the queue, so we've already
3832 // dealt with the props. Context in components that specify
3833 // shouldComponentUpdate is tricky; but we'll have to account for
3834 // that regardless.
3835
3836 markUnprocessedUpdateTime(newExpirationTime);
3837 workInProgress.expirationTime = newExpirationTime;
3838 workInProgress.memoizedState = resultState;
3839
3840 {
3841 currentlyProcessingQueue = null;
3842 }
3843}
3844
3845function callCallback(callback, context) {
3846 if (!(typeof callback === 'function')) {
3847 {
3848 throw Error("Invalid argument passed as callback. Expected a function. Instead received: " + callback);
3849 }
3850 }
3851
3852 callback.call(context);
3853}
3854
3855function resetHasForceUpdateBeforeProcessing() {
3856 hasForceUpdate = false;
3857}
3858function checkHasForceUpdateAfterProcessing() {
3859 return hasForceUpdate;
3860}
3861function commitUpdateQueue(finishedWork, finishedQueue, instance, renderExpirationTime) {
3862 // If the finished render included captured updates, and there are still
3863 // lower priority updates left over, we need to keep the captured updates
3864 // in the queue so that they are rebased and not dropped once we process the
3865 // queue again at the lower priority.
3866 if (finishedQueue.firstCapturedUpdate !== null) {
3867 // Join the captured update list to the end of the normal list.
3868 if (finishedQueue.lastUpdate !== null) {
3869 finishedQueue.lastUpdate.next = finishedQueue.firstCapturedUpdate;
3870 finishedQueue.lastUpdate = finishedQueue.lastCapturedUpdate;
3871 } // Clear the list of captured updates.
3872
3873
3874 finishedQueue.firstCapturedUpdate = finishedQueue.lastCapturedUpdate = null;
3875 } // Commit the effects
3876
3877
3878 commitUpdateEffects(finishedQueue.firstEffect, instance);
3879 finishedQueue.firstEffect = finishedQueue.lastEffect = null;
3880 commitUpdateEffects(finishedQueue.firstCapturedEffect, instance);
3881 finishedQueue.firstCapturedEffect = finishedQueue.lastCapturedEffect = null;
3882}
3883
3884function commitUpdateEffects(effect, instance) {
3885 while (effect !== null) {
3886 var callback = effect.callback;
3887
3888 if (callback !== null) {
3889 effect.callback = null;
3890 callCallback(callback, instance);
3891 }
3892
3893 effect = effect.nextEffect;
3894 }
3895}
3896
3897var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
3898function requestCurrentSuspenseConfig() {
3899 return ReactCurrentBatchConfig.suspense;
3900}
3901
3902var fakeInternalInstance = {};
3903var isArray$1 = Array.isArray; // React.Component uses a shared frozen object by default.
3904// We'll use it to determine whether we need to initialize legacy refs.
3905
3906var emptyRefsObject = new React.Component().refs;
3907var didWarnAboutStateAssignmentForComponent;
3908var didWarnAboutUninitializedState;
3909var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
3910var didWarnAboutLegacyLifecyclesAndDerivedState;
3911var didWarnAboutUndefinedDerivedState;
3912var warnOnUndefinedDerivedState;
3913var warnOnInvalidCallback;
3914var didWarnAboutDirectlyAssigningPropsToState;
3915var didWarnAboutContextTypeAndContextTypes;
3916var didWarnAboutInvalidateContextType;
3917
3918{
3919 didWarnAboutStateAssignmentForComponent = new Set();
3920 didWarnAboutUninitializedState = new Set();
3921 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
3922 didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
3923 didWarnAboutDirectlyAssigningPropsToState = new Set();
3924 didWarnAboutUndefinedDerivedState = new Set();
3925 didWarnAboutContextTypeAndContextTypes = new Set();
3926 didWarnAboutInvalidateContextType = new Set();
3927 var didWarnOnInvalidCallback = new Set();
3928
3929 warnOnInvalidCallback = function (callback, callerName) {
3930 if (callback === null || typeof callback === 'function') {
3931 return;
3932 }
3933
3934 var key = callerName + "_" + callback;
3935
3936 if (!didWarnOnInvalidCallback.has(key)) {
3937 didWarnOnInvalidCallback.add(key);
3938 warningWithoutStack$1(false, '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
3939 }
3940 };
3941
3942 warnOnUndefinedDerivedState = function (type, partialState) {
3943 if (partialState === undefined) {
3944 var componentName = getComponentName(type) || 'Component';
3945
3946 if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
3947 didWarnAboutUndefinedDerivedState.add(componentName);
3948 warningWithoutStack$1(false, '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
3949 }
3950 }
3951 }; // This is so gross but it's at least non-critical and can be removed if
3952 // it causes problems. This is meant to give a nicer error message for
3953 // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
3954 // ...)) which otherwise throws a "_processChildContext is not a function"
3955 // exception.
3956
3957
3958 Object.defineProperty(fakeInternalInstance, '_processChildContext', {
3959 enumerable: false,
3960 value: function () {
3961 {
3962 {
3963 throw 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).");
3964 }
3965 }
3966 }
3967 });
3968 Object.freeze(fakeInternalInstance);
3969}
3970
3971function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
3972 var prevState = workInProgress.memoizedState;
3973
3974 {
3975 if (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
3976 // Invoke the function an extra time to help detect side-effects.
3977 getDerivedStateFromProps(nextProps, prevState);
3978 }
3979 }
3980
3981 var partialState = getDerivedStateFromProps(nextProps, prevState);
3982
3983 {
3984 warnOnUndefinedDerivedState(ctor, partialState);
3985 } // Merge the partial state and the previous state.
3986
3987
3988 var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
3989 workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
3990 // base state.
3991
3992 var updateQueue = workInProgress.updateQueue;
3993
3994 if (updateQueue !== null && workInProgress.expirationTime === NoWork) {
3995 updateQueue.baseState = memoizedState;
3996 }
3997}
3998var classComponentUpdater = {
3999 isMounted: isMounted,
4000 enqueueSetState: function (inst, payload, callback) {
4001 var fiber = get(inst);
4002 var currentTime = requestCurrentTimeForUpdate();
4003 var suspenseConfig = requestCurrentSuspenseConfig();
4004 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4005 var update = createUpdate(expirationTime, suspenseConfig);
4006 update.payload = payload;
4007
4008 if (callback !== undefined && callback !== null) {
4009 {
4010 warnOnInvalidCallback(callback, 'setState');
4011 }
4012
4013 update.callback = callback;
4014 }
4015
4016 enqueueUpdate(fiber, update);
4017 scheduleWork(fiber, expirationTime);
4018 },
4019 enqueueReplaceState: function (inst, payload, callback) {
4020 var fiber = get(inst);
4021 var currentTime = requestCurrentTimeForUpdate();
4022 var suspenseConfig = requestCurrentSuspenseConfig();
4023 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4024 var update = createUpdate(expirationTime, suspenseConfig);
4025 update.tag = ReplaceState;
4026 update.payload = payload;
4027
4028 if (callback !== undefined && callback !== null) {
4029 {
4030 warnOnInvalidCallback(callback, 'replaceState');
4031 }
4032
4033 update.callback = callback;
4034 }
4035
4036 enqueueUpdate(fiber, update);
4037 scheduleWork(fiber, expirationTime);
4038 },
4039 enqueueForceUpdate: function (inst, callback) {
4040 var fiber = get(inst);
4041 var currentTime = requestCurrentTimeForUpdate();
4042 var suspenseConfig = requestCurrentSuspenseConfig();
4043 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
4044 var update = createUpdate(expirationTime, suspenseConfig);
4045 update.tag = ForceUpdate;
4046
4047 if (callback !== undefined && callback !== null) {
4048 {
4049 warnOnInvalidCallback(callback, 'forceUpdate');
4050 }
4051
4052 update.callback = callback;
4053 }
4054
4055 enqueueUpdate(fiber, update);
4056 scheduleWork(fiber, expirationTime);
4057 }
4058};
4059
4060function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
4061 var instance = workInProgress.stateNode;
4062
4063 if (typeof instance.shouldComponentUpdate === 'function') {
4064 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
4065 var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
4066 stopPhaseTimer();
4067
4068 {
4069 !(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;
4070 }
4071
4072 return shouldUpdate;
4073 }
4074
4075 if (ctor.prototype && ctor.prototype.isPureReactComponent) {
4076 return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
4077 }
4078
4079 return true;
4080}
4081
4082function checkClassInstance(workInProgress, ctor, newProps) {
4083 var instance = workInProgress.stateNode;
4084
4085 {
4086 var name = getComponentName(ctor) || 'Component';
4087 var renderPresent = instance.render;
4088
4089 if (!renderPresent) {
4090 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
4091 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
4092 } else {
4093 warningWithoutStack$1(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
4094 }
4095 }
4096
4097 var noGetInitialStateOnES6 = !instance.getInitialState || instance.getInitialState.isReactClassApproved || instance.state;
4098 !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;
4099 var noGetDefaultPropsOnES6 = !instance.getDefaultProps || instance.getDefaultProps.isReactClassApproved;
4100 !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;
4101 var noInstancePropTypes = !instance.propTypes;
4102 !noInstancePropTypes ? warningWithoutStack$1(false, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name) : void 0;
4103 var noInstanceContextType = !instance.contextType;
4104 !noInstanceContextType ? warningWithoutStack$1(false, 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name) : void 0;
4105
4106 if (disableLegacyContext) {
4107 if (ctor.childContextTypes) {
4108 warningWithoutStack$1(false, '%s uses the legacy childContextTypes API which is no longer supported. ' + 'Use React.createContext() instead.', name);
4109 }
4110
4111 if (ctor.contextTypes) {
4112 warningWithoutStack$1(false, '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with static contextType instead.', name);
4113 }
4114 } else {
4115 var noInstanceContextTypes = !instance.contextTypes;
4116 !noInstanceContextTypes ? warningWithoutStack$1(false, 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name) : void 0;
4117
4118 if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
4119 didWarnAboutContextTypeAndContextTypes.add(ctor);
4120 warningWithoutStack$1(false, '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
4121 }
4122 }
4123
4124 var noComponentShouldUpdate = typeof instance.componentShouldUpdate !== 'function';
4125 !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;
4126
4127 if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
4128 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');
4129 }
4130
4131 var noComponentDidUnmount = typeof instance.componentDidUnmount !== 'function';
4132 !noComponentDidUnmount ? warningWithoutStack$1(false, '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name) : void 0;
4133 var noComponentDidReceiveProps = typeof instance.componentDidReceiveProps !== 'function';
4134 !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;
4135 var noComponentWillRecieveProps = typeof instance.componentWillRecieveProps !== 'function';
4136 !noComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name) : void 0;
4137 var noUnsafeComponentWillRecieveProps = typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
4138 !noUnsafeComponentWillRecieveProps ? warningWithoutStack$1(false, '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name) : void 0;
4139 var hasMutatedProps = instance.props !== newProps;
4140 !(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;
4141 var noInstanceDefaultProps = !instance.defaultProps;
4142 !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;
4143
4144 if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
4145 didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
4146 warningWithoutStack$1(false, '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
4147 }
4148
4149 var noInstanceGetDerivedStateFromProps = typeof instance.getDerivedStateFromProps !== 'function';
4150 !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;
4151 var noInstanceGetDerivedStateFromCatch = typeof instance.getDerivedStateFromError !== 'function';
4152 !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;
4153 var noStaticGetSnapshotBeforeUpdate = typeof ctor.getSnapshotBeforeUpdate !== 'function';
4154 !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;
4155 var _state = instance.state;
4156
4157 if (_state && (typeof _state !== 'object' || isArray$1(_state))) {
4158 warningWithoutStack$1(false, '%s.state: must be set to an object or null', name);
4159 }
4160
4161 if (typeof instance.getChildContext === 'function') {
4162 !(typeof ctor.childContextTypes === 'object') ? warningWithoutStack$1(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name) : void 0;
4163 }
4164 }
4165}
4166
4167function adoptClassInstance(workInProgress, instance) {
4168 instance.updater = classComponentUpdater;
4169 workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
4170
4171 set$1(instance, workInProgress);
4172
4173 {
4174 instance._reactInternalInstance = fakeInternalInstance;
4175 }
4176}
4177
4178function constructClassInstance(workInProgress, ctor, props, renderExpirationTime) {
4179 var isLegacyContextConsumer = false;
4180 var unmaskedContext = emptyContextObject;
4181 var context = emptyContextObject;
4182 var contextType = ctor.contextType;
4183
4184 {
4185 if ('contextType' in ctor) {
4186 var isValid = // Allow null for conditional declaration
4187 contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
4188
4189 if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
4190 didWarnAboutInvalidateContextType.add(ctor);
4191 var addendum = '';
4192
4193 if (contextType === undefined) {
4194 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.';
4195 } else if (typeof contextType !== 'object') {
4196 addendum = ' However, it is set to a ' + typeof contextType + '.';
4197 } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
4198 addendum = ' Did you accidentally pass the Context.Provider instead?';
4199 } else if (contextType._context !== undefined) {
4200 // <Context.Consumer>
4201 addendum = ' Did you accidentally pass the Context.Consumer instead?';
4202 } else {
4203 addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
4204 }
4205
4206 warningWithoutStack$1(false, '%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum);
4207 }
4208 }
4209 }
4210
4211 if (typeof contextType === 'object' && contextType !== null) {
4212 context = readContext(contextType);
4213 } else if (!disableLegacyContext) {
4214 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4215 var contextTypes = ctor.contextTypes;
4216 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
4217 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
4218 } // Instantiate twice to help detect side-effects.
4219
4220
4221 {
4222 if (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
4223 new ctor(props, context); // eslint-disable-line no-new
4224 }
4225 }
4226
4227 var instance = new ctor(props, context);
4228 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
4229 adoptClassInstance(workInProgress, instance);
4230
4231 {
4232 if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
4233 var componentName = getComponentName(ctor) || 'Component';
4234
4235 if (!didWarnAboutUninitializedState.has(componentName)) {
4236 didWarnAboutUninitializedState.add(componentName);
4237 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);
4238 }
4239 } // If new component APIs are defined, "unsafe" lifecycles won't be called.
4240 // Warn about these lifecycles if they are present.
4241 // Don't warn about react-lifecycles-compat polyfilled methods though.
4242
4243
4244 if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
4245 var foundWillMountName = null;
4246 var foundWillReceivePropsName = null;
4247 var foundWillUpdateName = null;
4248
4249 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
4250 foundWillMountName = 'componentWillMount';
4251 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
4252 foundWillMountName = 'UNSAFE_componentWillMount';
4253 }
4254
4255 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
4256 foundWillReceivePropsName = 'componentWillReceiveProps';
4257 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
4258 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
4259 }
4260
4261 if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
4262 foundWillUpdateName = 'componentWillUpdate';
4263 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
4264 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
4265 }
4266
4267 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
4268 var _componentName = getComponentName(ctor) || 'Component';
4269
4270 var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
4271
4272 if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
4273 didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
4274 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 : '');
4275 }
4276 }
4277 }
4278 } // Cache unmasked context so we can avoid recreating masked context unless necessary.
4279 // ReactFiberContext usually updates this cache but can't for newly-created instances.
4280
4281
4282 if (isLegacyContextConsumer) {
4283 cacheContext(workInProgress, unmaskedContext, context);
4284 }
4285
4286 return instance;
4287}
4288
4289function callComponentWillMount(workInProgress, instance) {
4290 startPhaseTimer(workInProgress, 'componentWillMount');
4291 var oldState = instance.state;
4292
4293 if (typeof instance.componentWillMount === 'function') {
4294 instance.componentWillMount();
4295 }
4296
4297 if (typeof instance.UNSAFE_componentWillMount === 'function') {
4298 instance.UNSAFE_componentWillMount();
4299 }
4300
4301 stopPhaseTimer();
4302
4303 if (oldState !== instance.state) {
4304 {
4305 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');
4306 }
4307
4308 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
4309 }
4310}
4311
4312function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
4313 var oldState = instance.state;
4314 startPhaseTimer(workInProgress, 'componentWillReceiveProps');
4315
4316 if (typeof instance.componentWillReceiveProps === 'function') {
4317 instance.componentWillReceiveProps(newProps, nextContext);
4318 }
4319
4320 if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
4321 instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
4322 }
4323
4324 stopPhaseTimer();
4325
4326 if (instance.state !== oldState) {
4327 {
4328 var componentName = getComponentName(workInProgress.type) || 'Component';
4329
4330 if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
4331 didWarnAboutStateAssignmentForComponent.add(componentName);
4332 warningWithoutStack$1(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
4333 }
4334 }
4335
4336 classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
4337 }
4338} // Invokes the mount life-cycles on a previously never rendered instance.
4339
4340
4341function mountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
4342 {
4343 checkClassInstance(workInProgress, ctor, newProps);
4344 }
4345
4346 var instance = workInProgress.stateNode;
4347 instance.props = newProps;
4348 instance.state = workInProgress.memoizedState;
4349 instance.refs = emptyRefsObject;
4350 var contextType = ctor.contextType;
4351
4352 if (typeof contextType === 'object' && contextType !== null) {
4353 instance.context = readContext(contextType);
4354 } else if (disableLegacyContext) {
4355 instance.context = emptyContextObject;
4356 } else {
4357 var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4358 instance.context = getMaskedContext(workInProgress, unmaskedContext);
4359 }
4360
4361 {
4362 if (instance.state === newProps) {
4363 var componentName = getComponentName(ctor) || 'Component';
4364
4365 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
4366 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
4367 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);
4368 }
4369 }
4370
4371 if (workInProgress.mode & StrictMode) {
4372 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
4373 }
4374
4375 if (warnAboutDeprecatedLifecycles) {
4376 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
4377 }
4378 }
4379
4380 var updateQueue = workInProgress.updateQueue;
4381
4382 if (updateQueue !== null) {
4383 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4384 instance.state = workInProgress.memoizedState;
4385 }
4386
4387 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4388
4389 if (typeof getDerivedStateFromProps === 'function') {
4390 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4391 instance.state = workInProgress.memoizedState;
4392 } // In order to support react-lifecycles-compat polyfilled components,
4393 // Unsafe lifecycles should not be invoked for components using the new APIs.
4394
4395
4396 if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
4397 callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
4398 // process them now.
4399
4400 updateQueue = workInProgress.updateQueue;
4401
4402 if (updateQueue !== null) {
4403 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4404 instance.state = workInProgress.memoizedState;
4405 }
4406 }
4407
4408 if (typeof instance.componentDidMount === 'function') {
4409 workInProgress.effectTag |= Update;
4410 }
4411}
4412
4413function resumeMountClassInstance(workInProgress, ctor, newProps, renderExpirationTime) {
4414 var instance = workInProgress.stateNode;
4415 var oldProps = workInProgress.memoizedProps;
4416 instance.props = oldProps;
4417 var oldContext = instance.context;
4418 var contextType = ctor.contextType;
4419 var nextContext = emptyContextObject;
4420
4421 if (typeof contextType === 'object' && contextType !== null) {
4422 nextContext = readContext(contextType);
4423 } else if (!disableLegacyContext) {
4424 var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4425 nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
4426 }
4427
4428 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4429 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
4430 // ever the previously attempted to render - not the "current". However,
4431 // during componentDidUpdate we pass the "current" props.
4432 // In order to support react-lifecycles-compat polyfilled components,
4433 // Unsafe lifecycles should not be invoked for components using the new APIs.
4434
4435 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
4436 if (oldProps !== newProps || oldContext !== nextContext) {
4437 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
4438 }
4439 }
4440
4441 resetHasForceUpdateBeforeProcessing();
4442 var oldState = workInProgress.memoizedState;
4443 var newState = instance.state = oldState;
4444 var updateQueue = workInProgress.updateQueue;
4445
4446 if (updateQueue !== null) {
4447 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4448 newState = workInProgress.memoizedState;
4449 }
4450
4451 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
4452 // If an update was already in progress, we should schedule an Update
4453 // effect even though we're bailing out, so that cWU/cDU are called.
4454 if (typeof instance.componentDidMount === 'function') {
4455 workInProgress.effectTag |= Update;
4456 }
4457
4458 return false;
4459 }
4460
4461 if (typeof getDerivedStateFromProps === 'function') {
4462 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4463 newState = workInProgress.memoizedState;
4464 }
4465
4466 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
4467
4468 if (shouldUpdate) {
4469 // In order to support react-lifecycles-compat polyfilled components,
4470 // Unsafe lifecycles should not be invoked for components using the new APIs.
4471 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
4472 startPhaseTimer(workInProgress, 'componentWillMount');
4473
4474 if (typeof instance.componentWillMount === 'function') {
4475 instance.componentWillMount();
4476 }
4477
4478 if (typeof instance.UNSAFE_componentWillMount === 'function') {
4479 instance.UNSAFE_componentWillMount();
4480 }
4481
4482 stopPhaseTimer();
4483 }
4484
4485 if (typeof instance.componentDidMount === 'function') {
4486 workInProgress.effectTag |= Update;
4487 }
4488 } else {
4489 // If an update was already in progress, we should schedule an Update
4490 // effect even though we're bailing out, so that cWU/cDU are called.
4491 if (typeof instance.componentDidMount === 'function') {
4492 workInProgress.effectTag |= Update;
4493 } // If shouldComponentUpdate returned false, we should still update the
4494 // memoized state to indicate that this work can be reused.
4495
4496
4497 workInProgress.memoizedProps = newProps;
4498 workInProgress.memoizedState = newState;
4499 } // Update the existing instance's state, props, and context pointers even
4500 // if shouldComponentUpdate returns false.
4501
4502
4503 instance.props = newProps;
4504 instance.state = newState;
4505 instance.context = nextContext;
4506 return shouldUpdate;
4507} // Invokes the update life-cycles and returns false if it shouldn't rerender.
4508
4509
4510function updateClassInstance(current, workInProgress, ctor, newProps, renderExpirationTime) {
4511 var instance = workInProgress.stateNode;
4512 var oldProps = workInProgress.memoizedProps;
4513 instance.props = workInProgress.type === workInProgress.elementType ? oldProps : resolveDefaultProps(workInProgress.type, oldProps);
4514 var oldContext = instance.context;
4515 var contextType = ctor.contextType;
4516 var nextContext = emptyContextObject;
4517
4518 if (typeof contextType === 'object' && contextType !== null) {
4519 nextContext = readContext(contextType);
4520 } else if (!disableLegacyContext) {
4521 var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
4522 nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
4523 }
4524
4525 var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
4526 var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
4527 // ever the previously attempted to render - not the "current". However,
4528 // during componentDidUpdate we pass the "current" props.
4529 // In order to support react-lifecycles-compat polyfilled components,
4530 // Unsafe lifecycles should not be invoked for components using the new APIs.
4531
4532 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
4533 if (oldProps !== newProps || oldContext !== nextContext) {
4534 callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
4535 }
4536 }
4537
4538 resetHasForceUpdateBeforeProcessing();
4539 var oldState = workInProgress.memoizedState;
4540 var newState = instance.state = oldState;
4541 var updateQueue = workInProgress.updateQueue;
4542
4543 if (updateQueue !== null) {
4544 processUpdateQueue(workInProgress, updateQueue, newProps, instance, renderExpirationTime);
4545 newState = workInProgress.memoizedState;
4546 }
4547
4548 if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
4549 // If an update was already in progress, we should schedule an Update
4550 // effect even though we're bailing out, so that cWU/cDU are called.
4551 if (typeof instance.componentDidUpdate === 'function') {
4552 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4553 workInProgress.effectTag |= Update;
4554 }
4555 }
4556
4557 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4558 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4559 workInProgress.effectTag |= Snapshot;
4560 }
4561 }
4562
4563 return false;
4564 }
4565
4566 if (typeof getDerivedStateFromProps === 'function') {
4567 applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
4568 newState = workInProgress.memoizedState;
4569 }
4570
4571 var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
4572
4573 if (shouldUpdate) {
4574 // In order to support react-lifecycles-compat polyfilled components,
4575 // Unsafe lifecycles should not be invoked for components using the new APIs.
4576 if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
4577 startPhaseTimer(workInProgress, 'componentWillUpdate');
4578
4579 if (typeof instance.componentWillUpdate === 'function') {
4580 instance.componentWillUpdate(newProps, newState, nextContext);
4581 }
4582
4583 if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
4584 instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
4585 }
4586
4587 stopPhaseTimer();
4588 }
4589
4590 if (typeof instance.componentDidUpdate === 'function') {
4591 workInProgress.effectTag |= Update;
4592 }
4593
4594 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4595 workInProgress.effectTag |= Snapshot;
4596 }
4597 } else {
4598 // If an update was already in progress, we should schedule an Update
4599 // effect even though we're bailing out, so that cWU/cDU are called.
4600 if (typeof instance.componentDidUpdate === 'function') {
4601 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4602 workInProgress.effectTag |= Update;
4603 }
4604 }
4605
4606 if (typeof instance.getSnapshotBeforeUpdate === 'function') {
4607 if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) {
4608 workInProgress.effectTag |= Snapshot;
4609 }
4610 } // If shouldComponentUpdate returned false, we should still update the
4611 // memoized props/state to indicate that this work can be reused.
4612
4613
4614 workInProgress.memoizedProps = newProps;
4615 workInProgress.memoizedState = newState;
4616 } // Update the existing instance's state, props, and context pointers even
4617 // if shouldComponentUpdate returns false.
4618
4619
4620 instance.props = newProps;
4621 instance.state = newState;
4622 instance.context = nextContext;
4623 return shouldUpdate;
4624}
4625
4626var didWarnAboutMaps;
4627var didWarnAboutGenerators;
4628var didWarnAboutStringRefs;
4629var ownerHasKeyUseWarning;
4630var ownerHasFunctionTypeWarning;
4631
4632var warnForMissingKey = function (child) {};
4633
4634{
4635 didWarnAboutMaps = false;
4636 didWarnAboutGenerators = false;
4637 didWarnAboutStringRefs = {};
4638 /**
4639 * Warn if there's no key explicitly set on dynamic arrays of children or
4640 * object keys are not valid. This allows us to keep track of children between
4641 * updates.
4642 */
4643
4644 ownerHasKeyUseWarning = {};
4645 ownerHasFunctionTypeWarning = {};
4646
4647 warnForMissingKey = function (child) {
4648 if (child === null || typeof child !== 'object') {
4649 return;
4650 }
4651
4652 if (!child._store || child._store.validated || child.key != null) {
4653 return;
4654 }
4655
4656 if (!(typeof child._store === 'object')) {
4657 {
4658 throw Error("React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue.");
4659 }
4660 }
4661
4662 child._store.validated = true;
4663 var currentComponentErrorInfo = 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev();
4664
4665 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
4666 return;
4667 }
4668
4669 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
4670 warning$1(false, 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.');
4671 };
4672}
4673
4674var isArray = Array.isArray;
4675
4676function coerceRef(returnFiber, current$$1, element) {
4677 var mixedRef = element.ref;
4678
4679 if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
4680 {
4681 // TODO: Clean this up once we turn on the string ref warning for
4682 // everyone, because the strict mode case will no longer be relevant
4683 if (returnFiber.mode & StrictMode || warnAboutStringRefs) {
4684 var componentName = getComponentName(returnFiber.type) || 'Component';
4685
4686 if (!didWarnAboutStringRefs[componentName]) {
4687 if (warnAboutStringRefs) {
4688 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));
4689 } else {
4690 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));
4691 }
4692
4693 didWarnAboutStringRefs[componentName] = true;
4694 }
4695 }
4696 }
4697
4698 if (element._owner) {
4699 var owner = element._owner;
4700 var inst;
4701
4702 if (owner) {
4703 var ownerFiber = owner;
4704
4705 if (!(ownerFiber.tag === ClassComponent)) {
4706 {
4707 throw Error("Function components cannot have refs. Did you mean to use React.forwardRef()?");
4708 }
4709 }
4710
4711 inst = ownerFiber.stateNode;
4712 }
4713
4714 if (!inst) {
4715 {
4716 throw Error("Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue.");
4717 }
4718 }
4719
4720 var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
4721
4722 if (current$$1 !== null && current$$1.ref !== null && typeof current$$1.ref === 'function' && current$$1.ref._stringRef === stringRef) {
4723 return current$$1.ref;
4724 }
4725
4726 var ref = function (value) {
4727 var refs = inst.refs;
4728
4729 if (refs === emptyRefsObject) {
4730 // This is a lazy pooled frozen object, so we need to initialize.
4731 refs = inst.refs = {};
4732 }
4733
4734 if (value === null) {
4735 delete refs[stringRef];
4736 } else {
4737 refs[stringRef] = value;
4738 }
4739 };
4740
4741 ref._stringRef = stringRef;
4742 return ref;
4743 } else {
4744 if (!(typeof mixedRef === 'string')) {
4745 {
4746 throw Error("Expected ref to be a function, a string, an object returned by React.createRef(), or null.");
4747 }
4748 }
4749
4750 if (!element._owner) {
4751 {
4752 throw 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.");
4753 }
4754 }
4755 }
4756 }
4757
4758 return mixedRef;
4759}
4760
4761function throwOnInvalidObjectType(returnFiber, newChild) {
4762 if (returnFiber.type !== 'textarea') {
4763 var addendum = '';
4764
4765 {
4766 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getCurrentFiberStackInDev();
4767 }
4768
4769 {
4770 {
4771 throw 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);
4772 }
4773 }
4774 }
4775}
4776
4777function warnOnFunctionType() {
4778 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();
4779
4780 if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
4781 return;
4782 }
4783
4784 ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
4785 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.');
4786} // This wrapper function exists because I expect to clone the code in each path
4787// to be able to optimize each path individually by branching early. This needs
4788// a compiler or we can do it manually. Helpers that don't need this branching
4789// live outside of this function.
4790
4791
4792function ChildReconciler(shouldTrackSideEffects) {
4793 function deleteChild(returnFiber, childToDelete) {
4794 if (!shouldTrackSideEffects) {
4795 // Noop.
4796 return;
4797 } // Deletions are added in reversed order so we add it to the front.
4798 // At this point, the return fiber's effect list is empty except for
4799 // deletions, so we can just append the deletion to the list. The remaining
4800 // effects aren't added until the complete phase. Once we implement
4801 // resuming, this may not be true.
4802
4803
4804 var last = returnFiber.lastEffect;
4805
4806 if (last !== null) {
4807 last.nextEffect = childToDelete;
4808 returnFiber.lastEffect = childToDelete;
4809 } else {
4810 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
4811 }
4812
4813 childToDelete.nextEffect = null;
4814 childToDelete.effectTag = Deletion;
4815 }
4816
4817 function deleteRemainingChildren(returnFiber, currentFirstChild) {
4818 if (!shouldTrackSideEffects) {
4819 // Noop.
4820 return null;
4821 } // TODO: For the shouldClone case, this could be micro-optimized a bit by
4822 // assuming that after the first child we've already added everything.
4823
4824
4825 var childToDelete = currentFirstChild;
4826
4827 while (childToDelete !== null) {
4828 deleteChild(returnFiber, childToDelete);
4829 childToDelete = childToDelete.sibling;
4830 }
4831
4832 return null;
4833 }
4834
4835 function mapRemainingChildren(returnFiber, currentFirstChild) {
4836 // Add the remaining children to a temporary map so that we can find them by
4837 // keys quickly. Implicit (null) keys get added to this set with their index
4838 // instead.
4839 var existingChildren = new Map();
4840 var existingChild = currentFirstChild;
4841
4842 while (existingChild !== null) {
4843 if (existingChild.key !== null) {
4844 existingChildren.set(existingChild.key, existingChild);
4845 } else {
4846 existingChildren.set(existingChild.index, existingChild);
4847 }
4848
4849 existingChild = existingChild.sibling;
4850 }
4851
4852 return existingChildren;
4853 }
4854
4855 function useFiber(fiber, pendingProps, expirationTime) {
4856 // We currently set sibling to null and index to 0 here because it is easy
4857 // to forget to do before returning it. E.g. for the single child case.
4858 var clone = createWorkInProgress(fiber, pendingProps, expirationTime);
4859 clone.index = 0;
4860 clone.sibling = null;
4861 return clone;
4862 }
4863
4864 function placeChild(newFiber, lastPlacedIndex, newIndex) {
4865 newFiber.index = newIndex;
4866
4867 if (!shouldTrackSideEffects) {
4868 // Noop.
4869 return lastPlacedIndex;
4870 }
4871
4872 var current$$1 = newFiber.alternate;
4873
4874 if (current$$1 !== null) {
4875 var oldIndex = current$$1.index;
4876
4877 if (oldIndex < lastPlacedIndex) {
4878 // This is a move.
4879 newFiber.effectTag = Placement;
4880 return lastPlacedIndex;
4881 } else {
4882 // This item can stay in place.
4883 return oldIndex;
4884 }
4885 } else {
4886 // This is an insertion.
4887 newFiber.effectTag = Placement;
4888 return lastPlacedIndex;
4889 }
4890 }
4891
4892 function placeSingleChild(newFiber) {
4893 // This is simpler for the single child case. We only need to do a
4894 // placement for inserting new children.
4895 if (shouldTrackSideEffects && newFiber.alternate === null) {
4896 newFiber.effectTag = Placement;
4897 }
4898
4899 return newFiber;
4900 }
4901
4902 function updateTextNode(returnFiber, current$$1, textContent, expirationTime) {
4903 if (current$$1 === null || current$$1.tag !== HostText) {
4904 // Insert
4905 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
4906 created.return = returnFiber;
4907 return created;
4908 } else {
4909 // Update
4910 var existing = useFiber(current$$1, textContent, expirationTime);
4911 existing.return = returnFiber;
4912 return existing;
4913 }
4914 }
4915
4916 function updateElement(returnFiber, current$$1, element, expirationTime) {
4917 if (current$$1 !== null && (current$$1.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
4918 isCompatibleFamilyForHotReloading(current$$1, element)))) {
4919 // Move based on index
4920 var existing = useFiber(current$$1, element.props, expirationTime);
4921 existing.ref = coerceRef(returnFiber, current$$1, element);
4922 existing.return = returnFiber;
4923
4924 {
4925 existing._debugSource = element._source;
4926 existing._debugOwner = element._owner;
4927 }
4928
4929 return existing;
4930 } else {
4931 // Insert
4932 var created = createFiberFromElement(element, returnFiber.mode, expirationTime);
4933 created.ref = coerceRef(returnFiber, current$$1, element);
4934 created.return = returnFiber;
4935 return created;
4936 }
4937 }
4938
4939 function updatePortal(returnFiber, current$$1, portal, expirationTime) {
4940 if (current$$1 === null || current$$1.tag !== HostPortal || current$$1.stateNode.containerInfo !== portal.containerInfo || current$$1.stateNode.implementation !== portal.implementation) {
4941 // Insert
4942 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
4943 created.return = returnFiber;
4944 return created;
4945 } else {
4946 // Update
4947 var existing = useFiber(current$$1, portal.children || [], expirationTime);
4948 existing.return = returnFiber;
4949 return existing;
4950 }
4951 }
4952
4953 function updateFragment(returnFiber, current$$1, fragment, expirationTime, key) {
4954 if (current$$1 === null || current$$1.tag !== Fragment) {
4955 // Insert
4956 var created = createFiberFromFragment(fragment, returnFiber.mode, expirationTime, key);
4957 created.return = returnFiber;
4958 return created;
4959 } else {
4960 // Update
4961 var existing = useFiber(current$$1, fragment, expirationTime);
4962 existing.return = returnFiber;
4963 return existing;
4964 }
4965 }
4966
4967 function createChild(returnFiber, newChild, expirationTime) {
4968 if (typeof newChild === 'string' || typeof newChild === 'number') {
4969 // Text nodes don't have keys. If the previous node is implicitly keyed
4970 // we can continue to replace it without aborting even if it is not a text
4971 // node.
4972 var created = createFiberFromText('' + newChild, returnFiber.mode, expirationTime);
4973 created.return = returnFiber;
4974 return created;
4975 }
4976
4977 if (typeof newChild === 'object' && newChild !== null) {
4978 switch (newChild.$$typeof) {
4979 case REACT_ELEMENT_TYPE$1:
4980 {
4981 var _created = createFiberFromElement(newChild, returnFiber.mode, expirationTime);
4982
4983 _created.ref = coerceRef(returnFiber, null, newChild);
4984 _created.return = returnFiber;
4985 return _created;
4986 }
4987
4988 case REACT_PORTAL_TYPE:
4989 {
4990 var _created2 = createFiberFromPortal(newChild, returnFiber.mode, expirationTime);
4991
4992 _created2.return = returnFiber;
4993 return _created2;
4994 }
4995 }
4996
4997 if (isArray(newChild) || getIteratorFn(newChild)) {
4998 var _created3 = createFiberFromFragment(newChild, returnFiber.mode, expirationTime, null);
4999
5000 _created3.return = returnFiber;
5001 return _created3;
5002 }
5003
5004 throwOnInvalidObjectType(returnFiber, newChild);
5005 }
5006
5007 {
5008 if (typeof newChild === 'function') {
5009 warnOnFunctionType();
5010 }
5011 }
5012
5013 return null;
5014 }
5015
5016 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
5017 // Update the fiber if the keys match, otherwise return null.
5018 var key = oldFiber !== null ? oldFiber.key : null;
5019
5020 if (typeof newChild === 'string' || typeof newChild === 'number') {
5021 // Text nodes don't have keys. If the previous node is implicitly keyed
5022 // we can continue to replace it without aborting even if it is not a text
5023 // node.
5024 if (key !== null) {
5025 return null;
5026 }
5027
5028 return updateTextNode(returnFiber, oldFiber, '' + newChild, expirationTime);
5029 }
5030
5031 if (typeof newChild === 'object' && newChild !== null) {
5032 switch (newChild.$$typeof) {
5033 case REACT_ELEMENT_TYPE$1:
5034 {
5035 if (newChild.key === key) {
5036 if (newChild.type === REACT_FRAGMENT_TYPE) {
5037 return updateFragment(returnFiber, oldFiber, newChild.props.children, expirationTime, key);
5038 }
5039
5040 return updateElement(returnFiber, oldFiber, newChild, expirationTime);
5041 } else {
5042 return null;
5043 }
5044 }
5045
5046 case REACT_PORTAL_TYPE:
5047 {
5048 if (newChild.key === key) {
5049 return updatePortal(returnFiber, oldFiber, newChild, expirationTime);
5050 } else {
5051 return null;
5052 }
5053 }
5054 }
5055
5056 if (isArray(newChild) || getIteratorFn(newChild)) {
5057 if (key !== null) {
5058 return null;
5059 }
5060
5061 return updateFragment(returnFiber, oldFiber, newChild, expirationTime, null);
5062 }
5063
5064 throwOnInvalidObjectType(returnFiber, newChild);
5065 }
5066
5067 {
5068 if (typeof newChild === 'function') {
5069 warnOnFunctionType();
5070 }
5071 }
5072
5073 return null;
5074 }
5075
5076 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, expirationTime) {
5077 if (typeof newChild === 'string' || typeof newChild === 'number') {
5078 // Text nodes don't have keys, so we neither have to check the old nor
5079 // new node for the key. If both are text nodes, they match.
5080 var matchedFiber = existingChildren.get(newIdx) || null;
5081 return updateTextNode(returnFiber, matchedFiber, '' + newChild, expirationTime);
5082 }
5083
5084 if (typeof newChild === 'object' && newChild !== null) {
5085 switch (newChild.$$typeof) {
5086 case REACT_ELEMENT_TYPE$1:
5087 {
5088 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
5089
5090 if (newChild.type === REACT_FRAGMENT_TYPE) {
5091 return updateFragment(returnFiber, _matchedFiber, newChild.props.children, expirationTime, newChild.key);
5092 }
5093
5094 return updateElement(returnFiber, _matchedFiber, newChild, expirationTime);
5095 }
5096
5097 case REACT_PORTAL_TYPE:
5098 {
5099 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
5100
5101 return updatePortal(returnFiber, _matchedFiber2, newChild, expirationTime);
5102 }
5103 }
5104
5105 if (isArray(newChild) || getIteratorFn(newChild)) {
5106 var _matchedFiber3 = existingChildren.get(newIdx) || null;
5107
5108 return updateFragment(returnFiber, _matchedFiber3, newChild, expirationTime, null);
5109 }
5110
5111 throwOnInvalidObjectType(returnFiber, newChild);
5112 }
5113
5114 {
5115 if (typeof newChild === 'function') {
5116 warnOnFunctionType();
5117 }
5118 }
5119
5120 return null;
5121 }
5122 /**
5123 * Warns if there is a duplicate or missing key
5124 */
5125
5126
5127 function warnOnInvalidKey(child, knownKeys) {
5128 {
5129 if (typeof child !== 'object' || child === null) {
5130 return knownKeys;
5131 }
5132
5133 switch (child.$$typeof) {
5134 case REACT_ELEMENT_TYPE$1:
5135 case REACT_PORTAL_TYPE:
5136 warnForMissingKey(child);
5137 var key = child.key;
5138
5139 if (typeof key !== 'string') {
5140 break;
5141 }
5142
5143 if (knownKeys === null) {
5144 knownKeys = new Set();
5145 knownKeys.add(key);
5146 break;
5147 }
5148
5149 if (!knownKeys.has(key)) {
5150 knownKeys.add(key);
5151 break;
5152 }
5153
5154 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);
5155 break;
5156
5157 default:
5158 break;
5159 }
5160 }
5161
5162 return knownKeys;
5163 }
5164
5165 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) {
5166 // This algorithm can't optimize by searching from both ends since we
5167 // don't have backpointers on fibers. I'm trying to see how far we can get
5168 // with that model. If it ends up not being worth the tradeoffs, we can
5169 // add it later.
5170 // Even with a two ended optimization, we'd want to optimize for the case
5171 // where there are few changes and brute force the comparison instead of
5172 // going for the Map. It'd like to explore hitting that path first in
5173 // forward-only mode and only go for the Map once we notice that we need
5174 // lots of look ahead. This doesn't handle reversal as well as two ended
5175 // search but that's unusual. Besides, for the two ended optimization to
5176 // work on Iterables, we'd need to copy the whole set.
5177 // In this first iteration, we'll just live with hitting the bad case
5178 // (adding everything to a Map) in for every insert/move.
5179 // If you change this code, also update reconcileChildrenIterator() which
5180 // uses the same algorithm.
5181 {
5182 // First, validate keys.
5183 var knownKeys = null;
5184
5185 for (var i = 0; i < newChildren.length; i++) {
5186 var child = newChildren[i];
5187 knownKeys = warnOnInvalidKey(child, knownKeys);
5188 }
5189 }
5190
5191 var resultingFirstChild = null;
5192 var previousNewFiber = null;
5193 var oldFiber = currentFirstChild;
5194 var lastPlacedIndex = 0;
5195 var newIdx = 0;
5196 var nextOldFiber = null;
5197
5198 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
5199 if (oldFiber.index > newIdx) {
5200 nextOldFiber = oldFiber;
5201 oldFiber = null;
5202 } else {
5203 nextOldFiber = oldFiber.sibling;
5204 }
5205
5206 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime);
5207
5208 if (newFiber === null) {
5209 // TODO: This breaks on empty slots like null children. That's
5210 // unfortunate because it triggers the slow path all the time. We need
5211 // a better way to communicate whether this was a miss or null,
5212 // boolean, undefined, etc.
5213 if (oldFiber === null) {
5214 oldFiber = nextOldFiber;
5215 }
5216
5217 break;
5218 }
5219
5220 if (shouldTrackSideEffects) {
5221 if (oldFiber && newFiber.alternate === null) {
5222 // We matched the slot, but we didn't reuse the existing fiber, so we
5223 // need to delete the existing child.
5224 deleteChild(returnFiber, oldFiber);
5225 }
5226 }
5227
5228 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
5229
5230 if (previousNewFiber === null) {
5231 // TODO: Move out of the loop. This only happens for the first run.
5232 resultingFirstChild = newFiber;
5233 } else {
5234 // TODO: Defer siblings if we're not at the right index for this slot.
5235 // I.e. if we had null values before, then we want to defer this
5236 // for each null value. However, we also don't want to call updateSlot
5237 // with the previous one.
5238 previousNewFiber.sibling = newFiber;
5239 }
5240
5241 previousNewFiber = newFiber;
5242 oldFiber = nextOldFiber;
5243 }
5244
5245 if (newIdx === newChildren.length) {
5246 // We've reached the end of the new children. We can delete the rest.
5247 deleteRemainingChildren(returnFiber, oldFiber);
5248 return resultingFirstChild;
5249 }
5250
5251 if (oldFiber === null) {
5252 // If we don't have any more existing children we can choose a fast path
5253 // since the rest will all be insertions.
5254 for (; newIdx < newChildren.length; newIdx++) {
5255 var _newFiber = createChild(returnFiber, newChildren[newIdx], expirationTime);
5256
5257 if (_newFiber === null) {
5258 continue;
5259 }
5260
5261 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
5262
5263 if (previousNewFiber === null) {
5264 // TODO: Move out of the loop. This only happens for the first run.
5265 resultingFirstChild = _newFiber;
5266 } else {
5267 previousNewFiber.sibling = _newFiber;
5268 }
5269
5270 previousNewFiber = _newFiber;
5271 }
5272
5273 return resultingFirstChild;
5274 } // Add all children to a key map for quick lookups.
5275
5276
5277 var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
5278
5279 for (; newIdx < newChildren.length; newIdx++) {
5280 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], expirationTime);
5281
5282 if (_newFiber2 !== null) {
5283 if (shouldTrackSideEffects) {
5284 if (_newFiber2.alternate !== null) {
5285 // The new fiber is a work in progress, but if there exists a
5286 // current, that means that we reused the fiber. We need to delete
5287 // it from the child list so that we don't add it to the deletion
5288 // list.
5289 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
5290 }
5291 }
5292
5293 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
5294
5295 if (previousNewFiber === null) {
5296 resultingFirstChild = _newFiber2;
5297 } else {
5298 previousNewFiber.sibling = _newFiber2;
5299 }
5300
5301 previousNewFiber = _newFiber2;
5302 }
5303 }
5304
5305 if (shouldTrackSideEffects) {
5306 // Any existing children that weren't consumed above were deleted. We need
5307 // to add them to the deletion list.
5308 existingChildren.forEach(function (child) {
5309 return deleteChild(returnFiber, child);
5310 });
5311 }
5312
5313 return resultingFirstChild;
5314 }
5315
5316 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, expirationTime) {
5317 // This is the same implementation as reconcileChildrenArray(),
5318 // but using the iterator instead.
5319 var iteratorFn = getIteratorFn(newChildrenIterable);
5320
5321 if (!(typeof iteratorFn === 'function')) {
5322 {
5323 throw Error("An object is not an iterable. This error is likely caused by a bug in React. Please file an issue.");
5324 }
5325 }
5326
5327 {
5328 // We don't support rendering Generators because it's a mutation.
5329 // See https://github.com/facebook/react/issues/12995
5330 if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
5331 newChildrenIterable[Symbol.toStringTag] === 'Generator') {
5332 !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;
5333 didWarnAboutGenerators = true;
5334 } // Warn about using Maps as children
5335
5336
5337 if (newChildrenIterable.entries === iteratorFn) {
5338 !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;
5339 didWarnAboutMaps = true;
5340 } // First, validate keys.
5341 // We'll get a different iterator later for the main pass.
5342
5343
5344 var _newChildren = iteratorFn.call(newChildrenIterable);
5345
5346 if (_newChildren) {
5347 var knownKeys = null;
5348
5349 var _step = _newChildren.next();
5350
5351 for (; !_step.done; _step = _newChildren.next()) {
5352 var child = _step.value;
5353 knownKeys = warnOnInvalidKey(child, knownKeys);
5354 }
5355 }
5356 }
5357
5358 var newChildren = iteratorFn.call(newChildrenIterable);
5359
5360 if (!(newChildren != null)) {
5361 {
5362 throw Error("An iterable object provided no iterator.");
5363 }
5364 }
5365
5366 var resultingFirstChild = null;
5367 var previousNewFiber = null;
5368 var oldFiber = currentFirstChild;
5369 var lastPlacedIndex = 0;
5370 var newIdx = 0;
5371 var nextOldFiber = null;
5372 var step = newChildren.next();
5373
5374 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
5375 if (oldFiber.index > newIdx) {
5376 nextOldFiber = oldFiber;
5377 oldFiber = null;
5378 } else {
5379 nextOldFiber = oldFiber.sibling;
5380 }
5381
5382 var newFiber = updateSlot(returnFiber, oldFiber, step.value, expirationTime);
5383
5384 if (newFiber === null) {
5385 // TODO: This breaks on empty slots like null children. That's
5386 // unfortunate because it triggers the slow path all the time. We need
5387 // a better way to communicate whether this was a miss or null,
5388 // boolean, undefined, etc.
5389 if (oldFiber === null) {
5390 oldFiber = nextOldFiber;
5391 }
5392
5393 break;
5394 }
5395
5396 if (shouldTrackSideEffects) {
5397 if (oldFiber && newFiber.alternate === null) {
5398 // We matched the slot, but we didn't reuse the existing fiber, so we
5399 // need to delete the existing child.
5400 deleteChild(returnFiber, oldFiber);
5401 }
5402 }
5403
5404 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
5405
5406 if (previousNewFiber === null) {
5407 // TODO: Move out of the loop. This only happens for the first run.
5408 resultingFirstChild = newFiber;
5409 } else {
5410 // TODO: Defer siblings if we're not at the right index for this slot.
5411 // I.e. if we had null values before, then we want to defer this
5412 // for each null value. However, we also don't want to call updateSlot
5413 // with the previous one.
5414 previousNewFiber.sibling = newFiber;
5415 }
5416
5417 previousNewFiber = newFiber;
5418 oldFiber = nextOldFiber;
5419 }
5420
5421 if (step.done) {
5422 // We've reached the end of the new children. We can delete the rest.
5423 deleteRemainingChildren(returnFiber, oldFiber);
5424 return resultingFirstChild;
5425 }
5426
5427 if (oldFiber === null) {
5428 // If we don't have any more existing children we can choose a fast path
5429 // since the rest will all be insertions.
5430 for (; !step.done; newIdx++, step = newChildren.next()) {
5431 var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
5432
5433 if (_newFiber3 === null) {
5434 continue;
5435 }
5436
5437 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
5438
5439 if (previousNewFiber === null) {
5440 // TODO: Move out of the loop. This only happens for the first run.
5441 resultingFirstChild = _newFiber3;
5442 } else {
5443 previousNewFiber.sibling = _newFiber3;
5444 }
5445
5446 previousNewFiber = _newFiber3;
5447 }
5448
5449 return resultingFirstChild;
5450 } // Add all children to a key map for quick lookups.
5451
5452
5453 var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
5454
5455 for (; !step.done; newIdx++, step = newChildren.next()) {
5456 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, expirationTime);
5457
5458 if (_newFiber4 !== null) {
5459 if (shouldTrackSideEffects) {
5460 if (_newFiber4.alternate !== null) {
5461 // The new fiber is a work in progress, but if there exists a
5462 // current, that means that we reused the fiber. We need to delete
5463 // it from the child list so that we don't add it to the deletion
5464 // list.
5465 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
5466 }
5467 }
5468
5469 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
5470
5471 if (previousNewFiber === null) {
5472 resultingFirstChild = _newFiber4;
5473 } else {
5474 previousNewFiber.sibling = _newFiber4;
5475 }
5476
5477 previousNewFiber = _newFiber4;
5478 }
5479 }
5480
5481 if (shouldTrackSideEffects) {
5482 // Any existing children that weren't consumed above were deleted. We need
5483 // to add them to the deletion list.
5484 existingChildren.forEach(function (child) {
5485 return deleteChild(returnFiber, child);
5486 });
5487 }
5488
5489 return resultingFirstChild;
5490 }
5491
5492 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, expirationTime) {
5493 // There's no need to check for keys on text nodes since we don't have a
5494 // way to define them.
5495 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
5496 // We already have an existing node so let's just update it and delete
5497 // the rest.
5498 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
5499 var existing = useFiber(currentFirstChild, textContent, expirationTime);
5500 existing.return = returnFiber;
5501 return existing;
5502 } // The existing first child is not a text node so we need to create one
5503 // and delete the existing ones.
5504
5505
5506 deleteRemainingChildren(returnFiber, currentFirstChild);
5507 var created = createFiberFromText(textContent, returnFiber.mode, expirationTime);
5508 created.return = returnFiber;
5509 return created;
5510 }
5511
5512 function reconcileSingleElement(returnFiber, currentFirstChild, element, expirationTime) {
5513 var key = element.key;
5514 var child = currentFirstChild;
5515
5516 while (child !== null) {
5517 // TODO: If key === null and child.key === null, then this only applies to
5518 // the first item in the list.
5519 if (child.key === key) {
5520 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:
5521 isCompatibleFamilyForHotReloading(child, element))) {
5522 deleteRemainingChildren(returnFiber, child.sibling);
5523 var existing = useFiber(child, element.type === REACT_FRAGMENT_TYPE ? element.props.children : element.props, expirationTime);
5524 existing.ref = coerceRef(returnFiber, child, element);
5525 existing.return = returnFiber;
5526
5527 {
5528 existing._debugSource = element._source;
5529 existing._debugOwner = element._owner;
5530 }
5531
5532 return existing;
5533 } else {
5534 deleteRemainingChildren(returnFiber, child);
5535 break;
5536 }
5537 } else {
5538 deleteChild(returnFiber, child);
5539 }
5540
5541 child = child.sibling;
5542 }
5543
5544 if (element.type === REACT_FRAGMENT_TYPE) {
5545 var created = createFiberFromFragment(element.props.children, returnFiber.mode, expirationTime, element.key);
5546 created.return = returnFiber;
5547 return created;
5548 } else {
5549 var _created4 = createFiberFromElement(element, returnFiber.mode, expirationTime);
5550
5551 _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
5552 _created4.return = returnFiber;
5553 return _created4;
5554 }
5555 }
5556
5557 function reconcileSinglePortal(returnFiber, currentFirstChild, portal, expirationTime) {
5558 var key = portal.key;
5559 var child = currentFirstChild;
5560
5561 while (child !== null) {
5562 // TODO: If key === null and child.key === null, then this only applies to
5563 // the first item in the list.
5564 if (child.key === key) {
5565 if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
5566 deleteRemainingChildren(returnFiber, child.sibling);
5567 var existing = useFiber(child, portal.children || [], expirationTime);
5568 existing.return = returnFiber;
5569 return existing;
5570 } else {
5571 deleteRemainingChildren(returnFiber, child);
5572 break;
5573 }
5574 } else {
5575 deleteChild(returnFiber, child);
5576 }
5577
5578 child = child.sibling;
5579 }
5580
5581 var created = createFiberFromPortal(portal, returnFiber.mode, expirationTime);
5582 created.return = returnFiber;
5583 return created;
5584 } // This API will tag the children with the side-effect of the reconciliation
5585 // itself. They will be added to the side-effect list as we pass through the
5586 // children and the parent.
5587
5588
5589 function reconcileChildFibers(returnFiber, currentFirstChild, newChild, expirationTime) {
5590 // This function is not recursive.
5591 // If the top level item is an array, we treat it as a set of children,
5592 // not as a fragment. Nested arrays on the other hand will be treated as
5593 // fragment nodes. Recursion happens at the normal flow.
5594 // Handle top level unkeyed fragments as if they were arrays.
5595 // This leads to an ambiguity between <>{[...]}</> and <>...</>.
5596 // We treat the ambiguous cases above the same.
5597 var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
5598
5599 if (isUnkeyedTopLevelFragment) {
5600 newChild = newChild.props.children;
5601 } // Handle object types
5602
5603
5604 var isObject = typeof newChild === 'object' && newChild !== null;
5605
5606 if (isObject) {
5607 switch (newChild.$$typeof) {
5608 case REACT_ELEMENT_TYPE$1:
5609 return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, expirationTime));
5610
5611 case REACT_PORTAL_TYPE:
5612 return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, expirationTime));
5613 }
5614 }
5615
5616 if (typeof newChild === 'string' || typeof newChild === 'number') {
5617 return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, expirationTime));
5618 }
5619
5620 if (isArray(newChild)) {
5621 return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, expirationTime);
5622 }
5623
5624 if (getIteratorFn(newChild)) {
5625 return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, expirationTime);
5626 }
5627
5628 if (isObject) {
5629 throwOnInvalidObjectType(returnFiber, newChild);
5630 }
5631
5632 {
5633 if (typeof newChild === 'function') {
5634 warnOnFunctionType();
5635 }
5636 }
5637
5638 if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
5639 // If the new child is undefined, and the return fiber is a composite
5640 // component, throw an error. If Fiber return types are disabled,
5641 // we already threw above.
5642 switch (returnFiber.tag) {
5643 case ClassComponent:
5644 {
5645 {
5646 var instance = returnFiber.stateNode;
5647
5648 if (instance.render._isMockFunction) {
5649 // We allow auto-mocks to proceed as if they're returning null.
5650 break;
5651 }
5652 }
5653 }
5654 // Intentionally fall through to the next case, which handles both
5655 // functions and classes
5656 // eslint-disable-next-lined no-fallthrough
5657
5658 case FunctionComponent:
5659 {
5660 var Component = returnFiber.type;
5661
5662 {
5663 {
5664 throw 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.");
5665 }
5666 }
5667 }
5668 }
5669 } // Remaining cases are all treated as empty.
5670
5671
5672 return deleteRemainingChildren(returnFiber, currentFirstChild);
5673 }
5674
5675 return reconcileChildFibers;
5676}
5677
5678var reconcileChildFibers = ChildReconciler(true);
5679var mountChildFibers = ChildReconciler(false);
5680function cloneChildFibers(current$$1, workInProgress) {
5681 if (!(current$$1 === null || workInProgress.child === current$$1.child)) {
5682 {
5683 throw Error("Resuming work not yet implemented.");
5684 }
5685 }
5686
5687 if (workInProgress.child === null) {
5688 return;
5689 }
5690
5691 var currentChild = workInProgress.child;
5692 var newChild = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
5693 workInProgress.child = newChild;
5694 newChild.return = workInProgress;
5695
5696 while (currentChild.sibling !== null) {
5697 currentChild = currentChild.sibling;
5698 newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps, currentChild.expirationTime);
5699 newChild.return = workInProgress;
5700 }
5701
5702 newChild.sibling = null;
5703} // Reset a workInProgress child set to prepare it for a second pass.
5704
5705function resetChildFibers(workInProgress, renderExpirationTime) {
5706 var child = workInProgress.child;
5707
5708 while (child !== null) {
5709 resetWorkInProgress(child, renderExpirationTime);
5710 child = child.sibling;
5711 }
5712}
5713
5714var NO_CONTEXT$1 = {};
5715var contextStackCursor$1 = createCursor(NO_CONTEXT$1);
5716var contextFiberStackCursor = createCursor(NO_CONTEXT$1);
5717var rootInstanceStackCursor = createCursor(NO_CONTEXT$1);
5718
5719function requiredContext(c) {
5720 if (!(c !== NO_CONTEXT$1)) {
5721 {
5722 throw Error("Expected host context to exist. This error is likely caused by a bug in React. Please file an issue.");
5723 }
5724 }
5725
5726 return c;
5727}
5728
5729function getRootHostContainer() {
5730 var rootInstance = requiredContext(rootInstanceStackCursor.current);
5731 return rootInstance;
5732}
5733
5734function pushHostContainer(fiber, nextRootInstance) {
5735 // Push current root instance onto the stack;
5736 // This allows us to reset root when portals are popped.
5737 push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
5738 // This enables us to pop only Fibers that provide unique contexts.
5739
5740 push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
5741 // However, we can't just call getRootHostContext() and push it because
5742 // we'd have a different number of entries on the stack depending on
5743 // whether getRootHostContext() throws somewhere in renderer code or not.
5744 // So we push an empty value first. This lets us safely unwind on errors.
5745
5746 push(contextStackCursor$1, NO_CONTEXT$1, fiber);
5747 var nextRootContext = getRootHostContext(nextRootInstance); // Now that we know this function doesn't throw, replace it.
5748
5749 pop(contextStackCursor$1, fiber);
5750 push(contextStackCursor$1, nextRootContext, fiber);
5751}
5752
5753function popHostContainer(fiber) {
5754 pop(contextStackCursor$1, fiber);
5755 pop(contextFiberStackCursor, fiber);
5756 pop(rootInstanceStackCursor, fiber);
5757}
5758
5759function getHostContext() {
5760 var context = requiredContext(contextStackCursor$1.current);
5761 return context;
5762}
5763
5764function pushHostContext(fiber) {
5765 var rootInstance = requiredContext(rootInstanceStackCursor.current);
5766 var context = requiredContext(contextStackCursor$1.current);
5767 var nextContext = getChildHostContext(context, fiber.type, rootInstance); // Don't push this Fiber's context unless it's unique.
5768
5769 if (context === nextContext) {
5770 return;
5771 } // Track the context and the Fiber that provided it.
5772 // This enables us to pop only Fibers that provide unique contexts.
5773
5774
5775 push(contextFiberStackCursor, fiber, fiber);
5776 push(contextStackCursor$1, nextContext, fiber);
5777}
5778
5779function popHostContext(fiber) {
5780 // Do not pop unless this Fiber provided the current context.
5781 // pushHostContext() only pushes Fibers that provide unique contexts.
5782 if (contextFiberStackCursor.current !== fiber) {
5783 return;
5784 }
5785
5786 pop(contextStackCursor$1, fiber);
5787 pop(contextFiberStackCursor, fiber);
5788}
5789
5790var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
5791// inherited deeply down the subtree. The upper bits only affect
5792// this immediate suspense boundary and gets reset each new
5793// boundary or suspense list.
5794
5795var SubtreeSuspenseContextMask = 1; // Subtree Flags:
5796// InvisibleParentSuspenseContext indicates that one of our parent Suspense
5797// boundaries is not currently showing visible main content.
5798// Either because it is already showing a fallback or is not mounted at all.
5799// We can use this to determine if it is desirable to trigger a fallback at
5800// the parent. If not, then we might need to trigger undesirable boundaries
5801// and/or suspend the commit to avoid hiding the parent content.
5802
5803var InvisibleParentSuspenseContext = 1; // Shallow Flags:
5804// ForceSuspenseFallback can be used by SuspenseList to force newly added
5805// items into their fallback state during one of the render passes.
5806
5807var ForceSuspenseFallback = 2;
5808var suspenseStackCursor = createCursor(DefaultSuspenseContext);
5809function hasSuspenseContext(parentContext, flag) {
5810 return (parentContext & flag) !== 0;
5811}
5812function setDefaultShallowSuspenseContext(parentContext) {
5813 return parentContext & SubtreeSuspenseContextMask;
5814}
5815function setShallowSuspenseContext(parentContext, shallowContext) {
5816 return parentContext & SubtreeSuspenseContextMask | shallowContext;
5817}
5818function addSubtreeSuspenseContext(parentContext, subtreeContext) {
5819 return parentContext | subtreeContext;
5820}
5821function pushSuspenseContext(fiber, newContext) {
5822 push(suspenseStackCursor, newContext, fiber);
5823}
5824function popSuspenseContext(fiber) {
5825 pop(suspenseStackCursor, fiber);
5826}
5827
5828function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
5829 // If it was the primary children that just suspended, capture and render the
5830 // fallback. Otherwise, don't capture and bubble to the next boundary.
5831 var nextState = workInProgress.memoizedState;
5832
5833 if (nextState !== null) {
5834 if (nextState.dehydrated !== null) {
5835 // A dehydrated boundary always captures.
5836 return true;
5837 }
5838
5839 return false;
5840 }
5841
5842 var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
5843
5844 if (props.fallback === undefined) {
5845 return false;
5846 } // Regular boundaries always capture.
5847
5848
5849 if (props.unstable_avoidThisFallback !== true) {
5850 return true;
5851 } // If it's a boundary we should avoid, then we prefer to bubble up to the
5852 // parent boundary if it is currently invisible.
5853
5854
5855 if (hasInvisibleParent) {
5856 return false;
5857 } // If the parent is not able to handle it, we must handle it.
5858
5859
5860 return true;
5861}
5862function findFirstSuspended(row) {
5863 var node = row;
5864
5865 while (node !== null) {
5866 if (node.tag === SuspenseComponent) {
5867 var state = node.memoizedState;
5868
5869 if (state !== null) {
5870 var dehydrated = state.dehydrated;
5871
5872 if (dehydrated === null || isSuspenseInstancePending(dehydrated) || isSuspenseInstanceFallback(dehydrated)) {
5873 return node;
5874 }
5875 }
5876 } else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
5877 // keep track of whether it suspended or not.
5878 node.memoizedProps.revealOrder !== undefined) {
5879 var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
5880
5881 if (didSuspend) {
5882 return node;
5883 }
5884 } else if (node.child !== null) {
5885 node.child.return = node;
5886 node = node.child;
5887 continue;
5888 }
5889
5890 if (node === row) {
5891 return null;
5892 }
5893
5894 while (node.sibling === null) {
5895 if (node.return === null || node.return === row) {
5896 return null;
5897 }
5898
5899 node = node.return;
5900 }
5901
5902 node.sibling.return = node.return;
5903 node = node.sibling;
5904 }
5905
5906 return null;
5907}
5908
5909var emptyObject = {};
5910var isArray$2 = Array.isArray;
5911function createResponderInstance(responder, responderProps, responderState, fiber) {
5912 return {
5913 fiber: fiber,
5914 props: responderProps,
5915 responder: responder,
5916 rootEventTypes: null,
5917 state: responderState
5918 };
5919}
5920
5921function mountEventResponder(responder, responderProps, fiber, respondersMap, rootContainerInstance) {
5922 var responderState = emptyObject;
5923 var getInitialState = responder.getInitialState;
5924
5925 if (getInitialState !== null) {
5926 responderState = getInitialState(responderProps);
5927 }
5928
5929 var responderInstance = createResponderInstance(responder, responderProps, responderState, fiber);
5930
5931 if (!rootContainerInstance) {
5932 var node = fiber;
5933
5934 while (node !== null) {
5935 var tag = node.tag;
5936
5937 if (tag === HostComponent) {
5938 rootContainerInstance = node.stateNode;
5939 break;
5940 } else if (tag === HostRoot) {
5941 rootContainerInstance = node.stateNode.containerInfo;
5942 break;
5943 }
5944
5945 node = node.return;
5946 }
5947 }
5948
5949 respondersMap.set(responder, responderInstance);
5950}
5951
5952function updateEventListener(listener, fiber, visistedResponders, respondersMap, rootContainerInstance) {
5953 var responder;
5954 var props;
5955
5956 if (listener) {
5957 responder = listener.responder;
5958 props = listener.props;
5959 }
5960
5961 if (!(responder && responder.$$typeof === REACT_RESPONDER_TYPE)) {
5962 {
5963 throw Error("An invalid value was used as an event listener. Expect one or many event listeners created via React.unstable_useResponder().");
5964 }
5965 }
5966
5967 var listenerProps = props;
5968
5969 if (visistedResponders.has(responder)) {
5970 // show warning
5971 {
5972 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);
5973 }
5974
5975 return;
5976 }
5977
5978 visistedResponders.add(responder);
5979 var responderInstance = respondersMap.get(responder);
5980
5981 if (responderInstance === undefined) {
5982 // Mount (happens in either complete or commit phase)
5983 mountEventResponder(responder, listenerProps, fiber, respondersMap, rootContainerInstance);
5984 } else {
5985 // Update (happens during commit phase only)
5986 responderInstance.props = listenerProps;
5987 responderInstance.fiber = fiber;
5988 }
5989}
5990
5991function updateEventListeners(listeners, fiber, rootContainerInstance) {
5992 var visistedResponders = new Set();
5993 var dependencies = fiber.dependencies;
5994
5995 if (listeners != null) {
5996 if (dependencies === null) {
5997 dependencies = fiber.dependencies = {
5998 expirationTime: NoWork,
5999 firstContext: null,
6000 responders: new Map()
6001 };
6002 }
6003
6004 var respondersMap = dependencies.responders;
6005
6006 if (respondersMap === null) {
6007 respondersMap = new Map();
6008 }
6009
6010 if (isArray$2(listeners)) {
6011 for (var i = 0, length = listeners.length; i < length; i++) {
6012 var listener = listeners[i];
6013 updateEventListener(listener, fiber, visistedResponders, respondersMap, rootContainerInstance);
6014 }
6015 } else {
6016 updateEventListener(listeners, fiber, visistedResponders, respondersMap, rootContainerInstance);
6017 }
6018 }
6019
6020 if (dependencies !== null) {
6021 var _respondersMap = dependencies.responders;
6022
6023 if (_respondersMap !== null) {
6024 // Unmount
6025 var mountedResponders = Array.from(_respondersMap.keys());
6026
6027 for (var _i = 0, _length = mountedResponders.length; _i < _length; _i++) {
6028 var mountedResponder = mountedResponders[_i];
6029
6030 if (!visistedResponders.has(mountedResponder)) {
6031 var responderInstance = _respondersMap.get(mountedResponder);
6032
6033 _respondersMap.delete(mountedResponder);
6034 }
6035 }
6036 }
6037 }
6038}
6039function createResponderListener(responder, props) {
6040 var eventResponderListener = {
6041 responder: responder,
6042 props: props
6043 };
6044
6045 {
6046 Object.freeze(eventResponderListener);
6047 }
6048
6049 return eventResponderListener;
6050}
6051
6052var NoEffect$1 =
6053/* */
60540;
6055var UnmountSnapshot =
6056/* */
60572;
6058var UnmountMutation =
6059/* */
60604;
6061var MountMutation =
6062/* */
60638;
6064var UnmountLayout =
6065/* */
606616;
6067var MountLayout =
6068/* */
606932;
6070var MountPassive =
6071/* */
607264;
6073var UnmountPassive =
6074/* */
6075128;
6076
6077var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
6078var ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
6079var didWarnAboutMismatchedHooksForComponent;
6080
6081{
6082 didWarnAboutMismatchedHooksForComponent = new Set();
6083}
6084
6085// These are set right before calling the component.
6086var renderExpirationTime$1 = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
6087// the work-in-progress hook.
6088
6089var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
6090// current hook list is the list that belongs to the current fiber. The
6091// work-in-progress hook list is a new list that will be added to the
6092// work-in-progress fiber.
6093
6094var currentHook = null;
6095var nextCurrentHook = null;
6096var firstWorkInProgressHook = null;
6097var workInProgressHook = null;
6098var nextWorkInProgressHook = null;
6099var remainingExpirationTime = NoWork;
6100var componentUpdateQueue = null;
6101var sideEffectTag = 0; // Updates scheduled during render will trigger an immediate re-render at the
6102// end of the current pass. We can't store these updates on the normal queue,
6103// because if the work is aborted, they should be discarded. Because this is
6104// a relatively rare case, we also don't want to add an additional field to
6105// either the hook or queue object types. So we store them in a lazily create
6106// map of queue -> render-phase updates, which are discarded once the component
6107// completes without re-rendering.
6108// Whether an update was scheduled during the currently executing render pass.
6109
6110var didScheduleRenderPhaseUpdate = false; // Lazily created map of render-phase updates
6111
6112var renderPhaseUpdates = null; // Counter to prevent infinite loops.
6113
6114var numberOfReRenders = 0;
6115var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
6116
6117var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
6118// The list stores the order of hooks used during the initial render (mount).
6119// Subsequent renders (updates) reference this list.
6120
6121var hookTypesDev = null;
6122var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
6123// the dependencies for Hooks that need them (e.g. useEffect or useMemo).
6124// When true, such Hooks will always be "remounted". Only used during hot reload.
6125
6126var ignorePreviousDependencies = false;
6127
6128function mountHookTypesDev() {
6129 {
6130 var hookName = currentHookNameInDev;
6131
6132 if (hookTypesDev === null) {
6133 hookTypesDev = [hookName];
6134 } else {
6135 hookTypesDev.push(hookName);
6136 }
6137 }
6138}
6139
6140function updateHookTypesDev() {
6141 {
6142 var hookName = currentHookNameInDev;
6143
6144 if (hookTypesDev !== null) {
6145 hookTypesUpdateIndexDev++;
6146
6147 if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
6148 warnOnHookMismatchInDev(hookName);
6149 }
6150 }
6151 }
6152}
6153
6154function checkDepsAreArrayDev(deps) {
6155 {
6156 if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
6157 // Verify deps, but only on mount to avoid extra checks.
6158 // It's unlikely their type would change as usually you define them inline.
6159 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);
6160 }
6161 }
6162}
6163
6164function warnOnHookMismatchInDev(currentHookName) {
6165 {
6166 var componentName = getComponentName(currentlyRenderingFiber$1.type);
6167
6168 if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
6169 didWarnAboutMismatchedHooksForComponent.add(componentName);
6170
6171 if (hookTypesDev !== null) {
6172 var table = '';
6173 var secondColumnStart = 30;
6174
6175 for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
6176 var oldHookName = hookTypesDev[i];
6177 var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
6178 var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
6179 // lol @ IE not supporting String#repeat
6180
6181 while (row.length < secondColumnStart) {
6182 row += ' ';
6183 }
6184
6185 row += newHookName + '\n';
6186 table += row;
6187 }
6188
6189 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);
6190 }
6191 }
6192 }
6193}
6194
6195function throwInvalidHookError() {
6196 {
6197 {
6198 throw 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.");
6199 }
6200 }
6201}
6202
6203function areHookInputsEqual(nextDeps, prevDeps) {
6204 {
6205 if (ignorePreviousDependencies) {
6206 // Only true when this component is being hot reloaded.
6207 return false;
6208 }
6209 }
6210
6211 if (prevDeps === null) {
6212 {
6213 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);
6214 }
6215
6216 return false;
6217 }
6218
6219 {
6220 // Don't bother comparing lengths in prod because these arrays should be
6221 // passed inline.
6222 if (nextDeps.length !== prevDeps.length) {
6223 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(', ') + "]");
6224 }
6225 }
6226
6227 for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
6228 if (is$1(nextDeps[i], prevDeps[i])) {
6229 continue;
6230 }
6231
6232 return false;
6233 }
6234
6235 return true;
6236}
6237
6238function renderWithHooks(current, workInProgress, Component, props, refOrContext, nextRenderExpirationTime) {
6239 renderExpirationTime$1 = nextRenderExpirationTime;
6240 currentlyRenderingFiber$1 = workInProgress;
6241 nextCurrentHook = current !== null ? current.memoizedState : null;
6242
6243 {
6244 hookTypesDev = current !== null ? current._debugHookTypes : null;
6245 hookTypesUpdateIndexDev = -1; // Used for hot reloading:
6246
6247 ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
6248 } // The following should have already been reset
6249 // currentHook = null;
6250 // workInProgressHook = null;
6251 // remainingExpirationTime = NoWork;
6252 // componentUpdateQueue = null;
6253 // didScheduleRenderPhaseUpdate = false;
6254 // renderPhaseUpdates = null;
6255 // numberOfReRenders = 0;
6256 // sideEffectTag = 0;
6257 // TODO Warn if no hooks are used at all during mount, then some are used during update.
6258 // Currently we will identify the update render as a mount because nextCurrentHook === null.
6259 // This is tricky because it's valid for certain types of components (e.g. React.lazy)
6260 // Using nextCurrentHook to differentiate between mount/update only works if at least one stateful hook is used.
6261 // Non-stateful hooks (e.g. context) don't get added to memoizedState,
6262 // so nextCurrentHook would be null during updates and mounts.
6263
6264
6265 {
6266 if (nextCurrentHook !== null) {
6267 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
6268 } else if (hookTypesDev !== null) {
6269 // This dispatcher handles an edge case where a component is updating,
6270 // but no stateful hooks have been used.
6271 // We want to match the production code behavior (which will use HooksDispatcherOnMount),
6272 // but with the extra DEV validation to ensure hooks ordering hasn't changed.
6273 // This dispatcher does that.
6274 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountWithHookTypesInDEV;
6275 } else {
6276 ReactCurrentDispatcher$1.current = HooksDispatcherOnMountInDEV;
6277 }
6278 }
6279
6280 var children = Component(props, refOrContext);
6281
6282 if (didScheduleRenderPhaseUpdate) {
6283 do {
6284 didScheduleRenderPhaseUpdate = false;
6285 numberOfReRenders += 1;
6286
6287 {
6288 // Even when hot reloading, allow dependencies to stabilize
6289 // after first render to prevent infinite render phase updates.
6290 ignorePreviousDependencies = false;
6291 } // Start over from the beginning of the list
6292
6293
6294 nextCurrentHook = current !== null ? current.memoizedState : null;
6295 nextWorkInProgressHook = firstWorkInProgressHook;
6296 currentHook = null;
6297 workInProgressHook = null;
6298 componentUpdateQueue = null;
6299
6300 {
6301 // Also validate hook order for cascading updates.
6302 hookTypesUpdateIndexDev = -1;
6303 }
6304
6305 ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
6306 children = Component(props, refOrContext);
6307 } while (didScheduleRenderPhaseUpdate);
6308
6309 renderPhaseUpdates = null;
6310 numberOfReRenders = 0;
6311 } // We can assume the previous dispatcher is always this one, since we set it
6312 // at the beginning of the render phase and there's no re-entrancy.
6313
6314
6315 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
6316 var renderedWork = currentlyRenderingFiber$1;
6317 renderedWork.memoizedState = firstWorkInProgressHook;
6318 renderedWork.expirationTime = remainingExpirationTime;
6319 renderedWork.updateQueue = componentUpdateQueue;
6320 renderedWork.effectTag |= sideEffectTag;
6321
6322 {
6323 renderedWork._debugHookTypes = hookTypesDev;
6324 } // This check uses currentHook so that it works the same in DEV and prod bundles.
6325 // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
6326
6327
6328 var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
6329 renderExpirationTime$1 = NoWork;
6330 currentlyRenderingFiber$1 = null;
6331 currentHook = null;
6332 nextCurrentHook = null;
6333 firstWorkInProgressHook = null;
6334 workInProgressHook = null;
6335 nextWorkInProgressHook = null;
6336
6337 {
6338 currentHookNameInDev = null;
6339 hookTypesDev = null;
6340 hookTypesUpdateIndexDev = -1;
6341 }
6342
6343 remainingExpirationTime = NoWork;
6344 componentUpdateQueue = null;
6345 sideEffectTag = 0; // These were reset above
6346 // didScheduleRenderPhaseUpdate = false;
6347 // renderPhaseUpdates = null;
6348 // numberOfReRenders = 0;
6349
6350 if (!!didRenderTooFewHooks) {
6351 {
6352 throw Error("Rendered fewer hooks than expected. This may be caused by an accidental early return statement.");
6353 }
6354 }
6355
6356 return children;
6357}
6358function bailoutHooks(current, workInProgress, expirationTime) {
6359 workInProgress.updateQueue = current.updateQueue;
6360 workInProgress.effectTag &= ~(Passive | Update);
6361
6362 if (current.expirationTime <= expirationTime) {
6363 current.expirationTime = NoWork;
6364 }
6365}
6366function resetHooks() {
6367 // We can assume the previous dispatcher is always this one, since we set it
6368 // at the beginning of the render phase and there's no re-entrancy.
6369 ReactCurrentDispatcher$1.current = ContextOnlyDispatcher; // This is used to reset the state of this module when a component throws.
6370 // It's also called inside mountIndeterminateComponent if we determine the
6371 // component is a module-style component.
6372
6373 renderExpirationTime$1 = NoWork;
6374 currentlyRenderingFiber$1 = null;
6375 currentHook = null;
6376 nextCurrentHook = null;
6377 firstWorkInProgressHook = null;
6378 workInProgressHook = null;
6379 nextWorkInProgressHook = null;
6380
6381 {
6382 hookTypesDev = null;
6383 hookTypesUpdateIndexDev = -1;
6384 currentHookNameInDev = null;
6385 }
6386
6387 remainingExpirationTime = NoWork;
6388 componentUpdateQueue = null;
6389 sideEffectTag = 0;
6390 didScheduleRenderPhaseUpdate = false;
6391 renderPhaseUpdates = null;
6392 numberOfReRenders = 0;
6393}
6394
6395function mountWorkInProgressHook() {
6396 var hook = {
6397 memoizedState: null,
6398 baseState: null,
6399 queue: null,
6400 baseUpdate: null,
6401 next: null
6402 };
6403
6404 if (workInProgressHook === null) {
6405 // This is the first hook in the list
6406 firstWorkInProgressHook = workInProgressHook = hook;
6407 } else {
6408 // Append to the end of the list
6409 workInProgressHook = workInProgressHook.next = hook;
6410 }
6411
6412 return workInProgressHook;
6413}
6414
6415function updateWorkInProgressHook() {
6416 // This function is used both for updates and for re-renders triggered by a
6417 // render phase update. It assumes there is either a current hook we can
6418 // clone, or a work-in-progress hook from a previous render pass that we can
6419 // use as a base. When we reach the end of the base list, we must switch to
6420 // the dispatcher used for mounts.
6421 if (nextWorkInProgressHook !== null) {
6422 // There's already a work-in-progress. Reuse it.
6423 workInProgressHook = nextWorkInProgressHook;
6424 nextWorkInProgressHook = workInProgressHook.next;
6425 currentHook = nextCurrentHook;
6426 nextCurrentHook = currentHook !== null ? currentHook.next : null;
6427 } else {
6428 // Clone from the current hook.
6429 if (!(nextCurrentHook !== null)) {
6430 {
6431 throw Error("Rendered more hooks than during the previous render.");
6432 }
6433 }
6434
6435 currentHook = nextCurrentHook;
6436 var newHook = {
6437 memoizedState: currentHook.memoizedState,
6438 baseState: currentHook.baseState,
6439 queue: currentHook.queue,
6440 baseUpdate: currentHook.baseUpdate,
6441 next: null
6442 };
6443
6444 if (workInProgressHook === null) {
6445 // This is the first hook in the list.
6446 workInProgressHook = firstWorkInProgressHook = newHook;
6447 } else {
6448 // Append to the end of the list.
6449 workInProgressHook = workInProgressHook.next = newHook;
6450 }
6451
6452 nextCurrentHook = currentHook.next;
6453 }
6454
6455 return workInProgressHook;
6456}
6457
6458function createFunctionComponentUpdateQueue() {
6459 return {
6460 lastEffect: null
6461 };
6462}
6463
6464function basicStateReducer(state, action) {
6465 return typeof action === 'function' ? action(state) : action;
6466}
6467
6468function mountReducer(reducer, initialArg, init) {
6469 var hook = mountWorkInProgressHook();
6470 var initialState;
6471
6472 if (init !== undefined) {
6473 initialState = init(initialArg);
6474 } else {
6475 initialState = initialArg;
6476 }
6477
6478 hook.memoizedState = hook.baseState = initialState;
6479 var queue = hook.queue = {
6480 last: null,
6481 dispatch: null,
6482 lastRenderedReducer: reducer,
6483 lastRenderedState: initialState
6484 };
6485 var dispatch = queue.dispatch = dispatchAction.bind(null, // Flow doesn't know this is non-null, but we do.
6486 currentlyRenderingFiber$1, queue);
6487 return [hook.memoizedState, dispatch];
6488}
6489
6490function updateReducer(reducer, initialArg, init) {
6491 var hook = updateWorkInProgressHook();
6492 var queue = hook.queue;
6493
6494 if (!(queue !== null)) {
6495 {
6496 throw Error("Should have a queue. This is likely a bug in React. Please file an issue.");
6497 }
6498 }
6499
6500 queue.lastRenderedReducer = reducer;
6501
6502 if (numberOfReRenders > 0) {
6503 // This is a re-render. Apply the new render phase updates to the previous
6504 // work-in-progress hook.
6505 var _dispatch = queue.dispatch;
6506
6507 if (renderPhaseUpdates !== null) {
6508 // Render phase updates are stored in a map of queue -> linked list
6509 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
6510
6511 if (firstRenderPhaseUpdate !== undefined) {
6512 renderPhaseUpdates.delete(queue);
6513 var newState = hook.memoizedState;
6514 var update = firstRenderPhaseUpdate;
6515
6516 do {
6517 // Process this render phase update. We don't have to check the
6518 // priority because it will always be the same as the current
6519 // render's.
6520 var action = update.action;
6521 newState = reducer(newState, action);
6522 update = update.next;
6523 } while (update !== null); // Mark that the fiber performed work, but only if the new state is
6524 // different from the current state.
6525
6526
6527 if (!is$1(newState, hook.memoizedState)) {
6528 markWorkInProgressReceivedUpdate();
6529 }
6530
6531 hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
6532 // the base state unless the queue is empty.
6533 // TODO: Not sure if this is the desired semantics, but it's what we
6534 // do for gDSFP. I can't remember why.
6535
6536 if (hook.baseUpdate === queue.last) {
6537 hook.baseState = newState;
6538 }
6539
6540 queue.lastRenderedState = newState;
6541 return [newState, _dispatch];
6542 }
6543 }
6544
6545 return [hook.memoizedState, _dispatch];
6546 } // The last update in the entire queue
6547
6548
6549 var last = queue.last; // The last update that is part of the base state.
6550
6551 var baseUpdate = hook.baseUpdate;
6552 var baseState = hook.baseState; // Find the first unprocessed update.
6553
6554 var first;
6555
6556 if (baseUpdate !== null) {
6557 if (last !== null) {
6558 // For the first update, the queue is a circular linked list where
6559 // `queue.last.next = queue.first`. Once the first update commits, and
6560 // the `baseUpdate` is no longer empty, we can unravel the list.
6561 last.next = null;
6562 }
6563
6564 first = baseUpdate.next;
6565 } else {
6566 first = last !== null ? last.next : null;
6567 }
6568
6569 if (first !== null) {
6570 var _newState = baseState;
6571 var newBaseState = null;
6572 var newBaseUpdate = null;
6573 var prevUpdate = baseUpdate;
6574 var _update = first;
6575 var didSkip = false;
6576
6577 do {
6578 var updateExpirationTime = _update.expirationTime;
6579
6580 if (updateExpirationTime < renderExpirationTime$1) {
6581 // Priority is insufficient. Skip this update. If this is the first
6582 // skipped update, the previous update/state is the new base
6583 // update/state.
6584 if (!didSkip) {
6585 didSkip = true;
6586 newBaseUpdate = prevUpdate;
6587 newBaseState = _newState;
6588 } // Update the remaining priority in the queue.
6589
6590
6591 if (updateExpirationTime > remainingExpirationTime) {
6592 remainingExpirationTime = updateExpirationTime;
6593 markUnprocessedUpdateTime(remainingExpirationTime);
6594 }
6595 } else {
6596 // This update does have sufficient priority.
6597 // Mark the event time of this update as relevant to this render pass.
6598 // TODO: This should ideally use the true event time of this update rather than
6599 // its priority which is a derived and not reverseable value.
6600 // TODO: We should skip this update if it was already committed but currently
6601 // we have no way of detecting the difference between a committed and suspended
6602 // update here.
6603 markRenderEventTimeAndConfig(updateExpirationTime, _update.suspenseConfig); // Process this update.
6604
6605 if (_update.eagerReducer === reducer) {
6606 // If this update was processed eagerly, and its reducer matches the
6607 // current reducer, we can use the eagerly computed state.
6608 _newState = _update.eagerState;
6609 } else {
6610 var _action = _update.action;
6611 _newState = reducer(_newState, _action);
6612 }
6613 }
6614
6615 prevUpdate = _update;
6616 _update = _update.next;
6617 } while (_update !== null && _update !== first);
6618
6619 if (!didSkip) {
6620 newBaseUpdate = prevUpdate;
6621 newBaseState = _newState;
6622 } // Mark that the fiber performed work, but only if the new state is
6623 // different from the current state.
6624
6625
6626 if (!is$1(_newState, hook.memoizedState)) {
6627 markWorkInProgressReceivedUpdate();
6628 }
6629
6630 hook.memoizedState = _newState;
6631 hook.baseUpdate = newBaseUpdate;
6632 hook.baseState = newBaseState;
6633 queue.lastRenderedState = _newState;
6634 }
6635
6636 var dispatch = queue.dispatch;
6637 return [hook.memoizedState, dispatch];
6638}
6639
6640function mountState(initialState) {
6641 var hook = mountWorkInProgressHook();
6642
6643 if (typeof initialState === 'function') {
6644 initialState = initialState();
6645 }
6646
6647 hook.memoizedState = hook.baseState = initialState;
6648 var queue = hook.queue = {
6649 last: null,
6650 dispatch: null,
6651 lastRenderedReducer: basicStateReducer,
6652 lastRenderedState: initialState
6653 };
6654 var dispatch = queue.dispatch = dispatchAction.bind(null, // Flow doesn't know this is non-null, but we do.
6655 currentlyRenderingFiber$1, queue);
6656 return [hook.memoizedState, dispatch];
6657}
6658
6659function updateState(initialState) {
6660 return updateReducer(basicStateReducer, initialState);
6661}
6662
6663function pushEffect(tag, create, destroy, deps) {
6664 var effect = {
6665 tag: tag,
6666 create: create,
6667 destroy: destroy,
6668 deps: deps,
6669 // Circular
6670 next: null
6671 };
6672
6673 if (componentUpdateQueue === null) {
6674 componentUpdateQueue = createFunctionComponentUpdateQueue();
6675 componentUpdateQueue.lastEffect = effect.next = effect;
6676 } else {
6677 var lastEffect = componentUpdateQueue.lastEffect;
6678
6679 if (lastEffect === null) {
6680 componentUpdateQueue.lastEffect = effect.next = effect;
6681 } else {
6682 var firstEffect = lastEffect.next;
6683 lastEffect.next = effect;
6684 effect.next = firstEffect;
6685 componentUpdateQueue.lastEffect = effect;
6686 }
6687 }
6688
6689 return effect;
6690}
6691
6692function mountRef(initialValue) {
6693 var hook = mountWorkInProgressHook();
6694 var ref = {
6695 current: initialValue
6696 };
6697
6698 {
6699 Object.seal(ref);
6700 }
6701
6702 hook.memoizedState = ref;
6703 return ref;
6704}
6705
6706function updateRef(initialValue) {
6707 var hook = updateWorkInProgressHook();
6708 return hook.memoizedState;
6709}
6710
6711function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
6712 var hook = mountWorkInProgressHook();
6713 var nextDeps = deps === undefined ? null : deps;
6714 sideEffectTag |= fiberEffectTag;
6715 hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps);
6716}
6717
6718function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
6719 var hook = updateWorkInProgressHook();
6720 var nextDeps = deps === undefined ? null : deps;
6721 var destroy = undefined;
6722
6723 if (currentHook !== null) {
6724 var prevEffect = currentHook.memoizedState;
6725 destroy = prevEffect.destroy;
6726
6727 if (nextDeps !== null) {
6728 var prevDeps = prevEffect.deps;
6729
6730 if (areHookInputsEqual(nextDeps, prevDeps)) {
6731 pushEffect(NoEffect$1, create, destroy, nextDeps);
6732 return;
6733 }
6734 }
6735 }
6736
6737 sideEffectTag |= fiberEffectTag;
6738 hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps);
6739}
6740
6741function mountEffect(create, deps) {
6742 {
6743 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
6744 if ('undefined' !== typeof jest) {
6745 warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
6746 }
6747 }
6748
6749 return mountEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
6750}
6751
6752function updateEffect(create, deps) {
6753 {
6754 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
6755 if ('undefined' !== typeof jest) {
6756 warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
6757 }
6758 }
6759
6760 return updateEffectImpl(Update | Passive, UnmountPassive | MountPassive, create, deps);
6761}
6762
6763function mountLayoutEffect(create, deps) {
6764 return mountEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
6765}
6766
6767function updateLayoutEffect(create, deps) {
6768 return updateEffectImpl(Update, UnmountMutation | MountLayout, create, deps);
6769}
6770
6771function imperativeHandleEffect(create, ref) {
6772 if (typeof ref === 'function') {
6773 var refCallback = ref;
6774
6775 var _inst = create();
6776
6777 refCallback(_inst);
6778 return function () {
6779 refCallback(null);
6780 };
6781 } else if (ref !== null && ref !== undefined) {
6782 var refObject = ref;
6783
6784 {
6785 !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;
6786 }
6787
6788 var _inst2 = create();
6789
6790 refObject.current = _inst2;
6791 return function () {
6792 refObject.current = null;
6793 };
6794 }
6795}
6796
6797function mountImperativeHandle(ref, create, deps) {
6798 {
6799 !(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;
6800 } // TODO: If deps are provided, should we skip comparing the ref itself?
6801
6802
6803 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
6804 return mountEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
6805}
6806
6807function updateImperativeHandle(ref, create, deps) {
6808 {
6809 !(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;
6810 } // TODO: If deps are provided, should we skip comparing the ref itself?
6811
6812
6813 var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
6814 return updateEffectImpl(Update, UnmountMutation | MountLayout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
6815}
6816
6817function mountDebugValue(value, formatterFn) {// This hook is normally a no-op.
6818 // The react-debug-hooks package injects its own implementation
6819 // so that e.g. DevTools can display custom hook values.
6820}
6821
6822var updateDebugValue = mountDebugValue;
6823
6824function mountCallback(callback, deps) {
6825 var hook = mountWorkInProgressHook();
6826 var nextDeps = deps === undefined ? null : deps;
6827 hook.memoizedState = [callback, nextDeps];
6828 return callback;
6829}
6830
6831function updateCallback(callback, deps) {
6832 var hook = updateWorkInProgressHook();
6833 var nextDeps = deps === undefined ? null : deps;
6834 var prevState = hook.memoizedState;
6835
6836 if (prevState !== null) {
6837 if (nextDeps !== null) {
6838 var prevDeps = prevState[1];
6839
6840 if (areHookInputsEqual(nextDeps, prevDeps)) {
6841 return prevState[0];
6842 }
6843 }
6844 }
6845
6846 hook.memoizedState = [callback, nextDeps];
6847 return callback;
6848}
6849
6850function mountMemo(nextCreate, deps) {
6851 var hook = mountWorkInProgressHook();
6852 var nextDeps = deps === undefined ? null : deps;
6853 var nextValue = nextCreate();
6854 hook.memoizedState = [nextValue, nextDeps];
6855 return nextValue;
6856}
6857
6858function updateMemo(nextCreate, deps) {
6859 var hook = updateWorkInProgressHook();
6860 var nextDeps = deps === undefined ? null : deps;
6861 var prevState = hook.memoizedState;
6862
6863 if (prevState !== null) {
6864 // Assume these are defined. If they're not, areHookInputsEqual will warn.
6865 if (nextDeps !== null) {
6866 var prevDeps = prevState[1];
6867
6868 if (areHookInputsEqual(nextDeps, prevDeps)) {
6869 return prevState[0];
6870 }
6871 }
6872 }
6873
6874 var nextValue = nextCreate();
6875 hook.memoizedState = [nextValue, nextDeps];
6876 return nextValue;
6877}
6878
6879function mountDeferredValue(value, config) {
6880 var _mountState = mountState(value),
6881 prevValue = _mountState[0],
6882 setValue = _mountState[1];
6883
6884 mountEffect(function () {
6885 Scheduler$1.unstable_next(function () {
6886 var previousConfig = ReactCurrentBatchConfig$1.suspense;
6887 ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
6888
6889 try {
6890 setValue(value);
6891 } finally {
6892 ReactCurrentBatchConfig$1.suspense = previousConfig;
6893 }
6894 });
6895 }, [value, config]);
6896 return prevValue;
6897}
6898
6899function updateDeferredValue(value, config) {
6900 var _updateState = updateState(value),
6901 prevValue = _updateState[0],
6902 setValue = _updateState[1];
6903
6904 updateEffect(function () {
6905 Scheduler$1.unstable_next(function () {
6906 var previousConfig = ReactCurrentBatchConfig$1.suspense;
6907 ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
6908
6909 try {
6910 setValue(value);
6911 } finally {
6912 ReactCurrentBatchConfig$1.suspense = previousConfig;
6913 }
6914 });
6915 }, [value, config]);
6916 return prevValue;
6917}
6918
6919function mountTransition(config) {
6920 var _mountState2 = mountState(false),
6921 isPending = _mountState2[0],
6922 setPending = _mountState2[1];
6923
6924 var startTransition = mountCallback(function (callback) {
6925 setPending(true);
6926 Scheduler$1.unstable_next(function () {
6927 var previousConfig = ReactCurrentBatchConfig$1.suspense;
6928 ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
6929
6930 try {
6931 setPending(false);
6932 callback();
6933 } finally {
6934 ReactCurrentBatchConfig$1.suspense = previousConfig;
6935 }
6936 });
6937 }, [config, isPending]);
6938 return [startTransition, isPending];
6939}
6940
6941function updateTransition(config) {
6942 var _updateState2 = updateState(false),
6943 isPending = _updateState2[0],
6944 setPending = _updateState2[1];
6945
6946 var startTransition = updateCallback(function (callback) {
6947 setPending(true);
6948 Scheduler$1.unstable_next(function () {
6949 var previousConfig = ReactCurrentBatchConfig$1.suspense;
6950 ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
6951
6952 try {
6953 setPending(false);
6954 callback();
6955 } finally {
6956 ReactCurrentBatchConfig$1.suspense = previousConfig;
6957 }
6958 });
6959 }, [config, isPending]);
6960 return [startTransition, isPending];
6961}
6962
6963function dispatchAction(fiber, queue, action) {
6964 if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
6965 {
6966 throw Error("Too many re-renders. React limits the number of renders to prevent an infinite loop.");
6967 }
6968 }
6969
6970 {
6971 !(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;
6972 }
6973
6974 var alternate = fiber.alternate;
6975
6976 if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
6977 // This is a render phase update. Stash it in a lazily-created map of
6978 // queue -> linked list of updates. After this render pass, we'll restart
6979 // and apply the stashed updates on top of the work-in-progress hook.
6980 didScheduleRenderPhaseUpdate = true;
6981 var update = {
6982 expirationTime: renderExpirationTime$1,
6983 suspenseConfig: null,
6984 action: action,
6985 eagerReducer: null,
6986 eagerState: null,
6987 next: null
6988 };
6989
6990 {
6991 update.priority = getCurrentPriorityLevel();
6992 }
6993
6994 if (renderPhaseUpdates === null) {
6995 renderPhaseUpdates = new Map();
6996 }
6997
6998 var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
6999
7000 if (firstRenderPhaseUpdate === undefined) {
7001 renderPhaseUpdates.set(queue, update);
7002 } else {
7003 // Append the update to the end of the list.
7004 var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
7005
7006 while (lastRenderPhaseUpdate.next !== null) {
7007 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
7008 }
7009
7010 lastRenderPhaseUpdate.next = update;
7011 }
7012 } else {
7013 var currentTime = requestCurrentTimeForUpdate();
7014 var suspenseConfig = requestCurrentSuspenseConfig();
7015 var expirationTime = computeExpirationForFiber(currentTime, fiber, suspenseConfig);
7016 var _update2 = {
7017 expirationTime: expirationTime,
7018 suspenseConfig: suspenseConfig,
7019 action: action,
7020 eagerReducer: null,
7021 eagerState: null,
7022 next: null
7023 };
7024
7025 {
7026 _update2.priority = getCurrentPriorityLevel();
7027 } // Append the update to the end of the list.
7028
7029
7030 var last = queue.last;
7031
7032 if (last === null) {
7033 // This is the first update. Create a circular list.
7034 _update2.next = _update2;
7035 } else {
7036 var first = last.next;
7037
7038 if (first !== null) {
7039 // Still circular.
7040 _update2.next = first;
7041 }
7042
7043 last.next = _update2;
7044 }
7045
7046 queue.last = _update2;
7047
7048 if (fiber.expirationTime === NoWork && (alternate === null || alternate.expirationTime === NoWork)) {
7049 // The queue is currently empty, which means we can eagerly compute the
7050 // next state before entering the render phase. If the new state is the
7051 // same as the current state, we may be able to bail out entirely.
7052 var lastRenderedReducer = queue.lastRenderedReducer;
7053
7054 if (lastRenderedReducer !== null) {
7055 var prevDispatcher;
7056
7057 {
7058 prevDispatcher = ReactCurrentDispatcher$1.current;
7059 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7060 }
7061
7062 try {
7063 var currentState = queue.lastRenderedState;
7064 var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
7065 // it, on the update object. If the reducer hasn't changed by the
7066 // time we enter the render phase, then the eager state can be used
7067 // without calling the reducer again.
7068
7069 _update2.eagerReducer = lastRenderedReducer;
7070 _update2.eagerState = eagerState;
7071
7072 if (is$1(eagerState, currentState)) {
7073 // Fast path. We can bail out without scheduling React to re-render.
7074 // It's still possible that we'll need to rebase this update later,
7075 // if the component re-renders for a different reason and by that
7076 // time the reducer has changed.
7077 return;
7078 }
7079 } catch (error) {// Suppress the error. It will throw again in the render phase.
7080 } finally {
7081 {
7082 ReactCurrentDispatcher$1.current = prevDispatcher;
7083 }
7084 }
7085 }
7086 }
7087
7088 {
7089 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
7090 if ('undefined' !== typeof jest) {
7091 warnIfNotScopedWithMatchingAct(fiber);
7092 warnIfNotCurrentlyActingUpdatesInDev(fiber);
7093 }
7094 }
7095
7096 scheduleWork(fiber, expirationTime);
7097 }
7098}
7099
7100var ContextOnlyDispatcher = {
7101 readContext: readContext,
7102 useCallback: throwInvalidHookError,
7103 useContext: throwInvalidHookError,
7104 useEffect: throwInvalidHookError,
7105 useImperativeHandle: throwInvalidHookError,
7106 useLayoutEffect: throwInvalidHookError,
7107 useMemo: throwInvalidHookError,
7108 useReducer: throwInvalidHookError,
7109 useRef: throwInvalidHookError,
7110 useState: throwInvalidHookError,
7111 useDebugValue: throwInvalidHookError,
7112 useResponder: throwInvalidHookError,
7113 useDeferredValue: throwInvalidHookError,
7114 useTransition: throwInvalidHookError
7115};
7116var HooksDispatcherOnMountInDEV = null;
7117var HooksDispatcherOnMountWithHookTypesInDEV = null;
7118var HooksDispatcherOnUpdateInDEV = null;
7119var InvalidNestedHooksDispatcherOnMountInDEV = null;
7120var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
7121
7122{
7123 var warnInvalidContextAccess = function () {
7124 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().');
7125 };
7126
7127 var warnInvalidHookAccess = function () {
7128 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');
7129 };
7130
7131 HooksDispatcherOnMountInDEV = {
7132 readContext: function (context, observedBits) {
7133 return readContext(context, observedBits);
7134 },
7135 useCallback: function (callback, deps) {
7136 currentHookNameInDev = 'useCallback';
7137 mountHookTypesDev();
7138 checkDepsAreArrayDev(deps);
7139 return mountCallback(callback, deps);
7140 },
7141 useContext: function (context, observedBits) {
7142 currentHookNameInDev = 'useContext';
7143 mountHookTypesDev();
7144 return readContext(context, observedBits);
7145 },
7146 useEffect: function (create, deps) {
7147 currentHookNameInDev = 'useEffect';
7148 mountHookTypesDev();
7149 checkDepsAreArrayDev(deps);
7150 return mountEffect(create, deps);
7151 },
7152 useImperativeHandle: function (ref, create, deps) {
7153 currentHookNameInDev = 'useImperativeHandle';
7154 mountHookTypesDev();
7155 checkDepsAreArrayDev(deps);
7156 return mountImperativeHandle(ref, create, deps);
7157 },
7158 useLayoutEffect: function (create, deps) {
7159 currentHookNameInDev = 'useLayoutEffect';
7160 mountHookTypesDev();
7161 checkDepsAreArrayDev(deps);
7162 return mountLayoutEffect(create, deps);
7163 },
7164 useMemo: function (create, deps) {
7165 currentHookNameInDev = 'useMemo';
7166 mountHookTypesDev();
7167 checkDepsAreArrayDev(deps);
7168 var prevDispatcher = ReactCurrentDispatcher$1.current;
7169 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7170
7171 try {
7172 return mountMemo(create, deps);
7173 } finally {
7174 ReactCurrentDispatcher$1.current = prevDispatcher;
7175 }
7176 },
7177 useReducer: function (reducer, initialArg, init) {
7178 currentHookNameInDev = 'useReducer';
7179 mountHookTypesDev();
7180 var prevDispatcher = ReactCurrentDispatcher$1.current;
7181 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7182
7183 try {
7184 return mountReducer(reducer, initialArg, init);
7185 } finally {
7186 ReactCurrentDispatcher$1.current = prevDispatcher;
7187 }
7188 },
7189 useRef: function (initialValue) {
7190 currentHookNameInDev = 'useRef';
7191 mountHookTypesDev();
7192 return mountRef(initialValue);
7193 },
7194 useState: function (initialState) {
7195 currentHookNameInDev = 'useState';
7196 mountHookTypesDev();
7197 var prevDispatcher = ReactCurrentDispatcher$1.current;
7198 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7199
7200 try {
7201 return mountState(initialState);
7202 } finally {
7203 ReactCurrentDispatcher$1.current = prevDispatcher;
7204 }
7205 },
7206 useDebugValue: function (value, formatterFn) {
7207 currentHookNameInDev = 'useDebugValue';
7208 mountHookTypesDev();
7209 return mountDebugValue(value, formatterFn);
7210 },
7211 useResponder: function (responder, props) {
7212 currentHookNameInDev = 'useResponder';
7213 mountHookTypesDev();
7214 return createResponderListener(responder, props);
7215 },
7216 useDeferredValue: function (value, config) {
7217 currentHookNameInDev = 'useDeferredValue';
7218 mountHookTypesDev();
7219 return mountDeferredValue(value, config);
7220 },
7221 useTransition: function (config) {
7222 currentHookNameInDev = 'useTransition';
7223 mountHookTypesDev();
7224 return mountTransition(config);
7225 }
7226 };
7227 HooksDispatcherOnMountWithHookTypesInDEV = {
7228 readContext: function (context, observedBits) {
7229 return readContext(context, observedBits);
7230 },
7231 useCallback: function (callback, deps) {
7232 currentHookNameInDev = 'useCallback';
7233 updateHookTypesDev();
7234 return mountCallback(callback, deps);
7235 },
7236 useContext: function (context, observedBits) {
7237 currentHookNameInDev = 'useContext';
7238 updateHookTypesDev();
7239 return readContext(context, observedBits);
7240 },
7241 useEffect: function (create, deps) {
7242 currentHookNameInDev = 'useEffect';
7243 updateHookTypesDev();
7244 return mountEffect(create, deps);
7245 },
7246 useImperativeHandle: function (ref, create, deps) {
7247 currentHookNameInDev = 'useImperativeHandle';
7248 updateHookTypesDev();
7249 return mountImperativeHandle(ref, create, deps);
7250 },
7251 useLayoutEffect: function (create, deps) {
7252 currentHookNameInDev = 'useLayoutEffect';
7253 updateHookTypesDev();
7254 return mountLayoutEffect(create, deps);
7255 },
7256 useMemo: function (create, deps) {
7257 currentHookNameInDev = 'useMemo';
7258 updateHookTypesDev();
7259 var prevDispatcher = ReactCurrentDispatcher$1.current;
7260 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7261
7262 try {
7263 return mountMemo(create, deps);
7264 } finally {
7265 ReactCurrentDispatcher$1.current = prevDispatcher;
7266 }
7267 },
7268 useReducer: function (reducer, initialArg, init) {
7269 currentHookNameInDev = 'useReducer';
7270 updateHookTypesDev();
7271 var prevDispatcher = ReactCurrentDispatcher$1.current;
7272 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7273
7274 try {
7275 return mountReducer(reducer, initialArg, init);
7276 } finally {
7277 ReactCurrentDispatcher$1.current = prevDispatcher;
7278 }
7279 },
7280 useRef: function (initialValue) {
7281 currentHookNameInDev = 'useRef';
7282 updateHookTypesDev();
7283 return mountRef(initialValue);
7284 },
7285 useState: function (initialState) {
7286 currentHookNameInDev = 'useState';
7287 updateHookTypesDev();
7288 var prevDispatcher = ReactCurrentDispatcher$1.current;
7289 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7290
7291 try {
7292 return mountState(initialState);
7293 } finally {
7294 ReactCurrentDispatcher$1.current = prevDispatcher;
7295 }
7296 },
7297 useDebugValue: function (value, formatterFn) {
7298 currentHookNameInDev = 'useDebugValue';
7299 updateHookTypesDev();
7300 return mountDebugValue(value, formatterFn);
7301 },
7302 useResponder: function (responder, props) {
7303 currentHookNameInDev = 'useResponder';
7304 updateHookTypesDev();
7305 return createResponderListener(responder, props);
7306 },
7307 useDeferredValue: function (value, config) {
7308 currentHookNameInDev = 'useDeferredValue';
7309 updateHookTypesDev();
7310 return mountDeferredValue(value, config);
7311 },
7312 useTransition: function (config) {
7313 currentHookNameInDev = 'useTransition';
7314 updateHookTypesDev();
7315 return mountTransition(config);
7316 }
7317 };
7318 HooksDispatcherOnUpdateInDEV = {
7319 readContext: function (context, observedBits) {
7320 return readContext(context, observedBits);
7321 },
7322 useCallback: function (callback, deps) {
7323 currentHookNameInDev = 'useCallback';
7324 updateHookTypesDev();
7325 return updateCallback(callback, deps);
7326 },
7327 useContext: function (context, observedBits) {
7328 currentHookNameInDev = 'useContext';
7329 updateHookTypesDev();
7330 return readContext(context, observedBits);
7331 },
7332 useEffect: function (create, deps) {
7333 currentHookNameInDev = 'useEffect';
7334 updateHookTypesDev();
7335 return updateEffect(create, deps);
7336 },
7337 useImperativeHandle: function (ref, create, deps) {
7338 currentHookNameInDev = 'useImperativeHandle';
7339 updateHookTypesDev();
7340 return updateImperativeHandle(ref, create, deps);
7341 },
7342 useLayoutEffect: function (create, deps) {
7343 currentHookNameInDev = 'useLayoutEffect';
7344 updateHookTypesDev();
7345 return updateLayoutEffect(create, deps);
7346 },
7347 useMemo: function (create, deps) {
7348 currentHookNameInDev = 'useMemo';
7349 updateHookTypesDev();
7350 var prevDispatcher = ReactCurrentDispatcher$1.current;
7351 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7352
7353 try {
7354 return updateMemo(create, deps);
7355 } finally {
7356 ReactCurrentDispatcher$1.current = prevDispatcher;
7357 }
7358 },
7359 useReducer: function (reducer, initialArg, init) {
7360 currentHookNameInDev = 'useReducer';
7361 updateHookTypesDev();
7362 var prevDispatcher = ReactCurrentDispatcher$1.current;
7363 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7364
7365 try {
7366 return updateReducer(reducer, initialArg, init);
7367 } finally {
7368 ReactCurrentDispatcher$1.current = prevDispatcher;
7369 }
7370 },
7371 useRef: function (initialValue) {
7372 currentHookNameInDev = 'useRef';
7373 updateHookTypesDev();
7374 return updateRef(initialValue);
7375 },
7376 useState: function (initialState) {
7377 currentHookNameInDev = 'useState';
7378 updateHookTypesDev();
7379 var prevDispatcher = ReactCurrentDispatcher$1.current;
7380 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7381
7382 try {
7383 return updateState(initialState);
7384 } finally {
7385 ReactCurrentDispatcher$1.current = prevDispatcher;
7386 }
7387 },
7388 useDebugValue: function (value, formatterFn) {
7389 currentHookNameInDev = 'useDebugValue';
7390 updateHookTypesDev();
7391 return updateDebugValue(value, formatterFn);
7392 },
7393 useResponder: function (responder, props) {
7394 currentHookNameInDev = 'useResponder';
7395 updateHookTypesDev();
7396 return createResponderListener(responder, props);
7397 },
7398 useDeferredValue: function (value, config) {
7399 currentHookNameInDev = 'useDeferredValue';
7400 updateHookTypesDev();
7401 return updateDeferredValue(value, config);
7402 },
7403 useTransition: function (config) {
7404 currentHookNameInDev = 'useTransition';
7405 updateHookTypesDev();
7406 return updateTransition(config);
7407 }
7408 };
7409 InvalidNestedHooksDispatcherOnMountInDEV = {
7410 readContext: function (context, observedBits) {
7411 warnInvalidContextAccess();
7412 return readContext(context, observedBits);
7413 },
7414 useCallback: function (callback, deps) {
7415 currentHookNameInDev = 'useCallback';
7416 warnInvalidHookAccess();
7417 mountHookTypesDev();
7418 return mountCallback(callback, deps);
7419 },
7420 useContext: function (context, observedBits) {
7421 currentHookNameInDev = 'useContext';
7422 warnInvalidHookAccess();
7423 mountHookTypesDev();
7424 return readContext(context, observedBits);
7425 },
7426 useEffect: function (create, deps) {
7427 currentHookNameInDev = 'useEffect';
7428 warnInvalidHookAccess();
7429 mountHookTypesDev();
7430 return mountEffect(create, deps);
7431 },
7432 useImperativeHandle: function (ref, create, deps) {
7433 currentHookNameInDev = 'useImperativeHandle';
7434 warnInvalidHookAccess();
7435 mountHookTypesDev();
7436 return mountImperativeHandle(ref, create, deps);
7437 },
7438 useLayoutEffect: function (create, deps) {
7439 currentHookNameInDev = 'useLayoutEffect';
7440 warnInvalidHookAccess();
7441 mountHookTypesDev();
7442 return mountLayoutEffect(create, deps);
7443 },
7444 useMemo: function (create, deps) {
7445 currentHookNameInDev = 'useMemo';
7446 warnInvalidHookAccess();
7447 mountHookTypesDev();
7448 var prevDispatcher = ReactCurrentDispatcher$1.current;
7449 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7450
7451 try {
7452 return mountMemo(create, deps);
7453 } finally {
7454 ReactCurrentDispatcher$1.current = prevDispatcher;
7455 }
7456 },
7457 useReducer: function (reducer, initialArg, init) {
7458 currentHookNameInDev = 'useReducer';
7459 warnInvalidHookAccess();
7460 mountHookTypesDev();
7461 var prevDispatcher = ReactCurrentDispatcher$1.current;
7462 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7463
7464 try {
7465 return mountReducer(reducer, initialArg, init);
7466 } finally {
7467 ReactCurrentDispatcher$1.current = prevDispatcher;
7468 }
7469 },
7470 useRef: function (initialValue) {
7471 currentHookNameInDev = 'useRef';
7472 warnInvalidHookAccess();
7473 mountHookTypesDev();
7474 return mountRef(initialValue);
7475 },
7476 useState: function (initialState) {
7477 currentHookNameInDev = 'useState';
7478 warnInvalidHookAccess();
7479 mountHookTypesDev();
7480 var prevDispatcher = ReactCurrentDispatcher$1.current;
7481 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
7482
7483 try {
7484 return mountState(initialState);
7485 } finally {
7486 ReactCurrentDispatcher$1.current = prevDispatcher;
7487 }
7488 },
7489 useDebugValue: function (value, formatterFn) {
7490 currentHookNameInDev = 'useDebugValue';
7491 warnInvalidHookAccess();
7492 mountHookTypesDev();
7493 return mountDebugValue(value, formatterFn);
7494 },
7495 useResponder: function (responder, props) {
7496 currentHookNameInDev = 'useResponder';
7497 warnInvalidHookAccess();
7498 mountHookTypesDev();
7499 return createResponderListener(responder, props);
7500 },
7501 useDeferredValue: function (value, config) {
7502 currentHookNameInDev = 'useDeferredValue';
7503 warnInvalidHookAccess();
7504 mountHookTypesDev();
7505 return mountDeferredValue(value, config);
7506 },
7507 useTransition: function (config) {
7508 currentHookNameInDev = 'useTransition';
7509 warnInvalidHookAccess();
7510 mountHookTypesDev();
7511 return mountTransition(config);
7512 }
7513 };
7514 InvalidNestedHooksDispatcherOnUpdateInDEV = {
7515 readContext: function (context, observedBits) {
7516 warnInvalidContextAccess();
7517 return readContext(context, observedBits);
7518 },
7519 useCallback: function (callback, deps) {
7520 currentHookNameInDev = 'useCallback';
7521 warnInvalidHookAccess();
7522 updateHookTypesDev();
7523 return updateCallback(callback, deps);
7524 },
7525 useContext: function (context, observedBits) {
7526 currentHookNameInDev = 'useContext';
7527 warnInvalidHookAccess();
7528 updateHookTypesDev();
7529 return readContext(context, observedBits);
7530 },
7531 useEffect: function (create, deps) {
7532 currentHookNameInDev = 'useEffect';
7533 warnInvalidHookAccess();
7534 updateHookTypesDev();
7535 return updateEffect(create, deps);
7536 },
7537 useImperativeHandle: function (ref, create, deps) {
7538 currentHookNameInDev = 'useImperativeHandle';
7539 warnInvalidHookAccess();
7540 updateHookTypesDev();
7541 return updateImperativeHandle(ref, create, deps);
7542 },
7543 useLayoutEffect: function (create, deps) {
7544 currentHookNameInDev = 'useLayoutEffect';
7545 warnInvalidHookAccess();
7546 updateHookTypesDev();
7547 return updateLayoutEffect(create, deps);
7548 },
7549 useMemo: function (create, deps) {
7550 currentHookNameInDev = 'useMemo';
7551 warnInvalidHookAccess();
7552 updateHookTypesDev();
7553 var prevDispatcher = ReactCurrentDispatcher$1.current;
7554 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7555
7556 try {
7557 return updateMemo(create, deps);
7558 } finally {
7559 ReactCurrentDispatcher$1.current = prevDispatcher;
7560 }
7561 },
7562 useReducer: function (reducer, initialArg, init) {
7563 currentHookNameInDev = 'useReducer';
7564 warnInvalidHookAccess();
7565 updateHookTypesDev();
7566 var prevDispatcher = ReactCurrentDispatcher$1.current;
7567 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7568
7569 try {
7570 return updateReducer(reducer, initialArg, init);
7571 } finally {
7572 ReactCurrentDispatcher$1.current = prevDispatcher;
7573 }
7574 },
7575 useRef: function (initialValue) {
7576 currentHookNameInDev = 'useRef';
7577 warnInvalidHookAccess();
7578 updateHookTypesDev();
7579 return updateRef(initialValue);
7580 },
7581 useState: function (initialState) {
7582 currentHookNameInDev = 'useState';
7583 warnInvalidHookAccess();
7584 updateHookTypesDev();
7585 var prevDispatcher = ReactCurrentDispatcher$1.current;
7586 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
7587
7588 try {
7589 return updateState(initialState);
7590 } finally {
7591 ReactCurrentDispatcher$1.current = prevDispatcher;
7592 }
7593 },
7594 useDebugValue: function (value, formatterFn) {
7595 currentHookNameInDev = 'useDebugValue';
7596 warnInvalidHookAccess();
7597 updateHookTypesDev();
7598 return updateDebugValue(value, formatterFn);
7599 },
7600 useResponder: function (responder, props) {
7601 currentHookNameInDev = 'useResponder';
7602 warnInvalidHookAccess();
7603 updateHookTypesDev();
7604 return createResponderListener(responder, props);
7605 },
7606 useDeferredValue: function (value, config) {
7607 currentHookNameInDev = 'useDeferredValue';
7608 warnInvalidHookAccess();
7609 updateHookTypesDev();
7610 return updateDeferredValue(value, config);
7611 },
7612 useTransition: function (config) {
7613 currentHookNameInDev = 'useTransition';
7614 warnInvalidHookAccess();
7615 updateHookTypesDev();
7616 return updateTransition(config);
7617 }
7618 };
7619}
7620
7621// CommonJS interop named imports.
7622
7623var now$1 = Scheduler$1.unstable_now;
7624var commitTime = 0;
7625var profilerStartTime = -1;
7626
7627function getCommitTime() {
7628 return commitTime;
7629}
7630
7631function recordCommitTime() {
7632 if (!enableProfilerTimer) {
7633 return;
7634 }
7635
7636 commitTime = now$1();
7637}
7638
7639function startProfilerTimer(fiber) {
7640 if (!enableProfilerTimer) {
7641 return;
7642 }
7643
7644 profilerStartTime = now$1();
7645
7646 if (fiber.actualStartTime < 0) {
7647 fiber.actualStartTime = now$1();
7648 }
7649}
7650
7651function stopProfilerTimerIfRunning(fiber) {
7652 if (!enableProfilerTimer) {
7653 return;
7654 }
7655
7656 profilerStartTime = -1;
7657}
7658
7659function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
7660 if (!enableProfilerTimer) {
7661 return;
7662 }
7663
7664 if (profilerStartTime >= 0) {
7665 var elapsedTime = now$1() - profilerStartTime;
7666 fiber.actualDuration += elapsedTime;
7667
7668 if (overrideBaseTime) {
7669 fiber.selfBaseDuration = elapsedTime;
7670 }
7671
7672 profilerStartTime = -1;
7673 }
7674}
7675
7676// This may have been an insertion or a hydration.
7677
7678var hydrationParentFiber = null;
7679var nextHydratableInstance = null;
7680var isHydrating = false;
7681
7682function warnIfHydrating() {
7683 {
7684 !!isHydrating ? warning$1(false, 'We should not be hydrating here. This is a bug in React. Please file a bug.') : void 0;
7685 }
7686}
7687
7688function enterHydrationState(fiber) {
7689 if (!supportsHydration) {
7690 return false;
7691 }
7692
7693 var parentInstance = fiber.stateNode.containerInfo;
7694 nextHydratableInstance = getFirstHydratableChild(parentInstance);
7695 hydrationParentFiber = fiber;
7696 isHydrating = true;
7697 return true;
7698}
7699
7700function reenterHydrationStateFromDehydratedSuspenseInstance(fiber, suspenseInstance) {
7701 if (!supportsHydration) {
7702 return false;
7703 }
7704
7705 nextHydratableInstance = getNextHydratableSibling(suspenseInstance);
7706 popToNextHostParent(fiber);
7707 isHydrating = true;
7708 return true;
7709}
7710
7711function deleteHydratableInstance(returnFiber, instance) {
7712 {
7713 switch (returnFiber.tag) {
7714 case HostRoot:
7715 didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
7716 break;
7717
7718 case HostComponent:
7719 didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
7720 break;
7721 }
7722 }
7723
7724 var childToDelete = createFiberFromHostInstanceForDeletion();
7725 childToDelete.stateNode = instance;
7726 childToDelete.return = returnFiber;
7727 childToDelete.effectTag = Deletion; // This might seem like it belongs on progressedFirstDeletion. However,
7728 // these children are not part of the reconciliation list of children.
7729 // Even if we abort and rereconcile the children, that will try to hydrate
7730 // again and the nodes are still in the host tree so these will be
7731 // recreated.
7732
7733 if (returnFiber.lastEffect !== null) {
7734 returnFiber.lastEffect.nextEffect = childToDelete;
7735 returnFiber.lastEffect = childToDelete;
7736 } else {
7737 returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
7738 }
7739}
7740
7741function insertNonHydratedInstance(returnFiber, fiber) {
7742 fiber.effectTag = fiber.effectTag & ~Hydrating | Placement;
7743
7744 {
7745 switch (returnFiber.tag) {
7746 case HostRoot:
7747 {
7748 var parentContainer = returnFiber.stateNode.containerInfo;
7749
7750 switch (fiber.tag) {
7751 case HostComponent:
7752 var type = fiber.type;
7753 var props = fiber.pendingProps;
7754 didNotFindHydratableContainerInstance(parentContainer, type, props);
7755 break;
7756
7757 case HostText:
7758 var text = fiber.pendingProps;
7759 didNotFindHydratableContainerTextInstance(parentContainer, text);
7760 break;
7761
7762 case SuspenseComponent:
7763 didNotFindHydratableContainerSuspenseInstance(parentContainer);
7764 break;
7765 }
7766
7767 break;
7768 }
7769
7770 case HostComponent:
7771 {
7772 var parentType = returnFiber.type;
7773 var parentProps = returnFiber.memoizedProps;
7774 var parentInstance = returnFiber.stateNode;
7775
7776 switch (fiber.tag) {
7777 case HostComponent:
7778 var _type = fiber.type;
7779 var _props = fiber.pendingProps;
7780 didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type, _props);
7781 break;
7782
7783 case HostText:
7784 var _text = fiber.pendingProps;
7785 didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
7786 break;
7787
7788 case SuspenseComponent:
7789 didNotFindHydratableSuspenseInstance(parentType, parentProps, parentInstance);
7790 break;
7791 }
7792
7793 break;
7794 }
7795
7796 default:
7797 return;
7798 }
7799 }
7800}
7801
7802function tryHydrate(fiber, nextInstance) {
7803 switch (fiber.tag) {
7804 case HostComponent:
7805 {
7806 var type = fiber.type;
7807 var props = fiber.pendingProps;
7808 var instance = canHydrateInstance(nextInstance, type, props);
7809
7810 if (instance !== null) {
7811 fiber.stateNode = instance;
7812 return true;
7813 }
7814
7815 return false;
7816 }
7817
7818 case HostText:
7819 {
7820 var text = fiber.pendingProps;
7821 var textInstance = canHydrateTextInstance(nextInstance, text);
7822
7823 if (textInstance !== null) {
7824 fiber.stateNode = textInstance;
7825 return true;
7826 }
7827
7828 return false;
7829 }
7830
7831 case SuspenseComponent:
7832 {
7833 if (enableSuspenseServerRenderer) {
7834 var suspenseInstance = canHydrateSuspenseInstance(nextInstance);
7835
7836 if (suspenseInstance !== null) {
7837 var suspenseState = {
7838 dehydrated: suspenseInstance,
7839 retryTime: Never
7840 };
7841 fiber.memoizedState = suspenseState; // Store the dehydrated fragment as a child fiber.
7842 // This simplifies the code for getHostSibling and deleting nodes,
7843 // since it doesn't have to consider all Suspense boundaries and
7844 // check if they're dehydrated ones or not.
7845
7846 var dehydratedFragment = createFiberFromDehydratedFragment(suspenseInstance);
7847 dehydratedFragment.return = fiber;
7848 fiber.child = dehydratedFragment;
7849 return true;
7850 }
7851 }
7852
7853 return false;
7854 }
7855
7856 default:
7857 return false;
7858 }
7859}
7860
7861function tryToClaimNextHydratableInstance(fiber) {
7862 if (!isHydrating) {
7863 return;
7864 }
7865
7866 var nextInstance = nextHydratableInstance;
7867
7868 if (!nextInstance) {
7869 // Nothing to hydrate. Make it an insertion.
7870 insertNonHydratedInstance(hydrationParentFiber, fiber);
7871 isHydrating = false;
7872 hydrationParentFiber = fiber;
7873 return;
7874 }
7875
7876 var firstAttemptedInstance = nextInstance;
7877
7878 if (!tryHydrate(fiber, nextInstance)) {
7879 // If we can't hydrate this instance let's try the next one.
7880 // We use this as a heuristic. It's based on intuition and not data so it
7881 // might be flawed or unnecessary.
7882 nextInstance = getNextHydratableSibling(firstAttemptedInstance);
7883
7884 if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
7885 // Nothing to hydrate. Make it an insertion.
7886 insertNonHydratedInstance(hydrationParentFiber, fiber);
7887 isHydrating = false;
7888 hydrationParentFiber = fiber;
7889 return;
7890 } // We matched the next one, we'll now assume that the first one was
7891 // superfluous and we'll delete it. Since we can't eagerly delete it
7892 // we'll have to schedule a deletion. To do that, this node needs a dummy
7893 // fiber associated with it.
7894
7895
7896 deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
7897 }
7898
7899 hydrationParentFiber = fiber;
7900 nextHydratableInstance = getFirstHydratableChild(nextInstance);
7901}
7902
7903function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
7904 if (!supportsHydration) {
7905 {
7906 {
7907 throw Error("Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");
7908 }
7909 }
7910 }
7911
7912 var instance = fiber.stateNode;
7913 var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber); // TODO: Type this specific to this type of component.
7914
7915 fiber.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
7916 // is a new ref we mark this as an update.
7917
7918 if (updatePayload !== null) {
7919 return true;
7920 }
7921
7922 return false;
7923}
7924
7925function prepareToHydrateHostTextInstance(fiber) {
7926 if (!supportsHydration) {
7927 {
7928 {
7929 throw Error("Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");
7930 }
7931 }
7932 }
7933
7934 var textInstance = fiber.stateNode;
7935 var textContent = fiber.memoizedProps;
7936 var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
7937
7938 {
7939 if (shouldUpdate) {
7940 // We assume that prepareToHydrateHostTextInstance is called in a context where the
7941 // hydration parent is the parent host component of this host text.
7942 var returnFiber = hydrationParentFiber;
7943
7944 if (returnFiber !== null) {
7945 switch (returnFiber.tag) {
7946 case HostRoot:
7947 {
7948 var parentContainer = returnFiber.stateNode.containerInfo;
7949 didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
7950 break;
7951 }
7952
7953 case HostComponent:
7954 {
7955 var parentType = returnFiber.type;
7956 var parentProps = returnFiber.memoizedProps;
7957 var parentInstance = returnFiber.stateNode;
7958 didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
7959 break;
7960 }
7961 }
7962 }
7963 }
7964 }
7965
7966 return shouldUpdate;
7967}
7968
7969function prepareToHydrateHostSuspenseInstance(fiber) {
7970 if (!supportsHydration) {
7971 {
7972 {
7973 throw Error("Expected prepareToHydrateHostSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");
7974 }
7975 }
7976 }
7977
7978 var suspenseState = fiber.memoizedState;
7979 var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
7980
7981 if (!suspenseInstance) {
7982 {
7983 throw Error("Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue.");
7984 }
7985 }
7986
7987 hydrateSuspenseInstance(suspenseInstance, fiber);
7988}
7989
7990function skipPastDehydratedSuspenseInstance(fiber) {
7991 if (!supportsHydration) {
7992 {
7993 {
7994 throw Error("Expected skipPastDehydratedSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");
7995 }
7996 }
7997 }
7998
7999 var suspenseState = fiber.memoizedState;
8000 var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
8001
8002 if (!suspenseInstance) {
8003 {
8004 throw Error("Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue.");
8005 }
8006 }
8007
8008 return getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
8009}
8010
8011function popToNextHostParent(fiber) {
8012 var parent = fiber.return;
8013
8014 while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== SuspenseComponent) {
8015 parent = parent.return;
8016 }
8017
8018 hydrationParentFiber = parent;
8019}
8020
8021function popHydrationState(fiber) {
8022 if (!supportsHydration) {
8023 return false;
8024 }
8025
8026 if (fiber !== hydrationParentFiber) {
8027 // We're deeper than the current hydration context, inside an inserted
8028 // tree.
8029 return false;
8030 }
8031
8032 if (!isHydrating) {
8033 // If we're not currently hydrating but we're in a hydration context, then
8034 // we were an insertion and now need to pop up reenter hydration of our
8035 // siblings.
8036 popToNextHostParent(fiber);
8037 isHydrating = true;
8038 return false;
8039 }
8040
8041 var type = fiber.type; // If we have any remaining hydratable nodes, we need to delete them now.
8042 // We only do this deeper than head and body since they tend to have random
8043 // other nodes in them. We also ignore components with pure text content in
8044 // side of them.
8045 // TODO: Better heuristic.
8046
8047 if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
8048 var nextInstance = nextHydratableInstance;
8049
8050 while (nextInstance) {
8051 deleteHydratableInstance(fiber, nextInstance);
8052 nextInstance = getNextHydratableSibling(nextInstance);
8053 }
8054 }
8055
8056 popToNextHostParent(fiber);
8057
8058 if (fiber.tag === SuspenseComponent) {
8059 nextHydratableInstance = skipPastDehydratedSuspenseInstance(fiber);
8060 } else {
8061 nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
8062 }
8063
8064 return true;
8065}
8066
8067function resetHydrationState() {
8068 if (!supportsHydration) {
8069 return;
8070 }
8071
8072 hydrationParentFiber = null;
8073 nextHydratableInstance = null;
8074 isHydrating = false;
8075}
8076
8077var ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner;
8078var didReceiveUpdate = false;
8079var didWarnAboutBadClass;
8080var didWarnAboutModulePatternComponent;
8081var didWarnAboutContextTypeOnFunctionComponent;
8082var didWarnAboutGetDerivedStateOnFunctionComponent;
8083var didWarnAboutFunctionRefs;
8084var didWarnAboutReassigningProps;
8085var didWarnAboutMaxDuration;
8086var didWarnAboutRevealOrder;
8087var didWarnAboutTailOptions;
8088var didWarnAboutDefaultPropsOnFunctionComponent;
8089
8090{
8091 didWarnAboutBadClass = {};
8092 didWarnAboutModulePatternComponent = {};
8093 didWarnAboutContextTypeOnFunctionComponent = {};
8094 didWarnAboutGetDerivedStateOnFunctionComponent = {};
8095 didWarnAboutFunctionRefs = {};
8096 didWarnAboutReassigningProps = false;
8097 didWarnAboutMaxDuration = false;
8098 didWarnAboutRevealOrder = {};
8099 didWarnAboutTailOptions = {};
8100 didWarnAboutDefaultPropsOnFunctionComponent = {};
8101}
8102
8103function reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime) {
8104 if (current$$1 === null) {
8105 // If this is a fresh new component that hasn't been rendered yet, we
8106 // won't update its child set by applying minimal side-effects. Instead,
8107 // we will add them all to the child before it gets rendered. That means
8108 // we can optimize this reconciliation pass by not tracking side-effects.
8109 workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8110 } else {
8111 // If the current child is the same as the work in progress, it means that
8112 // we haven't yet started any work on these children. Therefore, we use
8113 // the clone algorithm to create a copy of all the current children.
8114 // If we had any progressed work already, that is invalid at this point so
8115 // let's throw it out.
8116 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, nextChildren, renderExpirationTime);
8117 }
8118}
8119
8120function forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime) {
8121 // This function is fork of reconcileChildren. It's used in cases where we
8122 // want to reconcile without matching against the existing set. This has the
8123 // effect of all current children being unmounted; even if the type and key
8124 // are the same, the old child is unmounted and a new child is created.
8125 //
8126 // To do this, we're going to go through the reconcile algorithm twice. In
8127 // the first pass, we schedule a deletion for all the current children by
8128 // passing null.
8129 workInProgress.child = reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime); // In the second pass, we mount the new children. The trick here is that we
8130 // pass null in place of where we usually pass the current child set. This has
8131 // the effect of remounting all children regardless of whether their their
8132 // identity matches.
8133
8134 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8135}
8136
8137function updateForwardRef(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8138 // TODO: current can be non-null here even if the component
8139 // hasn't yet mounted. This happens after the first render suspends.
8140 // We'll need to figure out if this is fine or can cause issues.
8141 {
8142 if (workInProgress.type !== workInProgress.elementType) {
8143 // Lazy component props can't be validated in createElement
8144 // because they're only guaranteed to be resolved here.
8145 var innerPropTypes = Component.propTypes;
8146
8147 if (innerPropTypes) {
8148 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
8149 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8150 }
8151 }
8152 }
8153
8154 var render = Component.render;
8155 var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
8156
8157 var nextChildren;
8158 prepareToReadContext(workInProgress, renderExpirationTime);
8159
8160 {
8161 ReactCurrentOwner$2.current = workInProgress;
8162 setCurrentPhase('render');
8163 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
8164
8165 if (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8166 // Only double-render components with Hooks
8167 if (workInProgress.memoizedState !== null) {
8168 nextChildren = renderWithHooks(current$$1, workInProgress, render, nextProps, ref, renderExpirationTime);
8169 }
8170 }
8171
8172 setCurrentPhase(null);
8173 }
8174
8175 if (current$$1 !== null && !didReceiveUpdate) {
8176 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
8177 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8178 } // React DevTools reads this flag.
8179
8180
8181 workInProgress.effectTag |= PerformedWork;
8182 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8183 return workInProgress.child;
8184}
8185
8186function updateMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
8187 if (current$$1 === null) {
8188 var type = Component.type;
8189
8190 if (isSimpleFunctionComponent(type) && Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
8191 Component.defaultProps === undefined) {
8192 var resolvedType = type;
8193
8194 {
8195 resolvedType = resolveFunctionForHotReloading(type);
8196 } // If this is a plain function component without default props,
8197 // and with only the default shallow comparison, we upgrade it
8198 // to a SimpleMemoComponent to allow fast path updates.
8199
8200
8201 workInProgress.tag = SimpleMemoComponent;
8202 workInProgress.type = resolvedType;
8203
8204 {
8205 validateFunctionComponentInDev(workInProgress, type);
8206 }
8207
8208 return updateSimpleMemoComponent(current$$1, workInProgress, resolvedType, nextProps, updateExpirationTime, renderExpirationTime);
8209 }
8210
8211 {
8212 var innerPropTypes = type.propTypes;
8213
8214 if (innerPropTypes) {
8215 // Inner memo component props aren't currently validated in createElement.
8216 // We could move it there, but we'd still need this for lazy code path.
8217 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
8218 'prop', getComponentName(type), getCurrentFiberStackInDev);
8219 }
8220 }
8221
8222 var child = createFiberFromTypeAndProps(Component.type, null, nextProps, null, workInProgress.mode, renderExpirationTime);
8223 child.ref = workInProgress.ref;
8224 child.return = workInProgress;
8225 workInProgress.child = child;
8226 return child;
8227 }
8228
8229 {
8230 var _type = Component.type;
8231 var _innerPropTypes = _type.propTypes;
8232
8233 if (_innerPropTypes) {
8234 // Inner memo component props aren't currently validated in createElement.
8235 // We could move it there, but we'd still need this for lazy code path.
8236 checkPropTypes_1(_innerPropTypes, nextProps, // Resolved props
8237 'prop', getComponentName(_type), getCurrentFiberStackInDev);
8238 }
8239 }
8240
8241 var currentChild = current$$1.child; // This is always exactly one child
8242
8243 if (updateExpirationTime < renderExpirationTime) {
8244 // This will be the props with resolved defaultProps,
8245 // unlike current.memoizedProps which will be the unresolved ones.
8246 var prevProps = currentChild.memoizedProps; // Default to shallow comparison
8247
8248 var compare = Component.compare;
8249 compare = compare !== null ? compare : shallowEqual;
8250
8251 if (compare(prevProps, nextProps) && current$$1.ref === workInProgress.ref) {
8252 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8253 }
8254 } // React DevTools reads this flag.
8255
8256
8257 workInProgress.effectTag |= PerformedWork;
8258 var newChild = createWorkInProgress(currentChild, nextProps, renderExpirationTime);
8259 newChild.ref = workInProgress.ref;
8260 newChild.return = workInProgress;
8261 workInProgress.child = newChild;
8262 return newChild;
8263}
8264
8265function updateSimpleMemoComponent(current$$1, workInProgress, Component, nextProps, updateExpirationTime, renderExpirationTime) {
8266 // TODO: current can be non-null here even if the component
8267 // hasn't yet mounted. This happens when the inner render suspends.
8268 // We'll need to figure out if this is fine or can cause issues.
8269 {
8270 if (workInProgress.type !== workInProgress.elementType) {
8271 // Lazy component props can't be validated in createElement
8272 // because they're only guaranteed to be resolved here.
8273 var outerMemoType = workInProgress.elementType;
8274
8275 if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
8276 // We warn when you define propTypes on lazy()
8277 // so let's just skip over it to find memo() outer wrapper.
8278 // Inner props for memo are validated later.
8279 outerMemoType = refineResolvedLazyComponent(outerMemoType);
8280 }
8281
8282 var outerPropTypes = outerMemoType && outerMemoType.propTypes;
8283
8284 if (outerPropTypes) {
8285 checkPropTypes_1(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
8286 'prop', getComponentName(outerMemoType), getCurrentFiberStackInDev);
8287 } // Inner propTypes will be validated in the function component path.
8288
8289 }
8290 }
8291
8292 if (current$$1 !== null) {
8293 var prevProps = current$$1.memoizedProps;
8294
8295 if (shallowEqual(prevProps, nextProps) && current$$1.ref === workInProgress.ref && ( // Prevent bailout if the implementation changed due to hot reload:
8296 workInProgress.type === current$$1.type)) {
8297 didReceiveUpdate = false;
8298
8299 if (updateExpirationTime < renderExpirationTime) {
8300 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8301 }
8302 }
8303 }
8304
8305 return updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
8306}
8307
8308function updateFragment(current$$1, workInProgress, renderExpirationTime) {
8309 var nextChildren = workInProgress.pendingProps;
8310 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8311 return workInProgress.child;
8312}
8313
8314function updateMode(current$$1, workInProgress, renderExpirationTime) {
8315 var nextChildren = workInProgress.pendingProps.children;
8316 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8317 return workInProgress.child;
8318}
8319
8320function updateProfiler(current$$1, workInProgress, renderExpirationTime) {
8321 if (enableProfilerTimer) {
8322 workInProgress.effectTag |= Update;
8323 }
8324
8325 var nextProps = workInProgress.pendingProps;
8326 var nextChildren = nextProps.children;
8327 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8328 return workInProgress.child;
8329}
8330
8331function markRef(current$$1, workInProgress) {
8332 var ref = workInProgress.ref;
8333
8334 if (current$$1 === null && ref !== null || current$$1 !== null && current$$1.ref !== ref) {
8335 // Schedule a Ref effect
8336 workInProgress.effectTag |= Ref;
8337 }
8338}
8339
8340function updateFunctionComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8341 {
8342 if (workInProgress.type !== workInProgress.elementType) {
8343 // Lazy component props can't be validated in createElement
8344 // because they're only guaranteed to be resolved here.
8345 var innerPropTypes = Component.propTypes;
8346
8347 if (innerPropTypes) {
8348 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
8349 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8350 }
8351 }
8352 }
8353
8354 var context;
8355
8356 if (!disableLegacyContext) {
8357 var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
8358 context = getMaskedContext(workInProgress, unmaskedContext);
8359 }
8360
8361 var nextChildren;
8362 prepareToReadContext(workInProgress, renderExpirationTime);
8363
8364 {
8365 ReactCurrentOwner$2.current = workInProgress;
8366 setCurrentPhase('render');
8367 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
8368
8369 if (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8370 // Only double-render components with Hooks
8371 if (workInProgress.memoizedState !== null) {
8372 nextChildren = renderWithHooks(current$$1, workInProgress, Component, nextProps, context, renderExpirationTime);
8373 }
8374 }
8375
8376 setCurrentPhase(null);
8377 }
8378
8379 if (current$$1 !== null && !didReceiveUpdate) {
8380 bailoutHooks(current$$1, workInProgress, renderExpirationTime);
8381 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8382 } // React DevTools reads this flag.
8383
8384
8385 workInProgress.effectTag |= PerformedWork;
8386 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8387 return workInProgress.child;
8388}
8389
8390function updateClassComponent(current$$1, workInProgress, Component, nextProps, renderExpirationTime) {
8391 {
8392 if (workInProgress.type !== workInProgress.elementType) {
8393 // Lazy component props can't be validated in createElement
8394 // because they're only guaranteed to be resolved here.
8395 var innerPropTypes = Component.propTypes;
8396
8397 if (innerPropTypes) {
8398 checkPropTypes_1(innerPropTypes, nextProps, // Resolved props
8399 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8400 }
8401 }
8402 } // Push context providers early to prevent context stack mismatches.
8403 // During mounting we don't know the child context yet as the instance doesn't exist.
8404 // We will invalidate the child context in finishClassComponent() right after rendering.
8405
8406
8407 var hasContext;
8408
8409 if (isContextProvider(Component)) {
8410 hasContext = true;
8411 pushContextProvider(workInProgress);
8412 } else {
8413 hasContext = false;
8414 }
8415
8416 prepareToReadContext(workInProgress, renderExpirationTime);
8417 var instance = workInProgress.stateNode;
8418 var shouldUpdate;
8419
8420 if (instance === null) {
8421 if (current$$1 !== null) {
8422 // An class component without an instance only mounts if it suspended
8423 // inside a non- concurrent tree, in an inconsistent state. We want to
8424 // tree it like a new mount, even though an empty version of it already
8425 // committed. Disconnect the alternate pointers.
8426 current$$1.alternate = null;
8427 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8428
8429 workInProgress.effectTag |= Placement;
8430 } // In the initial pass we might need to construct the instance.
8431
8432
8433 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8434 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8435 shouldUpdate = true;
8436 } else if (current$$1 === null) {
8437 // In a resume, we'll already have an instance we can reuse.
8438 shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8439 } else {
8440 shouldUpdate = updateClassInstance(current$$1, workInProgress, Component, nextProps, renderExpirationTime);
8441 }
8442
8443 var nextUnitOfWork = finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime);
8444
8445 {
8446 var inst = workInProgress.stateNode;
8447
8448 if (inst.props !== nextProps) {
8449 !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;
8450 didWarnAboutReassigningProps = true;
8451 }
8452 }
8453
8454 return nextUnitOfWork;
8455}
8456
8457function finishClassComponent(current$$1, workInProgress, Component, shouldUpdate, hasContext, renderExpirationTime) {
8458 // Refs should update even if shouldComponentUpdate returns false
8459 markRef(current$$1, workInProgress);
8460 var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
8461
8462 if (!shouldUpdate && !didCaptureError) {
8463 // Context providers should defer to sCU for rendering
8464 if (hasContext) {
8465 invalidateContextProvider(workInProgress, Component, false);
8466 }
8467
8468 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8469 }
8470
8471 var instance = workInProgress.stateNode; // Rerender
8472
8473 ReactCurrentOwner$2.current = workInProgress;
8474 var nextChildren;
8475
8476 if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
8477 // If we captured an error, but getDerivedStateFrom catch is not defined,
8478 // unmount all the children. componentDidCatch will schedule an update to
8479 // re-render a fallback. This is temporary until we migrate everyone to
8480 // the new API.
8481 // TODO: Warn in a future release.
8482 nextChildren = null;
8483
8484 if (enableProfilerTimer) {
8485 stopProfilerTimerIfRunning(workInProgress);
8486 }
8487 } else {
8488 {
8489 setCurrentPhase('render');
8490 nextChildren = instance.render();
8491
8492 if (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8493 instance.render();
8494 }
8495
8496 setCurrentPhase(null);
8497 }
8498 } // React DevTools reads this flag.
8499
8500
8501 workInProgress.effectTag |= PerformedWork;
8502
8503 if (current$$1 !== null && didCaptureError) {
8504 // If we're recovering from an error, reconcile without reusing any of
8505 // the existing children. Conceptually, the normal children and the children
8506 // that are shown on error are two different sets, so we shouldn't reuse
8507 // normal children even if their identities match.
8508 forceUnmountCurrentAndReconcile(current$$1, workInProgress, nextChildren, renderExpirationTime);
8509 } else {
8510 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8511 } // Memoize state using the values we just used to render.
8512 // TODO: Restructure so we never read values from the instance.
8513
8514
8515 workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
8516
8517 if (hasContext) {
8518 invalidateContextProvider(workInProgress, Component, true);
8519 }
8520
8521 return workInProgress.child;
8522}
8523
8524function pushHostRootContext(workInProgress) {
8525 var root = workInProgress.stateNode;
8526
8527 if (root.pendingContext) {
8528 pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
8529 } else if (root.context) {
8530 // Should always be set
8531 pushTopLevelContextObject(workInProgress, root.context, false);
8532 }
8533
8534 pushHostContainer(workInProgress, root.containerInfo);
8535}
8536
8537function updateHostRoot(current$$1, workInProgress, renderExpirationTime) {
8538 pushHostRootContext(workInProgress);
8539 var updateQueue = workInProgress.updateQueue;
8540
8541 if (!(updateQueue !== null)) {
8542 {
8543 throw 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.");
8544 }
8545 }
8546
8547 var nextProps = workInProgress.pendingProps;
8548 var prevState = workInProgress.memoizedState;
8549 var prevChildren = prevState !== null ? prevState.element : null;
8550 processUpdateQueue(workInProgress, updateQueue, nextProps, null, renderExpirationTime);
8551 var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
8552 // being called "element".
8553
8554 var nextChildren = nextState.element;
8555
8556 if (nextChildren === prevChildren) {
8557 // If the state is the same as before, that's a bailout because we had
8558 // no work that expires at this time.
8559 resetHydrationState();
8560 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
8561 }
8562
8563 var root = workInProgress.stateNode;
8564
8565 if (root.hydrate && enterHydrationState(workInProgress)) {
8566 // If we don't have any current children this might be the first pass.
8567 // We always try to hydrate. If this isn't a hydration pass there won't
8568 // be any children to hydrate which is effectively the same thing as
8569 // not hydrating.
8570 var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
8571 workInProgress.child = child;
8572 var node = child;
8573
8574 while (node) {
8575 // Mark each child as hydrating. This is a fast path to know whether this
8576 // tree is part of a hydrating tree. This is used to determine if a child
8577 // node has fully mounted yet, and for scheduling event replaying.
8578 // Conceptually this is similar to Placement in that a new subtree is
8579 // inserted into the React tree here. It just happens to not need DOM
8580 // mutations because it already exists.
8581 node.effectTag = node.effectTag & ~Placement | Hydrating;
8582 node = node.sibling;
8583 }
8584 } else {
8585 // Otherwise reset hydration state in case we aborted and resumed another
8586 // root.
8587 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8588 resetHydrationState();
8589 }
8590
8591 return workInProgress.child;
8592}
8593
8594function updateHostComponent(current$$1, workInProgress, renderExpirationTime) {
8595 pushHostContext(workInProgress);
8596
8597 if (current$$1 === null) {
8598 tryToClaimNextHydratableInstance(workInProgress);
8599 }
8600
8601 var type = workInProgress.type;
8602 var nextProps = workInProgress.pendingProps;
8603 var prevProps = current$$1 !== null ? current$$1.memoizedProps : null;
8604 var nextChildren = nextProps.children;
8605 var isDirectTextChild = shouldSetTextContent(type, nextProps);
8606
8607 if (isDirectTextChild) {
8608 // We special case a direct text child of a host node. This is a common
8609 // case. We won't handle it as a reified child. We will instead handle
8610 // this in the host environment that also have access to this prop. That
8611 // avoids allocating another HostText fiber and traversing it.
8612 nextChildren = null;
8613 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
8614 // If we're switching from a direct text child to a normal child, or to
8615 // empty, we need to schedule the text content to be reset.
8616 workInProgress.effectTag |= ContentReset;
8617 }
8618
8619 markRef(current$$1, workInProgress); // Check the host config to see if the children are offscreen/hidden.
8620
8621 if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(type, nextProps)) {
8622 if (enableSchedulerTracing) {
8623 markSpawnedWork(Never);
8624 } // Schedule this fiber to re-render at offscreen priority. Then bailout.
8625
8626
8627 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
8628 return null;
8629 }
8630
8631 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
8632 return workInProgress.child;
8633}
8634
8635function updateHostText(current$$1, workInProgress) {
8636 if (current$$1 === null) {
8637 tryToClaimNextHydratableInstance(workInProgress);
8638 } // Nothing to do here. This is terminal. We'll do the completion step
8639 // immediately after.
8640
8641
8642 return null;
8643}
8644
8645function mountLazyComponent(_current, workInProgress, elementType, updateExpirationTime, renderExpirationTime) {
8646 if (_current !== null) {
8647 // An lazy component only mounts if it suspended inside a non-
8648 // concurrent tree, in an inconsistent state. We want to treat it like
8649 // a new mount, even though an empty version of it already committed.
8650 // Disconnect the alternate pointers.
8651 _current.alternate = null;
8652 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8653
8654 workInProgress.effectTag |= Placement;
8655 }
8656
8657 var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
8658 // Cancel and resume right after we know the tag.
8659
8660 cancelWorkTimer(workInProgress);
8661 var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
8662
8663 workInProgress.type = Component;
8664 var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
8665 startWorkTimer(workInProgress);
8666 var resolvedProps = resolveDefaultProps(Component, props);
8667 var child;
8668
8669 switch (resolvedTag) {
8670 case FunctionComponent:
8671 {
8672 {
8673 validateFunctionComponentInDev(workInProgress, Component);
8674 workInProgress.type = Component = resolveFunctionForHotReloading(Component);
8675 }
8676
8677 child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8678 break;
8679 }
8680
8681 case ClassComponent:
8682 {
8683 {
8684 workInProgress.type = Component = resolveClassForHotReloading(Component);
8685 }
8686
8687 child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8688 break;
8689 }
8690
8691 case ForwardRef:
8692 {
8693 {
8694 workInProgress.type = Component = resolveForwardRefForHotReloading(Component);
8695 }
8696
8697 child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderExpirationTime);
8698 break;
8699 }
8700
8701 case MemoComponent:
8702 {
8703 {
8704 if (workInProgress.type !== workInProgress.elementType) {
8705 var outerPropTypes = Component.propTypes;
8706
8707 if (outerPropTypes) {
8708 checkPropTypes_1(outerPropTypes, resolvedProps, // Resolved for outer only
8709 'prop', getComponentName(Component), getCurrentFiberStackInDev);
8710 }
8711 }
8712 }
8713
8714 child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
8715 updateExpirationTime, renderExpirationTime);
8716 break;
8717 }
8718
8719 default:
8720 {
8721 var hint = '';
8722
8723 {
8724 if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
8725 hint = ' Did you wrap a component in React.lazy() more than once?';
8726 }
8727 } // This message intentionally doesn't mention ForwardRef or MemoComponent
8728 // because the fact that it's a separate type of work is an
8729 // implementation detail.
8730
8731
8732 {
8733 {
8734 throw Error("Element type is invalid. Received a promise that resolves to: " + Component + ". Lazy element type must resolve to a class or function." + hint);
8735 }
8736 }
8737 }
8738 }
8739
8740 return child;
8741}
8742
8743function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderExpirationTime) {
8744 if (_current !== null) {
8745 // An incomplete component only mounts if it suspended inside a non-
8746 // concurrent tree, in an inconsistent state. We want to treat it like
8747 // a new mount, even though an empty version of it already committed.
8748 // Disconnect the alternate pointers.
8749 _current.alternate = null;
8750 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8751
8752 workInProgress.effectTag |= Placement;
8753 } // Promote the fiber to a class and try rendering again.
8754
8755
8756 workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
8757 // Push context providers early to prevent context stack mismatches.
8758 // During mounting we don't know the child context yet as the instance doesn't exist.
8759 // We will invalidate the child context in finishClassComponent() right after rendering.
8760
8761 var hasContext;
8762
8763 if (isContextProvider(Component)) {
8764 hasContext = true;
8765 pushContextProvider(workInProgress);
8766 } else {
8767 hasContext = false;
8768 }
8769
8770 prepareToReadContext(workInProgress, renderExpirationTime);
8771 constructClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8772 mountClassInstance(workInProgress, Component, nextProps, renderExpirationTime);
8773 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
8774}
8775
8776function mountIndeterminateComponent(_current, workInProgress, Component, renderExpirationTime) {
8777 if (_current !== null) {
8778 // An indeterminate component only mounts if it suspended inside a non-
8779 // concurrent tree, in an inconsistent state. We want to treat it like
8780 // a new mount, even though an empty version of it already committed.
8781 // Disconnect the alternate pointers.
8782 _current.alternate = null;
8783 workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
8784
8785 workInProgress.effectTag |= Placement;
8786 }
8787
8788 var props = workInProgress.pendingProps;
8789 var context;
8790
8791 if (!disableLegacyContext) {
8792 var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
8793 context = getMaskedContext(workInProgress, unmaskedContext);
8794 }
8795
8796 prepareToReadContext(workInProgress, renderExpirationTime);
8797 var value;
8798
8799 {
8800 if (Component.prototype && typeof Component.prototype.render === 'function') {
8801 var componentName = getComponentName(Component) || 'Unknown';
8802
8803 if (!didWarnAboutBadClass[componentName]) {
8804 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);
8805 didWarnAboutBadClass[componentName] = true;
8806 }
8807 }
8808
8809 if (workInProgress.mode & StrictMode) {
8810 ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
8811 }
8812
8813 ReactCurrentOwner$2.current = workInProgress;
8814 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
8815 } // React DevTools reads this flag.
8816
8817
8818 workInProgress.effectTag |= PerformedWork;
8819
8820 if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
8821 {
8822 var _componentName = getComponentName(Component) || 'Unknown';
8823
8824 if (!didWarnAboutModulePatternComponent[_componentName]) {
8825 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);
8826 didWarnAboutModulePatternComponent[_componentName] = true;
8827 }
8828 } // Proceed under the assumption that this is a class instance
8829
8830
8831 workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
8832
8833 resetHooks(); // Push context providers early to prevent context stack mismatches.
8834 // During mounting we don't know the child context yet as the instance doesn't exist.
8835 // We will invalidate the child context in finishClassComponent() right after rendering.
8836
8837 var hasContext = false;
8838
8839 if (isContextProvider(Component)) {
8840 hasContext = true;
8841 pushContextProvider(workInProgress);
8842 } else {
8843 hasContext = false;
8844 }
8845
8846 workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
8847 var getDerivedStateFromProps = Component.getDerivedStateFromProps;
8848
8849 if (typeof getDerivedStateFromProps === 'function') {
8850 applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
8851 }
8852
8853 adoptClassInstance(workInProgress, value);
8854 mountClassInstance(workInProgress, Component, props, renderExpirationTime);
8855 return finishClassComponent(null, workInProgress, Component, true, hasContext, renderExpirationTime);
8856 } else {
8857 // Proceed under the assumption that this is a function component
8858 workInProgress.tag = FunctionComponent;
8859
8860 {
8861 if (disableLegacyContext && Component.contextTypes) {
8862 warningWithoutStack$1(false, '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with React.useContext() instead.', getComponentName(Component) || 'Unknown');
8863 }
8864
8865 if (debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8866 // Only double-render components with Hooks
8867 if (workInProgress.memoizedState !== null) {
8868 value = renderWithHooks(null, workInProgress, Component, props, context, renderExpirationTime);
8869 }
8870 }
8871 }
8872
8873 reconcileChildren(null, workInProgress, value, renderExpirationTime);
8874
8875 {
8876 validateFunctionComponentInDev(workInProgress, Component);
8877 }
8878
8879 return workInProgress.child;
8880 }
8881}
8882
8883function validateFunctionComponentInDev(workInProgress, Component) {
8884 if (Component) {
8885 !!Component.childContextTypes ? warningWithoutStack$1(false, '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component') : void 0;
8886 }
8887
8888 if (workInProgress.ref !== null) {
8889 var info = '';
8890 var ownerName = getCurrentFiberOwnerNameInDevOrNull();
8891
8892 if (ownerName) {
8893 info += '\n\nCheck the render method of `' + ownerName + '`.';
8894 }
8895
8896 var warningKey = ownerName || workInProgress._debugID || '';
8897 var debugSource = workInProgress._debugSource;
8898
8899 if (debugSource) {
8900 warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
8901 }
8902
8903 if (!didWarnAboutFunctionRefs[warningKey]) {
8904 didWarnAboutFunctionRefs[warningKey] = true;
8905 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);
8906 }
8907 }
8908
8909 if (warnAboutDefaultPropsOnFunctionComponents && Component.defaultProps !== undefined) {
8910 var componentName = getComponentName(Component) || 'Unknown';
8911
8912 if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {
8913 warningWithoutStack$1(false, '%s: Support for defaultProps will be removed from function components ' + 'in a future major release. Use JavaScript default parameters instead.', componentName);
8914 didWarnAboutDefaultPropsOnFunctionComponent[componentName] = true;
8915 }
8916 }
8917
8918 if (typeof Component.getDerivedStateFromProps === 'function') {
8919 var _componentName2 = getComponentName(Component) || 'Unknown';
8920
8921 if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
8922 warningWithoutStack$1(false, '%s: Function components do not support getDerivedStateFromProps.', _componentName2);
8923 didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
8924 }
8925 }
8926
8927 if (typeof Component.contextType === 'object' && Component.contextType !== null) {
8928 var _componentName3 = getComponentName(Component) || 'Unknown';
8929
8930 if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
8931 warningWithoutStack$1(false, '%s: Function components do not support contextType.', _componentName3);
8932 didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
8933 }
8934 }
8935}
8936
8937var SUSPENDED_MARKER = {
8938 dehydrated: null,
8939 retryTime: NoWork
8940};
8941
8942function shouldRemainOnFallback(suspenseContext, current$$1, workInProgress) {
8943 // If the context is telling us that we should show a fallback, and we're not
8944 // already showing content, then we should show the fallback instead.
8945 return hasSuspenseContext(suspenseContext, ForceSuspenseFallback) && (current$$1 === null || current$$1.memoizedState !== null);
8946}
8947
8948function updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime) {
8949 var mode = workInProgress.mode;
8950 var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
8951
8952 {
8953 if (shouldSuspend(workInProgress)) {
8954 workInProgress.effectTag |= DidCapture;
8955 }
8956 }
8957
8958 var suspenseContext = suspenseStackCursor.current;
8959 var nextDidTimeout = false;
8960 var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
8961
8962 if (didSuspend || shouldRemainOnFallback(suspenseContext, current$$1, workInProgress)) {
8963 // Something in this boundary's subtree already suspended. Switch to
8964 // rendering the fallback children.
8965 nextDidTimeout = true;
8966 workInProgress.effectTag &= ~DidCapture;
8967 } else {
8968 // Attempting the main content
8969 if (current$$1 === null || current$$1.memoizedState !== null) {
8970 // This is a new mount or this boundary is already showing a fallback state.
8971 // Mark this subtree context as having at least one invisible parent that could
8972 // handle the fallback state.
8973 // Boundaries without fallbacks or should be avoided are not considered since
8974 // they cannot handle preferred fallback states.
8975 if (nextProps.fallback !== undefined && nextProps.unstable_avoidThisFallback !== true) {
8976 suspenseContext = addSubtreeSuspenseContext(suspenseContext, InvisibleParentSuspenseContext);
8977 }
8978 }
8979 }
8980
8981 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
8982 pushSuspenseContext(workInProgress, suspenseContext);
8983
8984 {
8985 if ('maxDuration' in nextProps) {
8986 if (!didWarnAboutMaxDuration) {
8987 didWarnAboutMaxDuration = true;
8988 warning$1(false, 'maxDuration has been removed from React. ' + 'Remove the maxDuration prop.');
8989 }
8990 }
8991 } // This next part is a bit confusing. If the children timeout, we switch to
8992 // showing the fallback children in place of the "primary" children.
8993 // However, we don't want to delete the primary children because then their
8994 // state will be lost (both the React state and the host state, e.g.
8995 // uncontrolled form inputs). Instead we keep them mounted and hide them.
8996 // Both the fallback children AND the primary children are rendered at the
8997 // same time. Once the primary children are un-suspended, we can delete
8998 // the fallback children — don't need to preserve their state.
8999 //
9000 // The two sets of children are siblings in the host environment, but
9001 // semantically, for purposes of reconciliation, they are two separate sets.
9002 // So we store them using two fragment fibers.
9003 //
9004 // However, we want to avoid allocating extra fibers for every placeholder.
9005 // They're only necessary when the children time out, because that's the
9006 // only time when both sets are mounted.
9007 //
9008 // So, the extra fragment fibers are only used if the children time out.
9009 // Otherwise, we render the primary children directly. This requires some
9010 // custom reconciliation logic to preserve the state of the primary
9011 // children. It's essentially a very basic form of re-parenting.
9012
9013
9014 if (current$$1 === null) {
9015 // If we're currently hydrating, try to hydrate this boundary.
9016 // But only if this has a fallback.
9017 if (nextProps.fallback !== undefined) {
9018 tryToClaimNextHydratableInstance(workInProgress); // This could've been a dehydrated suspense component.
9019
9020 if (enableSuspenseServerRenderer) {
9021 var suspenseState = workInProgress.memoizedState;
9022
9023 if (suspenseState !== null) {
9024 var dehydrated = suspenseState.dehydrated;
9025
9026 if (dehydrated !== null) {
9027 return mountDehydratedSuspenseComponent(workInProgress, dehydrated, renderExpirationTime);
9028 }
9029 }
9030 }
9031 } // This is the initial mount. This branch is pretty simple because there's
9032 // no previous state that needs to be preserved.
9033
9034
9035 if (nextDidTimeout) {
9036 // Mount separate fragments for primary and fallback children.
9037 var nextFallbackChildren = nextProps.fallback;
9038 var primaryChildFragment = createFiberFromFragment(null, mode, NoWork, null);
9039 primaryChildFragment.return = workInProgress;
9040
9041 if ((workInProgress.mode & BlockingMode) === NoMode) {
9042 // Outside of blocking mode, we commit the effects from the
9043 // partially completed, timed-out tree, too.
9044 var progressedState = workInProgress.memoizedState;
9045 var progressedPrimaryChild = progressedState !== null ? workInProgress.child.child : workInProgress.child;
9046 primaryChildFragment.child = progressedPrimaryChild;
9047 var progressedChild = progressedPrimaryChild;
9048
9049 while (progressedChild !== null) {
9050 progressedChild.return = primaryChildFragment;
9051 progressedChild = progressedChild.sibling;
9052 }
9053 }
9054
9055 var fallbackChildFragment = createFiberFromFragment(nextFallbackChildren, mode, renderExpirationTime, null);
9056 fallbackChildFragment.return = workInProgress;
9057 primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
9058 // fallback children.
9059
9060 workInProgress.memoizedState = SUSPENDED_MARKER;
9061 workInProgress.child = primaryChildFragment;
9062 return fallbackChildFragment;
9063 } else {
9064 // Mount the primary children without an intermediate fragment fiber.
9065 var nextPrimaryChildren = nextProps.children;
9066 workInProgress.memoizedState = null;
9067 return workInProgress.child = mountChildFibers(workInProgress, null, nextPrimaryChildren, renderExpirationTime);
9068 }
9069 } else {
9070 // This is an update. This branch is more complicated because we need to
9071 // ensure the state of the primary children is preserved.
9072 var prevState = current$$1.memoizedState;
9073
9074 if (prevState !== null) {
9075 if (enableSuspenseServerRenderer) {
9076 var _dehydrated = prevState.dehydrated;
9077
9078 if (_dehydrated !== null) {
9079 if (!didSuspend) {
9080 return updateDehydratedSuspenseComponent(current$$1, workInProgress, _dehydrated, prevState, renderExpirationTime);
9081 } else if (workInProgress.memoizedState !== null) {
9082 // Something suspended and we should still be in dehydrated mode.
9083 // Leave the existing child in place.
9084 workInProgress.child = current$$1.child; // The dehydrated completion pass expects this flag to be there
9085 // but the normal suspense pass doesn't.
9086
9087 workInProgress.effectTag |= DidCapture;
9088 return null;
9089 } else {
9090 // Suspended but we should no longer be in dehydrated mode.
9091 // Therefore we now have to render the fallback. Wrap the children
9092 // in a fragment fiber to keep them separate from the fallback
9093 // children.
9094 var _nextFallbackChildren = nextProps.fallback;
9095
9096 var _primaryChildFragment = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
9097 // going to render this fragment.
9098 null, mode, NoWork, null);
9099
9100 _primaryChildFragment.return = workInProgress; // This is always null since we never want the previous child
9101 // that we're not going to hydrate.
9102
9103 _primaryChildFragment.child = null;
9104
9105 if ((workInProgress.mode & BlockingMode) === NoMode) {
9106 // Outside of blocking mode, we commit the effects from the
9107 // partially completed, timed-out tree, too.
9108 var _progressedChild = _primaryChildFragment.child = workInProgress.child;
9109
9110 while (_progressedChild !== null) {
9111 _progressedChild.return = _primaryChildFragment;
9112 _progressedChild = _progressedChild.sibling;
9113 }
9114 } else {
9115 // We will have dropped the effect list which contains the deletion.
9116 // We need to reconcile to delete the current child.
9117 reconcileChildFibers(workInProgress, current$$1.child, null, renderExpirationTime);
9118 } // Because primaryChildFragment is a new fiber that we're inserting as the
9119 // parent of a new tree, we need to set its treeBaseDuration.
9120
9121
9122 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9123 // treeBaseDuration is the sum of all the child tree base durations.
9124 var treeBaseDuration = 0;
9125 var hiddenChild = _primaryChildFragment.child;
9126
9127 while (hiddenChild !== null) {
9128 treeBaseDuration += hiddenChild.treeBaseDuration;
9129 hiddenChild = hiddenChild.sibling;
9130 }
9131
9132 _primaryChildFragment.treeBaseDuration = treeBaseDuration;
9133 } // Create a fragment from the fallback children, too.
9134
9135
9136 var _fallbackChildFragment = createFiberFromFragment(_nextFallbackChildren, mode, renderExpirationTime, null);
9137
9138 _fallbackChildFragment.return = workInProgress;
9139 _primaryChildFragment.sibling = _fallbackChildFragment;
9140 _fallbackChildFragment.effectTag |= Placement;
9141 _primaryChildFragment.childExpirationTime = NoWork;
9142 workInProgress.memoizedState = SUSPENDED_MARKER;
9143 workInProgress.child = _primaryChildFragment; // Skip the primary children, and continue working on the
9144 // fallback children.
9145
9146 return _fallbackChildFragment;
9147 }
9148 }
9149 } // The current tree already timed out. That means each child set is
9150 // wrapped in a fragment fiber.
9151
9152
9153 var currentPrimaryChildFragment = current$$1.child;
9154 var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
9155
9156 if (nextDidTimeout) {
9157 // Still timed out. Reuse the current primary children by cloning
9158 // its fragment. We're going to skip over these entirely.
9159 var _nextFallbackChildren2 = nextProps.fallback;
9160
9161 var _primaryChildFragment2 = createWorkInProgress(currentPrimaryChildFragment, currentPrimaryChildFragment.pendingProps, NoWork);
9162
9163 _primaryChildFragment2.return = workInProgress;
9164
9165 if ((workInProgress.mode & BlockingMode) === NoMode) {
9166 // Outside of blocking mode, we commit the effects from the
9167 // partially completed, timed-out tree, too.
9168 var _progressedState = workInProgress.memoizedState;
9169
9170 var _progressedPrimaryChild = _progressedState !== null ? workInProgress.child.child : workInProgress.child;
9171
9172 if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
9173 _primaryChildFragment2.child = _progressedPrimaryChild;
9174 var _progressedChild2 = _progressedPrimaryChild;
9175
9176 while (_progressedChild2 !== null) {
9177 _progressedChild2.return = _primaryChildFragment2;
9178 _progressedChild2 = _progressedChild2.sibling;
9179 }
9180 }
9181 } // Because primaryChildFragment is a new fiber that we're inserting as the
9182 // parent of a new tree, we need to set its treeBaseDuration.
9183
9184
9185 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9186 // treeBaseDuration is the sum of all the child tree base durations.
9187 var _treeBaseDuration = 0;
9188 var _hiddenChild = _primaryChildFragment2.child;
9189
9190 while (_hiddenChild !== null) {
9191 _treeBaseDuration += _hiddenChild.treeBaseDuration;
9192 _hiddenChild = _hiddenChild.sibling;
9193 }
9194
9195 _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
9196 } // Clone the fallback child fragment, too. These we'll continue
9197 // working on.
9198
9199
9200 var _fallbackChildFragment2 = createWorkInProgress(currentFallbackChildFragment, _nextFallbackChildren2, currentFallbackChildFragment.expirationTime);
9201
9202 _fallbackChildFragment2.return = workInProgress;
9203 _primaryChildFragment2.sibling = _fallbackChildFragment2;
9204 _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
9205 // fallback children.
9206
9207 workInProgress.memoizedState = SUSPENDED_MARKER;
9208 workInProgress.child = _primaryChildFragment2;
9209 return _fallbackChildFragment2;
9210 } else {
9211 // No longer suspended. Switch back to showing the primary children,
9212 // and remove the intermediate fragment fiber.
9213 var _nextPrimaryChildren = nextProps.children;
9214 var currentPrimaryChild = currentPrimaryChildFragment.child;
9215 var primaryChild = reconcileChildFibers(workInProgress, currentPrimaryChild, _nextPrimaryChildren, renderExpirationTime); // If this render doesn't suspend, we need to delete the fallback
9216 // children. Wait until the complete phase, after we've confirmed the
9217 // fallback is no longer needed.
9218 // TODO: Would it be better to store the fallback fragment on
9219 // the stateNode?
9220 // Continue rendering the children, like we normally do.
9221
9222 workInProgress.memoizedState = null;
9223 return workInProgress.child = primaryChild;
9224 }
9225 } else {
9226 // The current tree has not already timed out. That means the primary
9227 // children are not wrapped in a fragment fiber.
9228 var _currentPrimaryChild = current$$1.child;
9229
9230 if (nextDidTimeout) {
9231 // Timed out. Wrap the children in a fragment fiber to keep them
9232 // separate from the fallback children.
9233 var _nextFallbackChildren3 = nextProps.fallback;
9234
9235 var _primaryChildFragment3 = createFiberFromFragment( // It shouldn't matter what the pending props are because we aren't
9236 // going to render this fragment.
9237 null, mode, NoWork, null);
9238
9239 _primaryChildFragment3.return = workInProgress;
9240 _primaryChildFragment3.child = _currentPrimaryChild;
9241
9242 if (_currentPrimaryChild !== null) {
9243 _currentPrimaryChild.return = _primaryChildFragment3;
9244 } // Even though we're creating a new fiber, there are no new children,
9245 // because we're reusing an already mounted tree. So we don't need to
9246 // schedule a placement.
9247 // primaryChildFragment.effectTag |= Placement;
9248
9249
9250 if ((workInProgress.mode & BlockingMode) === NoMode) {
9251 // Outside of blocking mode, we commit the effects from the
9252 // partially completed, timed-out tree, too.
9253 var _progressedState2 = workInProgress.memoizedState;
9254
9255 var _progressedPrimaryChild2 = _progressedState2 !== null ? workInProgress.child.child : workInProgress.child;
9256
9257 _primaryChildFragment3.child = _progressedPrimaryChild2;
9258 var _progressedChild3 = _progressedPrimaryChild2;
9259
9260 while (_progressedChild3 !== null) {
9261 _progressedChild3.return = _primaryChildFragment3;
9262 _progressedChild3 = _progressedChild3.sibling;
9263 }
9264 } // Because primaryChildFragment is a new fiber that we're inserting as the
9265 // parent of a new tree, we need to set its treeBaseDuration.
9266
9267
9268 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
9269 // treeBaseDuration is the sum of all the child tree base durations.
9270 var _treeBaseDuration2 = 0;
9271 var _hiddenChild2 = _primaryChildFragment3.child;
9272
9273 while (_hiddenChild2 !== null) {
9274 _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
9275 _hiddenChild2 = _hiddenChild2.sibling;
9276 }
9277
9278 _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
9279 } // Create a fragment from the fallback children, too.
9280
9281
9282 var _fallbackChildFragment3 = createFiberFromFragment(_nextFallbackChildren3, mode, renderExpirationTime, null);
9283
9284 _fallbackChildFragment3.return = workInProgress;
9285 _primaryChildFragment3.sibling = _fallbackChildFragment3;
9286 _fallbackChildFragment3.effectTag |= Placement;
9287 _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
9288 // fallback children.
9289
9290 workInProgress.memoizedState = SUSPENDED_MARKER;
9291 workInProgress.child = _primaryChildFragment3;
9292 return _fallbackChildFragment3;
9293 } else {
9294 // Still haven't timed out. Continue rendering the children, like we
9295 // normally do.
9296 workInProgress.memoizedState = null;
9297 var _nextPrimaryChildren2 = nextProps.children;
9298 return workInProgress.child = reconcileChildFibers(workInProgress, _currentPrimaryChild, _nextPrimaryChildren2, renderExpirationTime);
9299 }
9300 }
9301 }
9302}
9303
9304function retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime) {
9305 // We're now not suspended nor dehydrated.
9306 workInProgress.memoizedState = null; // Retry with the full children.
9307
9308 var nextProps = workInProgress.pendingProps;
9309 var nextChildren = nextProps.children; // This will ensure that the children get Placement effects and
9310 // that the old child gets a Deletion effect.
9311 // We could also call forceUnmountCurrentAndReconcile.
9312
9313 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9314 return workInProgress.child;
9315}
9316
9317function mountDehydratedSuspenseComponent(workInProgress, suspenseInstance, renderExpirationTime) {
9318 // During the first pass, we'll bail out and not drill into the children.
9319 // Instead, we'll leave the content in place and try to hydrate it later.
9320 if ((workInProgress.mode & BlockingMode) === NoMode) {
9321 {
9322 warning$1(false, 'Cannot hydrate Suspense in legacy mode. Switch from ' + 'ReactDOM.hydrate(element, container) to ' + 'ReactDOM.createBlockingRoot(container, { hydrate: true })' + '.render(element) or remove the Suspense components from ' + 'the server rendered components.');
9323 }
9324
9325 workInProgress.expirationTime = Sync;
9326 } else if (isSuspenseInstanceFallback(suspenseInstance)) {
9327 // This is a client-only boundary. Since we won't get any content from the server
9328 // for this, we need to schedule that at a higher priority based on when it would
9329 // have timed out. In theory we could render it in this pass but it would have the
9330 // wrong priority associated with it and will prevent hydration of parent path.
9331 // Instead, we'll leave work left on it to render it in a separate commit.
9332 // TODO This time should be the time at which the server rendered response that is
9333 // a parent to this boundary was displayed. However, since we currently don't have
9334 // a protocol to transfer that time, we'll just estimate it by using the current
9335 // time. This will mean that Suspense timeouts are slightly shifted to later than
9336 // they should be.
9337 var serverDisplayTime = requestCurrentTimeForUpdate(); // Schedule a normal pri update to render this content.
9338
9339 var newExpirationTime = computeAsyncExpiration(serverDisplayTime);
9340
9341 if (enableSchedulerTracing) {
9342 markSpawnedWork(newExpirationTime);
9343 }
9344
9345 workInProgress.expirationTime = newExpirationTime;
9346 } else {
9347 // We'll continue hydrating the rest at offscreen priority since we'll already
9348 // be showing the right content coming from the server, it is no rush.
9349 workInProgress.expirationTime = Never;
9350
9351 if (enableSchedulerTracing) {
9352 markSpawnedWork(Never);
9353 }
9354 }
9355
9356 return null;
9357}
9358
9359function updateDehydratedSuspenseComponent(current$$1, workInProgress, suspenseInstance, suspenseState, renderExpirationTime) {
9360 // We should never be hydrating at this point because it is the first pass,
9361 // but after we've already committed once.
9362 warnIfHydrating();
9363
9364 if ((workInProgress.mode & BlockingMode) === NoMode) {
9365 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9366 }
9367
9368 if (isSuspenseInstanceFallback(suspenseInstance)) {
9369 // This boundary is in a permanent fallback state. In this case, we'll never
9370 // get an update and we'll never be able to hydrate the final content. Let's just try the
9371 // client side render instead.
9372 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9373 } // We use childExpirationTime to indicate that a child might depend on context, so if
9374 // any context has changed, we need to treat is as if the input might have changed.
9375
9376
9377 var hasContextChanged$$1 = current$$1.childExpirationTime >= renderExpirationTime;
9378
9379 if (didReceiveUpdate || hasContextChanged$$1) {
9380 // This boundary has changed since the first render. This means that we are now unable to
9381 // hydrate it. We might still be able to hydrate it using an earlier expiration time, if
9382 // we are rendering at lower expiration than sync.
9383 if (renderExpirationTime < Sync) {
9384 if (suspenseState.retryTime <= renderExpirationTime) {
9385 // This render is even higher pri than we've seen before, let's try again
9386 // at even higher pri.
9387 var attemptHydrationAtExpirationTime = renderExpirationTime + 1;
9388 suspenseState.retryTime = attemptHydrationAtExpirationTime;
9389 scheduleWork(current$$1, attemptHydrationAtExpirationTime); // TODO: Early abort this render.
9390 } else {// We have already tried to ping at a higher priority than we're rendering with
9391 // so if we got here, we must have failed to hydrate at those levels. We must
9392 // now give up. Instead, we're going to delete the whole subtree and instead inject
9393 // a new real Suspense boundary to take its place, which may render content
9394 // or fallback. This might suspend for a while and if it does we might still have
9395 // an opportunity to hydrate before this pass commits.
9396 }
9397 } // If we have scheduled higher pri work above, this will probably just abort the render
9398 // since we now have higher priority work, but in case it doesn't, we need to prepare to
9399 // render something, if we time out. Even if that requires us to delete everything and
9400 // skip hydration.
9401 // Delay having to do this as long as the suspense timeout allows us.
9402
9403
9404 renderDidSuspendDelayIfPossible();
9405 return retrySuspenseComponentWithoutHydrating(current$$1, workInProgress, renderExpirationTime);
9406 } else if (isSuspenseInstancePending(suspenseInstance)) {
9407 // This component is still pending more data from the server, so we can't hydrate its
9408 // content. We treat it as if this component suspended itself. It might seem as if
9409 // we could just try to render it client-side instead. However, this will perform a
9410 // lot of unnecessary work and is unlikely to complete since it often will suspend
9411 // on missing data anyway. Additionally, the server might be able to render more
9412 // than we can on the client yet. In that case we'd end up with more fallback states
9413 // on the client than if we just leave it alone. If the server times out or errors
9414 // these should update this boundary to the permanent Fallback state instead.
9415 // Mark it as having captured (i.e. suspended).
9416 workInProgress.effectTag |= DidCapture; // Leave the child in place. I.e. the dehydrated fragment.
9417
9418 workInProgress.child = current$$1.child; // Register a callback to retry this boundary once the server has sent the result.
9419
9420 registerSuspenseInstanceRetry(suspenseInstance, retryDehydratedSuspenseBoundary.bind(null, current$$1));
9421 return null;
9422 } else {
9423 // This is the first attempt.
9424 reenterHydrationStateFromDehydratedSuspenseInstance(workInProgress, suspenseInstance);
9425 var nextProps = workInProgress.pendingProps;
9426 var nextChildren = nextProps.children;
9427 var child = mountChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
9428 var node = child;
9429
9430 while (node) {
9431 // Mark each child as hydrating. This is a fast path to know whether this
9432 // tree is part of a hydrating tree. This is used to determine if a child
9433 // node has fully mounted yet, and for scheduling event replaying.
9434 // Conceptually this is similar to Placement in that a new subtree is
9435 // inserted into the React tree here. It just happens to not need DOM
9436 // mutations because it already exists.
9437 node.effectTag |= Hydrating;
9438 node = node.sibling;
9439 }
9440
9441 workInProgress.child = child;
9442 return workInProgress.child;
9443 }
9444}
9445
9446function scheduleWorkOnFiber(fiber, renderExpirationTime) {
9447 if (fiber.expirationTime < renderExpirationTime) {
9448 fiber.expirationTime = renderExpirationTime;
9449 }
9450
9451 var alternate = fiber.alternate;
9452
9453 if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
9454 alternate.expirationTime = renderExpirationTime;
9455 }
9456
9457 scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
9458}
9459
9460function propagateSuspenseContextChange(workInProgress, firstChild, renderExpirationTime) {
9461 // Mark any Suspense boundaries with fallbacks as having work to do.
9462 // If they were previously forced into fallbacks, they may now be able
9463 // to unblock.
9464 var node = firstChild;
9465
9466 while (node !== null) {
9467 if (node.tag === SuspenseComponent) {
9468 var state = node.memoizedState;
9469
9470 if (state !== null) {
9471 scheduleWorkOnFiber(node, renderExpirationTime);
9472 }
9473 } else if (node.tag === SuspenseListComponent) {
9474 // If the tail is hidden there might not be an Suspense boundaries
9475 // to schedule work on. In this case we have to schedule it on the
9476 // list itself.
9477 // We don't have to traverse to the children of the list since
9478 // the list will propagate the change when it rerenders.
9479 scheduleWorkOnFiber(node, renderExpirationTime);
9480 } else if (node.child !== null) {
9481 node.child.return = node;
9482 node = node.child;
9483 continue;
9484 }
9485
9486 if (node === workInProgress) {
9487 return;
9488 }
9489
9490 while (node.sibling === null) {
9491 if (node.return === null || node.return === workInProgress) {
9492 return;
9493 }
9494
9495 node = node.return;
9496 }
9497
9498 node.sibling.return = node.return;
9499 node = node.sibling;
9500 }
9501}
9502
9503function findLastContentRow(firstChild) {
9504 // This is going to find the last row among these children that is already
9505 // showing content on the screen, as opposed to being in fallback state or
9506 // new. If a row has multiple Suspense boundaries, any of them being in the
9507 // fallback state, counts as the whole row being in a fallback state.
9508 // Note that the "rows" will be workInProgress, but any nested children
9509 // will still be current since we haven't rendered them yet. The mounted
9510 // order may not be the same as the new order. We use the new order.
9511 var row = firstChild;
9512 var lastContentRow = null;
9513
9514 while (row !== null) {
9515 var currentRow = row.alternate; // New rows can't be content rows.
9516
9517 if (currentRow !== null && findFirstSuspended(currentRow) === null) {
9518 lastContentRow = row;
9519 }
9520
9521 row = row.sibling;
9522 }
9523
9524 return lastContentRow;
9525}
9526
9527function validateRevealOrder(revealOrder) {
9528 {
9529 if (revealOrder !== undefined && revealOrder !== 'forwards' && revealOrder !== 'backwards' && revealOrder !== 'together' && !didWarnAboutRevealOrder[revealOrder]) {
9530 didWarnAboutRevealOrder[revealOrder] = true;
9531
9532 if (typeof revealOrder === 'string') {
9533 switch (revealOrder.toLowerCase()) {
9534 case 'together':
9535 case 'forwards':
9536 case 'backwards':
9537 {
9538 warning$1(false, '"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'Use lowercase "%s" instead.', revealOrder, revealOrder.toLowerCase());
9539 break;
9540 }
9541
9542 case 'forward':
9543 case 'backward':
9544 {
9545 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());
9546 break;
9547 }
9548
9549 default:
9550 warning$1(false, '"%s" is not a supported revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
9551 break;
9552 }
9553 } else {
9554 warning$1(false, '%s is not a supported value for revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
9555 }
9556 }
9557 }
9558}
9559
9560function validateTailOptions(tailMode, revealOrder) {
9561 {
9562 if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
9563 if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
9564 didWarnAboutTailOptions[tailMode] = true;
9565 warning$1(false, '"%s" is not a supported value for tail on <SuspenseList />. ' + 'Did you mean "collapsed" or "hidden"?', tailMode);
9566 } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
9567 didWarnAboutTailOptions[tailMode] = true;
9568 warning$1(false, '<SuspenseList tail="%s" /> is only valid if revealOrder is ' + '"forwards" or "backwards". ' + 'Did you mean to specify revealOrder="forwards"?', tailMode);
9569 }
9570 }
9571 }
9572}
9573
9574function validateSuspenseListNestedChild(childSlot, index) {
9575 {
9576 var isArray = Array.isArray(childSlot);
9577 var isIterable = !isArray && typeof getIteratorFn(childSlot) === 'function';
9578
9579 if (isArray || isIterable) {
9580 var type = isArray ? 'array' : 'iterable';
9581 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);
9582 return false;
9583 }
9584 }
9585
9586 return true;
9587}
9588
9589function validateSuspenseListChildren(children, revealOrder) {
9590 {
9591 if ((revealOrder === 'forwards' || revealOrder === 'backwards') && children !== undefined && children !== null && children !== false) {
9592 if (Array.isArray(children)) {
9593 for (var i = 0; i < children.length; i++) {
9594 if (!validateSuspenseListNestedChild(children[i], i)) {
9595 return;
9596 }
9597 }
9598 } else {
9599 var iteratorFn = getIteratorFn(children);
9600
9601 if (typeof iteratorFn === 'function') {
9602 var childrenIterator = iteratorFn.call(children);
9603
9604 if (childrenIterator) {
9605 var step = childrenIterator.next();
9606 var _i = 0;
9607
9608 for (; !step.done; step = childrenIterator.next()) {
9609 if (!validateSuspenseListNestedChild(step.value, _i)) {
9610 return;
9611 }
9612
9613 _i++;
9614 }
9615 }
9616 } else {
9617 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);
9618 }
9619 }
9620 }
9621 }
9622}
9623
9624function initSuspenseListRenderState(workInProgress, isBackwards, tail, lastContentRow, tailMode, lastEffectBeforeRendering) {
9625 var renderState = workInProgress.memoizedState;
9626
9627 if (renderState === null) {
9628 workInProgress.memoizedState = {
9629 isBackwards: isBackwards,
9630 rendering: null,
9631 last: lastContentRow,
9632 tail: tail,
9633 tailExpiration: 0,
9634 tailMode: tailMode,
9635 lastEffect: lastEffectBeforeRendering
9636 };
9637 } else {
9638 // We can reuse the existing object from previous renders.
9639 renderState.isBackwards = isBackwards;
9640 renderState.rendering = null;
9641 renderState.last = lastContentRow;
9642 renderState.tail = tail;
9643 renderState.tailExpiration = 0;
9644 renderState.tailMode = tailMode;
9645 renderState.lastEffect = lastEffectBeforeRendering;
9646 }
9647} // This can end up rendering this component multiple passes.
9648// The first pass splits the children fibers into two sets. A head and tail.
9649// We first render the head. If anything is in fallback state, we do another
9650// pass through beginWork to rerender all children (including the tail) with
9651// the force suspend context. If the first render didn't have anything in
9652// in fallback state. Then we render each row in the tail one-by-one.
9653// That happens in the completeWork phase without going back to beginWork.
9654
9655
9656function updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime) {
9657 var nextProps = workInProgress.pendingProps;
9658 var revealOrder = nextProps.revealOrder;
9659 var tailMode = nextProps.tail;
9660 var newChildren = nextProps.children;
9661 validateRevealOrder(revealOrder);
9662 validateTailOptions(tailMode, revealOrder);
9663 validateSuspenseListChildren(newChildren, revealOrder);
9664 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9665 var suspenseContext = suspenseStackCursor.current;
9666 var shouldForceFallback = hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
9667
9668 if (shouldForceFallback) {
9669 suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
9670 workInProgress.effectTag |= DidCapture;
9671 } else {
9672 var didSuspendBefore = current$$1 !== null && (current$$1.effectTag & DidCapture) !== NoEffect;
9673
9674 if (didSuspendBefore) {
9675 // If we previously forced a fallback, we need to schedule work
9676 // on any nested boundaries to let them know to try to render
9677 // again. This is the same as context updating.
9678 propagateSuspenseContextChange(workInProgress, workInProgress.child, renderExpirationTime);
9679 }
9680
9681 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
9682 }
9683
9684 pushSuspenseContext(workInProgress, suspenseContext);
9685
9686 if ((workInProgress.mode & BlockingMode) === NoMode) {
9687 // Outside of blocking mode, SuspenseList doesn't work so we just
9688 // use make it a noop by treating it as the default revealOrder.
9689 workInProgress.memoizedState = null;
9690 } else {
9691 switch (revealOrder) {
9692 case 'forwards':
9693 {
9694 var lastContentRow = findLastContentRow(workInProgress.child);
9695 var tail;
9696
9697 if (lastContentRow === null) {
9698 // The whole list is part of the tail.
9699 // TODO: We could fast path by just rendering the tail now.
9700 tail = workInProgress.child;
9701 workInProgress.child = null;
9702 } else {
9703 // Disconnect the tail rows after the content row.
9704 // We're going to render them separately later.
9705 tail = lastContentRow.sibling;
9706 lastContentRow.sibling = null;
9707 }
9708
9709 initSuspenseListRenderState(workInProgress, false, // isBackwards
9710 tail, lastContentRow, tailMode, workInProgress.lastEffect);
9711 break;
9712 }
9713
9714 case 'backwards':
9715 {
9716 // We're going to find the first row that has existing content.
9717 // At the same time we're going to reverse the list of everything
9718 // we pass in the meantime. That's going to be our tail in reverse
9719 // order.
9720 var _tail = null;
9721 var row = workInProgress.child;
9722 workInProgress.child = null;
9723
9724 while (row !== null) {
9725 var currentRow = row.alternate; // New rows can't be content rows.
9726
9727 if (currentRow !== null && findFirstSuspended(currentRow) === null) {
9728 // This is the beginning of the main content.
9729 workInProgress.child = row;
9730 break;
9731 }
9732
9733 var nextRow = row.sibling;
9734 row.sibling = _tail;
9735 _tail = row;
9736 row = nextRow;
9737 } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
9738
9739
9740 initSuspenseListRenderState(workInProgress, true, // isBackwards
9741 _tail, null, // last
9742 tailMode, workInProgress.lastEffect);
9743 break;
9744 }
9745
9746 case 'together':
9747 {
9748 initSuspenseListRenderState(workInProgress, false, // isBackwards
9749 null, // tail
9750 null, // last
9751 undefined, workInProgress.lastEffect);
9752 break;
9753 }
9754
9755 default:
9756 {
9757 // The default reveal order is the same as not having
9758 // a boundary.
9759 workInProgress.memoizedState = null;
9760 }
9761 }
9762 }
9763
9764 return workInProgress.child;
9765}
9766
9767function updatePortalComponent(current$$1, workInProgress, renderExpirationTime) {
9768 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
9769 var nextChildren = workInProgress.pendingProps;
9770
9771 if (current$$1 === null) {
9772 // Portals are special because we don't append the children during mount
9773 // but at commit. Therefore we need to track insertions which the normal
9774 // flow doesn't do during mount. This doesn't happen at the root because
9775 // the root always starts with a "current" with a null child.
9776 // TODO: Consider unifying this with how the root works.
9777 workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderExpirationTime);
9778 } else {
9779 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9780 }
9781
9782 return workInProgress.child;
9783}
9784
9785function updateContextProvider(current$$1, workInProgress, renderExpirationTime) {
9786 var providerType = workInProgress.type;
9787 var context = providerType._context;
9788 var newProps = workInProgress.pendingProps;
9789 var oldProps = workInProgress.memoizedProps;
9790 var newValue = newProps.value;
9791
9792 {
9793 var providerPropTypes = workInProgress.type.propTypes;
9794
9795 if (providerPropTypes) {
9796 checkPropTypes_1(providerPropTypes, newProps, 'prop', 'Context.Provider', getCurrentFiberStackInDev);
9797 }
9798 }
9799
9800 pushProvider(workInProgress, newValue);
9801
9802 if (oldProps !== null) {
9803 var oldValue = oldProps.value;
9804 var changedBits = calculateChangedBits(context, newValue, oldValue);
9805
9806 if (changedBits === 0) {
9807 // No change. Bailout early if children are the same.
9808 if (oldProps.children === newProps.children && !hasContextChanged()) {
9809 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
9810 }
9811 } else {
9812 // The context value changed. Search for matching consumers and schedule
9813 // them to update.
9814 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
9815 }
9816 }
9817
9818 var newChildren = newProps.children;
9819 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9820 return workInProgress.child;
9821}
9822
9823var hasWarnedAboutUsingContextAsConsumer = false;
9824
9825function updateContextConsumer(current$$1, workInProgress, renderExpirationTime) {
9826 var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
9827 // DEV mode, we create a separate object for Context.Consumer that acts
9828 // like a proxy to Context. This proxy object adds unnecessary code in PROD
9829 // so we use the old behaviour (Context.Consumer references Context) to
9830 // reduce size and overhead. The separate object references context via
9831 // a property called "_context", which also gives us the ability to check
9832 // in DEV mode if this property exists or not and warn if it does not.
9833
9834 {
9835 if (context._context === undefined) {
9836 // This may be because it's a Context (rather than a Consumer).
9837 // Or it may be because it's older React where they're the same thing.
9838 // We only want to warn if we're sure it's a new React.
9839 if (context !== context.Consumer) {
9840 if (!hasWarnedAboutUsingContextAsConsumer) {
9841 hasWarnedAboutUsingContextAsConsumer = true;
9842 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?');
9843 }
9844 }
9845 } else {
9846 context = context._context;
9847 }
9848 }
9849
9850 var newProps = workInProgress.pendingProps;
9851 var render = newProps.children;
9852
9853 {
9854 !(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;
9855 }
9856
9857 prepareToReadContext(workInProgress, renderExpirationTime);
9858 var newValue = readContext(context, newProps.unstable_observedBits);
9859 var newChildren;
9860
9861 {
9862 ReactCurrentOwner$2.current = workInProgress;
9863 setCurrentPhase('render');
9864 newChildren = render(newValue);
9865 setCurrentPhase(null);
9866 } // React DevTools reads this flag.
9867
9868
9869 workInProgress.effectTag |= PerformedWork;
9870 reconcileChildren(current$$1, workInProgress, newChildren, renderExpirationTime);
9871 return workInProgress.child;
9872}
9873
9874function updateFundamentalComponent$1(current$$1, workInProgress, renderExpirationTime) {
9875 var fundamentalImpl = workInProgress.type.impl;
9876
9877 if (fundamentalImpl.reconcileChildren === false) {
9878 return null;
9879 }
9880
9881 var nextProps = workInProgress.pendingProps;
9882 var nextChildren = nextProps.children;
9883 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9884 return workInProgress.child;
9885}
9886
9887function updateScopeComponent(current$$1, workInProgress, renderExpirationTime) {
9888 var nextProps = workInProgress.pendingProps;
9889 var nextChildren = nextProps.children;
9890 reconcileChildren(current$$1, workInProgress, nextChildren, renderExpirationTime);
9891 return workInProgress.child;
9892}
9893
9894function markWorkInProgressReceivedUpdate() {
9895 didReceiveUpdate = true;
9896}
9897
9898function bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime) {
9899 cancelWorkTimer(workInProgress);
9900
9901 if (current$$1 !== null) {
9902 // Reuse previous dependencies
9903 workInProgress.dependencies = current$$1.dependencies;
9904 }
9905
9906 if (enableProfilerTimer) {
9907 // Don't update "base" render times for bailouts.
9908 stopProfilerTimerIfRunning(workInProgress);
9909 }
9910
9911 var updateExpirationTime = workInProgress.expirationTime;
9912
9913 if (updateExpirationTime !== NoWork) {
9914 markUnprocessedUpdateTime(updateExpirationTime);
9915 } // Check if the children have any pending work.
9916
9917
9918 var childExpirationTime = workInProgress.childExpirationTime;
9919
9920 if (childExpirationTime < renderExpirationTime) {
9921 // The children don't have any work either. We can skip them.
9922 // TODO: Once we add back resuming, we should check if the children are
9923 // a work-in-progress set. If so, we need to transfer their effects.
9924 return null;
9925 } else {
9926 // This fiber doesn't have work, but its subtree does. Clone the child
9927 // fibers and continue.
9928 cloneChildFibers(current$$1, workInProgress);
9929 return workInProgress.child;
9930 }
9931}
9932
9933function remountFiber(current$$1, oldWorkInProgress, newWorkInProgress) {
9934 {
9935 var returnFiber = oldWorkInProgress.return;
9936
9937 if (returnFiber === null) {
9938 throw new Error('Cannot swap the root fiber.');
9939 } // Disconnect from the old current.
9940 // It will get deleted.
9941
9942
9943 current$$1.alternate = null;
9944 oldWorkInProgress.alternate = null; // Connect to the new tree.
9945
9946 newWorkInProgress.index = oldWorkInProgress.index;
9947 newWorkInProgress.sibling = oldWorkInProgress.sibling;
9948 newWorkInProgress.return = oldWorkInProgress.return;
9949 newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
9950
9951 if (oldWorkInProgress === returnFiber.child) {
9952 returnFiber.child = newWorkInProgress;
9953 } else {
9954 var prevSibling = returnFiber.child;
9955
9956 if (prevSibling === null) {
9957 throw new Error('Expected parent to have a child.');
9958 }
9959
9960 while (prevSibling.sibling !== oldWorkInProgress) {
9961 prevSibling = prevSibling.sibling;
9962
9963 if (prevSibling === null) {
9964 throw new Error('Expected to find the previous sibling.');
9965 }
9966 }
9967
9968 prevSibling.sibling = newWorkInProgress;
9969 } // Delete the old fiber and place the new one.
9970 // Since the old fiber is disconnected, we have to schedule it manually.
9971
9972
9973 var last = returnFiber.lastEffect;
9974
9975 if (last !== null) {
9976 last.nextEffect = current$$1;
9977 returnFiber.lastEffect = current$$1;
9978 } else {
9979 returnFiber.firstEffect = returnFiber.lastEffect = current$$1;
9980 }
9981
9982 current$$1.nextEffect = null;
9983 current$$1.effectTag = Deletion;
9984 newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
9985
9986 return newWorkInProgress;
9987 }
9988}
9989
9990function beginWork$1(current$$1, workInProgress, renderExpirationTime) {
9991 var updateExpirationTime = workInProgress.expirationTime;
9992
9993 {
9994 if (workInProgress._debugNeedsRemount && current$$1 !== null) {
9995 // This will restart the begin phase with a new fiber.
9996 return remountFiber(current$$1, workInProgress, createFiberFromTypeAndProps(workInProgress.type, workInProgress.key, workInProgress.pendingProps, workInProgress._debugOwner || null, workInProgress.mode, workInProgress.expirationTime));
9997 }
9998 }
9999
10000 if (current$$1 !== null) {
10001 var oldProps = current$$1.memoizedProps;
10002 var newProps = workInProgress.pendingProps;
10003
10004 if (oldProps !== newProps || hasContextChanged() || ( // Force a re-render if the implementation changed due to hot reload:
10005 workInProgress.type !== current$$1.type)) {
10006 // If props or context changed, mark the fiber as having performed work.
10007 // This may be unset if the props are determined to be equal later (memo).
10008 didReceiveUpdate = true;
10009 } else if (updateExpirationTime < renderExpirationTime) {
10010 didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
10011 // the begin phase. There's still some bookkeeping we that needs to be done
10012 // in this optimized path, mostly pushing stuff onto the stack.
10013
10014 switch (workInProgress.tag) {
10015 case HostRoot:
10016 pushHostRootContext(workInProgress);
10017 resetHydrationState();
10018 break;
10019
10020 case HostComponent:
10021 pushHostContext(workInProgress);
10022
10023 if (workInProgress.mode & ConcurrentMode && renderExpirationTime !== Never && shouldDeprioritizeSubtree(workInProgress.type, newProps)) {
10024 if (enableSchedulerTracing) {
10025 markSpawnedWork(Never);
10026 } // Schedule this fiber to re-render at offscreen priority. Then bailout.
10027
10028
10029 workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
10030 return null;
10031 }
10032
10033 break;
10034
10035 case ClassComponent:
10036 {
10037 var Component = workInProgress.type;
10038
10039 if (isContextProvider(Component)) {
10040 pushContextProvider(workInProgress);
10041 }
10042
10043 break;
10044 }
10045
10046 case HostPortal:
10047 pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
10048 break;
10049
10050 case ContextProvider:
10051 {
10052 var newValue = workInProgress.memoizedProps.value;
10053 pushProvider(workInProgress, newValue);
10054 break;
10055 }
10056
10057 case Profiler:
10058 if (enableProfilerTimer) {
10059 // Profiler should only call onRender when one of its descendants actually rendered.
10060 var hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
10061
10062 if (hasChildWork) {
10063 workInProgress.effectTag |= Update;
10064 }
10065 }
10066
10067 break;
10068
10069 case SuspenseComponent:
10070 {
10071 var state = workInProgress.memoizedState;
10072
10073 if (state !== null) {
10074 if (enableSuspenseServerRenderer) {
10075 if (state.dehydrated !== null) {
10076 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // We know that this component will suspend again because if it has
10077 // been unsuspended it has committed as a resolved Suspense component.
10078 // If it needs to be retried, it should have work scheduled on it.
10079
10080 workInProgress.effectTag |= DidCapture;
10081 break;
10082 }
10083 } // If this boundary is currently timed out, we need to decide
10084 // whether to retry the primary children, or to skip over it and
10085 // go straight to the fallback. Check the priority of the primary
10086 // child fragment.
10087
10088
10089 var primaryChildFragment = workInProgress.child;
10090 var primaryChildExpirationTime = primaryChildFragment.childExpirationTime;
10091
10092 if (primaryChildExpirationTime !== NoWork && primaryChildExpirationTime >= renderExpirationTime) {
10093 // The primary children have pending work. Use the normal path
10094 // to attempt to render the primary children again.
10095 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
10096 } else {
10097 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // The primary children do not have pending work with sufficient
10098 // priority. Bailout.
10099
10100 var child = bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
10101
10102 if (child !== null) {
10103 // The fallback children have pending work. Skip over the
10104 // primary children and work on the fallback.
10105 return child.sibling;
10106 } else {
10107 return null;
10108 }
10109 }
10110 } else {
10111 pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current));
10112 }
10113
10114 break;
10115 }
10116
10117 case SuspenseListComponent:
10118 {
10119 var didSuspendBefore = (current$$1.effectTag & DidCapture) !== NoEffect;
10120
10121 var _hasChildWork = workInProgress.childExpirationTime >= renderExpirationTime;
10122
10123 if (didSuspendBefore) {
10124 if (_hasChildWork) {
10125 // If something was in fallback state last time, and we have all the
10126 // same children then we're still in progressive loading state.
10127 // Something might get unblocked by state updates or retries in the
10128 // tree which will affect the tail. So we need to use the normal
10129 // path to compute the correct tail.
10130 return updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime);
10131 } // If none of the children had any work, that means that none of
10132 // them got retried so they'll still be blocked in the same way
10133 // as before. We can fast bail out.
10134
10135
10136 workInProgress.effectTag |= DidCapture;
10137 } // If nothing suspended before and we're rendering the same children,
10138 // then the tail doesn't matter. Anything new that suspends will work
10139 // in the "together" mode, so we can continue from the state we had.
10140
10141
10142 var renderState = workInProgress.memoizedState;
10143
10144 if (renderState !== null) {
10145 // Reset to the "together" mode in case we've started a different
10146 // update in the past but didn't complete it.
10147 renderState.rendering = null;
10148 renderState.tail = null;
10149 }
10150
10151 pushSuspenseContext(workInProgress, suspenseStackCursor.current);
10152
10153 if (_hasChildWork) {
10154 break;
10155 } else {
10156 // If none of the children had any work, that means that none of
10157 // them got retried so they'll still be blocked in the same way
10158 // as before. We can fast bail out.
10159 return null;
10160 }
10161 }
10162 }
10163
10164 return bailoutOnAlreadyFinishedWork(current$$1, workInProgress, renderExpirationTime);
10165 } else {
10166 // An update was scheduled on this fiber, but there are no new props
10167 // nor legacy context. Set this to false. If an update queue or context
10168 // consumer produces a changed value, it will set this to true. Otherwise,
10169 // the component will assume the children have not changed and bail out.
10170 didReceiveUpdate = false;
10171 }
10172 } else {
10173 didReceiveUpdate = false;
10174 } // Before entering the begin phase, clear the expiration time.
10175
10176
10177 workInProgress.expirationTime = NoWork;
10178
10179 switch (workInProgress.tag) {
10180 case IndeterminateComponent:
10181 {
10182 return mountIndeterminateComponent(current$$1, workInProgress, workInProgress.type, renderExpirationTime);
10183 }
10184
10185 case LazyComponent:
10186 {
10187 var elementType = workInProgress.elementType;
10188 return mountLazyComponent(current$$1, workInProgress, elementType, updateExpirationTime, renderExpirationTime);
10189 }
10190
10191 case FunctionComponent:
10192 {
10193 var _Component = workInProgress.type;
10194 var unresolvedProps = workInProgress.pendingProps;
10195 var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
10196 return updateFunctionComponent(current$$1, workInProgress, _Component, resolvedProps, renderExpirationTime);
10197 }
10198
10199 case ClassComponent:
10200 {
10201 var _Component2 = workInProgress.type;
10202 var _unresolvedProps = workInProgress.pendingProps;
10203
10204 var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
10205
10206 return updateClassComponent(current$$1, workInProgress, _Component2, _resolvedProps, renderExpirationTime);
10207 }
10208
10209 case HostRoot:
10210 return updateHostRoot(current$$1, workInProgress, renderExpirationTime);
10211
10212 case HostComponent:
10213 return updateHostComponent(current$$1, workInProgress, renderExpirationTime);
10214
10215 case HostText:
10216 return updateHostText(current$$1, workInProgress);
10217
10218 case SuspenseComponent:
10219 return updateSuspenseComponent(current$$1, workInProgress, renderExpirationTime);
10220
10221 case HostPortal:
10222 return updatePortalComponent(current$$1, workInProgress, renderExpirationTime);
10223
10224 case ForwardRef:
10225 {
10226 var type = workInProgress.type;
10227 var _unresolvedProps2 = workInProgress.pendingProps;
10228
10229 var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
10230
10231 return updateForwardRef(current$$1, workInProgress, type, _resolvedProps2, renderExpirationTime);
10232 }
10233
10234 case Fragment:
10235 return updateFragment(current$$1, workInProgress, renderExpirationTime);
10236
10237 case Mode:
10238 return updateMode(current$$1, workInProgress, renderExpirationTime);
10239
10240 case Profiler:
10241 return updateProfiler(current$$1, workInProgress, renderExpirationTime);
10242
10243 case ContextProvider:
10244 return updateContextProvider(current$$1, workInProgress, renderExpirationTime);
10245
10246 case ContextConsumer:
10247 return updateContextConsumer(current$$1, workInProgress, renderExpirationTime);
10248
10249 case MemoComponent:
10250 {
10251 var _type2 = workInProgress.type;
10252 var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
10253
10254 var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
10255
10256 {
10257 if (workInProgress.type !== workInProgress.elementType) {
10258 var outerPropTypes = _type2.propTypes;
10259
10260 if (outerPropTypes) {
10261 checkPropTypes_1(outerPropTypes, _resolvedProps3, // Resolved for outer only
10262 'prop', getComponentName(_type2), getCurrentFiberStackInDev);
10263 }
10264 }
10265 }
10266
10267 _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
10268 return updateMemoComponent(current$$1, workInProgress, _type2, _resolvedProps3, updateExpirationTime, renderExpirationTime);
10269 }
10270
10271 case SimpleMemoComponent:
10272 {
10273 return updateSimpleMemoComponent(current$$1, workInProgress, workInProgress.type, workInProgress.pendingProps, updateExpirationTime, renderExpirationTime);
10274 }
10275
10276 case IncompleteClassComponent:
10277 {
10278 var _Component3 = workInProgress.type;
10279 var _unresolvedProps4 = workInProgress.pendingProps;
10280
10281 var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
10282
10283 return mountIncompleteClassComponent(current$$1, workInProgress, _Component3, _resolvedProps4, renderExpirationTime);
10284 }
10285
10286 case SuspenseListComponent:
10287 {
10288 return updateSuspenseListComponent(current$$1, workInProgress, renderExpirationTime);
10289 }
10290
10291 case FundamentalComponent:
10292 {
10293 if (enableFundamentalAPI) {
10294 return updateFundamentalComponent$1(current$$1, workInProgress, renderExpirationTime);
10295 }
10296
10297 break;
10298 }
10299
10300 case ScopeComponent:
10301 {
10302 if (enableScopeAPI) {
10303 return updateScopeComponent(current$$1, workInProgress, renderExpirationTime);
10304 }
10305
10306 break;
10307 }
10308 }
10309
10310 {
10311 {
10312 throw Error("Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue.");
10313 }
10314 }
10315}
10316
10317function createFundamentalStateInstance(currentFiber, props, impl, state) {
10318 return {
10319 currentFiber: currentFiber,
10320 impl: impl,
10321 instance: null,
10322 prevProps: null,
10323 props: props,
10324 state: state
10325 };
10326}
10327
10328function isFiberSuspenseAndTimedOut(fiber) {
10329 return fiber.tag === SuspenseComponent && fiber.memoizedState !== null;
10330}
10331
10332function getSuspenseFallbackChild(fiber) {
10333 return fiber.child.sibling.child;
10334}
10335
10336var emptyObject$1 = {};
10337
10338function collectScopedNodes(node, fn, scopedNodes) {
10339 if (enableScopeAPI) {
10340 if (node.tag === HostComponent) {
10341 var _type = node.type,
10342 memoizedProps = node.memoizedProps,
10343 stateNode = node.stateNode;
10344
10345 var _instance = getPublicInstance(stateNode);
10346
10347 if (_instance !== null && fn(_type, memoizedProps || emptyObject$1, _instance) === true) {
10348 scopedNodes.push(_instance);
10349 }
10350 }
10351
10352 var child = node.child;
10353
10354 if (isFiberSuspenseAndTimedOut(node)) {
10355 child = getSuspenseFallbackChild(node);
10356 }
10357
10358 if (child !== null) {
10359 collectScopedNodesFromChildren(child, fn, scopedNodes);
10360 }
10361 }
10362}
10363
10364function collectFirstScopedNode(node, fn) {
10365 if (enableScopeAPI) {
10366 if (node.tag === HostComponent) {
10367 var _type2 = node.type,
10368 memoizedProps = node.memoizedProps,
10369 stateNode = node.stateNode;
10370
10371 var _instance2 = getPublicInstance(stateNode);
10372
10373 if (_instance2 !== null && fn(_type2, memoizedProps, _instance2) === true) {
10374 return _instance2;
10375 }
10376 }
10377
10378 var child = node.child;
10379
10380 if (isFiberSuspenseAndTimedOut(node)) {
10381 child = getSuspenseFallbackChild(node);
10382 }
10383
10384 if (child !== null) {
10385 return collectFirstScopedNodeFromChildren(child, fn);
10386 }
10387 }
10388
10389 return null;
10390}
10391
10392function collectScopedNodesFromChildren(startingChild, fn, scopedNodes) {
10393 var child = startingChild;
10394
10395 while (child !== null) {
10396 collectScopedNodes(child, fn, scopedNodes);
10397 child = child.sibling;
10398 }
10399}
10400
10401function collectFirstScopedNodeFromChildren(startingChild, fn) {
10402 var child = startingChild;
10403
10404 while (child !== null) {
10405 var scopedNode = collectFirstScopedNode(child, fn);
10406
10407 if (scopedNode !== null) {
10408 return scopedNode;
10409 }
10410
10411 child = child.sibling;
10412 }
10413
10414 return null;
10415}
10416
10417function collectNearestScopeMethods(node, scope, childrenScopes) {
10418 if (isValidScopeNode(node, scope)) {
10419 childrenScopes.push(node.stateNode.methods);
10420 } else {
10421 var child = node.child;
10422
10423 if (isFiberSuspenseAndTimedOut(node)) {
10424 child = getSuspenseFallbackChild(node);
10425 }
10426
10427 if (child !== null) {
10428 collectNearestChildScopeMethods(child, scope, childrenScopes);
10429 }
10430 }
10431}
10432
10433function collectNearestChildScopeMethods(startingChild, scope, childrenScopes) {
10434 var child = startingChild;
10435
10436 while (child !== null) {
10437 collectNearestScopeMethods(child, scope, childrenScopes);
10438 child = child.sibling;
10439 }
10440}
10441
10442function isValidScopeNode(node, scope) {
10443 return node.tag === ScopeComponent && node.type === scope && node.stateNode !== null;
10444}
10445
10446function createScopeMethods(scope, instance) {
10447 return {
10448 getChildren: function () {
10449 var currentFiber = instance.fiber;
10450 var child = currentFiber.child;
10451 var childrenScopes = [];
10452
10453 if (child !== null) {
10454 collectNearestChildScopeMethods(child, scope, childrenScopes);
10455 }
10456
10457 return childrenScopes.length === 0 ? null : childrenScopes;
10458 },
10459 getChildrenFromRoot: function () {
10460 var currentFiber = instance.fiber;
10461 var node = currentFiber;
10462
10463 while (node !== null) {
10464 var parent = node.return;
10465
10466 if (parent === null) {
10467 break;
10468 }
10469
10470 node = parent;
10471
10472 if (node.tag === ScopeComponent && node.type === scope) {
10473 break;
10474 }
10475 }
10476
10477 var childrenScopes = [];
10478 collectNearestChildScopeMethods(node.child, scope, childrenScopes);
10479 return childrenScopes.length === 0 ? null : childrenScopes;
10480 },
10481 getParent: function () {
10482 var node = instance.fiber.return;
10483
10484 while (node !== null) {
10485 if (node.tag === ScopeComponent && node.type === scope) {
10486 return node.stateNode.methods;
10487 }
10488
10489 node = node.return;
10490 }
10491
10492 return null;
10493 },
10494 getProps: function () {
10495 var currentFiber = instance.fiber;
10496 return currentFiber.memoizedProps;
10497 },
10498 queryAllNodes: function (fn) {
10499 var currentFiber = instance.fiber;
10500 var child = currentFiber.child;
10501 var scopedNodes = [];
10502
10503 if (child !== null) {
10504 collectScopedNodesFromChildren(child, fn, scopedNodes);
10505 }
10506
10507 return scopedNodes.length === 0 ? null : scopedNodes;
10508 },
10509 queryFirstNode: function (fn) {
10510 var currentFiber = instance.fiber;
10511 var child = currentFiber.child;
10512
10513 if (child !== null) {
10514 return collectFirstScopedNodeFromChildren(child, fn);
10515 }
10516
10517 return null;
10518 },
10519 containsNode: function (node) {
10520 var fiber = getInstanceFromNode(node);
10521
10522 while (fiber !== null) {
10523 if (fiber.tag === ScopeComponent && fiber.type === scope && fiber.stateNode === instance) {
10524 return true;
10525 }
10526
10527 fiber = fiber.return;
10528 }
10529
10530 return false;
10531 }
10532 };
10533}
10534
10535function markUpdate(workInProgress) {
10536 // Tag the fiber with an update effect. This turns a Placement into
10537 // a PlacementAndUpdate.
10538 workInProgress.effectTag |= Update;
10539}
10540
10541function markRef$1(workInProgress) {
10542 workInProgress.effectTag |= Ref;
10543}
10544
10545var appendAllChildren;
10546var updateHostContainer;
10547var updateHostComponent$1;
10548var updateHostText$1;
10549
10550if (supportsMutation) {
10551 // Mutation mode
10552 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
10553 // We only have the top Fiber that was created but we need recurse down its
10554 // children to find all the terminal nodes.
10555 var node = workInProgress.child;
10556
10557 while (node !== null) {
10558 if (node.tag === HostComponent || node.tag === HostText) {
10559 appendInitialChild(parent, node.stateNode);
10560 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10561 appendInitialChild(parent, node.stateNode.instance);
10562 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10563 // down its children. Instead, we'll get insertions from each child in
10564 // the portal directly.
10565 } else if (node.child !== null) {
10566 node.child.return = node;
10567 node = node.child;
10568 continue;
10569 }
10570
10571 if (node === workInProgress) {
10572 return;
10573 }
10574
10575 while (node.sibling === null) {
10576 if (node.return === null || node.return === workInProgress) {
10577 return;
10578 }
10579
10580 node = node.return;
10581 }
10582
10583 node.sibling.return = node.return;
10584 node = node.sibling;
10585 }
10586 };
10587
10588 updateHostContainer = function (workInProgress) {// Noop
10589 };
10590
10591 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
10592 // If we have an alternate, that means this is an update and we need to
10593 // schedule a side-effect to do the updates.
10594 var oldProps = current.memoizedProps;
10595
10596 if (oldProps === newProps) {
10597 // In mutation mode, this is sufficient for a bailout because
10598 // we won't touch this node even if children changed.
10599 return;
10600 } // If we get updated because one of our children updated, we don't
10601 // have newProps so we'll have to reuse them.
10602 // TODO: Split the update API as separate for the props vs. children.
10603 // Even better would be if children weren't special cased at all tho.
10604
10605
10606 var instance = workInProgress.stateNode;
10607 var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
10608 // component is hitting the resume path. Figure out why. Possibly
10609 // related to `hidden`.
10610
10611 var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext); // TODO: Type this specific to this type of component.
10612
10613 workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
10614 // is a new ref we mark this as an update. All the work is done in commitWork.
10615
10616 if (updatePayload) {
10617 markUpdate(workInProgress);
10618 }
10619 };
10620
10621 updateHostText$1 = function (current, workInProgress, oldText, newText) {
10622 // If the text differs, mark it as an update. All the work in done in commitWork.
10623 if (oldText !== newText) {
10624 markUpdate(workInProgress);
10625 }
10626 };
10627} else if (supportsPersistence) {
10628 // Persistent host tree mode
10629 appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
10630 // We only have the top Fiber that was created but we need recurse down its
10631 // children to find all the terminal nodes.
10632 var node = workInProgress.child;
10633
10634 while (node !== null) {
10635 // eslint-disable-next-line no-labels
10636 branches: if (node.tag === HostComponent) {
10637 var instance = node.stateNode;
10638
10639 if (needsVisibilityToggle && isHidden) {
10640 // This child is inside a timed out tree. Hide it.
10641 var props = node.memoizedProps;
10642 var type = node.type;
10643 instance = cloneHiddenInstance(instance, type, props, node);
10644 }
10645
10646 appendInitialChild(parent, instance);
10647 } else if (node.tag === HostText) {
10648 var _instance = node.stateNode;
10649
10650 if (needsVisibilityToggle && isHidden) {
10651 // This child is inside a timed out tree. Hide it.
10652 var text = node.memoizedProps;
10653 _instance = cloneHiddenTextInstance(_instance, text, node);
10654 }
10655
10656 appendInitialChild(parent, _instance);
10657 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10658 var _instance2 = node.stateNode.instance;
10659
10660 if (needsVisibilityToggle && isHidden) {
10661 // This child is inside a timed out tree. Hide it.
10662 var _props = node.memoizedProps;
10663 var _type = node.type;
10664 _instance2 = cloneHiddenInstance(_instance2, _type, _props, node);
10665 }
10666
10667 appendInitialChild(parent, _instance2);
10668 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10669 // down its children. Instead, we'll get insertions from each child in
10670 // the portal directly.
10671 } else if (node.tag === SuspenseComponent) {
10672 if ((node.effectTag & Update) !== NoEffect) {
10673 // Need to toggle the visibility of the primary children.
10674 var newIsHidden = node.memoizedState !== null;
10675
10676 if (newIsHidden) {
10677 var primaryChildParent = node.child;
10678
10679 if (primaryChildParent !== null) {
10680 if (primaryChildParent.child !== null) {
10681 primaryChildParent.child.return = primaryChildParent;
10682 appendAllChildren(parent, primaryChildParent, true, newIsHidden);
10683 }
10684
10685 var fallbackChildParent = primaryChildParent.sibling;
10686
10687 if (fallbackChildParent !== null) {
10688 fallbackChildParent.return = node;
10689 node = fallbackChildParent;
10690 continue;
10691 }
10692 }
10693 }
10694 }
10695
10696 if (node.child !== null) {
10697 // Continue traversing like normal
10698 node.child.return = node;
10699 node = node.child;
10700 continue;
10701 }
10702 } else if (node.child !== null) {
10703 node.child.return = node;
10704 node = node.child;
10705 continue;
10706 } // $FlowFixMe This is correct but Flow is confused by the labeled break.
10707
10708
10709 node = node;
10710
10711 if (node === workInProgress) {
10712 return;
10713 }
10714
10715 while (node.sibling === null) {
10716 if (node.return === null || node.return === workInProgress) {
10717 return;
10718 }
10719
10720 node = node.return;
10721 }
10722
10723 node.sibling.return = node.return;
10724 node = node.sibling;
10725 }
10726 }; // An unfortunate fork of appendAllChildren because we have two different parent types.
10727
10728
10729 var appendAllChildrenToContainer = function (containerChildSet, workInProgress, needsVisibilityToggle, isHidden) {
10730 // We only have the top Fiber that was created but we need recurse down its
10731 // children to find all the terminal nodes.
10732 var node = workInProgress.child;
10733
10734 while (node !== null) {
10735 // eslint-disable-next-line no-labels
10736 branches: if (node.tag === HostComponent) {
10737 var instance = node.stateNode;
10738
10739 if (needsVisibilityToggle && isHidden) {
10740 // This child is inside a timed out tree. Hide it.
10741 var props = node.memoizedProps;
10742 var type = node.type;
10743 instance = cloneHiddenInstance(instance, type, props, node);
10744 }
10745
10746 appendChildToContainerChildSet(containerChildSet, instance);
10747 } else if (node.tag === HostText) {
10748 var _instance3 = node.stateNode;
10749
10750 if (needsVisibilityToggle && isHidden) {
10751 // This child is inside a timed out tree. Hide it.
10752 var text = node.memoizedProps;
10753 _instance3 = cloneHiddenTextInstance(_instance3, text, node);
10754 }
10755
10756 appendChildToContainerChildSet(containerChildSet, _instance3);
10757 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
10758 var _instance4 = node.stateNode.instance;
10759
10760 if (needsVisibilityToggle && isHidden) {
10761 // This child is inside a timed out tree. Hide it.
10762 var _props2 = node.memoizedProps;
10763 var _type2 = node.type;
10764 _instance4 = cloneHiddenInstance(_instance4, _type2, _props2, node);
10765 }
10766
10767 appendChildToContainerChildSet(containerChildSet, _instance4);
10768 } else if (node.tag === HostPortal) {// If we have a portal child, then we don't want to traverse
10769 // down its children. Instead, we'll get insertions from each child in
10770 // the portal directly.
10771 } else if (node.tag === SuspenseComponent) {
10772 if ((node.effectTag & Update) !== NoEffect) {
10773 // Need to toggle the visibility of the primary children.
10774 var newIsHidden = node.memoizedState !== null;
10775
10776 if (newIsHidden) {
10777 var primaryChildParent = node.child;
10778
10779 if (primaryChildParent !== null) {
10780 if (primaryChildParent.child !== null) {
10781 primaryChildParent.child.return = primaryChildParent;
10782 appendAllChildrenToContainer(containerChildSet, primaryChildParent, true, newIsHidden);
10783 }
10784
10785 var fallbackChildParent = primaryChildParent.sibling;
10786
10787 if (fallbackChildParent !== null) {
10788 fallbackChildParent.return = node;
10789 node = fallbackChildParent;
10790 continue;
10791 }
10792 }
10793 }
10794 }
10795
10796 if (node.child !== null) {
10797 // Continue traversing like normal
10798 node.child.return = node;
10799 node = node.child;
10800 continue;
10801 }
10802 } else if (node.child !== null) {
10803 node.child.return = node;
10804 node = node.child;
10805 continue;
10806 } // $FlowFixMe This is correct but Flow is confused by the labeled break.
10807
10808
10809 node = node;
10810
10811 if (node === workInProgress) {
10812 return;
10813 }
10814
10815 while (node.sibling === null) {
10816 if (node.return === null || node.return === workInProgress) {
10817 return;
10818 }
10819
10820 node = node.return;
10821 }
10822
10823 node.sibling.return = node.return;
10824 node = node.sibling;
10825 }
10826 };
10827
10828 updateHostContainer = function (workInProgress) {
10829 var portalOrRoot = workInProgress.stateNode;
10830 var childrenUnchanged = workInProgress.firstEffect === null;
10831
10832 if (childrenUnchanged) {// No changes, just reuse the existing instance.
10833 } else {
10834 var container = portalOrRoot.containerInfo;
10835 var newChildSet = createContainerChildSet(container); // If children might have changed, we have to add them all to the set.
10836
10837 appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
10838 portalOrRoot.pendingChildren = newChildSet; // Schedule an update on the container to swap out the container.
10839
10840 markUpdate(workInProgress);
10841 finalizeContainerChildren(container, newChildSet);
10842 }
10843 };
10844
10845 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
10846 var currentInstance = current.stateNode;
10847 var oldProps = current.memoizedProps; // If there are no effects associated with this node, then none of our children had any updates.
10848 // This guarantees that we can reuse all of them.
10849
10850 var childrenUnchanged = workInProgress.firstEffect === null;
10851
10852 if (childrenUnchanged && oldProps === newProps) {
10853 // No changes, just reuse the existing instance.
10854 // Note that this might release a previous clone.
10855 workInProgress.stateNode = currentInstance;
10856 return;
10857 }
10858
10859 var recyclableInstance = workInProgress.stateNode;
10860 var currentHostContext = getHostContext();
10861 var updatePayload = null;
10862
10863 if (oldProps !== newProps) {
10864 updatePayload = prepareUpdate(recyclableInstance, type, oldProps, newProps, rootContainerInstance, currentHostContext);
10865 }
10866
10867 if (childrenUnchanged && updatePayload === null) {
10868 // No changes, just reuse the existing instance.
10869 // Note that this might release a previous clone.
10870 workInProgress.stateNode = currentInstance;
10871 return;
10872 }
10873
10874 var newInstance = cloneInstance(currentInstance, updatePayload, type, oldProps, newProps, workInProgress, childrenUnchanged, recyclableInstance);
10875
10876 if (finalizeInitialChildren(newInstance, type, newProps, rootContainerInstance, currentHostContext)) {
10877 markUpdate(workInProgress);
10878 }
10879
10880 workInProgress.stateNode = newInstance;
10881
10882 if (childrenUnchanged) {
10883 // If there are no other effects in this tree, we need to flag this node as having one.
10884 // Even though we're not going to use it for anything.
10885 // Otherwise parents won't know that there are new children to propagate upwards.
10886 markUpdate(workInProgress);
10887 } else {
10888 // If children might have changed, we have to add them all to the set.
10889 appendAllChildren(newInstance, workInProgress, false, false);
10890 }
10891 };
10892
10893 updateHostText$1 = function (current, workInProgress, oldText, newText) {
10894 if (oldText !== newText) {
10895 // If the text content differs, we'll create a new text instance for it.
10896 var rootContainerInstance = getRootHostContainer();
10897 var currentHostContext = getHostContext();
10898 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.
10899 // This lets the parents know that at least one of their children has changed.
10900
10901 markUpdate(workInProgress);
10902 }
10903 };
10904} else {
10905 // No host operations
10906 updateHostContainer = function (workInProgress) {// Noop
10907 };
10908
10909 updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {// Noop
10910 };
10911
10912 updateHostText$1 = function (current, workInProgress, oldText, newText) {// Noop
10913 };
10914}
10915
10916function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
10917 switch (renderState.tailMode) {
10918 case 'hidden':
10919 {
10920 // Any insertions at the end of the tail list after this point
10921 // should be invisible. If there are already mounted boundaries
10922 // anything before them are not considered for collapsing.
10923 // Therefore we need to go through the whole tail to find if
10924 // there are any.
10925 var tailNode = renderState.tail;
10926 var lastTailNode = null;
10927
10928 while (tailNode !== null) {
10929 if (tailNode.alternate !== null) {
10930 lastTailNode = tailNode;
10931 }
10932
10933 tailNode = tailNode.sibling;
10934 } // Next we're simply going to delete all insertions after the
10935 // last rendered item.
10936
10937
10938 if (lastTailNode === null) {
10939 // All remaining items in the tail are insertions.
10940 renderState.tail = null;
10941 } else {
10942 // Detach the insertion after the last node that was already
10943 // inserted.
10944 lastTailNode.sibling = null;
10945 }
10946
10947 break;
10948 }
10949
10950 case 'collapsed':
10951 {
10952 // Any insertions at the end of the tail list after this point
10953 // should be invisible. If there are already mounted boundaries
10954 // anything before them are not considered for collapsing.
10955 // Therefore we need to go through the whole tail to find if
10956 // there are any.
10957 var _tailNode = renderState.tail;
10958 var _lastTailNode = null;
10959
10960 while (_tailNode !== null) {
10961 if (_tailNode.alternate !== null) {
10962 _lastTailNode = _tailNode;
10963 }
10964
10965 _tailNode = _tailNode.sibling;
10966 } // Next we're simply going to delete all insertions after the
10967 // last rendered item.
10968
10969
10970 if (_lastTailNode === null) {
10971 // All remaining items in the tail are insertions.
10972 if (!hasRenderedATailFallback && renderState.tail !== null) {
10973 // We suspended during the head. We want to show at least one
10974 // row at the tail. So we'll keep on and cut off the rest.
10975 renderState.tail.sibling = null;
10976 } else {
10977 renderState.tail = null;
10978 }
10979 } else {
10980 // Detach the insertion after the last node that was already
10981 // inserted.
10982 _lastTailNode.sibling = null;
10983 }
10984
10985 break;
10986 }
10987 }
10988}
10989
10990function completeWork(current, workInProgress, renderExpirationTime) {
10991 var newProps = workInProgress.pendingProps;
10992
10993 switch (workInProgress.tag) {
10994 case IndeterminateComponent:
10995 break;
10996
10997 case LazyComponent:
10998 break;
10999
11000 case SimpleMemoComponent:
11001 case FunctionComponent:
11002 break;
11003
11004 case ClassComponent:
11005 {
11006 var Component = workInProgress.type;
11007
11008 if (isContextProvider(Component)) {
11009 popContext(workInProgress);
11010 }
11011
11012 break;
11013 }
11014
11015 case HostRoot:
11016 {
11017 popHostContainer(workInProgress);
11018 popTopLevelContextObject(workInProgress);
11019 var fiberRoot = workInProgress.stateNode;
11020
11021 if (fiberRoot.pendingContext) {
11022 fiberRoot.context = fiberRoot.pendingContext;
11023 fiberRoot.pendingContext = null;
11024 }
11025
11026 if (current === null || current.child === null) {
11027 // If we hydrated, pop so that we can delete any remaining children
11028 // that weren't hydrated.
11029 var wasHydrated = popHydrationState(workInProgress);
11030
11031 if (wasHydrated) {
11032 // If we hydrated, then we'll need to schedule an update for
11033 // the commit side-effects on the root.
11034 markUpdate(workInProgress);
11035 }
11036 }
11037
11038 updateHostContainer(workInProgress);
11039 break;
11040 }
11041
11042 case HostComponent:
11043 {
11044 popHostContext(workInProgress);
11045 var rootContainerInstance = getRootHostContainer();
11046 var type = workInProgress.type;
11047
11048 if (current !== null && workInProgress.stateNode != null) {
11049 updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
11050
11051 if (enableFlareAPI) {
11052 var prevListeners = current.memoizedProps.listeners;
11053 var nextListeners = newProps.listeners;
11054
11055 if (prevListeners !== nextListeners) {
11056 markUpdate(workInProgress);
11057 }
11058 }
11059
11060 if (current.ref !== workInProgress.ref) {
11061 markRef$1(workInProgress);
11062 }
11063 } else {
11064 if (!newProps) {
11065 if (!(workInProgress.stateNode !== null)) {
11066 {
11067 throw Error("We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue.");
11068 }
11069 } // This can happen when we abort work.
11070
11071
11072 break;
11073 }
11074
11075 var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
11076 // "stack" as the parent. Then append children as we go in beginWork
11077 // or completeWork depending on we want to add then top->down or
11078 // bottom->up. Top->down is faster in IE11.
11079
11080 var _wasHydrated = popHydrationState(workInProgress);
11081
11082 if (_wasHydrated) {
11083 // TODO: Move this and createInstance step into the beginPhase
11084 // to consolidate.
11085 if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
11086 // If changes to the hydrated node needs to be applied at the
11087 // commit-phase we mark this as such.
11088 markUpdate(workInProgress);
11089 }
11090
11091 if (enableFlareAPI) {
11092 var listeners = newProps.listeners;
11093
11094 if (listeners != null) {
11095 updateEventListeners(listeners, workInProgress, rootContainerInstance);
11096 }
11097 }
11098 } else {
11099 var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
11100 appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
11101
11102 workInProgress.stateNode = instance;
11103
11104 if (enableFlareAPI) {
11105 var _listeners = newProps.listeners;
11106
11107 if (_listeners != null) {
11108 updateEventListeners(_listeners, workInProgress, rootContainerInstance);
11109 }
11110 } // Certain renderers require commit-time effects for initial mount.
11111 // (eg DOM renderer supports auto-focus for certain elements).
11112 // Make sure such renderers get scheduled for later work.
11113
11114
11115 if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance, currentHostContext)) {
11116 markUpdate(workInProgress);
11117 }
11118 }
11119
11120 if (workInProgress.ref !== null) {
11121 // If there is a ref on a host node we need to schedule a callback
11122 markRef$1(workInProgress);
11123 }
11124 }
11125
11126 break;
11127 }
11128
11129 case HostText:
11130 {
11131 var newText = newProps;
11132
11133 if (current && workInProgress.stateNode != null) {
11134 var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
11135 // to schedule a side-effect to do the updates.
11136
11137 updateHostText$1(current, workInProgress, oldText, newText);
11138 } else {
11139 if (typeof newText !== 'string') {
11140 if (!(workInProgress.stateNode !== null)) {
11141 {
11142 throw Error("We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue.");
11143 }
11144 } // This can happen when we abort work.
11145
11146 }
11147
11148 var _rootContainerInstance = getRootHostContainer();
11149
11150 var _currentHostContext = getHostContext();
11151
11152 var _wasHydrated2 = popHydrationState(workInProgress);
11153
11154 if (_wasHydrated2) {
11155 if (prepareToHydrateHostTextInstance(workInProgress)) {
11156 markUpdate(workInProgress);
11157 }
11158 } else {
11159 workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
11160 }
11161 }
11162
11163 break;
11164 }
11165
11166 case ForwardRef:
11167 break;
11168
11169 case SuspenseComponent:
11170 {
11171 popSuspenseContext(workInProgress);
11172 var nextState = workInProgress.memoizedState;
11173
11174 if (enableSuspenseServerRenderer) {
11175 if (nextState !== null && nextState.dehydrated !== null) {
11176 if (current === null) {
11177 var _wasHydrated3 = popHydrationState(workInProgress);
11178
11179 if (!_wasHydrated3) {
11180 {
11181 throw Error("A dehydrated suspense component was completed without a hydrated node. This is probably a bug in React.");
11182 }
11183 }
11184
11185 prepareToHydrateHostSuspenseInstance(workInProgress);
11186
11187 if (enableSchedulerTracing) {
11188 markSpawnedWork(Never);
11189 }
11190
11191 return null;
11192 } else {
11193 // We should never have been in a hydration state if we didn't have a current.
11194 // However, in some of those paths, we might have reentered a hydration state
11195 // and then we might be inside a hydration state. In that case, we'll need to
11196 // exit out of it.
11197 resetHydrationState();
11198
11199 if ((workInProgress.effectTag & DidCapture) === NoEffect) {
11200 // This boundary did not suspend so it's now hydrated and unsuspended.
11201 workInProgress.memoizedState = null;
11202 } // If nothing suspended, we need to schedule an effect to mark this boundary
11203 // as having hydrated so events know that they're free be invoked.
11204 // It's also a signal to replay events and the suspense callback.
11205 // If something suspended, schedule an effect to attach retry listeners.
11206 // So we might as well always mark this.
11207
11208
11209 workInProgress.effectTag |= Update;
11210 return null;
11211 }
11212 }
11213 }
11214
11215 if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
11216 // Something suspended. Re-render with the fallback children.
11217 workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
11218
11219 return workInProgress;
11220 }
11221
11222 var nextDidTimeout = nextState !== null;
11223 var prevDidTimeout = false;
11224
11225 if (current === null) {
11226 if (workInProgress.memoizedProps.fallback !== undefined) {
11227 popHydrationState(workInProgress);
11228 }
11229 } else {
11230 var prevState = current.memoizedState;
11231 prevDidTimeout = prevState !== null;
11232
11233 if (!nextDidTimeout && prevState !== null) {
11234 // We just switched from the fallback to the normal children.
11235 // Delete the fallback.
11236 // TODO: Would it be better to store the fallback fragment on
11237 // the stateNode during the begin phase?
11238 var currentFallbackChild = current.child.sibling;
11239
11240 if (currentFallbackChild !== null) {
11241 // Deletions go at the beginning of the return fiber's effect list
11242 var first = workInProgress.firstEffect;
11243
11244 if (first !== null) {
11245 workInProgress.firstEffect = currentFallbackChild;
11246 currentFallbackChild.nextEffect = first;
11247 } else {
11248 workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
11249 currentFallbackChild.nextEffect = null;
11250 }
11251
11252 currentFallbackChild.effectTag = Deletion;
11253 }
11254 }
11255 }
11256
11257 if (nextDidTimeout && !prevDidTimeout) {
11258 // If this subtreee is running in blocking mode we can suspend,
11259 // otherwise we won't suspend.
11260 // TODO: This will still suspend a synchronous tree if anything
11261 // in the concurrent tree already suspended during this render.
11262 // This is a known bug.
11263 if ((workInProgress.mode & BlockingMode) !== NoMode) {
11264 // TODO: Move this back to throwException because this is too late
11265 // if this is a large tree which is common for initial loads. We
11266 // don't know if we should restart a render or not until we get
11267 // this marker, and this is too late.
11268 // If this render already had a ping or lower pri updates,
11269 // and this is the first time we know we're going to suspend we
11270 // should be able to immediately restart from within throwException.
11271 var hasInvisibleChildContext = current === null && workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
11272
11273 if (hasInvisibleChildContext || hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext)) {
11274 // If this was in an invisible tree or a new render, then showing
11275 // this boundary is ok.
11276 renderDidSuspend();
11277 } else {
11278 // Otherwise, we're going to have to hide content so we should
11279 // suspend for longer if possible.
11280 renderDidSuspendDelayIfPossible();
11281 }
11282 }
11283 }
11284
11285 if (supportsPersistence) {
11286 // TODO: Only schedule updates if not prevDidTimeout.
11287 if (nextDidTimeout) {
11288 // If this boundary just timed out, schedule an effect to attach a
11289 // retry listener to the proimse. This flag is also used to hide the
11290 // primary children.
11291 workInProgress.effectTag |= Update;
11292 }
11293 }
11294
11295 if (supportsMutation) {
11296 // TODO: Only schedule updates if these values are non equal, i.e. it changed.
11297 if (nextDidTimeout || prevDidTimeout) {
11298 // If this boundary just timed out, schedule an effect to attach a
11299 // retry listener to the proimse. This flag is also used to hide the
11300 // primary children. In mutation mode, we also need the flag to
11301 // *unhide* children that were previously hidden, so check if the
11302 // is currently timed out, too.
11303 workInProgress.effectTag |= Update;
11304 }
11305 }
11306
11307 if (enableSuspenseCallback && workInProgress.updateQueue !== null && workInProgress.memoizedProps.suspenseCallback != null) {
11308 // Always notify the callback
11309 workInProgress.effectTag |= Update;
11310 }
11311
11312 break;
11313 }
11314
11315 case Fragment:
11316 break;
11317
11318 case Mode:
11319 break;
11320
11321 case Profiler:
11322 break;
11323
11324 case HostPortal:
11325 popHostContainer(workInProgress);
11326 updateHostContainer(workInProgress);
11327 break;
11328
11329 case ContextProvider:
11330 // Pop provider fiber
11331 popProvider(workInProgress);
11332 break;
11333
11334 case ContextConsumer:
11335 break;
11336
11337 case MemoComponent:
11338 break;
11339
11340 case IncompleteClassComponent:
11341 {
11342 // Same as class component case. I put it down here so that the tags are
11343 // sequential to ensure this switch is compiled to a jump table.
11344 var _Component = workInProgress.type;
11345
11346 if (isContextProvider(_Component)) {
11347 popContext(workInProgress);
11348 }
11349
11350 break;
11351 }
11352
11353 case SuspenseListComponent:
11354 {
11355 popSuspenseContext(workInProgress);
11356 var renderState = workInProgress.memoizedState;
11357
11358 if (renderState === null) {
11359 // We're running in the default, "independent" mode. We don't do anything
11360 // in this mode.
11361 break;
11362 }
11363
11364 var didSuspendAlready = (workInProgress.effectTag & DidCapture) !== NoEffect;
11365 var renderedTail = renderState.rendering;
11366
11367 if (renderedTail === null) {
11368 // We just rendered the head.
11369 if (!didSuspendAlready) {
11370 // This is the first pass. We need to figure out if anything is still
11371 // suspended in the rendered set.
11372 // If new content unsuspended, but there's still some content that
11373 // didn't. Then we need to do a second pass that forces everything
11374 // to keep showing their fallbacks.
11375 // We might be suspended if something in this render pass suspended, or
11376 // something in the previous committed pass suspended. Otherwise,
11377 // there's no chance so we can skip the expensive call to
11378 // findFirstSuspended.
11379 var cannotBeSuspended = renderHasNotSuspendedYet() && (current === null || (current.effectTag & DidCapture) === NoEffect);
11380
11381 if (!cannotBeSuspended) {
11382 var row = workInProgress.child;
11383
11384 while (row !== null) {
11385 var suspended = findFirstSuspended(row);
11386
11387 if (suspended !== null) {
11388 didSuspendAlready = true;
11389 workInProgress.effectTag |= DidCapture;
11390 cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
11391 // part of the second pass. In that case nothing will subscribe to
11392 // its thennables. Instead, we'll transfer its thennables to the
11393 // SuspenseList so that it can retry if they resolve.
11394 // There might be multiple of these in the list but since we're
11395 // going to wait for all of them anyway, it doesn't really matter
11396 // which ones gets to ping. In theory we could get clever and keep
11397 // track of how many dependencies remain but it gets tricky because
11398 // in the meantime, we can add/remove/change items and dependencies.
11399 // We might bail out of the loop before finding any but that
11400 // doesn't matter since that means that the other boundaries that
11401 // we did find already has their listeners attached.
11402
11403 var newThennables = suspended.updateQueue;
11404
11405 if (newThennables !== null) {
11406 workInProgress.updateQueue = newThennables;
11407 workInProgress.effectTag |= Update;
11408 } // Rerender the whole list, but this time, we'll force fallbacks
11409 // to stay in place.
11410 // Reset the effect list before doing the second pass since that's now invalid.
11411
11412
11413 if (renderState.lastEffect === null) {
11414 workInProgress.firstEffect = null;
11415 }
11416
11417 workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
11418
11419 resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
11420 // rerender the children.
11421
11422 pushSuspenseContext(workInProgress, setShallowSuspenseContext(suspenseStackCursor.current, ForceSuspenseFallback));
11423 return workInProgress.child;
11424 }
11425
11426 row = row.sibling;
11427 }
11428 }
11429 } else {
11430 cutOffTailIfNeeded(renderState, false);
11431 } // Next we're going to render the tail.
11432
11433 } else {
11434 // Append the rendered row to the child list.
11435 if (!didSuspendAlready) {
11436 var _suspended = findFirstSuspended(renderedTail);
11437
11438 if (_suspended !== null) {
11439 workInProgress.effectTag |= DidCapture;
11440 didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
11441 // get lost if this row ends up dropped during a second pass.
11442
11443 var _newThennables = _suspended.updateQueue;
11444
11445 if (_newThennables !== null) {
11446 workInProgress.updateQueue = _newThennables;
11447 workInProgress.effectTag |= Update;
11448 }
11449
11450 cutOffTailIfNeeded(renderState, true); // This might have been modified.
11451
11452 if (renderState.tail === null && renderState.tailMode === 'hidden' && !renderedTail.alternate) {
11453 // We need to delete the row we just rendered.
11454 // Reset the effect list to what it was before we rendered this
11455 // child. The nested children have already appended themselves.
11456 var lastEffect = workInProgress.lastEffect = renderState.lastEffect; // Remove any effects that were appended after this point.
11457
11458 if (lastEffect !== null) {
11459 lastEffect.nextEffect = null;
11460 } // We're done.
11461
11462
11463 return null;
11464 }
11465 } else if (now() > renderState.tailExpiration && renderExpirationTime > Never) {
11466 // We have now passed our CPU deadline and we'll just give up further
11467 // attempts to render the main content and only render fallbacks.
11468 // The assumption is that this is usually faster.
11469 workInProgress.effectTag |= DidCapture;
11470 didSuspendAlready = true;
11471 cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
11472 // to get it started back up to attempt the next item. If we can show
11473 // them, then they really have the same priority as this render.
11474 // So we'll pick it back up the very next render pass once we've had
11475 // an opportunity to yield for paint.
11476
11477 var nextPriority = renderExpirationTime - 1;
11478 workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
11479
11480 if (enableSchedulerTracing) {
11481 markSpawnedWork(nextPriority);
11482 }
11483 }
11484 }
11485
11486 if (renderState.isBackwards) {
11487 // The effect list of the backwards tail will have been added
11488 // to the end. This breaks the guarantee that life-cycles fire in
11489 // sibling order but that isn't a strong guarantee promised by React.
11490 // Especially since these might also just pop in during future commits.
11491 // Append to the beginning of the list.
11492 renderedTail.sibling = workInProgress.child;
11493 workInProgress.child = renderedTail;
11494 } else {
11495 var previousSibling = renderState.last;
11496
11497 if (previousSibling !== null) {
11498 previousSibling.sibling = renderedTail;
11499 } else {
11500 workInProgress.child = renderedTail;
11501 }
11502
11503 renderState.last = renderedTail;
11504 }
11505 }
11506
11507 if (renderState.tail !== null) {
11508 // We still have tail rows to render.
11509 if (renderState.tailExpiration === 0) {
11510 // Heuristic for how long we're willing to spend rendering rows
11511 // until we just give up and show what we have so far.
11512 var TAIL_EXPIRATION_TIMEOUT_MS = 500;
11513 renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS;
11514 } // Pop a row.
11515
11516
11517 var next = renderState.tail;
11518 renderState.rendering = next;
11519 renderState.tail = next.sibling;
11520 renderState.lastEffect = workInProgress.lastEffect;
11521 next.sibling = null; // Restore the context.
11522 // TODO: We can probably just avoid popping it instead and only
11523 // setting it the first time we go from not suspended to suspended.
11524
11525 var suspenseContext = suspenseStackCursor.current;
11526
11527 if (didSuspendAlready) {
11528 suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
11529 } else {
11530 suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
11531 }
11532
11533 pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
11534
11535 return next;
11536 }
11537
11538 break;
11539 }
11540
11541 case FundamentalComponent:
11542 {
11543 if (enableFundamentalAPI) {
11544 var fundamentalImpl = workInProgress.type.impl;
11545 var fundamentalInstance = workInProgress.stateNode;
11546
11547 if (fundamentalInstance === null) {
11548 var getInitialState = fundamentalImpl.getInitialState;
11549 var fundamentalState;
11550
11551 if (getInitialState !== undefined) {
11552 fundamentalState = getInitialState(newProps);
11553 }
11554
11555 fundamentalInstance = workInProgress.stateNode = createFundamentalStateInstance(workInProgress, newProps, fundamentalImpl, fundamentalState || {});
11556
11557 var _instance5 = getFundamentalComponentInstance(fundamentalInstance);
11558
11559 fundamentalInstance.instance = _instance5;
11560
11561 if (fundamentalImpl.reconcileChildren === false) {
11562 return null;
11563 }
11564
11565 appendAllChildren(_instance5, workInProgress, false, false);
11566 mountFundamentalComponent(fundamentalInstance);
11567 } else {
11568 // We fire update in commit phase
11569 var prevProps = fundamentalInstance.props;
11570 fundamentalInstance.prevProps = prevProps;
11571 fundamentalInstance.props = newProps;
11572 fundamentalInstance.currentFiber = workInProgress;
11573
11574 if (supportsPersistence) {
11575 var _instance6 = cloneFundamentalInstance(fundamentalInstance);
11576
11577 fundamentalInstance.instance = _instance6;
11578 appendAllChildren(_instance6, workInProgress, false, false);
11579 }
11580
11581 var shouldUpdate = shouldUpdateFundamentalComponent(fundamentalInstance);
11582
11583 if (shouldUpdate) {
11584 markUpdate(workInProgress);
11585 }
11586 }
11587 }
11588
11589 break;
11590 }
11591
11592 case ScopeComponent:
11593 {
11594 if (enableScopeAPI) {
11595 if (current === null) {
11596 var _type3 = workInProgress.type;
11597 var scopeInstance = {
11598 fiber: workInProgress,
11599 methods: null
11600 };
11601 workInProgress.stateNode = scopeInstance;
11602 scopeInstance.methods = createScopeMethods(_type3, scopeInstance);
11603
11604 if (enableFlareAPI) {
11605 var _listeners2 = newProps.listeners;
11606
11607 if (_listeners2 != null) {
11608 var _rootContainerInstance2 = getRootHostContainer();
11609
11610 updateEventListeners(_listeners2, workInProgress, _rootContainerInstance2);
11611 }
11612 }
11613
11614 if (workInProgress.ref !== null) {
11615 markRef$1(workInProgress);
11616 markUpdate(workInProgress);
11617 }
11618 } else {
11619 if (enableFlareAPI) {
11620 var _prevListeners = current.memoizedProps.listeners;
11621 var _nextListeners = newProps.listeners;
11622
11623 if (_prevListeners !== _nextListeners || workInProgress.ref !== null) {
11624 markUpdate(workInProgress);
11625 }
11626 } else {
11627 if (workInProgress.ref !== null) {
11628 markUpdate(workInProgress);
11629 }
11630 }
11631
11632 if (current.ref !== workInProgress.ref) {
11633 markRef$1(workInProgress);
11634 }
11635 }
11636 }
11637
11638 break;
11639 }
11640
11641 default:
11642 {
11643 {
11644 throw Error("Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue.");
11645 }
11646 }
11647
11648 }
11649
11650 return null;
11651}
11652
11653function unwindWork(workInProgress, renderExpirationTime) {
11654 switch (workInProgress.tag) {
11655 case ClassComponent:
11656 {
11657 var Component = workInProgress.type;
11658
11659 if (isContextProvider(Component)) {
11660 popContext(workInProgress);
11661 }
11662
11663 var effectTag = workInProgress.effectTag;
11664
11665 if (effectTag & ShouldCapture) {
11666 workInProgress.effectTag = effectTag & ~ShouldCapture | DidCapture;
11667 return workInProgress;
11668 }
11669
11670 return null;
11671 }
11672
11673 case HostRoot:
11674 {
11675 popHostContainer(workInProgress);
11676 popTopLevelContextObject(workInProgress);
11677 var _effectTag = workInProgress.effectTag;
11678
11679 if (!((_effectTag & DidCapture) === NoEffect)) {
11680 {
11681 throw Error("The root failed to unmount after an error. This is likely a bug in React. Please file an issue.");
11682 }
11683 }
11684
11685 workInProgress.effectTag = _effectTag & ~ShouldCapture | DidCapture;
11686 return workInProgress;
11687 }
11688
11689 case HostComponent:
11690 {
11691 // TODO: popHydrationState
11692 popHostContext(workInProgress);
11693 return null;
11694 }
11695
11696 case SuspenseComponent:
11697 {
11698 popSuspenseContext(workInProgress);
11699
11700 if (enableSuspenseServerRenderer) {
11701 var suspenseState = workInProgress.memoizedState;
11702
11703 if (suspenseState !== null && suspenseState.dehydrated !== null) {
11704 if (!(workInProgress.alternate !== null)) {
11705 {
11706 throw Error("Threw in newly mounted dehydrated component. This is likely a bug in React. Please file an issue.");
11707 }
11708 }
11709
11710 resetHydrationState();
11711 }
11712 }
11713
11714 var _effectTag2 = workInProgress.effectTag;
11715
11716 if (_effectTag2 & ShouldCapture) {
11717 workInProgress.effectTag = _effectTag2 & ~ShouldCapture | DidCapture; // Captured a suspense effect. Re-render the boundary.
11718
11719 return workInProgress;
11720 }
11721
11722 return null;
11723 }
11724
11725 case SuspenseListComponent:
11726 {
11727 popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
11728 // caught by a nested boundary. If not, it should bubble through.
11729
11730 return null;
11731 }
11732
11733 case HostPortal:
11734 popHostContainer(workInProgress);
11735 return null;
11736
11737 case ContextProvider:
11738 popProvider(workInProgress);
11739 return null;
11740
11741 default:
11742 return null;
11743 }
11744}
11745
11746function unwindInterruptedWork(interruptedWork) {
11747 switch (interruptedWork.tag) {
11748 case ClassComponent:
11749 {
11750 var childContextTypes = interruptedWork.type.childContextTypes;
11751
11752 if (childContextTypes !== null && childContextTypes !== undefined) {
11753 popContext(interruptedWork);
11754 }
11755
11756 break;
11757 }
11758
11759 case HostRoot:
11760 {
11761 popHostContainer(interruptedWork);
11762 popTopLevelContextObject(interruptedWork);
11763 break;
11764 }
11765
11766 case HostComponent:
11767 {
11768 popHostContext(interruptedWork);
11769 break;
11770 }
11771
11772 case HostPortal:
11773 popHostContainer(interruptedWork);
11774 break;
11775
11776 case SuspenseComponent:
11777 popSuspenseContext(interruptedWork);
11778 break;
11779
11780 case SuspenseListComponent:
11781 popSuspenseContext(interruptedWork);
11782 break;
11783
11784 case ContextProvider:
11785 popProvider(interruptedWork);
11786 break;
11787
11788 default:
11789 break;
11790 }
11791}
11792
11793function createCapturedValue(value, source) {
11794 // If the value is an error, call this function immediately after it is thrown
11795 // so the stack is accurate.
11796 return {
11797 value: value,
11798 source: source,
11799 stack: getStackByFiberInDevAndProd(source)
11800 };
11801}
11802
11803var invokeGuardedCallbackImpl = function (name, func, context, a, b, c, d, e, f) {
11804 var funcArgs = Array.prototype.slice.call(arguments, 3);
11805
11806 try {
11807 func.apply(context, funcArgs);
11808 } catch (error) {
11809 this.onError(error);
11810 }
11811};
11812
11813{
11814 // In DEV mode, we swap out invokeGuardedCallback for a special version
11815 // that plays more nicely with the browser's DevTools. The idea is to preserve
11816 // "Pause on exceptions" behavior. Because React wraps all user-provided
11817 // functions in invokeGuardedCallback, and the production version of
11818 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
11819 // like caught exceptions, and the DevTools won't pause unless the developer
11820 // takes the extra step of enabling pause on caught exceptions. This is
11821 // unintuitive, though, because even though React has caught the error, from
11822 // the developer's perspective, the error is uncaught.
11823 //
11824 // To preserve the expected "Pause on exceptions" behavior, we don't use a
11825 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
11826 // DOM node, and call the user-provided callback from inside an event handler
11827 // for that fake event. If the callback throws, the error is "captured" using
11828 // a global event handler. But because the error happens in a different
11829 // event loop context, it does not interrupt the normal program flow.
11830 // Effectively, this gives us try-catch behavior without actually using
11831 // try-catch. Neat!
11832 // Check that the browser supports the APIs we need to implement our special
11833 // DEV version of invokeGuardedCallback
11834 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
11835 var fakeNode = document.createElement('react');
11836
11837 var invokeGuardedCallbackDev = function (name, func, context, a, b, c, d, e, f) {
11838 // If document doesn't exist we know for sure we will crash in this method
11839 // when we call document.createEvent(). However this can cause confusing
11840 // errors: https://github.com/facebookincubator/create-react-app/issues/3482
11841 // So we preemptively throw with a better message instead.
11842 if (!(typeof document !== 'undefined')) {
11843 {
11844 throw 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.");
11845 }
11846 }
11847
11848 var evt = document.createEvent('Event'); // Keeps track of whether the user-provided callback threw an error. We
11849 // set this to true at the beginning, then set it to false right after
11850 // calling the function. If the function errors, `didError` will never be
11851 // set to false. This strategy works even if the browser is flaky and
11852 // fails to call our global error handler, because it doesn't rely on
11853 // the error event at all.
11854
11855 var didError = true; // Keeps track of the value of window.event so that we can reset it
11856 // during the callback to let user code access window.event in the
11857 // browsers that support it.
11858
11859 var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
11860 // dispatching: https://github.com/facebook/react/issues/13688
11861
11862 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event'); // Create an event handler for our fake event. We will synchronously
11863 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
11864 // call the user-provided callback.
11865
11866 var funcArgs = Array.prototype.slice.call(arguments, 3);
11867
11868 function callCallback() {
11869 // We immediately remove the callback from event listeners so that
11870 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
11871 // nested call would trigger the fake event handlers of any call higher
11872 // in the stack.
11873 fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
11874 // window.event assignment in both IE <= 10 as they throw an error
11875 // "Member not found" in strict mode, and in Firefox which does not
11876 // support window.event.
11877
11878 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
11879 window.event = windowEvent;
11880 }
11881
11882 func.apply(context, funcArgs);
11883 didError = false;
11884 } // Create a global error event handler. We use this to capture the value
11885 // that was thrown. It's possible that this error handler will fire more
11886 // than once; for example, if non-React code also calls `dispatchEvent`
11887 // and a handler for that event throws. We should be resilient to most of
11888 // those cases. Even if our error event handler fires more than once, the
11889 // last error event is always used. If the callback actually does error,
11890 // we know that the last error event is the correct one, because it's not
11891 // possible for anything else to have happened in between our callback
11892 // erroring and the code that follows the `dispatchEvent` call below. If
11893 // the callback doesn't error, but the error event was fired, we know to
11894 // ignore it because `didError` will be false, as described above.
11895
11896
11897 var error; // Use this to track whether the error event is ever called.
11898
11899 var didSetError = false;
11900 var isCrossOriginError = false;
11901
11902 function handleWindowError(event) {
11903 error = event.error;
11904 didSetError = true;
11905
11906 if (error === null && event.colno === 0 && event.lineno === 0) {
11907 isCrossOriginError = true;
11908 }
11909
11910 if (event.defaultPrevented) {
11911 // Some other error handler has prevented default.
11912 // Browsers silence the error report if this happens.
11913 // We'll remember this to later decide whether to log it or not.
11914 if (error != null && typeof error === 'object') {
11915 try {
11916 error._suppressLogging = true;
11917 } catch (inner) {// Ignore.
11918 }
11919 }
11920 }
11921 } // Create a fake event type.
11922
11923
11924 var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
11925
11926 window.addEventListener('error', handleWindowError);
11927 fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
11928 // errors, it will trigger our global error handler.
11929
11930 evt.initEvent(evtType, false, false);
11931 fakeNode.dispatchEvent(evt);
11932
11933 if (windowEventDescriptor) {
11934 Object.defineProperty(window, 'event', windowEventDescriptor);
11935 }
11936
11937 if (didError) {
11938 if (!didSetError) {
11939 // The callback errored, but the error event never fired.
11940 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.');
11941 } else if (isCrossOriginError) {
11942 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.');
11943 }
11944
11945 this.onError(error);
11946 } // Remove our event listeners
11947
11948
11949 window.removeEventListener('error', handleWindowError);
11950 };
11951
11952 invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
11953 }
11954}
11955
11956var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
11957
11958var hasError = false;
11959var caughtError = null; // Used by event system to capture/rethrow the first error.
11960
11961var reporter = {
11962 onError: function (error) {
11963 hasError = true;
11964 caughtError = error;
11965 }
11966};
11967/**
11968 * Call a function while guarding against errors that happens within it.
11969 * Returns an error if it throws, otherwise null.
11970 *
11971 * In production, this is implemented using a try-catch. The reason we don't
11972 * use a try-catch directly is so that we can swap out a different
11973 * implementation in DEV mode.
11974 *
11975 * @param {String} name of the guard to use for logging or debugging
11976 * @param {Function} func The function to invoke
11977 * @param {*} context The context to use when calling the function
11978 * @param {...*} args Arguments for function
11979 */
11980
11981function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
11982 hasError = false;
11983 caughtError = null;
11984 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
11985}
11986/**
11987 * Same as invokeGuardedCallback, but instead of returning an error, it stores
11988 * it in a global so it can be rethrown by `rethrowCaughtError` later.
11989 * TODO: See if caughtError and rethrowError can be unified.
11990 *
11991 * @param {String} name of the guard to use for logging or debugging
11992 * @param {Function} func The function to invoke
11993 * @param {*} context The context to use when calling the function
11994 * @param {...*} args Arguments for function
11995 */
11996
11997
11998/**
11999 * During execution of guarded functions we will capture the first error which
12000 * we will rethrow to be handled by the top level error handler.
12001 */
12002
12003
12004function hasCaughtError() {
12005 return hasError;
12006}
12007function clearCaughtError() {
12008 if (hasError) {
12009 var error = caughtError;
12010 hasError = false;
12011 caughtError = null;
12012 return error;
12013 } else {
12014 {
12015 {
12016 throw Error("clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue.");
12017 }
12018 }
12019 }
12020}
12021
12022// This module is forked in different environments.
12023// By default, return `true` to log errors to the console.
12024// Forks can return `false` if this isn't desirable.
12025function showErrorDialog(capturedError) {
12026 return true;
12027}
12028
12029function logCapturedError(capturedError) {
12030 var logError = showErrorDialog(capturedError); // Allow injected showErrorDialog() to prevent default console.error logging.
12031 // This enables renderers like ReactNative to better manage redbox behavior.
12032
12033 if (logError === false) {
12034 return;
12035 }
12036
12037 var error = capturedError.error;
12038
12039 {
12040 var componentName = capturedError.componentName,
12041 componentStack = capturedError.componentStack,
12042 errorBoundaryName = capturedError.errorBoundaryName,
12043 errorBoundaryFound = capturedError.errorBoundaryFound,
12044 willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
12045 // `preventDefault()` in window `error` handler.
12046 // We record this information as an expando on the error.
12047
12048 if (error != null && error._suppressLogging) {
12049 if (errorBoundaryFound && willRetry) {
12050 // The error is recoverable and was silenced.
12051 // Ignore it and don't print the stack addendum.
12052 // This is handy for testing error boundaries without noise.
12053 return;
12054 } // The error is fatal. Since the silencing might have
12055 // been accidental, we'll surface it anyway.
12056 // However, the browser would have silenced the original error
12057 // so we'll print it first, and then print the stack addendum.
12058
12059
12060 console.error(error); // For a more detailed description of this block, see:
12061 // https://github.com/facebook/react/pull/13384
12062 }
12063
12064 var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:';
12065 var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
12066
12067 if (errorBoundaryFound && errorBoundaryName) {
12068 if (willRetry) {
12069 errorBoundaryMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + errorBoundaryName + ".");
12070 } else {
12071 errorBoundaryMessage = "This error was initially handled by the error boundary " + errorBoundaryName + ".\n" + "Recreating the tree from scratch failed so React will unmount the tree.";
12072 }
12073 } else {
12074 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.';
12075 }
12076
12077 var combinedMessage = "" + componentNameMessage + componentStack + "\n\n" + ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
12078 // We don't include the original error message and JS stack because the browser
12079 // has already printed it. Even if the application swallows the error, it is still
12080 // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
12081
12082 console.error(combinedMessage);
12083 }
12084}
12085
12086var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
12087
12088{
12089 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
12090}
12091
12092var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
12093function logError(boundary, errorInfo) {
12094 var source = errorInfo.source;
12095 var stack = errorInfo.stack;
12096
12097 if (stack === null && source !== null) {
12098 stack = getStackByFiberInDevAndProd(source);
12099 }
12100
12101 var capturedError = {
12102 componentName: source !== null ? getComponentName(source.type) : null,
12103 componentStack: stack !== null ? stack : '',
12104 error: errorInfo.value,
12105 errorBoundary: null,
12106 errorBoundaryName: null,
12107 errorBoundaryFound: false,
12108 willRetry: false
12109 };
12110
12111 if (boundary !== null && boundary.tag === ClassComponent) {
12112 capturedError.errorBoundary = boundary.stateNode;
12113 capturedError.errorBoundaryName = getComponentName(boundary.type);
12114 capturedError.errorBoundaryFound = true;
12115 capturedError.willRetry = true;
12116 }
12117
12118 try {
12119 logCapturedError(capturedError);
12120 } catch (e) {
12121 // This method must not throw, or React internal state will get messed up.
12122 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
12123 // we want to report this error outside of the normal stack as a last resort.
12124 // https://github.com/facebook/react/issues/13188
12125 setTimeout(function () {
12126 throw e;
12127 });
12128 }
12129}
12130
12131var callComponentWillUnmountWithTimer = function (current$$1, instance) {
12132 startPhaseTimer(current$$1, 'componentWillUnmount');
12133 instance.props = current$$1.memoizedProps;
12134 instance.state = current$$1.memoizedState;
12135 instance.componentWillUnmount();
12136 stopPhaseTimer();
12137}; // Capture errors so they don't interrupt unmounting.
12138
12139
12140function safelyCallComponentWillUnmount(current$$1, instance) {
12141 {
12142 invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current$$1, instance);
12143
12144 if (hasCaughtError()) {
12145 var unmountError = clearCaughtError();
12146 captureCommitPhaseError(current$$1, unmountError);
12147 }
12148 }
12149}
12150
12151function safelyDetachRef(current$$1) {
12152 var ref = current$$1.ref;
12153
12154 if (ref !== null) {
12155 if (typeof ref === 'function') {
12156 {
12157 invokeGuardedCallback(null, ref, null, null);
12158
12159 if (hasCaughtError()) {
12160 var refError = clearCaughtError();
12161 captureCommitPhaseError(current$$1, refError);
12162 }
12163 }
12164 } else {
12165 ref.current = null;
12166 }
12167 }
12168}
12169
12170function safelyCallDestroy(current$$1, destroy) {
12171 {
12172 invokeGuardedCallback(null, destroy, null);
12173
12174 if (hasCaughtError()) {
12175 var error = clearCaughtError();
12176 captureCommitPhaseError(current$$1, error);
12177 }
12178 }
12179}
12180
12181function commitBeforeMutationLifeCycles(current$$1, finishedWork) {
12182 switch (finishedWork.tag) {
12183 case FunctionComponent:
12184 case ForwardRef:
12185 case SimpleMemoComponent:
12186 {
12187 commitHookEffectList(UnmountSnapshot, NoEffect$1, finishedWork);
12188 return;
12189 }
12190
12191 case ClassComponent:
12192 {
12193 if (finishedWork.effectTag & Snapshot) {
12194 if (current$$1 !== null) {
12195 var prevProps = current$$1.memoizedProps;
12196 var prevState = current$$1.memoizedState;
12197 startPhaseTimer(finishedWork, 'getSnapshotBeforeUpdate');
12198 var instance = finishedWork.stateNode; // We could update instance props and state here,
12199 // but instead we rely on them being set during last render.
12200 // TODO: revisit this when we implement resuming.
12201
12202 {
12203 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12204 !(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;
12205 !(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;
12206 }
12207 }
12208
12209 var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
12210
12211 {
12212 var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
12213
12214 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
12215 didWarnSet.add(finishedWork.type);
12216 warningWithoutStack$1(false, '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
12217 }
12218 }
12219
12220 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
12221 stopPhaseTimer();
12222 }
12223 }
12224
12225 return;
12226 }
12227
12228 case HostRoot:
12229 case HostComponent:
12230 case HostText:
12231 case HostPortal:
12232 case IncompleteClassComponent:
12233 // Nothing to do for these component types
12234 return;
12235
12236 default:
12237 {
12238 {
12239 {
12240 throw 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.");
12241 }
12242 }
12243 }
12244 }
12245}
12246
12247function commitHookEffectList(unmountTag, mountTag, finishedWork) {
12248 var updateQueue = finishedWork.updateQueue;
12249 var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
12250
12251 if (lastEffect !== null) {
12252 var firstEffect = lastEffect.next;
12253 var effect = firstEffect;
12254
12255 do {
12256 if ((effect.tag & unmountTag) !== NoEffect$1) {
12257 // Unmount
12258 var destroy = effect.destroy;
12259 effect.destroy = undefined;
12260
12261 if (destroy !== undefined) {
12262 destroy();
12263 }
12264 }
12265
12266 if ((effect.tag & mountTag) !== NoEffect$1) {
12267 // Mount
12268 var create = effect.create;
12269 effect.destroy = create();
12270
12271 {
12272 var _destroy = effect.destroy;
12273
12274 if (_destroy !== undefined && typeof _destroy !== 'function') {
12275 var addendum = void 0;
12276
12277 if (_destroy === null) {
12278 addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
12279 } else if (typeof _destroy.then === 'function') {
12280 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';
12281 } else {
12282 addendum = ' You returned: ' + _destroy;
12283 }
12284
12285 warningWithoutStack$1(false, 'An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, getStackByFiberInDevAndProd(finishedWork));
12286 }
12287 }
12288 }
12289
12290 effect = effect.next;
12291 } while (effect !== firstEffect);
12292 }
12293}
12294
12295function commitPassiveHookEffects(finishedWork) {
12296 if ((finishedWork.effectTag & Passive) !== NoEffect) {
12297 switch (finishedWork.tag) {
12298 case FunctionComponent:
12299 case ForwardRef:
12300 case SimpleMemoComponent:
12301 {
12302 commitHookEffectList(UnmountPassive, NoEffect$1, finishedWork);
12303 commitHookEffectList(NoEffect$1, MountPassive, finishedWork);
12304 break;
12305 }
12306
12307 default:
12308 break;
12309 }
12310 }
12311}
12312
12313function commitLifeCycles(finishedRoot, current$$1, finishedWork, committedExpirationTime) {
12314 switch (finishedWork.tag) {
12315 case FunctionComponent:
12316 case ForwardRef:
12317 case SimpleMemoComponent:
12318 {
12319 commitHookEffectList(UnmountLayout, MountLayout, finishedWork);
12320 break;
12321 }
12322
12323 case ClassComponent:
12324 {
12325 var instance = finishedWork.stateNode;
12326
12327 if (finishedWork.effectTag & Update) {
12328 if (current$$1 === null) {
12329 startPhaseTimer(finishedWork, 'componentDidMount'); // We could update instance props and state here,
12330 // but instead we rely on them being set during last render.
12331 // TODO: revisit this when we implement resuming.
12332
12333 {
12334 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12335 !(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;
12336 !(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;
12337 }
12338 }
12339
12340 instance.componentDidMount();
12341 stopPhaseTimer();
12342 } else {
12343 var prevProps = finishedWork.elementType === finishedWork.type ? current$$1.memoizedProps : resolveDefaultProps(finishedWork.type, current$$1.memoizedProps);
12344 var prevState = current$$1.memoizedState;
12345 startPhaseTimer(finishedWork, 'componentDidUpdate'); // We could update instance props and state here,
12346 // but instead we rely on them being set during last render.
12347 // TODO: revisit this when we implement resuming.
12348
12349 {
12350 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12351 !(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;
12352 !(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;
12353 }
12354 }
12355
12356 instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
12357 stopPhaseTimer();
12358 }
12359 }
12360
12361 var updateQueue = finishedWork.updateQueue;
12362
12363 if (updateQueue !== null) {
12364 {
12365 if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
12366 !(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;
12367 !(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;
12368 }
12369 } // We could update instance props and state here,
12370 // but instead we rely on them being set during last render.
12371 // TODO: revisit this when we implement resuming.
12372
12373
12374 commitUpdateQueue(finishedWork, updateQueue, instance, committedExpirationTime);
12375 }
12376
12377 return;
12378 }
12379
12380 case HostRoot:
12381 {
12382 var _updateQueue = finishedWork.updateQueue;
12383
12384 if (_updateQueue !== null) {
12385 var _instance = null;
12386
12387 if (finishedWork.child !== null) {
12388 switch (finishedWork.child.tag) {
12389 case HostComponent:
12390 _instance = getPublicInstance(finishedWork.child.stateNode);
12391 break;
12392
12393 case ClassComponent:
12394 _instance = finishedWork.child.stateNode;
12395 break;
12396 }
12397 }
12398
12399 commitUpdateQueue(finishedWork, _updateQueue, _instance, committedExpirationTime);
12400 }
12401
12402 return;
12403 }
12404
12405 case HostComponent:
12406 {
12407 var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
12408 // (eg DOM renderer may schedule auto-focus for inputs and form controls).
12409 // These effects should only be committed when components are first mounted,
12410 // aka when there is no current/alternate.
12411
12412 if (current$$1 === null && finishedWork.effectTag & Update) {
12413 var type = finishedWork.type;
12414 var props = finishedWork.memoizedProps;
12415
12416 }
12417
12418 return;
12419 }
12420
12421 case HostText:
12422 {
12423 // We have no life-cycles associated with text.
12424 return;
12425 }
12426
12427 case HostPortal:
12428 {
12429 // We have no life-cycles associated with portals.
12430 return;
12431 }
12432
12433 case Profiler:
12434 {
12435 if (enableProfilerTimer) {
12436 var onRender = finishedWork.memoizedProps.onRender;
12437
12438 if (typeof onRender === 'function') {
12439 if (enableSchedulerTracing) {
12440 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime(), finishedRoot.memoizedInteractions);
12441 } else {
12442 onRender(finishedWork.memoizedProps.id, current$$1 === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, getCommitTime());
12443 }
12444 }
12445 }
12446
12447 return;
12448 }
12449
12450 case SuspenseComponent:
12451 {
12452 commitSuspenseHydrationCallbacks(finishedRoot, finishedWork);
12453 return;
12454 }
12455
12456 case SuspenseListComponent:
12457 case IncompleteClassComponent:
12458 case FundamentalComponent:
12459 case ScopeComponent:
12460 return;
12461
12462 default:
12463 {
12464 {
12465 {
12466 throw 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.");
12467 }
12468 }
12469 }
12470 }
12471}
12472
12473function hideOrUnhideAllChildren(finishedWork, isHidden) {
12474 if (supportsMutation) {
12475 // We only have the top Fiber that was inserted but we need to recurse down its
12476 // children to find all the terminal nodes.
12477 var node = finishedWork;
12478
12479 while (true) {
12480 if (node.tag === HostComponent) {
12481 var instance = node.stateNode;
12482
12483 if (isHidden) {
12484 hideInstance(instance);
12485 } else {
12486 unhideInstance(node.stateNode, node.memoizedProps);
12487 }
12488 } else if (node.tag === HostText) {
12489 var _instance3 = node.stateNode;
12490
12491 if (isHidden) {
12492 hideTextInstance(_instance3);
12493 } else {
12494 unhideTextInstance(_instance3, node.memoizedProps);
12495 }
12496 } else if (node.tag === SuspenseComponent && node.memoizedState !== null && node.memoizedState.dehydrated === null) {
12497 // Found a nested Suspense component that timed out. Skip over the
12498 // primary child fragment, which should remain hidden.
12499 var fallbackChildFragment = node.child.sibling;
12500 fallbackChildFragment.return = node;
12501 node = fallbackChildFragment;
12502 continue;
12503 } else if (node.child !== null) {
12504 node.child.return = node;
12505 node = node.child;
12506 continue;
12507 }
12508
12509 if (node === finishedWork) {
12510 return;
12511 }
12512
12513 while (node.sibling === null) {
12514 if (node.return === null || node.return === finishedWork) {
12515 return;
12516 }
12517
12518 node = node.return;
12519 }
12520
12521 node.sibling.return = node.return;
12522 node = node.sibling;
12523 }
12524 }
12525}
12526
12527function commitAttachRef(finishedWork) {
12528 var ref = finishedWork.ref;
12529
12530 if (ref !== null) {
12531 var instance = finishedWork.stateNode;
12532 var instanceToUse;
12533
12534 switch (finishedWork.tag) {
12535 case HostComponent:
12536 instanceToUse = getPublicInstance(instance);
12537 break;
12538
12539 default:
12540 instanceToUse = instance;
12541 } // Moved outside to ensure DCE works with this flag
12542
12543
12544 if (enableScopeAPI && finishedWork.tag === ScopeComponent) {
12545 instanceToUse = instance.methods;
12546 }
12547
12548 if (typeof ref === 'function') {
12549 ref(instanceToUse);
12550 } else {
12551 {
12552 if (!ref.hasOwnProperty('current')) {
12553 warningWithoutStack$1(false, 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), getStackByFiberInDevAndProd(finishedWork));
12554 }
12555 }
12556
12557 ref.current = instanceToUse;
12558 }
12559 }
12560}
12561
12562function commitDetachRef(current$$1) {
12563 var currentRef = current$$1.ref;
12564
12565 if (currentRef !== null) {
12566 if (typeof currentRef === 'function') {
12567 currentRef(null);
12568 } else {
12569 currentRef.current = null;
12570 }
12571 }
12572} // User-originating errors (lifecycles and refs) should not interrupt
12573// deletion, so don't let them throw. Host-originating errors should
12574// interrupt deletion, so it's okay
12575
12576
12577function commitUnmount(finishedRoot, current$$1, renderPriorityLevel) {
12578 onCommitUnmount(current$$1);
12579
12580 switch (current$$1.tag) {
12581 case FunctionComponent:
12582 case ForwardRef:
12583 case MemoComponent:
12584 case SimpleMemoComponent:
12585 {
12586 var updateQueue = current$$1.updateQueue;
12587
12588 if (updateQueue !== null) {
12589 var lastEffect = updateQueue.lastEffect;
12590
12591 if (lastEffect !== null) {
12592 var firstEffect = lastEffect.next; // When the owner fiber is deleted, the destroy function of a passive
12593 // effect hook is called during the synchronous commit phase. This is
12594 // a concession to implementation complexity. Calling it in the
12595 // passive effect phase (like they usually are, when dependencies
12596 // change during an update) would require either traversing the
12597 // children of the deleted fiber again, or including unmount effects
12598 // as part of the fiber effect list.
12599 //
12600 // Because this is during the sync commit phase, we need to change
12601 // the priority.
12602 //
12603 // TODO: Reconsider this implementation trade off.
12604
12605 var priorityLevel = renderPriorityLevel > NormalPriority ? NormalPriority : renderPriorityLevel;
12606 runWithPriority(priorityLevel, function () {
12607 var effect = firstEffect;
12608
12609 do {
12610 var destroy = effect.destroy;
12611
12612 if (destroy !== undefined) {
12613 safelyCallDestroy(current$$1, destroy);
12614 }
12615
12616 effect = effect.next;
12617 } while (effect !== firstEffect);
12618 });
12619 }
12620 }
12621
12622 break;
12623 }
12624
12625 case ClassComponent:
12626 {
12627 safelyDetachRef(current$$1);
12628 var instance = current$$1.stateNode;
12629
12630 if (typeof instance.componentWillUnmount === 'function') {
12631 safelyCallComponentWillUnmount(current$$1, instance);
12632 }
12633
12634 return;
12635 }
12636
12637 case HostComponent:
12638 {
12639 if (enableFlareAPI) {
12640 var dependencies = current$$1.dependencies;
12641
12642 if (dependencies !== null) {
12643 var respondersMap = dependencies.responders;
12644
12645 if (respondersMap !== null) {
12646 var responderInstances = Array.from(respondersMap.values());
12647
12648 for (var i = 0, length = responderInstances.length; i < length; i++) {
12649 var responderInstance = responderInstances[i];
12650
12651 }
12652
12653 dependencies.responders = null;
12654 }
12655 }
12656 }
12657
12658 safelyDetachRef(current$$1);
12659 return;
12660 }
12661
12662 case HostPortal:
12663 {
12664 // TODO: this is recursive.
12665 // We are also not using this parent because
12666 // the portal will get pushed immediately.
12667 if (supportsMutation) {
12668 unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel);
12669 } else if (supportsPersistence) {
12670 emptyPortalContainer(current$$1);
12671 }
12672
12673 return;
12674 }
12675
12676 case FundamentalComponent:
12677 {
12678 if (enableFundamentalAPI) {
12679 var fundamentalInstance = current$$1.stateNode;
12680
12681 if (fundamentalInstance !== null) {
12682 unmountFundamentalComponent(fundamentalInstance);
12683 current$$1.stateNode = null;
12684 }
12685 }
12686
12687 return;
12688 }
12689
12690 case DehydratedFragment:
12691 {
12692 if (enableSuspenseCallback) {
12693 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
12694
12695 if (hydrationCallbacks !== null) {
12696 var onDeleted = hydrationCallbacks.onDeleted;
12697
12698 if (onDeleted) {
12699 onDeleted(current$$1.stateNode);
12700 }
12701 }
12702 }
12703
12704 return;
12705 }
12706
12707 case ScopeComponent:
12708 {
12709 if (enableScopeAPI) {
12710 safelyDetachRef(current$$1);
12711 }
12712 }
12713 }
12714}
12715
12716function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
12717 // While we're inside a removed host node we don't want to call
12718 // removeChild on the inner nodes because they're removed by the top
12719 // call anyway. We also want to call componentWillUnmount on all
12720 // composites before this host node is removed from the tree. Therefore
12721 // we do an inner loop while we're still inside the host node.
12722 var node = root;
12723
12724 while (true) {
12725 commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
12726 // Skip portals because commitUnmount() currently visits them recursively.
12727
12728 if (node.child !== null && ( // If we use mutation we drill down into portals using commitUnmount above.
12729 // If we don't use mutation we drill down into portals here instead.
12730 !supportsMutation || node.tag !== HostPortal)) {
12731 node.child.return = node;
12732 node = node.child;
12733 continue;
12734 }
12735
12736 if (node === root) {
12737 return;
12738 }
12739
12740 while (node.sibling === null) {
12741 if (node.return === null || node.return === root) {
12742 return;
12743 }
12744
12745 node = node.return;
12746 }
12747
12748 node.sibling.return = node.return;
12749 node = node.sibling;
12750 }
12751}
12752
12753function detachFiber(current$$1) {
12754 var alternate = current$$1.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
12755 // should clear the child pointer of the parent alternate to let this
12756 // get GC:ed but we don't know which for sure which parent is the current
12757 // one so we'll settle for GC:ing the subtree of this child. This child
12758 // itself will be GC:ed when the parent updates the next time.
12759
12760 current$$1.return = null;
12761 current$$1.child = null;
12762 current$$1.memoizedState = null;
12763 current$$1.updateQueue = null;
12764 current$$1.dependencies = null;
12765 current$$1.alternate = null;
12766 current$$1.firstEffect = null;
12767 current$$1.lastEffect = null;
12768 current$$1.pendingProps = null;
12769 current$$1.memoizedProps = null;
12770
12771 if (alternate !== null) {
12772 detachFiber(alternate);
12773 }
12774}
12775
12776function emptyPortalContainer(current$$1) {
12777 if (!supportsPersistence) {
12778 return;
12779 }
12780
12781 var portal = current$$1.stateNode;
12782 var containerInfo = portal.containerInfo;
12783 var emptyChildSet = createContainerChildSet(containerInfo);
12784 replaceContainerChildren(containerInfo, emptyChildSet);
12785}
12786
12787function commitContainer(finishedWork) {
12788 if (!supportsPersistence) {
12789 return;
12790 }
12791
12792 switch (finishedWork.tag) {
12793 case ClassComponent:
12794 case HostComponent:
12795 case HostText:
12796 case FundamentalComponent:
12797 {
12798 return;
12799 }
12800
12801 case HostRoot:
12802 case HostPortal:
12803 {
12804 var portalOrRoot = finishedWork.stateNode;
12805 var containerInfo = portalOrRoot.containerInfo,
12806 pendingChildren = portalOrRoot.pendingChildren;
12807 replaceContainerChildren(containerInfo, pendingChildren);
12808 return;
12809 }
12810
12811 default:
12812 {
12813 {
12814 {
12815 throw 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.");
12816 }
12817 }
12818 }
12819 }
12820}
12821
12822function getHostParentFiber(fiber) {
12823 var parent = fiber.return;
12824
12825 while (parent !== null) {
12826 if (isHostParent(parent)) {
12827 return parent;
12828 }
12829
12830 parent = parent.return;
12831 }
12832
12833 {
12834 {
12835 throw Error("Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.");
12836 }
12837 }
12838}
12839
12840function isHostParent(fiber) {
12841 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
12842}
12843
12844function getHostSibling(fiber) {
12845 // We're going to search forward into the tree until we find a sibling host
12846 // node. Unfortunately, if multiple insertions are done in a row we have to
12847 // search past them. This leads to exponential search for the next sibling.
12848 // TODO: Find a more efficient way to do this.
12849 var node = fiber;
12850
12851 siblings: while (true) {
12852 // If we didn't find anything, let's try the next sibling.
12853 while (node.sibling === null) {
12854 if (node.return === null || isHostParent(node.return)) {
12855 // If we pop out of the root or hit the parent the fiber we are the
12856 // last sibling.
12857 return null;
12858 }
12859
12860 node = node.return;
12861 }
12862
12863 node.sibling.return = node.return;
12864 node = node.sibling;
12865
12866 while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {
12867 // If it is not host node and, we might have a host node inside it.
12868 // Try to search down until we find one.
12869 if (node.effectTag & Placement) {
12870 // If we don't have a child, try the siblings instead.
12871 continue siblings;
12872 } // If we don't have a child, try the siblings instead.
12873 // We also skip portals because they are not part of this host tree.
12874
12875
12876 if (node.child === null || node.tag === HostPortal) {
12877 continue siblings;
12878 } else {
12879 node.child.return = node;
12880 node = node.child;
12881 }
12882 } // Check if this host node is stable or about to be placed.
12883
12884
12885 if (!(node.effectTag & Placement)) {
12886 // Found it!
12887 return node.stateNode;
12888 }
12889 }
12890}
12891
12892function commitPlacement(finishedWork) {
12893 if (!supportsMutation) {
12894 return;
12895 } // Recursively insert all host nodes into the parent.
12896
12897
12898 var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
12899
12900 var parent;
12901 var isContainer;
12902 var parentStateNode = parentFiber.stateNode;
12903
12904 switch (parentFiber.tag) {
12905 case HostComponent:
12906 parent = parentStateNode;
12907 isContainer = false;
12908 break;
12909
12910 case HostRoot:
12911 parent = parentStateNode.containerInfo;
12912 isContainer = true;
12913 break;
12914
12915 case HostPortal:
12916 parent = parentStateNode.containerInfo;
12917 isContainer = true;
12918 break;
12919
12920 case FundamentalComponent:
12921 if (enableFundamentalAPI) {
12922 parent = parentStateNode.instance;
12923 isContainer = false;
12924 }
12925
12926 // eslint-disable-next-line-no-fallthrough
12927
12928 default:
12929 {
12930 {
12931 throw Error("Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue.");
12932 }
12933 }
12934
12935 }
12936
12937 if (parentFiber.effectTag & ContentReset) {
12938 // Reset the text content of the parent before doing any insertions
12939 parentFiber.effectTag &= ~ContentReset;
12940 }
12941
12942 var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
12943 // children to find all the terminal nodes.
12944
12945 var node = finishedWork;
12946
12947 while (true) {
12948 var isHost = node.tag === HostComponent || node.tag === HostText;
12949
12950 if (isHost || enableFundamentalAPI && node.tag === FundamentalComponent) {
12951 var stateNode = isHost ? node.stateNode : node.stateNode.instance;
12952
12953 if (before) {
12954 if (isContainer) {
12955 insertInContainerBefore(parent, stateNode, before);
12956 } else {
12957 insertBefore(parent, stateNode, before);
12958 }
12959 } else {
12960 if (isContainer) {
12961 appendChildToContainer(parent, stateNode);
12962 } else {
12963 appendChild(parent, stateNode);
12964 }
12965 }
12966 } else if (node.tag === HostPortal) {// If the insertion itself is a portal, then we don't want to traverse
12967 // down its children. Instead, we'll get insertions from each child in
12968 // the portal directly.
12969 } else if (node.child !== null) {
12970 node.child.return = node;
12971 node = node.child;
12972 continue;
12973 }
12974
12975 if (node === finishedWork) {
12976 return;
12977 }
12978
12979 while (node.sibling === null) {
12980 if (node.return === null || node.return === finishedWork) {
12981 return;
12982 }
12983
12984 node = node.return;
12985 }
12986
12987 node.sibling.return = node.return;
12988 node = node.sibling;
12989 }
12990}
12991
12992function unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel) {
12993 // We only have the top Fiber that was deleted but we need to recurse down its
12994 // children to find all the terminal nodes.
12995 var node = current$$1; // Each iteration, currentParent is populated with node's host parent if not
12996 // currentParentIsValid.
12997
12998 var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
12999
13000 var currentParent;
13001 var currentParentIsContainer;
13002
13003 while (true) {
13004 if (!currentParentIsValid) {
13005 var parent = node.return;
13006
13007 findParent: while (true) {
13008 if (!(parent !== null)) {
13009 {
13010 throw Error("Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue.");
13011 }
13012 }
13013
13014 var parentStateNode = parent.stateNode;
13015
13016 switch (parent.tag) {
13017 case HostComponent:
13018 currentParent = parentStateNode;
13019 currentParentIsContainer = false;
13020 break findParent;
13021
13022 case HostRoot:
13023 currentParent = parentStateNode.containerInfo;
13024 currentParentIsContainer = true;
13025 break findParent;
13026
13027 case HostPortal:
13028 currentParent = parentStateNode.containerInfo;
13029 currentParentIsContainer = true;
13030 break findParent;
13031
13032 case FundamentalComponent:
13033 if (enableFundamentalAPI) {
13034 currentParent = parentStateNode.instance;
13035 currentParentIsContainer = false;
13036 }
13037
13038 }
13039
13040 parent = parent.return;
13041 }
13042
13043 currentParentIsValid = true;
13044 }
13045
13046 if (node.tag === HostComponent || node.tag === HostText) {
13047 commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
13048 // node from the tree.
13049
13050 if (currentParentIsContainer) {
13051 removeChildFromContainer(currentParent, node.stateNode);
13052 } else {
13053 removeChild(currentParent, node.stateNode);
13054 } // Don't visit children because we already visited them.
13055
13056 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {
13057 var fundamentalNode = node.stateNode.instance;
13058 commitNestedUnmounts(finishedRoot, node, renderPriorityLevel); // After all the children have unmounted, it is now safe to remove the
13059 // node from the tree.
13060
13061 if (currentParentIsContainer) {
13062 removeChildFromContainer(currentParent, fundamentalNode);
13063 } else {
13064 removeChild(currentParent, fundamentalNode);
13065 }
13066 } else if (enableSuspenseServerRenderer && node.tag === DehydratedFragment) {
13067 if (enableSuspenseCallback) {
13068 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
13069
13070 if (hydrationCallbacks !== null) {
13071 var onDeleted = hydrationCallbacks.onDeleted;
13072
13073 if (onDeleted) {
13074 onDeleted(node.stateNode);
13075 }
13076 }
13077 } // Delete the dehydrated suspense boundary and all of its content.
13078
13079
13080 if (currentParentIsContainer) {
13081 clearSuspenseBoundaryFromContainer(currentParent, node.stateNode);
13082 } else {
13083 clearSuspenseBoundary(currentParent, node.stateNode);
13084 }
13085 } else if (node.tag === HostPortal) {
13086 if (node.child !== null) {
13087 // When we go into a portal, it becomes the parent to remove from.
13088 // We will reassign it back when we pop the portal on the way up.
13089 currentParent = node.stateNode.containerInfo;
13090 currentParentIsContainer = true; // Visit children because portals might contain host components.
13091
13092 node.child.return = node;
13093 node = node.child;
13094 continue;
13095 }
13096 } else {
13097 commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because we may find more host components below.
13098
13099 if (node.child !== null) {
13100 node.child.return = node;
13101 node = node.child;
13102 continue;
13103 }
13104 }
13105
13106 if (node === current$$1) {
13107 return;
13108 }
13109
13110 while (node.sibling === null) {
13111 if (node.return === null || node.return === current$$1) {
13112 return;
13113 }
13114
13115 node = node.return;
13116
13117 if (node.tag === HostPortal) {
13118 // When we go out of the portal, we need to restore the parent.
13119 // Since we don't keep a stack of them, we will search for it.
13120 currentParentIsValid = false;
13121 }
13122 }
13123
13124 node.sibling.return = node.return;
13125 node = node.sibling;
13126 }
13127}
13128
13129function commitDeletion(finishedRoot, current$$1, renderPriorityLevel) {
13130 if (supportsMutation) {
13131 // Recursively delete all host nodes from the parent.
13132 // Detach refs and call componentWillUnmount() on the whole subtree.
13133 unmountHostComponents(finishedRoot, current$$1, renderPriorityLevel);
13134 } else {
13135 // Detach refs and call componentWillUnmount() on the whole subtree.
13136 commitNestedUnmounts(finishedRoot, current$$1, renderPriorityLevel);
13137 }
13138
13139 detachFiber(current$$1);
13140}
13141
13142function commitWork(current$$1, finishedWork) {
13143 if (!supportsMutation) {
13144 switch (finishedWork.tag) {
13145 case FunctionComponent:
13146 case ForwardRef:
13147 case MemoComponent:
13148 case SimpleMemoComponent:
13149 {
13150 // Note: We currently never use MountMutation, but useLayout uses
13151 // UnmountMutation.
13152 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
13153 return;
13154 }
13155
13156 case Profiler:
13157 {
13158 return;
13159 }
13160
13161 case SuspenseComponent:
13162 {
13163 commitSuspenseComponent(finishedWork);
13164 attachSuspenseRetryListeners(finishedWork);
13165 return;
13166 }
13167
13168 case SuspenseListComponent:
13169 {
13170 attachSuspenseRetryListeners(finishedWork);
13171 return;
13172 }
13173
13174 case HostRoot:
13175 {
13176 if (supportsHydration) {
13177 var root = finishedWork.stateNode;
13178
13179 if (root.hydrate) {
13180 // We've just hydrated. No need to hydrate again.
13181 root.hydrate = false;
13182 commitHydratedContainer(root.containerInfo);
13183 }
13184 }
13185
13186 break;
13187 }
13188 }
13189
13190 commitContainer(finishedWork);
13191 return;
13192 }
13193
13194 switch (finishedWork.tag) {
13195 case FunctionComponent:
13196 case ForwardRef:
13197 case MemoComponent:
13198 case SimpleMemoComponent:
13199 {
13200 // Note: We currently never use MountMutation, but useLayout uses
13201 // UnmountMutation.
13202 commitHookEffectList(UnmountMutation, MountMutation, finishedWork);
13203 return;
13204 }
13205
13206 case ClassComponent:
13207 {
13208 return;
13209 }
13210
13211 case HostComponent:
13212 {
13213 var instance = finishedWork.stateNode;
13214
13215 if (instance != null) {
13216 // Commit the work prepared earlier.
13217 var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
13218 // as the newProps. The updatePayload will contain the real change in
13219 // this case.
13220
13221 var oldProps = current$$1 !== null ? current$$1.memoizedProps : newProps;
13222 var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
13223
13224 var updatePayload = finishedWork.updateQueue;
13225 finishedWork.updateQueue = null;
13226
13227 if (updatePayload !== null) {
13228 commitUpdate(instance, updatePayload, type, oldProps, newProps, finishedWork);
13229 }
13230
13231 if (enableFlareAPI) {
13232 var prevListeners = oldProps.listeners;
13233 var nextListeners = newProps.listeners;
13234
13235 if (prevListeners !== nextListeners) {
13236 updateEventListeners(nextListeners, finishedWork, null);
13237 }
13238 }
13239 }
13240
13241 return;
13242 }
13243
13244 case HostText:
13245 {
13246 if (!(finishedWork.stateNode !== null)) {
13247 {
13248 throw Error("This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue.");
13249 }
13250 }
13251
13252 var textInstance = finishedWork.stateNode;
13253 var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
13254 // as the newProps. The updatePayload will contain the real change in
13255 // this case.
13256
13257 var oldText = current$$1 !== null ? current$$1.memoizedProps : newText;
13258 commitTextUpdate(textInstance, oldText, newText);
13259 return;
13260 }
13261
13262 case HostRoot:
13263 {
13264 if (supportsHydration) {
13265 var _root = finishedWork.stateNode;
13266
13267 if (_root.hydrate) {
13268 // We've just hydrated. No need to hydrate again.
13269 _root.hydrate = false;
13270 commitHydratedContainer(_root.containerInfo);
13271 }
13272 }
13273
13274 return;
13275 }
13276
13277 case Profiler:
13278 {
13279 return;
13280 }
13281
13282 case SuspenseComponent:
13283 {
13284 commitSuspenseComponent(finishedWork);
13285 attachSuspenseRetryListeners(finishedWork);
13286 return;
13287 }
13288
13289 case SuspenseListComponent:
13290 {
13291 attachSuspenseRetryListeners(finishedWork);
13292 return;
13293 }
13294
13295 case IncompleteClassComponent:
13296 {
13297 return;
13298 }
13299
13300 case FundamentalComponent:
13301 {
13302 if (enableFundamentalAPI) {
13303 var fundamentalInstance = finishedWork.stateNode;
13304 updateFundamentalComponent(fundamentalInstance);
13305 }
13306
13307 return;
13308 }
13309
13310 case ScopeComponent:
13311 {
13312 if (enableScopeAPI) {
13313 var scopeInstance = finishedWork.stateNode;
13314 scopeInstance.fiber = finishedWork;
13315
13316 if (enableFlareAPI) {
13317 var _newProps = finishedWork.memoizedProps;
13318
13319 var _oldProps = current$$1 !== null ? current$$1.memoizedProps : _newProps;
13320
13321 var _prevListeners = _oldProps.listeners;
13322 var _nextListeners = _newProps.listeners;
13323
13324 if (_prevListeners !== _nextListeners) {
13325 updateEventListeners(_nextListeners, finishedWork, null);
13326 }
13327 }
13328 }
13329
13330 return;
13331 }
13332
13333 default:
13334 {
13335 {
13336 {
13337 throw 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.");
13338 }
13339 }
13340 }
13341 }
13342}
13343
13344function commitSuspenseComponent(finishedWork) {
13345 var newState = finishedWork.memoizedState;
13346 var newDidTimeout;
13347 var primaryChildParent = finishedWork;
13348
13349 if (newState === null) {
13350 newDidTimeout = false;
13351 } else {
13352 newDidTimeout = true;
13353 primaryChildParent = finishedWork.child;
13354 markCommitTimeOfFallback();
13355 }
13356
13357 if (supportsMutation && primaryChildParent !== null) {
13358 hideOrUnhideAllChildren(primaryChildParent, newDidTimeout);
13359 }
13360
13361 if (enableSuspenseCallback && newState !== null) {
13362 var suspenseCallback = finishedWork.memoizedProps.suspenseCallback;
13363
13364 if (typeof suspenseCallback === 'function') {
13365 var thenables = finishedWork.updateQueue;
13366
13367 if (thenables !== null) {
13368 suspenseCallback(new Set(thenables));
13369 }
13370 } else {
13371 if (suspenseCallback !== undefined) {
13372 warning$1(false, 'Unexpected type for suspenseCallback.');
13373 }
13374 }
13375 }
13376}
13377
13378function commitSuspenseHydrationCallbacks(finishedRoot, finishedWork) {
13379 if (!supportsHydration) {
13380 return;
13381 }
13382
13383 var newState = finishedWork.memoizedState;
13384
13385 if (newState === null) {
13386 var current$$1 = finishedWork.alternate;
13387
13388 if (current$$1 !== null) {
13389 var prevState = current$$1.memoizedState;
13390
13391 if (prevState !== null) {
13392 var suspenseInstance = prevState.dehydrated;
13393
13394 if (suspenseInstance !== null) {
13395 commitHydratedSuspenseInstance(suspenseInstance);
13396
13397 if (enableSuspenseCallback) {
13398 var hydrationCallbacks = finishedRoot.hydrationCallbacks;
13399
13400 if (hydrationCallbacks !== null) {
13401 var onHydrated = hydrationCallbacks.onHydrated;
13402
13403 if (onHydrated) {
13404 onHydrated(suspenseInstance);
13405 }
13406 }
13407 }
13408 }
13409 }
13410 }
13411 }
13412}
13413
13414function attachSuspenseRetryListeners(finishedWork) {
13415 // If this boundary just timed out, then it will have a set of thenables.
13416 // For each thenable, attach a listener so that when it resolves, React
13417 // attempts to re-render the boundary in the primary (pre-timeout) state.
13418 var thenables = finishedWork.updateQueue;
13419
13420 if (thenables !== null) {
13421 finishedWork.updateQueue = null;
13422 var retryCache = finishedWork.stateNode;
13423
13424 if (retryCache === null) {
13425 retryCache = finishedWork.stateNode = new PossiblyWeakSet();
13426 }
13427
13428 thenables.forEach(function (thenable) {
13429 // Memoize using the boundary fiber to prevent redundant listeners.
13430 var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
13431
13432 if (!retryCache.has(thenable)) {
13433 if (enableSchedulerTracing) {
13434 if (thenable.__reactDoNotTraceInteractions !== true) {
13435 retry = unstable_wrap(retry);
13436 }
13437 }
13438
13439 retryCache.add(thenable);
13440 thenable.then(retry, retry);
13441 }
13442 });
13443 }
13444}
13445
13446function commitResetTextContent(current$$1) {
13447 if (!supportsMutation) {
13448 return;
13449 }
13450
13451 resetTextContent(current$$1.stateNode);
13452}
13453
13454var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
13455
13456function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
13457 var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
13458
13459 update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
13460 // being called "element".
13461
13462 update.payload = {
13463 element: null
13464 };
13465 var error = errorInfo.value;
13466
13467 update.callback = function () {
13468 onUncaughtError(error);
13469 logError(fiber, errorInfo);
13470 };
13471
13472 return update;
13473}
13474
13475function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
13476 var update = createUpdate(expirationTime, null);
13477 update.tag = CaptureUpdate;
13478 var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
13479
13480 if (typeof getDerivedStateFromError === 'function') {
13481 var error = errorInfo.value;
13482
13483 update.payload = function () {
13484 logError(fiber, errorInfo);
13485 return getDerivedStateFromError(error);
13486 };
13487 }
13488
13489 var inst = fiber.stateNode;
13490
13491 if (inst !== null && typeof inst.componentDidCatch === 'function') {
13492 update.callback = function callback() {
13493 {
13494 markFailedErrorBoundaryForHotReloading(fiber);
13495 }
13496
13497 if (typeof getDerivedStateFromError !== 'function') {
13498 // To preserve the preexisting retry behavior of error boundaries,
13499 // we keep track of which ones already failed during this batch.
13500 // This gets reset before we yield back to the browser.
13501 // TODO: Warn in strict mode if getDerivedStateFromError is
13502 // not defined.
13503 markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
13504
13505 logError(fiber, errorInfo);
13506 }
13507
13508 var error = errorInfo.value;
13509 var stack = errorInfo.stack;
13510 this.componentDidCatch(error, {
13511 componentStack: stack !== null ? stack : ''
13512 });
13513
13514 {
13515 if (typeof getDerivedStateFromError !== 'function') {
13516 // If componentDidCatch is the only error boundary method defined,
13517 // then it needs to call setState to recover from errors.
13518 // If no state update is scheduled then the boundary will swallow the error.
13519 !(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;
13520 }
13521 }
13522 };
13523 } else {
13524 update.callback = function () {
13525 markFailedErrorBoundaryForHotReloading(fiber);
13526 };
13527 }
13528
13529 return update;
13530}
13531
13532function attachPingListener(root, renderExpirationTime, thenable) {
13533 // Attach a listener to the promise to "ping" the root and retry. But
13534 // only if one does not already exist for the current render expiration
13535 // time (which acts like a "thread ID" here).
13536 var pingCache = root.pingCache;
13537 var threadIDs;
13538
13539 if (pingCache === null) {
13540 pingCache = root.pingCache = new PossiblyWeakMap();
13541 threadIDs = new Set();
13542 pingCache.set(thenable, threadIDs);
13543 } else {
13544 threadIDs = pingCache.get(thenable);
13545
13546 if (threadIDs === undefined) {
13547 threadIDs = new Set();
13548 pingCache.set(thenable, threadIDs);
13549 }
13550 }
13551
13552 if (!threadIDs.has(renderExpirationTime)) {
13553 // Memoize using the thread ID to prevent redundant listeners.
13554 threadIDs.add(renderExpirationTime);
13555 var ping = pingSuspendedRoot.bind(null, root, thenable, renderExpirationTime);
13556 thenable.then(ping, ping);
13557 }
13558}
13559
13560function throwException(root, returnFiber, sourceFiber, value, renderExpirationTime) {
13561 // The source fiber did not complete.
13562 sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
13563
13564 sourceFiber.firstEffect = sourceFiber.lastEffect = null;
13565
13566 if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
13567 // This is a thenable.
13568 var thenable = value;
13569 checkForWrongSuspensePriorityInDEV(sourceFiber);
13570 var hasInvisibleParentBoundary = hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext); // Schedule the nearest Suspense to re-render the timed out view.
13571
13572 var _workInProgress = returnFiber;
13573
13574 do {
13575 if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)) {
13576 // Found the nearest boundary.
13577 // Stash the promise on the boundary fiber. If the boundary times out, we'll
13578 // attach another listener to flip the boundary back to its normal state.
13579 var thenables = _workInProgress.updateQueue;
13580
13581 if (thenables === null) {
13582 var updateQueue = new Set();
13583 updateQueue.add(thenable);
13584 _workInProgress.updateQueue = updateQueue;
13585 } else {
13586 thenables.add(thenable);
13587 } // If the boundary is outside of blocking mode, we should *not*
13588 // suspend the commit. Pretend as if the suspended component rendered
13589 // null and keep rendering. In the commit phase, we'll schedule a
13590 // subsequent synchronous update to re-render the Suspense.
13591 //
13592 // Note: It doesn't matter whether the component that suspended was
13593 // inside a blocking mode tree. If the Suspense is outside of it, we
13594 // should *not* suspend the commit.
13595
13596
13597 if ((_workInProgress.mode & BlockingMode) === NoMode) {
13598 _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
13599 // But we shouldn't call any lifecycle methods or callbacks. Remove
13600 // all lifecycle effect tags.
13601
13602 sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
13603
13604 if (sourceFiber.tag === ClassComponent) {
13605 var currentSourceFiber = sourceFiber.alternate;
13606
13607 if (currentSourceFiber === null) {
13608 // This is a new mount. Change the tag so it's not mistaken for a
13609 // completed class component. For example, we should not call
13610 // componentWillUnmount if it is deleted.
13611 sourceFiber.tag = IncompleteClassComponent;
13612 } else {
13613 // When we try rendering again, we should not reuse the current fiber,
13614 // since it's known to be in an inconsistent state. Use a force update to
13615 // prevent a bail out.
13616 var update = createUpdate(Sync, null);
13617 update.tag = ForceUpdate;
13618 enqueueUpdate(sourceFiber, update);
13619 }
13620 } // The source fiber did not complete. Mark it with Sync priority to
13621 // indicate that it still has pending work.
13622
13623
13624 sourceFiber.expirationTime = Sync; // Exit without suspending.
13625
13626 return;
13627 } // Confirmed that the boundary is in a concurrent mode tree. Continue
13628 // with the normal suspend path.
13629 //
13630 // After this we'll use a set of heuristics to determine whether this
13631 // render pass will run to completion or restart or "suspend" the commit.
13632 // The actual logic for this is spread out in different places.
13633 //
13634 // This first principle is that if we're going to suspend when we complete
13635 // a root, then we should also restart if we get an update or ping that
13636 // might unsuspend it, and vice versa. The only reason to suspend is
13637 // because you think you might want to restart before committing. However,
13638 // it doesn't make sense to restart only while in the period we're suspended.
13639 //
13640 // Restarting too aggressively is also not good because it starves out any
13641 // intermediate loading state. So we use heuristics to determine when.
13642 // Suspense Heuristics
13643 //
13644 // If nothing threw a Promise or all the same fallbacks are already showing,
13645 // then don't suspend/restart.
13646 //
13647 // If this is an initial render of a new tree of Suspense boundaries and
13648 // those trigger a fallback, then don't suspend/restart. We want to ensure
13649 // that we can show the initial loading state as quickly as possible.
13650 //
13651 // If we hit a "Delayed" case, such as when we'd switch from content back into
13652 // a fallback, then we should always suspend/restart. SuspenseConfig applies to
13653 // this case. If none is defined, JND is used instead.
13654 //
13655 // If we're already showing a fallback and it gets "retried", allowing us to show
13656 // another level, but there's still an inner boundary that would show a fallback,
13657 // then we suspend/restart for 500ms since the last time we showed a fallback
13658 // anywhere in the tree. This effectively throttles progressive loading into a
13659 // consistent train of commits. This also gives us an opportunity to restart to
13660 // get to the completed state slightly earlier.
13661 //
13662 // If there's ambiguity due to batching it's resolved in preference of:
13663 // 1) "delayed", 2) "initial render", 3) "retry".
13664 //
13665 // We want to ensure that a "busy" state doesn't get force committed. We want to
13666 // ensure that new initial loading states can commit as soon as possible.
13667
13668
13669 attachPingListener(root, renderExpirationTime, thenable);
13670 _workInProgress.effectTag |= ShouldCapture;
13671 _workInProgress.expirationTime = renderExpirationTime;
13672 return;
13673 } // This boundary already captured during this render. Continue to the next
13674 // boundary.
13675
13676
13677 _workInProgress = _workInProgress.return;
13678 } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
13679 // TODO: Use invariant so the message is stripped in prod?
13680
13681
13682 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));
13683 } // We didn't find a boundary that could handle this type of exception. Start
13684 // over and traverse parent path again, this time treating the exception
13685 // as an error.
13686
13687
13688 renderDidError();
13689 value = createCapturedValue(value, sourceFiber);
13690 var workInProgress = returnFiber;
13691
13692 do {
13693 switch (workInProgress.tag) {
13694 case HostRoot:
13695 {
13696 var _errorInfo = value;
13697 workInProgress.effectTag |= ShouldCapture;
13698 workInProgress.expirationTime = renderExpirationTime;
13699
13700 var _update = createRootErrorUpdate(workInProgress, _errorInfo, renderExpirationTime);
13701
13702 enqueueCapturedUpdate(workInProgress, _update);
13703 return;
13704 }
13705
13706 case ClassComponent:
13707 // Capture and retry
13708 var errorInfo = value;
13709 var ctor = workInProgress.type;
13710 var instance = workInProgress.stateNode;
13711
13712 if ((workInProgress.effectTag & DidCapture) === NoEffect && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
13713 workInProgress.effectTag |= ShouldCapture;
13714 workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
13715
13716 var _update2 = createClassErrorUpdate(workInProgress, errorInfo, renderExpirationTime);
13717
13718 enqueueCapturedUpdate(workInProgress, _update2);
13719 return;
13720 }
13721
13722 break;
13723
13724 default:
13725 break;
13726 }
13727
13728 workInProgress = workInProgress.return;
13729 } while (workInProgress !== null);
13730}
13731
13732var ceil = Math.ceil;
13733var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
13734var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
13735var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
13736var NoContext =
13737/* */
137380;
13739var BatchedContext =
13740/* */
137411;
13742var DiscreteEventContext =
13743/* */
137444;
13745var LegacyUnbatchedContext =
13746/* */
137478;
13748var RenderContext =
13749/* */
1375016;
13751var CommitContext =
13752/* */
1375332;
13754var RootIncomplete = 0;
13755var RootFatalErrored = 1;
13756var RootErrored = 2;
13757var RootSuspended = 3;
13758var RootSuspendedWithDelay = 4;
13759var RootCompleted = 5;
13760// Describes where we are in the React execution stack
13761var executionContext = NoContext; // The root we're working on
13762
13763var workInProgressRoot = null; // The fiber we're working on
13764
13765var workInProgress = null; // The expiration time we're rendering
13766
13767var renderExpirationTime = NoWork; // Whether to root completed, errored, suspended, etc.
13768
13769var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
13770
13771var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
13772// This is conceptually a time stamp but expressed in terms of an ExpirationTime
13773// because we deal mostly with expiration times in the hot path, so this avoids
13774// the conversion happening in the hot path.
13775
13776var workInProgressRootLatestProcessedExpirationTime = Sync;
13777var workInProgressRootLatestSuspenseTimeout = Sync;
13778var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
13779// includes unprocessed updates, not work in bailed out children.
13780
13781var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
13782// This flag determines if it might be worthwhile to restart if an opportunity
13783// happens latere.
13784
13785var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
13786// model where we don't commit new loading states in too quick succession.
13787
13788var globalMostRecentFallbackTime = 0;
13789var FALLBACK_THROTTLE_MS = 500;
13790var nextEffect = null;
13791var hasUncaughtError = false;
13792var firstUncaughtError = null;
13793var legacyErrorBoundariesThatAlreadyFailed = null;
13794var rootDoesHavePassiveEffects = false;
13795var rootWithPendingPassiveEffects = null;
13796var pendingPassiveEffectsRenderPriority = NoPriority;
13797var pendingPassiveEffectsExpirationTime = NoWork;
13798var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
13799
13800var NESTED_UPDATE_LIMIT = 50;
13801var nestedUpdateCount = 0;
13802var rootWithNestedUpdates = null;
13803var NESTED_PASSIVE_UPDATE_LIMIT = 50;
13804var nestedPassiveUpdateCount = 0;
13805var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
13806// during the commit phase. This enables them to be traced across components
13807// that spawn new work during render. E.g. hidden boundaries, suspended SSR
13808// hydration or SuspenseList.
13809
13810var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
13811// time). However, if two updates are scheduled within the same event, we
13812// should treat their start times as simultaneous, even if the actual clock
13813// time has advanced between the first and second call.
13814// In other words, because expiration times determine how updates are batched,
13815// we want all updates of like priority that occur within the same event to
13816// receive the same expiration time. Otherwise we get tearing.
13817
13818var currentEventTime = NoWork;
13819function requestCurrentTimeForUpdate() {
13820 if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
13821 // We're inside React, so it's fine to read the actual time.
13822 return msToExpirationTime(now());
13823 } // We're not inside React, so we may be in the middle of a browser event.
13824
13825
13826 if (currentEventTime !== NoWork) {
13827 // Use the same start time for all updates until we enter React again.
13828 return currentEventTime;
13829 } // This is the first update since React yielded. Compute a new start time.
13830
13831
13832 currentEventTime = msToExpirationTime(now());
13833 return currentEventTime;
13834}
13835function getCurrentTime() {
13836 return msToExpirationTime(now());
13837}
13838function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
13839 var mode = fiber.mode;
13840
13841 if ((mode & BlockingMode) === NoMode) {
13842 return Sync;
13843 }
13844
13845 var priorityLevel = getCurrentPriorityLevel();
13846
13847 if ((mode & ConcurrentMode) === NoMode) {
13848 return priorityLevel === ImmediatePriority ? Sync : Batched;
13849 }
13850
13851 if ((executionContext & RenderContext) !== NoContext) {
13852 // Use whatever time we're already rendering
13853 // TODO: Should there be a way to opt out, like with `runWithPriority`?
13854 return renderExpirationTime;
13855 }
13856
13857 var expirationTime;
13858
13859 if (suspenseConfig !== null) {
13860 // Compute an expiration time based on the Suspense timeout.
13861 expirationTime = computeSuspenseExpiration(currentTime, suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
13862 } else {
13863 // Compute an expiration time based on the Scheduler priority.
13864 switch (priorityLevel) {
13865 case ImmediatePriority:
13866 expirationTime = Sync;
13867 break;
13868
13869 case UserBlockingPriority:
13870 // TODO: Rename this to computeUserBlockingExpiration
13871 expirationTime = computeInteractiveExpiration(currentTime);
13872 break;
13873
13874 case NormalPriority:
13875 case LowPriority:
13876 // TODO: Handle LowPriority
13877 // TODO: Rename this to... something better.
13878 expirationTime = computeAsyncExpiration(currentTime);
13879 break;
13880
13881 case IdlePriority:
13882 expirationTime = Idle;
13883 break;
13884
13885 default:
13886 {
13887 {
13888 throw Error("Expected a valid priority level");
13889 }
13890 }
13891
13892 }
13893 } // If we're in the middle of rendering a tree, do not update at the same
13894 // expiration time that is already rendering.
13895 // TODO: We shouldn't have to do this if the update is on a different root.
13896 // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
13897 // the root when we check for this condition.
13898
13899
13900 if (workInProgressRoot !== null && expirationTime === renderExpirationTime) {
13901 // This is a trick to move this update into a separate batch
13902 expirationTime -= 1;
13903 }
13904
13905 return expirationTime;
13906}
13907function scheduleUpdateOnFiber(fiber, expirationTime) {
13908 checkForNestedUpdates();
13909 warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber);
13910 var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
13911
13912 if (root === null) {
13913 warnAboutUpdateOnUnmountedFiberInDEV(fiber);
13914 return;
13915 }
13916
13917 checkForInterruption(fiber, expirationTime);
13918 recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
13919 // priority as an argument to that function and this one.
13920
13921 var priorityLevel = getCurrentPriorityLevel();
13922
13923 if (expirationTime === Sync) {
13924 if ( // Check if we're inside unbatchedUpdates
13925 (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
13926 (executionContext & (RenderContext | CommitContext)) === NoContext) {
13927 // Register pending interactions on the root to avoid losing traced interaction data.
13928 schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
13929 // root inside of batchedUpdates should be synchronous, but layout updates
13930 // should be deferred until the end of the batch.
13931
13932 performSyncWorkOnRoot(root);
13933 } else {
13934 ensureRootIsScheduled(root);
13935 schedulePendingInteractions(root, expirationTime);
13936
13937 if (executionContext === NoContext) {
13938 // Flush the synchronous work now, unless we're already working or inside
13939 // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
13940 // scheduleCallbackForFiber to preserve the ability to schedule a callback
13941 // without immediately flushing it. We only do this for user-initiated
13942 // updates, to preserve historical behavior of legacy mode.
13943 flushSyncCallbackQueue();
13944 }
13945 }
13946 } else {
13947 ensureRootIsScheduled(root);
13948 schedulePendingInteractions(root, expirationTime);
13949 }
13950
13951 if ((executionContext & DiscreteEventContext) !== NoContext && ( // Only updates at user-blocking priority or greater are considered
13952 // discrete, even inside a discrete event.
13953 priorityLevel === UserBlockingPriority || priorityLevel === ImmediatePriority)) {
13954 // This is the result of a discrete event. Track the lowest priority
13955 // discrete update per root so we can flush them early, if needed.
13956 if (rootsWithPendingDiscreteUpdates === null) {
13957 rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
13958 } else {
13959 var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
13960
13961 if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
13962 rootsWithPendingDiscreteUpdates.set(root, expirationTime);
13963 }
13964 }
13965 }
13966}
13967var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
13968// work without treating it as a typical update that originates from an event;
13969// e.g. retrying a Suspense boundary isn't an update, but it does schedule work
13970// on a fiber.
13971
13972function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
13973 // Update the source fiber's expiration time
13974 if (fiber.expirationTime < expirationTime) {
13975 fiber.expirationTime = expirationTime;
13976 }
13977
13978 var alternate = fiber.alternate;
13979
13980 if (alternate !== null && alternate.expirationTime < expirationTime) {
13981 alternate.expirationTime = expirationTime;
13982 } // Walk the parent path to the root and update the child expiration time.
13983
13984
13985 var node = fiber.return;
13986 var root = null;
13987
13988 if (node === null && fiber.tag === HostRoot) {
13989 root = fiber.stateNode;
13990 } else {
13991 while (node !== null) {
13992 alternate = node.alternate;
13993
13994 if (node.childExpirationTime < expirationTime) {
13995 node.childExpirationTime = expirationTime;
13996
13997 if (alternate !== null && alternate.childExpirationTime < expirationTime) {
13998 alternate.childExpirationTime = expirationTime;
13999 }
14000 } else if (alternate !== null && alternate.childExpirationTime < expirationTime) {
14001 alternate.childExpirationTime = expirationTime;
14002 }
14003
14004 if (node.return === null && node.tag === HostRoot) {
14005 root = node.stateNode;
14006 break;
14007 }
14008
14009 node = node.return;
14010 }
14011 }
14012
14013 if (root !== null) {
14014 if (workInProgressRoot === root) {
14015 // Received an update to a tree that's in the middle of rendering. Mark
14016 // that's unprocessed work on this root.
14017 markUnprocessedUpdateTime(expirationTime);
14018
14019 if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
14020 // The root already suspended with a delay, which means this render
14021 // definitely won't finish. Since we have a new update, let's mark it as
14022 // suspended now, right before marking the incoming update. This has the
14023 // effect of interrupting the current render and switching to the update.
14024 // TODO: This happens to work when receiving an update during the render
14025 // phase, because of the trick inside computeExpirationForFiber to
14026 // subtract 1 from `renderExpirationTime` to move it into a
14027 // separate bucket. But we should probably model it with an exception,
14028 // using the same mechanism we use to force hydration of a subtree.
14029 // TODO: This does not account for low pri updates that were already
14030 // scheduled before the root started rendering. Need to track the next
14031 // pending expiration time (perhaps by backtracking the return path) and
14032 // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
14033 markRootSuspendedAtTime(root, renderExpirationTime);
14034 }
14035 } // Mark that the root has a pending update.
14036
14037
14038 markRootUpdatedAtTime(root, expirationTime);
14039 }
14040
14041 return root;
14042}
14043
14044function getNextRootExpirationTimeToWorkOn(root) {
14045 // Determines the next expiration time that the root should render, taking
14046 // into account levels that may be suspended, or levels that may have
14047 // received a ping.
14048 var lastExpiredTime = root.lastExpiredTime;
14049
14050 if (lastExpiredTime !== NoWork) {
14051 return lastExpiredTime;
14052 } // "Pending" refers to any update that hasn't committed yet, including if it
14053 // suspended. The "suspended" range is therefore a subset.
14054
14055
14056 var firstPendingTime = root.firstPendingTime;
14057
14058 if (!isRootSuspendedAtTime(root, firstPendingTime)) {
14059 // The highest priority pending time is not suspended. Let's work on that.
14060 return firstPendingTime;
14061 } // If the first pending time is suspended, check if there's a lower priority
14062 // pending level that we know about. Or check if we received a ping. Work
14063 // on whichever is higher priority.
14064
14065
14066 var lastPingedTime = root.lastPingedTime;
14067 var nextKnownPendingLevel = root.nextKnownPendingLevel;
14068 return lastPingedTime > nextKnownPendingLevel ? lastPingedTime : nextKnownPendingLevel;
14069} // Use this function to schedule a task for a root. There's only one task per
14070// root; if a task was already scheduled, we'll check to make sure the
14071// expiration time of the existing task is the same as the expiration time of
14072// the next level that the root has work on. This function is called on every
14073// update, and right before exiting a task.
14074
14075
14076function ensureRootIsScheduled(root) {
14077 var lastExpiredTime = root.lastExpiredTime;
14078
14079 if (lastExpiredTime !== NoWork) {
14080 // Special case: Expired work should flush synchronously.
14081 root.callbackExpirationTime = Sync;
14082 root.callbackPriority = ImmediatePriority;
14083 root.callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
14084 return;
14085 }
14086
14087 var expirationTime = getNextRootExpirationTimeToWorkOn(root);
14088 var existingCallbackNode = root.callbackNode;
14089
14090 if (expirationTime === NoWork) {
14091 // There's nothing to work on.
14092 if (existingCallbackNode !== null) {
14093 root.callbackNode = null;
14094 root.callbackExpirationTime = NoWork;
14095 root.callbackPriority = NoPriority;
14096 }
14097
14098 return;
14099 } // TODO: If this is an update, we already read the current time. Pass the
14100 // time as an argument.
14101
14102
14103 var currentTime = requestCurrentTimeForUpdate();
14104 var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime); // If there's an existing render task, confirm it has the correct priority and
14105 // expiration time. Otherwise, we'll cancel it and schedule a new one.
14106
14107 if (existingCallbackNode !== null) {
14108 var existingCallbackPriority = root.callbackPriority;
14109 var existingCallbackExpirationTime = root.callbackExpirationTime;
14110
14111 if ( // Callback must have the exact same expiration time.
14112 existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
14113 existingCallbackPriority >= priorityLevel) {
14114 // Existing callback is sufficient.
14115 return;
14116 } // Need to schedule a new task.
14117 // TODO: Instead of scheduling a new task, we should be able to change the
14118 // priority of the existing one.
14119
14120
14121 cancelCallback(existingCallbackNode);
14122 }
14123
14124 root.callbackExpirationTime = expirationTime;
14125 root.callbackPriority = priorityLevel;
14126 var callbackNode;
14127
14128 if (expirationTime === Sync) {
14129 // Sync React callbacks are scheduled on a special internal queue
14130 callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
14131 } else if (disableSchedulerTimeoutBasedOnReactExpirationTime) {
14132 callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root));
14133 } else {
14134 callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
14135 // ordering because tasks are processed in timeout order.
14136 {
14137 timeout: expirationTimeToMs(expirationTime) - now()
14138 });
14139 }
14140
14141 root.callbackNode = callbackNode;
14142} // This is the entry point for every concurrent task, i.e. anything that
14143// goes through Scheduler.
14144
14145
14146function performConcurrentWorkOnRoot(root, didTimeout) {
14147 // Since we know we're in a React event, we can clear the current
14148 // event time. The next update will compute a new event time.
14149 currentEventTime = NoWork;
14150
14151 if (didTimeout) {
14152 // The render task took too long to complete. Mark the current time as
14153 // expired to synchronously render all expired work in a single batch.
14154 var currentTime = requestCurrentTimeForUpdate();
14155 markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
14156
14157 ensureRootIsScheduled(root);
14158 return null;
14159 } // Determine the next expiration time to work on, using the fields stored
14160 // on the root.
14161
14162
14163 var expirationTime = getNextRootExpirationTimeToWorkOn(root);
14164
14165 if (expirationTime !== NoWork) {
14166 var originalCallbackNode = root.callbackNode;
14167
14168 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
14169 {
14170 throw Error("Should not already be working.");
14171 }
14172 }
14173
14174 flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
14175 // and prepare a fresh one. Otherwise we'll continue where we left off.
14176
14177 if (root !== workInProgressRoot || expirationTime !== renderExpirationTime) {
14178 prepareFreshStack(root, expirationTime);
14179 startWorkOnPendingInteractions(root, expirationTime);
14180 } // If we have a work-in-progress fiber, it means there's still work to do
14181 // in this root.
14182
14183
14184 if (workInProgress !== null) {
14185 var prevExecutionContext = executionContext;
14186 executionContext |= RenderContext;
14187 var prevDispatcher = pushDispatcher(root);
14188 var prevInteractions = pushInteractions(root);
14189 startWorkLoopTimer(workInProgress);
14190
14191 do {
14192 try {
14193 workLoopConcurrent();
14194 break;
14195 } catch (thrownValue) {
14196 handleError(root, thrownValue);
14197 }
14198 } while (true);
14199
14200 resetContextDependencies();
14201 executionContext = prevExecutionContext;
14202 popDispatcher(prevDispatcher);
14203
14204 if (enableSchedulerTracing) {
14205 popInteractions(prevInteractions);
14206 }
14207
14208 if (workInProgressRootExitStatus === RootFatalErrored) {
14209 var fatalError = workInProgressRootFatalError;
14210 stopInterruptedWorkLoopTimer();
14211 prepareFreshStack(root, expirationTime);
14212 markRootSuspendedAtTime(root, expirationTime);
14213 ensureRootIsScheduled(root);
14214 throw fatalError;
14215 }
14216
14217 if (workInProgress !== null) {
14218 // There's still work left over. Exit without committing.
14219 stopInterruptedWorkLoopTimer();
14220 } else {
14221 // We now have a consistent tree. The next step is either to commit it,
14222 // or, if something suspended, wait to commit it after a timeout.
14223 stopFinishedWorkLoopTimer();
14224 var finishedWork = root.finishedWork = root.current.alternate;
14225 root.finishedExpirationTime = expirationTime;
14226 finishConcurrentRender(root, finishedWork, workInProgressRootExitStatus, expirationTime);
14227 }
14228
14229 ensureRootIsScheduled(root);
14230
14231 if (root.callbackNode === originalCallbackNode) {
14232 // The task node scheduled for this root is the same one that's
14233 // currently executed. Need to return a continuation.
14234 return performConcurrentWorkOnRoot.bind(null, root);
14235 }
14236 }
14237 }
14238
14239 return null;
14240}
14241
14242function finishConcurrentRender(root, finishedWork, exitStatus, expirationTime) {
14243 // Set this to null to indicate there's no in-progress render.
14244 workInProgressRoot = null;
14245
14246 switch (exitStatus) {
14247 case RootIncomplete:
14248 case RootFatalErrored:
14249 {
14250 {
14251 {
14252 throw Error("Root did not complete. This is a bug in React.");
14253 }
14254 }
14255 }
14256 // Flow knows about invariant, so it complains if I add a break
14257 // statement, but eslint doesn't know about invariant, so it complains
14258 // if I do. eslint-disable-next-line no-fallthrough
14259
14260 case RootErrored:
14261 {
14262 // If this was an async render, the error may have happened due to
14263 // a mutation in a concurrent event. Try rendering one more time,
14264 // synchronously, to see if the error goes away. If there are
14265 // lower priority updates, let's include those, too, in case they
14266 // fix the inconsistency. Render at Idle to include all updates.
14267 // If it was Idle or Never or some not-yet-invented time, render
14268 // at that time.
14269 markRootExpiredAtTime(root, expirationTime > Idle ? Idle : expirationTime); // We assume that this second render pass will be synchronous
14270 // and therefore not hit this path again.
14271
14272 break;
14273 }
14274
14275 case RootSuspended:
14276 {
14277 markRootSuspendedAtTime(root, expirationTime);
14278 var lastSuspendedTime = root.lastSuspendedTime;
14279
14280 if (expirationTime === lastSuspendedTime) {
14281 root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
14282 }
14283
14284 flushSuspensePriorityWarningInDEV(); // We have an acceptable loading state. We need to figure out if we
14285 // should immediately commit it or wait a bit.
14286 // If we have processed new updates during this render, we may now
14287 // have a new loading state ready. We want to ensure that we commit
14288 // that as soon as possible.
14289
14290 var hasNotProcessedNewUpdates = workInProgressRootLatestProcessedExpirationTime === Sync;
14291
14292 if (hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
14293 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current)) {
14294 // If we have not processed any new updates during this pass, then
14295 // this is either a retry of an existing fallback state or a
14296 // hidden tree. Hidden trees shouldn't be batched with other work
14297 // and after that's fixed it can only be a retry. We're going to
14298 // throttle committing retries so that we don't show too many
14299 // loading states too quickly.
14300 var msUntilTimeout = globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
14301
14302 if (msUntilTimeout > 10) {
14303 if (workInProgressRootHasPendingPing) {
14304 var lastPingedTime = root.lastPingedTime;
14305
14306 if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
14307 // This render was pinged but we didn't get to restart
14308 // earlier so try restarting now instead.
14309 root.lastPingedTime = expirationTime;
14310 prepareFreshStack(root, expirationTime);
14311 break;
14312 }
14313 }
14314
14315 var nextTime = getNextRootExpirationTimeToWorkOn(root);
14316
14317 if (nextTime !== NoWork && nextTime !== expirationTime) {
14318 // There's additional work on this root.
14319 break;
14320 }
14321
14322 if (lastSuspendedTime !== NoWork && lastSuspendedTime !== expirationTime) {
14323 // We should prefer to render the fallback of at the last
14324 // suspended level. Ping the last suspended level to try
14325 // rendering it again.
14326 root.lastPingedTime = lastSuspendedTime;
14327 break;
14328 } // The render is suspended, it hasn't timed out, and there's no
14329 // lower priority work to do. Instead of committing the fallback
14330 // immediately, wait for more data to arrive.
14331
14332
14333 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), msUntilTimeout);
14334 break;
14335 }
14336 } // The work expired. Commit immediately.
14337
14338
14339 commitRoot(root);
14340 break;
14341 }
14342
14343 case RootSuspendedWithDelay:
14344 {
14345 markRootSuspendedAtTime(root, expirationTime);
14346 var _lastSuspendedTime = root.lastSuspendedTime;
14347
14348 if (expirationTime === _lastSuspendedTime) {
14349 root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
14350 }
14351
14352 flushSuspensePriorityWarningInDEV();
14353
14354 if ( // do not delay if we're inside an act() scope
14355 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current)) {
14356 // We're suspended in a state that should be avoided. We'll try to
14357 // avoid committing it for as long as the timeouts let us.
14358 if (workInProgressRootHasPendingPing) {
14359 var _lastPingedTime = root.lastPingedTime;
14360
14361 if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
14362 // This render was pinged but we didn't get to restart earlier
14363 // so try restarting now instead.
14364 root.lastPingedTime = expirationTime;
14365 prepareFreshStack(root, expirationTime);
14366 break;
14367 }
14368 }
14369
14370 var _nextTime = getNextRootExpirationTimeToWorkOn(root);
14371
14372 if (_nextTime !== NoWork && _nextTime !== expirationTime) {
14373 // There's additional work on this root.
14374 break;
14375 }
14376
14377 if (_lastSuspendedTime !== NoWork && _lastSuspendedTime !== expirationTime) {
14378 // We should prefer to render the fallback of at the last
14379 // suspended level. Ping the last suspended level to try
14380 // rendering it again.
14381 root.lastPingedTime = _lastSuspendedTime;
14382 break;
14383 }
14384
14385 var _msUntilTimeout;
14386
14387 if (workInProgressRootLatestSuspenseTimeout !== Sync) {
14388 // We have processed a suspense config whose expiration time we
14389 // can use as the timeout.
14390 _msUntilTimeout = expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
14391 } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
14392 // This should never normally happen because only new updates
14393 // cause delayed states, so we should have processed something.
14394 // However, this could also happen in an offscreen tree.
14395 _msUntilTimeout = 0;
14396 } else {
14397 // If we don't have a suspense config, we're going to use a
14398 // heuristic to determine how long we can suspend.
14399 var eventTimeMs = inferTimeFromExpirationTime(workInProgressRootLatestProcessedExpirationTime);
14400 var currentTimeMs = now();
14401 var timeUntilExpirationMs = expirationTimeToMs(expirationTime) - currentTimeMs;
14402 var timeElapsed = currentTimeMs - eventTimeMs;
14403
14404 if (timeElapsed < 0) {
14405 // We get this wrong some time since we estimate the time.
14406 timeElapsed = 0;
14407 }
14408
14409 _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
14410 // event time is exact instead of inferred from expiration time
14411 // we don't need this.
14412
14413 if (timeUntilExpirationMs < _msUntilTimeout) {
14414 _msUntilTimeout = timeUntilExpirationMs;
14415 }
14416 } // Don't bother with a very short suspense time.
14417
14418
14419 if (_msUntilTimeout > 10) {
14420 // The render is suspended, it hasn't timed out, and there's no
14421 // lower priority work to do. Instead of committing the fallback
14422 // immediately, wait for more data to arrive.
14423 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout);
14424 break;
14425 }
14426 } // The work expired. Commit immediately.
14427
14428
14429 commitRoot(root);
14430 break;
14431 }
14432
14433 case RootCompleted:
14434 {
14435 // The work completed. Ready to commit.
14436 if ( // do not delay if we're inside an act() scope
14437 !(true && flushSuspenseFallbacksInTests && IsThisRendererActing.current) && workInProgressRootLatestProcessedExpirationTime !== Sync && workInProgressRootCanSuspendUsingConfig !== null) {
14438 // If we have exceeded the minimum loading delay, which probably
14439 // means we have shown a spinner already, we might have to suspend
14440 // a bit longer to ensure that the spinner is shown for
14441 // enough time.
14442 var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(workInProgressRootLatestProcessedExpirationTime, expirationTime, workInProgressRootCanSuspendUsingConfig);
14443
14444 if (_msUntilTimeout2 > 10) {
14445 markRootSuspendedAtTime(root, expirationTime);
14446 root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout2);
14447 break;
14448 }
14449 }
14450
14451 commitRoot(root);
14452 break;
14453 }
14454
14455 default:
14456 {
14457 {
14458 {
14459 throw Error("Unknown root exit status.");
14460 }
14461 }
14462 }
14463 }
14464} // This is the entry point for synchronous tasks that don't go
14465// through Scheduler
14466
14467
14468function performSyncWorkOnRoot(root) {
14469 // Check if there's expired work on this root. Otherwise, render at Sync.
14470 var lastExpiredTime = root.lastExpiredTime;
14471 var expirationTime = lastExpiredTime !== NoWork ? lastExpiredTime : Sync;
14472
14473 if (root.finishedExpirationTime === expirationTime) {
14474 // There's already a pending commit at this expiration time.
14475 // TODO: This is poorly factored. This case only exists for the
14476 // batch.commit() API.
14477 commitRoot(root);
14478 } else {
14479 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
14480 {
14481 throw Error("Should not already be working.");
14482 }
14483 }
14484
14485 flushPassiveEffects(); // If the root or expiration time have changed, throw out the existing stack
14486 // and prepare a fresh one. Otherwise we'll continue where we left off.
14487
14488 if (root !== workInProgressRoot || expirationTime !== renderExpirationTime) {
14489 prepareFreshStack(root, expirationTime);
14490 startWorkOnPendingInteractions(root, expirationTime);
14491 } // If we have a work-in-progress fiber, it means there's still work to do
14492 // in this root.
14493
14494
14495 if (workInProgress !== null) {
14496 var prevExecutionContext = executionContext;
14497 executionContext |= RenderContext;
14498 var prevDispatcher = pushDispatcher(root);
14499 var prevInteractions = pushInteractions(root);
14500 startWorkLoopTimer(workInProgress);
14501
14502 do {
14503 try {
14504 workLoopSync();
14505 break;
14506 } catch (thrownValue) {
14507 handleError(root, thrownValue);
14508 }
14509 } while (true);
14510
14511 resetContextDependencies();
14512 executionContext = prevExecutionContext;
14513 popDispatcher(prevDispatcher);
14514
14515 if (enableSchedulerTracing) {
14516 popInteractions(prevInteractions);
14517 }
14518
14519 if (workInProgressRootExitStatus === RootFatalErrored) {
14520 var fatalError = workInProgressRootFatalError;
14521 stopInterruptedWorkLoopTimer();
14522 prepareFreshStack(root, expirationTime);
14523 markRootSuspendedAtTime(root, expirationTime);
14524 ensureRootIsScheduled(root);
14525 throw fatalError;
14526 }
14527
14528 if (workInProgress !== null) {
14529 // This is a sync render, so we should have finished the whole tree.
14530 {
14531 {
14532 throw Error("Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue.");
14533 }
14534 }
14535 } else {
14536 // We now have a consistent tree. Because this is a sync render, we
14537 // will commit it even if something suspended.
14538 stopFinishedWorkLoopTimer();
14539 root.finishedWork = root.current.alternate;
14540 root.finishedExpirationTime = expirationTime;
14541 finishSyncRender(root, workInProgressRootExitStatus, expirationTime);
14542 } // Before exiting, make sure there's a callback scheduled for the next
14543 // pending level.
14544
14545
14546 ensureRootIsScheduled(root);
14547 }
14548 }
14549
14550 return null;
14551}
14552
14553function finishSyncRender(root, exitStatus, expirationTime) {
14554 // Set this to null to indicate there's no in-progress render.
14555 workInProgressRoot = null;
14556
14557 {
14558 if (exitStatus === RootSuspended || exitStatus === RootSuspendedWithDelay) {
14559 flushSuspensePriorityWarningInDEV();
14560 }
14561 }
14562
14563 commitRoot(root);
14564}
14565
14566
14567
14568
14569function syncUpdates(fn, a, b, c) {
14570 return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
14571}
14572
14573function batchedUpdates(fn, a) {
14574 var prevExecutionContext = executionContext;
14575 executionContext |= BatchedContext;
14576
14577 try {
14578 return fn(a);
14579 } finally {
14580 executionContext = prevExecutionContext;
14581
14582 if (executionContext === NoContext) {
14583 // Flush the immediate callbacks that were scheduled during this batch
14584 flushSyncCallbackQueue();
14585 }
14586 }
14587}
14588
14589
14590
14591function flushSync(fn, a) {
14592 if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
14593 {
14594 {
14595 throw Error("flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.");
14596 }
14597 }
14598 }
14599
14600 var prevExecutionContext = executionContext;
14601 executionContext |= BatchedContext;
14602
14603 try {
14604 return runWithPriority(ImmediatePriority, fn.bind(null, a));
14605 } finally {
14606 executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
14607 // Note that this will happen even if batchedUpdates is higher up
14608 // the stack.
14609
14610 flushSyncCallbackQueue();
14611 }
14612}
14613
14614
14615function prepareFreshStack(root, expirationTime) {
14616 root.finishedWork = null;
14617 root.finishedExpirationTime = NoWork;
14618 var timeoutHandle = root.timeoutHandle;
14619
14620 if (timeoutHandle !== noTimeout) {
14621 // The root previous suspended and scheduled a timeout to commit a fallback
14622 // state. Now that we have additional work, cancel the timeout.
14623 root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
14624
14625 cancelTimeout(timeoutHandle);
14626 }
14627
14628 if (workInProgress !== null) {
14629 var interruptedWork = workInProgress.return;
14630
14631 while (interruptedWork !== null) {
14632 unwindInterruptedWork(interruptedWork);
14633 interruptedWork = interruptedWork.return;
14634 }
14635 }
14636
14637 workInProgressRoot = root;
14638 workInProgress = createWorkInProgress(root.current, null, expirationTime);
14639 renderExpirationTime = expirationTime;
14640 workInProgressRootExitStatus = RootIncomplete;
14641 workInProgressRootFatalError = null;
14642 workInProgressRootLatestProcessedExpirationTime = Sync;
14643 workInProgressRootLatestSuspenseTimeout = Sync;
14644 workInProgressRootCanSuspendUsingConfig = null;
14645 workInProgressRootNextUnprocessedUpdateTime = NoWork;
14646 workInProgressRootHasPendingPing = false;
14647
14648 if (enableSchedulerTracing) {
14649 spawnedWorkDuringRender = null;
14650 }
14651
14652 {
14653 ReactStrictModeWarnings.discardPendingWarnings();
14654 componentsThatTriggeredHighPriSuspend = null;
14655 }
14656}
14657
14658function handleError(root, thrownValue) {
14659 do {
14660 try {
14661 // Reset module-level state that was set during the render phase.
14662 resetContextDependencies();
14663 resetHooks();
14664 resetCurrentFiber();
14665
14666 if (workInProgress === null || workInProgress.return === null) {
14667 // Expected to be working on a non-root fiber. This is a fatal error
14668 // because there's no ancestor that can handle it; the root is
14669 // supposed to capture all errors that weren't caught by an error
14670 // boundary.
14671 workInProgressRootExitStatus = RootFatalErrored;
14672 workInProgressRootFatalError = thrownValue;
14673 return null;
14674 }
14675
14676 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
14677 // Record the time spent rendering before an error was thrown. This
14678 // avoids inaccurate Profiler durations in the case of a
14679 // suspended render.
14680 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
14681 }
14682
14683 throwException(root, workInProgress.return, workInProgress, thrownValue, renderExpirationTime);
14684 workInProgress = completeUnitOfWork(workInProgress);
14685 } catch (yetAnotherThrownValue) {
14686 // Something in the return path also threw.
14687 thrownValue = yetAnotherThrownValue;
14688 continue;
14689 } // Return to the normal work loop.
14690
14691
14692 return;
14693 } while (true);
14694}
14695
14696function pushDispatcher(root) {
14697 var prevDispatcher = ReactCurrentDispatcher.current;
14698 ReactCurrentDispatcher.current = ContextOnlyDispatcher;
14699
14700 if (prevDispatcher === null) {
14701 // The React isomorphic package does not include a default dispatcher.
14702 // Instead the first renderer will lazily attach one, in order to give
14703 // nicer error messages.
14704 return ContextOnlyDispatcher;
14705 } else {
14706 return prevDispatcher;
14707 }
14708}
14709
14710function popDispatcher(prevDispatcher) {
14711 ReactCurrentDispatcher.current = prevDispatcher;
14712}
14713
14714function pushInteractions(root) {
14715 if (enableSchedulerTracing) {
14716 var prevInteractions = __interactionsRef.current;
14717 __interactionsRef.current = root.memoizedInteractions;
14718 return prevInteractions;
14719 }
14720
14721 return null;
14722}
14723
14724function popInteractions(prevInteractions) {
14725 if (enableSchedulerTracing) {
14726 __interactionsRef.current = prevInteractions;
14727 }
14728}
14729
14730function markCommitTimeOfFallback() {
14731 globalMostRecentFallbackTime = now();
14732}
14733function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
14734 if (expirationTime < workInProgressRootLatestProcessedExpirationTime && expirationTime > Idle) {
14735 workInProgressRootLatestProcessedExpirationTime = expirationTime;
14736 }
14737
14738 if (suspenseConfig !== null) {
14739 if (expirationTime < workInProgressRootLatestSuspenseTimeout && expirationTime > Idle) {
14740 workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
14741
14742 workInProgressRootCanSuspendUsingConfig = suspenseConfig;
14743 }
14744 }
14745}
14746function markUnprocessedUpdateTime(expirationTime) {
14747 if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
14748 workInProgressRootNextUnprocessedUpdateTime = expirationTime;
14749 }
14750}
14751function renderDidSuspend() {
14752 if (workInProgressRootExitStatus === RootIncomplete) {
14753 workInProgressRootExitStatus = RootSuspended;
14754 }
14755}
14756function renderDidSuspendDelayIfPossible() {
14757 if (workInProgressRootExitStatus === RootIncomplete || workInProgressRootExitStatus === RootSuspended) {
14758 workInProgressRootExitStatus = RootSuspendedWithDelay;
14759 } // Check if there's a lower priority update somewhere else in the tree.
14760
14761
14762 if (workInProgressRootNextUnprocessedUpdateTime !== NoWork && workInProgressRoot !== null) {
14763 // Mark the current render as suspended, and then mark that there's a
14764 // pending update.
14765 // TODO: This should immediately interrupt the current render, instead
14766 // of waiting until the next time we yield.
14767 markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime);
14768 markRootUpdatedAtTime(workInProgressRoot, workInProgressRootNextUnprocessedUpdateTime);
14769 }
14770}
14771function renderDidError() {
14772 if (workInProgressRootExitStatus !== RootCompleted) {
14773 workInProgressRootExitStatus = RootErrored;
14774 }
14775} // Called during render to determine if anything has suspended.
14776// Returns false if we're not sure.
14777
14778function renderHasNotSuspendedYet() {
14779 // If something errored or completed, we can't really be sure,
14780 // so those are false.
14781 return workInProgressRootExitStatus === RootIncomplete;
14782}
14783
14784function inferTimeFromExpirationTime(expirationTime) {
14785 // We don't know exactly when the update was scheduled, but we can infer an
14786 // approximate start time from the expiration time.
14787 var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
14788 return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
14789}
14790
14791function inferTimeFromExpirationTimeWithSuspenseConfig(expirationTime, suspenseConfig) {
14792 // We don't know exactly when the update was scheduled, but we can infer an
14793 // approximate start time from the expiration time by subtracting the timeout
14794 // that was added to the event time.
14795 var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
14796 return earliestExpirationTimeMs - (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION);
14797} // The work loop is an extremely hot path. Tell Closure not to inline it.
14798
14799/** @noinline */
14800
14801
14802function workLoopSync() {
14803 // Already timed out, so perform work without checking if we need to yield.
14804 while (workInProgress !== null) {
14805 workInProgress = performUnitOfWork(workInProgress);
14806 }
14807}
14808/** @noinline */
14809
14810
14811function workLoopConcurrent() {
14812 // Perform work until Scheduler asks us to yield
14813 while (workInProgress !== null && !shouldYield()) {
14814 workInProgress = performUnitOfWork(workInProgress);
14815 }
14816}
14817
14818function performUnitOfWork(unitOfWork) {
14819 // The current, flushed, state of this fiber is the alternate. Ideally
14820 // nothing should rely on this, but relying on it here means that we don't
14821 // need an additional field on the work in progress.
14822 var current$$1 = unitOfWork.alternate;
14823 startWorkTimer(unitOfWork);
14824 setCurrentFiber(unitOfWork);
14825 var next;
14826
14827 if (enableProfilerTimer && (unitOfWork.mode & ProfileMode) !== NoMode) {
14828 startProfilerTimer(unitOfWork);
14829 next = beginWork$$1(current$$1, unitOfWork, renderExpirationTime);
14830 stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
14831 } else {
14832 next = beginWork$$1(current$$1, unitOfWork, renderExpirationTime);
14833 }
14834
14835 resetCurrentFiber();
14836 unitOfWork.memoizedProps = unitOfWork.pendingProps;
14837
14838 if (next === null) {
14839 // If this doesn't spawn new work, complete the current work.
14840 next = completeUnitOfWork(unitOfWork);
14841 }
14842
14843 ReactCurrentOwner$1.current = null;
14844 return next;
14845}
14846
14847function completeUnitOfWork(unitOfWork) {
14848 // Attempt to complete the current unit of work, then move to the next
14849 // sibling. If there are no more siblings, return to the parent fiber.
14850 workInProgress = unitOfWork;
14851
14852 do {
14853 // The current, flushed, state of this fiber is the alternate. Ideally
14854 // nothing should rely on this, but relying on it here means that we don't
14855 // need an additional field on the work in progress.
14856 var current$$1 = workInProgress.alternate;
14857 var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
14858
14859 if ((workInProgress.effectTag & Incomplete) === NoEffect) {
14860 setCurrentFiber(workInProgress);
14861 var next = void 0;
14862
14863 if (!enableProfilerTimer || (workInProgress.mode & ProfileMode) === NoMode) {
14864 next = completeWork(current$$1, workInProgress, renderExpirationTime);
14865 } else {
14866 startProfilerTimer(workInProgress);
14867 next = completeWork(current$$1, workInProgress, renderExpirationTime); // Update render duration assuming we didn't error.
14868
14869 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
14870 }
14871
14872 stopWorkTimer(workInProgress);
14873 resetCurrentFiber();
14874 resetChildExpirationTime(workInProgress);
14875
14876 if (next !== null) {
14877 // Completing this fiber spawned new work. Work on that next.
14878 return next;
14879 }
14880
14881 if (returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
14882 (returnFiber.effectTag & Incomplete) === NoEffect) {
14883 // Append all the effects of the subtree and this fiber onto the effect
14884 // list of the parent. The completion order of the children affects the
14885 // side-effect order.
14886 if (returnFiber.firstEffect === null) {
14887 returnFiber.firstEffect = workInProgress.firstEffect;
14888 }
14889
14890 if (workInProgress.lastEffect !== null) {
14891 if (returnFiber.lastEffect !== null) {
14892 returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
14893 }
14894
14895 returnFiber.lastEffect = workInProgress.lastEffect;
14896 } // If this fiber had side-effects, we append it AFTER the children's
14897 // side-effects. We can perform certain side-effects earlier if needed,
14898 // by doing multiple passes over the effect list. We don't want to
14899 // schedule our own side-effect on our own list because if end up
14900 // reusing children we'll schedule this effect onto itself since we're
14901 // at the end.
14902
14903
14904 var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
14905 // list. PerformedWork effect is read by React DevTools but shouldn't be
14906 // committed.
14907
14908 if (effectTag > PerformedWork) {
14909 if (returnFiber.lastEffect !== null) {
14910 returnFiber.lastEffect.nextEffect = workInProgress;
14911 } else {
14912 returnFiber.firstEffect = workInProgress;
14913 }
14914
14915 returnFiber.lastEffect = workInProgress;
14916 }
14917 }
14918 } else {
14919 // This fiber did not complete because something threw. Pop values off
14920 // the stack without entering the complete phase. If this is a boundary,
14921 // capture values if possible.
14922 var _next = unwindWork(workInProgress, renderExpirationTime); // Because this fiber did not complete, don't reset its expiration time.
14923
14924
14925 if (enableProfilerTimer && (workInProgress.mode & ProfileMode) !== NoMode) {
14926 // Record the render duration for the fiber that errored.
14927 stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
14928
14929 var actualDuration = workInProgress.actualDuration;
14930 var child = workInProgress.child;
14931
14932 while (child !== null) {
14933 actualDuration += child.actualDuration;
14934 child = child.sibling;
14935 }
14936
14937 workInProgress.actualDuration = actualDuration;
14938 }
14939
14940 if (_next !== null) {
14941 // If completing this work spawned new work, do that next. We'll come
14942 // back here again.
14943 // Since we're restarting, remove anything that is not a host effect
14944 // from the effect tag.
14945 // TODO: The name stopFailedWorkTimer is misleading because Suspense
14946 // also captures and restarts.
14947 stopFailedWorkTimer(workInProgress);
14948 _next.effectTag &= HostEffectMask;
14949 return _next;
14950 }
14951
14952 stopWorkTimer(workInProgress);
14953
14954 if (returnFiber !== null) {
14955 // Mark the parent fiber as incomplete and clear its effect list.
14956 returnFiber.firstEffect = returnFiber.lastEffect = null;
14957 returnFiber.effectTag |= Incomplete;
14958 }
14959 }
14960
14961 var siblingFiber = workInProgress.sibling;
14962
14963 if (siblingFiber !== null) {
14964 // If there is more work to do in this returnFiber, do that next.
14965 return siblingFiber;
14966 } // Otherwise, return to the parent
14967
14968
14969 workInProgress = returnFiber;
14970 } while (workInProgress !== null); // We've reached the root.
14971
14972
14973 if (workInProgressRootExitStatus === RootIncomplete) {
14974 workInProgressRootExitStatus = RootCompleted;
14975 }
14976
14977 return null;
14978}
14979
14980function getRemainingExpirationTime(fiber) {
14981 var updateExpirationTime = fiber.expirationTime;
14982 var childExpirationTime = fiber.childExpirationTime;
14983 return updateExpirationTime > childExpirationTime ? updateExpirationTime : childExpirationTime;
14984}
14985
14986function resetChildExpirationTime(completedWork) {
14987 if (renderExpirationTime !== Never && completedWork.childExpirationTime === Never) {
14988 // The children of this component are hidden. Don't bubble their
14989 // expiration times.
14990 return;
14991 }
14992
14993 var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
14994
14995 if (enableProfilerTimer && (completedWork.mode & ProfileMode) !== NoMode) {
14996 // In profiling mode, resetChildExpirationTime is also used to reset
14997 // profiler durations.
14998 var actualDuration = completedWork.actualDuration;
14999 var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
15000 // only be updated if work is done on the fiber (i.e. it doesn't bailout).
15001 // When work is done, it should bubble to the parent's actualDuration. If
15002 // the fiber has not been cloned though, (meaning no work was done), then
15003 // this value will reflect the amount of time spent working on a previous
15004 // render. In that case it should not bubble. We determine whether it was
15005 // cloned by comparing the child pointer.
15006
15007 var shouldBubbleActualDurations = completedWork.alternate === null || completedWork.child !== completedWork.alternate.child;
15008 var child = completedWork.child;
15009
15010 while (child !== null) {
15011 var childUpdateExpirationTime = child.expirationTime;
15012 var childChildExpirationTime = child.childExpirationTime;
15013
15014 if (childUpdateExpirationTime > newChildExpirationTime) {
15015 newChildExpirationTime = childUpdateExpirationTime;
15016 }
15017
15018 if (childChildExpirationTime > newChildExpirationTime) {
15019 newChildExpirationTime = childChildExpirationTime;
15020 }
15021
15022 if (shouldBubbleActualDurations) {
15023 actualDuration += child.actualDuration;
15024 }
15025
15026 treeBaseDuration += child.treeBaseDuration;
15027 child = child.sibling;
15028 }
15029
15030 completedWork.actualDuration = actualDuration;
15031 completedWork.treeBaseDuration = treeBaseDuration;
15032 } else {
15033 var _child = completedWork.child;
15034
15035 while (_child !== null) {
15036 var _childUpdateExpirationTime = _child.expirationTime;
15037 var _childChildExpirationTime = _child.childExpirationTime;
15038
15039 if (_childUpdateExpirationTime > newChildExpirationTime) {
15040 newChildExpirationTime = _childUpdateExpirationTime;
15041 }
15042
15043 if (_childChildExpirationTime > newChildExpirationTime) {
15044 newChildExpirationTime = _childChildExpirationTime;
15045 }
15046
15047 _child = _child.sibling;
15048 }
15049 }
15050
15051 completedWork.childExpirationTime = newChildExpirationTime;
15052}
15053
15054function commitRoot(root) {
15055 var renderPriorityLevel = getCurrentPriorityLevel();
15056 runWithPriority(ImmediatePriority, commitRootImpl.bind(null, root, renderPriorityLevel));
15057 return null;
15058}
15059
15060function commitRootImpl(root, renderPriorityLevel) {
15061 do {
15062 // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
15063 // means `flushPassiveEffects` will sometimes result in additional
15064 // passive effects. So we need to keep flushing in a loop until there are
15065 // no more pending effects.
15066 // TODO: Might be better if `flushPassiveEffects` did not automatically
15067 // flush synchronous work at the end, to avoid factoring hazards like this.
15068 flushPassiveEffects();
15069 } while (rootWithPendingPassiveEffects !== null);
15070
15071 flushRenderPhaseStrictModeWarningsInDEV();
15072
15073 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
15074 {
15075 throw Error("Should not already be working.");
15076 }
15077 }
15078
15079 var finishedWork = root.finishedWork;
15080 var expirationTime = root.finishedExpirationTime;
15081
15082 if (finishedWork === null) {
15083 return null;
15084 }
15085
15086 root.finishedWork = null;
15087 root.finishedExpirationTime = NoWork;
15088
15089 if (!(finishedWork !== root.current)) {
15090 {
15091 throw Error("Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue.");
15092 }
15093 } // commitRoot never returns a continuation; it always finishes synchronously.
15094 // So we can clear these now to allow a new callback to be scheduled.
15095
15096
15097 root.callbackNode = null;
15098 root.callbackExpirationTime = NoWork;
15099 root.callbackPriority = NoPriority;
15100 root.nextKnownPendingLevel = NoWork;
15101 startCommitTimer(); // Update the first and last pending times on this root. The new first
15102 // pending time is whatever is left on the root fiber.
15103
15104 var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(finishedWork);
15105 markRootFinishedAtTime(root, expirationTime, remainingExpirationTimeBeforeCommit);
15106
15107 if (root === workInProgressRoot) {
15108 // We can reset these now that they are finished.
15109 workInProgressRoot = null;
15110 workInProgress = null;
15111 renderExpirationTime = NoWork;
15112 } else {} // This indicates that the last root we worked on is not the same one that
15113 // we're committing now. This most commonly happens when a suspended root
15114 // times out.
15115 // Get the list of effects.
15116
15117
15118 var firstEffect;
15119
15120 if (finishedWork.effectTag > PerformedWork) {
15121 // A fiber's effect list consists only of its children, not itself. So if
15122 // the root has an effect, we need to add it to the end of the list. The
15123 // resulting list is the set that would belong to the root's parent, if it
15124 // had one; that is, all the effects in the tree including the root.
15125 if (finishedWork.lastEffect !== null) {
15126 finishedWork.lastEffect.nextEffect = finishedWork;
15127 firstEffect = finishedWork.firstEffect;
15128 } else {
15129 firstEffect = finishedWork;
15130 }
15131 } else {
15132 // There is no effect on the root.
15133 firstEffect = finishedWork.firstEffect;
15134 }
15135
15136 if (firstEffect !== null) {
15137 var prevExecutionContext = executionContext;
15138 executionContext |= CommitContext;
15139 var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
15140
15141 ReactCurrentOwner$1.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
15142 // of the effect list for each phase: all mutation effects come before all
15143 // layout effects, and so on.
15144 // The first phase a "before mutation" phase. We use this phase to read the
15145 // state of the host tree right before we mutate it. This is where
15146 // getSnapshotBeforeUpdate is called.
15147
15148 startCommitSnapshotEffectsTimer();
15149 prepareForCommit(root.containerInfo);
15150 nextEffect = firstEffect;
15151
15152 do {
15153 {
15154 invokeGuardedCallback(null, commitBeforeMutationEffects, null);
15155
15156 if (hasCaughtError()) {
15157 if (!(nextEffect !== null)) {
15158 {
15159 throw Error("Should be working on an effect.");
15160 }
15161 }
15162
15163 var error = clearCaughtError();
15164 captureCommitPhaseError(nextEffect, error);
15165 nextEffect = nextEffect.nextEffect;
15166 }
15167 }
15168 } while (nextEffect !== null);
15169
15170 stopCommitSnapshotEffectsTimer();
15171
15172 if (enableProfilerTimer) {
15173 // Mark the current commit time to be shared by all Profilers in this
15174 // batch. This enables them to be grouped later.
15175 recordCommitTime();
15176 } // The next phase is the mutation phase, where we mutate the host tree.
15177
15178
15179 startCommitHostEffectsTimer();
15180 nextEffect = firstEffect;
15181
15182 do {
15183 {
15184 invokeGuardedCallback(null, commitMutationEffects, null, root, renderPriorityLevel);
15185
15186 if (hasCaughtError()) {
15187 if (!(nextEffect !== null)) {
15188 {
15189 throw Error("Should be working on an effect.");
15190 }
15191 }
15192
15193 var _error = clearCaughtError();
15194
15195 captureCommitPhaseError(nextEffect, _error);
15196 nextEffect = nextEffect.nextEffect;
15197 }
15198 }
15199 } while (nextEffect !== null);
15200
15201 stopCommitHostEffectsTimer();
15202 resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
15203 // the mutation phase, so that the previous tree is still current during
15204 // componentWillUnmount, but before the layout phase, so that the finished
15205 // work is current during componentDidMount/Update.
15206
15207 root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
15208 // the host tree after it's been mutated. The idiomatic use case for this is
15209 // layout, but class component lifecycles also fire here for legacy reasons.
15210
15211 startCommitLifeCyclesTimer();
15212 nextEffect = firstEffect;
15213
15214 do {
15215 {
15216 invokeGuardedCallback(null, commitLayoutEffects, null, root, expirationTime);
15217
15218 if (hasCaughtError()) {
15219 if (!(nextEffect !== null)) {
15220 {
15221 throw Error("Should be working on an effect.");
15222 }
15223 }
15224
15225 var _error2 = clearCaughtError();
15226
15227 captureCommitPhaseError(nextEffect, _error2);
15228 nextEffect = nextEffect.nextEffect;
15229 }
15230 }
15231 } while (nextEffect !== null);
15232
15233 stopCommitLifeCyclesTimer();
15234 nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
15235 // opportunity to paint.
15236
15237 requestPaint();
15238
15239 if (enableSchedulerTracing) {
15240 popInteractions(prevInteractions);
15241 }
15242
15243 executionContext = prevExecutionContext;
15244 } else {
15245 // No effects.
15246 root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
15247 // no effects.
15248 // TODO: Maybe there's a better way to report this.
15249
15250 startCommitSnapshotEffectsTimer();
15251 stopCommitSnapshotEffectsTimer();
15252
15253 if (enableProfilerTimer) {
15254 recordCommitTime();
15255 }
15256
15257 startCommitHostEffectsTimer();
15258 stopCommitHostEffectsTimer();
15259 startCommitLifeCyclesTimer();
15260 stopCommitLifeCyclesTimer();
15261 }
15262
15263 stopCommitTimer();
15264 var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
15265
15266 if (rootDoesHavePassiveEffects) {
15267 // This commit has passive effects. Stash a reference to them. But don't
15268 // schedule a callback until after flushing layout work.
15269 rootDoesHavePassiveEffects = false;
15270 rootWithPendingPassiveEffects = root;
15271 pendingPassiveEffectsExpirationTime = expirationTime;
15272 pendingPassiveEffectsRenderPriority = renderPriorityLevel;
15273 } else {
15274 // We are done with the effect chain at this point so let's clear the
15275 // nextEffect pointers to assist with GC. If we have passive effects, we'll
15276 // clear this in flushPassiveEffects.
15277 nextEffect = firstEffect;
15278
15279 while (nextEffect !== null) {
15280 var nextNextEffect = nextEffect.nextEffect;
15281 nextEffect.nextEffect = null;
15282 nextEffect = nextNextEffect;
15283 }
15284 } // Check if there's remaining work on this root
15285
15286
15287 var remainingExpirationTime = root.firstPendingTime;
15288
15289 if (remainingExpirationTime !== NoWork) {
15290 if (enableSchedulerTracing) {
15291 if (spawnedWorkDuringRender !== null) {
15292 var expirationTimes = spawnedWorkDuringRender;
15293 spawnedWorkDuringRender = null;
15294
15295 for (var i = 0; i < expirationTimes.length; i++) {
15296 scheduleInteractions(root, expirationTimes[i], root.memoizedInteractions);
15297 }
15298 }
15299
15300 schedulePendingInteractions(root, remainingExpirationTime);
15301 }
15302 } else {
15303 // If there's no remaining work, we can clear the set of already failed
15304 // error boundaries.
15305 legacyErrorBoundariesThatAlreadyFailed = null;
15306 }
15307
15308 if (enableSchedulerTracing) {
15309 if (!rootDidHavePassiveEffects) {
15310 // If there are no passive effects, then we can complete the pending interactions.
15311 // Otherwise, we'll wait until after the passive effects are flushed.
15312 // Wait to do this until after remaining work has been scheduled,
15313 // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
15314 finishPendingInteractions(root, expirationTime);
15315 }
15316 }
15317
15318 if (remainingExpirationTime === Sync) {
15319 // Count the number of times the root synchronously re-renders without
15320 // finishing. If there are too many, it indicates an infinite update loop.
15321 if (root === rootWithNestedUpdates) {
15322 nestedUpdateCount++;
15323 } else {
15324 nestedUpdateCount = 0;
15325 rootWithNestedUpdates = root;
15326 }
15327 } else {
15328 nestedUpdateCount = 0;
15329 }
15330
15331 onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
15332 // additional work on this root is scheduled.
15333
15334 ensureRootIsScheduled(root);
15335
15336 if (hasUncaughtError) {
15337 hasUncaughtError = false;
15338 var _error3 = firstUncaughtError;
15339 firstUncaughtError = null;
15340 throw _error3;
15341 }
15342
15343 if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
15344 // This is a legacy edge case. We just committed the initial mount of
15345 // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
15346 // synchronously, but layout updates should be deferred until the end
15347 // of the batch.
15348 return null;
15349 } // If layout work was scheduled, flush it now.
15350
15351
15352 flushSyncCallbackQueue();
15353 return null;
15354}
15355
15356function commitBeforeMutationEffects() {
15357 while (nextEffect !== null) {
15358 var effectTag = nextEffect.effectTag;
15359
15360 if ((effectTag & Snapshot) !== NoEffect) {
15361 setCurrentFiber(nextEffect);
15362 recordEffect();
15363 var current$$1 = nextEffect.alternate;
15364 commitBeforeMutationLifeCycles(current$$1, nextEffect);
15365 resetCurrentFiber();
15366 }
15367
15368 if ((effectTag & Passive) !== NoEffect) {
15369 // If there are passive effects, schedule a callback to flush at
15370 // the earliest opportunity.
15371 if (!rootDoesHavePassiveEffects) {
15372 rootDoesHavePassiveEffects = true;
15373 scheduleCallback(NormalPriority, function () {
15374 flushPassiveEffects();
15375 return null;
15376 });
15377 }
15378 }
15379
15380 nextEffect = nextEffect.nextEffect;
15381 }
15382}
15383
15384function commitMutationEffects(root, renderPriorityLevel) {
15385 // TODO: Should probably move the bulk of this function to commitWork.
15386 while (nextEffect !== null) {
15387 setCurrentFiber(nextEffect);
15388 var effectTag = nextEffect.effectTag;
15389
15390 if (effectTag & ContentReset) {
15391 commitResetTextContent(nextEffect);
15392 }
15393
15394 if (effectTag & Ref) {
15395 var current$$1 = nextEffect.alternate;
15396
15397 if (current$$1 !== null) {
15398 commitDetachRef(current$$1);
15399 }
15400 } // The following switch statement is only concerned about placement,
15401 // updates, and deletions. To avoid needing to add a case for every possible
15402 // bitmap value, we remove the secondary effects from the effect tag and
15403 // switch on that value.
15404
15405
15406 var primaryEffectTag = effectTag & (Placement | Update | Deletion | Hydrating);
15407
15408 switch (primaryEffectTag) {
15409 case Placement:
15410 {
15411 commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
15412 // inserted, before any life-cycles like componentDidMount gets called.
15413 // TODO: findDOMNode doesn't rely on this any more but isMounted does
15414 // and isMounted is deprecated anyway so we should be able to kill this.
15415
15416 nextEffect.effectTag &= ~Placement;
15417 break;
15418 }
15419
15420 case PlacementAndUpdate:
15421 {
15422 // Placement
15423 commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
15424 // inserted, before any life-cycles like componentDidMount gets called.
15425
15426 nextEffect.effectTag &= ~Placement; // Update
15427
15428 var _current = nextEffect.alternate;
15429 commitWork(_current, nextEffect);
15430 break;
15431 }
15432
15433 case Hydrating:
15434 {
15435 nextEffect.effectTag &= ~Hydrating;
15436 break;
15437 }
15438
15439 case HydratingAndUpdate:
15440 {
15441 nextEffect.effectTag &= ~Hydrating; // Update
15442
15443 var _current2 = nextEffect.alternate;
15444 commitWork(_current2, nextEffect);
15445 break;
15446 }
15447
15448 case Update:
15449 {
15450 var _current3 = nextEffect.alternate;
15451 commitWork(_current3, nextEffect);
15452 break;
15453 }
15454
15455 case Deletion:
15456 {
15457 commitDeletion(root, nextEffect, renderPriorityLevel);
15458 break;
15459 }
15460 } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
15461
15462
15463 recordEffect();
15464 resetCurrentFiber();
15465 nextEffect = nextEffect.nextEffect;
15466 }
15467}
15468
15469function commitLayoutEffects(root, committedExpirationTime) {
15470 // TODO: Should probably move the bulk of this function to commitWork.
15471 while (nextEffect !== null) {
15472 setCurrentFiber(nextEffect);
15473 var effectTag = nextEffect.effectTag;
15474
15475 if (effectTag & (Update | Callback)) {
15476 recordEffect();
15477 var current$$1 = nextEffect.alternate;
15478 commitLifeCycles(root, current$$1, nextEffect, committedExpirationTime);
15479 }
15480
15481 if (effectTag & Ref) {
15482 recordEffect();
15483 commitAttachRef(nextEffect);
15484 }
15485
15486 resetCurrentFiber();
15487 nextEffect = nextEffect.nextEffect;
15488 }
15489}
15490
15491function flushPassiveEffects() {
15492 if (pendingPassiveEffectsRenderPriority !== NoPriority) {
15493 var priorityLevel = pendingPassiveEffectsRenderPriority > NormalPriority ? NormalPriority : pendingPassiveEffectsRenderPriority;
15494 pendingPassiveEffectsRenderPriority = NoPriority;
15495 return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
15496 }
15497}
15498
15499function flushPassiveEffectsImpl() {
15500 if (rootWithPendingPassiveEffects === null) {
15501 return false;
15502 }
15503
15504 var root = rootWithPendingPassiveEffects;
15505 var expirationTime = pendingPassiveEffectsExpirationTime;
15506 rootWithPendingPassiveEffects = null;
15507 pendingPassiveEffectsExpirationTime = NoWork;
15508
15509 if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
15510 {
15511 throw Error("Cannot flush passive effects while already rendering.");
15512 }
15513 }
15514
15515 var prevExecutionContext = executionContext;
15516 executionContext |= CommitContext;
15517 var prevInteractions = pushInteractions(root); // Note: This currently assumes there are no passive effects on the root
15518 // fiber, because the root is not part of its own effect list. This could
15519 // change in the future.
15520
15521 var effect = root.current.firstEffect;
15522
15523 while (effect !== null) {
15524 {
15525 setCurrentFiber(effect);
15526 invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
15527
15528 if (hasCaughtError()) {
15529 if (!(effect !== null)) {
15530 {
15531 throw Error("Should be working on an effect.");
15532 }
15533 }
15534
15535 var error = clearCaughtError();
15536 captureCommitPhaseError(effect, error);
15537 }
15538
15539 resetCurrentFiber();
15540 }
15541
15542 var nextNextEffect = effect.nextEffect; // Remove nextEffect pointer to assist GC
15543
15544 effect.nextEffect = null;
15545 effect = nextNextEffect;
15546 }
15547
15548 if (enableSchedulerTracing) {
15549 popInteractions(prevInteractions);
15550 finishPendingInteractions(root, expirationTime);
15551 }
15552
15553 executionContext = prevExecutionContext;
15554 flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
15555 // exceeds the limit, we'll fire a warning.
15556
15557 nestedPassiveUpdateCount = rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
15558 return true;
15559}
15560
15561function isAlreadyFailedLegacyErrorBoundary(instance) {
15562 return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
15563}
15564function markLegacyErrorBoundaryAsFailed(instance) {
15565 if (legacyErrorBoundariesThatAlreadyFailed === null) {
15566 legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
15567 } else {
15568 legacyErrorBoundariesThatAlreadyFailed.add(instance);
15569 }
15570}
15571
15572function prepareToThrowUncaughtError(error) {
15573 if (!hasUncaughtError) {
15574 hasUncaughtError = true;
15575 firstUncaughtError = error;
15576 }
15577}
15578
15579var onUncaughtError = prepareToThrowUncaughtError;
15580
15581function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
15582 var errorInfo = createCapturedValue(error, sourceFiber);
15583 var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
15584 enqueueUpdate(rootFiber, update);
15585 var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
15586
15587 if (root !== null) {
15588 ensureRootIsScheduled(root);
15589 schedulePendingInteractions(root, Sync);
15590 }
15591}
15592
15593function captureCommitPhaseError(sourceFiber, error) {
15594 if (sourceFiber.tag === HostRoot) {
15595 // Error was thrown at the root. There is no parent, so the root
15596 // itself should capture it.
15597 captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
15598 return;
15599 }
15600
15601 var fiber = sourceFiber.return;
15602
15603 while (fiber !== null) {
15604 if (fiber.tag === HostRoot) {
15605 captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
15606 return;
15607 } else if (fiber.tag === ClassComponent) {
15608 var ctor = fiber.type;
15609 var instance = fiber.stateNode;
15610
15611 if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
15612 var errorInfo = createCapturedValue(error, sourceFiber);
15613 var update = createClassErrorUpdate(fiber, errorInfo, // TODO: This is always sync
15614 Sync);
15615 enqueueUpdate(fiber, update);
15616 var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
15617
15618 if (root !== null) {
15619 ensureRootIsScheduled(root);
15620 schedulePendingInteractions(root, Sync);
15621 }
15622
15623 return;
15624 }
15625 }
15626
15627 fiber = fiber.return;
15628 }
15629}
15630function pingSuspendedRoot(root, thenable, suspendedTime) {
15631 var pingCache = root.pingCache;
15632
15633 if (pingCache !== null) {
15634 // The thenable resolved, so we no longer need to memoize, because it will
15635 // never be thrown again.
15636 pingCache.delete(thenable);
15637 }
15638
15639 if (workInProgressRoot === root && renderExpirationTime === suspendedTime) {
15640 // Received a ping at the same priority level at which we're currently
15641 // rendering. We might want to restart this render. This should mirror
15642 // the logic of whether or not a root suspends once it completes.
15643 // TODO: If we're rendering sync either due to Sync, Batched or expired,
15644 // we should probably never restart.
15645 // If we're suspended with delay, we'll always suspend so we can always
15646 // restart. If we're suspended without any updates, it might be a retry.
15647 // If it's early in the retry we can restart. We can't know for sure
15648 // whether we'll eventually process an update during this render pass,
15649 // but it's somewhat unlikely that we get to a ping before that, since
15650 // getting to the root most update is usually very fast.
15651 if (workInProgressRootExitStatus === RootSuspendedWithDelay || workInProgressRootExitStatus === RootSuspended && workInProgressRootLatestProcessedExpirationTime === Sync && now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS) {
15652 // Restart from the root. Don't need to schedule a ping because
15653 // we're already working on this tree.
15654 prepareFreshStack(root, renderExpirationTime);
15655 } else {
15656 // Even though we can't restart right now, we might get an
15657 // opportunity later. So we mark this render as having a ping.
15658 workInProgressRootHasPendingPing = true;
15659 }
15660
15661 return;
15662 }
15663
15664 if (!isRootSuspendedAtTime(root, suspendedTime)) {
15665 // The root is no longer suspended at this time.
15666 return;
15667 }
15668
15669 var lastPingedTime = root.lastPingedTime;
15670
15671 if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
15672 // There's already a lower priority ping scheduled.
15673 return;
15674 } // Mark the time at which this ping was scheduled.
15675
15676
15677 root.lastPingedTime = suspendedTime;
15678
15679 if (root.finishedExpirationTime === suspendedTime) {
15680 // If there's a pending fallback waiting to commit, throw it away.
15681 root.finishedExpirationTime = NoWork;
15682 root.finishedWork = null;
15683 }
15684
15685 ensureRootIsScheduled(root);
15686 schedulePendingInteractions(root, suspendedTime);
15687}
15688
15689function retryTimedOutBoundary(boundaryFiber, retryTime) {
15690 // The boundary fiber (a Suspense component or SuspenseList component)
15691 // previously was rendered in its fallback state. One of the promises that
15692 // suspended it has resolved, which means at least part of the tree was
15693 // likely unblocked. Try rendering again, at a new expiration time.
15694 if (retryTime === NoWork) {
15695 var suspenseConfig = null; // Retries don't carry over the already committed update.
15696
15697 var currentTime = requestCurrentTimeForUpdate();
15698 retryTime = computeExpirationForFiber(currentTime, boundaryFiber, suspenseConfig);
15699 } // TODO: Special case idle priority?
15700
15701
15702 var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
15703
15704 if (root !== null) {
15705 ensureRootIsScheduled(root);
15706 schedulePendingInteractions(root, retryTime);
15707 }
15708}
15709
15710function retryDehydratedSuspenseBoundary(boundaryFiber) {
15711 var suspenseState = boundaryFiber.memoizedState;
15712 var retryTime = NoWork;
15713
15714 if (suspenseState !== null) {
15715 retryTime = suspenseState.retryTime;
15716 }
15717
15718 retryTimedOutBoundary(boundaryFiber, retryTime);
15719}
15720function resolveRetryThenable(boundaryFiber, thenable) {
15721 var retryTime = NoWork; // Default
15722
15723 var retryCache;
15724
15725 if (enableSuspenseServerRenderer) {
15726 switch (boundaryFiber.tag) {
15727 case SuspenseComponent:
15728 retryCache = boundaryFiber.stateNode;
15729 var suspenseState = boundaryFiber.memoizedState;
15730
15731 if (suspenseState !== null) {
15732 retryTime = suspenseState.retryTime;
15733 }
15734
15735 break;
15736
15737 case SuspenseListComponent:
15738 retryCache = boundaryFiber.stateNode;
15739 break;
15740
15741 default:
15742 {
15743 {
15744 throw Error("Pinged unknown suspense boundary type. This is probably a bug in React.");
15745 }
15746 }
15747
15748 }
15749 } else {
15750 retryCache = boundaryFiber.stateNode;
15751 }
15752
15753 if (retryCache !== null) {
15754 // The thenable resolved, so we no longer need to memoize, because it will
15755 // never be thrown again.
15756 retryCache.delete(thenable);
15757 }
15758
15759 retryTimedOutBoundary(boundaryFiber, retryTime);
15760} // Computes the next Just Noticeable Difference (JND) boundary.
15761// The theory is that a person can't tell the difference between small differences in time.
15762// Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
15763// difference in the experience. However, waiting for longer might mean that we can avoid
15764// showing an intermediate loading state. The longer we have already waited, the harder it
15765// is to tell small differences in time. Therefore, the longer we've already waited,
15766// the longer we can wait additionally. At some point we have to give up though.
15767// We pick a train model where the next boundary commits at a consistent schedule.
15768// These particular numbers are vague estimates. We expect to adjust them based on research.
15769
15770function jnd(timeElapsed) {
15771 return timeElapsed < 120 ? 120 : timeElapsed < 480 ? 480 : timeElapsed < 1080 ? 1080 : timeElapsed < 1920 ? 1920 : timeElapsed < 3000 ? 3000 : timeElapsed < 4320 ? 4320 : ceil(timeElapsed / 1960) * 1960;
15772}
15773
15774function computeMsUntilSuspenseLoadingDelay(mostRecentEventTime, committedExpirationTime, suspenseConfig) {
15775 var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
15776
15777 if (busyMinDurationMs <= 0) {
15778 return 0;
15779 }
15780
15781 var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
15782
15783 var currentTimeMs = now();
15784 var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(mostRecentEventTime, suspenseConfig);
15785 var timeElapsed = currentTimeMs - eventTimeMs;
15786
15787 if (timeElapsed <= busyDelayMs) {
15788 // If we haven't yet waited longer than the initial delay, we don't
15789 // have to wait any additional time.
15790 return 0;
15791 }
15792
15793 var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
15794
15795 return msUntilTimeout;
15796}
15797
15798function checkForNestedUpdates() {
15799 if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
15800 nestedUpdateCount = 0;
15801 rootWithNestedUpdates = null;
15802
15803 {
15804 {
15805 throw 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.");
15806 }
15807 }
15808 }
15809
15810 {
15811 if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
15812 nestedPassiveUpdateCount = 0;
15813 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.');
15814 }
15815 }
15816}
15817
15818function flushRenderPhaseStrictModeWarningsInDEV() {
15819 {
15820 ReactStrictModeWarnings.flushLegacyContextWarning();
15821
15822 if (warnAboutDeprecatedLifecycles) {
15823 ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
15824 }
15825 }
15826}
15827
15828function stopFinishedWorkLoopTimer() {
15829 var didCompleteRoot = true;
15830 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
15831 interruptedBy = null;
15832}
15833
15834function stopInterruptedWorkLoopTimer() {
15835 // TODO: Track which fiber caused the interruption.
15836 var didCompleteRoot = false;
15837 stopWorkLoopTimer(interruptedBy, didCompleteRoot);
15838 interruptedBy = null;
15839}
15840
15841function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
15842 if (enableUserTimingAPI && workInProgressRoot !== null && updateExpirationTime > renderExpirationTime) {
15843 interruptedBy = fiberThatReceivedUpdate;
15844 }
15845}
15846
15847var didWarnStateUpdateForUnmountedComponent = null;
15848
15849function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
15850 {
15851 var tag = fiber.tag;
15852
15853 if (tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent) {
15854 // Only warn for user-defined components, not internal ones like Suspense.
15855 return;
15856 } // We show the whole stack but dedupe on the top component's name because
15857 // the problematic code almost always lies inside that component.
15858
15859
15860 var componentName = getComponentName(fiber.type) || 'ReactComponent';
15861
15862 if (didWarnStateUpdateForUnmountedComponent !== null) {
15863 if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
15864 return;
15865 }
15866
15867 didWarnStateUpdateForUnmountedComponent.add(componentName);
15868 } else {
15869 didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
15870 }
15871
15872 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));
15873 }
15874}
15875
15876var beginWork$$1;
15877
15878if (true && replayFailedUnitOfWorkWithInvokeGuardedCallback) {
15879 var dummyFiber = null;
15880
15881 beginWork$$1 = function (current$$1, unitOfWork, expirationTime) {
15882 // If a component throws an error, we replay it again in a synchronously
15883 // dispatched event, so that the debugger will treat it as an uncaught
15884 // error See ReactErrorUtils for more information.
15885 // Before entering the begin phase, copy the work-in-progress onto a dummy
15886 // fiber. If beginWork throws, we'll use this to reset the state.
15887 var originalWorkInProgressCopy = assignFiberPropertiesInDEV(dummyFiber, unitOfWork);
15888
15889 try {
15890 return beginWork$1(current$$1, unitOfWork, expirationTime);
15891 } catch (originalError) {
15892 if (originalError !== null && typeof originalError === 'object' && typeof originalError.then === 'function') {
15893 // Don't replay promises. Treat everything else like an error.
15894 throw originalError;
15895 } // Keep this code in sync with handleError; any changes here must have
15896 // corresponding changes there.
15897
15898
15899 resetContextDependencies();
15900 resetHooks(); // Don't reset current debug fiber, since we're about to work on the
15901 // same fiber again.
15902 // Unwind the failed stack frame
15903
15904 unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
15905
15906 assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
15907
15908 if (enableProfilerTimer && unitOfWork.mode & ProfileMode) {
15909 // Reset the profiler timer.
15910 startProfilerTimer(unitOfWork);
15911 } // Run beginWork again.
15912
15913
15914 invokeGuardedCallback(null, beginWork$1, null, current$$1, unitOfWork, expirationTime);
15915
15916 if (hasCaughtError()) {
15917 var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
15918 // Rethrow this error instead of the original one.
15919
15920 throw replayError;
15921 } else {
15922 // This branch is reachable if the render phase is impure.
15923 throw originalError;
15924 }
15925 }
15926 };
15927} else {
15928 beginWork$$1 = beginWork$1;
15929}
15930
15931var didWarnAboutUpdateInRender = false;
15932var didWarnAboutUpdateInGetChildContext = false;
15933
15934function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) {
15935 {
15936 if (fiber.tag === ClassComponent) {
15937 switch (phase) {
15938 case 'getChildContext':
15939 if (didWarnAboutUpdateInGetChildContext) {
15940 return;
15941 }
15942
15943 warningWithoutStack$1(false, 'setState(...): Cannot call setState() inside getChildContext()');
15944 didWarnAboutUpdateInGetChildContext = true;
15945 break;
15946
15947 case 'render':
15948 if (didWarnAboutUpdateInRender) {
15949 return;
15950 }
15951
15952 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.');
15953 didWarnAboutUpdateInRender = true;
15954 break;
15955 }
15956 }
15957 }
15958} // a 'shared' variable that changes when act() opens/closes in tests.
15959
15960
15961var IsThisRendererActing = {
15962 current: false
15963};
15964function warnIfNotScopedWithMatchingAct(fiber) {
15965 {
15966 if (warnsIfNotActing === true && IsSomeRendererActing.current === true && IsThisRendererActing.current !== true) {
15967 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));
15968 }
15969 }
15970}
15971function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
15972 {
15973 if (warnsIfNotActing === true && (fiber.mode & StrictMode) !== NoMode && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
15974 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));
15975 }
15976 }
15977}
15978
15979function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
15980 {
15981 if (warnsIfNotActing === true && executionContext === NoContext && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
15982 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));
15983 }
15984 }
15985}
15986
15987var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
15988
15989var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
15990// scheduler is the actual recommendation. The alternative could be a testing build,
15991// a new lib, or whatever; we dunno just yet. This message is for early adopters
15992// to get their tests right.
15993
15994function warnIfUnmockedScheduler(fiber) {
15995 {
15996 if (didWarnAboutUnmockedScheduler === false && Scheduler$1.unstable_flushAllWithoutAsserting === undefined) {
15997 if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
15998 didWarnAboutUnmockedScheduler = true;
15999 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');
16000 } else if (warnAboutUnmockedScheduler === true) {
16001 didWarnAboutUnmockedScheduler = true;
16002 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');
16003 }
16004 }
16005 }
16006}
16007var componentsThatTriggeredHighPriSuspend = null;
16008function checkForWrongSuspensePriorityInDEV(sourceFiber) {
16009 {
16010 var currentPriorityLevel = getCurrentPriorityLevel();
16011
16012 if ((sourceFiber.mode & ConcurrentMode) !== NoEffect && (currentPriorityLevel === UserBlockingPriority || currentPriorityLevel === ImmediatePriority)) {
16013 var workInProgressNode = sourceFiber;
16014
16015 while (workInProgressNode !== null) {
16016 // Add the component that triggered the suspense
16017 var current$$1 = workInProgressNode.alternate;
16018
16019 if (current$$1 !== null) {
16020 // TODO: warn component that triggers the high priority
16021 // suspend is the HostRoot
16022 switch (workInProgressNode.tag) {
16023 case ClassComponent:
16024 // Loop through the component's update queue and see whether the component
16025 // has triggered any high priority updates
16026 var updateQueue = current$$1.updateQueue;
16027
16028 if (updateQueue !== null) {
16029 var update = updateQueue.firstUpdate;
16030
16031 while (update !== null) {
16032 var priorityLevel = update.priority;
16033
16034 if (priorityLevel === UserBlockingPriority || priorityLevel === ImmediatePriority) {
16035 if (componentsThatTriggeredHighPriSuspend === null) {
16036 componentsThatTriggeredHighPriSuspend = new Set([getComponentName(workInProgressNode.type)]);
16037 } else {
16038 componentsThatTriggeredHighPriSuspend.add(getComponentName(workInProgressNode.type));
16039 }
16040
16041 break;
16042 }
16043
16044 update = update.next;
16045 }
16046 }
16047
16048 break;
16049
16050 case FunctionComponent:
16051 case ForwardRef:
16052 case SimpleMemoComponent:
16053 if (workInProgressNode.memoizedState !== null && workInProgressNode.memoizedState.baseUpdate !== null) {
16054 var _update = workInProgressNode.memoizedState.baseUpdate; // Loop through the functional component's memoized state to see whether
16055 // the component has triggered any high pri updates
16056
16057 while (_update !== null) {
16058 var priority = _update.priority;
16059
16060 if (priority === UserBlockingPriority || priority === ImmediatePriority) {
16061 if (componentsThatTriggeredHighPriSuspend === null) {
16062 componentsThatTriggeredHighPriSuspend = new Set([getComponentName(workInProgressNode.type)]);
16063 } else {
16064 componentsThatTriggeredHighPriSuspend.add(getComponentName(workInProgressNode.type));
16065 }
16066
16067 break;
16068 }
16069
16070 if (_update.next === workInProgressNode.memoizedState.baseUpdate) {
16071 break;
16072 }
16073
16074 _update = _update.next;
16075 }
16076 }
16077
16078 break;
16079
16080 default:
16081 break;
16082 }
16083 }
16084
16085 workInProgressNode = workInProgressNode.return;
16086 }
16087 }
16088 }
16089}
16090
16091function flushSuspensePriorityWarningInDEV() {
16092 {
16093 if (componentsThatTriggeredHighPriSuspend !== null) {
16094 var componentNames = [];
16095 componentsThatTriggeredHighPriSuspend.forEach(function (name) {
16096 return componentNames.push(name);
16097 });
16098 componentsThatTriggeredHighPriSuspend = null;
16099
16100 if (componentNames.length > 0) {
16101 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 useTransition to learn how ' + 'to implement this pattern.', // TODO: Add link to React docs with more information, once it exists
16102 componentNames.sort().join(', '));
16103 }
16104 }
16105 }
16106}
16107
16108function computeThreadID(root, expirationTime) {
16109 // Interaction threads are unique per root and expiration time.
16110 return expirationTime * 1000 + root.interactionThreadID;
16111}
16112
16113function markSpawnedWork(expirationTime) {
16114 if (!enableSchedulerTracing) {
16115 return;
16116 }
16117
16118 if (spawnedWorkDuringRender === null) {
16119 spawnedWorkDuringRender = [expirationTime];
16120 } else {
16121 spawnedWorkDuringRender.push(expirationTime);
16122 }
16123}
16124
16125function scheduleInteractions(root, expirationTime, interactions) {
16126 if (!enableSchedulerTracing) {
16127 return;
16128 }
16129
16130 if (interactions.size > 0) {
16131 var pendingInteractionMap = root.pendingInteractionMap;
16132 var pendingInteractions = pendingInteractionMap.get(expirationTime);
16133
16134 if (pendingInteractions != null) {
16135 interactions.forEach(function (interaction) {
16136 if (!pendingInteractions.has(interaction)) {
16137 // Update the pending async work count for previously unscheduled interaction.
16138 interaction.__count++;
16139 }
16140
16141 pendingInteractions.add(interaction);
16142 });
16143 } else {
16144 pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
16145
16146 interactions.forEach(function (interaction) {
16147 interaction.__count++;
16148 });
16149 }
16150
16151 var subscriber = __subscriberRef.current;
16152
16153 if (subscriber !== null) {
16154 var threadID = computeThreadID(root, expirationTime);
16155 subscriber.onWorkScheduled(interactions, threadID);
16156 }
16157 }
16158}
16159
16160function schedulePendingInteractions(root, expirationTime) {
16161 // This is called when work is scheduled on a root.
16162 // It associates the current interactions with the newly-scheduled expiration.
16163 // They will be restored when that expiration is later committed.
16164 if (!enableSchedulerTracing) {
16165 return;
16166 }
16167
16168 scheduleInteractions(root, expirationTime, __interactionsRef.current);
16169}
16170
16171function startWorkOnPendingInteractions(root, expirationTime) {
16172 // This is called when new work is started on a root.
16173 if (!enableSchedulerTracing) {
16174 return;
16175 } // Determine which interactions this batch of work currently includes, So that
16176 // we can accurately attribute time spent working on it, And so that cascading
16177 // work triggered during the render phase will be associated with it.
16178
16179
16180 var interactions = new Set();
16181 root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
16182 if (scheduledExpirationTime >= expirationTime) {
16183 scheduledInteractions.forEach(function (interaction) {
16184 return interactions.add(interaction);
16185 });
16186 }
16187 }); // Store the current set of interactions on the FiberRoot for a few reasons:
16188 // We can re-use it in hot functions like performConcurrentWorkOnRoot()
16189 // without having to recalculate it. We will also use it in commitWork() to
16190 // pass to any Profiler onRender() hooks. This also provides DevTools with a
16191 // way to access it when the onCommitRoot() hook is called.
16192
16193 root.memoizedInteractions = interactions;
16194
16195 if (interactions.size > 0) {
16196 var subscriber = __subscriberRef.current;
16197
16198 if (subscriber !== null) {
16199 var threadID = computeThreadID(root, expirationTime);
16200
16201 try {
16202 subscriber.onWorkStarted(interactions, threadID);
16203 } catch (error) {
16204 // If the subscriber throws, rethrow it in a separate task
16205 scheduleCallback(ImmediatePriority, function () {
16206 throw error;
16207 });
16208 }
16209 }
16210 }
16211}
16212
16213function finishPendingInteractions(root, committedExpirationTime) {
16214 if (!enableSchedulerTracing) {
16215 return;
16216 }
16217
16218 var earliestRemainingTimeAfterCommit = root.firstPendingTime;
16219 var subscriber;
16220
16221 try {
16222 subscriber = __subscriberRef.current;
16223
16224 if (subscriber !== null && root.memoizedInteractions.size > 0) {
16225 var threadID = computeThreadID(root, committedExpirationTime);
16226 subscriber.onWorkStopped(root.memoizedInteractions, threadID);
16227 }
16228 } catch (error) {
16229 // If the subscriber throws, rethrow it in a separate task
16230 scheduleCallback(ImmediatePriority, function () {
16231 throw error;
16232 });
16233 } finally {
16234 // Clear completed interactions from the pending Map.
16235 // Unless the render was suspended or cascading work was scheduled,
16236 // In which case– leave pending interactions until the subsequent render.
16237 var pendingInteractionMap = root.pendingInteractionMap;
16238 pendingInteractionMap.forEach(function (scheduledInteractions, scheduledExpirationTime) {
16239 // Only decrement the pending interaction count if we're done.
16240 // If there's still work at the current priority,
16241 // That indicates that we are waiting for suspense data.
16242 if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
16243 pendingInteractionMap.delete(scheduledExpirationTime);
16244 scheduledInteractions.forEach(function (interaction) {
16245 interaction.__count--;
16246
16247 if (subscriber !== null && interaction.__count === 0) {
16248 try {
16249 subscriber.onInteractionScheduledWorkCompleted(interaction);
16250 } catch (error) {
16251 // If the subscriber throws, rethrow it in a separate task
16252 scheduleCallback(ImmediatePriority, function () {
16253 throw error;
16254 });
16255 }
16256 }
16257 });
16258 }
16259 });
16260 }
16261}
16262
16263var onCommitFiberRoot = null;
16264var onCommitFiberUnmount = null;
16265var hasLoggedError = false;
16266var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
16267function injectInternals(internals) {
16268 if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
16269 // No DevTools
16270 return false;
16271 }
16272
16273 var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
16274
16275 if (hook.isDisabled) {
16276 // This isn't a real property on the hook, but it can be set to opt out
16277 // of DevTools integration and associated warnings and logs.
16278 // https://github.com/facebook/react/issues/3877
16279 return true;
16280 }
16281
16282 if (!hook.supportsFiber) {
16283 {
16284 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');
16285 } // DevTools exists, even though it doesn't support Fiber.
16286
16287
16288 return true;
16289 }
16290
16291 try {
16292 var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
16293
16294 onCommitFiberRoot = function (root, expirationTime) {
16295 try {
16296 var didError = (root.current.effectTag & DidCapture) === DidCapture;
16297
16298 if (enableProfilerTimer) {
16299 var currentTime = getCurrentTime();
16300 var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime);
16301 hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
16302 } else {
16303 hook.onCommitFiberRoot(rendererID, root, undefined, didError);
16304 }
16305 } catch (err) {
16306 if (true && !hasLoggedError) {
16307 hasLoggedError = true;
16308 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
16309 }
16310 }
16311 };
16312
16313 onCommitFiberUnmount = function (fiber) {
16314 try {
16315 hook.onCommitFiberUnmount(rendererID, fiber);
16316 } catch (err) {
16317 if (true && !hasLoggedError) {
16318 hasLoggedError = true;
16319 warningWithoutStack$1(false, 'React DevTools encountered an error: %s', err);
16320 }
16321 }
16322 };
16323 } catch (err) {
16324 // Catch all errors because it is unsafe to throw during initialization.
16325 {
16326 warningWithoutStack$1(false, 'React DevTools encountered an error: %s.', err);
16327 }
16328 } // DevTools exists
16329
16330
16331 return true;
16332}
16333function onCommitRoot(root, expirationTime) {
16334 if (typeof onCommitFiberRoot === 'function') {
16335 onCommitFiberRoot(root, expirationTime);
16336 }
16337}
16338function onCommitUnmount(fiber) {
16339 if (typeof onCommitFiberUnmount === 'function') {
16340 onCommitFiberUnmount(fiber);
16341 }
16342}
16343
16344var hasBadMapPolyfill;
16345
16346{
16347 hasBadMapPolyfill = false;
16348
16349 try {
16350 var nonExtensibleObject = Object.preventExtensions({});
16351 var testMap = new Map([[nonExtensibleObject, null]]);
16352 var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
16353 // https://github.com/rollup/rollup/issues/1771
16354 // TODO: we can remove these if Rollup fixes the bug.
16355
16356 testMap.set(0, 0);
16357 testSet.add(0);
16358 } catch (e) {
16359 // TODO: Consider warning about bad polyfills
16360 hasBadMapPolyfill = true;
16361 }
16362}
16363
16364var debugCounter = 1;
16365
16366function FiberNode(tag, pendingProps, key, mode) {
16367 // Instance
16368 this.tag = tag;
16369 this.key = key;
16370 this.elementType = null;
16371 this.type = null;
16372 this.stateNode = null; // Fiber
16373
16374 this.return = null;
16375 this.child = null;
16376 this.sibling = null;
16377 this.index = 0;
16378 this.ref = null;
16379 this.pendingProps = pendingProps;
16380 this.memoizedProps = null;
16381 this.updateQueue = null;
16382 this.memoizedState = null;
16383 this.dependencies = null;
16384 this.mode = mode; // Effects
16385
16386 this.effectTag = NoEffect;
16387 this.nextEffect = null;
16388 this.firstEffect = null;
16389 this.lastEffect = null;
16390 this.expirationTime = NoWork;
16391 this.childExpirationTime = NoWork;
16392 this.alternate = null;
16393
16394 if (enableProfilerTimer) {
16395 // Note: The following is done to avoid a v8 performance cliff.
16396 //
16397 // Initializing the fields below to smis and later updating them with
16398 // double values will cause Fibers to end up having separate shapes.
16399 // This behavior/bug has something to do with Object.preventExtension().
16400 // Fortunately this only impacts DEV builds.
16401 // Unfortunately it makes React unusably slow for some applications.
16402 // To work around this, initialize the fields below with doubles.
16403 //
16404 // Learn more about this here:
16405 // https://github.com/facebook/react/issues/14365
16406 // https://bugs.chromium.org/p/v8/issues/detail?id=8538
16407 this.actualDuration = Number.NaN;
16408 this.actualStartTime = Number.NaN;
16409 this.selfBaseDuration = Number.NaN;
16410 this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
16411 // This won't trigger the performance cliff mentioned above,
16412 // and it simplifies other profiler code (including DevTools).
16413
16414 this.actualDuration = 0;
16415 this.actualStartTime = -1;
16416 this.selfBaseDuration = 0;
16417 this.treeBaseDuration = 0;
16418 } // This is normally DEV-only except www when it adds listeners.
16419 // TODO: remove the User Timing integration in favor of Root Events.
16420
16421
16422 if (enableUserTimingAPI) {
16423 this._debugID = debugCounter++;
16424 this._debugIsCurrentlyTiming = false;
16425 }
16426
16427 {
16428 this._debugSource = null;
16429 this._debugOwner = null;
16430 this._debugNeedsRemount = false;
16431 this._debugHookTypes = null;
16432
16433 if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
16434 Object.preventExtensions(this);
16435 }
16436 }
16437} // This is a constructor function, rather than a POJO constructor, still
16438// please ensure we do the following:
16439// 1) Nobody should add any instance methods on this. Instance methods can be
16440// more difficult to predict when they get optimized and they are almost
16441// never inlined properly in static compilers.
16442// 2) Nobody should rely on `instanceof Fiber` for type testing. We should
16443// always know when it is a fiber.
16444// 3) We might want to experiment with using numeric keys since they are easier
16445// to optimize in a non-JIT environment.
16446// 4) We can easily go from a constructor to a createFiber object literal if that
16447// is faster.
16448// 5) It should be easy to port this to a C struct and keep a C implementation
16449// compatible.
16450
16451
16452var createFiber = function (tag, pendingProps, key, mode) {
16453 // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
16454 return new FiberNode(tag, pendingProps, key, mode);
16455};
16456
16457function shouldConstruct(Component) {
16458 var prototype = Component.prototype;
16459 return !!(prototype && prototype.isReactComponent);
16460}
16461
16462function isSimpleFunctionComponent(type) {
16463 return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
16464}
16465function resolveLazyComponentTag(Component) {
16466 if (typeof Component === 'function') {
16467 return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
16468 } else if (Component !== undefined && Component !== null) {
16469 var $$typeof = Component.$$typeof;
16470
16471 if ($$typeof === REACT_FORWARD_REF_TYPE) {
16472 return ForwardRef;
16473 }
16474
16475 if ($$typeof === REACT_MEMO_TYPE) {
16476 return MemoComponent;
16477 }
16478 }
16479
16480 return IndeterminateComponent;
16481} // This is used to create an alternate fiber to do work on.
16482
16483function createWorkInProgress(current, pendingProps, expirationTime) {
16484 var workInProgress = current.alternate;
16485
16486 if (workInProgress === null) {
16487 // We use a double buffering pooling technique because we know that we'll
16488 // only ever need at most two versions of a tree. We pool the "other" unused
16489 // node that we're free to reuse. This is lazily created to avoid allocating
16490 // extra objects for things that are never updated. It also allow us to
16491 // reclaim the extra memory if needed.
16492 workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
16493 workInProgress.elementType = current.elementType;
16494 workInProgress.type = current.type;
16495 workInProgress.stateNode = current.stateNode;
16496
16497 {
16498 // DEV-only fields
16499 workInProgress._debugID = current._debugID;
16500 workInProgress._debugSource = current._debugSource;
16501 workInProgress._debugOwner = current._debugOwner;
16502 workInProgress._debugHookTypes = current._debugHookTypes;
16503 }
16504
16505 workInProgress.alternate = current;
16506 current.alternate = workInProgress;
16507 } else {
16508 workInProgress.pendingProps = pendingProps; // We already have an alternate.
16509 // Reset the effect tag.
16510
16511 workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
16512
16513 workInProgress.nextEffect = null;
16514 workInProgress.firstEffect = null;
16515 workInProgress.lastEffect = null;
16516
16517 if (enableProfilerTimer) {
16518 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
16519 // This prevents time from endlessly accumulating in new commits.
16520 // This has the downside of resetting values for different priority renders,
16521 // But works for yielding (the common case) and should support resuming.
16522 workInProgress.actualDuration = 0;
16523 workInProgress.actualStartTime = -1;
16524 }
16525 }
16526
16527 workInProgress.childExpirationTime = current.childExpirationTime;
16528 workInProgress.expirationTime = current.expirationTime;
16529 workInProgress.child = current.child;
16530 workInProgress.memoizedProps = current.memoizedProps;
16531 workInProgress.memoizedState = current.memoizedState;
16532 workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
16533 // it cannot be shared with the current fiber.
16534
16535 var currentDependencies = current.dependencies;
16536 workInProgress.dependencies = currentDependencies === null ? null : {
16537 expirationTime: currentDependencies.expirationTime,
16538 firstContext: currentDependencies.firstContext,
16539 responders: currentDependencies.responders
16540 }; // These will be overridden during the parent's reconciliation
16541
16542 workInProgress.sibling = current.sibling;
16543 workInProgress.index = current.index;
16544 workInProgress.ref = current.ref;
16545
16546 if (enableProfilerTimer) {
16547 workInProgress.selfBaseDuration = current.selfBaseDuration;
16548 workInProgress.treeBaseDuration = current.treeBaseDuration;
16549 }
16550
16551 {
16552 workInProgress._debugNeedsRemount = current._debugNeedsRemount;
16553
16554 switch (workInProgress.tag) {
16555 case IndeterminateComponent:
16556 case FunctionComponent:
16557 case SimpleMemoComponent:
16558 workInProgress.type = resolveFunctionForHotReloading(current.type);
16559 break;
16560
16561 case ClassComponent:
16562 workInProgress.type = resolveClassForHotReloading(current.type);
16563 break;
16564
16565 case ForwardRef:
16566 workInProgress.type = resolveForwardRefForHotReloading(current.type);
16567 break;
16568
16569 default:
16570 break;
16571 }
16572 }
16573
16574 return workInProgress;
16575} // Used to reuse a Fiber for a second pass.
16576
16577function resetWorkInProgress(workInProgress, renderExpirationTime) {
16578 // This resets the Fiber to what createFiber or createWorkInProgress would
16579 // have set the values to before during the first pass. Ideally this wouldn't
16580 // be necessary but unfortunately many code paths reads from the workInProgress
16581 // when they should be reading from current and writing to workInProgress.
16582 // We assume pendingProps, index, key, ref, return are still untouched to
16583 // avoid doing another reconciliation.
16584 // Reset the effect tag but keep any Placement tags, since that's something
16585 // that child fiber is setting, not the reconciliation.
16586 workInProgress.effectTag &= Placement; // The effect list is no longer valid.
16587
16588 workInProgress.nextEffect = null;
16589 workInProgress.firstEffect = null;
16590 workInProgress.lastEffect = null;
16591 var current = workInProgress.alternate;
16592
16593 if (current === null) {
16594 // Reset to createFiber's initial values.
16595 workInProgress.childExpirationTime = NoWork;
16596 workInProgress.expirationTime = renderExpirationTime;
16597 workInProgress.child = null;
16598 workInProgress.memoizedProps = null;
16599 workInProgress.memoizedState = null;
16600 workInProgress.updateQueue = null;
16601 workInProgress.dependencies = null;
16602
16603 if (enableProfilerTimer) {
16604 // Note: We don't reset the actualTime counts. It's useful to accumulate
16605 // actual time across multiple render passes.
16606 workInProgress.selfBaseDuration = 0;
16607 workInProgress.treeBaseDuration = 0;
16608 }
16609 } else {
16610 // Reset to the cloned values that createWorkInProgress would've.
16611 workInProgress.childExpirationTime = current.childExpirationTime;
16612 workInProgress.expirationTime = current.expirationTime;
16613 workInProgress.child = current.child;
16614 workInProgress.memoizedProps = current.memoizedProps;
16615 workInProgress.memoizedState = current.memoizedState;
16616 workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
16617 // it cannot be shared with the current fiber.
16618
16619 var currentDependencies = current.dependencies;
16620 workInProgress.dependencies = currentDependencies === null ? null : {
16621 expirationTime: currentDependencies.expirationTime,
16622 firstContext: currentDependencies.firstContext,
16623 responders: currentDependencies.responders
16624 };
16625
16626 if (enableProfilerTimer) {
16627 // Note: We don't reset the actualTime counts. It's useful to accumulate
16628 // actual time across multiple render passes.
16629 workInProgress.selfBaseDuration = current.selfBaseDuration;
16630 workInProgress.treeBaseDuration = current.treeBaseDuration;
16631 }
16632 }
16633
16634 return workInProgress;
16635}
16636function createHostRootFiber(tag) {
16637 var mode;
16638
16639 if (tag === ConcurrentRoot) {
16640 mode = ConcurrentMode | BlockingMode | StrictMode;
16641 } else if (tag === BlockingRoot) {
16642 mode = BlockingMode | StrictMode;
16643 } else {
16644 mode = NoMode;
16645 }
16646
16647 if (enableProfilerTimer && isDevToolsPresent) {
16648 // Always collect profile timings when DevTools are present.
16649 // This enables DevTools to start capturing timing at any point–
16650 // Without some nodes in the tree having empty base times.
16651 mode |= ProfileMode;
16652 }
16653
16654 return createFiber(HostRoot, null, null, mode);
16655}
16656function createFiberFromTypeAndProps(type, // React$ElementType
16657key, pendingProps, owner, mode, expirationTime) {
16658 var fiber;
16659 var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
16660
16661 var resolvedType = type;
16662
16663 if (typeof type === 'function') {
16664 if (shouldConstruct(type)) {
16665 fiberTag = ClassComponent;
16666
16667 {
16668 resolvedType = resolveClassForHotReloading(resolvedType);
16669 }
16670 } else {
16671 {
16672 resolvedType = resolveFunctionForHotReloading(resolvedType);
16673 }
16674 }
16675 } else if (typeof type === 'string') {
16676 fiberTag = HostComponent;
16677 } else {
16678 getTag: switch (type) {
16679 case REACT_FRAGMENT_TYPE:
16680 return createFiberFromFragment(pendingProps.children, mode, expirationTime, key);
16681
16682 case REACT_CONCURRENT_MODE_TYPE:
16683 fiberTag = Mode;
16684 mode |= ConcurrentMode | BlockingMode | StrictMode;
16685 break;
16686
16687 case REACT_STRICT_MODE_TYPE:
16688 fiberTag = Mode;
16689 mode |= StrictMode;
16690 break;
16691
16692 case REACT_PROFILER_TYPE:
16693 return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
16694
16695 case REACT_SUSPENSE_TYPE:
16696 return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
16697
16698 case REACT_SUSPENSE_LIST_TYPE:
16699 return createFiberFromSuspenseList(pendingProps, mode, expirationTime, key);
16700
16701 default:
16702 {
16703 if (typeof type === 'object' && type !== null) {
16704 switch (type.$$typeof) {
16705 case REACT_PROVIDER_TYPE:
16706 fiberTag = ContextProvider;
16707 break getTag;
16708
16709 case REACT_CONTEXT_TYPE:
16710 // This is a consumer
16711 fiberTag = ContextConsumer;
16712 break getTag;
16713
16714 case REACT_FORWARD_REF_TYPE:
16715 fiberTag = ForwardRef;
16716
16717 {
16718 resolvedType = resolveForwardRefForHotReloading(resolvedType);
16719 }
16720
16721 break getTag;
16722
16723 case REACT_MEMO_TYPE:
16724 fiberTag = MemoComponent;
16725 break getTag;
16726
16727 case REACT_LAZY_TYPE:
16728 fiberTag = LazyComponent;
16729 resolvedType = null;
16730 break getTag;
16731
16732 case REACT_FUNDAMENTAL_TYPE:
16733 if (enableFundamentalAPI) {
16734 return createFiberFromFundamental(type, pendingProps, mode, expirationTime, key);
16735 }
16736
16737 break;
16738
16739 case REACT_SCOPE_TYPE:
16740 if (enableScopeAPI) {
16741 return createFiberFromScope(type, pendingProps, mode, expirationTime, key);
16742 }
16743
16744 }
16745 }
16746
16747 var info = '';
16748
16749 {
16750 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
16751 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.';
16752 }
16753
16754 var ownerName = owner ? getComponentName(owner.type) : null;
16755
16756 if (ownerName) {
16757 info += '\n\nCheck the render method of `' + ownerName + '`.';
16758 }
16759 }
16760
16761 {
16762 {
16763 throw 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);
16764 }
16765 }
16766 }
16767 }
16768 }
16769
16770 fiber = createFiber(fiberTag, pendingProps, key, mode);
16771 fiber.elementType = type;
16772 fiber.type = resolvedType;
16773 fiber.expirationTime = expirationTime;
16774 return fiber;
16775}
16776function createFiberFromElement(element, mode, expirationTime) {
16777 var owner = null;
16778
16779 {
16780 owner = element._owner;
16781 }
16782
16783 var type = element.type;
16784 var key = element.key;
16785 var pendingProps = element.props;
16786 var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, expirationTime);
16787
16788 {
16789 fiber._debugSource = element._source;
16790 fiber._debugOwner = element._owner;
16791 }
16792
16793 return fiber;
16794}
16795function createFiberFromFragment(elements, mode, expirationTime, key) {
16796 var fiber = createFiber(Fragment, elements, key, mode);
16797 fiber.expirationTime = expirationTime;
16798 return fiber;
16799}
16800function createFiberFromFundamental(fundamentalComponent, pendingProps, mode, expirationTime, key) {
16801 var fiber = createFiber(FundamentalComponent, pendingProps, key, mode);
16802 fiber.elementType = fundamentalComponent;
16803 fiber.type = fundamentalComponent;
16804 fiber.expirationTime = expirationTime;
16805 return fiber;
16806}
16807
16808function createFiberFromScope(scope, pendingProps, mode, expirationTime, key) {
16809 var fiber = createFiber(ScopeComponent, pendingProps, key, mode);
16810 fiber.type = scope;
16811 fiber.elementType = scope;
16812 fiber.expirationTime = expirationTime;
16813 return fiber;
16814}
16815
16816function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
16817 {
16818 if (typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function') {
16819 warningWithoutStack$1(false, 'Profiler must specify an "id" string and "onRender" function as props');
16820 }
16821 }
16822
16823 var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
16824
16825 fiber.elementType = REACT_PROFILER_TYPE;
16826 fiber.type = REACT_PROFILER_TYPE;
16827 fiber.expirationTime = expirationTime;
16828 return fiber;
16829}
16830
16831function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
16832 var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
16833 // This needs to be fixed in getComponentName so that it relies on the tag
16834 // instead.
16835
16836 fiber.type = REACT_SUSPENSE_TYPE;
16837 fiber.elementType = REACT_SUSPENSE_TYPE;
16838 fiber.expirationTime = expirationTime;
16839 return fiber;
16840}
16841function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
16842 var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
16843
16844 {
16845 // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
16846 // This needs to be fixed in getComponentName so that it relies on the tag
16847 // instead.
16848 fiber.type = REACT_SUSPENSE_LIST_TYPE;
16849 }
16850
16851 fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
16852 fiber.expirationTime = expirationTime;
16853 return fiber;
16854}
16855function createFiberFromText(content, mode, expirationTime) {
16856 var fiber = createFiber(HostText, content, null, mode);
16857 fiber.expirationTime = expirationTime;
16858 return fiber;
16859}
16860function createFiberFromHostInstanceForDeletion() {
16861 var fiber = createFiber(HostComponent, null, null, NoMode); // TODO: These should not need a type.
16862
16863 fiber.elementType = 'DELETED';
16864 fiber.type = 'DELETED';
16865 return fiber;
16866}
16867function createFiberFromDehydratedFragment(dehydratedNode) {
16868 var fiber = createFiber(DehydratedFragment, null, null, NoMode);
16869 fiber.stateNode = dehydratedNode;
16870 return fiber;
16871}
16872function createFiberFromPortal(portal, mode, expirationTime) {
16873 var pendingProps = portal.children !== null ? portal.children : [];
16874 var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
16875 fiber.expirationTime = expirationTime;
16876 fiber.stateNode = {
16877 containerInfo: portal.containerInfo,
16878 pendingChildren: null,
16879 // Used by persistent updates
16880 implementation: portal.implementation
16881 };
16882 return fiber;
16883} // Used for stashing WIP properties to replay failed work in DEV.
16884
16885function assignFiberPropertiesInDEV(target, source) {
16886 if (target === null) {
16887 // This Fiber's initial properties will always be overwritten.
16888 // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
16889 target = createFiber(IndeterminateComponent, null, null, NoMode);
16890 } // This is intentionally written as a list of all properties.
16891 // We tried to use Object.assign() instead but this is called in
16892 // the hottest path, and Object.assign() was too slow:
16893 // https://github.com/facebook/react/issues/12502
16894 // This code is DEV-only so size is not a concern.
16895
16896
16897 target.tag = source.tag;
16898 target.key = source.key;
16899 target.elementType = source.elementType;
16900 target.type = source.type;
16901 target.stateNode = source.stateNode;
16902 target.return = source.return;
16903 target.child = source.child;
16904 target.sibling = source.sibling;
16905 target.index = source.index;
16906 target.ref = source.ref;
16907 target.pendingProps = source.pendingProps;
16908 target.memoizedProps = source.memoizedProps;
16909 target.updateQueue = source.updateQueue;
16910 target.memoizedState = source.memoizedState;
16911 target.dependencies = source.dependencies;
16912 target.mode = source.mode;
16913 target.effectTag = source.effectTag;
16914 target.nextEffect = source.nextEffect;
16915 target.firstEffect = source.firstEffect;
16916 target.lastEffect = source.lastEffect;
16917 target.expirationTime = source.expirationTime;
16918 target.childExpirationTime = source.childExpirationTime;
16919 target.alternate = source.alternate;
16920
16921 if (enableProfilerTimer) {
16922 target.actualDuration = source.actualDuration;
16923 target.actualStartTime = source.actualStartTime;
16924 target.selfBaseDuration = source.selfBaseDuration;
16925 target.treeBaseDuration = source.treeBaseDuration;
16926 }
16927
16928 target._debugID = source._debugID;
16929 target._debugSource = source._debugSource;
16930 target._debugOwner = source._debugOwner;
16931 target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
16932 target._debugNeedsRemount = source._debugNeedsRemount;
16933 target._debugHookTypes = source._debugHookTypes;
16934 return target;
16935}
16936
16937function FiberRootNode(containerInfo, tag, hydrate) {
16938 this.tag = tag;
16939 this.current = null;
16940 this.containerInfo = containerInfo;
16941 this.pendingChildren = null;
16942 this.pingCache = null;
16943 this.finishedExpirationTime = NoWork;
16944 this.finishedWork = null;
16945 this.timeoutHandle = noTimeout;
16946 this.context = null;
16947 this.pendingContext = null;
16948 this.hydrate = hydrate;
16949 this.callbackNode = null;
16950 this.callbackPriority = NoPriority;
16951 this.firstPendingTime = NoWork;
16952 this.firstSuspendedTime = NoWork;
16953 this.lastSuspendedTime = NoWork;
16954 this.nextKnownPendingLevel = NoWork;
16955 this.lastPingedTime = NoWork;
16956 this.lastExpiredTime = NoWork;
16957
16958 if (enableSchedulerTracing) {
16959 this.interactionThreadID = unstable_getThreadID();
16960 this.memoizedInteractions = new Set();
16961 this.pendingInteractionMap = new Map();
16962 }
16963
16964 if (enableSuspenseCallback) {
16965 this.hydrationCallbacks = null;
16966 }
16967}
16968
16969function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
16970 var root = new FiberRootNode(containerInfo, tag, hydrate);
16971
16972 if (enableSuspenseCallback) {
16973 root.hydrationCallbacks = hydrationCallbacks;
16974 } // Cyclic construction. This cheats the type system right now because
16975 // stateNode is any.
16976
16977
16978 var uninitializedFiber = createHostRootFiber(tag);
16979 root.current = uninitializedFiber;
16980 uninitializedFiber.stateNode = root;
16981 return root;
16982}
16983function isRootSuspendedAtTime(root, expirationTime) {
16984 var firstSuspendedTime = root.firstSuspendedTime;
16985 var lastSuspendedTime = root.lastSuspendedTime;
16986 return firstSuspendedTime !== NoWork && firstSuspendedTime >= expirationTime && lastSuspendedTime <= expirationTime;
16987}
16988function markRootSuspendedAtTime(root, expirationTime) {
16989 var firstSuspendedTime = root.firstSuspendedTime;
16990 var lastSuspendedTime = root.lastSuspendedTime;
16991
16992 if (firstSuspendedTime < expirationTime) {
16993 root.firstSuspendedTime = expirationTime;
16994 }
16995
16996 if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
16997 root.lastSuspendedTime = expirationTime;
16998 }
16999
17000 if (expirationTime <= root.lastPingedTime) {
17001 root.lastPingedTime = NoWork;
17002 }
17003
17004 if (expirationTime <= root.lastExpiredTime) {
17005 root.lastExpiredTime = NoWork;
17006 }
17007}
17008function markRootUpdatedAtTime(root, expirationTime) {
17009 // Update the range of pending times
17010 var firstPendingTime = root.firstPendingTime;
17011
17012 if (expirationTime > firstPendingTime) {
17013 root.firstPendingTime = expirationTime;
17014 } // Update the range of suspended times. Treat everything lower priority or
17015 // equal to this update as unsuspended.
17016
17017
17018 var firstSuspendedTime = root.firstSuspendedTime;
17019
17020 if (firstSuspendedTime !== NoWork) {
17021 if (expirationTime >= firstSuspendedTime) {
17022 // The entire suspended range is now unsuspended.
17023 root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
17024 } else if (expirationTime >= root.lastSuspendedTime) {
17025 root.lastSuspendedTime = expirationTime + 1;
17026 } // This is a pending level. Check if it's higher priority than the next
17027 // known pending level.
17028
17029
17030 if (expirationTime > root.nextKnownPendingLevel) {
17031 root.nextKnownPendingLevel = expirationTime;
17032 }
17033 }
17034}
17035function markRootFinishedAtTime(root, finishedExpirationTime, remainingExpirationTime) {
17036 // Update the range of pending times
17037 root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
17038 // equal to this update as unsuspended.
17039
17040 if (finishedExpirationTime <= root.lastSuspendedTime) {
17041 // The entire suspended range is now unsuspended.
17042 root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
17043 } else if (finishedExpirationTime <= root.firstSuspendedTime) {
17044 // Part of the suspended range is now unsuspended. Narrow the range to
17045 // include everything between the unsuspended time (non-inclusive) and the
17046 // last suspended time.
17047 root.firstSuspendedTime = finishedExpirationTime - 1;
17048 }
17049
17050 if (finishedExpirationTime <= root.lastPingedTime) {
17051 // Clear the pinged time
17052 root.lastPingedTime = NoWork;
17053 }
17054
17055 if (finishedExpirationTime <= root.lastExpiredTime) {
17056 // Clear the expired time
17057 root.lastExpiredTime = NoWork;
17058 }
17059}
17060function markRootExpiredAtTime(root, expirationTime) {
17061 var lastExpiredTime = root.lastExpiredTime;
17062
17063 if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
17064 root.lastExpiredTime = expirationTime;
17065 }
17066}
17067
17068// This lets us hook into Fiber to debug what it's doing.
17069// See https://github.com/facebook/react/pull/8033.
17070// This is not part of the public API, not even for React DevTools.
17071// You may only inject a debugTool if you work on React Fiber itself.
17072var ReactFiberInstrumentation = {
17073 debugTool: null
17074};
17075var ReactFiberInstrumentation_1 = ReactFiberInstrumentation;
17076
17077var didWarnAboutNestedUpdates;
17078{
17079 didWarnAboutNestedUpdates = false;
17080
17081}
17082
17083function getContextForSubtree(parentComponent) {
17084 if (!parentComponent) {
17085 return emptyContextObject;
17086 }
17087
17088 var fiber = get(parentComponent);
17089 var parentContext = findCurrentUnmaskedContext(fiber);
17090
17091 if (fiber.tag === ClassComponent) {
17092 var Component = fiber.type;
17093
17094 if (isContextProvider(Component)) {
17095 return processChildContext(fiber, Component, parentContext);
17096 }
17097 }
17098
17099 return parentContext;
17100}
17101
17102function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
17103 return createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks);
17104}
17105function updateContainer(element, container, parentComponent, callback) {
17106 var current$$1 = container.current;
17107 var currentTime = requestCurrentTimeForUpdate();
17108
17109 {
17110 // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
17111 if ('undefined' !== typeof jest) {
17112 warnIfUnmockedScheduler(current$$1);
17113 warnIfNotScopedWithMatchingAct(current$$1);
17114 }
17115 }
17116
17117 var suspenseConfig = requestCurrentSuspenseConfig();
17118 var expirationTime = computeExpirationForFiber(currentTime, current$$1, suspenseConfig);
17119
17120 {
17121 if (ReactFiberInstrumentation_1.debugTool) {
17122 if (current$$1.alternate === null) {
17123 ReactFiberInstrumentation_1.debugTool.onMountContainer(container);
17124 } else if (element === null) {
17125 ReactFiberInstrumentation_1.debugTool.onUnmountContainer(container);
17126 } else {
17127 ReactFiberInstrumentation_1.debugTool.onUpdateContainer(container);
17128 }
17129 }
17130 }
17131
17132 var context = getContextForSubtree(parentComponent);
17133
17134 if (container.context === null) {
17135 container.context = context;
17136 } else {
17137 container.pendingContext = context;
17138 }
17139
17140 {
17141 if (phase === 'render' && current !== null && !didWarnAboutNestedUpdates) {
17142 didWarnAboutNestedUpdates = true;
17143 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');
17144 }
17145 }
17146
17147 var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
17148 // being called "element".
17149
17150 update.payload = {
17151 element: element
17152 };
17153 callback = callback === undefined ? null : callback;
17154
17155 if (callback !== null) {
17156 !(typeof callback === 'function') ? warningWithoutStack$1(false, 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0;
17157 update.callback = callback;
17158 }
17159
17160 enqueueUpdate(current$$1, update);
17161 scheduleWork(current$$1, expirationTime);
17162 return expirationTime;
17163}
17164function getPublicRootInstance(container) {
17165 var containerFiber = container.current;
17166
17167 if (!containerFiber.child) {
17168 return null;
17169 }
17170
17171 switch (containerFiber.child.tag) {
17172 case HostComponent:
17173 return getPublicInstance(containerFiber.child.stateNode);
17174
17175 default:
17176 return containerFiber.child.stateNode;
17177 }
17178}
17179
17180
17181
17182
17183
17184
17185
17186var shouldSuspendImpl = function (fiber) {
17187 return false;
17188};
17189
17190function shouldSuspend(fiber) {
17191 return shouldSuspendImpl(fiber);
17192}
17193var overrideHookState = null;
17194var overrideProps = null;
17195var scheduleUpdate = null;
17196var setSuspenseHandler = null;
17197
17198{
17199 var copyWithSetImpl = function (obj, path, idx, value) {
17200 if (idx >= path.length) {
17201 return value;
17202 }
17203
17204 var key = path[idx];
17205 var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj); // $FlowFixMe number or string is fine here
17206
17207 updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
17208 return updated;
17209 };
17210
17211 var copyWithSet = function (obj, path, value) {
17212 return copyWithSetImpl(obj, path, 0, value);
17213 }; // Support DevTools editable values for useState and useReducer.
17214
17215
17216 overrideHookState = function (fiber, id, path, value) {
17217 // For now, the "id" of stateful hooks is just the stateful hook index.
17218 // This may change in the future with e.g. nested hooks.
17219 var currentHook = fiber.memoizedState;
17220
17221 while (currentHook !== null && id > 0) {
17222 currentHook = currentHook.next;
17223 id--;
17224 }
17225
17226 if (currentHook !== null) {
17227 var newState = copyWithSet(currentHook.memoizedState, path, value);
17228 currentHook.memoizedState = newState;
17229 currentHook.baseState = newState; // We aren't actually adding an update to the queue,
17230 // because there is no update we can add for useReducer hooks that won't trigger an error.
17231 // (There's no appropriate action type for DevTools overrides.)
17232 // As a result though, React will see the scheduled update as a noop and bailout.
17233 // Shallow cloning props works as a workaround for now to bypass the bailout check.
17234
17235 fiber.memoizedProps = _assign({}, fiber.memoizedProps);
17236 scheduleWork(fiber, Sync);
17237 }
17238 }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
17239
17240
17241 overrideProps = function (fiber, path, value) {
17242 fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
17243
17244 if (fiber.alternate) {
17245 fiber.alternate.pendingProps = fiber.pendingProps;
17246 }
17247
17248 scheduleWork(fiber, Sync);
17249 };
17250
17251 scheduleUpdate = function (fiber) {
17252 scheduleWork(fiber, Sync);
17253 };
17254
17255 setSuspenseHandler = function (newShouldSuspendImpl) {
17256 shouldSuspendImpl = newShouldSuspendImpl;
17257 };
17258}
17259
17260function injectIntoDevTools(devToolsConfig) {
17261 var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
17262 var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
17263 return injectInternals(_assign({}, devToolsConfig, {
17264 overrideHookState: overrideHookState,
17265 overrideProps: overrideProps,
17266 setSuspenseHandler: setSuspenseHandler,
17267 scheduleUpdate: scheduleUpdate,
17268 currentDispatcherRef: ReactCurrentDispatcher,
17269 findHostInstanceByFiber: function (fiber) {
17270 var hostFiber = findCurrentHostFiber(fiber);
17271
17272 if (hostFiber === null) {
17273 return null;
17274 }
17275
17276 return hostFiber.stateNode;
17277 },
17278 findFiberByHostInstance: function (instance) {
17279 if (!findFiberByHostInstance) {
17280 // Might not be implemented by the renderer.
17281 return null;
17282 }
17283
17284 return findFiberByHostInstance(instance);
17285 },
17286 // React Refresh
17287 findHostInstancesForRefresh: findHostInstancesForRefresh,
17288 scheduleRefresh: scheduleRefresh,
17289 scheduleRoot: scheduleRoot,
17290 setRefreshHandler: setRefreshHandler,
17291 // Enables DevTools to append owner stacks to error messages in DEV mode.
17292 getCurrentFiber: function () {
17293 return current;
17294 }
17295 }));
17296}
17297
17298// This file intentionally does *not* have the Flow annotation.
17299// Don't add it. See `./inline-typed.js` for an explanation.
17300
17301// TODO: this is special because it gets imported during build.
17302
17303var ReactVersion = '16.12.0';
17304
17305var didWarnAboutMessageChannel = false;
17306var enqueueTask;
17307
17308try {
17309 // read require off the module object to get around the bundlers.
17310 // we don't want them to detect a require and bundle a Node polyfill.
17311 var requireString = ('require' + Math.random()).slice(0, 7);
17312 var nodeRequire = module && module[requireString]; // assuming we're in node, let's try to get node's
17313 // version of setImmediate, bypassing fake timers if any.
17314
17315 enqueueTask = nodeRequire('timers').setImmediate;
17316} catch (_err) {
17317 // we're in a browser
17318 // we can't use regular timers because they may still be faked
17319 // so we try MessageChannel+postMessage instead
17320 enqueueTask = function (callback) {
17321 {
17322 if (didWarnAboutMessageChannel === false) {
17323 didWarnAboutMessageChannel = true;
17324 !(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;
17325 }
17326 }
17327
17328 var channel = new MessageChannel();
17329 channel.port1.onmessage = callback;
17330 channel.port2.postMessage(undefined);
17331 };
17332}
17333
17334var enqueueTask$1 = enqueueTask;
17335
17336var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
17337// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js
17338
17339var isSchedulerMocked = typeof Scheduler$1.unstable_flushAllWithoutAsserting === 'function';
17340
17341var flushWork = Scheduler$1.unstable_flushAllWithoutAsserting || function () {
17342 var didFlushWork = false;
17343
17344 while (flushPassiveEffects()) {
17345 didFlushWork = true;
17346 }
17347
17348 return didFlushWork;
17349};
17350
17351function flushWorkAndMicroTasks(onDone) {
17352 try {
17353 flushWork();
17354 enqueueTask$1(function () {
17355 if (flushWork()) {
17356 flushWorkAndMicroTasks(onDone);
17357 } else {
17358 onDone();
17359 }
17360 });
17361 } catch (err) {
17362 onDone(err);
17363 }
17364} // we track the 'depth' of the act() calls with this counter,
17365// so we can tell if any async act() calls try to run in parallel.
17366
17367
17368var actingUpdatesScopeDepth = 0;
17369function act(callback) {
17370 var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
17371 var previousIsSomeRendererActing;
17372 var previousIsThisRendererActing;
17373 actingUpdatesScopeDepth++;
17374 previousIsSomeRendererActing = IsSomeRendererActing$1.current;
17375 previousIsThisRendererActing = IsThisRendererActing.current;
17376 IsSomeRendererActing$1.current = true;
17377 IsThisRendererActing.current = true;
17378
17379 function onDone() {
17380 actingUpdatesScopeDepth--;
17381 IsSomeRendererActing$1.current = previousIsSomeRendererActing;
17382 IsThisRendererActing.current = previousIsThisRendererActing;
17383
17384 {
17385 if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
17386 // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
17387 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. ');
17388 }
17389 }
17390 }
17391
17392 var result;
17393
17394 try {
17395 result = batchedUpdates(callback);
17396 } catch (error) {
17397 // on sync errors, we still want to 'cleanup' and decrement actingUpdatesScopeDepth
17398 onDone();
17399 throw error;
17400 }
17401
17402 if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
17403 // setup a boolean that gets set to true only
17404 // once this act() call is await-ed
17405 var called = false;
17406
17407 {
17408 if (typeof Promise !== 'undefined') {
17409 //eslint-disable-next-line no-undef
17410 Promise.resolve().then(function () {}).then(function () {
17411 if (called === false) {
17412 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 () => ...);');
17413 }
17414 });
17415 }
17416 } // in the async case, the returned thenable runs the callback, flushes
17417 // effects and microtasks in a loop until flushPassiveEffects() === false,
17418 // and cleans up
17419
17420
17421 return {
17422 then: function (resolve, reject) {
17423 called = true;
17424 result.then(function () {
17425 if (actingUpdatesScopeDepth > 1 || isSchedulerMocked === true && previousIsSomeRendererActing === true) {
17426 onDone();
17427 resolve();
17428 return;
17429 } // we're about to exit the act() scope,
17430 // now's the time to flush tasks/effects
17431
17432
17433 flushWorkAndMicroTasks(function (err) {
17434 onDone();
17435
17436 if (err) {
17437 reject(err);
17438 } else {
17439 resolve();
17440 }
17441 });
17442 }, function (err) {
17443 onDone();
17444 reject(err);
17445 });
17446 }
17447 };
17448 } else {
17449 {
17450 !(result === undefined) ? warningWithoutStack$1(false, 'The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result) : void 0;
17451 } // flush effects until none remain, and cleanup
17452
17453
17454 try {
17455 if (actingUpdatesScopeDepth === 1 && (isSchedulerMocked === false || previousIsSomeRendererActing === false)) {
17456 // we're about to exit the act() scope,
17457 // now's the time to flush effects
17458 flushWork();
17459 }
17460
17461 onDone();
17462 } catch (err) {
17463 onDone();
17464 throw err;
17465 } // in the sync case, the returned thenable only warns *if* await-ed
17466
17467
17468 return {
17469 then: function (resolve) {
17470 {
17471 warningWithoutStack$1(false, 'Do not await the result of calling act(...) with sync logic, it is not a Promise.');
17472 }
17473
17474 resolve();
17475 }
17476 };
17477 }
17478}
17479
17480var defaultTestOptions = {
17481 createNodeMock: function () {
17482 return null;
17483 }
17484};
17485
17486function toJSON(inst) {
17487 if (inst.isHidden) {
17488 // Omit timed out children from output entirely. This seems like the least
17489 // surprising behavior. We could perhaps add a separate API that includes
17490 // them, if it turns out people need it.
17491 return null;
17492 }
17493
17494 switch (inst.tag) {
17495 case 'TEXT':
17496 return inst.text;
17497
17498 case 'INSTANCE':
17499 {
17500 /* eslint-disable no-unused-vars */
17501 // We don't include the `children` prop in JSON.
17502 // Instead, we will include the actual rendered children.
17503 var _inst$props = inst.props,
17504 children = _inst$props.children,
17505 props = _objectWithoutPropertiesLoose(_inst$props, ["children"]);
17506 /* eslint-enable */
17507
17508
17509 var renderedChildren = null;
17510
17511 if (inst.children && inst.children.length) {
17512 for (var i = 0; i < inst.children.length; i++) {
17513 var renderedChild = toJSON(inst.children[i]);
17514
17515 if (renderedChild !== null) {
17516 if (renderedChildren === null) {
17517 renderedChildren = [renderedChild];
17518 } else {
17519 renderedChildren.push(renderedChild);
17520 }
17521 }
17522 }
17523 }
17524
17525 var json = {
17526 type: inst.type,
17527 props: props,
17528 children: renderedChildren
17529 };
17530 Object.defineProperty(json, '$$typeof', {
17531 value: Symbol.for('react.test.json')
17532 });
17533 return json;
17534 }
17535
17536 default:
17537 throw new Error("Unexpected node type in toJSON: " + inst.tag);
17538 }
17539}
17540
17541function childrenToTree(node) {
17542 if (!node) {
17543 return null;
17544 }
17545
17546 var children = nodeAndSiblingsArray(node);
17547
17548 if (children.length === 0) {
17549 return null;
17550 } else if (children.length === 1) {
17551 return toTree(children[0]);
17552 }
17553
17554 return flatten(children.map(toTree));
17555}
17556
17557function nodeAndSiblingsArray(nodeWithSibling) {
17558 var array = [];
17559 var node = nodeWithSibling;
17560
17561 while (node != null) {
17562 array.push(node);
17563 node = node.sibling;
17564 }
17565
17566 return array;
17567}
17568
17569function flatten(arr) {
17570 var result = [];
17571 var stack = [{
17572 i: 0,
17573 array: arr
17574 }];
17575
17576 while (stack.length) {
17577 var n = stack.pop();
17578
17579 while (n.i < n.array.length) {
17580 var el = n.array[n.i];
17581 n.i += 1;
17582
17583 if (Array.isArray(el)) {
17584 stack.push(n);
17585 stack.push({
17586 i: 0,
17587 array: el
17588 });
17589 break;
17590 }
17591
17592 result.push(el);
17593 }
17594 }
17595
17596 return result;
17597}
17598
17599function toTree(node) {
17600 if (node == null) {
17601 return null;
17602 }
17603
17604 switch (node.tag) {
17605 case HostRoot:
17606 return childrenToTree(node.child);
17607
17608 case HostPortal:
17609 return childrenToTree(node.child);
17610
17611 case ClassComponent:
17612 return {
17613 nodeType: 'component',
17614 type: node.type,
17615 props: _assign({}, node.memoizedProps),
17616 instance: node.stateNode,
17617 rendered: childrenToTree(node.child)
17618 };
17619
17620 case FunctionComponent:
17621 case SimpleMemoComponent:
17622 return {
17623 nodeType: 'component',
17624 type: node.type,
17625 props: _assign({}, node.memoizedProps),
17626 instance: null,
17627 rendered: childrenToTree(node.child)
17628 };
17629
17630 case HostComponent:
17631 {
17632 return {
17633 nodeType: 'host',
17634 type: node.type,
17635 props: _assign({}, node.memoizedProps),
17636 instance: null,
17637 // TODO: use createNodeMock here somehow?
17638 rendered: flatten(nodeAndSiblingsArray(node.child).map(toTree))
17639 };
17640 }
17641
17642 case HostText:
17643 return node.stateNode.text;
17644
17645 case Fragment:
17646 case ContextProvider:
17647 case ContextConsumer:
17648 case Mode:
17649 case Profiler:
17650 case ForwardRef:
17651 case MemoComponent:
17652 case IncompleteClassComponent:
17653 case ScopeComponent:
17654 return childrenToTree(node.child);
17655
17656 default:
17657 {
17658 {
17659 throw Error("toTree() does not yet know how to handle nodes with tag=" + node.tag);
17660 }
17661 }
17662
17663 }
17664}
17665
17666var validWrapperTypes = new Set([FunctionComponent, ClassComponent, HostComponent, ForwardRef, MemoComponent, SimpleMemoComponent, // Normally skipped, but used when there's more than one root child.
17667HostRoot]);
17668
17669function getChildren(parent) {
17670 var children = [];
17671 var startingNode = parent;
17672 var node = startingNode;
17673
17674 if (node.child === null) {
17675 return children;
17676 }
17677
17678 node.child.return = node;
17679 node = node.child;
17680
17681 outer: while (true) {
17682 var descend = false;
17683
17684 if (validWrapperTypes.has(node.tag)) {
17685 children.push(wrapFiber(node));
17686 } else if (node.tag === HostText) {
17687 children.push('' + node.memoizedProps);
17688 } else {
17689 descend = true;
17690 }
17691
17692 if (descend && node.child !== null) {
17693 node.child.return = node;
17694 node = node.child;
17695 continue;
17696 }
17697
17698 while (node.sibling === null) {
17699 if (node.return === startingNode) {
17700 break outer;
17701 }
17702
17703 node = node.return;
17704 }
17705
17706 node.sibling.return = node.return;
17707 node = node.sibling;
17708 }
17709
17710 return children;
17711}
17712
17713var ReactTestInstance =
17714/*#__PURE__*/
17715function () {
17716 var _proto = ReactTestInstance.prototype;
17717
17718 _proto._currentFiber = function _currentFiber() {
17719 // Throws if this component has been unmounted.
17720 var fiber = findCurrentFiberUsingSlowPath(this._fiber);
17721
17722 if (!(fiber !== null)) {
17723 {
17724 throw Error("Can't read from currently-mounting component. This error is likely caused by a bug in React. Please file an issue.");
17725 }
17726 }
17727
17728 return fiber;
17729 };
17730
17731 function ReactTestInstance(fiber) {
17732 if (!validWrapperTypes.has(fiber.tag)) {
17733 {
17734 throw Error("Unexpected object passed to ReactTestInstance constructor (tag: " + fiber.tag + "). This is probably a bug in React.");
17735 }
17736 }
17737
17738 this._fiber = fiber;
17739 }
17740
17741 // Custom search functions
17742 _proto.find = function find(predicate) {
17743 return expectOne(this.findAll(predicate, {
17744 deep: false
17745 }), "matching custom predicate: " + predicate.toString());
17746 };
17747
17748 _proto.findByType = function findByType(type) {
17749 return expectOne(this.findAllByType(type, {
17750 deep: false
17751 }), "with node type: \"" + (type.displayName || type.name) + "\"");
17752 };
17753
17754 _proto.findByProps = function findByProps(props) {
17755 return expectOne(this.findAllByProps(props, {
17756 deep: false
17757 }), "with props: " + JSON.stringify(props));
17758 };
17759
17760 _proto.findAll = function findAll(predicate) {
17761 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
17762 return _findAll(this, predicate, options);
17763 };
17764
17765 _proto.findAllByType = function findAllByType(type) {
17766 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
17767 return _findAll(this, function (node) {
17768 return node.type === type;
17769 }, options);
17770 };
17771
17772 _proto.findAllByProps = function findAllByProps(props) {
17773 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
17774 return _findAll(this, function (node) {
17775 return node.props && propsMatch(node.props, props);
17776 }, options);
17777 };
17778
17779 _createClass(ReactTestInstance, [{
17780 key: "instance",
17781 get: function () {
17782 if (this._fiber.tag === HostComponent) {
17783 return getPublicInstance(this._fiber.stateNode);
17784 } else {
17785 return this._fiber.stateNode;
17786 }
17787 }
17788 }, {
17789 key: "type",
17790 get: function () {
17791 return this._fiber.type;
17792 }
17793 }, {
17794 key: "props",
17795 get: function () {
17796 return this._currentFiber().memoizedProps;
17797 }
17798 }, {
17799 key: "parent",
17800 get: function () {
17801 var parent = this._fiber.return;
17802
17803 while (parent !== null) {
17804 if (validWrapperTypes.has(parent.tag)) {
17805 if (parent.tag === HostRoot) {
17806 // Special case: we only "materialize" instances for roots
17807 // if they have more than a single child. So we'll check that now.
17808 if (getChildren(parent).length < 2) {
17809 return null;
17810 }
17811 }
17812
17813 return wrapFiber(parent);
17814 }
17815
17816 parent = parent.return;
17817 }
17818
17819 return null;
17820 }
17821 }, {
17822 key: "children",
17823 get: function () {
17824 return getChildren(this._currentFiber());
17825 }
17826 }]);
17827
17828 return ReactTestInstance;
17829}();
17830
17831function _findAll(root, predicate, options) {
17832 var deep = options ? options.deep : true;
17833 var results = [];
17834
17835 if (predicate(root)) {
17836 results.push(root);
17837
17838 if (!deep) {
17839 return results;
17840 }
17841 }
17842
17843 root.children.forEach(function (child) {
17844 if (typeof child === 'string') {
17845 return;
17846 }
17847
17848 results.push.apply(results, _findAll(child, predicate, options));
17849 });
17850 return results;
17851}
17852
17853function expectOne(all, message) {
17854 if (all.length === 1) {
17855 return all[0];
17856 }
17857
17858 var prefix = all.length === 0 ? 'No instances found ' : "Expected 1 but found " + all.length + " instances ";
17859 throw new Error(prefix + message);
17860}
17861
17862function propsMatch(props, filter) {
17863 for (var key in filter) {
17864 if (props[key] !== filter[key]) {
17865 return false;
17866 }
17867 }
17868
17869 return true;
17870}
17871
17872var ReactTestRendererFiber = {
17873 _Scheduler: Scheduler,
17874 create: function (element, options) {
17875 var createNodeMock = defaultTestOptions.createNodeMock;
17876 var isConcurrent = false;
17877
17878 if (typeof options === 'object' && options !== null) {
17879 if (typeof options.createNodeMock === 'function') {
17880 createNodeMock = options.createNodeMock;
17881 }
17882
17883 if (options.unstable_isConcurrent === true) {
17884 isConcurrent = true;
17885 }
17886 }
17887
17888 var container = {
17889 children: [],
17890 createNodeMock: createNodeMock,
17891 tag: 'CONTAINER'
17892 };
17893 var root = createContainer(container, isConcurrent ? ConcurrentRoot : LegacyRoot, false, null);
17894
17895 if (!(root != null)) {
17896 {
17897 throw Error("something went wrong");
17898 }
17899 }
17900
17901 updateContainer(element, root, null, null);
17902 var entry = {
17903 _Scheduler: Scheduler,
17904 root: undefined,
17905 // makes flow happy
17906 // we define a 'getter' for 'root' below using 'Object.defineProperty'
17907 toJSON: function () {
17908 if (root == null || root.current == null || container == null) {
17909 return null;
17910 }
17911
17912 if (container.children.length === 0) {
17913 return null;
17914 }
17915
17916 if (container.children.length === 1) {
17917 return toJSON(container.children[0]);
17918 }
17919
17920 if (container.children.length === 2 && container.children[0].isHidden === true && container.children[1].isHidden === false) {
17921 // Omit timed out children from output entirely, including the fact that we
17922 // temporarily wrap fallback and timed out children in an array.
17923 return toJSON(container.children[1]);
17924 }
17925
17926 var renderedChildren = null;
17927
17928 if (container.children && container.children.length) {
17929 for (var i = 0; i < container.children.length; i++) {
17930 var renderedChild = toJSON(container.children[i]);
17931
17932 if (renderedChild !== null) {
17933 if (renderedChildren === null) {
17934 renderedChildren = [renderedChild];
17935 } else {
17936 renderedChildren.push(renderedChild);
17937 }
17938 }
17939 }
17940 }
17941
17942 return renderedChildren;
17943 },
17944 toTree: function () {
17945 if (root == null || root.current == null) {
17946 return null;
17947 }
17948
17949 return toTree(root.current);
17950 },
17951 update: function (newElement) {
17952 if (root == null || root.current == null) {
17953 return;
17954 }
17955
17956 updateContainer(newElement, root, null, null);
17957 },
17958 unmount: function () {
17959 if (root == null || root.current == null) {
17960 return;
17961 }
17962
17963 updateContainer(null, root, null, null);
17964 container = null;
17965 root = null;
17966 },
17967 getInstance: function () {
17968 if (root == null || root.current == null) {
17969 return null;
17970 }
17971
17972 return getPublicRootInstance(root);
17973 },
17974 unstable_flushSync: function (fn) {
17975 return flushSync(fn);
17976 }
17977 };
17978 Object.defineProperty(entry, 'root', {
17979 configurable: true,
17980 enumerable: true,
17981 get: function () {
17982 if (root === null) {
17983 throw new Error("Can't access .root on unmounted test renderer");
17984 }
17985
17986 var children = getChildren(root.current);
17987
17988 if (children.length === 0) {
17989 throw new Error("Can't access .root on unmounted test renderer");
17990 } else if (children.length === 1) {
17991 // Normally, we skip the root and just give you the child.
17992 return children[0];
17993 } else {
17994 // However, we give you the root if there's more than one root child.
17995 // We could make this the behavior for all cases but it would be a breaking change.
17996 return wrapFiber(root.current);
17997 }
17998 }
17999 });
18000 return entry;
18001 },
18002
18003 /* eslint-disable-next-line camelcase */
18004 unstable_batchedUpdates: batchedUpdates,
18005 act: act
18006};
18007var fiberToWrapper = new WeakMap();
18008
18009function wrapFiber(fiber) {
18010 var wrapper = fiberToWrapper.get(fiber);
18011
18012 if (wrapper === undefined && fiber.alternate !== null) {
18013 wrapper = fiberToWrapper.get(fiber.alternate);
18014 }
18015
18016 if (wrapper === undefined) {
18017 wrapper = new ReactTestInstance(fiber);
18018 fiberToWrapper.set(fiber, wrapper);
18019 }
18020
18021 return wrapper;
18022} // Enable ReactTestRenderer to be used to test DevTools integration.
18023
18024
18025injectIntoDevTools({
18026 findFiberByHostInstance: function () {
18027 throw new Error('TestRenderer does not support findFiberByHostInstance()');
18028 },
18029 bundleType: 1,
18030 version: ReactVersion,
18031 rendererPackageName: 'react-test-renderer'
18032});
18033
18034
18035var ReactTestRenderer = Object.freeze({
18036 default: ReactTestRendererFiber
18037});
18038
18039var ReactTestRenderer$1 = ( ReactTestRenderer && ReactTestRendererFiber ) || ReactTestRenderer;
18040
18041// TODO: decide on the top-level export form.
18042// This is hacky but makes it work with both Rollup and Jest.
18043
18044
18045var reactTestRenderer = ReactTestRenderer$1.default || ReactTestRenderer$1;
18046
18047return reactTestRenderer;
18048
18049})));